SRV-18 — Billing V1 — invoices, payments, declarations, credit control
Invoices with legal mentions and statuses, payment recording and reseller declarations with proof, allocations, credit limit/exposure used at checkout, reseller finance summary.
| Field | Details |
|---|---|
| Task code | SRV-18 |
| Phase | P1 — V1 build & integration |
| Product scope | V1 |
| Status | Done (Mon 19 Oct 2026) |
| Start | Mon 19 Oct 2026 |
| Due | Mon 19 Oct 2026 |
| Responsible | Anis — Full-stack developer |
| Co-responsible | — |
| Effort | 1 person-day(s) planned · 5 from scratch · size S |
| Area · app | Server · server |
| Depends on | SRV-16, DQA-09 |
| Unblocks | DSH-07, MOB-12 |
| Milestones | — |
Summary
Invoices with legal mentions and statuses, payment recording and reseller declarations with proof, allocations, credit limit/exposure used at checkout, reseller finance summary.
Description
V1 finance covers invoices, payments, reseller payment declarations and basic credit control (cahier §4.7, §5; FIN-01…FIN-05, FIN-10, ACL-04). This task generates invoices from orders at billing.invoiceOn (default SHIPPED) with InvoiceLine snapshots, FAC-YYYY-NNNNNN numbers and the legal mentions of the invoice template (DQA-09), tracks InvoiceStatus (UNPAID, PARTIALLY_PAID, PAID, OVERDUE by a daily job, CANCELLED), records payments in the back-office and reseller declarations with proof (PaymentStatus PENDING_VERIFICATION → CONFIRMED/REJECTED with reason), allocates payments to invoices (oldest first or manual), and maintains CreditAccount (ceiling, exposure, available) with CreditLimitChange history and the credit check used at checkout and at validation. Credit notes from returns (SRV-20) reduce the balance. It exposes the reseller finance summary. Financial data is visible only to authorised roles (ACL-04). Out of scope: due dates, reminders and accounting exports (V2, SRV-32) and the finance pages (DSH-07).
Subtasks
| # | Subtask | Owner |
|---|---|---|
| 1 | Invoice generation consumer on billing.invoiceOn with InvoiceLine snapshots, HT/VAT/TTC totals and FAC numbering | Anis |
| 2 | Invoice PDF with legal mentions (seller RC, NIF, NIS, AI, address; buyer identifiers; totals; amount in words) from the DQA-09 template | Anis |
| 3 | Invoice status computation from allocations and credit notes; daily OVERDUE job; admin.invoices.cancel with reason | Anis |
| 4 | admin.payments.record (method, amount, reference, date, PAY numbering) and reseller payments.declare with PAYMENT_PROOF file | Anis |
| 5 | admin.payments.verify: confirm or reject with PAYMENT_REJECT_REASON; reseller notified | Anis |
| 6 | Allocation engine: automatic oldest-first allocation and manual admin.payments.allocate; unallocated balance kept | Anis |
| 7 | CreditAccount: ceiling, exposure (unpaid invoices + validated uninvoiced credit orders − credit notes), available; CreditLimitChange history; admin.credit.get/update | Anis |
| 8 | Credit check service replacing the SRV-15 stub, used by checkout and admin.orders.validate (credit.overLimitPolicy) | Anis |
| 9 | Reseller reads finance.summary, invoices.list/get, payments.list with self scope | Anis |
Deliverables
- apps/server/src/modules/billing/{invoices,payments,allocations,credit}.{service,router}.ts, jobs.ts, pdf/invoice.tsx
- packages/contracts/src/{finance.ts,admin/finance.ts}
- Invoice legal mentions checklist signed off with HOCO
Acceptance criteria
- An order reaching SHIPPED (default) gets exactly one invoice with totals equal to its lines (FIN-01)
- A declared payment stays PENDING_VERIFICATION and does not change invoice status until confirmed (FIN-03)
- A payment of 150 000 DA against two unpaid invoices of 100 000 DA each leaves one PAID and one PARTIALLY_PAID (FIN-04)
- A credit checkout that exceeds the available credit returns 422 CREDIT_LIMIT_EXCEEDED under BLOCK policy (FIN-05)
- A user without finance.view gets 403 PERMISSION_DENIED on admin.invoices.list and sees no credit fields elsewhere (ACL-04)
- finance.summary returns balance, available credit, unpaid invoices and recent payments for the reseller only (FIN-10)
Requirements covered
| Requirement | Title | Release |
|---|---|---|
| FIN-01 | Invoices generated from orders with legal mentions and PDF; statuses unpaid, partially paid, paid, overdue, cancelled | V1 |
| FIN-02 | Payment methods: cash on delivery, bank transfer, CCP, BaridiMob, credit | V1 |
| FIN-03 | Payment recording in the back-office and payment declaration with proof by the reseller | V1 |
| FIN-04 | Partial payments and allocation to invoices (reconciliation) | V1 |
| FIN-05 | Basic credit control: ceiling, used and available credit checked at checkout | V1 |
| FIN-10 | Reseller finance view: balance, available credit, invoices, payments | V1 |
| ACL-04 | Least privilege by default; financial data (purchase prices, margins, credit) strictly limited | V1 |
Screens
API surface
| Endpoint group | Operations |
|---|---|
| Reseller finance | 6 |
| Finance | 12 |
Test measures
- DB tests for allocation and status computation including credit notes
- Unit tests for exposure computation
- PDF snapshot test of the invoice with a sample order
Risks
- Algerian invoicing specifics (stamp duty on cash payments, mandatory mentions) not confirmed — checklist reviewed with HOCO's accountant before the template is frozen
KPI
- Delivered by Mon 19 Oct 2026 within 1 person-day(s).
- Every acceptance criterion above demonstrated before hand-off; linked requirements' acceptance criteria pass.
- Zero open critical defects, permission gaps or data-integrity regressions at sign-off.
Generated from content/plan/tasks.json by scripts/generate-team-tasks.mjs. Dates are computed by the scheduler (Sunday–Thursday weeks, holidays excluded) — change the plan, not this page.
SRV-17 — Preparation & delivery module
Delivery records per order, picking list, carrier assignment and tracking number, proof of delivery, delivery-fee policy.
SRV-24 — Support module — tickets & announcements
Tickets with types, related order and items, messages and internal notes, assignment and statuses; announcements with targeting; support contacts/FAQ; support regions with WhatsApp numbers resolved from the declared region or device location.