Merge branch 'dillon/90-e-invoice-f' into dillon/90-e-invoice-f-3

This commit is contained in:
Dillon Ngo
2025-08-21 02:51:52 +08:00
2 changed files with 30 additions and 8 deletions
@@ -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;
@@ -73,6 +73,9 @@
</modal-component>
</div>
</div>
<div class="row m-r-0 m-l-0" v-if="error">
<small class="bold fs-10 text-danger">{{error}}</small>
</div>
</div>
</div>
</div>
@@ -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]