From 1a58f9c984dcd163c502c6f1ceb4bac21543ef8d Mon Sep 17 00:00:00 2001 From: Dillon Ngo Date: Thu, 7 Nov 2024 05:54:41 +0800 Subject: [PATCH] Laravel Vapor - Fix a problem on downloading Wallet Transaction History --- .../Services/ExportsCustomersWalletTransactionHistory.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php index 745539f5..3121f9ea 100644 --- a/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php +++ b/app/Classes/Modules/Exports/Services/ExportsCustomersWalletTransactionHistory.php @@ -20,10 +20,14 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading private $request; private $runningBalance = 0; + protected $startDate; + protected $endDate; - public function __construct(Request $request) + public function __construct(Request $request, $startDate = null, $endDate = null) { $this->request = $request; + $this->startDate = $startDate ? Carbon::parse($startDate)->startOfDay() : Carbon::now()->subMonths(12); + $this->endDate = $endDate ? Carbon::parse($endDate)->endOfDay() : Carbon::now(); } public function headings(): array @@ -43,7 +47,7 @@ class ExportsCustomersWalletTransactionHistory implements FromQuery, WithHeading public function query() { $company = Company::where('reference', $this->request->route('marking'))->first(); - $transactions = $company->wallets()->first()->transactions()->whereIn('transactions.status', [2, 3])->orderBy('id'); + $transactions = $company->wallets()->first()->transactions()->whereIn('transactions.status', [2, 3])->whereBetween('created_at', [$this->startDate, $this->endDate])->orderBy('id'); // dd($transactions->get()->toArray()); return $transactions;