diff --git a/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php new file mode 100644 index 00000000..29692a89 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/CancelBookingLogic.php @@ -0,0 +1,68 @@ + 'Cancel Booking', + 'message' => 'You have successfully canceled the Booking' + ]; + } + + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var CancelsBooking */ + private $cancelsBooking; + + /** + * CancelBookingLogic constructor. + * @param FetchesBooking $fetchesBooking + * @param CancelsBooking $cancelsBooking + */ + public function __construct(FetchesBooking $fetchesBooking, CancelsBooking $cancelsBooking) + { + $this->fetchesBooking = $fetchesBooking; + $this->cancelsBooking = $cancelsBooking; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $bookingActivePayments = $booking->transactions()->where('type', '=', TransactionType::PAYMENT)->where('status', '!=', ApprovalStatus::PENDING_SUBMISSION)->get(); + + if(count($bookingActivePayments)){ + throw new MalformedRequestException('You can\'t cancel an order with active payments'); + } + + $this->cancelsBooking->execute($booking); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php b/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php new file mode 100644 index 00000000..2ad8fa26 --- /dev/null +++ b/app/Classes/Modules/Bookings/ControllersLogic/RestoreBookingLogic.php @@ -0,0 +1,68 @@ + 'Restore Booking', + 'message' => 'You have successfully restored the Booking' + ]; + } + + /** @var CanDeleteBooking */ + private $canDeleteBooking; + + /** @var FetchesBooking */ + private $fetchesBooking; + + /** @var RestoresBooking */ + private $restoresBooking; + + /** + * RestoreBookingLogic constructor. + * @param CanDeleteBooking $canDeleteBooking + * @param FetchesBooking $fetchesBooking + * @param RestoresBooking $restoresBooking + */ + public function __construct(CanDeleteBooking $canDeleteBooking, FetchesBooking $fetchesBooking, RestoresBooking $restoresBooking) + { + $this->canDeleteBooking = $canDeleteBooking; + $this->fetchesBooking = $fetchesBooking; + $this->restoresBooking = $restoresBooking; + } + + /** + * @param Request $request + * @return JsonResponse + * @throws \App\Classes\Exceptions\MalformedRequestException + */ + public function logic(Request $request) : JsonResponse + { + $booking = $this->fetchesBooking->execute(['id' => $request->route('id')]); + + $this->restoresBooking->execute($booking); + + return $this->resourceResponse(new BookingResource($booking)); + } + +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/CancelsBooking.php b/app/Classes/Modules/Bookings/Services/CancelsBooking.php new file mode 100644 index 00000000..dd9b12f3 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/CancelsBooking.php @@ -0,0 +1,24 @@ +status = ApprovalStatus::SUSPENDED; + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Services/RestoresBooking.php b/app/Classes/Modules/Bookings/Services/RestoresBooking.php new file mode 100644 index 00000000..9efef208 --- /dev/null +++ b/app/Classes/Modules/Bookings/Services/RestoresBooking.php @@ -0,0 +1,24 @@ +status = ApprovalStatus::APPROVED; + + return $this->handler($model); + } +} \ No newline at end of file diff --git a/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php b/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php index 1b5acee4..dfd307bc 100644 --- a/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php +++ b/app/Classes/Modules/Bookings/Standards/Rules/CanDeleteBooking.php @@ -34,7 +34,7 @@ class CanDeleteBooking extends AbstractRule /** - * @param BookingObject $object + * @param $object * @return bool */ protected function criteria($object): bool diff --git a/app/Http/Controllers/Bookings/CancelBookingController.php b/app/Http/Controllers/Bookings/CancelBookingController.php new file mode 100644 index 00000000..f31a80a1 --- /dev/null +++ b/app/Http/Controllers/Bookings/CancelBookingController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/app/Http/Controllers/Bookings/RestoreBookingController.php b/app/Http/Controllers/Bookings/RestoreBookingController.php new file mode 100644 index 00000000..5b4aa809 --- /dev/null +++ b/app/Http/Controllers/Bookings/RestoreBookingController.php @@ -0,0 +1,19 @@ +execute($request); + } +} \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/elements/BookingComponent.vue b/resources/assets/vue/components/bookings/elements/BookingComponent.vue index febce6ba..509e9840 100644 --- a/resources/assets/vue/components/bookings/elements/BookingComponent.vue +++ b/resources/assets/vue/components/bookings/elements/BookingComponent.vue @@ -52,17 +52,26 @@ Pending... -
@@ -70,6 +79,11 @@ \ No newline at end of file diff --git a/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue b/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue new file mode 100644 index 00000000..b32275f1 --- /dev/null +++ b/resources/assets/vue/components/bookings/forms/CancelBookingFormComponent.vue @@ -0,0 +1,40 @@ + +