feat: optimize B009 stock sync with full-sync logic and historical slot filtering
This commit is contained in:
parent
eb55a25ca8
commit
053c41d642
@ -607,10 +607,18 @@ class WarehouseController extends Controller
|
||||
->orderByRaw('CAST(slot_no AS UNSIGNED) ASC')
|
||||
->get();
|
||||
|
||||
// 取得流水帳中出現過的所有貨道編號 (包含已移除的)
|
||||
$historicalSlotNos = MachineStockMovement::where('machine_id', $machine->id)
|
||||
->distinct()
|
||||
->pluck('slot_no')
|
||||
->map(fn($val) => (string)$val)
|
||||
->toArray();
|
||||
|
||||
return response()->json([
|
||||
'success' => true,
|
||||
'machine' => $machine,
|
||||
'slots' => $slots
|
||||
'slots' => $slots,
|
||||
'historical_slot_nos' => $historicalSlotNos
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@ -888,19 +888,23 @@ document.addEventListener('alpine:init', () => {
|
||||
updateSlotSelect() {
|
||||
if (!this.movementsMachine) return;
|
||||
const machineId = this.movementsMachine.id;
|
||||
if (this.selectedMachine && this.selectedMachine.id == machineId && this.slots.length > 0) {
|
||||
this.movementsSlots = this.slots.map(s => s.slot_no);
|
||||
this.rebuildSlotSelect();
|
||||
} else {
|
||||
fetch(`/admin/warehouses/machine-inventory/${machineId}/slots`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
this.movementsSlots = (data.slots || []).map(s => s.slot_no);
|
||||
this.rebuildSlotSelect();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 每次開啟都重新抓取,以確保取得包含已移除貨道的完整清單
|
||||
fetch(`/admin/warehouses/machine-inventory/${machineId}/slots`)
|
||||
.then(res => res.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
// 優先使用歷史貨道清單 (由 Controller 新增回傳)
|
||||
let slotNos = data.historical_slot_nos || (data.slots || []).map(s => s.slot_no);
|
||||
|
||||
// 數字排序確保 UI 體驗一致
|
||||
this.movementsSlots = [...new Set(slotNos)].sort((a, b) => {
|
||||
return parseInt(a) - parseInt(b);
|
||||
});
|
||||
|
||||
this.rebuildSlotSelect();
|
||||
}
|
||||
});
|
||||
},
|
||||
|
||||
rebuildSlotSelect() {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user