diff --git a/app/Http/Controllers/Imports/ImportBankRecordController.php b/app/Http/Controllers/Imports/ImportBankRecordController.php
index 3c0ebb1b..ebf1ea61 100644
--- a/app/Http/Controllers/Imports/ImportBankRecordController.php
+++ b/app/Http/Controllers/Imports/ImportBankRecordController.php
@@ -10,8 +10,6 @@ use App\Models\Booking;
use App\Models\Group;
use App\Models\Transaction;
use Illuminate\Http\Request;
-use Illuminate\Support\Facades\Cache;
-use Illuminate\Support\Facades\DB;
use Maatwebsite\Excel\Facades\Excel;
use PhpOffice\PhpSpreadsheet\Shared\Date;
@@ -21,8 +19,7 @@ class ImportBankRecordController
* @param Request $request
* @return array
*/
- public function import(Request $request)
- {
+ public function import(Request $request) {
$headers = [
'Date',
'Bank',
@@ -44,59 +41,59 @@ class ImportBankRecordController
$yes = 'Yes';
$no = 'No';
- $table = '
| ' . implode(' | ', $headers) . ' |
';
+ $table = '| '.implode(' | ', $headers).' |
';
- $cacheKey = 'bank_transaction_data';
+ $collection = Excel::toCollection(new ImportsBankRecord(), 'daily_transaction_nov.xlsx');
- $data = Cache::get($cacheKey);
+ foreach ($collection as $key => $sheet){
+ $branch = $branches[$key];
+ foreach ($sheet as $row) {
+ $date = Date::excelToDateTimeObject($row['date']);
+ $credit = (float) $row['credit'];
+ $debit = (float) $row['debit'];
+ $creditTransactions = [];
+ $debitTransactions = [];
- if (!$data) {
- $data = $this->fetchDataFromDatabase();
- Cache::put($cacheKey, $data, now()->addMinutes(60));
- }
+ $systemReference = null;
- foreach ($data as $row) {
- $branch = $branches[$row->branch_id];
-
- $credit = (float)$row->credit;
- $debit = (float)$row->debit;
- $creditTransactions = [];
- $debitTransactions = [];
-
- $systemReference = null;
-
- if ($credit) {
- $creditTransactions = $this->getTransactions($row->date, $credit, TransactionType::PAYMENT, Booking::class, PaymentMethodType::WALLET, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
- foreach ($creditTransactions as $transaction) {
- $systemReference[] = $transaction->owner instanceof Booking ? $transaction->owner->marking : $transaction->bill_no;
+ if($credit){
+ $creditTransactions = $this->getTransactions($date, $credit, TransactionType::PAYMENT, Booking::class, PaymentMethodType::WALLET, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
+ foreach ($creditTransactions as $transaction) {
+ $systemReference[] = $transaction->owner instanceof Booking ? $transaction->owner->marking : $transaction->bill_no;
+ }
}
- }
- if ($debit) {
- $debitTransactions = $this->getTransactions($row->date, $debit, null, null, null, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED], Group::class);
- foreach ($debitTransactions as $transaction) {
- $systemReference[] = $transaction->reference;
+ if($debit){
+ $debitTransactions = $this->getTransactions($date, $debit, null, null, null, [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED], Group::class);
+ foreach ($debitTransactions as $transaction) {
+ $systemReference[] = $transaction->reference;
+ }
}
- }
- $multiple = count($creditTransactions) + count($debitTransactions) > 1 ? $yes : $no;
- $systemReference = $systemReference ? implode(',', $systemReference) : null;
+ $multiple = count($creditTransactions) + count($debitTransactions) > 1 ? $yes : $no;
- $matches = $systemReference == $row->remark_references ? $yes : $no;
- $table .= '
- | ' . $row->date->format('d-m-Y') . ' |
- ' . $branch . ' |
- ' . $row->description . ' |
- ' . $credit . ' |
- ' . $debit . ' |
- ' . $row->pay_for . ' |
- ' . $systemReference . ' |
- ' . $row->remark_references . ' |
- ' . $multiple . ' |
- ' . $matches . ' |
+
+
+
+ $systemReference = $systemReference ? implode(',', $systemReference) : null;
+
+ $matches = $systemReference == $row['remarkreferences'] ? $yes : $no;
+
+ $table .= '
+ | '.$date->format('d-m-Y').' |
+ '.$branch.' |
+ '.$row['description'].' |
+ '.$credit.' |
+ '.$debit.' |
+ '.$row['pay_for'].' |
+ '.$systemReference.' |
+ '.$row['remarkreferences'].' |
+ '.$multiple.' |
+ '.$matches.' |
';
+ }
}
$table .= '
';
@@ -104,30 +101,7 @@ class ImportBankRecordController
echo $table;
}
- private function fetchDataFromDatabase()
- {
- $data = DB::table('bank_transactions')
- ->select([
- 'date',
- 'branch_id',
- 'description',
- 'credit',
- 'debit',
- 'pay_for',
- 'remark_references',
- ])
- ->get();
-
- $data = $data->map(function ($row) {
- $row->date = Date::excelToDateTimeObject($row->date);
- return $row;
- });
-
- return $data;
- }
-
- private function getTransactions($date, $amount, $type, $ownerType, $paymentMethod, $statuses, $model = Transaction::class)
- {
+ private function getTransactions($date, $amount, $type, $ownerType, $paymentMethod, $statuses, $model = Transaction::class) {
$query = $model::whereIn('status', $statuses)
->where(function ($query) use ($ownerType, $paymentMethod, $type) {
if ($ownerType) {
@@ -144,9 +118,8 @@ class ImportBankRecordController
})
->whereDate('created_at', $date->format('Y-m-d'))
->where('amount', '>', ($amount - 0.01))
- ->where('amount', '<', ($amount + 0.01))
- ->cursor();
+ ->where('amount', '<', ($amount + 0.01));
- return $query;
+ return $query->get();
}
}