From 82675ab80c41c2d3a4fdefc604e8dcb78b2cd8b6 Mon Sep 17 00:00:00 2001 From: Omair Saleh Date: Mon, 1 Jul 2024 13:40:14 +0800 Subject: [PATCH] export based on payment date --- .../Services/ExportsPaymentTransactions.php | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php index 7942f6b5..3478b40c 100644 --- a/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php +++ b/app/Classes/Modules/Exports/Services/ExportsPaymentTransactions.php @@ -59,12 +59,12 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading { $start_date = $this->request->input('startDate', null); if ($start_date) { - $start_date = Carbon::parse($this->request->input('startDate'))->format('Y-m-d'); + $start_date = Carbon::parse($start_date)->startOfDay(); } $end_date = $this->request->input('endDate', null); if ($end_date) { - $end_date = Carbon::parse($this->request->input('endDate'))->format('Y-m-d'); + $end_date = Carbon::parse($end_date)->endOfDay(); } $query = Transaction::query(); @@ -77,32 +77,31 @@ class ExportsPaymentTransactions implements FromQuery, WithHeadings, WithHeading $approvalStatus = ApprovalStatus::APPROVED; } - // $query->where('type', TransactionType::SHIPPING_INVOICE)->whereIn('status', [$approvalStatus]); - $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE])->whereIn('status', [$approvalStatus]); + // Adjusted the query to include both types and status + $query->whereIn('type', [TransactionType::SHIPPING_INVOICE, TransactionType::STORAGE_INVOICE]) + ->where('status', $approvalStatus); - if($start_date && $end_date) { + if ($start_date && $end_date) { $query->whereHas('transactions', function($transaction) use ($start_date, $end_date) { $transaction->where('type', TransactionType::PAYMENT) - ->whereBetween('updated_at', [ - Carbon::parse($start_date)->format('Y-m-d 0:00:00'), - Carbon::parse($end_date)->format('Y-m-d 23:59:59') - ]); + ->whereBetween('updated_at', [$start_date, $end_date]); }); - } - elseif($start_date && !$end_date) { + } elseif ($start_date) { $query->whereHas('transactions', function($transaction) use ($start_date) { - $transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($start_date)->format('Y-m-d 0:00:00')); + $transaction->where('type', TransactionType::PAYMENT) + ->where('updated_at', '>=', $start_date); }); - - } - elseif(!$start_date && $end_date) { + } elseif ($end_date) { $query->whereHas('transactions', function($transaction) use ($end_date) { - $transaction->where('type', TransactionType::PAYMENT)->where('updated_at', '>=', Carbon::parse($end_date)->format('Y-m-d 0:00:00')); + $transaction->where('type', TransactionType::PAYMENT) + ->where('updated_at', '<=', $end_date); }); } + return $query; } + public function map($transaction): array { $container = $transaction->owner->containers()->first();