add route preview-unfinished-payment-orders

This commit is contained in:
Edmond Lang
2025-07-25 14:55:55 +08:00
parent f60241eafc
commit ed317ed176
2 changed files with 14 additions and 5 deletions
@@ -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');
}
}
+4 -5
View File
@@ -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 '<br><br>';
$cutOffDate = Carbon::parse($cutOffDate);
}
echo '<table style="border-collapse: collapse; width: 100%;" border="1">';
@@ -1389,9 +1391,6 @@ Route::get('/preview-unfinished-payment-orders', function (Request $request) {
<th>Order Created Date</th>
</tr></thead>';
echo '<tbody>';
$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) {