diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceWithRefundReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceWithRefundReport.php index ad650adc..513e94e5 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceWithRefundReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceWithRefundReport.php @@ -59,12 +59,27 @@ class ExportsSalesInvoiceWithRefundReport implements FromQuery, WithHeadings, Wi Log::info('ExportsSalesInvoiceWithRefundReport startDate: ' . $startDate->format('Y-m-d H:i:s')); Log::info('ExportsSalesInvoiceWithRefundReport endDate: ' . $endDate->format('Y-m-d H:i:s')); - return Booking::whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED]) - ->whereHas('transactions', function ($query) use ($startDate, $endDate) { - $query->payments() - ->where('status', ApprovalStatus::REFUNDED) - ->whereBetween('created_at', [$startDate, $endDate]) - ->latest('created_at'); + // return Booking::whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED, ApprovalStatus::SUSPENDED]) + // ->whereHas('transactions', function ($query) use ($startDate, $endDate) { + // $query->payments() + // ->where('status', ApprovalStatus::REFUNDED) + // ->whereBetween('created_at', [$startDate, $endDate]) + // ->latest('created_at'); + // }); + + return Booking::whereIn('status', [ + ApprovalStatus::APPROVED, + ApprovalStatus::COMPLETED, + ApprovalStatus::SUSPENDED, + ]) + ->whereHas('transactions', function ($transactionQuery) use ($startDate, $endDate) { + $transactionQuery->payments() + ->whereBetween('created_at', [$startDate, $endDate]) + ->latest('created_at') + ->whereHas('transactions', function ($refundQuery) { + $refundQuery->refunds() + ->whereIn('status', [ApprovalStatus::APPROVED]); + }); }); } @@ -83,7 +98,8 @@ class ExportsSalesInvoiceWithRefundReport implements FromQuery, WithHeadings, Wi $company = $booking->company()->first(); // $lastPaymentTransaction = $booking->transactions()->payments()->complete()->latest()->first(); - $lastPaymentTransaction = $booking->transactions()->payments()->where('status', ApprovalStatus::REFUNDED)->latest()->first(); + // $lastPaymentTransaction = $booking->transactions()->payments()->where('status', ApprovalStatus::REFUNDED)->latest()->first(); + $lastPaymentTransaction = $booking->transactions()->payments()->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::REFUNDED])->latest()->first(); if(!$lastPaymentTransaction){ return $records; }