diff --git a/app/Http/Controllers/Admin/MachineController.php b/app/Http/Controllers/Admin/MachineController.php index 5f39a41..8df0cd9 100644 --- a/app/Http/Controllers/Admin/MachineController.php +++ b/app/Http/Controllers/Admin/MachineController.php @@ -129,7 +129,6 @@ class MachineController extends AdminController 'stock' => 'nullable|integer|min:0', 'expiry_date' => 'nullable|date', 'batch_no' => 'nullable|string|max:50', - 'apply_all_same_product' => 'boolean' ]); $this->machineService->updateSlot($machine, $validated); diff --git a/app/Services/Machine/MachineService.php b/app/Services/Machine/MachineService.php index c46305a..f2e9898 100644 --- a/app/Services/Machine/MachineService.php +++ b/app/Services/Machine/MachineService.php @@ -105,26 +105,15 @@ class MachineService $stock = $data['stock'] ?? null; $expiryDate = $data['expiry_date'] ?? null; $batchNo = $data['batch_no'] ?? null; - $applyAllSame = $data['apply_all_same_product'] ?? false; + $slot = $machine->slots()->where('slot_no', $slotNo)->firstOrFail(); - $slot = $machine->slots()->where('slot_no', $slotNo)->with('product')->firstOrFail(); - - if ($applyAllSame && $slot->product_id) { - // 更新該機台內所有相同商品的貨道 - $machine->slots()->where('product_id', $slot->product_id)->update([ - 'stock' => $stock !== null ? (int)$stock : DB::raw('stock'), - 'expiry_date' => $expiryDate, - 'batch_no' => $batchNo, - ]); - } else { - // 僅更新單一貨道 - $updateData = [ - 'expiry_date' => $expiryDate, - 'batch_no' => $batchNo, - ]; - if ($stock !== null) $updateData['stock'] = (int)$stock; - $slot->update($updateData); - } + $updateData = [ + 'expiry_date' => $expiryDate, + 'batch_no' => $batchNo, + ]; + if ($stock !== null) $updateData['stock'] = (int)$stock; + + $slot->update($updateData); }); } diff --git a/resources/views/admin/machines/index.blade.php b/resources/views/admin/machines/index.blade.php index 69641f0..54caa08 100644 --- a/resources/views/admin/machines/index.blade.php +++ b/resources/views/admin/machines/index.blade.php @@ -18,11 +18,6 @@ window.machineApp = function() { viewMode: 'fleet', selectedMachine: null, slots: [], - showExpiryModal: false, - selectedSlot: null, - tempExpiry: '', - applyToAllSame: false, - updating: false, init() { const d = new Date(); @@ -46,15 +41,6 @@ window.machineApp = function() { await this.fetchLogs(); }, - async fetchDrawerSlots() { - this.loading = true; - try { - const res = await fetch('/admin/machines/' + this.currentMachineId + '/slots-ajax'); - const data = await res.json(); - if (data.success) this.slots = data.slots; - } catch(e) { console.error('fetchDrawerSlots error:', e); } - finally { this.loading = false; } - }, async fetchLogs() { this.loading = true; @@ -84,64 +70,12 @@ window.machineApp = function() { finally { this.loading = false; } }, - openSlotEdit(slot) { - this.selectedSlot = slot; - this.tempExpiry = slot.expiry_date ? slot.expiry_date.split('T')[0] : ''; - this.applyToAllSame = false; - this.showExpiryModal = true; - }, - - async saveExpiry() { - this.updating = true; - try { - const csrf = document.querySelector('meta[name="csrf-token"]').getAttribute('content'); - const machineId = this.selectedMachine ? this.selectedMachine.id : this.currentMachineId; - const res = await fetch('/admin/machines/' + machineId + '/slots/expiry', { - method: 'POST', - headers: { 'Content-Type': 'application/json', 'X-CSRF-TOKEN': csrf }, - body: JSON.stringify({ - slot_no: this.selectedSlot.slot_no, - expiry_date: this.tempExpiry, - stock: this.selectedSlot.stock, - batch_no: this.selectedSlot.batch_no, - apply_all_same_product: this.applyToAllSame - }) - }); - const data = await res.json(); - if (data.success) { - this.showExpiryModal = false; - if (this.selectedMachine) { - await this.openCabinet(this.selectedMachine.id); - } else { - // Refresh slots in offcanvas - const slotRes = await fetch(`/api/v1/machines/${machineId}/slots`); - const slotData = await slotRes.json(); - this.slots = slotData.slots; - } - } - } catch(e) { console.error('saveExpiry error:', e); } - finally { this.updating = false; } - }, - - getSlotColorClass(slot) { - if (!slot.expiry_date) return 'bg-slate-50/50 dark:bg-slate-800/50 text-slate-400 border-slate-200/60 dark:border-slate-700/50'; - const todayStr = new Date().toISOString().split('T')[0]; - const expiryStr = slot.expiry_date; - if (expiryStr < todayStr) { - return 'bg-rose-50/60 dark:bg-rose-500/10 text-rose-600 dark:text-rose-400 border-rose-200 dark:border-rose-500/30 shadow-sm shadow-rose-500/5'; - } - const diffDays = Math.round((new Date(expiryStr) - new Date(todayStr)) / 86400000); - if (diffDays <= 7) { - return 'bg-amber-50/60 dark:bg-amber-500/10 text-amber-600 dark:text-amber-400 border-amber-200 dark:border-amber-500/30 shadow-sm shadow-amber-500/5'; - } - return 'bg-emerald-50/60 dark:bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 border-emerald-200 dark:border-emerald-500/30 shadow-sm shadow-emerald-500/5'; - } }; };