diff --git a/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php new file mode 100644 index 00000000..0f91042c --- /dev/null +++ b/app/Classes/Modules/Transactions/ControllersLogic/UpdateGroupLogic.php @@ -0,0 +1,154 @@ + 'Update Group Transaction', + 'message' => 'You have successfully updated this Group Transaction' + ]; + } + + /** @var UpdatesTransactionStatus */ + private $updatesTransactionStatus; + + /** @var FetchesGroup */ + private $fetchesGroup; + + /** @var DeletesTransaction */ + private $deletesTransaction; + + /** @var FetchesCompany */ + private $fetchesCompany; + + /** @var CalculatesTransactionServiceCharge */ + private $calculatesTransactionServiceCharge; + + /** @var UpdatesTransaction */ + private $updatesTransaction; + + /** @var CalculatesTransactionTransferFee */ + private $calculatesTransactionTransferFee; + + public function __construct( + UpdatesTransactionStatus $updatesTransactionStatus, + FetchesGroup $fetchesGroup, + DeletesTransaction $deletesTransaction, + FetchesCompany $fetchesCompany, + CalculatesTransactionServiceCharge $calculatesTransactionServiceCharge, + UpdatesTransaction $updatesTransaction, + CalculatesTransactionTransferFee $calculatesTransactionTransferFee + ) + { + $this->updatesTransactionStatus = $updatesTransactionStatus; + $this->fetchesGroup = $fetchesGroup; + $this->deletesTransaction = $deletesTransaction; + $this->fetchesCompany = $fetchesCompany; + $this->calculatesTransactionServiceCharge = $calculatesTransactionServiceCharge; + $this->updatesTransaction = $updatesTransaction; + $this->calculatesTransactionTransferFee = $calculatesTransactionTransferFee; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $group = $this->fetchesGroup->execute(['id' => $request->route('id')]); + + $transactions = $group->transactions()->get(); + + $rate = $request->input('rate'); + + $supplier = $this->fetchesCompany->execute(['id' => $request->input('supplier_id')]); + + foreach($transactions as $transaction) { + + $constant = SegmentConstant::where('reference', SegmentConstants::SERVICE_CHARGE)->where('detail->id', $supplier->id)->first(); + $serviceCharge = $this->calculatesTransactionServiceCharge->execute($transaction->original_amount, $rate, $constant); + + $object = new TransactionObject( + $transaction->bill_no, + TransactionType::BILL, + $supplier->id, + 1, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount * (1 / $rate), + $transaction->original_amount, + 1, + $transaction->original_currency_id, + $rate, + 0, + $serviceCharge, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $billTransaction = $this->updatesTransaction->execute($transaction, $object); + + $transferTransaction = $transaction->transactions()->where('type', TransactionType::TRANSFER_FEE)->first(); + + $transferFee = $this->calculatesTransactionTransferFee->execute($billTransaction->amount, $constant); + + $object = new TransactionObject( + $transferTransaction->bill_no, + TransactionType::TRANSFER_FEE, + 1, + $supplier->id, + $supplier->banks()->where('default', true)->first()->id, + PaymentMethodType::CASH, + $transaction->original_amount, + $transaction->original_amount, + $transaction->original_currency_id, + $transaction->original_currency_id, + 1, + 0, + $transferFee, + null, + ApprovalStatus::PENDING_VERIFICATION + ); + + $this->updatesTransaction->execute($transferTransaction, $object); + } + + $group->issuer = $supplier; + $group->amount = $group->transactions()->sum('amount'); + $group->currency_rate = $rate; + $group->tax = $group->transactions()->sum('tax'); + $group->service_charge = $group->transactions()->sum('service_charge'); + + $group->save(); + + return $this->resourceResponse(new GroupResource($group)); + } + +} \ No newline at end of file diff --git a/app/Http/Controllers/Transactions/UpdateGroupController.php b/app/Http/Controllers/Transactions/UpdateGroupController.php new file mode 100644 index 00000000..db0b3a17 --- /dev/null +++ b/app/Http/Controllers/Transactions/UpdateGroupController.php @@ -0,0 +1,20 @@ +execute($request); + } +} diff --git a/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue b/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue index bad56836..51562c23 100644 --- a/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue +++ b/resources/assets/vue/components/bookings/elements/TransactionGroupComponent.vue @@ -38,7 +38,7 @@ - + diff --git a/resources/assets/vue/components/bookings/forms/EditTransactionGroupFormComponent.vue b/resources/assets/vue/components/bookings/forms/EditTransactionGroupFormComponent.vue index 17658ff5..299dc061 100644 --- a/resources/assets/vue/components/bookings/forms/EditTransactionGroupFormComponent.vue +++ b/resources/assets/vue/components/bookings/forms/EditTransactionGroupFormComponent.vue @@ -15,45 +15,17 @@ - - - - Supplier - {{selectedSupplier.name}} - - - - - - - - - - - - - - - - - - - {{supplier.name}} - - - - - - - - + + Supplier + + - + Purchase Rate - + @@ -62,7 +34,6 @@ Cancel - Update @@ -84,6 +55,10 @@ supplier_id: { type: Number, required: true + }, + id: { + type: Number, + required: true } }, data(){ @@ -95,37 +70,21 @@ name: '', status: false }, - email: '', - rate: (Math.round((this.currency_rate + Number.EPSILON) * 10000) / 10000).toFixed(5) + parameters: { + supplier_id: this.supplier_id, + rate: (Math.round((this.currency_rate + Number.EPSILON) * 10000) / 10000).toFixed(5) + }, } }, - created(){ - this.submit(route('api.company.list') + '?filters=' + JSON.stringify({'business_type': 3, 'status_in': [2, 0]}), 'get', 'pendingOrdersSection', false, false) - }, validations: { - email: { }, - rate: { }, + parameters: { + supplier_id: { }, + rate: { }, + }, }, methods: { - successHandler(response){ - var selected_supplier_id = this.supplier_id; - var selected_supplier = null; - this.suppliers = response.payload.data; - - this.suppliers.forEach(function(supplier) { - supplier.id === selected_supplier_id ? selected_supplier = supplier : ''; - }); - - this.selectedSupplier = selected_supplier; - this.selectedSupplier.status = false; - }, - updateSupplier(supplier){ - this.selectedSupplier = supplier; - this.selectedSupplier.status = false; - }, submitForm() { - console.log(this.rate); - console.log(this.selectedSupplier); + this.submit(route('api.transaction.group.update', this.id), 'put', this.section, true, true); } }, mixins: [ModalFormHandler] diff --git a/routes/transaction.php b/routes/transaction.php index cbff706d..9a820c11 100644 --- a/routes/transaction.php +++ b/routes/transaction.php @@ -23,6 +23,9 @@ Route::group(['prefix' => 'transactions', 'namespace' => 'Transactions', 'as' => Route::get('/bank/{id}/account/balance', 'FetchBankAccountBalanceController@fetch')->name('bank.account.balance'); - Route::get('/groups/list', 'ListGroupsController@list')->name('group.list'); - Route::delete('/groups/{id}/delete', 'DeleteGroupController@delete')->name('group.delete'); + Route::group(['prefix' => 'groups', 'as' => 'group.'], function () { + Route::get('/list', 'ListGroupsController@list')->name('list'); + Route::delete('/{id}/delete', 'DeleteGroupController@delete')->name('delete'); + Route::put('/{id}/update', 'UpdateGroupController@update')->name('update'); + }); }); \ No newline at end of file