سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 10:30 UTC
fix(purchases): hide other companies in purchase register and guard cross-company edit/print
davoodmehraban89 committed
Oct 14, 2026 at 12:28 UTC
eab533aff9dc1fbef545b339eea1f31665bc89f3
1 file changed
+11
-2
js/purchases.js
+11
-2
@@ -83,8 +83,10 @@
83
return v;
84
}
85
function purchaseVisibleRecords(){
86
+ const active=typeof afCompanyId==='function'?afCompanyId():getMySettings().default_company_id;
87
+ if(!active||!getMyCompanies().some(c=>c.id===active))return [];
88
const rows=myPurchases(),parents=new Set(rows.map(p=>p.correctsPurchaseId).filter(Boolean));
87
- return rows.filter(p=>!parents.has(p.id));
89
+ return rows.filter(p=>p.companyId===active&&!parents.has(p.id));
90
}
91
window.purchaseVisibleRecords=purchaseVisibleRecords;
92
window.purchaseVisibleNumber=purchaseVisibleNumber;
@@ -270,7 +272,12 @@
272
if(previousDraft?.correctsPurchaseId&&purchaseDocumentStatus(previousDraft)==='draft'
273
&&purNumber===purchaseVisibleNumber(previousDraft))purNumber=previousDraft.number;
274
if(purNumber&&myPurchases().some(p=>p.id!==editId&&p.supplierId===supSel.value&&String(p.number||'').trim()===purNumber)&&!(editingPostedPurchaseId===editId&&purchaseVisibleNumber(myPurchases().find(p=>p.id===editId))===purNumber)){alert('این شماره فاکتور برای تأمینکننده انتخابشده قبلاً ثبت شده است.');return;}
273
- const activeCompanyId=getMySettings().default_company_id||getMyCompanies()[0]?.id||'';const warehouseId=$('pur-warehouse')?.value||'',projectId=ccSel.value,projectName=projectId?ccSel.options[ccSel.selectedIndex].text:'';const payload={warehouseId,number:purNumber,date:$('pur-date').value.trim()||getJalaliNumeric(),companyId:activeCompanyId,supplierId:supSel.value,supplierName:supSel.options[supSel.selectedIndex].text,projectId,projectName,costCenterId:'',costCenterLabel:'',contractNumber:$('pur-contract').value.trim(),paymentMethod,paymentMethodLabel:paymentMethod==='credit'?'نسیه':'نقدی',items,subtotal:t.sub,discount:t.disc,vat:t.vat,grandTotal:t.grand,description:$('pur-desc').value.trim()};
275
+ const activeCompanyId=afCompanyId();
276
+ if(!activeCompanyId||!getMyCompanies().some(c=>c.id===activeCompanyId)){alert('شرکت فعال را در تنظیمات انتخاب کنید.');return;}
277
+ if(editId&&myPurchases().find(p=>p.id===editId)?.companyId!==activeCompanyId){
278
+ alert('برای اصلاح این فاکتور باید شرکت مربوطه را در تنظیمات فعال کنید.');return;
279
+ }
280
+ const warehouseId=$('pur-warehouse')?.value||'',projectId=ccSel.value,projectName=projectId?ccSel.options[ccSel.selectedIndex].text:'';const payload={warehouseId,number:purNumber,date:$('pur-date').value.trim()||getJalaliNumeric(),companyId:activeCompanyId,supplierId:supSel.value,supplierName:supSel.options[supSel.selectedIndex].text,projectId,projectName,costCenterId:'',costCenterLabel:'',contractNumber:$('pur-contract').value.trim(),paymentMethod,paymentMethodLabel:paymentMethod==='credit'?'نسیه':'نقدی',items,subtotal:t.sub,discount:t.disc,vat:t.vat,grandTotal:t.grand,description:$('pur-desc').value.trim()};
281
if(editId&&editingPostedPurchaseId===editId){
282
const btn=$('pur-save-btn');if(btn)btn.disabled=true;
283
void purchaseSaveSeamless(editId,payload).then(()=>{
@@ -315,6 +322,7 @@
322
};
323
window.purEdit=function(id,allowPostedCorrection=false){
324
const p=myPurchases().find(x=>x.id===id);if(!p)return;
325
+ if(!afCompanyId()||p.companyId!==afCompanyId()){alert('ابتدا شرکت مربوط به فاکتور را در تنظیمات فعال کنید.');return;}
326
if(purchaseDocumentStatus(p)!=='draft'&&!(allowPostedCorrection&&purchaseDocumentStatus(p)==='posted')){alert('سند قطعی ابتدا از مدیریت اسناد به نسخه موقت اصلاحی تبدیل شود؛ اسناد قدیمی نیازمند تطبیق هستند.');return;}
327
$('pur-edit-id').value=p.id;$('pur-form-title').innerText='✏️ اصلاح فاکتور خرید '+purchaseVisibleNumber(p);
328
$('pur-save-btn').innerText='💾 ذخیره اصلاحات';$('pur-cancel-edit').style.display='inline-flex';
@@ -324,6 +332,7 @@
332
};
333
window.purPrint=function(id){
334
const source=myPurchases().find(x=>x.id===id);if(!source)return;
335
+ if(!afCompanyId()||source.companyId!==afCompanyId()){alert('ابتدا شرکت مربوط به فاکتور را در تنظیمات فعال کنید.');return;}
336
const current=purchaseCurrentVisible(id)||source,p={...current,number:purchaseVisibleNumber(current)};
337
const cur=(typeof getCurrencyLabel==='function'?getCurrencyLabel():'ریال');
338
const itemRows=(p.items||[]).map((it,i)=>`<tr><td>${(i+1).toLocaleString('fa-IR')}</td><td>${esc(it.prodName||'')}</td><td>${esc(it.unit||'')}</td><td>${Number(it.qty||0).toLocaleString('fa-IR')}</td><td>${fmt(it.price)}</td><td>${fmt(it.lineTotal)}</td></tr>`).join('');