From ed317ed176b85c16aace71d4ee3b4802f67dddbd Mon Sep 17 00:00:00 2001 From: Edmond Lang Date: Fri, 25 Jul 2025 14:55:55 +0800 Subject: [PATCH] add route preview-unfinished-payment-orders --- .../Bookings/Services/CalculatesBookingPaidAmount.php | 10 ++++++++++ routes/web.php | 9 ++++----- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php index 42ce7589..d3f36916 100644 --- a/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php +++ b/app/Classes/Modules/Bookings/Services/CalculatesBookingPaidAmount.php @@ -15,4 +15,14 @@ class CalculatesBookingPaidAmount return $booking->transactions()->payments()->complete()->sum('original_amount'); } + public function executeUntilDate(Booking $booking, Carbon $cutOffDate = null){ + $amount = $booking->transactions()->payments()->complete(); + + if($cutOffDate){ + $amount->where('created_at', '<=', $cutOffDate); + } + + return $amount->sum('original_amount'); + } + } \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index 6f1184ce..521d91d1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1372,11 +1372,13 @@ Route::get('/maintenance', function () { }); Route::get('/preview-unfinished-payment-orders', function (Request $request) { - $cutOffDate = $request->cut_off_date; + $cutOffDate = $request->cut_off_date ?? null; if ($cutOffDate) { echo 'Cut Off Date: ' . $cutOffDate; echo '

'; + + $cutOffDate = Carbon::parse($cutOffDate); } echo ''; @@ -1389,9 +1391,6 @@ Route::get('/preview-unfinished-payment-orders', function (Request $request) { '; echo ''; - - $cutOffDate = Carbon::parse($cutOffDate); - $bookings = Booking::where('status', '<', ApprovalStatus::COMPLETED); if ($cutOffDate) { $bookings->where('created_at', '<=', $cutOffDate); @@ -1401,7 +1400,7 @@ Route::get('/preview-unfinished-payment-orders', function (Request $request) { $calculateBookingPaidAmount = new CalculatesBookingPaidAmount(); foreach ($bookings as $booking) { - $paid = $calculateBookingPaidAmount->execute($booking); + $paid = $calculateBookingPaidAmount->executeUntilDate($booking, $cutOffDate); $outstanding = $booking->fix_amount - $paid; if ($paid > 0 && $outstanding > 0) {
Order Created Date