From c0f32a6e1637428e8fc7631c8c2690209deb5108 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 29 Jan 2025 19:43:53 +0700 Subject: [PATCH] feat(jobs): tambahkan job untuk memproses berbagai data - Menambahkan job untuk memproses data akun. - Menambahkan job untuk memproses data transaksi. - Menambahkan job untuk memproses data transfer dana. - Menambahkan job untuk memproses data format narasi. - Menambahkan job untuk memproses data parameter narasi. - Menambahkan job untuk memproses data entry statement. - Memperbarui metode pengolahan data di MigrasiController. --- app/Http/Controllers/MigrasiController.php | 176 +++++++++------------ 1 file changed, 77 insertions(+), 99 deletions(-) diff --git a/app/Http/Controllers/MigrasiController.php b/app/Http/Controllers/MigrasiController.php index e52d05a..c91dd5d 100644 --- a/app/Http/Controllers/MigrasiController.php +++ b/app/Http/Controllers/MigrasiController.php @@ -2,52 +2,26 @@ namespace Modules\Webstatement\Http\Controllers; -use Exception; use App\Http\Controllers\Controller; -use Modules\Webstatement\Models\TempCustomer; -use Modules\Webstatement\Models\TempArrangement; +use Exception; +use Log; +use Modules\Webstatement\Jobs\ProcessAccountDataJob; +use Modules\Webstatement\Jobs\ProcessArrangementDataJob; +use Modules\Webstatement\Jobs\ProcessBillDetailDataJob; use Modules\Webstatement\Jobs\ProcessCustomerDataJob; -use Modules\Webstatement\Models\TempBillDetail; +use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob; +use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob; +use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob; +use Modules\Webstatement\Jobs\ProcessStmtNarrParamDataJob; +use Modules\Webstatement\Jobs\ProcessTransactionDataJob; class MigrasiController extends Controller { public function processArrangementData() { - $filePath = storage_path('app/20240901.ST.AA.ARRANGEMENT.csv'); // Adjust this path as needed try { - if (!file_exists($filePath)) { - throw new Exception("File not found: $filePath"); - } - - //ProcessCustomerDataJob::dispatch($filePath); - - set_time_limit(24 * 60 * 60); - - if (!file_exists($filePath)) { - throw new Exception("File not found: {$filePath}"); - } - - $handle = fopen($filePath, "r"); - - if ($handle !== false) { - $headers = (new TempArrangement())->getFillable(); - - while (($row = fgetcsv($handle, 0, ";")) !== false) { - unset($row[0]); // Remove the first empty column if present - if (count($headers) === count($row)) { - $data = array_combine($headers, $row); - TempArrangement::updateOrCreate( - ['arrangement_id' => $data['arrangement_id']], // key to find existing record - $data // data to update or create - ); - } - } - fclose($handle); - } else { - throw new Exception("Unable to open file: {$filePath}"); - } - + ProcessArrangementDataJob::dispatch(); return response()->json(['message' => 'Data Arrangement processing job has been successfully']); } catch (Exception $e) { return response()->json(['error' => $e->getMessage()], 500); @@ -58,35 +32,7 @@ class MigrasiController extends Controller { $filePath = storage_path('app/20240901.ST.CUSTOMER.csv'); // Adjust this path as needed try { - if (!file_exists($filePath)) { - throw new Exception("File not found: $filePath"); - } - - set_time_limit(24 * 60 * 60); - - if (!file_exists($filePath)) { - throw new Exception("File not found: {$filePath}"); - } - - $handle = fopen($filePath, "r"); - - if ($handle !== false) { - $headers = (new TempCustomer())->getFillable(); - while (($row = fgetcsv($handle, 0, "~")) !== false) { - unset($row[0]); // Remove the first empty column if present - if (count($headers) === count($row)) { - $data = array_combine($headers, $row); - TempCustomer::updateOrCreate( - ['customer_code' => $data['customer_code']], // key to find existing record - $data // data to update or create - ); - } - } - fclose($handle); - } else { - throw new Exception("Unable to open file: {$filePath}"); - } - + ProcessCustomerDataJob::dispatch(); return response()->json(['message' => 'Data Customer processing job has been successfully']); } catch (Exception $e) { return response()->json(['error' => $e->getMessage()], 500); @@ -95,51 +41,83 @@ class MigrasiController extends Controller public function processBillDetailData() { - $filePath = storage_path('app/20240901.ST.AA.BILL.DETAILS.csv'); // Adjust this path as needed try { - if (!file_exists($filePath)) { - throw new Exception("File not found: $filePath"); - } - - set_time_limit(24 * 60 * 60); - - if (!file_exists($filePath)) { - throw new Exception("File not found: {$filePath}"); - } - - $handle = fopen($filePath, "r"); - - if ($handle !== false) { - $headers = (new TempBillDetail())->getFillable(); - while (($row = fgetcsv($handle, 0, ";")) !== false) { - if (count($headers) === count($row)) { - $data = array_combine($headers, $row); - - try { - TempBillDetail::create( - $data // data to update or create - ); - } catch (Exception $e) { - echo json_encode($e->getMessage()); - } - } - } - fclose($handle); - } else { - throw new Exception("Unable to open file: {$filePath}"); - } - + ProcessBillDetailDataJob::dispatch(); return response()->json(['message' => 'Data Bill Details processing job has been successfully']); } catch (Exception $e) { return response()->json(['error' => $e->getMessage()], 500); } } + public function processAccountData(){ + try{ + ProcessAccountDataJob::dispatch(); + return response()->json(['message' => 'Data Account processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function processTransactionData(){ + try{ + ProcessTransactionDataJob::dispatch(); + Log::info('Data Transaction processing job has been successfully'); + return response()->json(['message' => 'Data Transaction processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function processFundsTransferData(){ + try{ + ProcessFundsTransferDataJob::dispatch(); + return response()->json(['message' => 'Data Funds Transfer processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function processStmtNarrParamData() + { + try { + ProcessStmtNarrParamDataJob::dispatch(); + return response()->json(['message' => 'Data TempStmtNarrParam processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function processStmtNarrFormatData(){ + try { + ProcessStmtNarrFormatDataJob::dispatch(); + return response()->json(['message' => 'Data TempStmtNarrFormat processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function processStmtEntryData(){ + try { + ProcessStmtEntryDataJob::dispatch(); + return response()->json(['message' => 'Data TempStmtEntry processing job has been successfully']); + } catch (Exception $e) { + return response()->json(['error' => $e->getMessage()], 500); + } + } + + public function index() { $this->processCustomerData(); + $this->processAccountData(); $this->processArrangementData(); $this->processBillDetailData(); + $this->processTransactionData(); + $this->processFundsTransferData(); + $this->processStmtNarrParamData(); + $this->processStmtNarrFormatData(); + $this->processStmtEntryData(); + return response()->json(['message' => 'Data processing job has been successfully']); } }