feat: implement inventory management controllers, dispatch service logic, and frontend inventory tracking dashboard
This commit is contained in:
@@ -26,7 +26,9 @@ class MaterialController extends Controller
|
||||
// --- Inventory Dashboard ---
|
||||
public function inventory(Request $request)
|
||||
{
|
||||
$warehouses = Warehouse::active()->select('id', 'ulid', 'name', 'code', 'type')
|
||||
$warehouses = Warehouse::active()
|
||||
->whereIn('id', $this->visibleWarehouseIdsQuery())
|
||||
->select('id', 'ulid', 'name', 'code', 'type')
|
||||
->with(['stock' => function ($query) {
|
||||
$query->where('quantity', '>', 0);
|
||||
}])
|
||||
@@ -62,7 +64,8 @@ class MaterialController extends Controller
|
||||
});
|
||||
|
||||
// Warehouse stock
|
||||
$warehouseStockQuery = WarehouseStock::with([
|
||||
$warehouseStockQuery = WarehouseStock::whereIn('warehouse_id', $this->visibleWarehouseIdsQuery())
|
||||
->with([
|
||||
'warehouse:id,ulid,name,code',
|
||||
'material' => function ($query) {
|
||||
$query->select('id', 'ulid', 'name', 'sku', 'unit', 'category', 'type')
|
||||
@@ -79,7 +82,8 @@ class MaterialController extends Controller
|
||||
->withQueryString();
|
||||
|
||||
// Project site stock
|
||||
$siteStockQuery = ProjectInventory::with([
|
||||
$siteStockQuery = ProjectInventory::whereIn('project_id', $this->visibleProjectIdsQuery())
|
||||
->with([
|
||||
'project:id,ulid,name,code',
|
||||
'material' => function ($query) {
|
||||
$query->select('id', 'ulid', 'name', 'sku', 'unit', 'category', 'type')
|
||||
@@ -96,11 +100,11 @@ class MaterialController extends Controller
|
||||
|
||||
// Summary stats
|
||||
$summary = [
|
||||
'total_warehouse' => WarehouseStock::sum('quantity'),
|
||||
'total_warehouse' => WarehouseStock::whereIn('warehouse_id', $this->visibleWarehouseIdsQuery())->sum('quantity'),
|
||||
|
||||
'total_onsite' => ProjectInventory::sum('on_hand_qty'),
|
||||
'total_reserved' => ProjectInventory::sum('allocated_qty'),
|
||||
'total_consumed' => ProjectInventory::sum('consumed_qty'),
|
||||
'total_onsite' => ProjectInventory::whereIn('project_id', $this->visibleProjectIdsQuery())->sum('on_hand_qty'),
|
||||
'total_reserved' => ProjectInventory::whereIn('project_id', $this->visibleProjectIdsQuery())->sum('allocated_qty'),
|
||||
'total_consumed' => ProjectInventory::whereIn('project_id', $this->visibleProjectIdsQuery())->sum('consumed_qty'),
|
||||
];
|
||||
|
||||
return Inertia::render('MaterialLogistics::Inventory/Index', [
|
||||
@@ -116,7 +120,9 @@ class MaterialController extends Controller
|
||||
// --- Inventory Operations Form Page ---
|
||||
public function operations(Request $request, string $type)
|
||||
{
|
||||
$warehouses = Warehouse::active()->select('id', 'ulid', 'name', 'code')->get();
|
||||
$warehouses = Warehouse::active()
|
||||
->whereIn('id', $this->visibleWarehouseIdsQuery())
|
||||
->select('id', 'ulid', 'name', 'code')->get();
|
||||
|
||||
$projects = Project::select('id', 'ulid', 'name', 'code')
|
||||
->with(['personnel' => function ($query) {
|
||||
@@ -377,4 +383,16 @@ class MaterialController extends Controller
|
||||
|
||||
return back()->with('success', 'Stock adjusted.');
|
||||
}
|
||||
|
||||
private function visibleProjectIdsQuery()
|
||||
{
|
||||
return Project::query()->select('projects.id');
|
||||
}
|
||||
|
||||
private function visibleWarehouseIdsQuery()
|
||||
{
|
||||
return Warehouse::query()
|
||||
->whereIn('project_id', $this->visibleProjectIdsQuery())
|
||||
->select('warehouses.id');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user