@davoodmehraban89 / Factor-easy-2 Mirror · read-only / commits / 9f3a0f5
Fork 0

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

Mirrored from https://github.com/davoodmehraban89/Factor-easy.git

Synced Dec 3, 17:00 UTC

Include purchases in sync import and migration

davoodmehraban89 committed Sep 28, 2026 at 12:51 UTC 9f3a0f51196edf6ef8b9ec7a49f586b5be976a47
1 file changed +4 -3
js/sync.js
+4 -3
@@ -1,8 +1,9 @@
1 -let datastore={companies:[],contacts:[],products:[],invoices:[],cheques:[],expenses:[],settings:[]};
1 +let datastore={companies:[],contacts:[],products:[],invoices:[],purchases:[],cheques:[],expenses:[],settings:[]};
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);}
4 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 getMySettings(){
@@ -143,7 +144,7 @@ function safeId(raw,prefix){
144 }
145 function absorbRecords(imported){
146 const uid=currentUser.id;let count=0;
146 - ['companies','contacts','products','invoices','cheques','expenses'].forEach(key=>{
147 + ['companies','contacts','products','invoices','purchases','cheques','expenses'].forEach(key=>{
148 if(!Array.isArray(imported[key]))return;
149 imported[key].forEach(raw=>{
150 if(!raw||typeof raw!=='object')return;
@@ -169,7 +170,7 @@ function maybeMigrateLegacyData(){
170 let old;try{old=JSON.parse(rawOld);}catch(e){return;}
171 const isSeed=it=>it&&it.ownerUserId==='user_admin'&&['COMP-1','C-1','P-1','P-2'].includes(it.id);
172 const clean={};let n=0;
172 - ['companies','contacts','products','invoices','cheques','expenses'].forEach(k=>{
173 + ['companies','contacts','products','invoices','purchases','cheques','expenses'].forEach(k=>{
174 clean[k]=(old&&Array.isArray(old[k])?old[k]:[]).filter(it=>!isSeed(it));
175 n+=clean[k].length;
176 });