E-Invoice - Project 27, IZYIM - Sales Invoice - Import

This commit is contained in:
Dillon Ngo
2025-08-31 17:39:07 +08:00
parent 8607caa84f
commit 3fb7befd62
2 changed files with 17 additions and 5 deletions
@@ -13,6 +13,7 @@ use Maatwebsite\Excel\Concerns\WithHeadingRow;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Carbon\Carbon;
use Illuminate\Support\Facades\Log;
class ExportsSalesInvoicesReport implements FromQuery, WithHeadings, WithHeadingRow, WithMapping, ShouldAutoSize
{
@@ -72,17 +73,20 @@ class ExportsSalesInvoicesReport implements FromQuery, WithHeadings, WithHeading
if ($start_date && $end_date) {
$query->whereHas('transactions', function($transaction) use ($start_date, $end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->whereBetween('updated_at', [$start_date, $end_date]);
->whereBetween('updated_at', [$start_date, $end_date])
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
} elseif ($start_date) {
$query->whereHas('transactions', function($transaction) use ($start_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '>=', $start_date);
->where('updated_at', '>=', $start_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
} elseif ($end_date) {
$query->whereHas('transactions', function($transaction) use ($end_date) {
$transaction->where('type', TransactionType::PAYMENT)
->where('updated_at', '<=', $end_date);
->where('updated_at', '<=', $end_date)
->whereIn('status', [ApprovalStatus::APPROVED, ApprovalStatus::COMPLETED]);
});
}
@@ -32,13 +32,21 @@ class ExportController
'endDate' => 'nullable|date_format:d-m-Y|after_or_equal:startDate',
]);
// $startDate = isset($validated['startDate']) && $validated['startDate']
// ? Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay()
// : Carbon::now()->subMonth()->startOfDay();
// $endDate = isset($validated['endDate']) && $validated['endDate']
// ? Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay()
// : Carbon::now()->endOfDay();
$startDate = isset($validated['startDate']) && $validated['startDate']
? Carbon::createFromFormat('d-m-Y', $validated['startDate'])->startOfDay()
: Carbon::now()->subMonth()->startOfDay();
: Carbon::now()->startOfMonth()->startOfDay();
$endDate = isset($validated['endDate']) && $validated['endDate']
? Carbon::createFromFormat('d-m-Y', $validated['endDate'])->endOfDay()
: Carbon::now()->endOfDay();
: Carbon::now()->endOfMonth()->endOfDay();
return [$startDate, $endDate];
}