All money movement in AquaDealers flows through the cash_book table, providing a unified ledger for every financial transaction.
| Field | Description |
|---|---|
entry_type | cash_in Money received (from bills, payments) cash_out Money paid out (purchases, supplier payments, expenses) |
source | Origin of the entry — see source types below |
amount | Absolute amount of the transaction |
reference_id | Links back to the originating record (bill ID, payment ID, etc.) |
| Source | Entry Type | Created By |
|---|---|---|
bill | cash_in | Bill creation (amount_paid portion) |
payment | cash_in | Farmer payment collection |
purchase | cash_out | Stock purchase from supplier |
supplier_payment | cash_out | Payment made to supplier |
expense | cash_out | Expense recording |
manual | either | Manual cash book adjustment |
cash_book entry via its respective RPC. This ensures the cash book is always in sync with the underlying transactions.
At the end of each business day, the dealer performs a cash closing to reconcile actual cash on hand with the system's expected balance.
| Field | Description |
|---|---|
opening_balance | Cash at start of day (previous day's closing or manual override) |
total_in | Sum of all cash_in entries for the day |
total_out | Sum of all cash_out entries for the day |
expected_closing | opening_balance + total_in − total_out |
actual_closing | Actual cash counted by the dealer |
variance | actual_closing − expected_closing |
notes | Optional notes explaining variance |
The opening balance for a new day is automatically set to the previous day's actual_closing value. If no previous closing exists (first day, or gap in closings), the dealer can enter a manual opening balance override. This ensures continuity even if days are skipped.
| Metric | Calculation | Source |
|---|---|---|
| Today's Sales | Σ bills.total WHERE bill_date = today AND status ≠ cancelled |
get_dashboard_aggregates RPC |
| Today's Collection | Σ payments.amount WHERE payment_date = today |
get_dashboard_aggregates RPC |
| Outstanding Dues | Σ farmers.total_due WHERE total_due > 0 |
Dashboard + Dues page |
| Cash in Hand | opening + cash_in − cash_out for today |
Cashbook daily counter |
| Inventory Value | Σ(inventory.quantity_in_stock × inventory.cost_price) |
Dashboard stat |
| Supplier Dues | Σ suppliers.total_due |
Supplier list |
Uses the get_profit_report_data RPC to calculate profitability.
Profit = Revenue − COGS − Expenses Where: Revenue = Σ(bill totals) for the period COGS = Σ(FIFO lot cost_price × quantity sold) per item Expenses = Σ(expenses.amount) for the period
Cost of Goods Sold (COGS) is calculated using FIFO lot tracking. When items are sold, the cost price comes from the specific inventory lots that were consumed (earliest first). This gives an accurate per-item cost basis rather than using average cost.
| Field | Description |
|---|---|
category | User-defined category (electricity, rent, transport, etc.) |
amount | Expense amount |
description | Free-text description |
paid_via | Payment method used (cash, upi, etc.) |
expense_date | Date of the expense |
Each expense automatically creates a cash_book entry with entry_type = cash_out and source = expense.
Categories are user-defined — dealers can create and manage their own expense categories. There are no hard-coded categories in the system. Common examples include: electricity, rent, transport, labour, repairs, feed wastage.
Supplier finances mirror the farmer side but in the opposite direction — the dealer owes money to suppliers instead of receiving it.
Recorded in stock_purchases table.
cost_price_per_unitsupplier.total_due via triggersRecorded in supplier_payments table.
supplier.total_duecash_book entry (cash_out, source: supplier_payment)Available at /suppliers/:id. Shows a chronological view of all purchases and payments for a given supplier, with running balance calculation.
supplier.total_due is maintained by database triggers, similar to farmers.total_due. It is automatically recalculated whenever stock purchases or supplier payments are inserted, updated, or deleted.