diff --git a/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php new file mode 100644 index 00000000..8e67f4ec --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/UpdateBookingAmountLogic.php @@ -0,0 +1,90 @@ + 'Updated Booking', + 'message' => 'You have successfully updated the Booking' + ]; + } + + /** @var CanUpdateBooking */ + private $canUpdateBooking; + + /** @var UpdatesBookingFixedAmount */ + private $updatesBookingFixedAmount; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var CalculatesBookingOutstanding */ + private $calculatesBookingOutstanding; + + /** + * UpdateBookingAmountLogic constructor. + * @param CanUpdateBooking $canUpdateBooking + * @param UpdatesBookingFixedAmount $updatesBookingFixedAmount + * @param FetchesBooking $fetchesBooking + * @param CalculatesBookingOutstanding $calculatesBookingOutstanding + */ + public function __construct( + CanUpdateBooking $canUpdateBooking, + UpdatesBookingFixedAmount $updatesBookingFixedAmount, + FetchesBooking $fetchesBooking, + CalculatesBookingOutstanding $calculatesBookingOutstanding + ) + { + $this->canUpdateBooking = $canUpdateBooking; + $this->updatesBookingFixedAmount = $updatesBookingFixedAmount; + $this->fetchesBooking = $fetchesBooking; + $this->calculatesBookingOutstanding = $calculatesBookingOutstanding; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws ErrorException + */ + public function logic(Request $request) : JsonResponse + { + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $input_amount = number_format( floatval(str_replace(',', '', $request->input('fix_amount', $booking->fix_amount))), 5, '.', ''); + + $minimum_amount = $booking->fix_amount - $this->calculatesBookingOutstanding->execute($booking); + + if ((float)$input_amount < $minimum_amount) { + throw new MalformedRequestException('Booking Amount cannot be less than '. $minimum_amount .'.'); + } + + // $this->canUpdateBooking->passes($booking); + $booking = $this->updatesBookingFixedAmount->execute($booking, $input_amount); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/UpdatesBooking.php b/app/Classes/Modules/Bookings/Services/UpdatesBooking.php index 37ca5b7c..2c0ec871 100644 --- a/app/Classes/Modules/Bookings/Services/UpdatesBooking.php +++ b/app/Classes/Modules/Bookings/Services/UpdatesBooking.php @@ -17,8 +17,8 @@ class UpdatesBooking extends AbstractUpdateRecord */ public function execute(Booking $model, BookingObject $object) { - $model->transferable_bank_id = $object->getTransferableBankId(); - $model->reference = $object->getReference(); + $model->bank_id = $object->getTransferableBankId(); + $model->marking = $object->getMarking(); $model->fix_amount = $object->getFixAmount(); $model->fix_currency_id = $object->getFixCurrencyId(); $model->convertible_currency_id = $object->getConvertibleCurrencyId(); diff --git a/app/Classes/Modules/Bookings/Services/UpdatesBookingFixedAmount.php b/app/Classes/Modules/Bookings/Services/UpdatesBookingFixedAmount.php new file mode 100644 index 00000000..83779bc6 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/UpdatesBookingFixedAmount.php @@ -0,0 +1,23 @@ +fix_amount = $fixedAmount; + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/UpdateBookingAmountController.php b/app/Http/Controllers/Bookings/UpdateBookingAmountController.php new file mode 100644 index 00000000..d0f6dd6c --- /dev/null +++ b/app/Http/Controllers/Bookings/UpdateBookingAmountController.php @@ -0,0 +1,20 @@ +execute($request); + } + +} \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue index 524826ba..f344c8cb 100644 --- a/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue +++ b/resources/assets/vue/components/bookings/forms/BookingPaymentQuotationComponent.vue @@ -73,7 +73,7 @@