# Sales Module

Implemented:

- Customer master data: see `docs/customer-supplier-module.md`.
- Sales invoices at `/sales-invoices`.
- Sales returns at `/sales-returns`.
- POS sales at `/pos`: see `docs/pos-module.md`.

## Sales Invoice Rules

- Sales invoices are posted documents only; posted invoices are immutable.
- Posting runs inside `SalesInvoiceService::createAndPost()` as one transaction.
- Document numbers use branch, company, and fiscal-year scoped `SI-000001` sequences.
- The invoice customer must be active and branch-scoped to the selected company and branch.
- Current invoice lines support active inventory-tracked items only.
- Line warehouse, batch, expiry, serial, and stock availability are validated by the stock movement engine.
- Posting creates a stock issue through `StockMovementService`, then copies actual calculated stock costs back to invoice lines.
- Posting creates a balanced journal entry for customer receivable, sales revenue, output tax when present, COGS, and inventory relief.
- Required seeded posting accounts are Product Sales, Output Tax Payable, Merchandise Inventory, and Cost of Goods Sold.
- Every posted invoice records an audit log event `SalesInvoice.posted`.

## Sales Return Rules

- Sales returns are posted documents only and must reference a posted sales invoice.
- Posting runs inside `SalesReturnService::createAndPost()` as one transaction.
- Return document numbers use branch, company, and fiscal-year scoped `SR-000001` sequences.
- Return date must be inside the selected open fiscal period and cannot be before the original invoice date.
- Return lines must reference original sales invoice lines; price, discount, tax, and cost are derived from the original invoice line.
- Return quantity cannot exceed the invoice line quantity remaining after previous posted returns.
- Posting creates an inbound `sales_return` stock movement using the original invoice unit cost.
- Posting creates a balanced journal entry that debits sales revenue and output tax, credits customer receivable, debits inventory, and credits COGS.
- Every posted return records an audit log event `SalesReturn.posted`.

Deferred work: standalone receipts, customer refunds, customer statements, customer opening balances, configurable item sales accounts, and service/non-stock sales.
