From 62d3242db5a6c79f70f6eb7fa44c6f942092f305 Mon Sep 17 00:00:00 2001 From: sky121113 Date: Tue, 23 Jun 2026 15:27:31 +0800 Subject: [PATCH] =?UTF-8?q?[FIX]=20=E8=A3=9C=E8=B2=A8=E5=96=AE=E6=AD=B8?= =?UTF-8?q?=E5=B1=AC=E6=94=B9=E4=BB=A5=E6=A9=9F=E5=8F=B0=E6=89=80=E7=B6=81?= =?UTF-8?q?=E5=85=AC=E5=8F=B8=E7=82=BA=E6=BA=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. storeReplenishment / autoReplenishment 建單時 company_id 由「建立者」改為「機台的 company_id」 2. 修正系統管理員為他公司機台建單時 company_id 被寫成 null,導致篩選列選公司及租戶帳號登入皆看不到補貨單 3. 新增 migration 依機台回填既有舊單據的 company_id Co-Authored-By: Claude Opus 4.8 (1M context) --- .../Controllers/Admin/WarehouseController.php | 15 ++++++---- ...eplenishment_orders_company_by_machine.php | 28 +++++++++++++++++++ 2 files changed, 37 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2026_06_23_120000_backfill_replenishment_orders_company_by_machine.php diff --git a/app/Http/Controllers/Admin/WarehouseController.php b/app/Http/Controllers/Admin/WarehouseController.php index 6b603f7..5c6411e 100644 --- a/app/Http/Controllers/Admin/WarehouseController.php +++ b/app/Http/Controllers/Admin/WarehouseController.php @@ -877,7 +877,10 @@ class WarehouseController extends Controller 'items.*.quantity.min' => __('Please enter valid quantity for item :num', ['num' => ':position']), ]); - DB::transaction(function () use ($validated) { + // 補貨針對機台,單據歸屬以「機台所綁公司」為準(系統管理員可為他公司機台建單) + $machine = Machine::findOrFail($validated['machine_id']); + + DB::transaction(function () use ($validated, $machine) { $prefix = 'RP-' . now()->format('Ymd') . '-'; $lastOrder = ReplenishmentOrder::withoutGlobalScopes() ->withTrashed() @@ -889,10 +892,10 @@ class WarehouseController extends Controller $order_no = $prefix . str_pad($nextNumber, 4, '0', STR_PAD_LEFT); $order = ReplenishmentOrder::create([ - 'company_id' => Auth::user()->company_id, + 'company_id' => $machine->company_id, 'order_no' => $order_no, 'warehouse_id' => $validated['warehouse_id'], - 'machine_id' => $validated['machine_id'], + 'machine_id' => $machine->id, 'status' => ReplenishmentOrder::STATUS_PENDING, 'note' => $validated['note'] ?? null, 'created_by' => Auth::id(), @@ -1011,7 +1014,7 @@ class WarehouseController extends Controller } // 有 items = 確認建單 - DB::transaction(function () use ($validated) { + DB::transaction(function () use ($validated, $machine) { $prefix = 'RP-' . now()->format('Ymd') . '-'; $lastOrder = ReplenishmentOrder::withoutGlobalScopes() ->withTrashed() @@ -1023,10 +1026,10 @@ class WarehouseController extends Controller $order_no = $prefix . str_pad($nextNumber, 4, '0', STR_PAD_LEFT); $order = ReplenishmentOrder::create([ - 'company_id' => Auth::user()->company_id, + 'company_id' => $machine->company_id, 'order_no' => $order_no, 'warehouse_id' => $validated['warehouse_id'], - 'machine_id' => $validated['machine_id'], + 'machine_id' => $machine->id, 'status' => ReplenishmentOrder::STATUS_PENDING, 'note' => $validated['note'] ?? __('Auto Replenishment'), 'created_by' => Auth::id(), diff --git a/database/migrations/2026_06_23_120000_backfill_replenishment_orders_company_by_machine.php b/database/migrations/2026_06_23_120000_backfill_replenishment_orders_company_by_machine.php new file mode 100644 index 0000000..f49e5bf --- /dev/null +++ b/database/migrations/2026_06_23_120000_backfill_replenishment_orders_company_by_machine.php @@ -0,0 +1,28 @@ + m.company_id) + SQL); + } + + public function down(): void + { + // 資料校正,無法可靠還原 + } +};