@davoodmehraban89 / Factor-easy / commits / 4a09715
Fork 0

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

Protect financial records referenced by settlements

davoodmehraban89 committed Sep 28, 2026 at 15:09 UTC 4a0971579fe850ea45f0f99c87430d2ef622cc4d
1 file changed +3 -2
js/operations.js
+3 -2
@@ -13,7 +13,8 @@ const dc=window.deleteContact;window.deleteContact=function(id){
13 const sales=getMyInvoices().some(i=>i.contactId===id);
14 const buys=(datastore.purchases||[]).some(p=>p.ownerUserId===currentUser?.id&&p.supplierId===id);
15 const chqs=getMyCheques().some(q=>q.contactId===id);
16 - if(sales||buys||chqs){alert('این طرف حساب در اسناد مالی استفاده شده و برای حفظ سابقه قابل حذف نیست. ابتدا اسناد مرتبط را حذف یا به طرف حساب دیگری منتقل کنید.');return;}
16 + const pays=typeof getMyPayments==='function'&&getMyPayments().some(p=>p.contactId===id);
17 + if(sales||buys||chqs||pays){alert('این طرف حساب در اسناد مالی استفاده شده و برای حفظ سابقه قابل حذف نیست. ابتدا اسناد مرتبط را حذف یا به طرف حساب دیگری منتقل کنید.');return;}
18 if(ec===id)resetContact();return dc(id);
19 };
20 const rc=window.renderContacts;window.renderContacts=function(){rc();document.querySelectorAll('#contacts-ledger-table-body tr').forEach(tr=>{const del=tr.querySelector('button.btn-danger');if(!del)return;const m=(del.getAttribute('onclick')||'').match(/deleteContact\('([^']+)'\)/);if(!m)return;const id=m[1],cell=del.parentElement;if(!cell.querySelector('.edit-contact')){const b=document.createElement('button');b.className='btn btn-secondary btn-inline edit-contact';b.style.cssText='padding:4px 8px;font-size:12px;min-height:30px;margin-left:5px';b.textContent='✏️ اصلاح';b.onclick=()=>editContact(id);cell.insertBefore(b,del);}});};
@@ -62,7 +63,7 @@ window.deleteExpense=function(id){if(!requireWrite()||!confirm('این سند ح
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 // فاکتور فروش: حذف در کنار ویرایش/چاپ
65 -window.deleteInvoice=function(id){if(!requireWrite()||!confirm('این فاکتور حذف شود؟'))return;datastore.invoices=datastore.invoices.filter(x=>!(x.id===id&&x.ownerUserId===currentUser.id));saveDatastore();refreshAllSurfaces();};
66 +window.deleteInvoice=function(id){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