# TANRAIL ONE — Phase 3.2.4 Procurement Data Model

## 1. Enums
### `PurchaseOrderStatus`
- `DRAFT`: Being drafted by user.
- `SUBMITTED`: Awaiting manager approval.
- `APPROVED`: Confirmed. Sent to supplier. Commercials frozen.
- `PARTIAL_RECEIVED`: Some items received.
- `RECEIVED`: All items fully received.
- `CANCELLED`: Order aborted.

## 2. Core Entities

### `PurchaseOrder`
Tracks the overall purchasing transaction.
- `id`
- `branch_id` (FK to branches, enforces BU context)
- `business_unit_id` (FK to business_units)
- `supplier_id` (FK to suppliers)
- `reference_number` (String, e.g., PO-12345)
- `status` (Enum: PurchaseOrderStatus)
- `subtotal` (Decimal, sum of lines)
- `tax_total` (Decimal, sum of tax)
- `total` (Decimal, final cost)

### `PurchaseOrderLine`
Details the requested goods.
- `id`
- `purchase_order_id` (FK)
- `item_id` (FK to generic Items)
- `quantity` (Decimal, requested amount)
- `unit_price` (Decimal, agreed cost per unit)
- `tax_amount` (Decimal)
- `subtotal` (Decimal)
- `total` (Decimal)
- `received_quantity` (Decimal, tracks partial fulfillment)

### `PurchaseReceipt`
Tracks a physical receiving event (a single delivery truck).
- `id`
- `purchase_order_id` (FK)
- `inventory_location_id` (FK, where goods were placed)
- `reference_number` (Supplier delivery note #)
- `received_at` (Timestamp)
- `created_by` (FK to users)

### `PurchaseReceiptLine`
Tracks what was on the specific truck.
- `id`
- `purchase_receipt_id` (FK)
- `purchase_order_line_id` (FK)
- `item_id` (FK)
- `quantity` (Decimal, amount physically received this time)

### `SupplierPayment` (or reuse Payment)
For simplicity and architectural consistency, we will create `SupplierPayment` (or use a polymorphic `Payment` if authorized. For strictness, `SupplierPayment` avoids altering the Sales architecture).
- `id`
- `purchase_order_id` (FK)
- `amount`
- `method` (PaymentMethod Enum)
- `reference`
