From 13ba4e5c1254ffe1e335c9a3af67a9eb09353584 Mon Sep 17 00:00:00 2001 From: Dillon Date: Fri, 20 Jan 2023 01:23:03 +0800 Subject: [PATCH 1/5] Edit book recipient bank details --- .../UpdateBookingRecipientLogic.php | 94 ++++++++++++ .../UpdateBookingRecipientController.php | 20 +++ .../banks/forms/BankAccountFormComponent.vue | 25 +++- .../banks/forms/PhoneAccountFormComponent.vue | 27 +++- .../BookingRecipientEditComponent.vue | 141 ++++++++++++++++++ .../BookingPaymentQuotationComponent.vue | 33 +++- .../bookings/forms/UpdateBookingComponent.vue | 41 +++++ routes/booking.php | 3 +- 8 files changed, 371 insertions(+), 13 deletions(-) create mode 100644 app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingRecipientLogic.php create mode 100644 app/Http/Controllers/Bookings/UpdateBookingRecipientController.php create mode 100644 resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue diff --git a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingRecipientLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingRecipientLogic.php new file mode 100644 index 00000000..8bdee9e3 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingRecipientLogic.php @@ -0,0 +1,94 @@ + 'Updated Booking', + 'message' => 'You have successfully updated the Booking' + ]; + } + + /** @var CanUpdateBooking */ + private $canUpdateBooking; + + /** @var UpdatesBooking */ + private $updatesBooking; + + /** @var FetchesBooking */ + private $fetchesBooking; + + + /** + * UpdateBookingRecipientLogic constructor. + * @param CanUpdateBooking $canUpdateBooking + * @param UpdatesBooking $updatesBooking + * @param FetchesBooking $fetchesBooking + */ + public function __construct( + CanUpdateBooking $canUpdateBooking, + UpdatesBooking $updatesBooking, + FetchesBooking $fetchesBooking + ) + { + $this->canUpdateBooking = $canUpdateBooking; + $this->updatesBooking = $updatesBooking; + $this->fetchesBooking = $fetchesBooking; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + try { + DB::beginTransaction(); + + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + + $booking_object = new BookingObject( + $booking->service_id, + $request->input('transferable_bank_id', $booking->transferable_bank_id), + $booking->marking, + $booking->fix_amount, + $booking->fix_currency_id, + $booking->convertible_currency_id, + $booking->conversion_currency_id + ); + $this->canUpdateBooking->passes($booking_object); + $booking = $this->updatesBooking->execute($booking, $booking_object); + + DB::commit(); + + return $this->resourceResponse(new BookingResource($booking)); + + } catch (\Exception $exception){ + throw new ErrorException($exception->getMessage(), $exception->getCode()); + } + } + +} diff --git a/app/Http/Controllers/Bookings/UpdateBookingRecipientController.php b/app/Http/Controllers/Bookings/UpdateBookingRecipientController.php new file mode 100644 index 00000000..670db6da --- /dev/null +++ b/app/Http/Controllers/Bookings/UpdateBookingRecipientController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} diff --git a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue index 6e9518d9..e1fd6f0d 100644 --- a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue @@ -136,9 +136,12 @@
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
-
+
Add Account
+
+
Update Details
+
@@ -179,6 +182,10 @@ type: String, required: false, default: 'RMB' + }, + isEditing: { + type: Boolean, + default: false } }, data(){ @@ -224,10 +231,22 @@ }, methods: { submitForm(){ - this.submit(route('api.bank.create'), 'post', this.section, true, false); + if(this.isEditing){ + this.parameters.company_id = this.company_id; + this.parameters.account_type = this.type; + this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); + } + else{ + this.submit(route('api.bank.create'), 'post', this.section, true, false); + } }, successHandler(response){ - this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); + if(this.isEditing){ + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + } + else{ + this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); + } this.formHandler(); this.resetForm(); }, diff --git a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue index 76401d2b..aea24179 100644 --- a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue @@ -42,9 +42,12 @@
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
-
+
+
+ +
@@ -80,6 +83,10 @@ type: Object, required: false, default: null + }, + isEditing: { + type: Boolean, + default: false } }, data(){ @@ -115,10 +122,22 @@ submitForm(){ this.parameters.account_type = 3; this.parameters.bank_name = '-'; - this.submit(route('api.bank.create'), 'post', this.section, true, false); + if(this.isEditing){ + this.parameters.company_id = this.company_id; + this.parameters.account_type = this.type; + this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); + } + else{ + this.submit(route('api.bank.create'), 'post', this.section, true, false); + } }, successHandler(response){ - this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); + if(this.isEditing){ + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + } + else{ + this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); + } this.formHandler(); this.resetForm(); }, @@ -140,4 +159,4 @@ mixins: [FormHandler] } - \ No newline at end of file + diff --git a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue new file mode 100644 index 00000000..ffdbece2 --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue @@ -0,0 +1,141 @@ + + + diff --git a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue index 37a51a43..e2f5dfad 100644 --- a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue +++ b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue @@ -81,6 +81,14 @@ +
+
+
EDIT
+
+ + + +
@@ -540,12 +548,26 @@ id: '', status: false }, - onlinePayment: { + onlinePayment: { id: '', status: false }, amount: (Math.round((this.data.outstanding_amount + Number.EPSILON) * 100) / 100).toFixed(2), - calculation: null + calculation: null, + recipientBanks: { + company: this.data.company, + serviceType: { + status: false, + id: this.data.service.id, + name: this.data.service.name, + currencies: this.data.service.configurations.currencies, + selectedCurrency: this.data.service.configurations.currencies[0] + }, + bankAccount: this.data.bank, + bankAccountDefault: this.data.bank, + recipientBanks: this.data.company.recipient_banks.accounts, + bookingId: this.data.id + } } }, validations () { @@ -575,14 +597,12 @@ id: bankCode, status: true, } - }, submitForm(){ this.parameters = { payment_method: this.paymentMethod.id, amount: this.amount }; - this.submit(route('api.booking.payment.quotation', this.item.id), 'post', this.section, false, false) this.calculation = null; }, @@ -600,9 +620,12 @@ cancelQuotation(){ this.calculation = null; this.expandPayment = false; + }, + updatedBankDetails(bank){ + this.item.bank = bank; } }, mixins: [componentHandler], directives: {money: VMoney} } - \ No newline at end of file + diff --git a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue new file mode 100644 index 00000000..73d6d51f --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue @@ -0,0 +1,41 @@ + + + diff --git a/routes/booking.php b/routes/booking.php index 0cbeca76..e54ba278 100644 --- a/routes/booking.php +++ b/routes/booking.php @@ -7,6 +7,7 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::get('/list', 'ListBookingsController@list')->name('list'); Route::post('/create', 'CreateBookingController@create')->name('create'); Route::put('/update/{id}', 'UpdateBookingController@update')->name('update'); + Route::put('/recipient/update/{id}', 'UpdateBookingRecipientController@update')->name('update.recipient'); Route::put('/cancel/{id}', 'CancelBookingController@cancel')->name('cancel'); Route::put('/restore/{id}', 'RestoreBookingController@restore')->name('restore'); Route::delete('/delete/{id}', 'DeleteBookingController@delete')->name('delete'); @@ -33,4 +34,4 @@ Route::group(['prefix' => 'booking', 'as' => 'booking.', 'namespace' => 'Booking Route::post('{id}/proforma/create', 'CreateProformaInvoiceTransaction@create')->name('proforma.create'); -}); \ No newline at end of file +}); From 0b37cf6e7275c5f5d18f4e8d51715b1b976a92f7 Mon Sep 17 00:00:00 2001 From: Dillon Date: Fri, 20 Jan 2023 23:47:22 +0800 Subject: [PATCH 2/5] Edit recipient details do not allow empty --- .../bookings/elements/BookingRecipientEditComponent.vue | 1 + .../vue/components/bookings/forms/UpdateBookingComponent.vue | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue index ffdbece2..6240b629 100644 --- a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue @@ -129,6 +129,7 @@ this.createBank = false; this.isEditing = false; this.account_no = ''; + this.parameters.bankAccount = {}; }, cancelUpdate(){ this.parameters.bankAccount = this.parameters.bankAccountDefault; diff --git a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue index 73d6d51f..16cae41c 100644 --- a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue +++ b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue @@ -3,7 +3,7 @@
-
+
From 3bd708ed0e9e297635354f9289977f6041e8eb2e Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 7 Aug 2024 06:46:17 +0800 Subject: [PATCH 3/5] Recipient Bank Details to follow payment overriding the default attached to Booking --- app/Classes/Jobs/UpdatePerfexCRMPrelude.php | 6 +- .../Accounts/Services/DeletesKeyValuePair.php | 19 ++ .../ControllersLogic/UpdateBankLogic.php | 40 ++-- .../UpdateBankMetadataLogic.php | 67 ++++++ .../BankMetadataObject.php | 29 +++ .../Banks/Processors/UpdateBankProcessor.php | 97 +++++++++ .../Banks/Services/CreatesOrUpdateBank.php | 44 ++++ .../Standards/Rules/CanUpdateBankMetadata.php | 66 ++++++ .../Validators/BankMetadataValidation.php | 38 ++++ .../ExportsAnalyticBillingTransactions.php | 8 +- .../Banks/UpdateBankMetadataController.php | 19 ++ app/Http/Resources/CompanyResource.php | 2 +- .../Resources/ListTransactionJobResource.php | 14 +- .../Resources/PaymentTransactionResource.php | 14 +- app/Http/Resources/TransactionResource.php | 17 +- app/Http/Resources/V2/CompanyV2Resource.php | 2 +- app/Models/Bank.php | 35 ++- app/Models/KeyValuePair.php | 6 +- app/Models/Transaction.php | 24 +- ...ted_by_and_creator_type_to_banks_table.php | 35 +++ ...2359_add_deleted_at_to_key_value_pairs.php | 32 +++ .../seeds/AdminUserPermissionsTableSeeder.php | 1 + .../banks/forms/BankAccountFormComponent.vue | 20 +- .../banks/forms/PhoneAccountFormComponent.vue | 20 +- .../BookingPaymentRecipientEditComponent.vue | 177 +++++++++++++++ .../BookingRecipientEditComponent.vue | 44 +++- .../BookingPaymentQuotationComponent.vue | 67 +++--- ...itPaymentRecipientBankDetailsComponent.vue | 205 ++++++++++++++++++ .../forms/RecipientBankDetailsComponent.vue | 83 +++++++ .../bookings/forms/UpdateBookingComponent.vue | 2 +- .../GeneralConfirmationFormComponent.vue | 2 +- .../pdfs/currency_vendor_order.blade.php | 16 +- .../currency_vendor_order_inner.blade.php | 10 +- routes/api.php | 4 +- routes/bank.php | 4 +- routes/web.php | 40 ++-- 36 files changed, 1193 insertions(+), 116 deletions(-) create mode 100644 app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php create mode 100644 app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php create mode 100644 app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php create mode 100644 app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php create mode 100644 app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php create mode 100644 app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php create mode 100644 app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php create mode 100644 app/Http/Controllers/Banks/UpdateBankMetadataController.php create mode 100644 database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php create mode 100644 database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php create mode 100644 resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/EditPaymentRecipientBankDetailsComponent.vue create mode 100644 resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue diff --git a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php index 3b05ac63..1bf9dede 100644 --- a/app/Classes/Jobs/UpdatePerfexCRMPrelude.php +++ b/app/Classes/Jobs/UpdatePerfexCRMPrelude.php @@ -41,7 +41,11 @@ class UpdatePerfexCRMPrelude implements ShouldQueue { $serviceTypeName = $this->transaction->owner->company->services()->where('id', $this->transaction->owner->service_id)->first()->name; $booking = $this->transaction->booking; - $bankDetails = $this->generateBankDetails($booking->bank); + $bank = $booking->bank; //cief todo: 66 + if($this->transaction->bank){ + $bank = $this->transaction->bank; + } + $bankDetails = $this->generateBankDetails($bank); $data = [ 'amount' => number_format($this->transaction->amount, 2, '.', ''), diff --git a/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php b/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php new file mode 100644 index 00000000..a52288af --- /dev/null +++ b/app/Classes/Modules/Accounts/Services/DeletesKeyValuePair.php @@ -0,0 +1,19 @@ +handler($model); + } +} diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php index 8509ed6b..88172f47 100644 --- a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankLogic.php @@ -3,21 +3,17 @@ namespace App\Classes\Modules\Banks\ControllersLogic; use App\Http\Resources\BankResource; - use App\Classes\General\Abstracts\AbstractControllerLogic; - use App\Classes\Modules\Banks\Services\FetchesBank; - use App\Classes\Modules\Banks\Standards\Rules\CanUpdateBank; use App\Classes\Modules\Banks\Services\UpdatesBank; +use App\Classes\Modules\Banks\Services\CreatesOrUpdateBank; use App\Classes\Modules\Banks\Services\CreatesBankLog; - +use App\Classes\Modules\Banks\Processors\UpdateBankProcessor; use App\Classes\Modules\Banks\DataTransferObjects\BankObject; - -use ErrorException; use Illuminate\Http\JsonResponse; use Illuminate\Http\Request; -use Illuminate\Support\Facades\DB; + class UpdateBankLogic extends AbstractControllerLogic { @@ -44,24 +40,36 @@ class UpdateBankLogic extends AbstractControllerLogic /** @var CreatesBankLog */ private $createsBankLog; + /** @var CreatesOrUpdateBank */ + private $createsOrUpdateBank; + + /** @var UpdateBankProcessor */ + private $updateBankProcessor; + /** * UpdateBankLogic constructor. * @param CanUpdateBank $canUpdateBank * @param UpdatesBank $updatesBank * @param FetchesBank $fetchesBank * @param CreatesBankLog $createsBankLog + * @param CreatesOrUpdateBank $createsOrUpdateBank + * @param UpdateBankProcessor $updateBankProcessor */ public function __construct( CanUpdateBank $canUpdateBank, UpdatesBank $updatesBank, FetchesBank $fetchesBank, - CreatesBankLog $createsBankLog + CreatesBankLog $createsBankLog, + CreatesOrUpdateBank $createsOrUpdateBank, + UpdateBankProcessor $updateBankProcessor ) { $this->canUpdateBank = $canUpdateBank; $this->updatesBank = $updatesBank; $this->fetchesBank = $fetchesBank; $this->createsBankLog = $createsBankLog; + $this->createsOrUpdateBank = $createsOrUpdateBank; + $this->updateBankProcessor = $updateBankProcessor; } /** @@ -74,15 +82,15 @@ class UpdateBankLogic extends AbstractControllerLogic public function logic(Request $request) : JsonResponse { $bankObject = new BankObject( - $request->input('company_id'), + $request->input('company_id'), $request->input('account_type'), $request->input('bank_name'), - $request->input('holder_name'), + $request->input('holder_name'), $request->input('account_no'), - $request->input('bank_branch'), - $request->input('swift'), + $request->input('bank_branch'), + $request->input('swift'), $request->input('snap'), - $request->input('country_id'), + $request->input('country_id'), $request->input('reference') ); @@ -90,12 +98,10 @@ class UpdateBankLogic extends AbstractControllerLogic $this->canUpdateBank->passes($bankObject); - $bank_query = $this->updatesBank->execute($bank, $bankObject); - -// $bankLog = $this->createsBankLog->execute($bank_query); + $bank_query = $this->updateBankProcessor->execute($bankObject, $bank, $request->input('bill_no') ?? '', (int) $request->input('transaction_id') ?? 0 ); return $this->resourceResponse(new BankResource($bank_query)); } -} \ No newline at end of file +} diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php new file mode 100644 index 00000000..1dc79f1a --- /dev/null +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php @@ -0,0 +1,67 @@ + 'Update Bank Metadata', + 'message' => 'You have successfully updated the Bank metadata' + ]; + } + + /** @var CanUpdateBankMetadata */ + private $canUpdateBankMetadata; + + /** @var FetchesTransaction */ + private $fetchesTransaction; + + /** + * UpdateBankMetadataLogic constructor. + * @param CanUpdateBankMetadata $canUpdateBankMetadata + * @param FetchesTransaction $fetchesTransaction + */ + public function __construct( + CanUpdateBankMetadata $canUpdateBankMetadata, + FetchesTransaction $fetchesTransaction + ) + { + $this->canUpdateBankMetadata = $canUpdateBankMetadata; + $this->fetchesTransaction = $fetchesTransaction; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\AccessForbiddenException + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\RequestValidationException + */ + public function logic(Request $request) : JsonResponse + { + $bankMetadataObject = new BankMetadataObject( + $request->input('transactionId'), + ); + + $this->canUpdateBankMetadata->passes($bankMetadataObject); + + $transaction = $this->fetchesTransaction->execute(['id' => $request->input('transactionId')]); + $transaction->attributes()->delete(); + + return $this->response([]); + } + +} diff --git a/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php b/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php new file mode 100644 index 00000000..dae7a61e --- /dev/null +++ b/app/Classes/Modules/Banks/DataTransferObjects/BankMetadataObject.php @@ -0,0 +1,29 @@ +transaction_id = $transaction_id; + } + + /** + * @return int + */ + public function getTransactionId(): int + { + return $this->transaction_id; + } +} diff --git a/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php new file mode 100644 index 00000000..a646cb95 --- /dev/null +++ b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php @@ -0,0 +1,97 @@ +updatesBank = $updatesBank; + $this->createsOrUpdateBank = $createsOrUpdateBank; + $this->createsKeyValuePair = $createsKeyValuePair; + $this->fetchesTransaction = $fetchesTransaction; + } + + /** + * @param BankObject $bankObject + * @param Bank $bank + * @param string $billNo + * @param int $transactionId + * @return Model + * @throws \App\Classes\Exceptions\MalformedRequestException + * @throws \App\Classes\Exceptions\JobResourceNotFoundException + */ + public function execute(BankObject $bankObject, Bank $bank, string $billNo, int $transactionId) { + $result = null; + if($billNo && $transactionId){ + $transaction = $this->fetchesTransaction->execute(['id' => $transactionId]); + //If payment transaction do not have a bank yet, create one + if(!$transaction->bank){ + $result = $this->createsOrUpdateBank->execute($bankObject); + + // if ($result->wasRecentlyCreated) { + //Key #1 for Bank + $kvp = $bank->attributes()->where('key', 'App\Models\Bank')->where('value', $result->id)->latest()->first(); + if(!$kvp){ + $keyValuePairObject = new KeyValuePairObject( + "App\Models\Bank", + $result->id + ); + $this->createsKeyValuePair->execute($bank, $keyValuePairObject); + } + + //Key #2 for Payment Transaction (owner type: booking) + $keyValuePairObject = new KeyValuePairObject( + "App\Models\Bank", + $result->id + ); + $this->createsKeyValuePair->execute($transaction, $keyValuePairObject); + // } + + } + else{ + $result = $this->updatesBank->execute($transaction->bank, $bankObject); + } + } + else{ + $result = $this->updatesBank->execute($bank, $bankObject); + } + + return $result; + } +} diff --git a/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php b/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php new file mode 100644 index 00000000..1c582229 --- /dev/null +++ b/app/Classes/Modules/Banks/Services/CreatesOrUpdateBank.php @@ -0,0 +1,44 @@ + $object->getCompanyId(), + 'account_no' => $object->getAccountNo(), + 'reference' => $object->getReference(), + 'bank_name' => $object->getBankName(), + 'holder_name' => $object->getHolderName(), + 'bank_branch' => $object->getBankBranch(), + 'type' => $object->getType(), + 'country_id' => $object->getCountryId(), + 'created_by' => Auth::id(), + 'creator_type' => in_array($user->type, RoleTypes::ADMIN_ROLES) ? RoleTypes::ADMIN : RoleTypes::USER, + ]; + + $values = [ + 'swift' => $object->getSwift(), + 'snap' => $object->getSnap(), + ]; + + $model = Bank::updateOrCreate($attributes, $values); //Bank::firstOrCreate($attributes, $values); + + return $model; + } +} diff --git a/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php new file mode 100644 index 00000000..7d4de3aa --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php @@ -0,0 +1,66 @@ +validation = $validation; + } + + /** + * @return bool + */ + protected function authorized(): bool + { + //cief todo: 66 - temporary workaround + // if (!Auth::user()->can('update bank_metadata')) { + // return false; + // } + + // return true; + + if (in_array(Auth::user()->type, RoleTypes::ADMIN_ROLES)) { + return true; + } + + return false; + } + + /** + * @param BankMetadataObject $object + * @return bool + * @throws \App\Classes\Exceptions\RequestValidationException + */ + protected function validators($object): bool + { + return $this->validation->validate($object); + } + + /** + * @param BankMetadataObject $object + * @return bool + */ + protected function criteria($object): bool + { + return true; + } + +} diff --git a/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php b/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php new file mode 100644 index 00000000..37e134c4 --- /dev/null +++ b/app/Classes/Modules/Banks/Standards/Validators/BankMetadataValidation.php @@ -0,0 +1,38 @@ + $object->getTransactionId(), + ]; + } + + /** + * @return array + */ + protected function rules(): array + { + return [ + 'transaction_id' => 'required', + ]; + } + + /** + * @return array + */ + protected function messages(): array + { + return []; + } +} diff --git a/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php b/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php index af4c88c4..d368574f 100644 --- a/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsAnalyticBillingTransactions.php @@ -65,8 +65,12 @@ class ExportsAnalyticBillingTransactions implements FromCollection, WithHeadings $bill = $transaction; $payment = $transaction->owner; $booking = $payment->owner; + $bank = $booking->bank; //cief todo: 66 + if($payment->bank){ + $bank = $payment->bank; + } $company = $booking->company; - $ecommerce = str::contains($booking->bank->bank_name, ['浙江网商银行']); + $ecommerce = str::contains($bank->bank_name, ['浙江网商银行']); return [ $booking->id, @@ -88,4 +92,4 @@ class ExportsAnalyticBillingTransactions implements FromCollection, WithHeadings $bill->created_at ]; } -} \ No newline at end of file +} diff --git a/app/Http/Controllers/Banks/UpdateBankMetadataController.php b/app/Http/Controllers/Banks/UpdateBankMetadataController.php new file mode 100644 index 00000000..3b89c1ff --- /dev/null +++ b/app/Http/Controllers/Banks/UpdateBankMetadataController.php @@ -0,0 +1,19 @@ +execute($request); + } +} diff --git a/app/Http/Resources/CompanyResource.php b/app/Http/Resources/CompanyResource.php index a8103e8b..82b4cf3e 100644 --- a/app/Http/Resources/CompanyResource.php +++ b/app/Http/Resources/CompanyResource.php @@ -56,7 +56,7 @@ class CompanyResource extends JsonResource 'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments', 'personal_banks' => BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), 'recipient_banks' => [ - 'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])), + 'accounts' => BankResource::collection($this->banks->whereIn('type', [BankAccountType::EXTERNAL, BankAccountType::ALIPAY_1688, BankAccountType::ALIPAY_RECIPIENT])->whereIn('creator_type', [null])), 'default' => new BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => SegmentResource::collection($this->segments), diff --git a/app/Http/Resources/ListTransactionJobResource.php b/app/Http/Resources/ListTransactionJobResource.php index 6c4c0ece..b8908ee6 100644 --- a/app/Http/Resources/ListTransactionJobResource.php +++ b/app/Http/Resources/ListTransactionJobResource.php @@ -16,8 +16,16 @@ class ListTransactionJobResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank ?? $booking->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank ?? $booking->bank; + } $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ @@ -27,7 +35,7 @@ class ListTransactionJobResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, diff --git a/app/Http/Resources/PaymentTransactionResource.php b/app/Http/Resources/PaymentTransactionResource.php index 456ece3d..d0549c38 100644 --- a/app/Http/Resources/PaymentTransactionResource.php +++ b/app/Http/Resources/PaymentTransactionResource.php @@ -18,8 +18,16 @@ class PaymentTransactionResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank ?? $booking->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank ?? $booking->bank; + } $booking_marking = ''; switch ($this->owner_type) { @@ -38,7 +46,7 @@ class PaymentTransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) $this->amount, diff --git a/app/Http/Resources/TransactionResource.php b/app/Http/Resources/TransactionResource.php index d259d777..f8620f05 100644 --- a/app/Http/Resources/TransactionResource.php +++ b/app/Http/Resources/TransactionResource.php @@ -19,8 +19,16 @@ class TransactionResource extends JsonResource */ public function toArray($request) { - - $booking = in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND, TransactionType::SUPPLIER_REFUND])? $this->owner->owner : $this->owner; + $booking = null; //cief todo: 66 + $bank = null; + if(in_array((int)$this->type, [TransactionType::BILL, TransactionType::REFUND, TransactionType::SUPPLIER_REFUND])){ + $booking = $this->owner->owner; + $bank = $this->owner->bank; + } + else{ + $booking = $this->owner; + $bank = $this->bank; + } $days = $this->created_at->endOfDay()->addWeekdays($booking->service_id === 3 ? 3 : 1); return [ @@ -30,7 +38,7 @@ class TransactionResource extends JsonResource 'bill_no' => $this->bill_no, 'payment_reference' => $this->payment_reference, 'payment_method' => (float) $this->payment_method, - 'recipient_bank_account' => new BankResource($booking->bank), + 'recipient_bank_account' => new BankResource($bank), 'issuer_name' => $this->issuerCompany->name, 'issuer_id' => $this->issuerCompany->id, 'amount' => (double) ($this->type === TransactionType::SUPPLIER_REFUND ? $this->amount - $this->transactions()->where('type', TransactionType::BILL_REFUND)->where('status', ApprovalStatus::APPROVED)->sum('amount') : $this->amount), @@ -54,7 +62,8 @@ class TransactionResource extends JsonResource 'duration' => $days->diff(Carbon::now())->format('%d'), ], 'remarks' => RemarkResource::collection($this->remarks), - 'redemption' => new VoucherRedemptionResource($this->voucherRedemption) + 'redemption' => new VoucherRedemptionResource($this->voucherRedemption), + 'bank' => ((int) $this->type === TransactionType::PAYMENT) ? new BankResource($bank) : null, //When a transaction (of type payment) has an override recipient bank details on booking, this is NOT null ]; } } diff --git a/app/Http/Resources/V2/CompanyV2Resource.php b/app/Http/Resources/V2/CompanyV2Resource.php index 64fca7c7..3f2cb4c2 100644 --- a/app/Http/Resources/V2/CompanyV2Resource.php +++ b/app/Http/Resources/V2/CompanyV2Resource.php @@ -82,7 +82,7 @@ class CompanyV2Resource extends JsonResource 'last_payment' => $lastPayment ? $lastPayment->created_at->diffForHumans() : 'No Payments', 'personal_banks' => V1\BankResource::collection($this->banks->where('type', BankAccountType::PERSONAL)), 'recipient_banks' => [ - 'accounts' => V1\BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)), + 'accounts' => V1\BankResource::collection($this->banks->where('type', BankAccountType::EXTERNAL)->whereIn('creator_type', [null])), 'default' => new V1\BankResource($this->banks->where('type', BankAccountType::EXTERNAL)->where('default', true)->first()) ], 'segments' => V1\SegmentResource::collection($this->segments), diff --git a/app/Models/Bank.php b/app/Models/Bank.php index 3b0bb915..30a429ae 100644 --- a/app/Models/Bank.php +++ b/app/Models/Bank.php @@ -7,6 +7,8 @@ use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\BelongsTo; +use Illuminate\Database\Eloquent\Relations\MorphMany; +use App\Classes\General\Interfaces\KeyValueInterface; /** * Class Bank @@ -21,10 +23,29 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; * @property int default * @property int status */ -class Bank extends AbstractModel +class Bank extends AbstractModel implements KeyValueInterface { use SoftDeletes; - + + /** + * + * @var array + */ + protected $fillable = [ + 'company_id', + 'reference', + 'bank_name', + 'holder_name', + 'account_no', + 'bank_branch', + 'swift', + 'snap', + 'type', + 'country_id', + 'created_by', + 'creator_type', + ]; + protected $table = 'banks'; /** @@ -42,7 +63,7 @@ class Bank extends AbstractModel { return $this->BelongsTo(Company::class, 'company_id', 'id'); } - + /** * @return HasMany */ @@ -50,4 +71,12 @@ class Bank extends AbstractModel { return $this->HasMany(Transaction::class, 'recipient_bank_account_id'); } + + /** + * @return MorphMany + */ + public function attributes(): MorphMany + { + return $this->morphMany(KeyValuePair::class, 'owner'); + } } diff --git a/app/Models/KeyValuePair.php b/app/Models/KeyValuePair.php index 3ad6d6cd..8f8ddec8 100644 --- a/app/Models/KeyValuePair.php +++ b/app/Models/KeyValuePair.php @@ -2,10 +2,14 @@ namespace App\Models; use Illuminate\Database\Eloquent\Relations\MorphTo; - +use Illuminate\Database\Eloquent\SoftDeletes; class KeyValuePair extends AbstractModel { + use SoftDeletes; + + protected $dates = ['deleted_at']; + protected $table = 'key_value_pairs'; public function owner(): MorphTo diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index 31b67e69..dc18faa1 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -3,6 +3,7 @@ namespace App\Models; use App\Classes\General\Interfaces\Documentable; +use App\Classes\General\Interfaces\KeyValueInterface; use App\Classes\General\Interfaces\Remarkable; use App\Classes\General\Interfaces\Transactionable; use App\Classes\General\Interfaces\Voucherifiable; @@ -22,7 +23,7 @@ use Staudenmeir\EloquentHasManyDeep\HasTableAlias; use App\Models\StatementTransactionOwner; -class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable, Remarkable +class Transaction extends AbstractModel implements Documentable, Transactionable, Voucherifiable, Remarkable, KeyValueInterface { use HasTableAlias; use SoftDeletes; @@ -268,4 +269,25 @@ class Transaction extends AbstractModel implements Documentable, Transactionable return $this->morphMany(Remark::class, 'owner'); } + /** + * @return MorphMany + */ + public function attributes(): MorphMany + { + return $this->morphMany(KeyValuePair::class, 'owner'); + } + + /** + * + * @return Model|null + */ + public function getBankAttribute() + { + $keyValuePairs = $this->attributes()->where('key', 'App\Models\Bank')->latest()->first(); + if($keyValuePairs){ + $bank = Bank::where('id', $keyValuePairs->value)->first(); + return $bank; + } + return null; + } } diff --git a/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php b/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php new file mode 100644 index 00000000..1d99906f --- /dev/null +++ b/database/migrations/2024_07_25_205651_add_created_by_and_creator_type_to_banks_table.php @@ -0,0 +1,35 @@ +unsignedBigInteger('created_by')->nullable()->after('country_id'); + $table->unsignedInteger('creator_type')->nullable()->after('created_by'); // 'admin' or 'customer', see RoleTypes.php for more + $table->foreign('created_by')->references('id')->on('users')->onDelete('set null'); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('banks', function (Blueprint $table) { + $table->dropForeign(['created_by']); + $table->dropColumn(['created_by', 'creator_type']); + }); + } +} diff --git a/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php b/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php new file mode 100644 index 00000000..df64b4a8 --- /dev/null +++ b/database/migrations/2024_07_31_212359_add_deleted_at_to_key_value_pairs.php @@ -0,0 +1,32 @@ +softDeletes(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('key_value_pairs', function (Blueprint $table) { + $table->dropSoftDeletes(); + }); + } +} diff --git a/database/seeds/AdminUserPermissionsTableSeeder.php b/database/seeds/AdminUserPermissionsTableSeeder.php index 0c3d5acf..c111ab6a 100644 --- a/database/seeds/AdminUserPermissionsTableSeeder.php +++ b/database/seeds/AdminUserPermissionsTableSeeder.php @@ -71,6 +71,7 @@ class AdminUserPermissionsTableSeeder extends Seeder ['name' => 'delete milestone', 'guard_name' => 'web'], ['name' => 'delete reward', 'guard_name' => 'web'], + ['name' => 'update bank_metadata', 'guard_name' => 'web'], ]; foreach ($permissions as $permission){ diff --git a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue index 80a3c94d..3bf4f46a 100644 --- a/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/BankAccountFormComponent.vue @@ -133,7 +133,7 @@
-
+
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
@@ -186,6 +186,18 @@ isEditing: { type: Boolean, default: false + }, + isCancelButtonHidden: { + type: Boolean, + default: false + }, + billNo: { + type: String, + default: '' + }, + transactionId: { + type: Number, + default: 0 } }, data(){ @@ -201,6 +213,8 @@ swift: '', snap: '', country_id: this.country_id, + bill_no: this.billNo, + transaction_id: this.transactionId, } } }, @@ -234,6 +248,8 @@ if(this.isEditing){ this.parameters.company_id = this.company_id; this.parameters.account_type = this.type; + this.parameters.bill_no = this.billNo; + this.parameters.transaction_id = this.transactionId; this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); } else{ @@ -242,7 +258,7 @@ }, successHandler(response){ if(this.isEditing){ - this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data, this.transactionId); } else{ this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); diff --git a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue index cf589b25..dde77e9c 100644 --- a/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue +++ b/resources/assets/vue/components/banks/forms/PhoneAccountFormComponent.vue @@ -39,7 +39,7 @@
-
+
{{disabled ? 'Change Recipient Account' : 'Cancel'}}
@@ -87,6 +87,18 @@ isEditing: { type: Boolean, default: false + }, + isCancelButtonHidden: { + type: Boolean, + default: false + }, + billNo: { + type: String, + default: '' + }, + transactionId: { + type: Number, + default: 0 } }, data(){ @@ -100,6 +112,8 @@ account_no: '', bank_branch: '', country_id: this.country_id, + bill_no: this.billNo, + transaction_id: this.transactionId, }, englishTextWarning: false, confirmProceedEnglishText: false, @@ -125,6 +139,8 @@ if(this.isEditing){ this.parameters.company_id = this.company_id; this.parameters.account_type = this.type; + this.parameters.bill_no = this.billNo; + this.parameters.transaction_id = this.transactionId; this.submit(route('api.bank.update', this.parameters.id), 'put', this.section, true, false); } else{ @@ -133,7 +149,7 @@ }, successHandler(response){ if(this.isEditing){ - this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data); + this.type !== 2 ? this.closeModal() : this.$emit('updatedBankDetails', response.payload.data, this.transactionId); } else{ this.type !== 2 ? this.closeModal() : this.$emit('createdBank', response.payload.data); diff --git a/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue new file mode 100644 index 00000000..12b673af --- /dev/null +++ b/resources/assets/vue/components/bookings/elements/BookingPaymentRecipientEditComponent.vue @@ -0,0 +1,177 @@ + + + + + diff --git a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue index 6240b629..8690d262 100644 --- a/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingRecipientEditComponent.vue @@ -3,9 +3,12 @@
-
-
-
Recipient Details
+
+
+
Edit Recipient Bank Details ({{ data.billNo }})
+
+
+
Edit Recipient Bank Details (Default)
@@ -64,8 +67,31 @@
- - + + + +
@@ -84,9 +110,9 @@ diff --git a/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue b/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue new file mode 100644 index 00000000..a58a6fd5 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/RecipientBankDetailsComponent.vue @@ -0,0 +1,83 @@ + + diff --git a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue index 16cae41c..1634e9d9 100644 --- a/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue +++ b/resources/assets/vue/components/bookings/forms/UpdateBookingComponent.vue @@ -4,7 +4,7 @@
- +
diff --git a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue index 0cb9435b..85526d4e 100644 --- a/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue +++ b/resources/assets/vue/components/general/forms/GeneralConfirmationFormComponent.vue @@ -33,7 +33,7 @@ required: true }, params: { - type: Array, + type: Object, required: false }, modalType: { diff --git a/resources/views/pages/pdfs/currency_vendor_order.blade.php b/resources/views/pages/pdfs/currency_vendor_order.blade.php index df445998..7638f5c5 100644 --- a/resources/views/pages/pdfs/currency_vendor_order.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order.blade.php @@ -46,12 +46,18 @@ {{$transaction->currency_rate}} {{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}} - Account Holder Name: {{$transaction->owner->owner->bank->holder_name}} -
{{$transaction->owner->owner->bank->bank_name}}: {{$transaction->owner->owner->bank->account_no}} -
Branch: {{$transaction->owner->owner->bank->bank_branch}} + @php + $bank = $transaction->owner->owner->bank; + if($transaction->owner->bank){ + $bank = $transaction->owner->bank; + } + @endphp + Account Holder Name: {{$bank->holder_name}} +
{{$bank->bank_name}}: {{$bank->account_no}} +
Branch: {{$bank->bank_branch}} @if($transaction->original_currency->short_code === 'USD') -
Account Holder Address: {{$transaction->owner->owner->bank->reference}} -
Swift Code: {{$transaction->owner->owner->bank->swift}} +
Account Holder Address: {{$bank->reference}} +
Swift Code: {{$bank->swift}} @endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} @if ($order_reference_no) diff --git a/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php b/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php index e477c538..2d0c486f 100644 --- a/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php +++ b/resources/views/pages/pdfs/currency_vendor_order_inner.blade.php @@ -19,12 +19,18 @@ @foreach($transactions as $transaction) + @php + $bank = $transaction->owner->owner->bank; + if($transaction->owner->bank){ + $bank = $transaction->owner->bank; + } + @endphp {{$transaction->owner->owner->marking}} {{$transaction->owner->owner->company->reference}} {{$transaction->currency_rate}} {{$transaction->currency->short_code}} {{number_format((float)$transaction->amount, 2, '.', '')}} - Account Holder Name: {{$transaction->owner->owner->bank->holder_name}}
{{$transaction->owner->owner->bank->bank_name}}: {{$transaction->owner->owner->bank->account_no}} -
Branch: {{$transaction->owner->owner->bank->bank_branch}}@if($transaction->original_currency->short_code === 'USD')
Swift Code: {{$transaction->owner->owner->bank->swift}}@endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} + Account Holder Name: {{$bank->holder_name}}
{{$bank->bank_name}}: {{$bank->account_no}} +
Branch: {{$bank->bank_branch}}@if($transaction->original_currency->short_code === 'USD')
Swift Code: {{$bank->swift}}@endif
Bank in Amount: {{$transaction->original_currency->short_code}} {{$transaction->original_amount}} @endforeach diff --git a/routes/api.php b/routes/api.php index 2d52b3ea..23adace3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -60,7 +60,7 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__ . '/wallet.php'; require __DIR__ . '/voucher.php'; - + require __DIR__ . '/accounting.php'; require __DIR__ . '/reward.php'; @@ -69,8 +69,6 @@ Route::group(['middleware' => 'api', 'prefix' => 'v1', 'as' => 'api.'], function require __DIR__.'/remark.php'; - // require __DIR__ . '/accounting.php'; //cief todo: To check if this is needed - require __DIR__ . '/job.php'; // require __DIR__ . '/rate.php'; diff --git a/routes/bank.php b/routes/bank.php index 03c719e6..b7c7e96e 100644 --- a/routes/bank.php +++ b/routes/bank.php @@ -10,4 +10,6 @@ Route::group(['prefix' => 'bank', 'as' => 'bank.', 'namespace' => 'Banks'], func Route::delete('/delete/{id}', 'DeleteBankController@delete')->name('delete'); Route::put('/update/{id}/status', 'UpdateBankStatusController@update')->name('status.update'); -}); \ No newline at end of file + + Route::post('/metadata/update/{id}', 'UpdateBankMetadataController@delete')->name('update.metadata'); +}); diff --git a/routes/web.php b/routes/web.php index a7c87263..23c4239e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -406,16 +406,18 @@ Route::get('/pending_orders', function(){ $i = 0; foreach ($payments as $payment){ $booking = $payment->owner; + $bank = $payment->bank ?? $booking->bank; //cief todo: 66 + $original_refunds = floatval((App()->make(CalculatesBookingRefundAmount::class))->calculateRefundAmount($payment, $booking->fix_currency_id)); $refunds = $original_refunds / $payment->currency_rate; if(!$booking instanceof Booking){ dd($payment); } - $bankType = str::length($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str::length($bank->holder_name) > 4 ? 'Company' : 'Personal'; - if (!preg_match('/[^A-Za-z0-9]/', $booking->bank->holder_name)) + if (!preg_match('/[^A-Za-z0-9]/', $bank->holder_name)) { - $bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str_word_count($bank->holder_name) > 4 ? 'Company' : 'Personal'; } echo ''; @@ -432,7 +434,7 @@ Route::get('/pending_orders', function(){ echo ''.$booking->service->name.''; echo ''.$payment->updated_at->diffForHumans().''; echo ''.$bankType.''; - echo ''.$booking->bank->holder_name.''; + echo ''.$bank->holder_name.''; echo ''; } echo ''; @@ -509,14 +511,16 @@ Route::get('/approve_refunds', function(Request $request){ foreach ($approve_refunds->orderBy('created_at', 'DESC')->get() as $index => $refund){ $payment = $refund->owner; $booking = $refund->owner->owner; + $bank = $payment->bank ?? $booking->bank; //cief todo: 66 + if(!$booking instanceof Booking){ dd($refund); } - $bankType = str::length($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str::length($bank->holder_name) > 4 ? 'Company' : 'Personal'; - if (!preg_match('/[^A-Za-z0-9]/', $booking->bank->holder_name)) + if (!preg_match('/[^A-Za-z0-9]/', $bank->holder_name)) { - $bankType = str_word_count($booking->bank->holder_name) > 4 ? 'Company' : 'Personal'; + $bankType = str_word_count($bank->holder_name) > 4 ? 'Company' : 'Personal'; } $remark = $refund->original_amount === $refund->owner->original_amount ? 'Fully Refund' : 'Partial Refund'; @@ -545,7 +549,7 @@ Route::get('/approve_refunds', function(Request $request){ echo ''.$booking->service->name.''; echo ''.$payment->updated_at->diffForHumans().''; echo ''.$bankType.''; - echo ''.$booking->bank->holder_name.''; + echo ''.$bank->holder_name.''; echo ''.$noteRemark.''; echo ''; } @@ -563,10 +567,12 @@ Route::get('/group/text/{id}', function($id){ foreach ($group->transactions as $transaction){ $i++; $booking = $transaction->owner->owner; + $bank = $transaction->owner->bank ?? $booking->bank; //cief todo: 66 + echo 'No.'.$i.'
'; - echo 'Bank Details:'.$booking->bank->holder_name.'
'; - echo $booking->bank->bank_name.' '.$booking->bank->bank_branch.'
'; - echo 'Bank Account Number:'.$booking->bank->account_no.'
'; + echo 'Bank Details:'.$bank->holder_name.'
'; + echo $bank->bank_name.' '.$bank->bank_branch.'
'; + echo 'Bank Account Number:'.$bank->account_no.'
'; echo 'Order Amount:'.$transaction->original_currency->short_code.' '.(round($transaction->original_amount, 2) + 0).'

'; } @@ -576,7 +582,7 @@ Route::get('/group/invoice/{id}', function ($id) { $group = Group::findOrFail($id); - $supplier = $group->issuerCompany; + $supplier = $group->issuerCompany; $transferFeeTransactions = $group->transactions() ->with(['transactions' => function ($transaction) { @@ -588,8 +594,8 @@ Route::get('/group/invoice/{id}', function ($id) { $html = view('pages.pdfs.supplier_deliver_order_group_invoice', [ 'group'=> $group, - 'transactions' => $group->transactions, - 'transferFeeTransactions' => $transferFeeTransactions, + 'transactions' => $group->transactions, + 'transferFeeTransactions' => $transferFeeTransactions, 'supplier' => $supplier ])->render(); @@ -597,7 +603,7 @@ Route::get('/group/invoice/{id}', function ($id) { $dompdf->loadHtml($html); $dompdf->setPaper('A4', 'portrait'); $dompdf->render(); - + return $dompdf->stream("invoice_pdf_{$supplier->name}.pdf"); })->name('group.invoice'); @@ -1167,7 +1173,7 @@ Route::get('check-duplicate-refunds', function () { foreach ($results as $result) { $booking_ref_arr = explode(' ', $result->payment_reference); $booking_ref = end($booking_ref_arr); - + echo ''; echo "$result->owner_type"; echo "$result->owner_id"; @@ -1204,7 +1210,7 @@ Route::get('check-duplicate-refunds', function () { echo "" . ($refund ? $refund : '') . ""; echo ''; - + } echo ''; echo ''; From 32833064b33d1eda60065d7b313a34ab2aa3b540 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 7 Aug 2024 06:56:49 +0800 Subject: [PATCH 4/5] Fix some breaking changes that is already deployed to master branch --- .../Banks/ControllersLogic/UpdateBankMetadataLogic.php | 2 +- app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php | 2 +- app/Models/Bank.php | 2 +- app/Models/Transaction.php | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php index 1dc79f1a..e73d051a 100644 --- a/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php +++ b/app/Classes/Modules/Banks/ControllersLogic/UpdateBankMetadataLogic.php @@ -59,7 +59,7 @@ class UpdateBankMetadataLogic extends AbstractControllerLogic $this->canUpdateBankMetadata->passes($bankMetadataObject); $transaction = $this->fetchesTransaction->execute(['id' => $request->input('transactionId')]); - $transaction->attributes()->delete(); + $transaction->attributesKVP()->delete(); return $this->response([]); } diff --git a/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php index a646cb95..6030c11d 100644 --- a/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php +++ b/app/Classes/Modules/Banks/Processors/UpdateBankProcessor.php @@ -66,7 +66,7 @@ class UpdateBankProcessor // if ($result->wasRecentlyCreated) { //Key #1 for Bank - $kvp = $bank->attributes()->where('key', 'App\Models\Bank')->where('value', $result->id)->latest()->first(); + $kvp = $bank->attributesKVP()->where('key', 'App\Models\Bank')->where('value', $result->id)->latest()->first(); if(!$kvp){ $keyValuePairObject = new KeyValuePairObject( "App\Models\Bank", diff --git a/app/Models/Bank.php b/app/Models/Bank.php index 30a429ae..42cdf3df 100644 --- a/app/Models/Bank.php +++ b/app/Models/Bank.php @@ -75,7 +75,7 @@ class Bank extends AbstractModel implements KeyValueInterface /** * @return MorphMany */ - public function attributes(): MorphMany + public function attributesKVP(): MorphMany { return $this->morphMany(KeyValuePair::class, 'owner'); } diff --git a/app/Models/Transaction.php b/app/Models/Transaction.php index dc18faa1..c84c0238 100644 --- a/app/Models/Transaction.php +++ b/app/Models/Transaction.php @@ -272,7 +272,7 @@ class Transaction extends AbstractModel implements Documentable, Transactionable /** * @return MorphMany */ - public function attributes(): MorphMany + public function attributesKVP(): MorphMany { return $this->morphMany(KeyValuePair::class, 'owner'); } @@ -283,7 +283,7 @@ class Transaction extends AbstractModel implements Documentable, Transactionable */ public function getBankAttribute() { - $keyValuePairs = $this->attributes()->where('key', 'App\Models\Bank')->latest()->first(); + $keyValuePairs = $this->attributesKVP()->where('key', 'App\Models\Bank')->latest()->first(); if($keyValuePairs){ $bank = Bank::where('id', $keyValuePairs->value)->first(); return $bank; From 039d8deeea2e0a8847780275c5fafc149ba28b72 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Wed, 7 Aug 2024 07:23:45 +0800 Subject: [PATCH 5/5] Fix some breaking changes that is already deployed to master branch --- .../Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php index 7d4de3aa..d102a763 100644 --- a/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php +++ b/app/Classes/Modules/Banks/Standards/Rules/CanUpdateBankMetadata.php @@ -28,7 +28,7 @@ class CanUpdateBankMetadata extends AbstractRule /** * @return bool */ - protected function authorized(): bool + protected function authorized($object): bool { //cief todo: 66 - temporary workaround // if (!Auth::user()->can('update bank_metadata')) {