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

feat: accounting document manager for draft review, edit, posting and audit preview

davoodmehraban89 committed Oct 11, 2026 at 20:44 UTC bb8a60a3f802ad579786523b104dcb5e7a42dbdd
1 file changed +31
js/document-management.js new
+31
@@ -0,0 +1,31 @@
1 +/* Finora document management: accounting posting is explicit, never part of Save. */
2 +function renderDocumentManagement(){
3 + const tbody=document.getElementById('finora-document-management-body');if(!tbody||!currentUser)return;
4 + const status=document.getElementById('document-status-filter')?.value||'all';
5 + const active=typeof afCompanyId==='function'?afCompanyId():'';
6 + const records=getMyInvoices().filter(x=>(!active||x.companyId===active)&&(status==='all'||invoiceDocumentStatus(x)===status))
7 + .slice().sort((a,b)=>String(b.createdAt||b.date||'').localeCompare(String(a.createdAt||a.date||'')));
8 + tbody.innerHTML=records.length?records.map(inv=>{
9 + const state=invoiceDocumentStatus(inv);
10 + const mayPost=invoiceCreatesAccountingEntry(inv.kind)&&state==='draft';
11 + const btn=mayPost?'<button class="btn btn-success btn-inline" data-doc-action="post" data-doc-id="'+esc(inv.id)+'">قطعی‌سازی</button>':'';
12 + const edit=invoiceMayEdit(inv)?'<button class="btn btn-secondary btn-inline" data-doc-action="edit" data-doc-id="'+esc(inv.id)+'">ویرایش</button>':'';
13 + const posted=inv.journalVoucherId?'<button class="btn btn-secondary btn-inline" data-doc-action="voucher" data-doc-id="'+esc(inv.id)+'">مشاهده سند قطعی</button>':'';
14 + const print='<button class="btn btn-secondary btn-inline" data-doc-action="print" data-doc-id="'+esc(inv.id)+'">پیش‌نمایش چاپ</button>';
15 + return '<tr><td>'+esc(inv.number||'—')+'</td><td>'+esc(inv.date||'—')+'</td><td>'+esc(inv.companyName||'—')+'</td><td>'+esc(inv.contactName||'—')+'</td><td>'+Number(inv.grandTotal||0).toLocaleString('fa-IR')+'</td><td>'+esc(invoiceDocumentStatusLabel(inv))+'</td><td style="display:flex;flex-wrap:wrap;gap:5px">'+edit+btn+posted+print+'</td></tr>';
16 + }).join(''):'<tr><td colspan="7" class="af-empty">سندی در این وضعیت ثبت نشده است.</td></tr>';
17 +}
18 +document.addEventListener('click',event=>{
19 + const button=event.target instanceof Element?event.target.closest('#view-journal button[data-doc-action]'):null;
20 + if(!button)return;
21 + const inv=getMyInvoices().find(x=>x.id===button.dataset.docId);
22 + if(!inv)return;
23 + const action=button.dataset.docAction;
24 + if(action==='edit')return editInvoice(inv.id);
25 + if(action==='post')return finalizeInvoiceDocumentUi(inv.id);
26 + if(action==='print')return renderAndPrintDirect(inv.id);
27 + if(action==='voucher'){
28 + if(typeof openDashboardVoucher==='function'&&inv.journalVoucherId)return openDashboardVoucher(inv.journalVoucherId);
29 + alert('مرجع حسابداری قابل نمایش نیست.');
30 + }
31 +});