refactor(modular): 完成第二階段儀表板解耦與模型清理
This commit is contained in:
@@ -7,7 +7,7 @@ use App\Http\Controllers\Controller;
|
||||
use App\Modules\Production\Models\ProductionOrder;
|
||||
use App\Modules\Production\Models\ProductionOrderItem;
|
||||
use App\Modules\Inventory\Contracts\InventoryServiceInterface;
|
||||
use App\Modules\Core\Models\User;
|
||||
use App\Modules\Core\Contracts\CoreServiceInterface;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
@@ -16,10 +16,12 @@ use Inertia\Response;
|
||||
class ProductionOrderController extends Controller
|
||||
{
|
||||
protected $inventoryService;
|
||||
protected $coreService;
|
||||
|
||||
public function __construct(InventoryServiceInterface $inventoryService)
|
||||
public function __construct(InventoryServiceInterface $inventoryService, CoreServiceInterface $coreService)
|
||||
{
|
||||
$this->inventoryService = $inventoryService;
|
||||
$this->coreService = $coreService;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -38,7 +40,10 @@ class ProductionOrderController extends Controller
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('output_batch_number', 'like', "%{$search}%");
|
||||
// 若要搜尋產品名稱,現在需先從 Inventory 查出 IDs
|
||||
$productIds = \App\Modules\Inventory\Models\Product::where('name', 'like', "%{$search}%")->pluck('id');
|
||||
$q->where('code', 'like', "%{$search}%")
|
||||
->orWhere('output_batch_number', 'like', "%{$search}%");
|
||||
// 若要搜尋產品名稱,現在需先從 Inventory 查出 IDs
|
||||
$productIds = $this->inventoryService->getProductsByName($search)->pluck('id');
|
||||
$q->orWhereIn('product_id', $productIds);
|
||||
});
|
||||
}
|
||||
@@ -62,7 +67,7 @@ class ProductionOrderController extends Controller
|
||||
|
||||
$products = $this->inventoryService->getProductsByIds($productIds)->keyBy('id');
|
||||
$warehouses = $this->inventoryService->getAllWarehouses()->whereIn('id', $warehouseIds)->keyBy('id');
|
||||
$users = User::whereIn('id', $userIds)->get()->keyBy('id'); // Core 模組暫由 Model 直接獲取
|
||||
$users = $this->coreService->getUsersByIds($userIds)->keyBy('id');
|
||||
|
||||
$productionOrders->getCollection()->transform(function ($order) use ($products, $warehouses, $users) {
|
||||
$order->product = $products->get($order->product_id);
|
||||
@@ -195,7 +200,7 @@ class ProductionOrderController extends Controller
|
||||
$productionOrder->product->base_unit = $this->inventoryService->getUnits()->where('id', $productionOrder->product->base_unit_id)->first();
|
||||
}
|
||||
$productionOrder->warehouse = $this->inventoryService->getWarehouse($productionOrder->warehouse_id);
|
||||
$productionOrder->user = User::find($productionOrder->user_id);
|
||||
$productionOrder->user = $this->coreService->getUser($productionOrder->user_id);
|
||||
|
||||
// 手動水和明細資料
|
||||
$items = $productionOrder->items;
|
||||
|
||||
Reference in New Issue
Block a user