# P4 Sales & CRM — customer foundation

**Applied:** 2026-10-23  
**Status:** Customer master implemented on ERP development. Invoice posting, receivables and Focus invoice XML are not implemented.

## Implemented

- Added the additive `sales_customers` table with company and optional branch ownership.
- Added ERP customer code and optional Focus code, each unique inside its company.
- Preserved customer display/legal names, TRN, contact and billing/shipping addresses.
- Added Cash / On account classification, currency, optional credit-limit reference and payment-term days.
- Added Active / On hold / Inactive lifecycle without destructive delete.
- Added explicit assigned user and creator references.
- Added searchable, paginated `/sales/customers` administration.
- Added create/update audit events with redacted audit infrastructure.
- Replaced the planned Customers navigation entry with the live Sales & CRM customer page.

## Security boundary

- All reads and mutations require a selected active company.
- `sales.view`, `sales.create` and `sales.edit` remain the governing permissions.
- Existing own/team/department/branch/company record scopes are enforced by the shared `RecordScope`.
- Branches and assignees are validated inside the current company.
- Non-company-wide users cannot assign or reassign customers to another user.
- Cross-company IDs return validation errors or 404 without exposing the foreign record.
- No delete route exists.

## Data and accounting boundary

- Credit limit and payment terms are reference fields only.
- No receivable, outstanding balance or credit enforcement is claimed.
- No customer import was run and no existing business data was changed.
- No invoice numbering, tax calculation, stock posting, receipt allocation or Focus XML was inferred.
- Catalog and VAN were not changed.

## Verification

- Focused customer suite: 5 tests / 33 assertions PASS.
- Full isolated SQLite suite: 88 tests / 555 assertions PASS.
- PHP syntax checks pass.
- Migration `2026_10_23_010000` applied as batch 20 on ERP development.
- Feature tests rendered the live customer Blade page and verified navigation, forms and empty state.
- Company isolation, branch isolation, own scope, assignment protection, Focus-code uniqueness and audit events are covered.

## Decisions required before invoice implementation

1. Official invoice number sequence: company-wide or separate per branch.
2. Operational date source: invoice date, posting date or delivery date.
3. VAT calculation/rounding: per line or at document total, and whether unit prices are VAT-inclusive.
4. Cash versus on-account approval and whether an on-hold customer may keep drafts but cannot post.
5. Which warehouse/stock event creates the invoice and deducts stock.
6. Whether ERP exports a confirmed invoice to Focus before or after stock posting.
7. Focus XML voucher type and mandatory codes/fields from an accepted `Transactions_0.xml` sample.
8. Whether Focus import success is recorded manually or by returned reference/file reconciliation.

Until these are approved, P4 must not post invoices or enforce outstanding credit.
