سامانه صدور فاکتور و حسابداری
fix(finance): preserve reversal status and block direct deletion of finalized/legacy invoices
davoodmehraban89 committed
Oct 11, 2026 at 21:02 UTC
6396717fe5c441ae6feb1264855365e842d7e86e
1 file changed
+1
-1
js/operations.js
+1
-1
@@ -63,7 +63,7 @@ window.deleteExpense=function(id){if(!requireWrite())return;const source=getMyEx
63
window.renderExpenses=function(){const tb=$('expenses-ledger-table-body'),list=getMyExpenses();if(!tb)return;refreshExpenseContacts();const projectName=e=>{const c=getMyContacts().find(x=>x.id===e.contactId);for(const p of (c?.projects||[])){if(p.id===e.projectId)return p.name;const s=(p.subprojects||[]).find(x=>x.id===e.projectId);if(s)return p.name+' / '+s.name;}return e.projectId?'پروژه حذف/تغییر یافته':'—';};tb.innerHTML=list.length?list.map(e=>`<tr><td>${esc(e.kind)}</td><td>${esc(e.category)}</td><td>${esc(e.contactName||'—')}</td><td>${esc(projectName(e))}</td><td>${esc(e.desc)}</td><td>${fmt(e.amount)}</td><td><button class="btn btn-secondary btn-inline" onclick="editExpense('${e.id}')">✏️ اصلاح</button> <button class="btn btn-danger btn-inline" onclick="deleteExpense('${e.id}')">حذف</button></td></tr>`).join(''):'<tr><td colspan="7" style="text-align:center;padding:20px">موردی ثبت نشده است.</td></tr>';};
64
65
// فاکتور فروش: حذف در کنار ویرایش/چاپ
66
-window.deleteInvoice=function(id){const source=getMyInvoices().find(x=>x.id===id);if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(source,'فاکتور فروش');}catch(e){alert(e.message);return;}}if(typeof getMyPayments==='function'&&getMyPayments().some(p=>p.invoiceType==='sale'&&p.invoiceId===id)){alert('برای این فاکتور دریافت ثبت شده است؛ برای حفظ سابقه مالی ابتدا تخصیص دریافت را اصلاح کنید.');return;}if(!requireWrite()||!confirm('این فاکتور حذف شود؟'))return;datastore.invoices=datastore.invoices.filter(x=>!(x.id===id&&x.ownerUserId===currentUser.id));saveDatastore();refreshAllSurfaces();};
66
+window.deleteInvoice=function(id){const source=getMyInvoices().find(x=>x.id===id);if(typeof invoiceDocumentStatus==='function'&&(!source||!['draft','operational'].includes(invoiceDocumentStatus(source)))){alert('حذف مستقیم اسناد قطعی یا قدیمی مجاز نیست؛ از مدیریت اسناد استفاده کنید.');return;}if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(source,'فاکتور فروش');}catch(e){alert(e.message);return;}}if(typeof getMyPayments==='function'&&getMyPayments().some(p=>p.invoiceType==='sale'&&p.invoiceId===id)){alert('برای این فاکتور دریافت ثبت شده است؛ برای حفظ سابقه مالی ابتدا تخصیص دریافت را اصلاح کنید.');return;}if(!requireWrite()||!confirm('این فاکتور حذف شود؟'))return;datastore.invoices=datastore.invoices.filter(x=>!(x.id===id&&x.ownerUserId===currentUser.id));saveDatastore();refreshAllSurfaces();};
67
const ri=window.renderInvoices;window.renderInvoices=function(){ri();document.querySelectorAll('#invoice-archive-table-body tr').forEach(tr=>{const edit=tr.querySelector('button[onclick^="editInvoice"]');if(!edit)return;const m=(edit.getAttribute('onclick')||'').match(/editInvoice\('([^']+)'\)/);if(!m)return;const cell=tr.lastElementChild;if(cell&&!cell.querySelector('.delete-invoice')){const b=document.createElement('button');b.className='btn btn-danger btn-inline delete-invoice';b.style.cssText='padding:4px 8px;font-size:12px;min-height:30px';b.textContent='حذف';b.onclick=()=>deleteInvoice(m[1]);cell.appendChild(b);}});};
68
try{if(currentUser)refreshAllSurfaces();}catch(e){console.error('crud init',e);}
69
})();
\ No newline at end of file