سامانه صدور فاکتور و حسابداری

fix(print): remove pale draft watermark from all invoice printouts (#90)

* docs(phase0): log owner print watermark defect and safe fix scope * fix(print): remove draft-status overlay from invoice print layout * fix(print): bust cached print bundle after watermark removal * test(print): verify clean formal draft print with unchanged accounting state * test(print): protect clean pro-forma invoice output * test(finance): require clean invoice prints while retaining draft/posting invariants

davoodmehraban89 committed Oct 12, 2026 at 09:56 UTC 8a0023c53f0c14b0063ab771fdb3669a05997387
6 files changed +31 -5
PROJECT_STATE.md
+8
@@ -285,3 +285,11 @@ Owner reports login blocked with generic 'check internet/VPN' network error on l
285 - **All protected-main gates on this exact SHA:** Quality `38211377516` SUCCESS, Security `38211377395` SUCCESS, Release gate `38211501537` SUCCESS, gated Pages `38211523493` SUCCESS. Duplicate Release `38211497461` cancelled and Pages `38211511555` skipped; these duplicates were **not** counted as passing.
286 - Confirmed persistent `main` acceptance register read back, with F0-01..F0-08 status matrix, nine old PR dispositions, Supabase migration/security-advisor read-only evidence and no unauthorized mutation. Remote read-only HTTP smoke confirmed `factoreasy.ir` plus `js/login-connectivity.js`, `js/ux-hardening-r2.js`, `js/print.js` HTTP 200 from authorized device. No user-authenticated login, real tenant query, true server invoice save, actual printer, dual-account RLS or precise served asset-version parity is claimed.
287 - **Current decision:** PHASE 0 ACCEPTANCE STARTED / **NOT OWNER-ACCEPTED**. Continue F0-01 owner-ISP login first, F0-02 live catalog/person search, F0-04 print-existing-invoice visual check, then separately authorized isolated safe F0-03 write/read and F0-07 second-account permission proof. F0-05 stress controlled test passed but live tenant acceptance open; F0-06 UI visual review and F0-08 old PR final disposition remain. No code, schema, role, auth, finance or account changes allowed by this docs-only checkpoint. Rollback: revert PR #88 (or the acceptance documentation slice only).
288 +
289 +
290 +## 2026-10-12 Phase 0 F0-04 owner screenshot: remove draft watermark from printed invoices — FIX REQUESTED / IN PROGRESS
291 +- **Owner direction:** The attached photograph of an actual printed sale-goods/services invoice shows a pale diagonal header overlay `پیش‌نویس — غیرقطعی`. Remove that overlay from all ordinary invoice printouts (formal, informal, pro-forma, purchase where applicable), without interrupting ongoing Phase 0 acceptance. The owner requests a clean full invoice layout independent of document draft status.
292 +- **Baseline:** protected `main` `5c2a5bf263f7a3bfe5a6b2e99cba5c8e5443db04`; Phase 0 acceptance register from merged PR #88 is present. Investigation isolated overlay to `js/print.js` `renderAndPrintDirect` lines building `draftMark` and prepending it to `stageInvoicePrint`. Print-preview isolated frame and printable container both use that string. Taxpayer/electronic document printing has a separate explicit post/finalization check and remains unchanged.
293 +- **Accountable:** implementation/print with independent QA. **Narrow authorized scope:** remove display watermark only; add browser regression asserting clean formal draft and a pro-forma/non-formal printed page still contains all invoice content, amounts, and unchanged financial draft status. Preserve `invoiceDocumentStatus` / posting gate, electronic taxpayer safeguards, numeric formatting, pagination, dimensions, signature areas, invoice saving/editing and report status. Change `index.html` print asset cache key to force deployment refresh. Add regression to existing Quality suite, PR gates and gated deployment verification.
294 +- **Forbidden:** changing stored draft/posted status, auto-posting, RLS/Auth/schema/roles, financial data, Supabase, legal/tax declarations, closing Phase 0 by inference. Recheck with owner's real printed invoice remains separate F0-04 authenticated acceptance gate. Revert the targeted PR for rollback if necessary.
295 +- **State:** REPRODUCED IN SOURCE / IMPLEMENTATION STARTING. Phase 0 acceptance stays OPEN.
index.html
+1 -1
@@ -893,7 +893,7 @@ body{background:#f6f9fc}
893 <script src="js/sync.js?v=20260928-data-v4"></script>
894 <script src="js/ui.js?v=20261002-shell-scroll-ownership-v2"></script>
895 <script src="js/invoices.js?v=20261011-doc-draft-v1"></script>
896 -<script src="js/print.js?v=20261011-draft-watermark-v2"></script>
896 +<script src="js/print.js?v=20261012-clean-invoice-print-v1"></script>
897 <script src="js/products.js"></script>
898 <script src="js/contacts.js?v=20260928-roles-v3"></script>
899 <script src="js/cheques.js"></script>
js/print.js
+3 -3
@@ -565,7 +565,7 @@ function renderAndPrintDirect(invId){
565 const totalPages=pageGroups.length;
566 const containerHtml=pageGroups.map((g,idx)=>builder(g.items,seller,contact,inv,{pageNum:idx+1,totalPages,isFirstPage:g.isFirstPage,isLastPage:g.isLastPage,cumulativeBefore:g.cumulativeBefore,cumulativeSubtotal:g.cumulativeSubtotal,cumulativeDiscount:g.cumulativeDiscount,cumulativeVat:g.cumulativeVat,cumulativeNet:g.cumulativeNet})).join('');
567 const spec=getInvoicePrintSpec(inv);
568 - const unposted=typeof invoiceDocumentStatus==='function'&&invoiceDocumentStatus(inv)==='draft';
569 - const draftMark=unposted?'<div style="position:fixed;top:16mm;left:28%;font-size:19pt;font-weight:900;opacity:.24;transform:rotate(-12deg);z-index:1000;pointer-events:none">پیش‌نویس — غیرقطعی</div>':'';
570 - stageInvoicePrint(draftMark+containerHtml,spec);
568 + // Print the complete invoice layout without a draft-status watermark.
569 + // Document state and explicit accounting finalization remain unchanged.
570 + stageInvoicePrint(containerHtml,spec);
571 }
scripts/accounting-document-workflow.spec.js
+12
@@ -85,6 +85,18 @@ test('formal invoice remains editable draft across server reload; explicit posti
85 expect(remoteInvoices(server)[0].accountingStatus).toBe('draft');
86 expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(0);
87 const id=remoteInvoices(server)[0].id;
88 + // A saved formal draft prints its complete invoice; the print UI must not stamp it
89 + // as provisional. The underlying draft state and zero-posting invariant remain.
90 + await page.evaluate(x=>renderAndPrintDirect(x),id);
91 + await expect(page.locator('#printable-invoice')).toContainText('FIN-DRAFT-۰۰۱');
92 + await expect(page.locator('#printable-invoice')).toContainText('۳٬۰۰۰');
93 + await expect(page.locator('#printable-invoice')).not.toContainText('پیش‌نویس — غیرقطعی');
94 + await expect(page.locator('#printable-invoice [style*="rotate(-12deg)"]')).toHaveCount(0);
95 + const isolatedPrint=page.frameLocator('#finora-print-frame').locator('#finora-print-document');
96 + await expect(isolatedPrint).toContainText('FIN-DRAFT-۰۰۱');
97 + await expect(isolatedPrint).not.toContainText('پیش‌نویس — غیرقطعی');
98 + expect(remoteInvoices(server)[0].accountingStatus).toBe('draft');
99 + expect([...server.records.values()].filter(x=>x.collection==='journalVouchers')).toHaveLength(0);
100 await page.reload({waitUntil:'domcontentloaded'});await authenticatedMockBrowser(page);
101 await page.evaluate(x=>editInvoice(x),id);
102 await expect(page.locator('#edit-invoice-id')).toHaveValue(id);
scripts/phase0-invoice-persistence.spec.js
+2
@@ -107,6 +107,8 @@ test('F0-03 isolated invoice save → mock-server sync → reload → edit → r
107 await page.evaluate(id=>renderAndPrintDirect(id),savedId);
108 await expect(page.locator('#printable-invoice')).toContainText('QA-PINV-۰۰۰۱');
109 await expect(page.locator('#printable-invoice')).toContainText('۴٬۵۰۰');
110 + await expect(page.locator('#printable-invoice')).not.toContainText('پیش‌نویس — غیرقطعی');
111 + await expect(page.frameLocator('#finora-print-frame').locator('#finora-print-document')).not.toContainText('پیش‌نویس — غیرقطعی');
112 const printable=await page.locator('#printable-invoice').innerText();
113 expect(printable).not.toMatch(/[0-9٠-٩]/);
114 });
scripts/posting-idempotency-check.mjs
+5 -1
@@ -22,5 +22,9 @@ assert.match(manager,/invoiceDocumentStatus\(inv\)/);
22 assert.match(product,/invoiceDocumentStatus\(x\)==='posted'/);
23 assert.match(inventory,/invoiceDocumentStatus\(d\)==='posted'/);
24 assert.match(cash,/invoiceDocumentStatus\(inv\)!=='posted'/);
25 -assert.match(print,/پیش‌نویس — غیرقطعی/);
25 +assert.doesNotMatch(print,/پیش‌نویس — غیرقطعی|draftMark/);
26 +assert.match(print,/stageInvoicePrint\(containerHtml,spec\)/);
27 +// Financial finalization remains explicit even though the ordinary paper print is clean.
28 +assert.match(invoice,/documentStatus:'draft',accountingStatus:'draft'/);
29 +assert.match(invoice,/async function finalizeInvoiceDocument\(/);
30 console.log('Financial draft/posted data safety invariants PASS');