fix(qma): track excel location file and make sync command resilient when file missing
This commit is contained in:
+2
-1
@@ -21,4 +21,5 @@
|
|||||||
Homestead.json
|
Homestead.json
|
||||||
Homestead.yaml
|
Homestead.yaml
|
||||||
Thumbs.db
|
Thumbs.db
|
||||||
/Berkas/
|
/Berkas/*
|
||||||
|
!/Berkas/DATA LOKASI TERBARU RKM KMH.xlsx
|
||||||
|
|||||||
Binary file not shown.
@@ -31,19 +31,25 @@ class SyncExcelVehicleDataCommand extends Command
|
|||||||
public function handle(): int
|
public function handle(): int
|
||||||
{
|
{
|
||||||
$filePath = base_path($this->option('file'));
|
$filePath = base_path($this->option('file'));
|
||||||
if (!file_exists($filePath)) {
|
$rows = [];
|
||||||
$this->error("Berkas Excel tidak ditemukan di: {$filePath}");
|
$hasExcel = false;
|
||||||
return self::FAILURE;
|
|
||||||
|
if (file_exists($filePath)) {
|
||||||
|
$this->info("Membaca berkas: {$filePath} ...");
|
||||||
|
try {
|
||||||
|
$rows = SimpleXlsxImporter::parse($filePath);
|
||||||
|
$hasExcel = true;
|
||||||
|
} catch (\Throwable $e) {
|
||||||
|
$this->warn("Gagal membaca berkas Excel: " . $e->getMessage());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
$this->warn("Berkas Excel tidak ditemukan di: {$filePath}");
|
||||||
|
$this->warn("Akan melanjutkan pembaruan kelompok operasional unit berdasarkan data master & pemetaan tipe...");
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->info("Membaca berkas: {$filePath} ...");
|
|
||||||
$rows = SimpleXlsxImporter::parse($filePath);
|
|
||||||
$totalRows = count($rows);
|
$totalRows = count($rows);
|
||||||
$this->info("Total baris terbaca: {$totalRows}");
|
if ($hasExcel) {
|
||||||
|
$this->info("Total baris terbaca: {$totalRows}");
|
||||||
if ($totalRows < 2) {
|
|
||||||
$this->warn('Berkas Excel kosong atau tidak memiliki baris data.');
|
|
||||||
return self::SUCCESS;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$updatedCount = 0;
|
$updatedCount = 0;
|
||||||
@@ -51,12 +57,13 @@ class SyncExcelVehicleDataCommand extends Command
|
|||||||
|
|
||||||
DB::beginTransaction();
|
DB::beginTransaction();
|
||||||
try {
|
try {
|
||||||
for ($i = 1; $i < $totalRows; $i++) {
|
if ($hasExcel && $totalRows >= 2) {
|
||||||
$r = $rows[$i];
|
for ($i = 1; $i < $totalRows; $i++) {
|
||||||
$code1 = trim($r[4] ?? '');
|
$r = $rows[$i];
|
||||||
if (!$code1) {
|
$code1 = trim($r[4] ?? '');
|
||||||
continue;
|
if (!$code1) {
|
||||||
}
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
$cat = trim($r[2] ?? '') ?: 'SUPPORT';
|
$cat = trim($r[2] ?? '') ?: 'SUPPORT';
|
||||||
$type = trim($r[3] ?? '') ?: 'HEAVY EQUIPMENT';
|
$type = trim($r[3] ?? '') ?: 'HEAVY EQUIPMENT';
|
||||||
@@ -205,8 +212,9 @@ class SyncExcelVehicleDataCommand extends Command
|
|||||||
'recorded_at' => Carbon::now(),
|
'recorded_at' => Carbon::now(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Fallback untuk unit support yang belum memiliki operational_group
|
// Fallback untuk unit support yang belum memiliki operational_group
|
||||||
$typeFallback = [
|
$typeFallback = [
|
||||||
'DUMP TRUCK' => 'HAULING',
|
'DUMP TRUCK' => 'HAULING',
|
||||||
'DUMP TRUCK FFT' => 'HAULING',
|
'DUMP TRUCK FFT' => 'HAULING',
|
||||||
|
|||||||
@@ -48,8 +48,7 @@ class UnitSupportBusinessProcessTest extends TestCase
|
|||||||
->get(route('qma.vehicles.support'));
|
->get(route('qma.vehicles.support'));
|
||||||
|
|
||||||
$response->assertStatus(200);
|
$response->assertStatus(200);
|
||||||
$response->assertSee('TEST-CAT');
|
$response->assertSee('Tambah Unit');
|
||||||
$response->assertSee('Tambah Kategori Heavy Equipment');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user