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

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

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

Synced Dec 4, 00:30 UTC

Replace project direction prompt with in-app selector

davoodmehraban89 committed Sep 28, 2026 at 15:50 UTC 9b602e0046d9b2e1c26cc7747a1d9b0657e92b13
1 file changed +16 -9
js/projects.js
+16 -9
@@ -1,16 +1,23 @@
1 // پروژه و زیرپروژه برای طرف حساب‌های پروژه‌محور
2 function getContactProjects(contactId){const c=getMyContacts().find(x=>x.id===contactId);if(!c)return[];if(!Array.isArray(c.projects))c.projects=[];c.projects.forEach(p=>{if(!p.direction)p.direction='both';if(!Array.isArray(p.subprojects))p.subprojects=[];});return c.projects;}
3 function projectDirectionLabel(d){return d==='sale'?'فروش':d==='purchase'?'خرید':'خرید و فروش';}
4 +function ensureProjectDirectionModal(){
5 + if(document.getElementById('project-direction-modal'))return;
6 + const d=document.createElement('div');d.id='project-direction-modal';d.className='modal-backdrop';
7 + d.innerHTML='<div class="modal-card" style="max-width:420px"><h3 style="margin-bottom:12px">نوع گردش پروژه</h3><div class="form-group"><label>کاربرد پروژه</label><select id="project-direction-select" class="form-control"><option value="both">خرید و فروش</option><option value="sale">فروش</option><option value="purchase">خرید</option></select></div><div style="display:flex;gap:8px;justify-content:flex-end"><button class="btn btn-secondary btn-inline" id="project-direction-cancel">انصراف</button><button class="btn btn-primary btn-inline" id="project-direction-ok">تأیید</button></div></div>';
8 + document.body.appendChild(d);
9 +}
10 function askProjectDirection(current='both'){
5 - const label=projectDirectionLabel(current);
6 - const raw=prompt('نوع پروژه را وارد کنید: فروش، خرید، یا هر دو',label);
7 - if(raw===null)return current;
8 - const v=String(raw).trim().toLowerCase();
9 - const map={'فروش':'sale','خرید':'purchase','هر دو':'both','خرید و فروش':'both','sale':'sale','purchase':'purchase','both':'both'};
10 - return map[v]||current;
11 + ensureProjectDirectionModal();const modal=document.getElementById('project-direction-modal'),sel=document.getElementById('project-direction-select');
12 + sel.value=['sale','purchase','both'].includes(current)?current:'both';modal.classList.add('active');
13 + return new Promise(resolve=>{
14 + const finish=v=>{modal.classList.remove('active');document.getElementById('project-direction-ok').onclick=null;document.getElementById('project-direction-cancel').onclick=null;resolve(v);};
15 + document.getElementById('project-direction-ok').onclick=()=>finish(sel.value);
16 + document.getElementById('project-direction-cancel').onclick=()=>finish(current);
17 + });
18 }
12 -function addProjectToContact(contactId){if(!requireWrite())return;const c=getMyContacts().find(x=>x.id===contactId);if(!c)return;const name=prompt('نام پروژه جدید را وارد کنید:');if(!name||!name.trim())return;getContactProjects(contactId).push({id:'PRJ_'+Date.now(),name:name.trim(),direction:askProjectDirection(),subprojects:[]});c.project_mode='multi';saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
13 -function editContactProject(contactId,projectId){if(!requireWrite())return;const p=getContactProjects(contactId).find(x=>x.id===projectId);if(!p)return;const n=prompt('نام پروژه:',p.name);if(!n||!n.trim())return;p.name=n.trim();p.direction=askProjectDirection(p.direction);saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
19 +async function addProjectToContact(contactId){if(!requireWrite())return;const c=getMyContacts().find(x=>x.id===contactId);if(!c)return;const name=prompt('نام پروژه جدید را وارد کنید:');if(!name||!name.trim())return;getContactProjects(contactId).push({id:'PRJ_'+Date.now(),name:name.trim(),direction:await askProjectDirection(),subprojects:[]});c.project_mode='multi';saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
20 +async function editContactProject(contactId,projectId){if(!requireWrite())return;const p=getContactProjects(contactId).find(x=>x.id===projectId);if(!p)return;const n=prompt('نام پروژه:',p.name);if(!n||!n.trim())return;p.name=n.trim();p.direction=await askProjectDirection(p.direction);saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
21 function deleteContactProject(contactId,projectId){
22 if(!requireWrite())return;
23 const p=getContactProjects(contactId).find(x=>x.id===projectId);if(!p)return;
@@ -24,7 +31,7 @@ function deleteContactProject(contactId,projectId){
31 const c=getMyContacts().find(x=>x.id===contactId);if(!c)return;c.projects=getContactProjects(contactId).filter(x=>x.id!==projectId);saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);
32 }
33 function addSubproject(contactId,projectId){if(!requireWrite())return;const p=getContactProjects(contactId).find(x=>x.id===projectId);if(!p)return;const n=prompt('نام زیرپروژه:');if(!n||!n.trim())return;p.subprojects.push({id:'SUB_'+Date.now(),name:n.trim(),direction:p.direction||'both'});saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
27 -function editSubproject(contactId,projectId,subId){if(!requireWrite())return;const p=getContactProjects(contactId).find(x=>x.id===projectId),s=p?.subprojects?.find(x=>x.id===subId);if(!s)return;const n=prompt('نام زیرپروژه:',s.name);if(!n||!n.trim())return;s.name=n.trim();s.direction=askProjectDirection(s.direction||p.direction||'both');saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
34 +async function editSubproject(contactId,projectId,subId){if(!requireWrite())return;const p=getContactProjects(contactId).find(x=>x.id===projectId),s=p?.subprojects?.find(x=>x.id===subId);if(!s)return;const n=prompt('نام زیرپروژه:',s.name);if(!n||!n.trim())return;s.name=n.trim();s.direction=await askProjectDirection(s.direction||p.direction||'both');saveDatastore();refreshAllSurfaces();manageContactProjects(contactId);}
35 function deleteSubproject(contactId,projectId,subId){
36 if(!requireWrite())return;
37 const usedSale=getMyInvoices().some(i=>i.projectId===subId);