fix(qma): track excel location file and make sync command resilient when file missing

This commit is contained in:
Ray1111-aa
2026-11-02 13:35:33 +07:00
parent b8fa1771b9
commit 23377631b3
4 changed files with 28 additions and 20 deletions
+2 -1
View File
@@ -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);
if ($hasExcel) {
$this->info("Total baris terbaca: {$totalRows}"); $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,6 +57,7 @@ class SyncExcelVehicleDataCommand extends Command
DB::beginTransaction(); DB::beginTransaction();
try { try {
if ($hasExcel && $totalRows >= 2) {
for ($i = 1; $i < $totalRows; $i++) { for ($i = 1; $i < $totalRows; $i++) {
$r = $rows[$i]; $r = $rows[$i];
$code1 = trim($r[4] ?? ''); $code1 = trim($r[4] ?? '');
@@ -205,6 +212,7 @@ 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 = [
@@ -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');
} }
/** /**