# Inventory Systems Unification - Implementation Plan

**Status:** Draft
**Created:** 2026-02-14
**Reference:** [INVENTORY_STORES_UNIFICATION_PLAN.md](../INVENTORY_STORES_UNIFICATION_PLAN.md)
**Strategy:** Option A - Enhance Catalog System (Migrate Accounting → Catalog)

---

## Table of Contents

1. [Phase 1: Foundation - Schema Enhancement](#phase-1-foundation---schema-enhancement)
2. [Phase 2: Permission System Setup](#phase-2-permission-system-setup)
3. [Phase 3: Model Layer Unification](#phase-3-model-layer-unification)
4. [Phase 4: Service Layer Unification](#phase-4-service-layer-unification)
5. [Phase 5: Repository Layer Updates](#phase-5-repository-layer-updates)
6. [Phase 6: Controller & API Consolidation](#phase-6-controller--api-consolidation)
7. [Phase 7: Event System Integration](#phase-7-event-system-integration)
8. [Phase 8: Data Migration](#phase-8-data-migration)
9. [Phase 9: Financial Integration](#phase-9-financial-integration)
10. [Phase 10: Testing & Validation](#phase-10-testing--validation)
11. [Phase 11: Cleanup & Deprecation](#phase-11-cleanup--deprecation)

---

## Phase 1: Foundation - Schema Enhancement

### 1.1 Multi-Tenancy Support for Catalog Warehouses

#### 1.1.1 Create Migration: Add company_id to catalog_warehouses

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_warehouses_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
- [ ] Add index on company_id
- [ ] Add composite unique constraint (company_id, code)
- [ ] Update existing records with default company_id
```

#### 1.1.2 Create Migration: Add chart_account_id to catalog_warehouses

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_chart_account_id_to_catalog_warehouses_table.php`

```
Tasks:
- [ ] Add chart_account_id foreign key (nullable initially)
- [ ] Add index on chart_account_id
```

#### 1.1.3 Create Migration: Add item type flags to catalog_warehouses

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_item_type_flags_to_catalog_warehouses_table.php`

```
Tasks:
- [ ] Add for_product boolean (default: true)
- [ ] Add for_material boolean (default: false)
- [ ] Add for_equipment boolean (default: false)
- [ ] Add project_id foreign key (nullable)
- [ ] Add title JSON column for translations
```

---

### 1.2 Multi-Tenancy Support for Catalog Inventories

#### 1.2.1 Create Migration: Add company_id to catalog_inventories

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventories_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
- [ ] Add index on company_id
- [ ] Update existing records with default company_id
```

#### 1.2.2 Create Migration: Add unit tracking to catalog_inventories

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_unit_id_to_catalog_inventories_table.php`

```
Tasks:
- [ ] Add unit_id foreign key (references measurement_units/units table)
- [ ] Add index on unit_id
```

#### 1.2.3 Create Migration: Add approval workflow to catalog_inventories

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_approval_workflow_to_catalog_inventories_table.php`

```
Tasks:
- [ ] Add status enum column (pending, approved)
- [ ] Add type enum column (product, material, equipment)
- [ ] Add price float column
- [ ] Add amount float column (alias for quantity calculations)
```

---

### 1.3 Multi-Tenancy Support for Related Tables

#### 1.3.1 Create Migration: Add company_id to catalog_inventory_transactions

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventory_transactions_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
- [ ] Add unit_id foreign key column
- [ ] Add unit_price decimal column
- [ ] Add total_price decimal column
- [ ] Add status enum column (pending, approved)
```

#### 1.3.2 Create Migration: Add company_id to catalog_inventory_costs

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventory_costs_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
- [ ] Add unit_id foreign key column
- [ ] Add remaining_quantity decimal column
- [ ] Add is_consumed boolean column
- [ ] Add batch_number string column (unique per company)
- [ ] Add transaction_date date column
```

#### 1.3.3 Create Migration: Add company_id to catalog_inventory_batches

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventory_batches_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
```

#### 1.3.4 Create Migration: Add company_id to catalog_inventory_serials

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventory_serials_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
```

#### 1.3.5 Create Migration: Add company_id to catalog_inventory_reservations

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_company_id_to_catalog_inventory_reservations_table.php`

```
Tasks:
- [ ] Add company_id foreign key column
```

---

## Phase 2: Permission System Setup

### 2.1 Create Unified Inventory Permissions

#### 2.1.1 Create Permission Seeder

**File:** `database/seeders/UnifiedInventoryPermissionSeeder.php`

```
Tasks:
- [ ] Create seeder class
- [ ] Define permission structure:
```

**Permission Categories:**

```php
$permissions = [
    // Warehouse Management
    'unified-inventory' => [
        'warehouses.index',
        'warehouses.show',
        'warehouses.store',
        'warehouses.update',
        'warehouses.destroy',
        'warehouses.restore',
        'warehouses.bulk-delete',
    ],

    // Stock Level Management
    'unified-inventory' => [
        'stock.index',
        'stock.show',
        'stock.adjust',
        'stock.transfer',
        'stock.approve',
        'stock.reject',
    ],

    // Transaction Management
    'unified-inventory' => [
        'transactions.index',
        'transactions.show',
        'transactions.store',
        'transactions.export',
    ],

    // First Term (Opening Balance)
    'unified-inventory' => [
        'first-term.index',
        'first-term.show',
        'first-term.store',
        'first-term.update',
        'first-term.destroy',
        'first-term.approve',
        'first-term.import',
        'first-term.export',
    ],

    // Transfers
    'unified-inventory' => [
        'transfers.index',
        'transfers.show',
        'transfers.store',
        'transfers.update',
        'transfers.destroy',
        'transfers.approve',
    ],

    // Settlements
    'unified-inventory' => [
        'settlements.index',
        'settlements.show',
        'settlements.store',
        'settlements.update',
        'settlements.destroy',
        'settlements.approve',
    ],

    // Reservations
    'unified-inventory' => [
        'reservations.index',
        'reservations.show',
        'reservations.store',
        'reservations.confirm',
        'reservations.cancel',
        'reservations.release',
    ],

    // Serial/Batch Management
    'unified-inventory' => [
        'serials.index',
        'serials.show',
        'serials.store',
        'serials.update',
        'batches.index',
        'batches.show',
        'batches.store',
        'batches.update',
    ],

    // Valuation & Costing
    'unified-inventory' => [
        'valuation.index',
        'valuation.show',
        'valuation.configure',
    ],

    // Reports
    'unified-inventory' => [
        'reports.stock-levels',
        'reports.movements',
        'reports.valuation',
        'reports.low-stock',
        'reports.stagnant',
        'reports.reorder',
    ],
];
```

#### 2.1.2 Create Permission Migration

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_add_unified_inventory_permissions.php`

```
Tasks:
- [ ] Create migration to run seeder
- [ ] Assign permissions to super_admin role
```

### 2.2 Permission Mapping Table

#### 2.2.1 Create Legacy Permission Mapping

**File:** `docs/plans/INVENTORY_PERMISSION_MAPPING.md`

```
Tasks:
- [ ] Document old → new permission mappings:
```

| Old Permission (Accounting) | Old Permission (Catalog) | New Unified Permission |
|-----------------------------|--------------------------|------------------------|
| inventories.index | catalog.inventory.view | unified-inventory.stock.index |
| store-first-terms.store | - | unified-inventory.first-term.store |
| store-transfers.store | - | unified-inventory.transfers.store |
| store-settlements.store | - | unified-inventory.settlements.store |
| - | catalog.inventory.manage-warehouses | unified-inventory.warehouses.* |
| - | catalog.inventory.manage-transactions | unified-inventory.transactions.* |

---

## Phase 3: Model Layer Unification

### 3.1 Enhance Warehouse Model

#### 3.1.1 Modify Warehouse Model

**File:** `app/Domains/Catalog/Inventory/Models/Warehouse.php`

```
Tasks:
- [ ] Add company_id relationship
- [ ] Add HasCompanyScope trait (or implement manually)
- [ ] Add chartAccount relationship (belongsTo ChartOfAccount)
- [ ] Add project relationship (belongsTo Project, nullable)
- [ ] Add fillable fields: company_id, chart_account_id, project_id, title, for_product, for_material, for_equipment
- [ ] Add code generation trait (GeneratesCode)
- [ ] Add Observer for auto ChartOfAccount creation
- [ ] Add title accessor for translations
```

**Code Changes:**

```php
// Add to Warehouse.php
use App\Domains\Core\Company\Traits\HasCompanyScope;
use App\Domains\Core\Traits\GeneratesCode;

class Warehouse extends Model
{
    use HasFactory, SoftDeletes, HasCompanyScope, GeneratesCode;

    protected static string $codePrefix = 'WH';

    protected $fillable = [
        'company_id',
        'chart_account_id',
        'project_id',
        'name',
        'code',
        'title',        // JSON for translations
        'location',
        'for_product',
        'for_material',
        'for_equipment',
        'is_active',
    ];

    protected $casts = [
        'title' => 'array',
        'for_product' => 'boolean',
        'for_material' => 'boolean',
        'for_equipment' => 'boolean',
        'is_active' => 'boolean',
    ];

    // Relationships
    public function company(): BelongsTo
    {
        return $this->belongsTo(Company::class);
    }

    public function chartAccount(): BelongsTo
    {
        return $this->belongsTo(ChartOfAccount::class, 'chart_account_id');
    }

    public function project(): BelongsTo
    {
        return $this->belongsTo(Project::class);
    }
}
```

#### 3.1.2 Create Warehouse Observer

**File:** `app/Domains/Catalog/Inventory/Observers/WarehouseObserver.php`

```
Tasks:
- [ ] Create observer class
- [ ] Implement creating() method for code generation
- [ ] Implement created() method for ChartOfAccount auto-creation
- [ ] Register observer in service provider
```

### 3.2 Enhance Inventory Model

#### 3.2.1 Modify Inventory Model

**File:** `app/Domains/Catalog/Inventory/Models/Inventory.php`

```
Tasks:
- [ ] Add company_id relationship
- [ ] Add HasCompanyScope trait
- [ ] Add unit relationship (belongsTo Unit/MeasurementUnit)
- [ ] Add fillable fields: company_id, unit_id, status, type, price, amount
- [ ] Add status enum casting
- [ ] Add type enum casting
- [ ] Add approval methods
- [ ] Add incrementOrCreate static method (from ProductStore)
- [ ] Add decreaseOrCreate static method (from ProductStore)
```

**Code Changes:**

```php
// Add to Inventory.php
protected $fillable = [
    'company_id',
    'variant_id',
    'warehouse_id',
    'inventory_type_id',
    'unit_id',
    'quantity',
    'amount',       // For financial calculations
    'price',        // Current unit price
    'status',       // pending, approved
    'type',         // product, material, equipment
];

protected $casts = [
    'quantity' => 'decimal:3',
    'amount' => 'decimal:4',
    'price' => 'decimal:4',
    'status' => InventoryStatus::class,
    'type' => InventoryItemType::class,
];

public function unit(): BelongsTo
{
    return $this->belongsTo(Unit::class);
}

// Static methods migrated from ProductStore
public static function incrementOrCreate(array $attributes, float $quantity, float $price = null): self
{
    // Implementation from ProductStore
}

public static function decreaseOrCreate(array $attributes, float $quantity): self
{
    // Implementation from ProductStore
}
```

#### 3.2.2 Create Inventory Status Enum

**File:** `app/Domains/Catalog/Inventory/Enums/InventoryStatus.php`

```
Tasks:
- [ ] Create enum with: PENDING, APPROVED
```

#### 3.2.3 Create Inventory Item Type Enum

**File:** `app/Domains/Catalog/Inventory/Enums/InventoryItemType.php`

```
Tasks:
- [ ] Create enum with: PRODUCT, MATERIAL, EQUIPMENT
```

### 3.3 Enhance InventoryTransaction Model

#### 3.3.1 Modify InventoryTransaction Model

**File:** `app/Domains/Catalog/Inventory/Models/InventoryTransaction.php`

```
Tasks:
- [ ] Add company_id relationship
- [ ] Add HasCompanyScope trait
- [ ] Add unit relationship
- [ ] Add fillable fields: company_id, unit_id, unit_price, total_price, status
- [ ] Add status enum casting
- [ ] Extend transaction types if needed
```

### 3.4 Enhance InventoryCost Model

#### 3.4.1 Modify InventoryCost Model (Merge with InventoryValuation)

**File:** `app/Domains/Catalog/Inventory/Models/InventoryCost.php`

```
Tasks:
- [ ] Add company_id relationship
- [ ] Add HasCompanyScope trait
- [ ] Add batch tracking fields (from InventoryValuation)
- [ ] Add remaining_quantity field
- [ ] Add is_consumed field
- [ ] Add batch_number field with auto-generation
- [ ] Add consume() method
- [ ] Add calculateWeightedAverage() method
- [ ] Add getAvailableQuantity() method
- [ ] Add scopes: available(), incoming(), outgoing(), forProduct(), forWarehouse()
```

### 3.5 Create Bridge/Compatibility Models

#### 3.5.1 Create MainInventoryBridge Model (Temporary)

**File:** `app/Domains/Accounting/Inventory/Models/MainInventoryBridge.php`

```
Tasks:
- [ ] Create bridge model that maps old MainInventory calls to new Warehouse
- [ ] Implement __call magic method for backward compatibility
- [ ] Log deprecation warnings
```

#### 3.5.2 Create ProductStoreBridge Model (Temporary)

**File:** `app/Domains/Accounting/Inventory/Models/ProductStoreBridge.php`

```
Tasks:
- [ ] Create bridge model that maps old ProductStore calls to new Inventory
- [ ] Implement __call magic method for backward compatibility
- [ ] Log deprecation warnings
```

---

## Phase 4: Service Layer Unification

### 4.1 Create Unified Inventory Service

#### 4.1.1 Create Main Service Interface

**File:** `app/Domains/Catalog/Inventory/Contracts/UnifiedInventoryServiceInterface.php`

```
Tasks:
- [ ] Define contract with all inventory operations:
```

```php
interface UnifiedInventoryServiceInterface
{
    // Warehouse Operations
    public function getWarehouses(array $filters = []): LengthAwarePaginator;
    public function getWarehouse(int $id): Warehouse;
    public function createWarehouse(WarehouseDTO $dto): Warehouse;
    public function updateWarehouse(int $id, WarehouseDTO $dto): Warehouse;
    public function deleteWarehouse(int $id): bool;

    // Stock Operations
    public function getStock(array $filters = []): LengthAwarePaginator;
    public function getStockByWarehouse(int $warehouseId): Collection;
    public function adjustStock(int $inventoryId, AdjustmentDTO $dto): Inventory;
    public function transferStock(TransferDTO $dto): InventoryTransaction;

    // First Term Operations
    public function createFirstTerm(FirstTermDTO $dto): StoreFirstTerm;
    public function approveFirstTerm(int $id): StoreFirstTerm;

    // Valuation Operations
    public function recordIncrease(ValuationDTO $dto): InventoryCost;
    public function getCostForSale(int $inventoryId, float $quantity, string $method): float;

    // Reservation Operations
    public function createReservation(ReservationDTO $dto): InventoryReservation;
    public function confirmReservation(int $id): InventoryReservation;
    public function releaseReservation(int $id): bool;
}
```

#### 4.1.2 Create Unified Inventory Service Implementation

**File:** `app/Domains/Catalog/Inventory/Services/UnifiedInventoryService.php`

```
Tasks:
- [ ] Create service class implementing interface
- [ ] Inject required repositories
- [ ] Implement all warehouse operations
- [ ] Implement all stock operations
- [ ] Implement all first term operations
- [ ] Implement all valuation operations
- [ ] Implement all reservation operations
- [ ] Add database transaction wrapping
- [ ] Add event dispatching
- [ ] Add ChartOfAccount integration
```

### 4.2 Migrate Accounting Services Logic

#### 4.2.1 Migrate InventoryServices Logic

**Source:** `app/Domains/Accounting/Inventory/Services/InventoryServices.php`

```
Tasks:
- [ ] Move index() logic to UnifiedInventoryService::getWarehouses()
- [ ] Move ActiveStoreQuarry() to UnifiedInventoryService::getActiveWarehouses()
- [ ] Move increaseStock() to UnifiedInventoryService::adjustStock()
- [ ] Move getStoreById() to UnifiedInventoryService::getWarehouse()
- [ ] Move getProducts() to UnifiedInventoryService::getStockByWarehouse()
```

#### 4.2.2 Migrate InventoryValuationService Logic

**Source:** `app/Domains/Accounting/Inventory/Services/InventoryValuationService.php`

```
Tasks:
- [ ] Move recordIncrease() logic
- [ ] Move getCostForSale() logic
- [ ] Move valuation method selection logic
- [ ] Move FIFO implementation
- [ ] Move LIFO implementation
- [ ] Move Weighted Average implementation
```

#### 4.2.3 Migrate StoreFirstTermServices Logic

**Source:** `app/Domains/Accounting/Inventory/Services/StoreFirstTermServices.php`

```
Tasks:
- [ ] Move first term creation logic
- [ ] Move approval workflow logic
- [ ] Move import/export logic
```

#### 4.2.4 Migrate StoreTransferServices Logic

**Source:** `app/Domains/Accounting/Inventory/Services/StoreTransferServices.php`

```
Tasks:
- [ ] Move transfer creation logic
- [ ] Move approval workflow logic
```

#### 4.2.5 Migrate StoreSettlementServices Logic

**Source:** `app/Domains/Accounting/Inventory/Services/StoreSettlementServices.php`

```
Tasks:
- [ ] Move settlement creation logic
- [ ] Move approval workflow logic
```

### 4.3 Enhance Existing Catalog Services

#### 4.3.1 Update InventoryService

**File:** `app/Domains/Catalog/Inventory/Services/InventoryService.php`

```
Tasks:
- [ ] Add company scoping to all queries
- [ ] Add unit tracking to operations
- [ ] Add approval workflow methods
- [ ] Add price tracking to operations
- [ ] Update adjustInventory() to support valuation
```

#### 4.3.2 Update WarehouseService

**File:** `app/Domains/Catalog/Inventory/Services/WarehouseService.php`

```
Tasks:
- [ ] Add company scoping to all queries
- [ ] Add ChartOfAccount creation on warehouse creation
- [ ] Add project assignment support
- [ ] Add item type filtering (product/material/equipment)
```

### 4.4 Create Valuation Strategy Services

#### 4.4.1 Move Valuation Strategies to Catalog

**Files to create/move:**
- `app/Domains/Catalog/Inventory/Services/Valuation/ValuationMethodInterface.php`
- `app/Domains/Catalog/Inventory/Services/Valuation/FifoValuationService.php`
- `app/Domains/Catalog/Inventory/Services/Valuation/LifoValuationService.php`
- `app/Domains/Catalog/Inventory/Services/Valuation/WeightedAverageValuationService.php`
- `app/Domains/Catalog/Inventory/Services/Valuation/CurrentPriceValuationService.php`

```
Tasks:
- [ ] Copy valuation interface
- [ ] Copy FIFO service and update to use Catalog models
- [ ] Copy LIFO service and update to use Catalog models
- [ ] Copy Weighted Average service and update to use Catalog models
- [ ] Copy Current Price service and update to use Catalog models
- [ ] Update InventoryCost model references
- [ ] Update Warehouse model references
```

---

## Phase 5: Repository Layer Updates

### 5.1 Update Warehouse Repository

#### 5.1.1 Modify WarehouseRepository

**File:** `app/Domains/Catalog/Inventory/Repositories/WarehouseRepository.php`

```
Tasks:
- [ ] Add company scoping to all queries
- [ ] Add getByChartAccount() method
- [ ] Add getByProject() method
- [ ] Add getForItemType() method (product/material/equipment)
- [ ] Add getActiveWithStock() method
```

#### 5.1.2 Update WarehouseRepositoryContract

**File:** `app/Domains/Catalog/Inventory/Contracts/WarehouseRepositoryContract.php`

```
Tasks:
- [ ] Add new method signatures
```

### 5.2 Update Inventory Repository

#### 5.2.1 Modify InventoryRepository

**File:** `app/Domains/Catalog/Inventory/Repositories/InventoryRepository.php`

```
Tasks:
- [ ] Add company scoping to all queries
- [ ] Add getByUnit() method
- [ ] Add getByStatus() method (pending/approved)
- [ ] Add getByType() method (product/material/equipment)
- [ ] Add getPendingApproval() method
- [ ] Add getWithValuation() method
```

#### 5.2.2 Update InventoryRepositoryContract

**File:** `app/Domains/Catalog/Inventory/Contracts/InventoryRepositoryContract.php`

```
Tasks:
- [ ] Add new method signatures
```

### 5.3 Create New Repositories

#### 5.3.1 Create ValuationRepository

**File:** `app/Domains/Catalog/Inventory/Repositories/ValuationRepository.php`

```
Tasks:
- [ ] Create repository for InventoryCost/valuation operations
- [ ] Implement getAvailableBatches() method
- [ ] Implement consume() method
- [ ] Implement getWeightedAverageCost() method
```

#### 5.3.2 Create FirstTermRepository

**File:** `app/Domains/Catalog/Inventory/Repositories/FirstTermRepository.php`

```
Tasks:
- [ ] Create repository for first term operations
- [ ] Implement standard CRUD
- [ ] Implement approval workflow methods
```

---

## Phase 6: Controller & API Consolidation

### 6.1 Create Unified API Controllers

#### 6.1.1 Create UnifiedWarehouseController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedWarehouseController.php`

```
Tasks:
- [ ] Create controller with full CRUD
- [ ] Implement index() with company scoping
- [ ] Implement store() with ChartOfAccount creation
- [ ] Implement update() with validation
- [ ] Implement destroy() with dependency checks
- [ ] Implement restore() for soft-deleted warehouses
- [ ] Implement getForProduct() for product-type warehouses
- [ ] Implement getForMaterial() for material-type warehouses
- [ ] Implement getForEquipment() for equipment-type warehouses
- [ ] Implement showWithStock() to display warehouse with stock levels
```

#### 6.1.2 Create UnifiedStockController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedStockController.php`

```
Tasks:
- [ ] Create controller for stock operations
- [ ] Implement index() with filtering
- [ ] Implement show() with details
- [ ] Implement adjust() for adjustments
- [ ] Implement transfer() for inter-warehouse transfers
- [ ] Implement approve() for pending stock
- [ ] Implement reject() for pending stock
- [ ] Implement byWarehouse()
- [ ] Implement lowStock()
- [ ] Implement byType() (product/material/equipment)
```

#### 6.1.3 Create UnifiedFirstTermController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedFirstTermController.php`

```
Tasks:
- [ ] Create controller for first term (opening balance)
- [ ] Implement full CRUD operations
- [ ] Implement approve() method
- [ ] Implement import() method
- [ ] Implement export() method
```

#### 6.1.4 Create UnifiedTransferController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedTransferController.php`

```
Tasks:
- [ ] Create controller for transfers
- [ ] Implement full CRUD operations
- [ ] Implement approve() method
```

#### 6.1.5 Create UnifiedSettlementController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedSettlementController.php`

```
Tasks:
- [ ] Create controller for settlements
- [ ] Implement full CRUD operations
- [ ] Implement approve() method
```

#### 6.1.6 Create UnifiedReservationController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedReservationController.php`

```
Tasks:
- [ ] Create controller for reservations
- [ ] Implement index()
- [ ] Implement store()
- [ ] Implement confirm()
- [ ] Implement cancel()
- [ ] Implement release()
- [ ] Implement getPending()
- [ ] Implement getExpired()
```

#### 6.1.7 Create UnifiedValuationController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedValuationController.php`

```
Tasks:
- [ ] Create controller for valuation/costing
- [ ] Implement index() for valuation records
- [ ] Implement show() for valuation details
- [ ] Implement configure() for method settings
- [ ] Implement calculateCost() for cost calculations
```

#### 6.1.8 Create UnifiedReportController

**File:** `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedReportController.php`

```
Tasks:
- [ ] Create controller for reports
- [ ] Implement stockLevels() report
- [ ] Implement movements() report
- [ ] Implement valuation() report
- [ ] Implement lowStock() report
- [ ] Implement stagnant() report
- [ ] Implement reorder() report
```

### 6.2 Create Request Validation Classes

#### 6.2.1 Warehouse Requests

**Files:**
- `app/Domains/Catalog/Inventory/Requests/V2/StoreWarehouseRequest.php`
- `app/Domains/Catalog/Inventory/Requests/V2/UpdateWarehouseRequest.php`

```
Tasks:
- [ ] Create store request with validation rules
- [ ] Create update request with validation rules
- [ ] Add rules for: name, code, location, for_product, for_material, for_equipment, project_id
```

#### 6.2.2 Stock Requests

**Files:**
- `app/Domains/Catalog/Inventory/Requests/V2/AdjustStockRequest.php`
- `app/Domains/Catalog/Inventory/Requests/V2/TransferStockRequest.php`

```
Tasks:
- [ ] Create adjustment request with validation rules
- [ ] Create transfer request with validation rules
- [ ] Add rules for: quantity, unit_id, warehouse_id, reason, etc.
```

#### 6.2.3 First Term Requests

**Files:**
- `app/Domains/Catalog/Inventory/Requests/V2/StoreFirstTermRequest.php`
- `app/Domains/Catalog/Inventory/Requests/V2/UpdateFirstTermRequest.php`

```
Tasks:
- [ ] Create store request (migrate from Accounting)
- [ ] Create update request (migrate from Accounting)
```

### 6.3 Create API Resources

#### 6.3.1 Unified Resources

**Files:**
- `app/Domains/Catalog/Inventory/Resources/V2/WarehouseResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/StockResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/FirstTermResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/TransferResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/SettlementResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/ReservationResource.php`
- `app/Domains/Catalog/Inventory/Resources/V2/ValuationResource.php`

```
Tasks:
- [ ] Create resource classes with all required fields
- [ ] Include relationships (warehouse, unit, company)
- [ ] Include computed fields (total_value, average_cost)
```

### 6.4 Create Unified Routes

#### 6.4.1 Create V2 Route File

**File:** `routes/apis/UnifiedInventory.php`

```
Tasks:
- [ ] Create route file with all unified endpoints
- [ ] Add permission middleware
- [ ] Group routes appropriately
```

**Route Structure:**

```php
Route::prefix('v2/inventory')->middleware(['auth:sanctum'])->group(function () {

    // Warehouses
    Route::middleware('permission:unified-inventory.warehouses.index')
        ->get('warehouses', [UnifiedWarehouseController::class, 'index']);
    Route::middleware('permission:unified-inventory.warehouses.store')
        ->post('warehouses', [UnifiedWarehouseController::class, 'store']);
    Route::middleware('permission:unified-inventory.warehouses.show')
        ->get('warehouses/{id}', [UnifiedWarehouseController::class, 'show']);
    Route::middleware('permission:unified-inventory.warehouses.update')
        ->put('warehouses/{id}', [UnifiedWarehouseController::class, 'update']);
    Route::middleware('permission:unified-inventory.warehouses.destroy')
        ->delete('warehouses/{id}', [UnifiedWarehouseController::class, 'destroy']);
    Route::middleware('permission:unified-inventory.warehouses.restore')
        ->post('warehouses/{id}/restore', [UnifiedWarehouseController::class, 'restore']);

    // Stock
    Route::middleware('permission:unified-inventory.stock.index')
        ->get('stock', [UnifiedStockController::class, 'index']);
    Route::middleware('permission:unified-inventory.stock.show')
        ->get('stock/{id}', [UnifiedStockController::class, 'show']);
    Route::middleware('permission:unified-inventory.stock.adjust')
        ->post('stock/{id}/adjust', [UnifiedStockController::class, 'adjust']);
    Route::middleware('permission:unified-inventory.stock.transfer')
        ->post('stock/transfer', [UnifiedStockController::class, 'transfer']);
    Route::middleware('permission:unified-inventory.stock.approve')
        ->post('stock/{id}/approve', [UnifiedStockController::class, 'approve']);

    // First Term
    Route::middleware('permission:unified-inventory.first-term.index')
        ->get('first-term', [UnifiedFirstTermController::class, 'index']);
    Route::middleware('permission:unified-inventory.first-term.store')
        ->post('first-term', [UnifiedFirstTermController::class, 'store']);
    Route::middleware('permission:unified-inventory.first-term.show')
        ->get('first-term/{id}', [UnifiedFirstTermController::class, 'show']);
    Route::middleware('permission:unified-inventory.first-term.update')
        ->put('first-term/{id}', [UnifiedFirstTermController::class, 'update']);
    Route::middleware('permission:unified-inventory.first-term.destroy')
        ->delete('first-term/{id}', [UnifiedFirstTermController::class, 'destroy']);
    Route::middleware('permission:unified-inventory.first-term.approve')
        ->post('first-term/{id}/approve', [UnifiedFirstTermController::class, 'approve']);
    Route::middleware('permission:unified-inventory.first-term.import')
        ->post('first-term/import', [UnifiedFirstTermController::class, 'import']);
    Route::middleware('permission:unified-inventory.first-term.export')
        ->get('first-term/export', [UnifiedFirstTermController::class, 'export']);

    // Transfers
    Route::apiResource('transfers', UnifiedTransferController::class)
        ->middleware('permission:unified-inventory.transfers.*');
    Route::middleware('permission:unified-inventory.transfers.approve')
        ->post('transfers/{id}/approve', [UnifiedTransferController::class, 'approve']);

    // Settlements
    Route::apiResource('settlements', UnifiedSettlementController::class)
        ->middleware('permission:unified-inventory.settlements.*');
    Route::middleware('permission:unified-inventory.settlements.approve')
        ->post('settlements/{id}/approve', [UnifiedSettlementController::class, 'approve']);

    // Reservations
    Route::middleware('permission:unified-inventory.reservations.index')
        ->get('reservations', [UnifiedReservationController::class, 'index']);
    Route::middleware('permission:unified-inventory.reservations.store')
        ->post('reservations', [UnifiedReservationController::class, 'store']);
    Route::middleware('permission:unified-inventory.reservations.confirm')
        ->post('reservations/{id}/confirm', [UnifiedReservationController::class, 'confirm']);
    Route::middleware('permission:unified-inventory.reservations.cancel')
        ->post('reservations/{id}/cancel', [UnifiedReservationController::class, 'cancel']);
    Route::middleware('permission:unified-inventory.reservations.release')
        ->post('reservations/{id}/release', [UnifiedReservationController::class, 'release']);

    // Valuation
    Route::middleware('permission:unified-inventory.valuation.index')
        ->get('valuation', [UnifiedValuationController::class, 'index']);
    Route::middleware('permission:unified-inventory.valuation.show')
        ->get('valuation/{id}', [UnifiedValuationController::class, 'show']);
    Route::middleware('permission:unified-inventory.valuation.configure')
        ->post('valuation/configure', [UnifiedValuationController::class, 'configure']);

    // Reports
    Route::prefix('reports')->middleware('permission:unified-inventory.reports.*')->group(function () {
        Route::get('stock-levels', [UnifiedReportController::class, 'stockLevels']);
        Route::get('movements', [UnifiedReportController::class, 'movements']);
        Route::get('valuation', [UnifiedReportController::class, 'valuation']);
        Route::get('low-stock', [UnifiedReportController::class, 'lowStock']);
        Route::get('stagnant', [UnifiedReportController::class, 'stagnant']);
        Route::get('reorder', [UnifiedReportController::class, 'reorder']);
    });
});
```

#### 6.4.2 Create Backward Compatible Routes (Deprecated)

**File:** `routes/apis/InventoryLegacy.php`

```
Tasks:
- [ ] Create deprecated routes that redirect to new endpoints
- [ ] Add deprecation headers to responses
- [ ] Log usage of deprecated endpoints
```

---

## Phase 7: Event System Integration

### 7.1 Create Unified Events

#### 7.1.1 Create Inventory Events

**Files:**
- `app/Domains/Catalog/Inventory/Events/WarehouseCreated.php`
- `app/Domains/Catalog/Inventory/Events/StockAdjusted.php`
- `app/Domains/Catalog/Inventory/Events/StockTransferred.php`
- `app/Domains/Catalog/Inventory/Events/FirstTermApproved.php`
- `app/Domains/Catalog/Inventory/Events/ValuationRecorded.php`

```
Tasks:
- [ ] Create event classes with required properties
- [ ] Include company_id in all events
- [ ] Include user_id for audit trail
```

### 7.2 Create/Update Event Listeners

#### 7.2.1 Financial Integration Listeners

**Files:**
- `app/Domains/Catalog/Inventory/Listeners/CreateAccountingTransactionListener.php`
- `app/Domains/Catalog/Inventory/Listeners/UpdateChartOfAccountBalanceListener.php`

```
Tasks:
- [ ] Create listener for AccountingTransaction creation
- [ ] Create listener for ChartOfAccount balance updates
- [ ] Wire up with events
```

#### 7.2.2 Update Existing Listeners

```
Tasks:
- [ ] Update CreateInventoryTransactionListener to include company_id
- [ ] Update CheckLowStockListener to use unified service
- [ ] Update NotifySupplyDomainListener to use unified service
```

### 7.3 Register Events and Listeners

#### 7.3.1 Update EventServiceProvider

**File:** `app/Providers/EventServiceProvider.php` (or domain-specific provider)

```
Tasks:
- [ ] Register all new events with listeners
- [ ] Register financial integration listeners
```

---

## Phase 8: Data Migration

### 8.1 Create Data Migration Scripts

#### 8.1.1 Create Warehouse Migration Command

**File:** `app/Console/Commands/MigrateAccountingWarehousesCommand.php`

```
Tasks:
- [ ] Create Artisan command
- [ ] Implement warehouse data migration logic:
  - Read from main_inventories
  - Map fields to catalog_warehouses
  - Create ChartOfAccount links
  - Handle code conflicts
  - Log migration progress
- [ ] Add dry-run option
- [ ] Add rollback capability
```

#### 8.1.2 Create Stock Migration Command

**File:** `app/Console/Commands/MigrateAccountingStockCommand.php`

```
Tasks:
- [ ] Create Artisan command
- [ ] Implement stock data migration logic:
  - Read from product_stores
  - Map to catalog_inventories
  - Handle unit conversions
  - Preserve approval status
  - Log migration progress
- [ ] Add dry-run option
- [ ] Add rollback capability
```

#### 8.1.3 Create Transaction Migration Command

**File:** `app/Console/Commands/MigrateAccountingTransactionsCommand.php`

```
Tasks:
- [ ] Create Artisan command
- [ ] Implement transaction migration logic:
  - Read from accounting inventory_transactions
  - Map to catalog_inventory_transactions
  - Map transaction types
  - Preserve polymorphic references
  - Log migration progress
- [ ] Add dry-run option
- [ ] Add rollback capability
```

#### 8.1.4 Create Valuation Migration Command

**File:** `app/Console/Commands/MigrateAccountingValuationsCommand.php`

```
Tasks:
- [ ] Create Artisan command
- [ ] Implement valuation migration logic:
  - Read from inventory_valuations
  - Map to catalog_inventory_costs
  - Preserve batch numbers
  - Handle consumed batches
  - Log migration progress
- [ ] Add dry-run option
- [ ] Add rollback capability
```

### 8.2 Create Migration Mapping Table

#### 8.2.1 Create Mapping Table Migration

**File:** `database/migrations/YYYY_MM_DD_XXXXXX_create_inventory_migration_map_table.php`

```
Tasks:
- [ ] Create table with columns:
  - id
  - entity_type (warehouse, stock, transaction, valuation)
  - old_table
  - old_id
  - new_table
  - new_id
  - migrated_at
  - status
```

### 8.3 Create Verification Commands

#### 8.3.1 Create Data Verification Command

**File:** `app/Console/Commands/VerifyInventoryMigrationCommand.php`

```
Tasks:
- [ ] Create Artisan command
- [ ] Implement verification logic:
  - Compare row counts
  - Compare totals
  - Check foreign key integrity
  - Report discrepancies
```

---

## Phase 9: Financial Integration

### 9.1 ChartOfAccount Integration

#### 9.1.1 Create Warehouse ChartOfAccount Service

**File:** `app/Domains/Catalog/Inventory/Services/WarehouseAccountService.php`

```
Tasks:
- [ ] Create service for ChartOfAccount operations
- [ ] Implement createAccountForWarehouse() method
- [ ] Implement updateAccountForWarehouse() method
- [ ] Implement deleteAccountForWarehouse() method
- [ ] Use proper account types and hierarchies
```

#### 9.1.2 Update Warehouse Observer

```
Tasks:
- [ ] Call WarehouseAccountService on warehouse creation
- [ ] Call WarehouseAccountService on warehouse update
- [ ] Handle warehouse deletion (soft delete account)
```

### 9.2 AccountingTransaction Integration

#### 9.2.1 Create Inventory Accounting Service

**File:** `app/Domains/Catalog/Inventory/Services/InventoryAccountingService.php`

```
Tasks:
- [ ] Create service for accounting entries
- [ ] Implement createTransactionEntry() for stock increases
- [ ] Implement createTransactionEntry() for stock decreases
- [ ] Implement createTransactionEntry() for adjustments
- [ ] Implement createTransactionEntry() for transfers
- [ ] Link to proper ChartOfAccount entries
```

### 9.3 Update Financial Reports

#### 9.3.1 Modify Existing Report Queries

```
Tasks:
- [ ] Update inventory valuation reports to use new tables
- [ ] Update stock value reports to use new tables
- [ ] Update movement reports to use new tables
- [ ] Verify report accuracy with test data
```

---

## Phase 10: Testing & Validation

### 10.1 Unit Tests

#### 10.1.1 Model Tests

**Files:**
- `tests/Unit/Domains/Catalog/Inventory/Models/WarehouseTest.php`
- `tests/Unit/Domains/Catalog/Inventory/Models/InventoryTest.php`
- `tests/Unit/Domains/Catalog/Inventory/Models/InventoryCostTest.php`

```
Tasks:
- [ ] Test company scoping
- [ ] Test relationships
- [ ] Test accessors/mutators
- [ ] Test static methods (incrementOrCreate, etc.)
```

#### 10.1.2 Service Tests

**Files:**
- `tests/Unit/Domains/Catalog/Inventory/Services/UnifiedInventoryServiceTest.php`
- `tests/Unit/Domains/Catalog/Inventory/Services/WarehouseServiceTest.php`
- `tests/Unit/Domains/Catalog/Inventory/Services/ValuationServiceTest.php`

```
Tasks:
- [ ] Test all service methods
- [ ] Test error handling
- [ ] Test transaction rollbacks
- [ ] Test event dispatching
```

### 10.2 Feature Tests

#### 10.2.1 API Tests

**Files:**
- `tests/Feature/Domains/Catalog/Inventory/WarehouseApiTest.php`
- `tests/Feature/Domains/Catalog/Inventory/StockApiTest.php`
- `tests/Feature/Domains/Catalog/Inventory/FirstTermApiTest.php`
- `tests/Feature/Domains/Catalog/Inventory/TransferApiTest.php`
- `tests/Feature/Domains/Catalog/Inventory/ReservationApiTest.php`

```
Tasks:
- [ ] Test all API endpoints
- [ ] Test permission middleware
- [ ] Test validation rules
- [ ] Test response formats
```

### 10.3 Integration Tests

#### 10.3.1 Financial Integration Tests

**File:** `tests/Integration/Inventory/AccountingIntegrationTest.php`

```
Tasks:
- [ ] Test ChartOfAccount creation
- [ ] Test AccountingTransaction creation
- [ ] Test balance calculations
```

#### 10.3.2 Migration Tests

**File:** `tests/Integration/Inventory/MigrationTest.php`

```
Tasks:
- [ ] Test data migration accuracy
- [ ] Test rollback capability
- [ ] Test verification commands
```

### 10.4 Create Test Data Factories

```
Tasks:
- [ ] Update WarehouseFactory
- [ ] Update InventoryFactory
- [ ] Create FirstTermFactory
- [ ] Create TransferFactory
- [ ] Create SettlementFactory
```

---

## Phase 11: Cleanup & Deprecation

### 11.1 Mark Deprecated Code

#### 11.1.1 Add Deprecation Notices

```
Tasks:
- [ ] Add @deprecated annotations to old models:
  - MainInventory
  - ProductStore
  - Accounting\InventoryTransaction
  - InventoryValuation
- [ ] Add @deprecated annotations to old services:
  - InventoryServices
  - InventoryValuationService
  - StoreFirstTermServices
  - StoreTransferServices
  - StoreSettlementServices
- [ ] Add @deprecated annotations to old controllers:
  - Accounting\InventoryController
  - MainInventoryController
```

#### 11.1.2 Create Deprecation Logger

**File:** `app/Support/DeprecationLogger.php`

```
Tasks:
- [ ] Create logger for deprecated code usage
- [ ] Log file/line where deprecated code is called
- [ ] Create daily report of deprecation usage
```

### 11.2 Update Documentation

#### 11.2.1 API Documentation

```
Tasks:
- [ ] Update API documentation with new endpoints
- [ ] Mark old endpoints as deprecated
- [ ] Add migration guide for API consumers
```

#### 11.2.2 Internal Documentation

```
Tasks:
- [ ] Update this plan with completion status
- [ ] Create architecture decision record (ADR)
- [ ] Update system diagrams
```

### 11.3 Final Cleanup (Post-Migration Verification)

#### 11.3.1 Remove Deprecated Code (Future Phase)

```
Tasks (to be done after 30+ days of successful operation):
- [ ] Remove MainInventory model
- [ ] Remove ProductStore model
- [ ] Remove Accounting InventoryTransaction model
- [ ] Remove InventoryValuation model
- [ ] Remove old services
- [ ] Remove old controllers
- [ ] Remove old routes
- [ ] Drop deprecated tables
```

---

## Appendix A: File Checklist

### New Files to Create

| File | Phase | Status |
|------|-------|--------|
| `database/migrations/YYYY_add_company_id_to_catalog_warehouses.php` | 1.1.1 | [ ] |
| `database/migrations/YYYY_add_chart_account_id_to_catalog_warehouses.php` | 1.1.2 | [ ] |
| `database/migrations/YYYY_add_item_type_flags_to_catalog_warehouses.php` | 1.1.3 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventories.php` | 1.2.1 | [ ] |
| `database/migrations/YYYY_add_unit_id_to_catalog_inventories.php` | 1.2.2 | [ ] |
| `database/migrations/YYYY_add_approval_workflow_to_catalog_inventories.php` | 1.2.3 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventory_transactions.php` | 1.3.1 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventory_costs.php` | 1.3.2 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventory_batches.php` | 1.3.3 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventory_serials.php` | 1.3.4 | [ ] |
| `database/migrations/YYYY_add_company_id_to_catalog_inventory_reservations.php` | 1.3.5 | [ ] |
| `database/seeders/UnifiedInventoryPermissionSeeder.php` | 2.1.1 | [ ] |
| `database/migrations/YYYY_add_unified_inventory_permissions.php` | 2.1.2 | [ ] |
| `app/Domains/Catalog/Inventory/Observers/WarehouseObserver.php` | 3.1.2 | [ ] |
| `app/Domains/Catalog/Inventory/Enums/InventoryStatus.php` | 3.2.2 | [ ] |
| `app/Domains/Catalog/Inventory/Enums/InventoryItemType.php` | 3.2.3 | [ ] |
| `app/Domains/Accounting/Inventory/Models/MainInventoryBridge.php` | 3.5.1 | [ ] |
| `app/Domains/Accounting/Inventory/Models/ProductStoreBridge.php` | 3.5.2 | [ ] |
| `app/Domains/Catalog/Inventory/Contracts/UnifiedInventoryServiceInterface.php` | 4.1.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/UnifiedInventoryService.php` | 4.1.2 | [ ] |
| `app/Domains/Catalog/Inventory/Services/Valuation/ValuationMethodInterface.php` | 4.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/Valuation/FifoValuationService.php` | 4.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/Valuation/LifoValuationService.php` | 4.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/Valuation/WeightedAverageValuationService.php` | 4.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/Valuation/CurrentPriceValuationService.php` | 4.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Repositories/ValuationRepository.php` | 5.3.1 | [ ] |
| `app/Domains/Catalog/Inventory/Repositories/FirstTermRepository.php` | 5.3.2 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedWarehouseController.php` | 6.1.1 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedStockController.php` | 6.1.2 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedFirstTermController.php` | 6.1.3 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedTransferController.php` | 6.1.4 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedSettlementController.php` | 6.1.5 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedReservationController.php` | 6.1.6 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedValuationController.php` | 6.1.7 | [ ] |
| `app/Domains/Catalog/Inventory/Controllers/V2/UnifiedReportController.php` | 6.1.8 | [ ] |
| `app/Domains/Catalog/Inventory/Requests/V2/*.php` | 6.2.* | [ ] |
| `app/Domains/Catalog/Inventory/Resources/V2/*.php` | 6.3.* | [ ] |
| `routes/apis/UnifiedInventory.php` | 6.4.1 | [ ] |
| `routes/apis/InventoryLegacy.php` | 6.4.2 | [ ] |
| `app/Domains/Catalog/Inventory/Events/*.php` | 7.1.* | [ ] |
| `app/Domains/Catalog/Inventory/Listeners/CreateAccountingTransactionListener.php` | 7.2.1 | [ ] |
| `app/Domains/Catalog/Inventory/Listeners/UpdateChartOfAccountBalanceListener.php` | 7.2.1 | [ ] |
| `app/Console/Commands/MigrateAccountingWarehousesCommand.php` | 8.1.1 | [ ] |
| `app/Console/Commands/MigrateAccountingStockCommand.php` | 8.1.2 | [ ] |
| `app/Console/Commands/MigrateAccountingTransactionsCommand.php` | 8.1.3 | [ ] |
| `app/Console/Commands/MigrateAccountingValuationsCommand.php` | 8.1.4 | [ ] |
| `database/migrations/YYYY_create_inventory_migration_map_table.php` | 8.2.1 | [ ] |
| `app/Console/Commands/VerifyInventoryMigrationCommand.php` | 8.3.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/WarehouseAccountService.php` | 9.1.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/InventoryAccountingService.php` | 9.2.1 | [ ] |
| `tests/Unit/Domains/Catalog/Inventory/Models/*.php` | 10.1.1 | [ ] |
| `tests/Unit/Domains/Catalog/Inventory/Services/*.php` | 10.1.2 | [ ] |
| `tests/Feature/Domains/Catalog/Inventory/*.php` | 10.2.* | [ ] |
| `tests/Integration/Inventory/*.php` | 10.3.* | [ ] |
| `app/Support/DeprecationLogger.php` | 11.1.2 | [ ] |

### Files to Modify

| File | Phase | Status |
|------|-------|--------|
| `app/Domains/Catalog/Inventory/Models/Warehouse.php` | 3.1.1 | [ ] |
| `app/Domains/Catalog/Inventory/Models/Inventory.php` | 3.2.1 | [ ] |
| `app/Domains/Catalog/Inventory/Models/InventoryTransaction.php` | 3.3.1 | [ ] |
| `app/Domains/Catalog/Inventory/Models/InventoryCost.php` | 3.4.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/InventoryService.php` | 4.3.1 | [ ] |
| `app/Domains/Catalog/Inventory/Services/WarehouseService.php` | 4.3.2 | [ ] |
| `app/Domains/Catalog/Inventory/Repositories/WarehouseRepository.php` | 5.1.1 | [ ] |
| `app/Domains/Catalog/Inventory/Repositories/InventoryRepository.php` | 5.2.1 | [ ] |
| `app/Domains/Catalog/Inventory/Contracts/WarehouseRepositoryContract.php` | 5.1.2 | [ ] |
| `app/Domains/Catalog/Inventory/Contracts/InventoryRepositoryContract.php` | 5.2.2 | [ ] |
| `app/Providers/EventServiceProvider.php` | 7.3.1 | [ ] |

### Files to Deprecate (Mark, Don't Delete)

| File | Phase | Status |
|------|-------|--------|
| `app/Domains/Accounting/Entities/Models/MainInventory.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Entities/Models/ProductStore.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Entities/Models/InventoryTransaction.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Inventory/Models/InventoryValuation.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Inventory/Services/InventoryServices.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Inventory/Services/InventoryValuationService.php` | 11.1.1 | [ ] |
| `app/Domains/Accounting/Inventory/Controllers/V1/InventoryController.php` | 11.1.1 | [ ] |

---

## Appendix B: Database Schema Changes Summary

### Tables to Add Columns

| Table | New Columns |
|-------|------------|
| `catalog_warehouses` | company_id, chart_account_id, project_id, title, for_product, for_material, for_equipment |
| `catalog_inventories` | company_id, unit_id, status, type, price, amount |
| `catalog_inventory_transactions` | company_id, unit_id, unit_price, total_price, status |
| `catalog_inventory_costs` | company_id, unit_id, remaining_quantity, is_consumed, batch_number, transaction_date |
| `catalog_inventory_batches` | company_id |
| `catalog_inventory_serials` | company_id |
| `catalog_inventory_reservations` | company_id |

### New Tables

| Table | Purpose |
|-------|---------|
| `inventory_migration_map` | Track migration of records from old to new tables |

---

## Appendix C: Permission Mapping Reference

| Category | Old Permission | New Permission |
|----------|---------------|----------------|
| Warehouses | inventories.index | unified-inventory.warehouses.index |
| Warehouses | - | unified-inventory.warehouses.show |
| Warehouses | - | unified-inventory.warehouses.store |
| Warehouses | - | unified-inventory.warehouses.update |
| Warehouses | - | unified-inventory.warehouses.destroy |
| Stock | inventories.show-store-and-products | unified-inventory.stock.index |
| Stock | - | unified-inventory.stock.show |
| Stock | - | unified-inventory.stock.adjust |
| Stock | - | unified-inventory.stock.transfer |
| Stock | - | unified-inventory.stock.approve |
| First Term | store-first-terms.index | unified-inventory.first-term.index |
| First Term | store-first-terms.show | unified-inventory.first-term.show |
| First Term | store-first-terms.store | unified-inventory.first-term.store |
| First Term | store-first-terms.update | unified-inventory.first-term.update |
| First Term | store-first-terms.destroy | unified-inventory.first-term.destroy |
| Transfers | store-transfers.* | unified-inventory.transfers.* |
| Settlements | store-settlements.* | unified-inventory.settlements.* |
| Catalog | catalog.inventory.view | unified-inventory.stock.index |
| Catalog | catalog.inventory.create | unified-inventory.stock.adjust |
| Catalog | catalog.inventory.manage-warehouses | unified-inventory.warehouses.* |
| Catalog | catalog.inventory.manage-transactions | unified-inventory.transactions.* |

---

*Document Version: 1.0*
*Last Updated: 2026-02-14*
