From 54bc9d1cfa0c8aef48f6f10b062865203d92a4dc Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 10 Aug 2025 22:18:46 +0800 Subject: [PATCH 1/3] E-Invoice - Sales Invoice Report, updated filtering logic --- .../Services/ExportsSalesInvoiceReport.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 74598a8d..cf0a7fe7 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -14,7 +14,6 @@ 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 { @@ -60,7 +59,17 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR // $query->where('type', TransactionType::PURCHASE_ORDER)->complete(); // }); - return Booking::where('status', ApprovalStatus::COMPLETED)->whereBetween('created_at', [$this->startDate, $this->endDate]); + // return Booking::where('status', ApprovalStatus::COMPLETED)->whereBetween('created_at', [$this->startDate, $this->endDate]); + + $startDate = $this->startDate; + $endDate = $this->endDate; + return Booking::where('status', ApprovalStatus::COMPLETED) + ->whereHas('transactions', function ($query) use ($startDate, $endDate) { + $query->payments() + ->complete() + ->whereBetween('created_at', [$startDate, $endDate]) + ->latest('created_at'); + }); } /** @@ -76,12 +85,18 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $purchaseOrder = $booking->transactions()->where('type', TransactionType::PURCHASE_ORDER)->first(); $company = $booking->company()->first(); - $lastPaymentTransaction = $booking->transactions()->where('type', TransactionType::PAYMENT)->whereIn('status', [ApprovalStatus::COMPLETED, ApprovalStatus::APPROVED])->latest()->first(); + + $lastPaymentTransaction = $booking->transactions()->payments()->complete()->latest()->first(); if(!$lastPaymentTransaction){ return $records; } - $invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED])->first(); + $documentDate = $lastPaymentTransaction->created_at; + if ($documentDate < $this->startDate || $documentDate > $this->endDate) { + return $records; + } + + $invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->complete()->first(); $currencyId = $booking->fix_currency_id; @@ -114,10 +129,6 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR $totalPayment = $paymentSum - $refundedAmount - $refundedServiceCharge; } - $documentDate = $lastPaymentTransaction->created_at; - // if(Carbon::parse($booking->updated_at)->isAfter($lastPaymentTransaction->created_at)){ //cief todo: 90 - Report E-Invoice date incorrect - // $documentDate = $booking->updated_at; - // } $formattedDocumentDate = Carbon::parse($documentDate)->format('m/d/Y'); $firstItem = true; From fb3a1668d34c001ad1203a8ccda8cbbc9131f464 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 10 Aug 2025 22:37:17 +0800 Subject: [PATCH 2/3] E-Invoice - Sales Invoice Report, updated filtering logic --- .../bookings/elements/DownloadUploadComponent.vue | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue index ab1524e8..c28b108e 100644 --- a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue +++ b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue @@ -69,6 +69,9 @@ +
+ {{error}} +
@@ -88,6 +91,7 @@ export default { }, data(){ return { + error: '', parameters: { startDate: '', endDate: '', @@ -125,6 +129,7 @@ export default { ]; }, handleExportClick(){ + this.error = ''; if (!this.validate()) return; const reportType = this.parameters.reportType; @@ -145,6 +150,7 @@ export default { } }, handleGenerateEInvoiceClick(){ + this.error = ''; if (!this.validate()) return; const reportType = this.parameters.reportType; @@ -175,6 +181,7 @@ export default { }, errorHandler(error) { this.isDownloading = false; + this.error = error.message + '. Please try again with a shorter date span between the two date filters.'; }, }, mixins: [componentHandler] From cbf650c8be75a66b750027e2b41d698d0b9ac893 Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Sun, 10 Aug 2025 22:50:37 +0800 Subject: [PATCH 3/3] E-Invoice - Sales Invoice Report, updated filtering logic --- .../Modules/Exports/Services/ExportsSalesInvoiceReport.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index cf0a7fe7..5ecc250c 100644 --- a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php +++ b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php @@ -96,6 +96,10 @@ class ExportsSalesInvoiceReport implements FromQuery, WithHeadings, WithHeadingR return $records; } + if($company->e_invoice === 1){ + $documentDate = $documentDate->copy()->endOfMonth(); + } + $invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->complete()->first(); $currencyId = $booking->fix_currency_id;