Files
webstatement/app/Jobs/ProcessFtTxnTypeConditionJob.php
Daeng Deni Mardaeni 6a7a3418b7 fix(webstatement): perbaiki logika kondisi periode kosong di job processing
- Memperbaiki kondisi pengecekan `$this->period` yang salah (ekstra tanda kurung) pada beberapa job processing, seperti:
  1. `ProcessAtmTransactionJob`
  2. `ProcessBillDetailDataJob`
  3. `ProcessCategoryDataJob`
  4. `ProcessCompanyDataJob`
  5. `ProcessCustomerDataJob`
  6. `ProcessDataCaptureDataJob`
  7. `ProcessFundsTransferDataJob`
  8. `ProcessStmtEntryDataJob`
  9. `ProcessTellerDataJob`
- Menambahkan kejelasan logging untuk kasus ketika periode tidak disediakan (`period === ''`).
- Menghapus kode komentar tidak terpakai di `ProcessFtTxnTypeConditionJob`.

Perubahan ini memastikan bahwa logika untuk kondisi periode kosong berjalan dengan benar dan menghindari potensi error di runtime.

Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
2025-05-26 09:12:17 +07:00

114 lines
4.1 KiB
PHP

<?php
namespace Modules\Webstatement\Jobs;
use Exception;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Storage;
use Modules\Webstatement\Models\FtTxnTypeCondition;
class ProcessFtTxnTypeConditionJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
protected $periods;
protected $filename;
/**
* Create a new job instance.
*/
public function __construct(array $periods = [], string $filename = "ST.FT.TXN.TYPE.CONDITION.csv")
{
$this->periods = $periods;
$this->filename = $filename;
}
/**
* Execute the job.
*/
public function handle(): void
{
try {
set_time_limit(24 * 60 * 60);
$disk = Storage::disk('sftpStatement');
$processedCount = 0;
$errorCount = 0;
if (empty($this->periods)) {
Log::warning('No periods provided for transaction type condition data processing');
return;
}
foreach ($this->periods as $period) {
// Construct the filepath based on the period folder name
$filePath = "$period/{$this->filename}";
Log::info("Processing transaction type condition file: $filePath");
if (!$disk->exists($filePath)) {
Log::warning("File not found: $filePath");
continue;
}
// Create a temporary local copy of the file
$tempFilePath = storage_path("app/temp_{$this->filename}");
file_put_contents($tempFilePath, $disk->get($filePath));
$handle = fopen($tempFilePath, "r");
if ($handle !== false) {
$headers = ['id', 'date_time', 'transaction_type', 'short_descr', 'txn_code_cr', 'txn_code_dr'];
$rowCount = 0;
while (($row = fgetcsv($handle, 0, "~")) !== false) {
$rowCount++;
// Skip header row if it exists
if ($rowCount === 1 && strtolower($row[0]) === 'id') {
continue;
}
if (count($headers) === count($row)) {
$data = array_combine($headers, $row);
try {
if (!empty($data['id'])) {
FtTxnTypeCondition::updateOrCreate(
['id' => $data['id']],
$data
);
$processedCount++;
}
} catch (Exception $e) {
$errorCount++;
Log::error("Error processing Transaction Type Condition at row $rowCount in $filePath: " . $e->getMessage());
}
} else {
Log::warning("Row $rowCount in $filePath has incorrect column count. Expected: " . count($headers) . ", Got: " . count($row));
}
}
fclose($handle);
Log::info("Completed processing $filePath. Processed $processedCount records with $errorCount errors.");
// Clean up the temporary file
unlink($tempFilePath);
} else {
Log::error("Unable to open file: $filePath");
}
}
Log::info("Transaction type condition data processing completed. Total processed: $processedCount, Total errors: $errorCount");
} catch (Exception $e) {
Log::error('Error in ProcessFtTxnTypeConditionJob: ' . $e->getMessage());
throw $e;
}
}
}