سامانه صدور فاکتور و حسابداری
Implement Office C6 SLA reminder escalation UI
davoodmehraban89 committed
Oct 1, 2026 at 00:17 UTC
8d96b209f66e1e9a177e07536325422f8ac67282
1 file changed
+51
js/office-mature.js
+51
@@ -293,4 +293,55 @@ window.officeOpenRecord=async function(id){
293
return result;
294
};
295
296
+
297
+window.FINORA_SLA_QUEUE=[];
298
+window.officeSlaWorkQueue=function(){return Array.isArray(window.FINORA_SLA_QUEUE)?window.FINORA_SLA_QUEUE:[]};
299
+window.officeLoadSlaQueue=async function(render=true){
300
+ if(!currentUser?.organizationId)return [];
301
+ const {data,error}=await sb.rpc('office_sla_work_queue',{p_organization_id:currentUser.organizationId});
302
+ if(error){console.error('office SLA queue failed',error);if(render)alert('دریافت کارتابل SLA ناموفق بود: '+error.message);return []}
303
+ window.FINORA_SLA_QUEUE=Array.isArray(data)?data:[];
304
+ if(render)renderSlaWork();
305
+ return window.FINORA_SLA_QUEUE;
306
+};
307
+window.officeEmitSlaEvent=async function(workType,workId,eventName){
308
+ if(!currentUser?.organizationId||!['referral','approval'].includes(workType)||!['sla_reminder','sla_escalated'].includes(eventName))return false;
309
+ const label=eventName==='sla_reminder'?'یادآوری داخلی':'تصعید داخلی';
310
+ const {error}=await sb.rpc('office_emit_sla_event',{
311
+ p_organization_id:currentUser.organizationId,p_work_type:workType,p_work_id:workId,p_event:eventName
312
+ });
313
+ if(error){
314
+ console.error('office SLA event failed',error);
315
+ if(/already emitted for policy window/i.test(error.message||''))return alert(label+' برای بازه سیاست فعلی قبلاً ثبت شده است.');
316
+ if(/24 hours overdue/i.test(error.message||''))return alert('تصعید پس از حداقل ۲۴ ساعت تأخیر مجاز است.');
317
+ if(/pending work required/i.test(error.message||''))return alert('این کار دیگر در وضعیت باز نیست و رویداد SLA جدید برای آن مجاز نیست.');
318
+ return alert(label+' ثبت نشد: '+error.message);
319
+ }
320
+ await window.officeLoadSlaQueue(true);
321
+ alert(label+' بهصورت Evidence داخلی ثبت شد؛ در C6 هیچ ایمیل، پیامک یا webhook بیرونی ارسال نمیشود.');
322
+ return true;
323
+};
324
+function renderSlaWork(){
325
+ const root=document.getElementById('view-office');if(!root)return;
326
+ const rows=window.officeSlaWorkQueue();
327
+ const todayUtc=new Date().toISOString().slice(0,10);
328
+ const body=rows.length?rows.map(r=>{
329
+ const type=r.work_type==='approval'?'تأیید':'ارجاع';
330
+ const stateMap={sent:'ارسالشده',acknowledged:'دریافتشده',completed:'تکمیلشده',pending:'در انتظار',approved:'تأییدشده',rejected:'ردشده',stale:'محتوا تغییر کرده'};
331
+ const state=stateMap[r.work_state]||r.work_state||'—';
332
+ const reminderToday=r.last_reminder_at&&String(r.last_reminder_at).slice(0,10)===todayUtc;
333
+ const canReminder=r.can_emit&&r.overdue&&['sent','acknowledged','pending'].includes(r.work_state)&&!reminderToday;
334
+ const canEscalate=r.can_emit&&r.overdue&&Number(r.overdue_hours||0)>=24&&!r.escalated_at&&['sent','acknowledged','pending'].includes(r.work_state);
335
+ const actions='<button class="btn btn-secondary btn-inline" onclick="officeOpenRecord(\''+oe(r.correspondence_id)+'\')">نامه</button> '
336
+ +(canReminder?'<button class="btn btn-secondary btn-inline" onclick="officeEmitSlaEvent(\''+oe(r.work_type)+'\',\''+oe(r.work_id)+'\',\'sla_reminder\')">یادآوری</button> ':'')
337
+ +(canEscalate?'<button class="btn btn-primary btn-inline" onclick="officeEmitSlaEvent(\''+oe(r.work_type)+'\',\''+oe(r.work_id)+'\',\'sla_escalated\')">تصعید</button>':'');
338
+ return '<tr><td>'+type+'</td><td><strong>'+oe(r.register_number||'—')+'</strong></td><td>'+oe(r.subject||'—')+'</td><td>'+state+(r.overdue?' <strong>· معوق</strong>':'')+'</td><td>'+faDate(r.due_at)+'</td><td>'+Number(r.overdue_hours||0).toLocaleString('fa-IR')+'</td><td>'+faDate(r.last_reminder_at)+'</td><td>'+faDate(r.escalated_at)+'</td><td>'+actions+'</td></tr>';
339
+ }).join(''):'<tr><td colspan="9" class="af-empty">کار دارای مهلت برای نمایش وجود ندارد.</td></tr>';
340
+ root.innerHTML='<div class="af-head"><div><h1>SLA، یادآوری و تصعید</h1><p>وضعیت مهلت از سرور محاسبه میشود. یادآوری و تصعید فقط Evidence داخلی هستند؛ C6 هیچ ارسال ایمیل، پیامک یا webhook بیرونی انجام نمیدهد.</p></div><div><button class="btn btn-secondary btn-inline" onclick="officeLoadSlaQueue(true)">بازخوانی</button></div></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><th>تصعید</th><th>عملیات</th></tr></thead><tbody>'+body+'</tbody></table></div></div>';
341
+}
342
+const c5OfficeRenderForC6=window.officeRender;
343
+window.officeRender=function(task='inbox'){
344
+ if(task==='sla'){c5OfficeRenderForC6('inbox');window.FINORA_OFFICE_TASK='sla';renderSlaWork();window.officeLoadSlaQueue(true);return}
345
+ return c5OfficeRenderForC6(task);
346
+};
347
})();