سامانه صدور فاکتور و حسابداری
Complete runtime financial referential integrity checks
davoodmehraban89 committed
Sep 28, 2026 at 15:23 UTC
05a55581016a09af53a8ab700006212dbd4e2c24
1 file changed
+8
js/selfcheck.js
+8
@@ -8,6 +8,8 @@
8
if(typeof currentUser!=='undefined'&¤tUser&&typeof datastore!=='undefined'){
9
const uid=currentUser.id;
10
const contacts=new Set((datastore.contacts||[]).filter(x=>x.ownerUserId===uid).map(x=>x.id));
11
+ const invoices=new Set((datastore.invoices||[]).filter(x=>x.ownerUserId===uid).map(x=>x.id));
12
+ const purchases=new Set((datastore.purchases||[]).filter(x=>x.ownerUserId===uid).map(x=>x.id));
13
const companies=new Set((datastore.companies||[]).filter(x=>x.ownerUserId===uid).map(x=>x.id));
14
const products=new Set((datastore.products||[]).filter(x=>x.ownerUserId===uid).map(x=>x.id));
15
(datastore.invoices||[]).filter(x=>x.ownerUserId===uid).forEach(i=>{
@@ -20,6 +22,12 @@
22
if(p.companyId&&!companies.has(p.companyId))dataIssues.push('فاکتور خرید '+(p.number||p.id)+' به شرکت حذفشده متصل است.');
23
(p.items||[]).forEach(it=>{if(it.prodId&&!products.has(it.prodId))dataIssues.push('فاکتور خرید '+(p.number||p.id)+' کالای حذفشده دارد.');});
24
});
25
+ (datastore.payments||[]).filter(x=>x.ownerUserId===uid).forEach(p=>{
26
+ if(p.contactId&&!contacts.has(p.contactId))dataIssues.push('دریافت/پرداخت '+p.id+' به طرف حساب حذفشده متصل است.');
27
+ if(p.companyId&&!companies.has(p.companyId))dataIssues.push('دریافت/پرداخت '+p.id+' به شرکت حذفشده متصل است.');
28
+ if(p.invoiceType==='sale'&&p.invoiceId&&!invoices.has(p.invoiceId))dataIssues.push('دریافت '+p.id+' به فاکتور فروش ناموجود متصل است.');
29
+ if(p.invoiceType==='purchase'&&p.invoiceId&&!purchases.has(p.invoiceId))dataIssues.push('پرداخت '+p.id+' به فاکتور خرید ناموجود متصل است.');
30
+ });
31
(datastore.payments||[]).filter(x=>x.ownerUserId===uid).forEach(p=>{
32
if(p.contactId&&!contacts.has(p.contactId))dataIssues.push('دریافت/پرداخت '+p.id+' به طرف حساب حذفشده متصل است.');
33
if(p.companyId&&!companies.has(p.companyId))dataIssues.push('دریافت/پرداخت '+p.id+' به شرکت حذفشده متصل است.');