(function(){ if(window.__v2in)return;window.__v2in=1; var css=document.createElement('style'); css.textContent='.rinrow .rtin{padding-right:44px!important;min-width:0}' +'.stC{position:relative;flex:0 0 96px;display:flex;align-items:center;justify-content:center;gap:6px;border-radius:10px;border:1px solid var(--line);background:transparent;color:var(--txt);font-size:12px;font-weight:700;white-space:nowrap;overflow:hidden}' +'.stC .dot{width:9px;height:9px;border-radius:50%;flex:none}' +'.stC #rInSt{position:absolute;left:0;top:0;width:100%;height:100%;opacity:0;cursor:pointer;font-size:16px;z-index:2;padding:0;border:0}' +'.rplus{position:absolute;right:111px;top:50%;transform:translateY(-50%);width:30px;height:30px;border-radius:50%;border:0;padding:0;display:flex;align-items:center;justify-content:center;font-size:20px;line-height:1;font-weight:700;background:rgba(255,255,255,.12);color:#9aa4b0;cursor:pointer;z-index:1}' +'.rplus.on{background:#e0a458;color:#1b1020}'; document.head.appendChild(css); var M={done:['Xong','#8fd3b4'],doing:['Đang xử lý','#8fb6e6'],todo:['Chưa xong','#e0a458']}; var cur=null; function init(){ var sel=document.getElementById('rInSt'),inp=document.getElementById('rtin'); if(!sel||!inp)return; if(sel.parentNode.classList.contains('stC'))return; var row=sel.parentNode; var w=document.createElement('div');w.className='stC'; var dot=document.createElement('span');dot.className='dot'; var tx=document.createElement('span'); row.insertBefore(w,sel);w.appendChild(dot);w.appendChild(tx);w.appendChild(sel); var b=document.createElement('button');b.type='button';b.className='rplus'; b.setAttribute('aria-label','Thêm việc');b.textContent='+';row.appendChild(b); b.addEventListener('mousedown',function(e){e.preventDefault();}); b.addEventListener('click',function(){ if(!inp.value.trim()){inp.focus();return;} inp.dispatchEvent(new KeyboardEvent('keydown',{key:'Enter',keyCode:13,bubbles:true,cancelable:true})); setTimeout(cur,60); }); cur=function(){var m=M[sel.value]||M.done;for(var i=0;i=0.8;} function cluster(recs){ var list=(recs||[]).slice().sort(function(a,b){var x=a.date||'',y=b.date||'';return xy?1:0);}); var cl=[]; list.forEach(function(rec){(rec.items||[]).forEach(function(it){ if(!it||!it.t)return; var t=norm(it.t);if(!t||t.charAt(0)==='@')return; if(String(it.g||'').toLowerCase().indexOf('kế hoạch')>=0)return; var st=stOf(t,it),k=t.toLowerCase(),c=null; for(var i=0;i=g.f&&r.date<=g.t;}); return []; } function clean(html){ var d=document.createElement('div');d.innerHTML=html; var cont=[],news=[],mode=''; Array.prototype.slice.call(d.children).forEach(function(n){ if(n.tagName!=='LI')return; if(n.classList.contains('psh')){mode=/MỚI/i.test(n.textContent)?'n':'c';return;} var b=n.querySelector('span[contenteditable="false"]'); if(b){if(/^\d+%$/.test(b.textContent.trim()))return;b.parentNode.removeChild(b);} (mode==='n'?news:cont).push(n.outerHTML); }); var out=news.concat(cont).join(''); return out||'
  • '; } function install(){ var f=window.ndsPlanHTML; if(typeof f!=='function'||f.__v2in)return; var orig=f; var w=function(g,base){ var g2={},m={}; try{ for(var k in g)g2[k]=g[k]; cluster(recsOfWeek(g)).forEach(function(c){for(var k2 in c.keys)m[k2]=c.st;}); g2.stMap=m; }catch(e){return orig(g,base);} var html=orig(g2,base); try{return clean(html);}catch(e2){return html;} }; w.__v2in=1;window.ndsPlanHTML=w; } window.ndsMonthPlan=function(g){ var recs=(g&&g.recs&&g.recs.length)?g.recs:[]; if(!recs.length&&typeof allDaily!=='undefined'&&typeof mRange==='function'){ var r=mRange();if(r&&r.mset)recs=allDaily.filter(function(x){return r.mset[(x.date||'').slice(0,7)];}); } var cut=(window.__v2cut?window.__v2cut(recs,g):''),out=[],PCT=/\(\s*đang xử lý\s*\d+%\s*\)\s*$/i; function add(x){var t=norm(x);if(!t)return;for(var i=0;i=0&&(rec.date||'')>=cut)add(t); });}); cluster(recs).forEach(function(c){if(c.st!=='done')add(c.t);}); return out; }; setInterval(install,300);install(); })(); (function(){ if(window.__v2in4)return;window.__v2in4=1; function stamp(){ var ifr=document.getElementById('reportFrame');var doc=ifr&&ifr.contentDocument; if(!doc||typeof curReportKind==='undefined'||curReportKind!=='weekly')return; var sm={};try{var g=wGather();sm=(g&&g.stMap)||{};}catch(e){} doc.querySelectorAll('.pad li').forEach(function(li){ if(li.hasAttribute('data-wst'))return; if(li.closest&&li.closest('.plan'))return; var sp=li.querySelector('.itx');if(!sp)return; var t=sp.textContent.trim();if(!t)return; var b=li.querySelector('.stx');var st=b&&b.getAttribute('data-st'); if(!st){var k1=t.toLowerCase(),k2=k1.replace(/\s+/g,' ');st=sm[k1]||sm[k2];} if(!st){var m=/\((đang xử lý|chưa xong)\)\s*$/i.exec(t);if(m)st=/đang/i.test(m[1])?'doing':'todo';} if(!st)st=(typeof mIsDone==='function'&&mIsDone(t))?'done':'doing'; li.setAttribute('data-wst',st); }); } function wrap(){ if(typeof window.doRptSave!=='function'||window.doRptSave.__v2in4)return; var o=window.doRptSave; var w=async function(){try{stamp();}catch(e){}return o.apply(this,arguments);}; w.__v2in4=1;window.doRptSave=w; } setInterval(wrap,400);wrap(); })(); (function(){ if(window.__v2in6)return;window.__v2in6=1; function wrapM(){ if(typeof window.mGather==='function'&&!window.mGather.__v2in6){ var o=window.mGather; var w=function(){ var saved=null; try{if(typeof allDaily!=='undefined'&&Array.isArray(allDaily)){saved=allDaily;allDaily=saved.slice().sort(function(a,b){var x=a.date||'',y=b.date||'';return xy?-1:0);});}}catch(e){saved=null;} try{return o.apply(this,arguments);}finally{if(saved){try{allDaily=saved;}catch(e2){}}} }; w.__v2in6=1;window.mGather=w; } if(typeof window.buildMonthReportHTML==='function'&&!window.buildMonthReportHTML.__v2in6){ var ob=window.buildMonthReportHTML; var wb=function(){ var h=ob.apply(this,arguments); try{if(typeof h==='string'&&h.indexOf('id="v2nostx"')<0)h=h.replace('','');}catch(e){} return h; }; wb.__v2in6=1;window.buildMonthReportHTML=wb; } } setInterval(wrapM,400);wrapM(); })(); (function(){ if(window.__v2in8)return;window.__v2in8=1; window.__v2cut=function(recs,g){ var mx=''; (recs||[]).forEach(function(r){var d=String(r&&r.date||'').slice(0,10);if(d>mx)mx=d;}); var to=(g&&g.r&&g.r.to)?String(g.r.to).slice(0,10):''; if(to&&mx&&to"]/g,function(c){return {'&':'&','<':'<','>':'>','"':'"'}[c];});} var BT=''; function isM(){try{return typeof curReportKind!=='undefined'&&curReportKind==='monthly';}catch(e){return false;}} function lines(){ var g=null;try{g=mGather();}catch(e){} var recs=(g&&g.recs)?g.recs.slice():[]; recs.sort(function(a,b){var x=a.date||'',y=b.date||'';return xy?1:0);}); var out=[],idx=Object.create(null); recs.forEach(function(r){(r.items||[]).forEach(function(it){ if(!it||typeof it.t!=='string')return; var gr=String(it.g||'').toLowerCase(); if(gr.indexOf('kế hoạch')>=0||gr.indexOf('tuyển')>=0||gr.indexOf('mua sắm')>=0)return; var t=it.t.trim();var m=/^@SG@[^|]*\|([\s\S]*)$/.exec(t); if(m)t=m[1].trim();else if(t.charAt(0)==='@')return; if(!t)return; var k=t.toLowerCase(),st=it.st||'done'; if(k in idx){out[idx[k]].st=st;return;} idx[k]=out.length;out.push({t:t,st:st}); });}); return out.slice(0,300); } function modal(html){var ov=document.createElement('div');ov.className='v2aiov';ov.style.cssText='position:fixed;left:0;top:0;right:0;bottom:0;z-index:2147483000;background:rgba(10,14,20,.6);display:flex;align-items:center;justify-content:center;padding:16px';ov.innerHTML='
    '+html+'
    ';document.body.appendChild(ov);return ov;} function liH(it){ var x=it.t,i=x.indexOf(':'),body=(i>0&&i<70)?''+E(x.slice(0,i))+':'+E(x.slice(i+1)):E(x); return '
  • '+body+''+BT+'
  • '; } function secTitle(s){var t=s.querySelector('.sechd .t');return t?t.textContent.replace(/\s+/g,' ').trim():'';} function getTitles(){ var ifr=document.getElementById('reportFrame');var doc=ifr&&ifr.contentDocument;if(!doc)return []; var pad=doc.querySelector('.pad');if(!pad)return []; var out=[]; Array.prototype.forEach.call(pad.querySelectorAll('.sec'),function(s){if(s.querySelector(':scope > ul.items')){var t=secTitle(s);if(t)out.push(t);}}); return out; } function apply(sections){ var ifr=document.getElementById('reportFrame');var doc=ifr&&ifr.contentDocument;if(!doc)return false; var pad=doc.querySelector('.pad');if(!pad)return false; var olds=Array.prototype.filter.call(pad.querySelectorAll('.sec'),function(s){return !!s.querySelector(':scope > ul.items');}); var map={};olds.forEach(function(s){map[secTitle(s).toUpperCase()]=s;}); if(!sections.length)return false; for(var i=0;i ul.items'); ul.innerHTML=s.items.map(liH).join(''); }); return true; } function btnSet(busy){var b=document.getElementById('rptAiM');if(!b)return;b.disabled=!!busy;b.textContent=busy?'⏳ Đang gộp…':'✨ Gộp bằng AI';b.style.opacity=busy?'.7':'';} async function doRun(L){ btnSet(true); try{if(typeof doRptSave==='function')await doRptSave(true);}catch(e){} var dept='';try{dept=rGetS('nds_daily_dept','');}catch(e){} var r=null; try{r=await apiPost('aiMonthly',{lines:L,dept:dept,period:(typeof curKey!=='undefined'?curKey:''),titles:getTitles()});}catch(e){} btnSet(false);var d=r&&r.data; if(!r||r.status!==200||!d||!d.ok){ var m={limit:'Đã dùng hết 5 lượt gộp AI hôm nay, thử lại ngày mai.',nokey:'Máy chủ chưa có khóa API.',empty:'Không có dòng nào để gộp.',parse:'AI trả kết quả không hợp lệ, bấm gộp lại thử.',api:'Không gọi được AI'+(d&&d.msg?(': '+d.msg):'')+'.'}; if(typeof toast==='function')toast((d&&m[d.error])||'Gộp không thành công, thử lại.');return; } var ok=apply(d.sections||[]);var n=0;(d.sections||[]).forEach(function(s){n+=s.items.length;}); if(typeof toast==='function')toast(ok?('✨ Đã gộp '+d.n+' dòng thành '+n+' mục'+(d.cached?' (dùng lại kết quả trước, không tốn phí)':'')+(d.miss?(' · '+d.miss+' dòng AI bỏ sót đã đưa vào mục Khác'):'')):'Không áp được vào báo cáo, báo cáo giữ nguyên'); } function ask(){ if(document.querySelector('.v2aiov'))return; var b=document.getElementById('rptAiM');if(b&&b.disabled)return; var L=lines(); if(!L.length){if(typeof toast==='function')toast('Tháng này chưa có dòng công việc nào để gộp');return;} var ov=modal('
    ✨ Gộp báo cáo tháng bằng AI
    AI sẽ đọc '+L.length+' dòng công việc trong tháng, gom việc cùng chủ đề và viết gọn lại. Bảng Mua sắm, KPI, Đánh giá, Kế hoạch tháng tới và bốn ô số giữ nguyên. Bản đang mở được lưu vào Lịch sử trước, có thể quay lại.
    '); ov.querySelector('.aiNo').onclick=function(){ov.remove();}; ov.querySelector('.aiGo').onclick=function(){ov.remove();doRun(L);}; } function ensureBtn(){ var ref=document.getElementById('rptAi');if(!ref)return null; var b=document.getElementById('rptAiM'); if(!b){b=document.createElement('button');b.id='rptAiM';b.type='button';b.style.cssText=ref.style.cssText;b.style.display='none';b.textContent='✨ Gộp bằng AI';ref.parentNode.insertBefore(b,ref.nextSibling);} return b; } document.addEventListener('click',function(e){var b=e.target.closest&&e.target.closest('#rptAiM');if(b){e.preventDefault();ask();}}); setInterval(function(){try{var b=ensureBtn();if(b)b.style.display=(isM()&&(window.myDeptType||'')==='cnan')?'':'none';}catch(e){}},800); function guard(ifr){ try{ var doc=ifr&&ifr.contentDocument;if(!doc||!isM()||doc.__v2tg)return;doc.__v2tg=1; setTimeout(function(){try{ var els=[],saved=[]; ['.tile-rate','.tile-total','.tile-done','.tile-doing'].forEach(function(s){var e=doc.querySelector(s);if(e){els.push(e);saved.push(e.textContent);}}); if(!els.length)return; var MO=(ifr.contentWindow&&ifr.contentWindow.MutationObserver)||window.MutationObserver; var mo=new MO(function(){els.forEach(function(e,i){var t=e.textContent;if(t===saved[i])return;var ae=doc.activeElement;if(ae&&(ae===e||e.contains(ae))){saved[i]=t;return;}e.textContent=saved[i];});}); els.forEach(function(e){mo.observe(e,{childList:true,characterData:true,subtree:true});}); }catch(e){}},900); }catch(e){} } function wrapW(){ if(typeof window.wireReportEdit==='function'&&!window.wireReportEdit.__v2in9){ var o=window.wireReportEdit; var w=function(ifr){var r=o.apply(this,arguments);try{guard(ifr);}catch(e){}return r;}; w.__v2in9=1;window.wireReportEdit=w; } } setInterval(wrapW,400);wrapW(); })();