ورود کارشناس

`); w.document.close();setTimeout(()=>{w.focus();w.print();},500); } function renderLists(){ const el=$r('receiptExpertLists');if(!el)return; const activeLists=lists.filter(l=>l.status!=='approved'); const archivedLists=lists.filter(l=>l.status==='approved'); if(!activeLists.length&&!archivedLists.length){el.innerHTML='

هنوز فهرستی ثبت نشده است.

';return;} const caseDeliveryBadge=(x,l)=>{ const stage=String(l?.status||'').toLowerCase(); if(stage==='approved')return '✓ تأیید نهایی مدیر'; if(stage==='secretary_approved')return '✓ تأیید دبیر · در انتظار مدیر'; if(stage==='secretary_rejected')return 'ردشده توسط دبیر'; if(stage==='manager_rejected')return 'ردشده توسط مدیر'; if(stage==='submitted')return 'در انتظار تأیید دبیر'; const st=String(x.case_delivery_status||'not_found').toLowerCase(); if(st==='confirmed')return 'تحویل به دبیر تأیید شد'; if(st==='rejected')return 'تحویل به دبیر رد شد'; if(st==='pending')return 'در انتظار تأیید دبیر'; return 'تحویل به دبیر تأیید نشده'; }; el.innerHTML='

فهرست‌های جاری و در انتظار بررسی

ملاک این ستون، تأیید واقعی تحویل پرونده در پنل دبیر است؛ وضعیت فیش نباید به‌اشتباه جایگزین وضعیت تحویل پرونده شود.
'+activeLists.map(l=>{ const rows=l.expert_financial_receipt_items||[]; const canModifyList=['draft','submitted','secretary_approved','secretary_rejected','manager_rejected'].includes(l.status)&&!l.approved_at;const canResubmit=['draft','secretary_rejected','manager_rejected'].includes(l.status)&&!l.approved_at&&rows.length>0; const table=rows.length?'
'+rows.map(x=>{const itemEditable=canModifyList;return '';}).join('')+'
شماره فیشمبلغتاریخشماره پروندهمتقاضیوضعیت بررسی و تأییدعملیات
'+esc(x.receipt_no)+''+faMoney(x.amount)+' تومان'+esc(gregorianReceiptToJalali(x.receipt_date)||'—')+''+esc(x.case_no)+''+esc(x.applicant_name)+''+caseDeliveryBadge(x,l)+(x.case_delivery_confirmed_at?'
'+esc(new Date(x.case_delivery_confirmed_at).toLocaleString('fa-IR'))+'
':'')+'
'+(itemEditable?' ':'فقط پس از تأیید نهایی مدیر قفل است')+'
':'

این فهرست هنوز فیشی ندارد.

'; const statusText=l.status==='approved'?'تأیید نهایی مدیر':l.status==='secretary_approved'?'تأیید دبیر؛ ارسال‌شده به مدیر':l.status==='secretary_rejected'?'ردشده توسط دبیر':l.status==='manager_rejected'?'ردشده توسط مدیر':l.status==='submitted'?'در انتظار بررسی دبیر':'پیش‌نویس'; const statusMessage=l.status==='secretary_approved'?'فهرست مالی شما توسط دبیر تأیید و برای مدیر ارسال شده است':l.status==='approved'?'تأیید نهایی مدیر انجام شد؛ فهرست مالی شما قطعی و قفل شده است':''; const messageBox=statusMessage?'
'+statusMessage+'
':''; const managerApprovalBox=l.status==='approved'?'
✓تأیید نهایی مدیر انجام شداین فهرست به تأیید نهایی رسیده است و دیگر قابل ویرایش نیست.'+(l.approved_at?'زمان تأیید: '+esc(new Date(l.approved_at).toLocaleString('fa-IR'))+'':'')+'
':''; return '
'+esc(l.title)+'
'+esc(statusText)+' · '+new Date(l.created_at).toLocaleDateString('fa-IR')+' · '+faMoney(rows.reduce((s,x)=>s+Number(x.amount||0),0))+' تومان
'+(l.secretary_note?'
یادداشت دبیر: '+esc(l.secretary_note)+'
':'')+(l.manager_note?'
یادداشت مدیر: '+esc(l.manager_note)+'
':'')+'
'+(canResubmit?' ':'')+'
'+table+'
'; }).join('')+ (archivedLists.length?'
🗄️ بایگانی فیش‌های تأیید نهایی ('+archivedLists.length.toLocaleString('fa-IR')+')

سوابق قطعی و بایگانی فیش‌های تأیید نهایی

فهرست‌های این بخش فقط برای مشاهده و چاپ هستند و در تهیه فهرست جدید محاسبه نمی‌شوند.

'+ archivedLists.map(l=>{ const rows=l.expert_financial_receipt_items||[]; const total=rows.reduce((s,x)=>s+Number(x.amount||0),0); const table=rows.length?'
'+ rows.map(x=>'').join('')+ '
شماره فیشمبلغتاریخشماره پروندهمتقاضی
'+esc(x.receipt_no)+''+faMoney(x.amount)+' تومان'+esc(gregorianReceiptToJalali(x.receipt_date)||'—')+''+esc(x.case_no)+''+esc(x.applicant_name)+'
':'

جزئیات فیش ثبت نشده است.

'; return '
'+esc(l.title||'فهرست قطعی')+'
✓ تأیید نهایی مدیر · '+new Date(l.approved_at||l.created_at).toLocaleDateString('fa-IR')+' · '+rows.length.toLocaleString('fa-IR')+' فیش · '+faMoney(total)+' تومان
'+table+'
'; }).join('')+'
':''); } function faMoney(n){return Number(n||0).toLocaleString('fa-IR');} document.addEventListener('click',e=>{const pick=e.target.closest('[data-receipt-case]');if(pick){const sel=$r('receiptCaseNo');if(sel){sel.value=pick.dataset.receiptCase;updateApplicantFromReferral();}return;}const rm=e.target.closest('[data-receipt-remove]');if(rm){draft.splice(Number(rm.dataset.receiptRemove),1);renderDraft();}const edit=e.target.closest('[data-receipt-edit]');if(edit){beginEditReceipt(edit.dataset.receiptEdit);return;}const del=e.target.closest('[data-receipt-delete]');if(del){deleteSavedReceipt(del.dataset.receiptDelete);return;}const rs=e.target.closest('[data-receipt-resubmit]');if(rs){resubmitList(rs.dataset.receiptResubmit);return;}const pr=e.target.closest('[data-receipt-print]');if(pr){const l=lists.find(x=>x.id===pr.dataset.receiptPrint);if(l)printList(l);}}); let receiptCalendarYear=0,receiptCalendarMonth=0; const receiptJMonths=['فروردین','اردیبهشت','خرداد','تیر','مرداد','شهریور','مهر','آبان','آذر','دی','بهمن','اسفند']; function receiptMonthDays(y,m){for(let d=31;d>=29;d--){try{jalaliReceiptToGregorian(String(y)+'/'+String(m).padStart(2,'0')+'/'+String(d).padStart(2,'0'));return d;}catch(e){}}return 29;} function receiptCalendarRender(){ const box=$r('receiptJalaliCalendar');if(!box)return; const first=jalaliReceiptToGregorian(String(receiptCalendarYear)+'/'+String(receiptCalendarMonth).padStart(2,'0')+'/01'); const dt=new Date(first+'T12:00:00'),offset=(dt.getDay()+1)%7,days=receiptMonthDays(receiptCalendarYear,receiptCalendarMonth); const current=normalizeJalali($r('receiptDate').value),now=new Date(),today=gregorianToJalali(now.getFullYear(),now.getMonth()+1,now.getDate()).text; let html='
'+receiptJMonths[receiptCalendarMonth-1]+' '+String(receiptCalendarYear)+'
'+['ش','ی','د','س','چ','پ','ج'].map(x=>''+x+'').join(''); for(let i=0;i'; for(let d=1;d<=days;d++){const val=String(receiptCalendarYear)+'/'+String(receiptCalendarMonth).padStart(2,'0')+'/'+String(d).padStart(2,'0');html+='';} box.innerHTML=html+'
'; } function initJalaliReceiptCalendar(){ const box=$r('receiptJalaliCalendar'),input=$r('receiptDate'),btn=$r('receiptDatePickerBtn');if(!box||!input||!btn)return; const open=()=>{const m=normalizeJalali(input.value).match(/^(\d{4})\/(\d{1,2})\/(\d{1,2})$/);if(m){receiptCalendarYear=+m[1];receiptCalendarMonth=+m[2];}else{const n=new Date(),j=gregorianToJalali(n.getFullYear(),n.getMonth()+1,n.getDate());receiptCalendarYear=j.y;receiptCalendarMonth=j.m;}box.classList.remove('hidden');receiptCalendarRender();}; btn.addEventListener('click',()=>box.classList.contains('hidden')?open():box.classList.add('hidden'));input.addEventListener('focus',open); box.addEventListener('click',e=>{if(e.target.closest('[data-jc-prev]')){receiptCalendarMonth--;if(receiptCalendarMonth<1){receiptCalendarMonth=12;receiptCalendarYear--;}receiptCalendarRender();return;}if(e.target.closest('[data-jc-next]')){receiptCalendarMonth++;if(receiptCalendarMonth>12){receiptCalendarMonth=1;receiptCalendarYear++;}receiptCalendarRender();return;}const day=e.target.closest('[data-jc-day]');if(day){input.value=String(receiptCalendarYear)+'/'+String(receiptCalendarMonth).padStart(2,'0')+'/'+String(+day.dataset.jcDay).padStart(2,'0');box.classList.add('hidden');input.dispatchEvent(new Event('change',{bubbles:true}));}}); document.addEventListener('click',e=>{if(!e.target.closest('#receiptJalaliCalendar')&&!e.target.closest('#receiptDatePickerBtn')&&e.target!==input)box.classList.add('hidden');}); } initJalaliReceiptCalendar(); $r('receiptCaseNo')?.addEventListener('change',updateApplicantFromReferral);$r('receiptCancelEdit')?.addEventListener('click',()=>{clearReceiptForm();say('ویرایش لغو شد.');});$r('receiptAddItem')?.addEventListener('click',addItem);$r('receiptSaveDraft')?.addEventListener('click',()=>saveList(false));$r('receiptSubmitList')?.addEventListener('click',()=>saveList(true));$r('receiptRefreshExpert')?.addEventListener('click',async()=>{await pullExpertCases(true);syncReferralOptions($r('receiptCaseNo')?.value||'');await loadLists();}); const nav=document.getElementById('sectionNav');if(nav&&!nav.querySelector('[data-section-tab="financialReceipts"]')){const b=document.createElement('button');b.type='button';b.textContent='فهرست مالی فیش‌ها';b.setAttribute('data-section-tab','financialReceipts');b.onclick=()=>navigateSection('financialReceipts');nav.appendChild(b);} const oldShow=window.showApp;if(typeof oldShow==='function')window.showApp=function(...args){const r=oldShow.apply(this,args);setTimeout(loadLists,300);return r;}; // به‌روزرسانی خودکار وضعیت تحویل پرونده؛ پس از تأیید دبیر نیازی به خروج و ورود مجدد نیست. if(!window.__arsinDeliveryStatusRefreshTimer){ window.__arsinDeliveryStatusRefreshTimer=setInterval(()=>{ if(document.visibilityState==='visible'&&document.body.classList.contains('expert-authenticated'))loadLists(); },45000); document.addEventListener('visibilitychange',()=>{ if(document.visibilityState==='visible'&&document.body.classList.contains('expert-authenticated'))loadLists(); }); } setTimeout(()=>{syncReferralOptions();if(getUser()&&document.body.classList.contains('expert-authenticated'))loadLists();renderDraft();},800); })();