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 '
| Order Created Date | '; 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) {
|---|