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

fix(company): enforce active-company scope through js/purchases.js runtime paths

davoodmehraban89 committed Oct 14, 2026 at 11:39 UTC 7106fc2a0f3c97963da52efd12b1837c707dc19d
1 file changed +4 -4
js/purchases.js
+4 -4
@@ -5,7 +5,7 @@
5 function myPurchases(){
6 if(!currentUser)return [];
7 if(!Array.isArray(datastore.purchases))datastore.purchases=[];
8 - return datastore.purchases.filter(p=>p.ownerUserId===currentUser.id);
8 + return getMyPurchases();
9 }
10 const $=id=>document.getElementById(id);
11 const fmt=n=>Number(n||0).toLocaleString('fa-IR');
@@ -282,7 +282,7 @@
282 return;
283 }
284 if(editId){
285 - const old=datastore.purchases.find(p=>p.id===editId&&p.ownerUserId===currentUser.id);
285 + const old=myPurchases().find(p=>p.id===editId);
286 if(!old){alert('فاکتور خرید پیدا نشد.');return;}
287 if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(old,'فاکتور خرید');}catch(e){alert(e.message);return;}}
288 Object.assign(old,payload);
@@ -336,7 +336,7 @@
336 window.purDelete=function(id){
337 const source=myPurchases().find(x=>x.id===id);if(!source)return;if(purchaseDocumentStatus(source)==='draft')return purDeleteDraftUi(id);if(purchaseDocumentStatus(source)!=='draft')return alert('فقط نسخه موقت بدون سابقه حسابداری قابل حذف است؛ سند قطعی را از مسیر ابطال قابل‌ردیابی اصلاح کنید.');if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(source,'فاکتور خرید');}catch(e){alert(e.message);return;}}if(typeof getMyPayments==='function'&&getMyPayments().some(p=>p.invoiceType==='purchase'&&p.invoiceId===id)){alert('برای این فاکتور پرداخت ثبت شده است؛ برای حفظ سابقه مالی ابتدا تخصیص پرداخت را اصلاح کنید.');return;}
338 if(!requireWrite()||!confirm('این فاکتور خرید حذف شود؟'))return;
339 - datastore.purchases=datastore.purchases.filter(p=>!(p.id===id&&p.ownerUserId===currentUser.id));
339 + datastore.purchases=datastore.purchases.filter(p=>!(p.id===id&&finoraInActiveCompany(p)));
340 saveDatastore();refreshAllSurfaces();
341 };
342 window.purImportExcel=function(ev){
@@ -356,7 +356,7 @@
356 const price=parseFormattedNumber(r['فی']||r['قیمت']||r['قیمت واحد']||0);
357 if(!name&&!code)return;
358 let p=prods.find(x=>(code&&x.code===code)||(name&&x.name===name));
359 - if(!p){p={id:'P_'+Date.now()+'_'+Math.random().toString(36).slice(2,6),ownerUserId:currentUser.id,code:code||String(prods.length+1),name:name||code,spec:'',type:'good',unit,buy_price:price,sale_price:0,stock:0,internal_id:''};datastore.products.push(p);prods.push(p);}
359 + if(!p){p={id:'P_'+Date.now()+'_'+Math.random().toString(36).slice(2,6),ownerUserId:currentUser.id,companyId:finoraActiveCompanyId(),code:code||String(prods.length+1),name:name||code,spec:'',type:'good',unit,buy_price:price,sale_price:0,stock:0,internal_id:''};datastore.products.push(p);prods.push(p);}
360 purAddRow(p.id,qty,price,unit);n++;
361 });
362 if(n){saveDatastore();alert(n+' ردیف از اکسل اضافه شد.');}else alert('ردیف معتبری پیدا نشد. ستون‌ها: کد کالا، شرح، تعداد، واحد، فی');