سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 10:30 UTC
fix(companies): bind invoice header and archive to company selected in Settings
davoodmehraban89 committed
Oct 14, 2026 at 12:27 UTC
350ec0364f35d4696bb494d915f23f03ff2a75dc
1 file changed
+20
-6
js/companies.js
+20
-6
@@ -100,17 +100,31 @@ function renderCompanies(){
100
tbody.innerHTML=myCompanies.map(c=>`<tr><td><strong>${esc(c.name)}</strong></td><td>${esc(companyLegalSummary(c))}</td><td>${esc(COMPANY_ACTIVITY_LABELS[c.activityType||'trading']||c.activityType||'—')}</td><td>${esc(c.national_id||'—')}</td><td>${esc(c.economic_code||'—')}</td><td>${c.id===defCompId?'<span class="badge badge-success">پیشفرض</span>':`<button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px" onclick="setDefaultCompany('${c.id}')">انتخاب</button>`}</td><td><button class="btn btn-secondary btn-inline" style="padding:2px 8px;font-size:11px;margin-left:5px" data-company-id="${c.id}" onclick="editCompany(this.dataset.companyId)">✏️ اصلاح</button>${myCompanies.length>1?`<button class="btn btn-danger btn-inline" style="padding:2px 8px;font-size:11px" onclick="deleteCompany('${c.id}')">حذف</button>`:'—'}</td></tr>`).join('');
101
}
102
}
103
+ // Company selection is owned by Settings, not the invoice archive or
104
+ // seller header. Never offer an "ALL" option that leaks another company's rows.
105
+ const activeCompany=myCompanies.find(c=>c.id===defCompId);
106
if(invoiceCompSelect){
104
- invoiceCompSelect.innerHTML=myCompanies.map(c=>`<option value="${c.id}" ${c.id===defCompId?'selected':''}>${esc(c.name)}</option>`).join('');
105
- if(defCompId)invoiceCompSelect.value=defCompId;
107
+ invoiceCompSelect.innerHTML=activeCompany?`<option value="${esc(activeCompany.id)}">${esc(activeCompany.name)}</option>`:'<option value="">شرکت فعالی انتخاب نشده است</option>';
108
+ invoiceCompSelect.disabled=true;
109
}
110
if(filterCompSelect){
108
- const currentVal=filterCompSelect.value||'ALL';
109
- filterCompSelect.innerHTML=`<option value="ALL">نمایش همه شرکتها</option>`+myCompanies.map(c=>`<option value="${c.id}">فقط ${esc(c.name)}</option>`).join('');
110
- filterCompSelect.value=currentVal;
111
+ filterCompSelect.innerHTML=activeCompany?`<option value="${esc(activeCompany.id)}">فقط ${esc(activeCompany.name)}</option>`:'<option value="">شرکت فعالی انتخاب نشده است</option>';
112
+ filterCompSelect.disabled=true;
113
}
114
}
113
-function setDefaultCompany(id){if(!requireWrite())return;const s=getMySettings();s.default_company_id=id;saveDatastore();refreshAllSurfaces();}
115
+function setDefaultCompany(id){
116
+ if(!requireWrite())return;
117
+ const owned=getMyCompanies().find(c=>c.id===id);
118
+ if(!owned){alert('شرکت انتخابی متعلق به حساب جاری نیست.');return;}
119
+ const s=getMySettings();
120
+ if(s.default_company_id!==owned.id){
121
+ if(document.getElementById('edit-invoice-id')?.value&&typeof cancelInvoiceEdit==='function')cancelInvoiceEdit();
122
+ if(document.getElementById('pur-edit-id')?.value&&typeof purCancelEdit==='function')purCancelEdit();
123
+ s.default_company_id=owned.id;saveDatastore();
124
+ }
125
+ refreshAllSurfaces();
126
+ if(typeof renderDocumentManagement==='function')renderDocumentManagement();
127
+}
128
function deleteCompany(id){
129
if(!requireWrite())return;
130
if(!currentUser)return;