From 6decba6cb6120231592e324ede5a63092f737dbc Mon Sep 17 00:00:00 2001 From: sky121113 Date: Thu, 7 May 2026 15:08:01 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E5=84=AA=E5=8C=96=20B009=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5=E6=A9=9F=E5=88=B6=E3=80=81=E5=BA=AB=E5=AD=98=E6=8E=92?= =?UTF-8?q?=E5=BA=8F=E8=88=87=E4=BF=AE=E6=AD=A3=E7=AE=A1=E7=90=86=E5=BE=8C?= =?UTF-8?q?=E5=8F=B0=20UI=20=E9=81=AE=E6=93=8B=E5=95=8F=E9=A1=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 實作 B009 貨道全量同步與拆除 (decommission) 紀錄機制。 2. 優化機台庫存概覽排序邏輯,優先顯示低填充率 (需補貨) 之機台。 3. 修正新增機台 Modal 的 z-index 層級與 overflow 限制,解決下拉選單被蓋住的問題。 4. 修復機台庫存分頁中的 JS 語法錯誤並新增貨道拆除狀態標籤。 --- app/Models/Machine/MachineStockMovement.php | 13 ++++++++++--- app/Services/Machine/MachineService.php | 17 ++++++++++------- lang/en.json | 1 + lang/zh_TW.json | 1 + .../basic-settings/machines/index.blade.php | 4 ++-- .../warehouses/machine-inventory.blade.php | 2 +- 6 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/Models/Machine/MachineStockMovement.php b/app/Models/Machine/MachineStockMovement.php index f246ac8..a96f203 100644 --- a/app/Models/Machine/MachineStockMovement.php +++ b/app/Models/Machine/MachineStockMovement.php @@ -25,15 +25,14 @@ class MachineStockMovement extends Model 'reference_type', 'reference_id', 'note', + 'context', 'created_by', ]; protected $appends = [ 'translated_note', + 'translated_type', ]; - /** - * 動態翻譯備註 - */ public function getTranslatedNoteAttribute(): ?string { if (empty($this->note)) { @@ -43,6 +42,14 @@ class MachineStockMovement extends Model return __($this->note, $this->context ?? []); } + /** + * 動態翻譯類型 + */ + public function getTranslatedTypeAttribute(): string + { + return __("movement.type.{$this->type}"); + } + protected $casts = [ 'quantity' => 'integer', 'before_qty' => 'integer', diff --git a/app/Services/Machine/MachineService.php b/app/Services/Machine/MachineService.php index cce74a2..03c43dc 100644 --- a/app/Services/Machine/MachineService.php +++ b/app/Services/Machine/MachineService.php @@ -246,7 +246,7 @@ class MachineService MachineStockMovement::TYPE_ADJUSTMENT, null, $note, - ['old' => $oldStock, 'new' => $newStock, 'old_product_id' => $oldProductId, 'new_product_id' => $actualProductId] + ['slot_no' => $existingSlot->slot_no, 'old' => $oldStock, 'new' => $newStock, 'old_product_id' => $oldProductId, 'new_product_id' => $actualProductId] ); } } else { @@ -260,7 +260,7 @@ class MachineService MachineStockMovement::TYPE_ADJUSTMENT, null, "movement.note.initial_sync_report", - ['old' => 0, 'new' => $newStock] + ['slot_no' => $slotNo, 'old' => 0, 'new' => $newStock] ); } } @@ -283,19 +283,21 @@ class MachineService foreach ($orphanedSlots as $orphan) { $oldStock = (int) $orphan->stock; - // 先記流水帳(保留歷史可追溯性) if ($oldStock > 0) { + // 先將 stock 設為 0 以便 recordStockMovement 正確計算 before/after + $orphan->stock = 0; + $this->recordStockMovement( $orphan, -$oldStock, - MachineStockMovement::TYPE_DECOMMISSION, + MachineStockMovement::TYPE_ADJUSTMENT, // 使用 adjustment 以確保相容舊版 Enum null, "movement.note.slot_decommissioned_by_b009", ['old' => $oldStock, 'new' => 0, 'slot_no' => $orphan->slot_no] ); } - // 硬刪除貨道(B009 全量同步,機台沒有就不該存在) + // 更新貨道狀態為非使用中或直接刪除 (依據需求決定,目前採刪除以維持 B009 全量同步語意) $orphan->delete(); } }); @@ -356,7 +358,7 @@ class MachineService MachineStockMovement::TYPE_ADJUSTMENT, null, "movement.note.manual_adjustment", - ['old' => $oldData['stock'], 'new' => $stock] + ['slot_no' => $slot->slot_no, 'old' => $oldData['stock'], 'new' => $stock] ); } @@ -443,7 +445,8 @@ class MachineService -1, MachineStockMovement::TYPE_REMOTE_DISPENSE, $command, - "遠端出貨指令 (B055),指令 ID: {$command->id}" + "movement.note.remote_dispense_queued", + ['slot_no' => $slotNo, 'id' => $command->id] ); // 4. 推播 MQTT diff --git a/lang/en.json b/lang/en.json index 3447cb1..47619f7 100644 --- a/lang/en.json +++ b/lang/en.json @@ -1704,6 +1704,7 @@ "movement.note.product_changed_and_adjusted": "B009 report: product changed and stock adjusted (:old → :new)", "movement.note.replenishment_correction": "B009 inventory report correction (old: :old → new: :new)", "movement.note.slot_decommissioned_by_b009": "B009 full sync: slot :slot_no not in report, stock :old cleared and slot removed", + "movement.note.remote_dispense_queued": "Remote dispense command (B055), Command ID: :id", "of": "of", "of items": "of items", "pending": "pending", diff --git a/lang/zh_TW.json b/lang/zh_TW.json index e9df9af..765acc2 100644 --- a/lang/zh_TW.json +++ b/lang/zh_TW.json @@ -1843,6 +1843,7 @@ "movement.note.product_changed_and_adjusted": "B009 廢道商品變更並調整庫存(庫存 :old → :new)", "movement.note.replenishment_correction": "B009 盤點回報修正(舊: :old → 新: :new)", "movement.note.slot_decommissioned_by_b009": "B009 全量同步:貨道 :slot_no 不在回報清單中,庫存 :old 歸零並移除", + "movement.note.remote_dispense_queued": "遠端出貨指令 (B055),指令 ID: :id", "movement.type.adjustment": "盤點調整", "movement.type.decommission": "B009 全量同步移除", "movement.type.pickup": "取貨碼消耗", diff --git a/resources/views/admin/basic-settings/machines/index.blade.php b/resources/views/admin/basic-settings/machines/index.blade.php index 9f79d86..a2eac7c 100644 --- a/resources/views/admin/basic-settings/machines/index.blade.php +++ b/resources/views/admin/basic-settings/machines/index.blade.php @@ -770,7 +770,7 @@ placeholder="{{ __('Enter machine location') }}"> -
+
-
+