# P4 Sales — invoice numbering and physical book control

**Applied:** 2026-10-23  
**Status:** Number registry and book custody foundation implemented on ERP development. Invoice accounting/posting and historical Focus invoice detail import remain pending.

## Owner rules implemented

- An administrator configures a separate starting invoice number for each salesperson.
- The first system number is starting number + 1.
- Abdullah starting at 10000 produces 10001, 10002, and so on.
- Mohammed starting at 20000 produces 20001, 20002, and so on.
- The starting number becomes immutable after the first system invoice number is issued.
- Existing Focus document numbers are preserved as legacy numbers and never renumbered.
- If a legacy/manual number already occupies the next system number, allocation skips it rather than duplicating it.
- Physical manual-invoice, sales-return/damaged-goods and cash/cheque receipt books are registered by printed book number and printed page range.
- A physical book is assigned to an active company salesperson as an auditable custody record.
- Manual documents consume the exact printed number from the assigned book range.
- Used and void printed pages are separately recorded.
- Cash/cheque receipt entries support amount, payment method and cheque number.
- One company-wide registry prevents duplicate invoice, return or receipt numbers across system, book and Focus-legacy sources.

## Implemented surfaces

- `/sales/document-control`
- Per-salesperson system invoice sequence configuration.
- Physical book registration and assignment.
- Printed page use/void recording.
- Company/permission-scoped registry history.
- Salespeople see only their assigned books and numbers unless they have company-wide management rights.

## Safety and boundaries

- Additive migration `2026_10_23_020000`; no existing business rows changed.
- Cross-company books, customers, salespeople and assignments are blocked.
- Overlapping ranges for the same physical book type are rejected.
- A range containing a previously registered ERP/Focus number is rejected.
- Sequence allocation and book-page consumption use database transactions and row locks.
- No delete or renumber action exists.
- The registry reserves a system number, but an invoice record is not yet created.
- Legacy Focus registration currently preserves number/source/reference only; historical header/lines/tax/customer import awaits the real source mapping.
- No inventory movement, receivable, VAT posting or Focus XML generation is performed by this foundation.

## Verification

- Focused numbering/book suite: 6 tests / 21 assertions PASS.
- Full isolated suite: 94 tests / 577 assertions PASS.
- PHP syntax and migration preview pass.
- Migration applied as batch 21 on ERP development.
- Coverage includes independent salesperson sequences, legacy collision skipping, sequence lock, exact printed number, duplicate blocking, overlapping range rejection, custody permissions and cheque receipt data.

## Next input and implementation

1. Obtain representative old Focus invoice exports with header, item, VAT, customer and salesperson identifiers.
2. Confirm which Focus field identifies the salesperson and whether the invoice number is globally unique.
3. Build immutable historical invoice/header/line import using the central number registry.
4. Build ERP draft/confirm invoice records; confirmation reserves the salesperson system number.
5. Generate Focus XML from confirmed ERP invoices and reconcile the accepted import reference.
6. Add physical book return/closure and exception reconciliation for unused, void and missing pages.
