Josan platform — Phase 11, batch 1 verification log Receivables: credit notes, customer refunds, bad-debt write-offs, customer statements, aged receivables Run on 2026-11-20 21:09 UTC, PHP 8.3.6, 10.11.14-MariaDB-0ubuntu0.24.04.1 ================ Full regression (fresh install from schema.sql + demo data, then every test) -- part 1 db:1 web:200 mail:1 == test_phase12.py 33/33 checks passed Remove all demo data later with: php database/demo_seed.php --remove == test_phase3.py 37/37 checks passed == test_phase4.py 34/34 checks passed == test_dashboard.py 90/90 checks passed == test_phase6.py 58/58 checks passed -- part 2 db:1 web:200 mail:1 == test_phase7.py 46/46 checks passed == test_category.py 13/13 checks passed == test_industry.py 18/18 checks passed == test_phase8.py 50/50 checks passed == test_audit_workflow.py 74/74 checks passed == test_phase9.py 57/57 checks passed == test_phase10.py 61/61 checks passed == test_phase10b.py 58/58 checks passed == test_phase10c.py 35/35 checks passed == test_phase11.py 45/45 checks passed == test_phase5.py 59/59 checks passed == separation_test All 255 separation checks passed. == stale_check_test All 10 stale-check tests passed. == backup_restore_test All 10 restore checks passed. == accounting_test All 75 accounting tests passed. == ledger_periods_test All 70 ledger and period tests passed. == autopost_test All 60 automatic posting tests passed. == receivables_test All 55 receivables tests passed. == money_test All 34 money tests passed. == ip_test All 23 IP tests passed. == integrity_check Checked 10 invoices, 7 payments, 29 expenses, 4 attachments, 68 journal entries, 527 accounts, 60 accounting periods. No problems found. == php errors: 0 bytes Totals: browser tests 768 checks (phases 3-11), PHP tests 592 checks (separation 255, stale-check 10, restore 10, accounting 75, ledger and periods 70, automatic posting 60, receivables 55, money 34, IP 23), integrity clean, 0 bytes of PHP errors. ================ tests/receivables_test.php Credit notes: PASS numbered RABFA4-CN-0001; tax credited in the invoice's proportion ($200.00 + $16.50) PASS invoice balance $866.00; stored amount_adjusted and balance_due agree PASS status: partly credited (shown), stored partially paid PASS posted on the credit note date: Dr Revenue $200.00, Dr Sales Tax $16.50, Cr Accounts Receivable $216.50 PASS a credit note cannot exceed what is left to credit PASS form: date before the invoice and an empty reason are refused PASS payments are capped by the balance after credits PASS an invoice with a credit note cannot be cancelled PASS no credit note on a draft invoice Write-offs: PASS write-off posted: Dr 6970 Bad Debts, Cr Accounts Receivable PASS invoice settled: balance $0, status paid, shown as Settled PASS nothing more can be written off PASS cancelled write-off: entry reversed, balance back to $300.00, status partially paid PASS a cancelled write-off cannot be cancelled again PASS cancelling needs a reason Refunds: PASS a paid invoice has nothing to refund until a credit note PASS credit on a paid invoice: balance −$150.00, owed to the customer, refundable $150.00 PASS a refund cannot be more than what is owed back PASS refund numbered RABFA4-RF-0001, posted Dr Accounts Receivable, Cr Bank (cheque) PASS after the refund the invoice is square (balance $0) PASS the credit note cannot be cancelled while its refund stands PASS refund then credit note cancelled: both reversed, invoice paid in full again PASS a payment can still settle the invoice whose write-off was cancelled Database protection: PASS the database refuses a balance due that does not match paid and adjusted PASS the database refuses a credit note whose net + tax is not its total, or a zero amount PASS the database refuses a credit note on another business's invoice or customer PASS a cancelled record must keep its reason Aged receivables: PASS as of Jun 1: Feb-15 invoice 107 days late (over 90), Jun-19 invoice not yet due PASS Mar-1 invoice: $1,082.50 less the $216.50 credit = $866.00, in the 61–90 days column by its due date PASS fully settled invoices are left out PASS aging: owed $1,686.00, and owed less credits owed back = Accounts Receivable in the books at that date PASS a payment dated while the write-off stood shows as credit owed back that day ($300.00) PASS as of Mar 4 (before the credit note): Mar-1 invoice owed in full, and equals the books PASS as of Apr 20 the write-off cancelled later still counts (as in the books) PASS today: aging = sum of balance due on the invoices = Accounts Receivable PASS the Financial Reports aging uses the same figures PASS customer balances report: owed after credits; credits and write-offs column PASS credits owed to customers appear separately, not as a negative owed PASS aging of several businesses keeps them apart Statements: PASS Alice, March: opening $700.00 (Feb invoice), Mar-1 invoice, credit note; closing $1,566.00 PASS running balance and totals PASS Bob, the year: cancelled write-off, credit note and refund are left out PASS statement closing (today) = customer's balance due on invoices PASS a statement shows only that customer of that business PASS statement PDF renders with the balance PASS share link: 64-character token, expires in 90 days PASS credit note PDF renders PASS with two credits, the one a refund relies on still cannot be cancelled (invoice would owe again) Books, integrity and separation: PASS every receivables record is in the books as recorded PASS all postings balance PASS integrity check clean PASS a credit note cancelled outside the app is reported (balance and books out of step) PASS A cannot read, cancel or adjust with B's ids PASS B's list is empty, A's has only A's PASS a business without a Bad Debts account gets one (next free code if 6970 is taken) All 55 receivables tests passed. ================ e2e test_phase11.py (screens, email, WhatsApp link, permissions, owners, separation, phone) PASS two invoices issued for this run PASS credit note form offers up to what can be credited PASS credit note issued: numbered HPP-CN-…, page shows it with the invoice balance now PASS posted: Dr Revenue (and Sales Tax), Cr Accounts Receivable $25.00 PASS credit note page: In the books card PASS credit note PDF PASS credit note emailed (logged, mail delivered with the PDF) PASS customer link opens the credit note without signing in PASS invoice page: balance reduced by $25.00, credits card lists the credit note PASS invoice can no longer be cancelled (it has a credit note) PASS write-off of the remaining balance posted Dr 6970 Bad Debts, Cr Accounts Receivable PASS invoice now Settled, balance $0.00, no Record payment PASS write-off cancelled on screen: entry reversed, balance back PASS another invoice paid in full PASS credit on a paid invoice: page shows Owed to customer $40.00 and a Refund button PASS refund recorded HPP-RF-…: Dr Accounts Receivable, Cr Cash on Hand PASS the credit note cannot be cancelled while its refund stands (message shown) PASS Receivables: customers owe = sum of invoice balances PASS adjustments listed (credit notes, refund, write-off) PASS aged receivables CSV PASS aged receivables PDF PASS aged as of an earlier date (Jan 15): later invoices not owed yet PASS statement closing = the customer's balance due PASS statement PDF PASS statement has Print PASS statement emailed (logged, delivered) PASS WhatsApp: secure link made, wa.me message with the balance and link PASS statement link opens without signing in PASS statement link PDF PASS an expired statement link is refused PASS customer page has a Statement button PASS staff without receivables.adjust: no Credit note or Write off buttons PASS staff without receivables.adjust: the form is refused (403) PASS with the permission the buttons appear PASS staff without records.cancel: no Cancel button PASS staff without records.cancel: cancelling by direct post refused PASS staff without invoices.manage: statement visible, no Email or WhatsApp PASS staff without invoices.manage: sharing by direct post refused (403) PASS staff: an unassigned business's receivables, statements and credit notes are not found PASS owner: Receivables in the menu and the page shows their figures PASS owner: credit note read-only (no Cancel, no Email) PASS owner: statement with PDF and Print, no Email or WhatsApp PASS owner: another business's statement, credit note and admin pages not found PASS phone: receivables, statement, credit note and form fit the screen PASS integrity check clean after the run 45/45 checks passed ================ tests/separation_test.php (receivables lines) PASS blocked: GET admin/receivables.php?business=31 PASS blocked: GET admin/receivables.php?business=31&format=csv PASS blocked: GET admin/statement.php?business=31&customer=33 PASS blocked: GET admin/statement.php?business=30&customer=33 PASS blocked: GET admin/statement.php?business=30&customer=33&format=pdf PASS blocked: GET admin/adjustment_new.php?business=30&invoice=48&type=credit_note PASS blocked: GET admin/adjustment_new.php?business=31&invoice=48&type=write_off PASS blocked: credit note on B's invoice through business A PASS blocked: share B's customer statement through business A PASS A's receivables page has no Business B invoice PASS owner receivables ignore ?business=B PASS owner statement is their own customer PASS blocked: owner GET owner/statement.php?customer=33 PASS blocked: owner GET admin/receivables.php?business=30 PASS blocked: owner GET admin/statement.php?business=30&customer=32 PASS blocked: owner GET owner/adjustment_new.php PASS blocked: owner GET admin/adjustment_new.php?business=30&invoice=48&type=refund PASS redirected to sign in: admin/receivables.php?business=30 PASS redirected to sign in: owner/receivables.php PASS redirected to sign in: admin/statement.php?business=30&customer=32 PASS redirected to sign in: owner/statement.php?customer=32 All 255 separation checks passed. ================ Schema check database/schema.sql (fresh install) and the batch-10 database upgraded with migrate.php (011) give identical columns, constraints and CHECK clauses (compared through information_schema). ================ Found and fixed while testing - The database CHECK on invoices required balance_due = total - amount_paid, so the first credit note was refused. Invoices now keep amount_adjusted (credit notes + write-offs - refunds) and the CHECK is balance_due = total - amount_paid - amount_adjusted, with 0 <= amount_adjusted <= total. - invoice_history.action is an ENUM: the six new history actions were added. - A credit note could be cancelled after its refund when the invoice had another credit. Rule tightened: a credit note or write-off cannot be cancelled while refunds stand if the invoice would owe again (tested). - "Credit note" matched the old test selector for "Edit" (case-insensitive); two browser tests now match the Edit link exactly. ================ tests/integrity_check.php Checked 12 invoices, 8 payments, 29 expenses, 4 attachments, 76 journal entries, 527 accounts, 60 accounting periods. No problems found.