From 6aa2ed53c76e9968b7083f21a35864a11c106d69 Mon Sep 17 00:00:00 2001 From: Dillon Date: Wed, 12 Apr 2023 05:02:48 +0800 Subject: [PATCH] Allow user to upload statement repeatedly + master list page + rerun mapping + bug fixes --- .../CreateBankStatementDetailsProcessor.php | 30 +++++++--------- .../Accounting/BankStatementController.php | 35 ++++++++++++++----- app/Models/StatementTransaction.php | 1 + app/Models/StatementTransactionsDetail.php | 4 +-- ...34_create_statement_transactions_table.php | 1 + ...e_statement_transactions_details_table.php | 4 +-- .../StatementTransactionsDetailsComponent.vue | 7 +++- .../bank-statements/index.blade.php | 15 ++++++-- routes/web.php | 1 + 9 files changed, 63 insertions(+), 35 deletions(-) diff --git a/app/Classes/Modules/Accounting/Processors/CreateBankStatementDetailsProcessor.php b/app/Classes/Modules/Accounting/Processors/CreateBankStatementDetailsProcessor.php index 4514682c..a978fb33 100644 --- a/app/Classes/Modules/Accounting/Processors/CreateBankStatementDetailsProcessor.php +++ b/app/Classes/Modules/Accounting/Processors/CreateBankStatementDetailsProcessor.php @@ -55,9 +55,8 @@ class CreateBankStatementDetailsProcessor $count = 0; foreach ($transactions as $row) { - $isExist = StatementTransactionsDetail::where('statement_transactions_id', $row->id)->first(); - - if ($isExist) { + $existingRecord = StatementTransactionsDetail::where('statement_transaction_id', $row->id)->first(); + if ($existingRecord && $existingRecord->pay_for != "") { continue; } @@ -140,21 +139,16 @@ class CreateBankStatementDetailsProcessor $matches = $systemReference == $row['remarkreferences'] ? $yes : $no; - $statementTransactionsDetail = new StatementTransactionsDetail([ - 'date' => $date, - 'statement_transactions_id' => $row->id, - // 'description' => is_null($description) ? "" : $description, - // 'credit' => $credit, - // 'debit' => $debit, - 'pay_for' => is_null($system) ? "" : $system, - 'system_references' => is_null($systemReference) ? "" : $systemReference, - // 'remark_references' => is_null($row['remarkreferences']) ? "" : $row['remarkreferences'], - // 'is_multiple' => $multiple == "Yes" ? 1 : 0, - // 'is_matches' => $matches == "Yes" ? 1 : 0, - 'system_amounts'=> is_null($systemAmount) ? "" : $systemAmount, - ]); - - $statementTransactionsDetail->save(); + StatementTransactionsDetail::updateOrCreate( + ['statement_transaction_id' => $row->id], + [ + 'date' => $date, + 'pay_for' => is_null($system) ? "" : $system, + 'system_references' => is_null($systemReference) ? "" : $systemReference, + 'system_amounts'=> is_null($systemAmount) ? "" : $systemAmount, + 'remark_references'=> is_null($row['remarkreferences']) ? "" : $row['remarkreferences'], + ] + ); // if($count == 10){ // break; diff --git a/app/Http/Controllers/Accounting/BankStatementController.php b/app/Http/Controllers/Accounting/BankStatementController.php index 3146e13d..5352d196 100644 --- a/app/Http/Controllers/Accounting/BankStatementController.php +++ b/app/Http/Controllers/Accounting/BankStatementController.php @@ -24,6 +24,7 @@ use Maatwebsite\Excel\Facades\Excel; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; use Illuminate\Support\Carbon; +use Illuminate\Support\Facades\Log; use DateTime; @@ -93,13 +94,22 @@ class BankStatementController extends Controller ] ); - $statement = new AccountStatement([ - 'date_from' => $dateFrom, - 'date_to' => $dateTo, - 'total_amount' => $totalDebit ?: $totalCredit, - 'begin_balance' => $beginBalance, - 'end_balance' => $endBalance, - ]); + $statement = AccountStatement::where('date_from', $dateFrom) + ->where('date_to', $dateTo) + ->where('total_amount', $totalDebit ?: $totalCredit,) + ->where('begin_balance', $beginBalance) + ->where('end_balance', $endBalance)->first(); + + + if(!$statement){ + $statement = new AccountStatement([ + 'date_from' => $dateFrom, + 'date_to' => $dateTo, + 'total_amount' => $totalDebit ?: $totalCredit, + 'begin_balance' => $beginBalance, + 'end_balance' => $endBalance, + ]); + } // $existingStatement = AccountStatement::where('date_from', $dateFrom) // ->where('date_to', $dateTo) @@ -154,6 +164,7 @@ class BankStatementController extends Controller ->where('teller_id', $tellerId) ->where('branch_channel', $branchChannel) ->where('transaction_code', $transactionCode) + ->where('end_balance', $endBalance) ->first(); if (!$existingTransaction) { @@ -168,6 +179,12 @@ class BankStatementController extends Controller return redirect()->back()->with('success', 'Statement imported successfully.')->with('newTransactions', $newTransactions); } + public function rerun(AccountStatement $statement, Request $request) + { + CreateBankStatementDetails::dispatch($statement)->delay(30); + return redirect()->back()->with('success', 'Rerun triggered successfully'); + } + public function show(AccountStatement $statement, Request $request) { $transactions = $statement->transactions(); @@ -247,7 +264,7 @@ class BankStatementController extends Controller $count = 0; foreach ($transactions as $row) { - $isExist = StatementTransactionsDetail::where('statement_transactions_id', $row->id)->first(); + $isExist = StatementTransactionsDetail::where('statement_transaction_id', $row->id)->first(); if ($isExist) { continue; @@ -356,7 +373,7 @@ class BankStatementController extends Controller $statementTransactionsDetail = new StatementTransactionsDetail([ 'date' => $date, - 'statement_transactions_id' => $row->id, + 'statement_transaction_id' => $row->id, 'description' => is_null($description) ? "" : $description, 'credit' => $credit, 'debit' => $debit, diff --git a/app/Models/StatementTransaction.php b/app/Models/StatementTransaction.php index 7d089b65..6b789f08 100644 --- a/app/Models/StatementTransaction.php +++ b/app/Models/StatementTransaction.php @@ -23,6 +23,7 @@ class StatementTransaction extends Model 'teller_id', 'branch_channel', 'transaction_code', + 'end_balance', ]; protected $casts = [ diff --git a/app/Models/StatementTransactionsDetail.php b/app/Models/StatementTransactionsDetail.php index 1a0ee6ba..074f5304 100644 --- a/app/Models/StatementTransactionsDetail.php +++ b/app/Models/StatementTransactionsDetail.php @@ -11,7 +11,7 @@ class StatementTransactionsDetail extends Model protected $fillable = [ 'date', - 'statement_transactions_id', + 'statement_transaction_id', // 'description', // 'credit', // 'debit', @@ -25,6 +25,6 @@ class StatementTransactionsDetail extends Model public function statementTransaction() { - return $this->belongsTo(StatementTransaction::class, 'statement_transactions_id', 'id'); + return $this->belongsTo(StatementTransaction::class, 'statement_transaction_id', 'id'); } } diff --git a/database/migrations/2023_03_26_190934_create_statement_transactions_table.php b/database/migrations/2023_03_26_190934_create_statement_transactions_table.php index bdb90b53..95ad3571 100644 --- a/database/migrations/2023_03_26_190934_create_statement_transactions_table.php +++ b/database/migrations/2023_03_26_190934_create_statement_transactions_table.php @@ -28,6 +28,7 @@ class CreateStatementTransactionsTable extends Migration $table->string('teller_id')->nullable(); $table->string('branch_channel'); $table->string('transaction_code'); + $table->string('end_balance')->nullable(); $table->string('owner_system')->nullable(); $table->string('owner_type')->nullable(); $table->unsignedBigInteger('owner_id')->nullable(); diff --git a/database/migrations/2023_04_07_212512_create_statement_transactions_details_table.php b/database/migrations/2023_04_07_212512_create_statement_transactions_details_table.php index 41abbd96..3bc547fd 100644 --- a/database/migrations/2023_04_07_212512_create_statement_transactions_details_table.php +++ b/database/migrations/2023_04_07_212512_create_statement_transactions_details_table.php @@ -16,8 +16,8 @@ class CreateStatementTransactionsDetailsTable extends Migration Schema::create('statement_transactions_details', function (Blueprint $table) { $table->id(); $table->date('date'); - $table->unsignedBigInteger('statement_transactions_id'); - $table->foreign('statement_transactions_id')->references('id')->on('statement_transactions'); + $table->unsignedBigInteger('statement_transaction_id'); + $table->foreign('statement_transaction_id')->references('id')->on('statement_transactions'); // $table->string('description'); // $table->decimal('credit', 8, 2); // $table->decimal('debit', 8, 2); diff --git a/resources/assets/vue/components/accounting/sections/StatementTransactionsDetailsComponent.vue b/resources/assets/vue/components/accounting/sections/StatementTransactionsDetailsComponent.vue index db9e25e1..9a5e0058 100644 --- a/resources/assets/vue/components/accounting/sections/StatementTransactionsDetailsComponent.vue +++ b/resources/assets/vue/components/accounting/sections/StatementTransactionsDetailsComponent.vue @@ -133,7 +133,7 @@ export default { days: [] }, - filters: {'per_page': 10, order_by: {column: 'id', DESC: true}, 'has_account_statement_id': this.statement}, + filters: {'per_page': 10, order_by: {column: 'id', DESC: true}}, page: 1, days: [], @@ -183,6 +183,11 @@ export default { }, created(){ this.setDecoratorDefault(); + if (this.statement === 0) { + this.filters = { 'per_page': 10, order_by: {column: 'id', DESC: true} }; + } else { + this.filters = { 'per_page': 10, order_by: {column: 'id', DESC: true}, 'has_account_statement_id': this.statement }; + } this.$store.dispatch('updateListQueue', {'name': this.section, 'page': 1, 'filters': this.filters}); }, methods: { diff --git a/resources/views/pages/accounting/bank-statements/index.blade.php b/resources/views/pages/accounting/bank-statements/index.blade.php index 2269ad94..f41813db 100644 --- a/resources/views/pages/accounting/bank-statements/index.blade.php +++ b/resources/views/pages/accounting/bank-statements/index.blade.php @@ -31,8 +31,14 @@
-
Bank Statements
- + @if (session('message')) +
+ {{ session('message') }} +
+ @endif +
Bank Statements + View All +
@@ -65,7 +71,7 @@ Total Amount Begin Balance End Balance - Actions + Actions @@ -80,6 +86,9 @@ View + + Rerun + @endforeach diff --git a/routes/web.php b/routes/web.php index 9c06273e..d7117c89 100644 --- a/routes/web.php +++ b/routes/web.php @@ -561,6 +561,7 @@ Route::get('/statements/{statement}/details', function ($statement) { return view('pages.accounting.bank-statements.details', ['statement' => $statement]); })->name('statements.transactions.details'); Route::get('/statements/{statement}', [BankStatementController::class, 'show'])->name('statements.show'); +Route::get('/statements/{statement}/rerun', [BankStatementController::class, 'rerun'])->name('statements.rerun'); Route::get('/statements/{statement}/download', 'StatementController@download')->name('statements.download'); Route::get('/bank-record', 'Imports\ImportBankRecordController@import');