更新:優化配方詳情彈窗 UI 與一般修正
All checks were successful
Koori-ERP-Deploy-System / deploy-demo (push) Has been skipped
Koori-ERP-Deploy-System / deploy-production (push) Successful in 49s

This commit is contained in:
2026-01-29 16:13:56 +08:00
parent 7619dc24f7
commit 746eeb6f01
23 changed files with 1925 additions and 79 deletions

View File

@@ -8,20 +8,28 @@ use App\Modules\Production\Models\ProductionOrder;
use App\Modules\Production\Models\ProductionOrderItem;
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
use App\Modules\Core\Contracts\CoreServiceInterface;
use App\Modules\Procurement\Contracts\ProcurementServiceInterface;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Inertia\Inertia;
use Inertia\Response;
class ProductionOrderController extends Controller
{
protected $inventoryService;
protected $coreService;
protected $procurementService;
public function __construct(InventoryServiceInterface $inventoryService, CoreServiceInterface $coreService)
public function __construct(
InventoryServiceInterface $inventoryService,
CoreServiceInterface $coreService,
ProcurementServiceInterface $procurementService
)
{
$this->inventoryService = $inventoryService;
$this->coreService = $coreService;
$this->procurementService = $procurementService;
}
/**
@@ -37,9 +45,6 @@ class ProductionOrderController extends Controller
if ($request->filled('search')) {
$search = $request->search;
$query->where(function ($q) use ($search) {
$q->where('code', 'like', "%{$search}%")
->orWhere('output_batch_number', 'like', "%{$search}%");
// 若要搜尋產品名稱,現在需先從 Inventory 查出 IDs
$q->where('code', 'like', "%{$search}%")
->orWhere('output_batch_number', 'like', "%{$search}%");
// 若要搜尋產品名稱,現在需先從 Inventory 查出 IDs
@@ -205,15 +210,29 @@ class ProductionOrderController extends Controller
// 手動水和明細資料
$items = $productionOrder->items;
$inventoryIds = $items->pluck('inventory_id')->unique()->filter()->toArray();
// 修正: 移除跨模組關聯 sourcePurchaseOrder.vendor
$inventories = $this->inventoryService->getInventoriesByIds(
$inventoryIds,
['product.baseUnit', 'sourcePurchaseOrder.vendor']
['product.baseUnit']
)->keyBy('id');
// 手動載入 Purchase Orders
$poIds = $inventories->pluck('source_purchase_order_id')->unique()->filter()->toArray();
$purchaseOrders = collect();
if (!empty($poIds)) {
$purchaseOrders = $this->procurementService->getPurchaseOrdersByIds($poIds, ['vendor'])->keyBy('id');
}
$units = $this->inventoryService->getUnits()->keyBy('id');
foreach ($items as $item) {
$item->inventory = $inventories->get($item->inventory_id);
if ($item->inventory) {
// 手動掛載 PO
$poId = $item->inventory->source_purchase_order_id;
$item->inventory->sourcePurchaseOrder = $purchaseOrders->get($poId);
}
$item->unit = $units->get($item->unit_id);
}