سامانه صدور فاکتور و حسابداری
fix(company): reconcile PR133 isolation patch with merged main js/purchases.js
davoodmehraban89 committed
Oct 14, 2026 at 13:15 UTC
a742091f2ea17451476c7e7b10cc378f3e696073
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');
@@ -289,7 +289,7 @@
289
return;
290
}
291
if(editId){
292
- const old=datastore.purchases.find(p=>p.id===editId&&p.ownerUserId===currentUser.id);
292
+ const old=myPurchases().find(p=>p.id===editId);
293
if(!old){alert('فاکتور خرید پیدا نشد.');return;}
294
if(typeof jeGuardSourceMutation==='function'){try{jeGuardSourceMutation(old,'فاکتور خرید');}catch(e){alert(e.message);return;}}
295
Object.assign(old,payload);
@@ -345,7 +345,7 @@
345
window.purDelete=function(id){
346
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;}
347
if(!requireWrite()||!confirm('این فاکتور خرید حذف شود؟'))return;
348
- datastore.purchases=datastore.purchases.filter(p=>!(p.id===id&&p.ownerUserId===currentUser.id));
348
+ datastore.purchases=datastore.purchases.filter(p=>!(p.id===id&&finoraInActiveCompany(p)));
349
saveDatastore();refreshAllSurfaces();
350
};
351
window.purImportExcel=function(ev){
@@ -365,7 +365,7 @@
365
const price=parseFormattedNumber(r['فی']||r['قیمت']||r['قیمت واحد']||0);
366
if(!name&&!code)return;
367
let p=prods.find(x=>(code&&x.code===code)||(name&&x.name===name));
368
- 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);}
368
+ 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);}
369
purAddRow(p.id,qty,price,unit);n++;
370
});
371
if(n){saveDatastore();alert(n+' ردیف از اکسل اضافه شد.');}else alert('ردیف معتبری پیدا نشد. ستونها: کد کالا، شرح، تعداد، واحد، فی');