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') }}"> -