[REFACTOR] 移除機台管理與庫存設定中的貨道同步套用功能與日誌面板冗餘分頁
All checks were successful
star-cloud-deploy-demo / deploy-demo (push) Successful in 46s

1. 移除 MachineController 貨道更新 API 的 apply_all_same_product 驗證規則。
2. 簡化 MachineService 的 updateSlot 邏輯,取消「同步套用至同機台其他相同商品」的批次異動功能以確保資料準確性。
3. 清理 index.blade.php 機台管理頁面中的「貨道狀態 (Slot Status)」分頁、相關 Alpine.js 函式與專用的貨道編輯 Modal。
4. 修正 stock.blade.php 庫存管理介面,移除編輯 Modal 內的同步切換開關。
This commit is contained in:
2026-04-01 16:10:40 +08:00
parent 969e4df629
commit 3dbb394862
4 changed files with 11 additions and 280 deletions

View File

@@ -129,7 +129,6 @@ class MachineController extends AdminController
'stock' => 'nullable|integer|min:0', 'stock' => 'nullable|integer|min:0',
'expiry_date' => 'nullable|date', 'expiry_date' => 'nullable|date',
'batch_no' => 'nullable|string|max:50', 'batch_no' => 'nullable|string|max:50',
'apply_all_same_product' => 'boolean'
]); ]);
$this->machineService->updateSlot($machine, $validated); $this->machineService->updateSlot($machine, $validated);

View File

@@ -105,26 +105,15 @@ class MachineService
$stock = $data['stock'] ?? null; $stock = $data['stock'] ?? null;
$expiryDate = $data['expiry_date'] ?? null; $expiryDate = $data['expiry_date'] ?? null;
$batchNo = $data['batch_no'] ?? 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(); $updateData = [
'expiry_date' => $expiryDate,
'batch_no' => $batchNo,
];
if ($stock !== null) $updateData['stock'] = (int)$stock;
if ($applyAllSame && $slot->product_id) { $slot->update($updateData);
// 更新該機台內所有相同商品的貨道
$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);
}
}); });
} }

View File

@@ -18,11 +18,6 @@ window.machineApp = function() {
viewMode: 'fleet', viewMode: 'fleet',
selectedMachine: null, selectedMachine: null,
slots: [], slots: [],
showExpiryModal: false,
selectedSlot: null,
tempExpiry: '',
applyToAllSame: false,
updating: false,
init() { init() {
const d = new Date(); const d = new Date();
@@ -46,15 +41,6 @@ window.machineApp = function() {
await this.fetchLogs(); 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() { async fetchLogs() {
this.loading = true; this.loading = true;
@@ -84,64 +70,12 @@ window.machineApp = function() {
finally { this.loading = false; } 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';
}
}; };
}; };
</script> </script>
<div class="space-y-4 pb-20 mt-4" x-data="machineApp()" <div class="space-y-4 pb-20 mt-4" x-data="machineApp()"
@keydown.escape.window="showExpiryModal = false; showLogPanel = false"> @keydown.escape.window="showLogPanel = false">
<!-- Top Header & Actions --> <!-- Top Header & Actions -->
<div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4"> <div class="flex flex-col md:flex-row md:items-center md:justify-between gap-4">
<div class="flex items-center gap-4"> <div class="flex items-center gap-4">
@@ -445,11 +379,6 @@ window.machineApp = function() {
class="whitespace-nowrap py-4 px-1 border-b-2 font-bold text-[13px] sm:text-sm transition duration-300"> class="whitespace-nowrap py-4 px-1 border-b-2 font-bold text-[13px] sm:text-sm transition duration-300">
{{ __('Device Status Logs') }} {{ __('Device Status Logs') }}
</button> </button>
<button @click="activeTab = 'expiry'; fetchDrawerSlots()"
:class="{'border-cyan-500 text-cyan-600 dark:text-cyan-400': activeTab === 'expiry', 'border-transparent text-slate-500 hover:text-slate-700 hover:border-slate-300 dark:hover:text-slate-300': activeTab !== 'expiry'}"
class="whitespace-nowrap py-4 px-1 border-b-2 font-bold text-[13px] sm:text-sm transition duration-300">
{{ __('Slot Status') }}
</button>
</nav> </nav>
</div> </div>
@@ -565,58 +494,6 @@ window.machineApp = function() {
</template> </template>
</div> </div>
<!-- Expiry Tab Content -->
<div x-show="activeTab === 'expiry'" class="space-y-6">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
<template x-for="slot in slots" :key="slot.id">
<div
class="p-4 rounded-2xl bg-white dark:bg-slate-800 border border-slate-100 dark:border-slate-700 shadow-sm flex items-center justify-between transition-all hover:border-cyan-500/30">
<div class="flex items-center gap-3">
<div :class="getSlotColorClass(slot)"
class="w-10 h-10 rounded-xl flex items-center justify-center font-black text-xs border">
<span x-text="slot.slot_no"></span>
</div>
<div class="min-w-0">
<div class="text-[13px] font-bold text-slate-800 dark:text-white leading-tight truncate"
x-text="slot.product ? slot.product.name : 'Unknown Product'">
</div>
<div class="text-[10px] font-black text-slate-400 uppercase tracking-widest mt-1"
x-text="slot.expiry_date ? slot.expiry_date.split('T')[0] : '{{ __('Pending') }}'">
</div>
</div>
</div>
<button @click="openSlotEdit(slot)"
class="p-2 rounded-lg bg-slate-50 dark:bg-slate-800 text-slate-400 hover:text-cyan-500 hover:bg-cyan-500/5 dark:hover:bg-cyan-500/10 border border-transparent hover:border-cyan-500/20 transition-all inline-flex group/btn shadow-sm">
<svg class="w-4 h-4 stroke-[2.5] group-hover:scale-110 transition-transform"
fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round"
d="M11 5H6a2 2 0 00-2 2v11a2 2 0 002 2h11a2 2 0 002-2v-5m-1.414-9.414a2 2 0 112.828 2.828L11.828 15H9v-2.828l8.586-8.586z" />
</svg>
</button>
</div>
</template>
</div>
<template x-if="slots.length === 0 && !loading">
<div class="py-20 text-center">
<div class="flex flex-col items-center">
<div
class="p-4 rounded-full bg-slate-50 dark:bg-slate-800/50 mb-4 border border-slate-100 dark:border-slate-800/50">
<svg class="w-8 h-8 text-slate-300 dark:text-slate-600"
viewBox="0 0 24 24" fill="none" stroke="currentColor"
stroke-width="1.5">
<path
d="M21 7v10c0 1.1-.9 2-2 2H5c-1.1 0-2-.9-2-2V7c0-1.1.9-2 2-2h14c1.1 0 2 .9 2 2z" />
<path d="M12 11l4-4" />
<path d="M8 15l4-4" />
</svg>
</div>
<span
class="text-[11px] font-bold text-slate-400 dark:text-slate-500 uppercase tracking-widest">{{
__('No slots found') }}</span>
</div>
</div>
</template>
</div>
</div> </div>
</div> </div>
@@ -627,125 +504,4 @@ window.machineApp = function() {
</div> </div>
</div><!-- /Offcanvas --> </div><!-- /Offcanvas -->
<!-- Slot Expiry Edit Modal -->
<div x-show="showExpiryModal" class="fixed inset-0 z-[110] overflow-y-auto" style="display: none;" x-cloak>
<div class="flex items-center justify-center min-h-screen p-4 text-center">
<div x-show="showExpiryModal" x-transition:enter="ease-out duration-300" x-transition:enter-start="opacity-0"
x-transition:enter-end="opacity-100" x-transition:leave="ease-in duration-200"
x-transition:leave-start="opacity-100" x-transition:leave-end="opacity-0"
class="fixed inset-0 bg-slate-900/60 backdrop-blur-sm transition-opacity" @click="showExpiryModal = false">
</div>
<div x-show="showExpiryModal" x-transition:enter="ease-out duration-300"
x-transition:enter-start="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
x-transition:enter-end="opacity-100 translate-y-0 sm:scale-100" x-transition:leave="ease-in duration-200"
x-transition:leave-start="opacity-100 translate-y-0 sm:scale-100"
x-transition:leave-end="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
class="relative bg-white dark:bg-slate-900 rounded-[2rem] p-6 text-left overflow-hidden shadow-2xl transform transition-all sm:max-w-lg sm:w-full border border-slate-100 dark:border-slate-800">
<div class="flex items-center justify-between mb-6">
<h3 class="text-xl font-black text-slate-800 dark:text-white font-display flex items-center gap-3">
<div class="w-8 h-8 rounded-xl bg-cyan-500/10 flex items-center justify-center text-cyan-600">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5"
d="M20 7l-8-4-8 4m16 0l-8 4m8-4v10l-8 4m0-10L4 7m8 4v10M4 7v10l8 4" />
</svg>
</div>
{{ __('Edit Stock & Expiry') }}
</h3>
<button @click="showExpiryModal = false" class="text-slate-400 hover:text-slate-600 transition-colors">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2"
d="M6 18L18 6M6 6l12 12" />
</svg>
</button>
</div>
<template x-if="selectedSlot">
<div class="space-y-6">
<!-- Slot Header Info -->
<div
class="flex items-center gap-4 p-4 rounded-2xl bg-slate-50 dark:bg-slate-800/50 border border-slate-100 dark:border-slate-800">
<div class="flex-shrink-0 w-16 h-16 rounded-xl bg-slate-100 dark:bg-slate-800 flex items-center justify-center p-2 overflow-hidden">
<template x-if="selectedSlot.product && selectedSlot.product.image_url">
<img :src="selectedSlot.product.image_url" class="w-full h-full object-contain">
</template>
<template x-if="!selectedSlot.product || !selectedSlot.product.image_url">
<svg class="w-8 h-8 text-slate-300 dark:text-slate-600" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="1.5" d="M4 16l4.586-4.586a2 2 0 012.828 0L16 16m-2-2l1.586-1.586a2 2 0 012.828 0L20 14m-6-6h.01M6 20h12a2 2 0 002-2V6a2 2 0 00-2-2H6a2 2 0 00-2 2v12a2 2 0 002 2z" /></svg>
</template>
</div>
<div>
<div class="text-[10px] font-black text-slate-400 uppercase tracking-widest">{{ __('Slot')
}}
<span x-text="selectedSlot.slot_no"></span>
</div>
<div class="text-base font-black text-slate-800 dark:text-white"
x-text="selectedSlot.product ? selectedSlot.product.name : 'Unknown Product'"></div>
</div>
</div>
<!-- Input Fields -->
<div class="grid grid-cols-2 gap-4">
<div>
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2">{{
__('Stock') }}</label>
<input type="number" x-model="selectedSlot.stock"
class="luxury-input w-full py-2.5 px-4 text-base font-black" placeholder="0">
</div>
<div>
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2">{{
__('Expiry Date') }}</label>
<input type="date" x-model="tempExpiry"
class="luxury-input w-full py-2.5 px-4 text-base font-black">
</div>
</div>
<div>
<label class="block text-xs font-black text-slate-500 uppercase tracking-widest mb-2">{{
__('Batch No') }}</label>
<input type="text" x-model="selectedSlot.batch_no"
class="luxury-input w-full py-2.5 px-4 font-bold" placeholder="{{ __('Optional') }}">
</div>
<!-- Sync Options -->
<div class="p-4 rounded-2xl bg-cyan-500/5 border border-cyan-500/10">
<label class="flex items-center gap-3 cursor-pointer group">
<div class="relative">
<input type="checkbox" x-model="applyToAllSame" class="peer sr-only">
<div
class="w-12 h-6 bg-slate-200 dark:bg-slate-700 rounded-full transition-colors peer-checked:bg-cyan-500">
</div>
<div
class="absolute left-1 top-1 w-4 h-4 bg-white rounded-full transition-transform peer-checked:translate-x-6">
</div>
</div>
<span
class="text-sm font-bold text-slate-600 dark:text-slate-400 group-hover:text-cyan-600 transition-colors">{{
__('Apply to all identical products in this machine') }}</span>
</label>
</div>
<!-- Save Button -->
<button @click="saveExpiry()"
class="w-full py-3 rounded-2xl bg-slate-900 dark:bg-cyan-600 text-white font-black hover:bg-cyan-600 dark:hover:bg-cyan-500 transition-all duration-300 shadow-xl shadow-cyan-500/20 flex items-center justify-center gap-3 group">
<svg x-show="!updating" class="w-5 h-5 group-hover:scale-110 transition-transform" fill="none"
stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2.5"
d="M5 13l4 4L19 7" />
</svg>
<svg x-show="updating" class="animate-spin h-5 w-5 text-white"
xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24">
<circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4">
</circle>
<path class="opacity-75" fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z">
</path>
</svg>
<span x-text="updating ? '{{ __('Saving...') }}' : '{{ __('Save Changes') }}'"></span>
</button>
</div>
</template>
</div>
</div>
</div>
@endsection @endsection

View File

@@ -14,12 +14,10 @@ window.stockApp = function(initialMachineId) {
// Modal State // Modal State
showEditModal: false, showEditModal: false,
selectedSlot: null,
formData: { formData: {
stock: 0, stock: 0,
expiry_date: '', expiry_date: '',
batch_no: '', batch_no: ''
apply_all_same_product: false
}, },
async init() { async init() {
@@ -73,8 +71,7 @@ window.stockApp = function(initialMachineId) {
this.formData = { this.formData = {
stock: slot.stock || 0, stock: slot.stock || 0,
expiry_date: slot.expiry_date ? slot.expiry_date.split('T')[0] : '', expiry_date: slot.expiry_date ? slot.expiry_date.split('T')[0] : '',
batch_no: slot.batch_no || '', batch_no: slot.batch_no || ''
apply_all_same_product: false
}; };
this.showEditModal = true; this.showEditModal = true;
}, },
@@ -444,16 +441,6 @@ window.stockApp = function(initialMachineId) {
</div> </div>
</div> </div>
<!-- Toggle: Apply to all -->
<div class="pt-4 border-t border-slate-100 dark:border-slate-800/50">
<label class="relative inline-flex items-center cursor-pointer group">
<input type="checkbox" x-model="formData.apply_all_same_product" class="sr-only peer">
<div class="w-11 h-6 bg-slate-200 dark:bg-slate-800 peer-focus:outline-none rounded-full peer peer-checked:after:translate-x-full peer-checked:after:border-white after:content-[''] after:absolute after:top-[2px] after:left-[2px] after:bg-white after:border-slate-300 after:border after:rounded-full after:h-5 after:w-5 after:transition-all peer-checked:bg-cyan-500 transition-all duration-300"></div>
<span class="ml-4 text-xs font-black text-slate-500 dark:text-slate-400 uppercase tracking-widest group-hover:text-cyan-600 transition-colors">
{{ __('Apply changes to all identical products in this machine') }}
</span>
</label>
</div>
</div> </div>
<!-- Footer Actions --> <!-- Footer Actions -->