Files
GSB-Construction/docs/PLAN-inventory-operations.md

3.7 KiB

Implementation Plan: Inventory Operations Architecture (Option B)

Overview

This plan outlines the refactoring of the Inventory/OperationsForm.tsx to handle four distinct operations (Dispatch, Receive, Return, Adjust) via a single "Smart Unified Form" driven by distinct URL parameters (e.g. /inventory/operations/dispatch), completely decoupled from the previously used tabbed interface.

Additionally, it tracks specific personnel involved in each transaction and introduces deep-linking for Warehouses and Projects on the main Inventory Index view.

🟢 Finalized Requirements

1. Personnel Selection (The "Who"):
We will restrict the dropdown lists for personnel to Project Managers initially.

2. Available Quantity Validations:
We will query and display the current available stock in the material cart. The form will validate that dispatch/adjust quantities do not exceed available stock.

3. Tracking Mechanism:
We will create a database migration to add dispatched_by, received_by, returned_by, and adjusted_by columns to the inventory_movements table (as foreign keys to the users table).


Technical Approach

1. Route Re-Architecture

  • Target: Modules/MaterialLogistics/routes/web.php
  • Add a specific parameter format: Route::get('inventory/operations/{type}', [MaterialController::class, 'operations'])->name('inventory.operations');
  • Ensure type is restricted/validated (dispatch, receive, return, adjust).

2. Backend Controller Upgrades (InventoryMovement)

  • Target: MaterialController@operations
  • Create a Migration: add_personnel_columns_to_inventory_movements_table adding dispatched_by, received_by, returned_by, adjusted_by (nullable foreign keys to users.id).
  • Inject the type parameter cleanly.
  • Extract a list of Project Managers (User::role('Project Manager')->select('id', 'name')->get()) so the frontend can populate the Personnel dropdowns.
  • Load material stock balances for the selected Warehouse/Project so the React form can enforce maximum limits.

3. Smart Frontend Unified Page (React/Inertia)

  • Target: resources/js/Pages/Inventory/OperationsForm.tsx
  • Remove Tabs entirely.
  • Dynamic Configuration based on URL:
    • If type === 'dispatch': Title becomes "Dispatch Materials". Shows "From Warehouse" and "To Project". Personnel label is "Dispatched By".
    • If type === 'receive': Title becomes "Receive Materials". Personnel label is "Received By".
    • (Same logic for Return / Adjust)
  • Implement "Line Item Cart": Provide an array-based selection table where users can hit "Add Material" to append multiple items to the single operation with their distinct quantities.
  • Target: resources/js/Pages/Inventory/Index.tsx
  • In the "Warehouse Stock List" and "Project Site Stock List" datatables, update the cell rendering to wrap the location names in <Link href={route('warehouses.show', item.warehouse.ulid)}> and <Link href={route('projects.show', item.project.ulid)}> respectively.

Agent / Specialist Handoffs

  • backend-specialist will handle routing and controller data loading logic (Users, Material Stock limits).
  • frontend-specialist will handle constructing the dynamic React components and modifying the Index tables to be natively clickable.

Verification Checklist

  • Users can navigate directly to /inventory/operations/dispatch without seeing tabs for other modes.
  • Multiple materials can be added to a single dispatch queue simultaneously.
  • Submitting the transaction correctly saves the assigned handler_id in the database.
  • Clicking a Warehouse from the Inventory Tracker redirects to its dedicated view.