From 72f4fee8649936d991c8fa1bb535c28e6c68427b Mon Sep 17 00:00:00 2001 From: Steve Ng Date: Mon, 16 Oct 2023 10:24:44 +0800 Subject: [PATCH] add edit at pending_export --- .../UpdateBankStatementDetailLogic.php | 38 +++++++++++++++++-- .../EditSingleItemInListComponent.vue | 9 +++++ .../StatementTransactionComponent.vue | 10 +++++ 3 files changed, 53 insertions(+), 4 deletions(-) diff --git a/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php b/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php index d9eab3db..9f6c28e6 100644 --- a/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php +++ b/app/Classes/Modules/Accounting/ControllersLogic/UpdateBankStatementDetailLogic.php @@ -19,6 +19,9 @@ use App\Models\Wallet; use Exception; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; +use App\Classes\Modules\Accounting\Services\UpdatesBankStatementTransactionOwnerStatus; +use App\Classes\ValueObjects\Constants\ApprovalStatus; +use App\Models\StatementTransactionOwner; class UpdateBankStatementDetailLogic extends AbstractControllerLogic { @@ -40,14 +43,21 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic /** @var ChecksBillNumber */ private $checksBillNumber; + /** @var UpdatesBankStatementTransactionOwnerStatus */ + private $updatesBankStatementTransactionOwnerStatus; + /** * @param FetchesBankStatementTransaction $fetchesBankStatementTransaction * @param ChecksBillNumber $checksBillNumber */ - public function __construct(FetchesBankStatementTransaction $fetchesBankStatementTransaction, ChecksBillNumber $checksBillNumber) + public function __construct( + FetchesBankStatementTransaction $fetchesBankStatementTransaction, + ChecksBillNumber $checksBillNumber, + UpdatesBankStatementTransactionOwnerStatus $updatesBankStatementTransactionOwnerStatus) { $this->fetchesBankStatementTransaction = $fetchesBankStatementTransaction; $this->checksBillNumber = $checksBillNumber; + $this->updatesBankStatementTransactionOwnerStatus = $updatesBankStatementTransactionOwnerStatus; } public function logic(Request $request): JsonResponse @@ -129,7 +139,10 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic $system = $systemReference != null ? SystemType::SYSTEM_NAMES[$systemReference] : ''; - $this->createBankStatementTransactionOwner($bankStatementTransaction, $statementTransactionOwnerType, $system, $owner_type, $owner_id, $owner_reference); + $statementTransactionOwner = $this->createBankStatementTransactionOwner($bankStatementTransaction, $statementTransactionOwnerType, $system, $owner_type, $owner_id, $owner_reference); + + // this for edit a transaction already mapped + if ($request->has('editMapped')) $this->editAccountMapped($statementTransactionOwner); return $this->response([]); } @@ -144,9 +157,26 @@ class UpdateBankStatementDetailLogic extends AbstractControllerLogic 'owner_reference' => $owner_reference, ]; - $bankStatementTransaction->owners()->firstOrCreate($ownerData); - + return $bankStatementTransaction->owners()->firstOrCreate($ownerData); } + private function editAccountMapped(StatementTransactionOwner $owner){ + $this->updateOwnerStatus($owner, ApprovalStatus::APPROVED); + + // update all other owners with the same system, owner type, and owner ID + $this->updateOtherOwners($owner, ApprovalStatus::REJECTED); + } + + private function updateOwnerStatus(StatementTransactionOwner $owner, int $status) + { + $this->updatesBankStatementTransactionOwnerStatus->execute($owner, $status); + } + + private function updateOtherOwners(StatementTransactionOwner $owner, int $status): void + { + StatementTransactionOwner::where('statement_transaction_id', $owner->statement_transaction_id) + ->where('id', '!=', $owner->id) + ->update(['status' => $status]); + } } diff --git a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue index b3d50d7b..5d1341b1 100644 --- a/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue +++ b/resources/assets/vue/components/accounting/elements/EditSingleItemInListComponent.vue @@ -77,6 +77,13 @@ import { required } from "vuelidate/lib/validators"; export default { + props:{ + editMapped: { + type: Boolean, + default: false, + required: false + } + }, data(){ return { error: '', @@ -116,6 +123,8 @@ system_references : this.system_references ? this.system_references.toLowerCase() : '', transaction_reference : this.transaction_reference }; + + if (this.editMapped) this.parameters['editMapped'] = true; this.submit(this.route('api.accounting.statement.details.update', this.data.id), 'put', this.section, true, true); }, diff --git a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue index 6014bb5d..1caef408 100644 --- a/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue +++ b/resources/assets/vue/components/accounting/elements/StatementTransactionComponent.vue @@ -21,6 +21,7 @@
{{item.owners.approved[0].reference}}
+ @@ -35,6 +36,15 @@ > + + + + + + +