refactor(webstatement): update job and model for arrangement processing
- Refactor `ProcessArrangementDataJob`:
- Mengubah parameter dari array periods menjadi string period untuk simplifikasi proses.
- Mengadaptasi logika proses file CSV dari multiple periods menjadi single period.
- Menghapus logika iterasi folder `_parameter` dan menyederhanakan nama file dengan menggunakan single period.
- Menambahkan validasi dan penanganan error jika file tidak ditemukan atau tidak dapat dibuka.
- Menyederhanakan proses membaca dan memproses row dari file CSV dengan pendekatan baru.
- Memperbaiki logging untuk mencatat catatan processing dan error yang lebih tepat.
- Update Model `StmtEntry`:
- Menambahkan relasi baru:
- `tt`: Relasi dengan model `Teller` berdasarkan `trans_reference`.
- `dc`: Relasi dengan model `DataCapture` berdasarkan `trans_reference`.
- `aa`: Relasi dengan model `TempArrangement` berdasarkan `trans_reference`.
Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -16,14 +16,14 @@
|
|||||||
{
|
{
|
||||||
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,69 +37,61 @@
|
|||||||
$processedCount = 0;
|
$processedCount = 0;
|
||||||
$errorCount = 0;
|
$errorCount = 0;
|
||||||
|
|
||||||
if (empty($this->periods)) {
|
if (empty($this->period)) {
|
||||||
Log::warning('No periods provided for arrangement data processing');
|
Log::warning('No period provided for arrangement data processing');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($this->periods as $period) {
|
// Construct the filename based on the period folder name
|
||||||
// Skip the _parameter folder
|
$filename = "{$this->period}.ST.AA.ARRANGEMENT.csv";
|
||||||
if ($period === '_parameter') {
|
$filePath = "{$this->period}/$filename";
|
||||||
Log::info("Skipping _parameter folder");
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Construct the filename based on the period folder name
|
Log::info("Processing arrangement file: $filePath");
|
||||||
$filename = "$period.ST.AA.ARRANGEMENT.csv";
|
|
||||||
$filePath = "$period/$filename";
|
|
||||||
|
|
||||||
Log::info("Processing arrangement file: $filePath");
|
if (!$disk->exists($filePath)) {
|
||||||
|
Log::warning("File not found: $filePath");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (!$disk->exists($filePath)) {
|
// Create a temporary local copy of the file
|
||||||
Log::warning("File not found: $filePath");
|
$tempFilePath = storage_path("app/temp_$filename");
|
||||||
continue;
|
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||||
}
|
|
||||||
|
|
||||||
// Create a temporary local copy of the file
|
$handle = fopen($tempFilePath, "r");
|
||||||
$tempFilePath = storage_path("app/temp_$filename");
|
|
||||||
file_put_contents($tempFilePath, $disk->get($filePath));
|
|
||||||
|
|
||||||
$handle = fopen($tempFilePath, "r");
|
if ($handle !== false) {
|
||||||
|
$headers = (new TempArrangement())->getFillable();
|
||||||
|
$rowCount = 0;
|
||||||
|
|
||||||
if ($handle !== false) {
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
$headers = (new TempArrangement())->getFillable();
|
$rowCount++;
|
||||||
$rowCount = 0;
|
|
||||||
|
|
||||||
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
if (count($headers) === count($row)) {
|
||||||
$rowCount++;
|
$data = array_combine($headers, $row);
|
||||||
|
try {
|
||||||
if (count($headers) === count($row)) {
|
if ($data['arrangement_id'] !== 'arrangement_id') {
|
||||||
$data = array_combine($headers, $row);
|
TempArrangement::updateOrCreate(
|
||||||
try {
|
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
||||||
if ($data['arrangement_id'] !== 'arrangement_id') {
|
$data // data to update or create
|
||||||
TempArrangement::updateOrCreate(
|
);
|
||||||
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
$processedCount++;
|
||||||
$data // data to update or create
|
|
||||||
);
|
|
||||||
$processedCount++;
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
$errorCount++;
|
|
||||||
Log::error("Error processing Arrangement at row $rowCount in $filePath: " . $e->getMessage());
|
|
||||||
}
|
}
|
||||||
} else {
|
} catch (Exception $e) {
|
||||||
Log::warning("Row $rowCount in $filePath has incorrect column count. Expected: " . count($headers) . ", Got: " . count($row));
|
$errorCount++;
|
||||||
|
Log::error("Error processing Arrangement 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");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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("Arrangement data processing completed. Total processed: $processedCount, Total errors: $errorCount");
|
Log::info("Arrangement data processing completed. Total processed: $processedCount, Total errors: $errorCount");
|
||||||
|
|||||||
@@ -64,4 +64,16 @@ class StmtEntry extends Model
|
|||||||
public function transaction(){
|
public function transaction(){
|
||||||
return $this->belongsTo(TempTransaction::class, 'transaction_code', 'transaction_code');
|
return $this->belongsTo(TempTransaction::class, 'transaction_code', 'transaction_code');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function tt(){
|
||||||
|
return $this->belongsTo(Teller::class, 'trans_reference', 'id_teller');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dc(){
|
||||||
|
return $this->belongsTo(DataCapture::class, 'trans_reference', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function aa(){
|
||||||
|
return $this->belongsTo(TempArrangement::class, 'trans_reference', 'arrangement_id');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user