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

fix(company): stamp company on products.js records and guard company writes

davoodmehraban89 committed Oct 14, 2026 at 11:35 UTC 9af5cdbff19fca2141d9f15111d940918535e6d5
1 file changed +6 -4
js/products.js
+6 -4
@@ -20,11 +20,12 @@ function commitSaveProduct(){
20 const internal_id=code;
21 const official_id=document.getElementById('prod-official-id-input')?.value.trim()||'';
22 if(!name){alert('عنوان کالا الزامی است.');return;}
23 + if(!finoraActiveCompanyId())return alert('ابتدا شرکت فعال را انتخاب کنید.');
24 const type=document.getElementById('prod-type-input')?.value||'good',barcode=document.getElementById('prod-barcode-input')?.value.trim()||'',min_stock=parseFormattedNumber(document.getElementById('prod-min-stock-input')?.value||0);
25 if(editingProductId){
25 - const row=datastore.products.find(x=>x.id===editingProductId&&x.ownerUserId===currentUser.id);if(!row)return alert('کالا/خدمت برای اصلاح یافت نشد.');
26 + const row=datastore.products.find(x=>x.id===editingProductId&&finoraInActiveCompany(x));if(!row)return alert('کالا/خدمت برای اصلاح یافت نشد.');
27 Object.assign(row,{code,name,spec,type,category,subcategory,barcode,unit,buy_price,sale_price,min_stock,internal_id,official_id});editingProductId='';alert('کالا/خدمت اصلاح شد.');
27 - }else datastore.products.push({id:'P_'+Date.now(),ownerUserId:currentUser.id,code,name,spec,type,category,subcategory,barcode,unit,buy_price,sale_price,stock:0,min_stock,internal_id,official_id});
28 + }else datastore.products.push({id:'P_'+Date.now(),ownerUserId:currentUser.id,companyId:finoraActiveCompanyId(),code,name,spec,type,category,subcategory,barcode,unit,buy_price,sale_price,stock:0,min_stock,internal_id,official_id});
29 saveDatastore();
30 if(!editingProductId)alert('کالا ثبت شد.');
31 document.getElementById('prod-name-input').value='';
@@ -44,7 +45,7 @@ function deleteProduct(id){
45 if(!currentUser)return;
46 const referenced=Object.entries(datastore).some(([key,rows])=>key!=='products'&&Array.isArray(rows)&&rows.some(r=>{try{return JSON.stringify(r).includes('"'+id+'"')}catch(_){return false}}));if(referenced){alert('این کالا/خدمت در فاکتور، انبار، شمارش یا سابقه عملیاتی استفاده شده و برای حفظ تاریخچه قابل حذف نیست.');return;}
47 if(confirm('حذف شود؟')){
47 - datastore.products=datastore.products.filter(p=>!(p.id===id&&p.ownerUserId===currentUser.id));
48 + datastore.products=datastore.products.filter(p=>!(p.id===id&&finoraInActiveCompany(p)));
49 saveDatastore();refreshAllSurfaces();
50 }
51 }
@@ -62,8 +63,9 @@ function saveQuickProduct(){
63 const internal_id=code;
64 const official_id=document.getElementById('quick-p-official-id')?.value.trim()||'';
65 if(!name){alert('عنوان کالا الزامی است.');return;}
66 + if(!finoraActiveCompanyId())return alert('ابتدا شرکت فعال را انتخاب کنید.');
67 const newId='P_'+Date.now();
66 - datastore.products.push({id:newId,ownerUserId:currentUser.id,code,name,spec,unit,buy_price:0,sale_price:price,stock:0,type:'good',internal_id,official_id});
68 + datastore.products.push({id:newId,ownerUserId:currentUser.id,companyId:finoraActiveCompanyId(),code,name,spec,unit,buy_price:0,sale_price:price,stock:0,type:'good',internal_id,official_id});
69 saveDatastore();
70 closeQuickProductModal();
71 refreshAllSurfaces();