listAccount() as $accountNumber) { foreach ($this->listPeriod() as $period) { $job = new ExportStatementJob( $accountNumber, $period, $this->getAccountBalance($accountNumber, $period) ); $jobIds[] = app(Dispatcher::class)->dispatch($job); $data[] = [ 'account_number' => $accountNumber, 'period' => $period ]; } } return response()->json([ 'message' => 'Statement export jobs have been queued', 'jobs' => array_map(function ($index, $jobId) use ($data) { return [ 'job_id' => $jobId, 'account_number' => $data[$index]['account_number'], 'period' => $data[$index]['period'], 'file_name' => "{$data[$index]['account_number']}_{$data[$index]['period']}.csv" ]; }, array_keys($jobIds), $jobIds) ]); } function listAccount(){ return [ '1080426085', '1080425781', '1081647484', '1081647485', '1083123710', '1083123711', '1083123712', '1083123713', '1083123714', '1083123715', '1083123716', '1083123718', '1083123719', '1083123721', '1083123722', '1083123723', '1083123724', '1083123726', '1083123727', '1083123728', '1083123730', '1083123731', '1083123732', '1083123734', '1083123735', '1086677889', '1086677890', '1086677891', '1086677892', '1086677893', '1086677894', '1086677895', '1086677896', '1086677897', '1080119298', '1080119361', '1080119425', '1080119387', '1082208069', '1085151668', '1085368601', '1078333878', '0081272689' ]; } function listPeriod(){ return [ '20250512', '20250513', '20250514', '20250515', '20250516', '20250517', '20250518', '20250519', '20250520', '20250521', '20250522' ]; } function getAccountBalance($accountNumber, $period) { $accountBalance = AccountBalance::where('account_number', $accountNumber) ->where('period', '<', $period) ->orderBy('period', 'desc') ->first(); return $accountBalance->actual_balance ?? 0; } }