Aesthetic Fixes
This commit is contained in:
@@ -3,17 +3,18 @@
|
||||
namespace Modules\MaterialLogistics\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\User;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Inertia\Inertia;
|
||||
use Modules\MasterData\Models\Material;
|
||||
use Modules\MaterialLogistics\Models\InventoryBatch;
|
||||
use Modules\MaterialLogistics\Models\ProjectInventory;
|
||||
use Modules\MaterialLogistics\Models\Warehouse;
|
||||
use Modules\MaterialLogistics\Models\WarehouseStock;
|
||||
use Modules\MaterialLogistics\Services\WarehouseService;
|
||||
use Modules\ProjectManagement\Models\Project;
|
||||
use Modules\ProjectManagement\Models\Task;
|
||||
use Modules\MaterialLogistics\Models\InventoryBatch;
|
||||
|
||||
class MaterialController extends Controller
|
||||
{
|
||||
@@ -64,7 +65,7 @@ class MaterialController extends Controller
|
||||
'warehouse:id,ulid,name,code',
|
||||
'material' => function ($query) {
|
||||
$query->select('id', 'ulid', 'name', 'sku', 'unit', 'category', 'type')
|
||||
->with('components.component:id,name,unit');
|
||||
->with('components.component:id,name,unit');
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -81,7 +82,7 @@ class MaterialController extends Controller
|
||||
'project:id,ulid,name,code',
|
||||
'material' => function ($query) {
|
||||
$query->select('id', 'ulid', 'name', 'sku', 'unit', 'category', 'type')
|
||||
->with('components.component:id,name,unit');
|
||||
->with('components.component:id,name,unit');
|
||||
},
|
||||
]);
|
||||
|
||||
@@ -115,14 +116,34 @@ class MaterialController extends Controller
|
||||
public function operations(Request $request, string $type)
|
||||
{
|
||||
$warehouses = Warehouse::active()->select('id', 'ulid', 'name', 'code')->get();
|
||||
$projects = Project::select('id', 'ulid', 'name', 'code')->latest()->get();
|
||||
|
||||
$projects = Project::select('id', 'ulid', 'name', 'code')
|
||||
->with(['personnel' => function ($query) {
|
||||
$query->wherePivot('role', 'pm')->select('users.id', 'users.name');
|
||||
}])
|
||||
->latest()
|
||||
->get()
|
||||
->map(function ($p) {
|
||||
$pm = $p->personnel->first();
|
||||
|
||||
return [
|
||||
'id' => $p->id,
|
||||
'ulid' => $p->ulid,
|
||||
'name' => $p->name,
|
||||
'code' => $p->code,
|
||||
'pm' => $pm ? [
|
||||
'id' => $pm->id,
|
||||
'name' => $pm->name,
|
||||
] : null,
|
||||
];
|
||||
});
|
||||
|
||||
// Materials with their warehouse/site stocks to enforce limits
|
||||
$materials = Material::select('id', 'ulid', 'name', 'sku', 'unit', 'unit_cost')
|
||||
->with(['warehouseStocks', 'projectInventories'])
|
||||
->get();
|
||||
|
||||
$projectManagers = \App\Models\User::role('project_manager')->select('id', 'name')->get();
|
||||
|
||||
$projectManagers = User::role('Project Manager')->select('id', 'name')->get();
|
||||
|
||||
return Inertia::render('MaterialLogistics::Inventory/OperationsForm', [
|
||||
'warehouses' => $warehouses,
|
||||
@@ -155,33 +176,32 @@ class MaterialController extends Controller
|
||||
foreach ($validated['items'] as $item) {
|
||||
$material = Material::where('ulid', $item['material_ulid'])->firstOrFail();
|
||||
$batchId = null;
|
||||
|
||||
if (!empty($item['inventory_batch_ulid'])) {
|
||||
|
||||
if (! empty($item['inventory_batch_ulid'])) {
|
||||
$batchId = InventoryBatch::where('ulid', $item['inventory_batch_ulid'])->firstOrFail()->id;
|
||||
}
|
||||
|
||||
|
||||
$this->warehouseService->dispatchToProject(
|
||||
warehouse: $warehouse,
|
||||
project: $project,
|
||||
warehouse: $warehouse,
|
||||
project: $project,
|
||||
material: $material,
|
||||
quantity: $item['quantity'],
|
||||
inventoryBatchId: $batchId,
|
||||
performedBy: auth()->id(),
|
||||
dispatchedBy: $validated['handler_id'],
|
||||
performedBy: auth()->id(),
|
||||
dispatchedBy: $validated['handler_id'],
|
||||
notes: $validated['notes'] ?? null,
|
||||
);
|
||||
}
|
||||
DB::commit();
|
||||
} catch (\Exception $e) {
|
||||
DB::rollBack();
|
||||
|
||||
return back()->with('error', $e->getMessage());
|
||||
}
|
||||
|
||||
return back()->with('success', "Materials dispatched to {$project->name}.");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// --- Reserve for Task ---
|
||||
public function reserveForTask(Request $request)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user