ProcessTransactionDataJob::class, 'stmtNarrParam' => ProcessStmtNarrParamDataJob::class, 'stmtNarrFormat' => ProcessStmtNarrFormatDataJob::class, 'ftTxnTypeCondition' => ProcessFtTxnTypeConditionJob::class, 'category' => ProcessCategoryDataJob::class, 'company' => ProcessCompanyDataJob::class, 'customer' => ProcessCustomerDataJob::class, 'account' => ProcessAccountDataJob::class, 'stmtEntry' => ProcessStmtEntryDataJob::class, 'dataCapture' => ProcessDataCaptureDataJob::class, 'fundsTransfer' => ProcessFundsTransferDataJob::class, 'teller' => ProcessTellerDataJob::class, 'atmTransaction' => ProcessAtmTransactionJob::class, 'arrangement' => ProcessArrangementDataJob::class, 'billDetail' => ProcessBillDetailDataJob::class, 'sector' => ProcessSectorDataJob::class ]; private const PARAMETER_PROCESSES = [ 'transaction', 'stmtNarrParam', 'stmtNarrFormat', 'ftTxnTypeCondition', 'sector' ]; private const DATA_PROCESSES = [ 'category', 'company', 'customer', 'account', 'stmtEntry', 'dataCapture', 'fundsTransfer', 'teller', 'atmTransaction', 'arrangement', 'billDetail' ]; public function __call($method, $parameters) { if (strpos($method, 'process') === 0) { $type = lcfirst(substr($method, 7)); if (isset(self::PROCESS_TYPES[$type])) { return $this->processData($type, $parameters[0] ?? ''); } } throw new BadMethodCallException("Method {$method} does not exist."); } private function processData(string $type, string $period) : JsonResponse { try { $jobClass = self::PROCESS_TYPES[$type]; $jobClass::dispatch($period); $message = sprintf('%s data processing job has been queued successfully', ucfirst($type)); Log::info($message); return response()->json(['message' => $message]); } catch (Exception $e) { Log::error(sprintf('Error in %s processing: %s', $type, $e->getMessage())); return response()->json(['error' => $e->getMessage()], 500); } } public function index($processParameter = false) { $disk = Storage::disk('sftpStatement'); if ($processParameter) { foreach (self::PARAMETER_PROCESSES as $process) { $this->processData($process, '_parameter'); } return response()->json(['message' => 'Parameter processes completed successfully']); } $period = date('Ymd', strtotime('-1 day')); if (!$disk->exists($period)) { return response()->json([ "message" => "Period {$period} folder not found in SFTP storage" ], 404); } foreach (self::DATA_PROCESSES as $process) { $this->processData($process, $period); } return response()->json([ 'message' => "Data processing for period {$period} has been queued successfully" ]); } }