refactor(jobs): simplify jobs and controllers by replacing period array with single period parameter

- Mengganti parameter `$periods` (array) menjadi `$period` (string) pada semua Job terkait: `ProcessCustomerDataJob`, `ProcessFundsTransferDataJob, etc`.
- Menyederhanakan operasi loop dalam proses data dengan hanya memproses satu periode per eksekusi Job.
- Memodifikasi fungsi controller di `MigrasiController` agar sesuai dengan perubahan parameter dari array ke string.
- Menambahkan pengamanan jika `$period` kosong atau bernilai '_parameter' untuk mencegah proses yang tidak diperlukan.
- Mengurangi duplikasi kode dengan mengeliminasi metode yang mengelola array periode dan menggantinya dengan pendekatan tunggal.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
Daeng Deni Mardaeni
2025-05-24 19:40:40 +07:00
parent 85b8bfa07b
commit cd447eb019
9 changed files with 761 additions and 799 deletions

View File

@@ -1,78 +1,34 @@
<?php <?php
namespace Modules\Webstatement\Http\Controllers; namespace Modules\Webstatement\Http\Controllers;
use App\Http\Controllers\Controller; use App\Http\Controllers\Controller;
use Exception; use Exception;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Log; use Log;
use Modules\Webstatement\Jobs\ProcessAccountDataJob; use Modules\Webstatement\Jobs\ProcessAccountDataJob;
use Modules\Webstatement\Jobs\ProcessArrangementDataJob; use Modules\Webstatement\Jobs\ProcessArrangementDataJob;
use Modules\Webstatement\Jobs\ProcessAtmTransactionJob; use Modules\Webstatement\Jobs\ProcessAtmTransactionJob;
use Modules\Webstatement\Jobs\ProcessBillDetailDataJob; use Modules\Webstatement\Jobs\ProcessBillDetailDataJob;
use Modules\Webstatement\Jobs\ProcessCategoryDataJob; use Modules\Webstatement\Jobs\ProcessCategoryDataJob;
use Modules\Webstatement\Jobs\ProcessCompanyDataJob; use Modules\Webstatement\Jobs\ProcessCompanyDataJob;
use Modules\Webstatement\Jobs\ProcessCustomerDataJob; use Modules\Webstatement\Jobs\ProcessCustomerDataJob;
use Modules\Webstatement\Jobs\ProcessDataCaptureDataJob; use Modules\Webstatement\Jobs\ProcessDataCaptureDataJob;
use Modules\Webstatement\Jobs\ProcessFtTxnTypeConditionJob; use Modules\Webstatement\Jobs\ProcessFtTxnTypeConditionJob;
use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob; use Modules\Webstatement\Jobs\ProcessFundsTransferDataJob;
use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob; use Modules\Webstatement\Jobs\ProcessStmtEntryDataJob;
use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob; use Modules\Webstatement\Jobs\ProcessStmtNarrFormatDataJob;
use Modules\Webstatement\Jobs\ProcessStmtNarrParamDataJob; use Modules\Webstatement\Jobs\ProcessStmtNarrParamDataJob;
use Modules\Webstatement\Jobs\ProcessTellerDataJob; use Modules\Webstatement\Jobs\ProcessTellerDataJob;
use Modules\Webstatement\Jobs\ProcessTransactionDataJob; use Modules\Webstatement\Jobs\ProcessTransactionDataJob;
class MigrasiController extends Controller class MigrasiController extends Controller
{ {
public function processArrangementData($periods) public function processTransactionData($period)
{ {
try { try {
ProcessArrangementDataJob::dispatch($periods); ProcessTransactionDataJob::dispatch($period);
return response()->json(['message' => 'Data Arrangement processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processCustomerData($periods)
{
try {
// Pass the periods to the job for processing
ProcessCustomerDataJob::dispatch($periods);
return response()->json([
'message' => 'Data Customer processing job has been successfully queued',
'periods' => $periods
]);
} catch (Exception $e) {
Log::error('Error in processCustomerData: ' . $e->getMessage());
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processBillDetailData($periods)
{
try {
ProcessBillDetailDataJob::dispatch($periods);
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($periods){
try{
ProcessAccountDataJob::dispatch($periods);
return response()->json(['message' => 'Data Account processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processTransactionData($periods){
try{
ProcessTransactionDataJob::dispatch($periods);
Log::info('Data Transaction processing job has been successfully'); Log::info('Data Transaction processing job has been successfully');
return response()->json(['message' => 'Data Transaction processing job has been successfully']); return response()->json(['message' => 'Data Transaction processing job has been successfully']);
} catch (Exception $e) { } catch (Exception $e) {
@@ -80,99 +36,36 @@ class MigrasiController extends Controller
} }
} }
public function processFundsTransferData($periods){ public function processStmtNarrParamData($period)
try{
ProcessFundsTransferDataJob::dispatch($periods);
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($periods)
{ {
try { try {
ProcessStmtNarrParamDataJob::dispatch($periods); ProcessStmtNarrParamDataJob::dispatch($period);
return response()->json(['message' => 'Data TempStmtNarrParam processing job has been successfully']); return response()->json(['message' => 'Data TempStmtNarrParam processing job has been successfully']);
} catch (Exception $e) { } catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500); return response()->json(['error' => $e->getMessage()], 500);
} }
} }
public function processStmtNarrFormatData($periods){ public function processStmtNarrFormatData($period)
{
try { try {
ProcessStmtNarrFormatDataJob::dispatch($periods); ProcessStmtNarrFormatDataJob::dispatch($period);
return response()->json(['message' => 'Data TempStmtNarrFormat processing job has been successfully']); return response()->json(['message' => 'Data TempStmtNarrFormat processing job has been successfully']);
} catch (Exception $e) { } catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500); return response()->json(['error' => $e->getMessage()], 500);
} }
} }
public function ProcessFtTxnTypeConditioData($periods){ public function ProcessFtTxnTypeConditioData($period)
{
try { try {
ProcessFtTxnTypeConditionJob::dispatch($periods); ProcessFtTxnTypeConditionJob::dispatch($period);
return response()->json(['message' => 'FtTxnTypeCondition processing job has been successfully']); return response()->json(['message' => 'FtTxnTypeCondition processing job has been successfully']);
} catch (Exception $e) { } catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500); return response()->json(['error' => $e->getMessage()], 500);
} }
} }
public function processStmtEntryData($periods){
try {
ProcessStmtEntryDataJob::dispatch($periods);
return response()->json(['message' => 'Stmt Entry processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCompanyData($periods){
try {
ProcessCompanyDataJob::dispatch($periods);
return response()->json(['message' => 'Company processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessDataCaptureData($periods){
try {
ProcessDataCaptureDataJob::dispatch($periods);
return response()->json(['message' => 'Data Capture processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCategoryData($periods){
try {
ProcessCategoryDataJob::dispatch($periods);
return response()->json(['message' => 'Category processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessTellerData($periods){
try {
ProcessTellerDataJob::dispatch($periods);
return response()->json(['message' => 'Teller processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessAtmTransaction($periods){
try {
ProcessAtmTransactionJob::dispatch($periods);
return response()->json(['message' => 'AtmTransaction processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function index_manual() public function index_manual()
{ {
//$disk = Storage::disk('sftpStatement'); //$disk = Storage::disk('sftpStatement');
@@ -180,10 +73,10 @@ class MigrasiController extends Controller
// Get all directories (periods) in the SFTP disk // Get all directories (periods) in the SFTP disk
//$allDirectories = $disk->directories(); //$allDirectories = $disk->directories();
//$this->processTransactionData(['_parameter']); //$this->processTransactionData('_parameter');
//$this->processStmtNarrParamData(['_parameter']); //$this->processStmtNarrParamData('_parameter');
//$this->processStmtNarrFormatData(['_parameter']); //$this->processStmtNarrFormatData('_parameter');
//$this->ProcessFtTxnTypeConditioData(['_parameter']); //$this->ProcessFtTxnTypeConditioData('_parameter');
// Filter out the _parameter folder // Filter out the _parameter folder
/*$periods = array_filter($allDirectories, function($dir) { /*$periods = array_filter($allDirectories, function($dir) {
@@ -206,7 +99,7 @@ class MigrasiController extends Controller
]; ];
// Sort periods by date (descending) // Sort periods by date (descending)
usort($periods, function($a, $b) { usort($periods, function ($a, $b) {
return strcmp($b, $a); // Reverse comparison for descending order return strcmp($b, $a); // Reverse comparison for descending order
}); });
@@ -214,26 +107,142 @@ class MigrasiController extends Controller
return response()->json(['message' => 'No valid period folders found in SFTP storage'], 404); return response()->json(['message' => 'No valid period folders found in SFTP storage'], 404);
} }
foreach($periods as $period){ foreach ($periods as $period) {
$this->ProcessCategoryData([$period]); $this->ProcessCategoryData($period);
$this->ProcessCompanyData([$period]); $this->ProcessCompanyData($period);
$this->processCustomerData([$period]); $this->processCustomerData($period);
$this->processAccountData([$period]); $this->processAccountData($period);
$this->processStmtEntryData([$period]); $this->processStmtEntryData($period);
$this->ProcessDataCaptureData([$period]); $this->ProcessDataCaptureData($period);
$this->processFundsTransferData([$period]); $this->processFundsTransferData($period);
$this->ProcessTellerData([$period]); $this->ProcessTellerData($period);
$this->ProcessAtmTransaction([$period]); $this->ProcessAtmTransaction($period);
$this->processArrangementData([$period]); $this->processArrangementData($period);
$this->processBillDetailData([$period]); $this->processBillDetailData($period);
} }
return response()->json(['message' => 'Data processing job has been successfully']); return response()->json(['message' => 'Data processing job has been successfully']);
} }
public function ProcessCategoryData($period)
{
try {
ProcessCategoryDataJob::dispatch($period);
return response()->json(['message' => 'Category processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessCompanyData($period)
{
try {
ProcessCompanyDataJob::dispatch($period);
return response()->json(['message' => 'Company processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processCustomerData($period)
{
try {
// Pass the period to the job for processing
ProcessCustomerDataJob::dispatch($period);
return response()->json([
'message' => 'Data Customer processing job has been successfully queued',
'period' => $period
]);
} catch (Exception $e) {
Log::error('Error in processCustomerData: ' . $e->getMessage());
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processAccountData($period)
{
try {
ProcessAccountDataJob::dispatch($period);
return response()->json(['message' => 'Data Account processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processStmtEntryData($period)
{
try {
ProcessStmtEntryDataJob::dispatch($period);
return response()->json(['message' => 'Stmt Entry processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessDataCaptureData($period)
{
try {
ProcessDataCaptureDataJob::dispatch($period);
return response()->json(['message' => 'Data Capture processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processFundsTransferData($period)
{
try {
ProcessFundsTransferDataJob::dispatch($period);
return response()->json(['message' => 'Data Funds Transfer processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessTellerData($period)
{
try {
ProcessTellerDataJob::dispatch($period);
return response()->json(['message' => 'Teller processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function ProcessAtmTransaction($period)
{
try {
ProcessAtmTransactionJob::dispatch($period);
return response()->json(['message' => 'AtmTransaction processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processArrangementData($period)
{
try {
ProcessArrangementDataJob::dispatch($period);
return response()->json(['message' => 'Data Arrangement processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
public function processBillDetailData($period)
{
try {
ProcessBillDetailDataJob::dispatch($period);
return response()->json(['message' => 'Data Bill Details processing job has been successfully']);
} catch (Exception $e) {
return response()->json(['error' => $e->getMessage()], 500);
}
}
/** /**
* Process data migration for the previous day's period. * Process data migration for the previous day's period.
* *
@@ -244,7 +253,8 @@ class MigrasiController extends Controller
* @return \Illuminate\Http\JsonResponse A JSON response indicating success or failure * @return \Illuminate\Http\JsonResponse A JSON response indicating success or failure
* @throws \Exception If the period folder doesn't exist or if any processing job fails * @throws \Exception If the period folder doesn't exist or if any processing job fails
*/ */
public function index(){ public function index()
{
$disk = Storage::disk('sftpStatement'); $disk = Storage::disk('sftpStatement');
$period = date('Ymd', strtotime('-1 day')); $period = date('Ymd', strtotime('-1 day'));
@@ -255,18 +265,18 @@ class MigrasiController extends Controller
$this->ProcessCategoryData($period); $this->ProcessCategoryData($period);
$this->ProcessCompanyData($period); $this->ProcessCompanyData($period);
$this->processCustomerData([$period]); $this->processCustomerData($period);
$this->processAccountData([$period]); $this->processAccountData($period);
$this->processStmtEntryData([$period]); $this->processStmtEntryData($period);
$this->ProcessDataCaptureData([$period]); $this->ProcessDataCaptureData($period);
$this->processFundsTransferData([$period]); $this->processFundsTransferData($period);
$this->ProcessTellerData([$period]); $this->ProcessTellerData($period);
$this->ProcessAtmTransaction([$period]); $this->ProcessAtmTransaction($period);
$this->processArrangementData([$period]); $this->processArrangementData($period);
$this->processBillDetailData([$period]); $this->processBillDetailData($period);
return response()->json(['message' => "Data processing {$period} job has been successfully"]); return response()->json(['message' => "Data processing {$period} job has been successfully"]);
} }
} }

View File

@@ -17,20 +17,21 @@
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
* Execute the job. * Execute the job.
*/ */
public function handle(): void public function handle()
: void
{ {
try { try {
set_time_limit(24 * 60 * 60); set_time_limit(24 * 60 * 60);
@@ -38,27 +39,26 @@
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for account data processing'); Log::warning('No period provided for account data processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filename based on the period folder name // Construct the filename based on the period folder name
$filename = "$period.ST.ACCOUNT.csv"; $filename = "{$this->period}.ST.ACCOUNT.csv";
$filePath = "$period/$filename"; $filePath = "{$this->period}/$filename";
Log::info("Processing account file: $filePath"); Log::info("Processing account file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -98,7 +98,7 @@
if (isset($data['open_actual_bal']) || isset($data['open_cleared_bal'])) { if (isset($data['open_actual_bal']) || isset($data['open_cleared_bal'])) {
$accountBalance = AccountBalance::firstOrNew([ $accountBalance = AccountBalance::firstOrNew([
'account_number' => $data['account_number'], 'account_number' => $data['account_number'],
'period' => $period 'period' => $this->period
]); ]);
// Set the balances // Set the balances
@@ -106,7 +106,7 @@
$accountBalance->cleared_balance = $data['open_cleared_bal'] ?? 0; $accountBalance->cleared_balance = $data['open_cleared_bal'] ?? 0;
$accountBalance->save(); $accountBalance->save();
Log::info("Saved balance for account {$data['account_number']} for period $period"); Log::info("Saved balance for account {$data['account_number']} for period {$this->period}");
} }
$processedCount++; $processedCount++;
@@ -128,7 +128,6 @@
} else { } else {
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Account data processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Account data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -43,30 +43,37 @@
]; ];
// Pemetaan bidang header ke kolom model // Pemetaan bidang header ke kolom model
protected array $periods; protected string $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
* Execute the job. * Execute the job.
*/ */
public function handle(): void public function handle()
: void
{ {
try { try {
set_time_limit(24 * 60 * 60); set_time_limit(24 * 60 * 60);
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for ATM transaction data processing'); Log::warning('No period provided for ATM transaction data processing');
return; return;
} }
$stats = $this->processPeriods(); // Skip the parameter folder
if ($this->period === self::PARAMETER_FOLDER) {
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
return;
}
$stats = $this->processPeriodFile();
Log::info("ProcessAtmTransactionJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}"); Log::info("ProcessAtmTransactionJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}");
} catch (Exception $e) { } catch (Exception $e) {
@@ -75,40 +82,15 @@
} }
} }
/**
* Process all periods and return statistics
*/
private function processPeriods(): array
{
$disk = Storage::disk(self::DISK_NAME);
$processedCount = 0;
$errorCount = 0;
foreach ($this->periods as $period) {
// Skip the parameter folder
if ($period === self::PARAMETER_FOLDER) {
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
continue;
}
$result = $this->processPeriodFile($disk, $period);
$processedCount += $result['processed'];
$errorCount += $result['errors'];
}
return [
'processed' => $processedCount,
'errors' => $errorCount
];
}
/** /**
* Process a single period file * Process a single period file
*/ */
private function processPeriodFile($disk, string $period): array private function processPeriodFile()
: array
{ {
$filename = $period . self::FILE_EXTENSION; $disk = Storage::disk(self::DISK_NAME);
$filePath = "$period/$filename"; $filename = $this->period . self::FILE_EXTENSION;
$filePath = "{$this->period}/$filename";
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
@@ -141,7 +123,8 @@
/** /**
* Create a temporary file for processing * Create a temporary file for processing
*/ */
private function createTempFile($disk, string $filePath, string $filename): string private function createTempFile($disk, string $filePath, string $filename)
: string
{ {
$tempFilePath = storage_path("app/temp_$filename"); $tempFilePath = storage_path("app/temp_$filename");
file_put_contents($tempFilePath, $disk->get($filePath)); file_put_contents($tempFilePath, $disk->get($filePath));
@@ -151,7 +134,8 @@
/** /**
* Process a CSV file and import data * Process a CSV file and import data
*/ */
private function processCSVFile(string $tempFilePath, string $originalFilePath): array private function processCSVFile(string $tempFilePath, string $originalFilePath)
: array
{ {
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
@@ -194,7 +178,8 @@
/** /**
* Process a single row from the CSV file * Process a single row from the CSV file
*/ */
private function processRow(array $headerRow, array $row, int $rowCount, string $filePath): array private function processRow(array $headerRow, array $row, int $rowCount, string $filePath)
: array
{ {
// Combine the header row with the data row // Combine the header row with the data row
$rawData = array_combine($headerRow, $row); $rawData = array_combine($headerRow, $row);

View File

@@ -1,29 +1,29 @@
<?php <?php
namespace Modules\Webstatement\Jobs; namespace Modules\Webstatement\Jobs;
use Illuminate\Bus\Queueable; use Exception;
use Illuminate\Queue\SerializesModels; use Illuminate\Bus\Queueable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Support\Facades\Log; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Log;
use Modules\Webstatement\Models\TempBillDetail; use Illuminate\Support\Facades\Storage;
use Exception; use Modules\Webstatement\Models\TempBillDetail;
class ProcessBillDetailDataJob implements ShouldQueue class ProcessBillDetailDataJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected string $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
@@ -37,27 +37,26 @@ class ProcessBillDetailDataJob implements ShouldQueue
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for bill detail data processing'); Log::warning('No period provided for bill detail data processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filename based on the period folder name // Construct the filename based on the period folder name
$filename = "$period.ST.AA.BILL.DETAILS.csv"; $filename = "{$this->period}.ST.AA.BILL.DETAILS.csv";
$filePath = "$period/$filename"; $filePath = "{$this->period}/$filename";
Log::info("Processing bill detail file: $filePath"); Log::info("Processing bill detail file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -78,7 +77,7 @@ class ProcessBillDetailDataJob implements ShouldQueue
try { try {
if (isset($data['_id']) && $data['_id'] !== '_id') { if (isset($data['_id']) && $data['_id'] !== '_id') {
TempBillDetail::updateOrCreate( TempBillDetail::updateOrCreate(
['_id' => $data['_id']], // Fixed the syntax error here ['_id' => $data['_id']],
$data $data
); );
$processedCount++; $processedCount++;
@@ -100,7 +99,6 @@ class ProcessBillDetailDataJob implements ShouldQueue
} else { } else {
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Bill Detail data processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Bill Detail data processing completed. Total processed: $processedCount, Total errors: $errorCount");
@@ -109,4 +107,4 @@ class ProcessBillDetailDataJob implements ShouldQueue
throw $e; throw $e;
} }
} }
} }

View File

@@ -1,26 +1,26 @@
<?php <?php
namespace Modules\Webstatement\Jobs; namespace Modules\Webstatement\Jobs;
use Exception; use Exception;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Modules\Webstatement\Models\Customer; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Storage; use Modules\Webstatement\Models\Customer;
class ProcessCustomerDataJob implements ShouldQueue class ProcessCustomerDataJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected $period;
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
public function handle() public function handle()
@@ -31,28 +31,26 @@ class ProcessCustomerDataJob implements ShouldQueue
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for customer data processing'); Log::warning('No period provided for customer data processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filename based on the period folder name // Construct the filename based on the period folder name
$filename = "$period.ST.CUSTOMER.csv"; $filename = "{$this->period}.ST.CUSTOMER.csv";
$filePath = "$period/$filename"; $filePath = "{$this->period}/$filename";
Log::info("Processing customer file: $filePath"); Log::info("Processing customer file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -95,8 +93,6 @@ class ProcessCustomerDataJob implements ShouldQueue
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Customer data processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Customer data processing completed. Total processed: $processedCount, Total errors: $errorCount");
} catch (Exception $e) { } catch (Exception $e) {
@@ -104,4 +100,4 @@ class ProcessCustomerDataJob implements ShouldQueue
throw $e; throw $e;
} }
} }
} }

View File

@@ -16,15 +16,15 @@
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected $period;
protected $filename; protected $filename;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = [], string $filename = "ST.DATA.CAPTURE.csv") public function __construct(string $period = '', string $filename = "ST.DATA.CAPTURE.csv")
{ {
$this->periods = $periods; $this->period = $period;
$this->filename = $filename; $this->filename = $filename;
} }
@@ -40,27 +40,26 @@
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for data capture processing'); Log::warning('No period provided for data capture processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filepath based on the period folder name // Construct the filepath based on the period folder name
$fileName = "$period.$this->filename"; $fileName = "{$this->period}.{$this->filename}";
$filePath = "$period/$fileName"; $filePath = "{$this->period}/$fileName";
Log::info("Processing data capture file: $filePath"); Log::info("Processing data capture file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -173,7 +172,6 @@
} else { } else {
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Data capture processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Data capture processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -16,20 +16,21 @@
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
* Execute the job. * Execute the job.
*/ */
public function handle(): void public function handle()
: void
{ {
try { try {
set_time_limit(24 * 60 * 60); set_time_limit(24 * 60 * 60);
@@ -37,27 +38,26 @@
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for funds transfer data processing'); Log::warning('No period provided for funds transfer data processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filename based on the period folder name // Construct the filename based on the period folder name
$filename = "$period.ST.FUNDS.TRANSFER.csv"; $filename = "{$this->period}.ST.FUNDS.TRANSFER.csv";
$filePath = "$period/$filename"; $filePath = "{$this->period}/$filename";
Log::info("Processing funds transfer file: $filePath"); Log::info("Processing funds transfer file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -105,7 +105,6 @@
} else { } else {
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Funds Transfer data processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Funds Transfer data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -11,26 +11,26 @@
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Storage;
use Modules\Webstatement\Models\StmtEntry; use Modules\Webstatement\Models\StmtEntry;
use Modules\Webstatement\Models\TempStmtEntry;
class ProcessStmtEntryDataJob implements ShouldQueue class ProcessStmtEntryDataJob implements ShouldQueue
{ {
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods; protected $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
* Execute the job. * Execute the job.
*/ */
public function handle(): void public function handle()
: void
{ {
try { try {
set_time_limit(24 * 60 * 60); set_time_limit(24 * 60 * 60);
@@ -38,27 +38,26 @@
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for statement entry data processing'); Log::warning('No period provided for statement entry data processing');
return; return;
} }
foreach ($this->periods as $period) {
// Skip the _parameter folder // Skip the _parameter folder
if ($period === '_parameter') { if ($this->period === '_parameter') {
Log::info("Skipping _parameter folder"); Log::info("Skipping _parameter folder");
continue; return;
} }
// Construct the filename based on the period folder name // Construct the filename based on the period folder name
$filename = "$period.ST.STMT.ENTRY.csv"; $filename = "{$this->period}.ST.STMT.ENTRY.csv";
$filePath = "$period/$filename"; $filePath = "{$this->period}/$filename";
Log::info("Processing statement entry file: $filePath"); Log::info("Processing statement entry file: $filePath");
if (!$disk->exists($filePath)) { if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath"); Log::warning("File not found: $filePath");
continue; return;
} }
// Create a temporary local copy of the file // Create a temporary local copy of the file
@@ -106,7 +105,6 @@
} else { } else {
Log::error("Unable to open file: $filePath"); Log::error("Unable to open file: $filePath");
} }
}
Log::info("Statement Entry data processing completed. Total processed: $processedCount, Total errors: $errorCount"); Log::info("Statement Entry data processing completed. Total processed: $processedCount, Total errors: $errorCount");

View File

@@ -129,14 +129,14 @@
]; ];
// Pemetaan bidang header ke kolom model // Pemetaan bidang header ke kolom model
protected array $periods; protected string $period;
/** /**
* Create a new job instance. * Create a new job instance.
*/ */
public function __construct(array $periods = []) public function __construct(string $period = '')
{ {
$this->periods = $periods; $this->period = $period;
} }
/** /**
@@ -148,12 +148,18 @@
try { try {
set_time_limit(24 * 60 * 60); set_time_limit(24 * 60 * 60);
if (empty($this->periods)) { if (empty($this->period)) {
Log::warning('No periods provided for teller data processing'); Log::warning('No period provided for teller data processing');
return; return;
} }
$stats = $this->processPeriods(); // Skip the parameter folder
if ($this->period === self::PARAMETER_FOLDER) {
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
return;
}
$stats = $this->processPeriodFile();
Log::info("ProcessTellerDataJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}"); Log::info("ProcessTellerDataJob completed. Total processed: {$stats['processed']}, Total errors: {$stats['errors']}");
} catch (Exception $e) { } catch (Exception $e) {
@@ -163,41 +169,14 @@
} }
/** /**
* Process all periods and return statistics * Process a single period file
*/ */
private function processPeriods() private function processPeriodFile()
: array : array
{ {
$disk = Storage::disk(self::DISK_NAME); $disk = Storage::disk(self::DISK_NAME);
$processedCount = 0; $filename = $this->period . self::FILE_EXTENSION;
$errorCount = 0; $filePath = "{$this->period}/$filename";
foreach ($this->periods as $period) {
// Skip the parameter folder
if ($period === self::PARAMETER_FOLDER) {
Log::info("Skipping " . self::PARAMETER_FOLDER . " folder");
continue;
}
$result = $this->processPeriodFile($disk, $period);
$processedCount += $result['processed'];
$errorCount += $result['errors'];
}
return [
'processed' => $processedCount,
'errors' => $errorCount
];
}
/**
* Process a single period file
*/
private function processPeriodFile($disk, string $period)
: array
{
$filename = $period . self::FILE_EXTENSION;
$filePath = "$period/$filename";
$processedCount = 0; $processedCount = 0;
$errorCount = 0; $errorCount = 0;