fix(webstatement): perbaikan parameter dan refactor pada ProcessCompanyDataJob
- Mengubah parameter pada pemanggilan `$this->ProcessCompanyData()` dari array menjadi string untuk konsistensi data. - Mengubah properti `protected` pada `ProcessCompanyDataJob` dari `$periods` menjadi `$period` untuk menggunakan string daripada array. - Menyesuaikan constructor `__construct` untuk menerima parameter string `$period` alih-alih array `$periods`. - Memperbaiki mekanisme validasi pada `handle()`, mengganti pengecekan array kosong `$this->periods` menjadi validasi string `$this->period` dengan nilai kosong. - Menghapus iterasi `foreach` untuk mengakomodasi perubahan dari array ke string sederhana. - Memastikan mapping data CSV tetap konsisten dan menambahkan identasi untuk peningkatan keterbacaan. - Memperbaiki nama variabel dan properti agar lebih eksplisit (`$periods` menjadi `$period`, `$fileName` menjadi `$fileName`, dsb.). - Menambahkan logging yang lebih jelas mengenai proses data dan kondisi error pada job `ProcessCompanyDataJob`. Signed-off-by: Daeng Deni Mardaeni <ddeni05@gmail.com>
This commit is contained in:
@@ -253,7 +253,7 @@ 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]);
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ namespace Modules\Webstatement\Jobs;
|
|||||||
|
|
||||||
use Exception;
|
use Exception;
|
||||||
use Illuminate\Bus\Queueable;
|
use Illuminate\Bus\Queueable;
|
||||||
use Illuminate\Queue\SerializesModels;
|
|
||||||
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\Queue\SerializesModels;
|
||||||
use Illuminate\Support\Facades\Log;
|
use Illuminate\Support\Facades\Log;
|
||||||
use Illuminate\Support\Facades\Storage;
|
use Illuminate\Support\Facades\Storage;
|
||||||
use Modules\Basicdata\Models\Branch;
|
use Modules\Basicdata\Models\Branch;
|
||||||
@@ -16,22 +16,23 @@ class ProcessCompanyDataJob implements ShouldQueue
|
|||||||
{
|
{
|
||||||
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.COMPANY.csv")
|
public function __construct(string $period = '', string $filename = "ST.COMPANY.csv")
|
||||||
{
|
{
|
||||||
$this->periods = $periods;
|
$this->period = $period;
|
||||||
$this->filename = $filename;
|
$this->filename = $filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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);
|
||||||
@@ -39,27 +40,26 @@ class ProcessCompanyDataJob implements ShouldQueue
|
|||||||
$processedCount = 0;
|
$processedCount = 0;
|
||||||
$errorCount = 0;
|
$errorCount = 0;
|
||||||
|
|
||||||
if (empty($this->periods)) {
|
if (empty($this->period)) {
|
||||||
Log::warning('No periods provided for company data processing');
|
Log::warning('No period provided for company 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 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 company file: $filePath");
|
Log::info("Processing company 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
|
||||||
@@ -71,9 +71,19 @@ class ProcessCompanyDataJob implements ShouldQueue
|
|||||||
if ($handle !== false) {
|
if ($handle !== false) {
|
||||||
// CSV headers from the file
|
// CSV headers from the file
|
||||||
$csvHeaders = [
|
$csvHeaders = [
|
||||||
'id', 'date_time', 'company_code', 'company_name', 'name_address',
|
'id',
|
||||||
'mnemonic', 'customer_company', 'customer_mnemonic', 'company_group',
|
'date_time',
|
||||||
'curr_no', 'co_code', 'l_vendor_atm', 'l_vendor_cpc'
|
'company_code',
|
||||||
|
'company_name',
|
||||||
|
'name_address',
|
||||||
|
'mnemonic',
|
||||||
|
'customer_company',
|
||||||
|
'customer_mnemonic',
|
||||||
|
'company_group',
|
||||||
|
'curr_no',
|
||||||
|
'co_code',
|
||||||
|
'l_vendor_atm',
|
||||||
|
'l_vendor_cpc'
|
||||||
];
|
];
|
||||||
|
|
||||||
// Field mapping from CSV to Branch model
|
// Field mapping from CSV to Branch model
|
||||||
@@ -142,7 +152,6 @@ class ProcessCompanyDataJob implements ShouldQueue
|
|||||||
} else {
|
} else {
|
||||||
Log::error("Unable to open file: $filePath");
|
Log::error("Unable to open file: $filePath");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Log::info("Company data processing completed. Total processed: $processedCount, Total errors: $errorCount");
|
Log::info("Company data processing completed. Total processed: $processedCount, Total errors: $errorCount");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user