From d0f1c57f198ae6c1ed6096c62c042f343c85c330 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 14 Sep 2025 13:30:20 +0800 Subject: [PATCH 1/3] E-Invoice - Look into another timed out problem, error 504 --- .../Services/ExportsSalesInvoiceReport.php | 30 +++++++++++-------- 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 5ecc250c..19ddd71c 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -63,7 +63,12 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $startDate = $this->startDate; $endDate = $this->endDate; - return Booking::where('status', ApprovalStatus::COMPLETED) + return Booking::with([ + 'company', + 'transactions.transactionDetails', + 'transactions.voucherRedemption' + ]) + ->where('status', ApprovalStatus::COMPLETED) ->whereHas('transactions', function ($query) use ($startDate, $endDate) { $query->payments() ->complete() @@ -82,11 +87,15 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $averageCurrencyRate = 0; $currencyId = 0; - $purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); - $company = $booking->company()->first(); + $purchaseOrder = $booking->transactions->where('type', TransactionType::PURCHASE_ORDER)->first(); + $company = $booking->company->first(); - $lastPaymentTransaction = $booking->transactions()->payments()->complete()->latest()->first(); + $lastPaymentTransaction = $booking->transactions + ->where('type', TransactionType::PAYMENT) + ->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]) + ->sortByDesc('created_at') + ->first(); if(!$lastPaymentTransaction){ return $records; } @@ -100,7 +109,7 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $documentDate = $documentDate->copy()->endOfMonth(); } - $invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->complete()->first(); + $invoiceTransaction = $booking->transactions->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); $currencyId = $booking->fix_currency_id; @@ -108,21 +117,19 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $displayedSubtotal = 0; $totalPayment = 0; $averageCurrencyRate = $invoiceTransaction->currency_rate; - $paymentSum = $booking->transactions() + $paymentSum = $booking->transactions ->where('type', TransactionType::PAYMENT) ->where('status', ApprovalStatus::COMPLETED) - ->get() ->sum(function ($transaction) { return round($transaction->amount, 2); }); if ($paymentSum){ - $averageCurrencyRate = $booking->transactions() + $averageCurrencyRate = $booking->transactions ->where('type', TransactionType::PAYMENT) ->where('status', ApprovalStatus::COMPLETED) - ->get() ->sum(function ($transaction) { return $transaction->currency_rate; - }) / $booking->transactions() + }) / $booking->transactions ->where('type', TransactionType::PAYMENT) ->where('status', ApprovalStatus::COMPLETED) ->count(); @@ -178,10 +185,9 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $serviceCharge = $invoiceTransaction->service_charge; } else { - $serviceCharge = $booking->transactions() + $serviceCharge = $booking->transactions ->where('type', TransactionType::PAYMENT) ->where('status', ApprovalStatus::COMPLETED) - ->get() ->sum(function ($transaction) { return $transaction->service_charge; }); From e0f1e3f38bfd98899bf002b5f350d5b174676ef4 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 14 Sep 2025 14:15:24 +0800 Subject: [PATCH 2/3] E-Invoice - Look into another timed out problem, error 504 --- .../Modules/Exports/Services/ExportsSalesInvoiceReport.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 19ddd71c..0be6f1d3 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -100,7 +100,9 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR return $records; } - $documentDate = $lastPaymentTransaction->created_at; + // $documentDate = $lastPaymentTransaction->created_at; + $documentDate = Carbon::parse($lastPaymentTransaction->created_at); + if ($documentDate < $this->startDate || $documentDate > $this->endDate) { return $records; } From 97861e29c8b6cae38e9ba8676d30424c02b3c538 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 14 Sep 2025 14:33:10 +0800 Subject: [PATCH 3/3] E-Invoice - Look into another timed out problem, error 504 --- .../Modules/Exports/Services/ExportsSalesInvoiceReport.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 0be6f1d3..289f86f2 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -14,6 +14,7 @@ use Maatwebsite\Excel\Concerns\WithMapping; use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundAmount; use App\Classes\Modules\Bookings\Services\CalculatesBookingRefundServiceCharge; use Carbon\Carbon; +use Illuminate\Support\Facades\Log; class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize { @@ -88,7 +89,7 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $currencyId = 0; $purchaseOrder = $booking->transactions->where('type', TransactionType::PURCHASE_ORDER)->first(); - $company = $booking->company->first(); + $company = $booking->company; $lastPaymentTransaction = $booking->transactions