diff --git a/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php b/app/Classes/Modules/Exports/Services/ExportsSalesInvoiceReport.php index 74598a8d..5ecc250c 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,22 @@ 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; + } + + if($company->e_invoice === 1){ + $documentDate = $documentDate->copy()->endOfMonth(); + } + + $invoiceTransaction = $booking->transactions()->where('type', TransactionType::INVOICE)->complete()->first(); $currencyId = $booking->fix_currency_id; @@ -114,10 +133,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; diff --git a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue index 6766d83a..e8837794 100644 --- a/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue +++ b/resources/assets/vue/components/bookings/elements/DownloadUploadComponent.vue @@ -73,6 +73,9 @@ +
+ {{error}} +
@@ -92,6 +95,7 @@ export default { }, data(){ return { + error: '', parameters: { startDate: '', endDate: '', @@ -129,6 +133,7 @@ export default { ]; }, handleExportClick(){ + this.error = ''; if (!this.validate()) return; const reportType = this.parameters.reportType; @@ -152,6 +157,7 @@ export default { } }, handleGenerateEInvoiceClick(){ + this.error = ''; if (!this.validate()) return; const reportType = this.parameters.reportType; @@ -182,6 +188,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]