سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 15:30 UTC
feat(company): fail closed for cross-company operational getters and unassigned multi-company legacy records
davoodmehraban89 committed
Oct 14, 2026 at 11:33 UTC
8b708706a49db53bd03fb4ae7da9951eaa856795
1 file changed
+25
-7
js/sync.js
+25
-7
@@ -1,12 +1,30 @@
1
let datastore={companies:[],contacts:[],products:[],invoices:[],purchases:[],cheques:[],expenses:[],payments:[],settings:[],fiscalYears:[],accounts:[],dimensionTypes:[],dimensionValues:[],accountDimensionRules:[],branches:[],projects:[],projectLinks:[],postingProfiles:[],journalVouchers:[],journalLines:[],journalLineDimensions:[],contracts:[],contractAmendments:[],contractParties:[],contractDeductions:[],guarantees:[],guaranteeEvents:[],contractStatements:[],phase4Audit:[],warehouses:[],stockMovements:[],inventoryCounts:[],fixedAssets:[],assetDepreciations:[],currencies:[],exchangeRates:[],costCenters:[],importBatches:[],integrationConnections:[],integrationOutbox:[],phase5Audit:[],employees:[],employmentContracts:[],employeeLeave:[],cashboxes:[],pettyCashFunds:[],complianceRules:[],payrollRuns:[],payrollLines:[],employeeBenefitAccruals:[],pettyCashTransactions:[],budgets:[],costDrivers:[],costAllocations:[],intercompanyTransactions:[],enterpriseAudit:[]};
2
-function getMyProducts(){return !currentUser?[]:datastore.products.filter(p=>p.ownerUserId===currentUser.id);}
3
-function getMyContacts(){return !currentUser?[]:datastore.contacts.filter(c=>c.ownerUserId===currentUser.id);}
2
function getMyCompanies(){return !currentUser?[]:datastore.companies.filter(c=>c.ownerUserId===currentUser.id);}
5
-function getMyInvoices(){return !currentUser?[]:datastore.invoices.filter(i=>i.ownerUserId===currentUser.id);}
6
-function getMyPurchases(){return !currentUser?[]:(datastore.purchases||[]).filter(i=>i.ownerUserId===currentUser.id);}
7
-function getMyCheques(){return !currentUser?[]:datastore.cheques.filter(c=>c.ownerUserId===currentUser.id);}
8
-function getMyExpenses(){return !currentUser?[]:datastore.expenses.filter(e=>e.ownerUserId===currentUser.id);}
9
-function getMyPayments(){return !currentUser?[]:(datastore.payments||[]).filter(p=>p.ownerUserId===currentUser.id);}
3
+// Active company is one exact owned company, NOT all companies or a holding-wide
4
+// writable context. Orphaned data can be reviewed separately, never broadcast.
5
+function finoraActiveCompanyId(){
6
+ if(!currentUser)return '';
7
+ const companies=getMyCompanies(),selected=getMySettings().default_company_id;
8
+ return companies.some(c=>c.id===selected)?selected:(companies[0]?.id||'');
9
+}
10
+function finoraInActiveCompany(x,{allowSingleCompanyLegacy=true}={}){
11
+ if(!currentUser||!x||x.ownerUserId!==currentUser.id)return false;
12
+ const cid=finoraActiveCompanyId();if(!cid)return false;
13
+ if(x.companyId)return x.companyId===cid;
14
+ // Old unassigned records are only shown while a single company exists.
15
+ // When additional companies are created they become unassigned-review cases.
16
+ return allowSingleCompanyLegacy&&getMyCompanies().length===1;
17
+}
18
+function finoraScopedRows(key,{allowSingleCompanyLegacy=true}={}){
19
+ return !currentUser?[]:(datastore[key]||[]).filter(x=>finoraInActiveCompany(x,{allowSingleCompanyLegacy}));
20
+}
21
+function getMyProducts(){return finoraScopedRows('products');}
22
+function getMyContacts(){return finoraScopedRows('contacts');}
23
+function getMyInvoices(){return finoraScopedRows('invoices');}
24
+function getMyPurchases(){return finoraScopedRows('purchases');}
25
+function getMyCheques(){return finoraScopedRows('cheques');}
26
+function getMyExpenses(){return finoraScopedRows('expenses');}
27
+function getMyPayments(){return finoraScopedRows('payments');}
28
function getMySettings(){
29
if(!currentUser)return{invoice_kind:'non_formal',vat_mode:'none',vat_rate:10,default_company_id:'',currency_mode:'rial',currency_custom:''};
30
if(!Array.isArray(datastore.settings))datastore.settings=[];