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;
|
||||
|
||||
protected $periods;
|
||||
protected string $period;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
$errorCount = 0;
|
||||
|
||||
if (empty($this->periods)) {
|
||||
Log::warning('No periods provided for arrangement data processing');
|
||||
if (empty($this->period)) {
|
||||
Log::warning('No period provided for arrangement data processing');
|
||||
return;
|
||||
}
|
||||
|
||||
foreach ($this->periods as $period) {
|
||||
// Skip the _parameter folder
|
||||
if ($period === '_parameter') {
|
||||
Log::info("Skipping _parameter folder");
|
||||
continue;
|
||||
}
|
||||
// Construct the filename based on the period folder name
|
||||
$filename = "{$this->period}.ST.AA.ARRANGEMENT.csv";
|
||||
$filePath = "{$this->period}/$filename";
|
||||
|
||||
// Construct the filename based on the period folder name
|
||||
$filename = "$period.ST.AA.ARRANGEMENT.csv";
|
||||
$filePath = "$period/$filename";
|
||||
Log::info("Processing arrangement file: $filePath");
|
||||
|
||||
Log::info("Processing arrangement file: $filePath");
|
||||
if (!$disk->exists($filePath)) {
|
||||
Log::warning("File not found: $filePath");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$disk->exists($filePath)) {
|
||||
Log::warning("File not found: $filePath");
|
||||
continue;
|
||||
}
|
||||
// Create a temporary local copy of the file
|
||||
$tempFilePath = storage_path("app/temp_$filename");
|
||||
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||
|
||||
// Create a temporary local copy of the file
|
||||
$tempFilePath = storage_path("app/temp_$filename");
|
||||
file_put_contents($tempFilePath, $disk->get($filePath));
|
||||
$handle = fopen($tempFilePath, "r");
|
||||
|
||||
$handle = fopen($tempFilePath, "r");
|
||||
if ($handle !== false) {
|
||||
$headers = (new TempArrangement())->getFillable();
|
||||
$rowCount = 0;
|
||||
|
||||
if ($handle !== false) {
|
||||
$headers = (new TempArrangement())->getFillable();
|
||||
$rowCount = 0;
|
||||
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||
$rowCount++;
|
||||
|
||||
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||
$rowCount++;
|
||||
|
||||
if (count($headers) === count($row)) {
|
||||
$data = array_combine($headers, $row);
|
||||
try {
|
||||
if ($data['arrangement_id'] !== 'arrangement_id') {
|
||||
TempArrangement::updateOrCreate(
|
||||
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
||||
$data // data to update or create
|
||||
);
|
||||
$processedCount++;
|
||||
}
|
||||
} catch (Exception $e) {
|
||||
$errorCount++;
|
||||
Log::error("Error processing Arrangement at row $rowCount in $filePath: " . $e->getMessage());
|
||||
if (count($headers) === count($row)) {
|
||||
$data = array_combine($headers, $row);
|
||||
try {
|
||||
if ($data['arrangement_id'] !== 'arrangement_id') {
|
||||
TempArrangement::updateOrCreate(
|
||||
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
||||
$data // data to update or create
|
||||
);
|
||||
$processedCount++;
|
||||
}
|
||||
} else {
|
||||
Log::warning("Row $rowCount in $filePath has incorrect column count. Expected: " . count($headers) . ", Got: " . count($row));
|
||||
} catch (Exception $e) {
|
||||
$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");
|
||||
|
||||
Reference in New Issue
Block a user