diff --git a/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php index 9a909d71..164cb142 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/ImportCiefLiteStatementLogic.php @@ -7,6 +7,7 @@ use App\Classes\Exceptions\MalformedRequestException; use App\Classes\General\Abstracts\AbstractControllerLogic; use App\Classes\Modules\Documents\DataTransferObjects\DocumentObject; use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Classes\ValueObjects\Constants\StatementTransactionOwnerType; use App\Models\AccountStatement; use App\Models\StatementAccount; use App\Models\StatementTransaction; @@ -45,77 +46,28 @@ class ImportCiefLiteStatementLogic extends AbstractControllerLogic $sheet = $collection->first()->skip(1); - $dateTo = $sheet->first()[10]; - $dateFrom = $sheet->last()[10]; - $totalTransaction = $sheet->count(); - - $offset = 1; - do { - $dateFrom = $sheet->offsetGet($sheet->count() - $offset)[10]; - $offset += 1; - } while(!$dateFrom); - - - $dateFrom = carbon::parse($dateFrom); - $dateTo = carbon::parse($dateTo); - - $statement = AccountStatement::whereDate('date_from', $dateFrom) - ->whereDate('date_to', $dateTo) - ->where('total_amount', $totalTransaction) - ->first(); - - if(!$statement){ - $statement = new AccountStatement([ - 'date_from' => $dateFrom, - 'date_to' => $dateTo, - 'total_amount' => $totalTransaction, - ]); - } - - $account = StatementAccount::where("name", "CIEF LITE")->first(); - - if (!$account) { - throw new Exception("Statement Account for CIEF LITE not found."); - } - - $account->statements()->save($statement); - - $sheet->map(function ($row) use ($statement) { - if (!$row[0]) { + $sheet->map(function ($row) { + if (!$row[0] || trim($row[8]) !== "已审核") { return; } - $postingDate = $row[10]; - $transactionDescription = trim($row[1]); - $description2 = trim($row[2]); - $description3 = "Fee " . $row[6]; - $description4 = trim($row[8]); - $transactionRef = trim($row[12]); + $postingDate =date('Y-m-d', strtotime($row[10])); $amount = ((float) str_replace(',', '', $row[7])); - $transactionCode = $row[0]; - $transaction = new StatementTransaction([ - 'posting_date' => $postingDate, - 'transaction_description' => $transactionDescription, - 'transaction_description_2' => $description2, - 'transaction_description_3' => $description3, - 'transaction_description_4' => $description4, - 'transaction_ref' => $transactionRef, - 'amount' => $amount, - 'transaction_code' => $transactionCode, - ]); + + $statementTransaction = StatementTransaction::whereHas('account', function($query) { + $query->where('statement_accounts.number', 8881040198515); + })->whereDate('posting_date', $postingDate)->where('amount', $amount)->first(); - // Check if the transaction already exists for this statement - $existingTransaction = StatementTransaction::where('transaction_ref', $transactionRef) - ->where('posting_date', $postingDate) - ->where('amount', $amount) - ->where('transaction_description', $transactionDescription) - ->where('transaction_code', $transactionCode) - ->first(); - - if (!$existingTransaction) { - $statement->transactions()->save($transaction); + if (!$statementTransaction) { + return; } - return $transaction; + $owner = $statementTransaction->owners()->firstOrCreate([ + 'type' => StatementTransactionOwnerType::WALLET_TOP_UP, + 'system' => 'LITE', + 'owner_reference'=> $row[0], + ]); + + return $owner; }); } diff --git a/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php index 3a006e9e..55051959 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/UpdateStatementTransactionStatusLogic.php @@ -63,7 +63,7 @@ class UpdateStatementTransactionStatusLogic extends AbstractControllerLogic { $statementTrasaction = $this->fetchesBankStatementTransaction->execute(['id' => $request->route('id')]); - $statementTrasactionOwner = $statementTrasaction->owners->first(); + $statementTrasactionOwner = $statementTrasaction->owners()->where('status', '!=', ApprovalStatus::REJECTED)->first(); $this->updatesBankStatementTransactionOwnerStatus->execute($statementTrasactionOwner, $request->route('status') == 'approve' ? ApprovalStatus::APPROVED : ApprovalStatus::REJECTED); diff --git a/app/Models/StatementTransaction.php b/app/Models/StatementTransaction.php index 4bba7903..6f9013b7 100644 --- a/app/Models/StatementTransaction.php +++ b/app/Models/StatementTransaction.php @@ -56,7 +56,9 @@ class StatementTransaction extends Model public function scopeDoesntMapStatement($query) { - $query->whereDoesntHave('owners', function($query){ + $query->whereHas('account', function($query) { + $query->where('statement_accounts.number', 568603010762); + })->whereDoesntHave('owners', function($query){ return $query->whereIn('status', [ApprovalStatus::PENDING_VERIFICATION, ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]); })->orderBy('posting_date'); } diff --git a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue index 5d1341b1..3e077bbc 100644 --- a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue +++ b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue @@ -136,7 +136,7 @@ case 'Sales': return ['Exchange', 'Izyim', 'Lite', 'Cntr', 'Probashi', 'Pets']; case 'Top Up': - return ['Exchange', 'Izyim']; + return ['Exchange', 'Izyim', 'Lite']; default: return []; } diff --git a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue index 0c193871..f92fc5d7 100644 --- a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue +++ b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue @@ -10,7 +10,8 @@