Module Relationship Diagram (ERD)
erDiagram
SUPPLIER_CATEGORIES ||--|{ SUPPLIERS : "categorizes"
SUPPLIERS ||--|{ ITEM_PURCHASE_PRICES : "sets"
SUPPLIERS ||--|{ PURCHASE_ORDERS : "receives"
PURCHASE_ORDERS ||--|{ PURCHASE_ORDER_ITEMS : "contains"
%% PURCHASE_ORDER_ITEMS ||--|{ PURCHASE_SCHEDULE_ITEMS : "has" %% (schedule items commented out)
PURCHASE_INVOICES ||--|{ PURCHASE_INVOICE_ITEMS : "contains"
PURCHASE_INVOICES }o--|| SUPPLIER_PAYMENTS : "is paid by"
PURCHASE_RETURNS ||--|{ PURCHASE_RETURN_ITEMS : "contains"
SUPPLIER_CATEGORIES {
int id PK
string category_name
string description
bool is_active
}
SUPPLIERS {
int id PK
int supplier_category_id FK
int branch_id FK
int general_ledger_account_id FK "Accounts Payable"
int purchase_general_ledger_account_id FK "Purchase Account"
int purchase_discount_ledger_account_id FK "Purchase Discount Account"
int advance_tax_ledger_account_id FK "Advance Tax Account"
string supplier_code
string supplier_name
string address
string residential_phone
string office_phone
string relevant_person
string mobile_number
string email
string saletax_reg_no
string payment_term
int credit_days
decimal credit_limit
bool is_active
}
ITEM_PURCHASE_PRICES {
int id PK
int item_variant_id FK
int supplier_id FK
decimal purchase_price
decimal purchase_discount
datetime effective_date
}
PURCHASE_ORDERS {
int id PK
int supplier_id FK
int branch_id FK
string po_number "Unique PO code"
date order_date
date delivery_date
string purchaser "Employee/User who created"
string payment_term "Net 30, COD, etc."
string trade_term "FOB, CIF, etc."
decimal sub_total
decimal total_discount
decimal tax_amount
decimal net_total
string status "draft, approved, closed, cancelled"
text remarks
datetime created_at
datetime updated_at
}
PURCHASE_ORDER_ITEMS {
int id PK
int purchase_order_id FK
int item_variant_id FK
decimal quantity
decimal unit_price
decimal discount
json tax "[{tax_id: 1, tax_name: VAT}, {tax_id: 2, tax_name: 'Service Tax'}]"
int total_tax_amount "Sum of all taxes applied"
decimal line_total
}
%% PURCHASE_SCHEDULE_ITEMS { %% (Deprecated/commented in ERD)
%% int id PK
%% int purchase_order_item_id FK
%% date schedule_date
%% decimal scheduled_qty
%% string status "pending, delivered, cancelled"
%% }
SUPPLIERS ||--|{ SUPPLIER_ADVANCES : "receives"
SUPPLIER_ADVANCES ||--|{ SUPPLIER_ADVANCE_ALLOCATIONS : "is allocated to"
SUPPLIER_ADVANCE_ALLOCATIONS }o--|| PURCHASE_INVOICES : "applies to"
SUPPLIER_ADVANCES {
int id PK
int supplier_id FK
string advance_code "e.g., ADV-2026-001"
decimal total_amount
decimal available_balance
string status "draft, active, exhausted, closed"
enum payment_method "CASH|BANK_TRANSFER"
int voucher_id FK "The GL Journal Entry for the Payment"
string description "e.g., Advance for Project Alpha raw materials"
datetime closed_at
string closed_reason "e.g., Project cancelled"
datetime created_at
int created_by FK
}
SUPPLIER_ADVANCE_ALLOCATIONS {
int id PK
int supplier_advance_id FK
enum allocation_type "DOWN_PAYMENT|INVOICE_PAYMENT"
int reference_id FK "The PO ID or Invoice ID"
decimal amount
int gl_voucher_id FK "The Journal Entry created for THIS specific usage"
string status "active, reversed"
datetime allocation_date
int created_by FK
text note "e.g., Used against INV-101"
datetime created_at
}
PURCHASE_INVOICES {
int id PK
string invoice_number
date invoice_date
decimal sub_total
decimal total_discount
decimal shipping_cost
decimal tax_amount
decimal net_total
string reference_type "PO, GRN, Others"
int reference_id FK "ID of linked PO or GRN"
string status "unpaid, partially_paid, paid, cancelled"
datetime posted_at "When invoice was finalized"
}
PURCHASE_INVOICE_ITEMS {
int id PK
int purchase_invoice_id FK
int item_variant_id FK
decimal quantity
decimal unit_price
decimal discount
json tax "[{tax_id: 1, tax_name: VAT}, {tax_id: 2, tax_name: 'Service Tax'}]"
int total_tax_amount "Sum of all taxes applied"
decimal line_total
}
SUPPLIER_PAYMENTS {
int id PK
int invoice_id FK
decimal amount
date payment_date
string payment_method "Cash, Bank Transfer, Cheque"
string reference_number
string status "pending, cleared, bounced"
}
PURCHASE_RETURN_INVOICE {
bigint id PK
varchar return_number UK
bigint purchase_invoice_id FK
bigint receiving_return_voucher_id FK
bigint supplier_id FK
bigint branch_id FK
date return_date
varchar return_reason
decimal sub_total
decimal total_discount
decimal tax_amount
decimal total_amount
enum status
timestamp posted_at
text remarks
bigint created_by FK
}
PURCHASE_RETURN_INVOICE_items {
bigint id PK
bigint purchase_return_invoice_id FK
bigint item_variant_id FK
decimal quantity
decimal unit_price
decimal discount
json tax
decimal total_tax_amount
decimal line_total
}
Purchase Module - Main Flow
flowchart LR
%% Main Flow Controller
S1[1. Supplier
Setup]:::setup --> S2[2. Purchase
Order]:::procurement
S2 --> S3[3. Purchase
Invoice]:::receiving
S3 --> S4[4. Supplier
Payment]:::financials
S3 -.-> S5[5. Purchase
Return]:::returns
S4 & S5 & S3 -.-> S6[6. Financial
Posting]:::gl
%% Styles
classDef setup fill:#262f4a,stroke:#58648c,color:#fff
classDef procurement fill:#3a244a,stroke:#7e529e,color:#fff
classDef receiving fill:#1e4348,stroke:#428a94,color:#fff
classDef financials fill:#244a44,stroke:#529e94,color:#fff
classDef returns fill:#4a2424,stroke:#9e5252,color:#fff
classDef gl fill:#4a4424,stroke:#9e9452,color:#fff
classDef reporting fill:#243a4a,stroke:#527e9e,color:#fff
1. Supplier Setup Flow
flowchart LR
A1[Create Supplier Category] --> A2[Add Supplier Details & Link Accounts]
A2 --> A3{Has Opening Balance?}
A3 -- Yes --> A4[Enter Opening Balance
Cr: Accounts Payable]
A3 -- No --> A5[Optional: Set Supplier-Item Prices]
A4 --> A5
A5 --> A_END(( Ready))
%% Styles
classDef setup fill:#262f4a,stroke:#58648c,color:#fff
class A1,A2,A3,A4,A5,A_END setup
2. Purchase Order (PO) Flow
flowchart LR
B1[Create Purchase Order
Status: Draft] --> B2[Add PO Items]
B2 --> B3{Options?}
B3 -- Add Schedules --> B4[Define Delivery Schedules]
B3 -- Add Downpayment --> B5[Record Downpayment
Dr: Supplier Advance
Cr: Bank]
B3 -- Approve --> B6[Approve PO
Status: Approved]
B4 --> B6
B5 --> B6
B6 --> B_END(( Contractual Stage))
%% Styles
classDef procurement fill:#3a244a,stroke:#7e529e,color:#fff
class B1,B2,B3,B4,B5,B6,B_END procurement
3. Purchase Invoice Flow
flowchart LR
C1[Create Invoice & Link to PO] --> C2[Add Items & Match to PO/GRN]
C2 --> C3{Downpayment to apply?}
C3 -- Yes --> C4[Adjust Downpayment
Dr: Accts Payable
Cr: Supplier Advance]
C3 -- No --> C5[Post Invoice
Dr: Inventory/Expense
Cr: Accts Payable]
C4 --> C5
C5 --> C6[ Stock Levels Updated
Txn: Purchase In]
C6 --> C_END(( Liability Recorded))
%% Styles
classDef receiving fill:#1e4348,stroke:#428a94,color:#fff
class C1,C2,C3,C4,C5,C6,C_END receiving
4. Supplier Payment Flow
flowchart LR
D1[Create Payment & Select Invoices] --> D2{Method?}
D2 -- Cheque/Bank --> D3[Process Payment
Status: Pending -> Cleared]
D2 -- Cash --> D4[Payment Cleared Instantly]
D3 --> D5[Post Payment
Dr: Accts Payable
Cr: Bank/Cash]
D4 --> D5
D5 --> D_END(( Invoice Settled))
%% Styles
classDef financials fill:#244a44,stroke:#529e94,color:#fff
class D1,D2,D3,D4,D5,D_END financials
5. Purchase Return Flow
flowchart LR
E1[Create Return Against Invoice] --> E2[Add Return Items & Reason]
E2 --> E3[Post Return
Dr: Accts Payable
Cr: Inventory]
E3 --> E4[ Stock Levels Updated
Txn: Purchase Return]
E4 --> E_END(( Debit Note Created))
%% Styles
classDef returns fill:#4a2424,stroke:#9e5252,color:#fff
class E1,E2,E3,E4,E_END returns
6. Financial Posting Summary
graph TD
F1["PO Downpayment:
Dr: Supplier Advance
Cr: Bank"]
F2["Purchase Invoice:
Dr: Inventory
Cr: Accts Payable"]
F3["Downpayment Adjustment:
Dr: Accts Payable
Cr: Supplier Advance"]
F4["Supplier Payment:
Dr: Accts Payable
Cr: Bank"]
F5["Purchase Return:
Dr: Accts Payable
Cr: Inventory"]
%% Styles
classDef gl fill:#4a4424,stroke:#9e9452,color:#fff
class F1,F2,F3,F4,F5 gl
7. Reporting & Analytics
graph TD
R1[Supplier Ledger & Aging]
R2[PO & Invoice Status Reports]
R3[Purchase & Return Analysis]
R4[Tax & Supplier Performance]
%% Styles
classDef reporting fill:#243a4a,stroke:#527e9e,color:#fff
class R1,R2,R3,R4 reporting
Table Documentation Links
Suppliers
Master data for all vendors, contacts, and pricing.
Purchase Orders (PO)
Requests for goods, including schedules and downpayments.
Purchase Invoices
The supplier's bill for goods; linked from a PO.
Supplier Payments
Records payments made against supplier invoices.
Purchase Returns
Manages returning goods to suppliers against an invoice.