This is an old revision of the document!
Table of Contents
contact invoices types (Resolved)
Reported by: Khaled Tarabay on 2026-07-29T11:46:48+01:00
Assigned to: Claude
Resolved by: Claude on 2026-07-29T20:45:53+01:00
Priority: normal
Severity: minor
Reproducibility: have not tried
Category: General
Description: the type of contacts we have supplier, client, internet provider right now they all share the same type of invoices with the customers, we don't want that we want that each type of contact has their own invoice format in the “print/pdf” feature and even what type of order transaction with what payment about also if it's a client we can see an invoice or record on how much we collected from him, if a supplier or internet provider what we paid them, if a supplier and a client then we both collect and pay from them, you have to devise a way to apply this, keep it mind the type of orders that each type of contact may differ from the types and stuff we write a customer in an invoice so also reason accordingly, also all these types of invoices should still appear in the invoices tab they all should be connected to the finance module and the finance dashboards. ensure total connectivity with the modules, and before you declare the task done you have to verify that this works with trying it out with new data and checking this data in a perfectionist way, also if you create forms or whatsoever you better ensure they are customizable like the other forms of manara, and also you have to ensure they have the safety limits like no negative numbers in place where positive integers must be, and no letters or characters where numbers must be, and vise versa, and make sure you integrate this perfectly with how manara works right now with it's philosophy, approaches, and techniques
Resolution: FIXED. Each contact type now has its own invoice in the tab, its own Print/PDF format, and full finance connectivity.
WHAT WAS ASKED: clients = a record of what we COLLECTED; suppliers/internet providers = a record of what we PAID them; a supplier+client = both; each type prints in its own format; all appear in the invoices tab and feed the finance module/dashboards; safety limits on amounts.
WHERE / FIX (migration 073 adds invoices.invoice_kind ENUM('sale','purchase')): - Client SALE → a 'sale' invoice (we collect), Draft → Issue → Collect via the real payment path (unchanged from #140). - Supplier/provider PURCHASE → now ALSO raises an invoice: a 'purchase' payable “Purchase Bill” (App\Billing\ContactInvoicer::purchaseBillInvoice()), created Issued, linked to the ledger row. It is deliberately never given `payments` rows (those are money-RECEIVED and would pollute revenue); its Paid/Balance/Status are mirrored from the contact ledger as it's settled (Invoice::applyPurchaseBillSettlement(), driven from ContactTransaction::recordPayment()). Settling a purchase still posts the DEBIT expense to finance (Expenses / Net Liquidity), so it's fully connected. - Print/PDF (app/views/billing/print.php) branches on invoice_kind + contact type: a purchase prints “PURCHASE BILL” with a “Supplier” / “Internet Provider” party heading; a sale/customer prints as an “INVOICE” with “Bill To” / “Client”. - Revenue aggregates (Invoice::totals/invoicedBetween/periodTotals/countsByStatus) exclude 'purchase' bills so payables never inflate invoiced/outstanding revenue; a client sale still counts as revenue. - The /billing list (app/views/billing/index.php) shows a “Purchase” pill and links contact invoices to their contact page. - Safety limits: contact amounts already run through Validator (positive, non-numeric rejected, $100M ceiling) — re-verified for the new purchase path. - Order types: an invoice's direction (Sale vs Purchase) is what differs per contact type; the existing free-text line-item description carries the specifics — no separate per-type taxonomy invented. - Forms: no new standalone form was created (the contact entity form is already Form-Customization-customizable); the purchase/sale is recorded through the existing contact ledger.
VERIFIED LIVE end-to-end (36 checks total, all green): supplier+client contact → a $250 purchase created an Issued Purchase Bill + a $175 sale created a Draft invoice; both appear in /billing; purchase prints “PURCHASE BILL”/“Supplier”, provider-only prints “Internet Provider”, sale prints “Invoice”/“Client”; issuing+collecting the sale drove partially_paid + posted a credit; paying the purchase mirrored the bill (partially_paid → paid, correct balance) + posted a debit expense with NO payments row; Total Invoiced rose by exactly the sale (250 purchase excluded); negative / over-ceiling / non-numeric amounts all rejected; customer-invoice regression clean. PHPUnit 29/29. Test data cleaned up. Prod must run /run-migrations.php for migration 073.
Activity / Notes
- 2026-07-29T20:45:50+01:00 - Claude: FIXED. Each contact type now has its own invoice in the tab, its own Print/PDF format, and full finance connectivity.
WHAT WAS ASKED: clients = a record of what we COLLECTED; suppliers/internet providers = a record of what we PAID them; a supplier+client = both; each type prints in its own format; all appear in the invoices tab and feed the finance module/dashboards; safety limits on amounts.
WHERE / FIX (migration 073 adds invoices.invoice_kind ENUM('sale','purchase')): - Client SALE → a 'sale' invoice (we collect), Draft → Issue → Collect via the real payment path (unchanged from #140). - Supplier/provider PURCHASE → now ALSO raises an invoice: a 'purchase' payable “Purchase Bill” (App\Billing\ContactInvoicer::purchaseBillInvoice()), created Issued, linked to the ledger row. It is deliberately never given `payments` rows (those are money-RECEIVED and would pollute revenue); its Paid/Balance/Status are mirrored from the contact ledger as it's settled (Invoice::applyPurchaseBillSettlement(), driven from ContactTransaction::recordPayment()). Settling a purchase still posts the DEBIT expense to finance (Expenses / Net Liquidity), so it's fully connected. - Print/PDF (app/views/billing/print.php) branches on invoice_kind + contact type: a purchase prints “PURCHASE BILL” with a “Supplier” / “Internet Provider” party heading; a sale/customer prints as an “INVOICE” with “Bill To” / “Client”. - Revenue aggregates (Invoice::totals/invoicedBetween/periodTotals/countsByStatus) exclude 'purchase' bills so payables never inflate invoiced/outstanding revenue; a client sale still counts as revenue. - The /billing list (app/views/billing/index.php) shows a “Purchase” pill and links contact invoices to their contact page. - Safety limits: contact amounts already run through Validator (positive, non-numeric rejected, $100M ceiling) — re-verified for the new purchase path. - Order types: an invoice's direction (Sale vs Purchase) is what differs per contact type; the existing free-text line-item description carries the specifics — no separate per-type taxonomy invented. - Forms: no new standalone form was created (the contact entity form is already Form-Customization-customizable); the purchase/sale is recorded through the existing contact ledger.
VERIFIED LIVE end-to-end (36 checks total, all green): supplier+client contact → a $250 purchase created an Issued Purchase Bill + a $175 sale created a Draft invoice; both appear in /billing; purchase prints “PURCHASE BILL”/“Supplier”, provider-only prints “Internet Provider”, sale prints “Invoice”/“Client”; issuing+collecting the sale drove partially_paid + posted a credit; paying the purchase mirrored the bill (partially_paid → paid, correct balance) + posted a debit expense with NO payments row; Total Invoiced rose by exactly the sale (250 purchase excluded); negative / over-ceiling / non-numeric amounts all rejected; customer-invoice regression clean. PHPUnit 29/29. Test data cleaned up. Prod must run /run-migrations.php for migration 073.
Full History
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2026-07-29T11:46:48+01:00 | Khaled Tarabay | issue-new | New Issue |
| 2026-07-29T20:45:46+01:00 | Claude | Assigned To | ⇒ Claudine |
| 2026-07-29T20:45:48+01:00 | Claude | tag-added | Tag Attached: done-by-claude |
| 2026-07-29T20:45:50+01:00 | Claude | note-added | Note Added: 0000101 |
| 2026-07-29T20:45:53+01:00 | Claude | Status | new ⇒ resolved |
Synced automatically from MantisBT issue #142.
