feat(statement-processing): update StmtEntry model and optimize data processing logic
- Menambahkan relasi baru pada model `StmtEntry`: - `ft()` untuk relasi ke model `TempFundsTransfer` berdasarkan kolom `trans_reference`. - `transaction()` untuk relasi ke model `TempTransaction` berdasarkan kolom `transaction_code`. - Memperbarui `ProcessStmtEntryDataJob`: - Mengganti penggunaan model `TempStmtEntry` menjadi `StmtEntry`. - Mengubah delimiter parsing file CSV dari `/` menjadi `~`. - Menggunakan `stmt_entry_id` sebagai kunci utama dalam metode `updateOrCreate`. - Menghapus validasi kolom `_id` pada data yang diproses. Perubahan ini bertujuan untuk menyelaraskan model dan cara proses data agar lebih akurat dan sesuai dengan kebutuhan sistem.
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
use Illuminate\Queue\SerializesModels;
|
use Illuminate\Queue\SerializesModels;
|
||||||
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\TempStmtEntry;
|
use Modules\Webstatement\Models\TempStmtEntry;
|
||||||
|
|
||||||
class ProcessStmtEntryDataJob implements ShouldQueue
|
class ProcessStmtEntryDataJob implements ShouldQueue
|
||||||
@@ -67,22 +68,20 @@
|
|||||||
$handle = fopen($tempFilePath, "r");
|
$handle = fopen($tempFilePath, "r");
|
||||||
|
|
||||||
if ($handle !== false) {
|
if ($handle !== false) {
|
||||||
$headers = (new TempStmtEntry())->getFillable();
|
$headers = (new StmtEntry())->getFillable();
|
||||||
$rowCount = 0;
|
$rowCount = 0;
|
||||||
|
|
||||||
while (($row = fgetcsv($handle, 0, "/")) !== false) {
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
$rowCount++;
|
$rowCount++;
|
||||||
|
|
||||||
if (count($headers) === count($row)) {
|
if (count($headers) === count($row)) {
|
||||||
$data = array_combine($headers, $row);
|
$data = array_combine($headers, $row);
|
||||||
try {
|
try {
|
||||||
if (isset($data['_id']) && $data['_id'] !== '_id') {
|
StmtEntry::updateOrCreate(
|
||||||
TempStmtEntry::updateOrCreate(
|
['stmt_entry_id' => $data['stmt_entry_id']],
|
||||||
['_id' => $data['_id']],
|
$data
|
||||||
$data
|
);
|
||||||
);
|
$processedCount++;
|
||||||
$processedCount++;
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
$errorCount++;
|
$errorCount++;
|
||||||
Log::error("Error processing Statement Entry at row $rowCount in $filePath: " . $e->getMessage());
|
Log::error("Error processing Statement Entry at row $rowCount in $filePath: " . $e->getMessage());
|
||||||
|
|||||||
@@ -56,4 +56,12 @@ class StmtEntry extends Model
|
|||||||
{
|
{
|
||||||
return $this->belongsTo(Account::class, 'account_number', 'account_number');
|
return $this->belongsTo(Account::class, 'account_number', 'account_number');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function ft(){
|
||||||
|
return $this->belongsTo(TempFundsTransfer::class, 'trans_reference', 'ref_no');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function transaction(){
|
||||||
|
return $this->belongsTo(TempTransaction::class, 'transaction_code', 'transaction_code');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user