سامانه صدور فاکتور و حسابداری
Mirrored from https://github.com/davoodmehraban89/Factor-easy.git
Synced Dec 4, 15:30 UTC
fix(company): stamp company on contacts.js records and guard company writes
davoodmehraban89 committed
Oct 14, 2026 at 11:35 UTC
69ef27a3a529fa7fe7232036b580febdc549d44a
1 file changed
+5
-3
js/contacts.js
+5
-3
@@ -14,8 +14,9 @@ function commitSaveContact(){
14
const projectModeEl=document.getElementById('contact-project-mode');
15
const project_mode=projectModeEl?projectModeEl.value:'single';
16
if(!raw_name.trim()){alert('نام طرف حساب الزامی است.');return;}
17
+ if(!finoraActiveCompanyId())return alert('ابتدا شرکت فعال را انتخاب کنید.');
18
const formatted_name=formatEntityName(raw_name,entity_type,custom_prefix);
18
- datastore.contacts.push({id:'C_'+Date.now(),ownerUserId:currentUser.id,floatingCode:(typeof afNextFloatingCode==='function'?afNextFloatingCode(2,1):''),entity_type,name:formatted_name,role,mobile,national_id,economic_code,reg_number,postal_code,address,balance:0,project_mode,projects:[]});
19
+ datastore.contacts.push({id:'C_'+Date.now(),ownerUserId:currentUser.id,companyId:finoraActiveCompanyId(),floatingCode:(typeof afNextFloatingCode==='function'?afNextFloatingCode(2,1):''),entity_type,name:formatted_name,role,mobile,national_id,economic_code,reg_number,postal_code,address,balance:0,project_mode,projects:[]});
20
saveDatastore();
21
alert('طرف حساب ثبت شد.');
22
document.getElementById('contact-name-input').value='';
@@ -42,7 +43,7 @@ function deleteContact(id){
43
if(!currentUser)return;
44
const referenced=Object.entries(datastore).some(([key,rows])=>key!=='contacts'&&Array.isArray(rows)&&rows.some(r=>{try{return JSON.stringify(r).includes('"'+id+'"')}catch(_){return false}}));if(referenced){alert('این شخص/شرکت در سند، پرداخت، چک، پروژه، قرارداد یا سابقه تحلیلی استفاده شده و برای حفظ تاریخچه قابل حذف نیست.');return;}
45
if(confirm('حذف شود؟')){
45
- datastore.contacts=datastore.contacts.filter(c=>!(c.id===id&&c.ownerUserId===currentUser.id));
46
+ datastore.contacts=datastore.contacts.filter(c=>!(c.id===id&&finoraInActiveCompany(c)));
47
saveDatastore();refreshAllSurfaces();
48
}
49
}
@@ -55,8 +56,9 @@ function saveQuickContact(){
56
const prefix=entity_type==='natural'?document.getElementById('quick-c-prefix')?.value:'';
57
const raw_name=document.getElementById('quick-c-name').value;
58
if(!raw_name.trim()){alert('نام الزامی است.');return;}
59
+ if(!finoraActiveCompanyId())return alert('ابتدا شرکت فعال را انتخاب کنید.');
60
const newId='C_'+Date.now();
59
- datastore.contacts.push({id:newId,ownerUserId:currentUser.id,floatingCode:(typeof afNextFloatingCode==='function'?afNextFloatingCode(2,1):''),entity_type,name:formatEntityName(raw_name,entity_type,prefix),role:(window.FINORA_QUICK_CONTACT_ROLE||'customer'),mobile:document.getElementById('quick-c-mobile').value,national_id:document.getElementById('quick-c-national').value,economic_code:(entity_type==='natural')?'':document.getElementById('quick-c-economic').value,reg_number:(entity_type==='natural')?'':document.getElementById('quick-c-reg').value,postal_code:document.getElementById('quick-c-postal').value,address:document.getElementById('quick-c-address').value,balance:0,project_mode:'single',projects:[]});
61
+ datastore.contacts.push({id:newId,ownerUserId:currentUser.id,companyId:finoraActiveCompanyId(),floatingCode:(typeof afNextFloatingCode==='function'?afNextFloatingCode(2,1):''),entity_type,name:formatEntityName(raw_name,entity_type,prefix),role:(window.FINORA_QUICK_CONTACT_ROLE||'customer'),mobile:document.getElementById('quick-c-mobile').value,national_id:document.getElementById('quick-c-national').value,economic_code:(entity_type==='natural')?'':document.getElementById('quick-c-economic').value,reg_number:(entity_type==='natural')?'':document.getElementById('quick-c-reg').value,postal_code:document.getElementById('quick-c-postal').value,address:document.getElementById('quick-c-address').value,balance:0,project_mode:'single',projects:[]});
62
saveDatastore();
63
closeQuickContactModal();
64
refreshAllSurfaces();