From 5d3a3eecd0239482be907039d0723097bcfcd5da Mon Sep 17 00:00:00 2001 From: Dwi Swandhana Date: Fri, 13 Mar 2026 12:31:48 +0700 Subject: [PATCH] Improve GudangPos barcode fields --- htdocs/app/Livewire/GudangPos.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/htdocs/app/Livewire/GudangPos.php b/htdocs/app/Livewire/GudangPos.php index 32eb3067..d10c1252 100644 --- a/htdocs/app/Livewire/GudangPos.php +++ b/htdocs/app/Livewire/GudangPos.php @@ -62,6 +62,12 @@ class GudangPos extends Component return; } + $saldoBase = $service->getStockBaseByJenis((string) ($jenis->jenis ?? '')); + if ($saldoBase <= 0) { + $this->toast('error', 'Stok kosong untuk ' . ((string) ($jenis->jenis ?? 'barang')) . '.'); + return; + } + $this->selectedKode = (string) ($jenis->kodejenis ?? ''); $this->qty = 1; $this->satuanTransaksi = (string) ($parsed['satuan_transaksi'] ?? 'besar'); @@ -81,6 +87,12 @@ class GudangPos extends Component return; } + $saldoBase = $service->getStockBaseByJenis((string) ($jenis->jenis ?? '')); + if ($saldoBase <= 0) { + $this->toast('error', 'Stok kosong untuk ' . ((string) ($jenis->jenis ?? 'barang')) . '.'); + return; + } + $this->selectedKode = (string) ($jenis->kodejenis ?? ''); $this->qty = 1; $this->syncSatuanAvailability(); @@ -215,7 +227,11 @@ class GudangPos extends Component } if ($qtyBase > $stockCache[$jenisNama]) { - $this->toast('error', 'Stok tidak cukup untuk ' . $jenisNama . '.'); + if ((int) $stockCache[$jenisNama] <= 0) { + $this->toast('error', 'Stok kosong untuk ' . $jenisNama . '.'); + } else { + $this->toast('error', 'Stok tidak cukup untuk ' . $jenisNama . '.'); + } return; } $stockCache[$jenisNama] -= $qtyBase; @@ -301,9 +317,11 @@ class GudangPos extends Component $search = trim((string) $this->search); if ($search !== '') { $searchLike = '%' . $search . '%'; - $query->where(function ($q) use ($searchLike) { - $q->where('jenis', 'LIKE', $searchLike) - ->orWhere('kodejenis', 'LIKE', $searchLike); + $driver = DB::connection()->getDriverName(); + $operator = ($driver === 'pgsql') ? 'ILIKE' : 'LIKE'; + $query->where(function ($q) use ($searchLike, $operator) { + $q->where('jenis', $operator, $searchLike) + ->orWhere('kodejenis', $operator, $searchLike); }); }