سامانه صدور فاکتور و حسابداری
Implement Office C3 related archive runtime
davoodmehraban89 committed
Sep 30, 2026 at 19:18 UTC
07da0f88649412a87fde8d75a45c2a604b3b26f9
1 file changed
+57
js/office-mature.js
+57
@@ -93,4 +93,61 @@ window.officeReferPrompt=async function(correspondenceId){
93
}
94
await pullAll();alert('ارجاع ثبت شد و در کارتابل پیگیری قابل مشاهده است.');officeRender('work');
95
};
96
+
97
+window.FINORA_ARCHIVE_INDEX=[];
98
+window.officeArchiveIndex=function(){return Array.isArray(window.FINORA_ARCHIVE_INDEX)?window.FINORA_ARCHIVE_INDEX:[]};
99
+function canOffice(c){return typeof hasFinoraCapability==='function'&&hasFinoraCapability('office_automation',c)}
100
+function renderArchiveIndex(){
101
+ const root=document.getElementById('view-office');if(!root)return;
102
+ const rows=window.officeArchiveIndex();
103
+ const body=rows.length?rows.map(r=>{
104
+ const tags=Array.isArray(r.tags)?r.tags.join('، '):'';
105
+ const classify=(canOffice('archive')||canOffice('configure'))?'<button class="btn btn-secondary btn-inline" onclick="officeClassifyPrompt(\''+oe(r.correspondence_id)+'\')">طبقهبندی</button> ':'';
106
+ const link=(canOffice('edit')||canOffice('refer'))?'<button class="btn btn-secondary btn-inline" onclick="officeLinkPrompt(\''+oe(r.correspondence_id)+'\')">ارتباط</button>':'';
107
+ return '<tr><td><strong>'+oe(r.register_number||'—')+'</strong></td><td>'+oe(r.subject||'—')+'</td><td>'+oe(r.folder||'—')+'</td><td>'+oe(r.classification_code||'—')+'</td><td>'+oe(tags||'—')+'</td><td>'+Number(r.related_count||0).toLocaleString('fa-IR')+'</td><td><button class="btn btn-secondary btn-inline" onclick="officeOpenRecord(\''+oe(r.correspondence_id)+'\')">مشاهده</button> '+classify+link+'</td></tr>'
108
+ }).join(''):'<tr><td colspan="7" class="af-empty">مکاتبهای مطابق فیلتر آرشیو یافت نشد.</td></tr>';
109
+ root.innerHTML='<div class="af-head"><div><h1>جستوجو و آرشیو مکاتبات</h1><p>جستوجوی سرورمحور بر اساس فراداده، پوشه و کد طبقهبندی؛ ارتباط پاسخ/مرتبط نیز بهصورت سابقه غیرقابلتغییر ثبت میشود.</p></div></div><div class="card"><div class="form-row"><div class="form-group" style="grid-column:span 2"><label>جستوجو</label><input id="office-archive-q" class="form-control" placeholder="شماره، موضوع، طرف مکاتبه، برچسب"></div><div class="form-group"><label>پوشه</label><input id="office-archive-folder" class="form-control"></div><div class="form-group"><label>کد طبقهبندی</label><input id="office-archive-code" class="form-control"></div></div><button class="btn btn-primary btn-inline" onclick="officeLoadArchiveIndex(true)">جستوجو</button></div><div class="card"><div class="table-responsive"><table><thead><tr><th>ثبت</th><th>موضوع</th><th>پوشه</th><th>کد</th><th>برچسبها</th><th>ارتباطها</th><th>عملیات</th></tr></thead><tbody>'+body+'</tbody></table></div></div>';
110
+}
111
+window.officeLoadArchiveIndex=async function(render=true){
112
+ if(!currentUser?.organizationId)return [];
113
+ const q=document.getElementById('office-archive-q')?.value||null;
114
+ const folder=document.getElementById('office-archive-folder')?.value||null;
115
+ const code=document.getElementById('office-archive-code')?.value||null;
116
+ const {data,error}=await sb.rpc('office_archive_search',{p_organization_id:currentUser.organizationId,p_query:q,p_folder:folder,p_classification_code:code,p_related_to:null});
117
+ if(error){console.error('office archive search failed',error);if(render)alert('جستوجوی آرشیو ناموفق بود: '+error.message);return []}
118
+ window.FINORA_ARCHIVE_INDEX=Array.isArray(data)?data:[];
119
+ if(render)renderArchiveIndex();
120
+ return window.FINORA_ARCHIVE_INDEX;
121
+};
122
+window.officeClassifyPrompt=async function(correspondenceId){
123
+ if(!(canOffice('archive')||canOffice('configure')))return alert('برای طبقهبندی آرشیو دسترسی لازم را ندارید.');
124
+ const folder=String(prompt('پوشه آرشیو:')||'').trim();
125
+ const code=String(prompt('کد طبقهبندی:')||'').trim();
126
+ const tags=String(prompt('برچسبها با ویرگول جدا شوند:')||'').split(',').map(x=>x.trim()).filter(Boolean);
127
+ const {error}=await sb.rpc('office_classify_correspondence',{p_organization_id:currentUser.organizationId,p_correspondence_id:correspondenceId,p_folder:folder,p_classification_code:code,p_tags:tags});
128
+ if(error){console.error('office classification failed',error);return alert('طبقهبندی انجام نشد: '+error.message)}
129
+ await window.officeLoadArchiveIndex(true);alert('طبقهبندی آرشیو با سابقه غیرقابلتغییر ثبت شد.');
130
+};
131
+window.officeLinkPrompt=async function(sourceId){
132
+ if(!(canOffice('edit')||canOffice('refer')))return alert('برای ایجاد ارتباط نامه دسترسی لازم را ندارید.');
133
+ const choices=(datastore.correspondence||[]).filter(x=>x.id!==sourceId).map((x,i)=>({n:i+1,x}));
134
+ if(!choices.length)return alert('نامه دیگری برای ایجاد ارتباط در دسترس نیست.');
135
+ const text=choices.slice(0,50).map(z=>z.n+') '+(z.x.registerNumber||'—')+' · '+(z.x.subject||'بدون موضوع')).join('\n');
136
+ const pick=Number(prompt('نامه مقصد را انتخاب کنید:\n'+text)),chosen=choices.find(z=>z.n===pick);if(!chosen)return;
137
+ const relPick=String(prompt('نوع ارتباط: 1 = پاسخ به، 2 = مرتبط')||'').trim();
138
+ const relation=relPick==='1'?'reply_to':relPick==='2'?'related':null;if(!relation)return;
139
+ const {error}=await sb.rpc('office_link_correspondence',{p_organization_id:currentUser.organizationId,p_source_id:sourceId,p_target_id:chosen.x.id,p_relation_type:relation});
140
+ if(error){console.error('office relation failed',error);return alert('ایجاد ارتباط انجام نشد: '+error.message)}
141
+ await window.officeLoadArchiveIndex(true);alert('ارتباط نامه با سابقه غیرقابلتغییر ثبت شد.');
142
+};
143
+const c2OfficeRender=window.officeRender;
144
+window.officeRender=function(task='inbox'){
145
+ if(task==='archive'){
146
+ c2OfficeRender('inbox');
147
+ renderArchiveIndex();
148
+ window.officeLoadArchiveIndex(true);
149
+ return;
150
+ }
151
+ return c2OfficeRender(task);
152
+};
153
})();
\ No newline at end of file