html
A Comprehensive Guide to the PurchaseController Workflow and Architecture
The PurchaseController manages the entire lifecycle of material receiving into the system. This includes managing suppliers, item inventories, accounting ledgers, and barcode generation. It is a critical component for inventory management and financial tracking.
The system uses a normalized database structure to ensure data integrity across purchases, inventory, and accounts.
| Table Name | Description | Key Fields |
|---|---|---|
purchases |
Master table for purchase headers. | _order_number, _ledger_id, _total |
purchase_details |
Line items for each purchase invoice. | _item_id, _qty, _rate, _barcode |
purchase_accounts |
Accounting entries related to the purchase. | _ledger_id, _dr_amount, _cr_amount |
item_inventories |
Stock movement ledger entries. | _item_id, _qty, _transection |
product_price_list |
Maintains current stock & pricing for barcodes. | _barcode, _pur_rate, _qty |
accounts |
Global financial transaction journal (referenced as Model Accounts). |
_ref_master_id, _account_ledger |
Models are mapped using Eloquent for seamless database interactions.
PurchaseDetail and
PurchaseAccount.Inventory (Items) and Units.
The PurchaseController handles complex multi-step transactions using database commits and
rollbacks for safety.
| Method | Route Type | Core Functionality |
|---|---|---|
index() |
GET | Lists all purchases with advanced filters (date, branch, user). |
create() |
GET | Initializes the form with ledger and item dropdowns. |
store() |
POST | Critical method: Saves Master, Details, Inventory, and Ledger entries. |
edit($id) |
GET | Retrieves an existing purchase for modification. |
update() |
POST | Clears old entries and re-processes the entire transaction. |
purchasePrint($id) |
GET | Generates PDF/Printable invoice using one of 4 templates. |
Pro-Tip: The store() and update() methods automatically
update the supplier's balance and generate accounting vouchers (Debit/Credit) across involved ledgers.
The interface is split into specialized Blade components for better maintainability.
| View Path | Purpose |
|---|---|
backend.purchase.index |
Overview dashboard and search interface. |
backend.purchase.create |
Dynamic entry form with AJAX barcode and item search. |
backend.purchase.edit |
Record editing interface. |
backend.purchase.print |
Invoice template selector (System Default). |
backend.purchase.money_receipt |
Generates payment vouchers for the transaction. |
Navigate to Material Receipt > Create New. Choose the Branch, Cost Center, and Date. Select the Main Ledger (Supplier).
Search or barcode-scan items. Enter Quantity, Purchase Rate, and Sales Rate. The system handles VAT and Discounts per line item.
Check the Sub-Total and Grand Total. Ensure Account Ledger entries (Debit/Credit) for payments (if any) are correctly mapped in the account section below the items.
Click "Save Information". The controller will:
1. Generate an Invoice Number.
2. Add stock to item_inventories.
3. Deduct/Credit supplier ledger.
4. (Optional) Send an SMS to the supplier.
Use the Print action to download the invoice or the Money Receipt action for financial proof.