1import{u as ee,j as s,r as te}from"./vendor-query-BnhkeaN7.js";import{c as K,Q as se,b as T,u as re,S as ae}from"./index--qDVQvnn.js";import{n as oe}from"./notes.repository-C0G-7xiZ.js";import{a as Q}from"./format-D9wN-UhI.js";import{f as q}from"./money-CcWLoV5p.js";import{S as C}from"./index-DoqGDKIP.js";import{P as le}from"./index-BZ7B0cLJ.js";import"./vendor-react-C_-XA8Pp.js";import"./index--miCJeVk.js";const H={total:0,sent:0,error:0,valorCent:"0",daily:[],dailySent:[]};function ne(e,t){return{month:e,year:t,daysInMonth:new Date(t,e,0).getDate(),digitacao:{...H},emissao:{...H,porCnpj:[]},cnpjGeral:{rows:[],truncated:!1,totalCnpjs:0,totalNotas:0,valorCent:"0"}}}function ie(e,t,l){const r=K.c(20);let c;r[0]!==t||r[1]!==e||r[2]!==l?(c=[se.REPORTS,"month",e,l,t],r[0]=t,r[1]=e,r[2]=l,r[3]=c):c=r[3];let a;r[4]!==t||r[5]!==l?(a=()=>oe.monthReport(t,l),r[4]=t,r[5]=l,r[6]=a):a=r[6];const u=e!==void 0&&e!=="";let m;r[7]!==c||r[8]!==a||r[9]!==u?(m={queryKey:c,queryFn:a,enabled:u},r[7]=c,r[8]=a,r[9]=u,r[10]=m):m=r[10];const i=ee(m);let p;r[11]!==t||r[12]!==i.data||r[13]!==l?(p=i.data??ne(t,l),r[11]=t,r[12]=i.data,r[13]=l,r[14]=p):p=r[14];const g=i.error instanceof Error?i.error.message:null;let o;return r[15]!==i.isPending||r[16]!==i.refetch||r[17]!==p||r[18]!==g?(o={report:p,loading:i.isPending,error:g,reload:i.refetch},r[15]=i.isPending,r[16]=i.refetch,r[17]=p,r[18]=g,r[19]=o):o=r[19],o}function V(e,t){const r="\uFEFF"+t.map(m=>m.join(";")).join(` 2`),c=new Blob([r],{type:"text/csv;charset=utf-8;"}),a=URL.createObjectURL(c),u=document.createElement("a");u.href=a,u.download=e,u.click(),URL.revokeObjectURL(a)}const ce=[18,31,22,45,38,12,55,42,29,61,37,18,44,52,28,39,63,47,21,56,34,18,49,41,26,58,33,15,47,38];function z(e){const t=K.c(31),{counts:l,daysInMonth:r,label:c,className:a}=e;let u;t[0]!==l?(u=l.every(me),t[0]=l,t[1]=u):u=t[1];const m=u;let i;t[2]!==l||t[3]!==r||t[4]!==m?(i=m?ce.slice(0,r):l,t[2]=l,t[3]=r,t[4]=m,t[5]=i):i=t[5];const p=i,g=Math.max(...p,1);let o;t[6]===Symbol.for("react.memo_cache_sentinel")?(o=[1,8,15,22,30],t[6]=o):o=t[6];let f;t[7]!==r?(f=o.filter(N=>N<=r),t[7]=r,t[8]=f):f=t[8];const d=f;let n;t[9]!==a?(n=T("bg-bg-surface border border-border-base rounded-xl p-5",a),t[9]=a,t[10]=n):n=t[10];let b;t[11]!==c?(b=s.jsx("p",{className:"text-xs font-semibold text-text-secondary mb-4",children:c}),t[11]=c,t[12]=b):b=t[12];let h;if(t[13]!==p||t[14]!==m||t[15]!==g){let N;t[17]!==m||t[18]!==g?(N=(_,w)=>s.jsx("div",{className:"flex-1 rounded-sm transition-all",style:{height:`${Math.max(_/g*100,m?10:0)}%`,minHeight:_>0||m?4:0,background:m?"var(--color-accent)88":"var(--color-accent)",borderRadius:"2px 2px 0 0"}},w),t[17]=m,t[18]=g,t[19]=N):N=t[19],h=p.map(N),t[13]=p,t[14]=m,t[15]=g,t[16]=h}else h=t[16];let x;t[20]!==h?(x=s.jsx("div",{className:"flex items-end gap-0.5 h-full",children:h}),t[20]=h,t[21]=x):x=t[21];let j;t[22]!==d?(j=s.jsx("div",{className:"flex justify-between mt-2",children:d.map(de)}),t[22]=d,t[23]=j):j=t[23];let v;t[24]!==x||t[25]!==j?(v=s.jsxs("div",{className:"relative h-24",children:[x,j]}),t[24]=x,t[25]=j,t[26]=v):v=t[26];let y;return t[27]!==v||t[28]!==n||t[29]!==b?(y=s.jsxs("div",{className:n,children:[b,v]}),t[27]=v,t[28]=n,t[29]=b,t[30]=y):y=t[30],y}function de(e){return s.jsx("span",{className:"text-3xs text-text-muted",children:String(e).padStart(2,"0")},e)}function me(e){return e===0}const X=["Janeiro","Fevereiro","Março","Abril","Maio","Junho","Julho","Agosto","Setembro","Outubro","Novembro","Dezembro"],xe=[{id:"digitacao",label:"Digitação"},{id:"transmissao",label:"Transmissão"},{id:"emissao",label:"Data de Emissão"},{id:"creditos",label:"Créditos"}],$="text-left text-3xs font-semibold text-text-muted uppercase tracking-wider px-4 py-3 border-b border-border-base",F="px-4 py-3 text-sm text-text-primary border-b border-border-base last:border-0",I="flex-1 sm:flex-none h-11 sm:h-auto bg-bg-elevated border border-border-base rounded-lg text-text-primary text-base sm:text-sm px-2.5 sm:py-1.5 font-sans cursor-pointer outline-none",G="h-11 sm:h-auto sm:py-1.5 rounded-lg text-sm font-sans cursor-pointer transition-transform duration-150 ease-out-strong active:scale-[.97] motion-reduce:active:scale-100";function pe(e){const t=K.c(31),{month:l,year:r,years:c,onMonth:a,onYear:u,onApply:m,onCurrentMonth:i,onExport:p}=e;let g;t[0]===Symbol.for("react.memo_cache_sentinel")?(g=s.jsx("span",{className:"w-full sm:w-auto text-sm text-text-muted",children:"PerÃodo:"}),t[0]=g):g=t[0];let o;t[1]!==a?(o=S=>a(Number(S.target.value)),t[1]=a,t[2]=o):o=t[2];let f;t[3]===Symbol.for("react.memo_cache_sentinel")?(f=X.map(ue),t[3]=f):f=t[3];let d;
2t[4]!==l||t[5]!==o?(d=s.jsx("select",{value:l,onChange:o,className:I,children:f}),t[4]=l,t[5]=o,t[6]=d):d=t[6];let n;t[7]!==u?(n=S=>u(Number(S.target.value)),t[7]=u,t[8]=n):n=t[8];let b;t[9]!==c?(b=c.map(be),t[9]=c,t[10]=b):b=t[10];let h;t[11]!==n||t[12]!==b||t[13]!==r?(h=s.jsx("select",{value:r,onChange:n,className:I,children:b}),t[11]=n,t[12]=b,t[13]=r,t[14]=h):h=t[14];let x;t[15]===Symbol.for("react.memo_cache_sentinel")?(x=T(G,"bg-accent text-white border-none px-4 font-semibold"),t[15]=x):x=t[15];let j;t[16]!==m?(j=s.jsx("button",{type:"button",onClick:m,className:x,children:"Filtrar"}),t[16]=m,t[17]=j):j=t[17];let v;t[18]===Symbol.for("react.memo_cache_sentinel")?(v=T(G,"bg-transparent text-text-secondary border border-border-base px-3 [@media(hover:hover)]:hover:border-border-strong"),t[18]=v):v=t[18];let y;t[19]!==i?(y=s.jsx("button",{type:"button",onClick:i,className:v,children:"Mês atual"}),t[19]=i,t[20]=y):y=t[20];let N;t[21]===Symbol.for("react.memo_cache_sentinel")?(N=s.jsx("div",{className:"hidden sm:block flex-1"}),t[21]=N):N=t[21];let _;t[22]===Symbol.for("react.memo_cache_sentinel")?(_=T(G,"w-full sm:w-auto bg-transparent text-text-secondary border border-border-base px-3.5 [@media(hover:hover)]:hover:border-border-strong flex items-center justify-center gap-1.5"),t[22]=_):_=t[22];let w;t[23]!==p?(w=s.jsx("button",{type:"button",onClick:p,className:_,children:"â Exportar Excel"}),t[23]=p,t[24]=w):w=t[24];let E;return t[25]!==y||t[26]!==w||t[27]!==d||t[28]!==h||t[29]!==j?(E=s.jsxs("div",{className:"flex items-center gap-2 mb-5 flex-wrap",children:[g,d,h,j,y,N,w]}),t[25]=y,t[26]=w,t[27]=d,t[28]=h,t[29]=j,t[30]=E):E=t[30],E}function be(e){return s.jsx("option",{value:e,children:e},e)}function ue(e,t){return s.jsx("option",{value:t+1,children:e},e)}function W(e,t,l){return e===0?"0,00%":`${((t+l)/e*100).toFixed(2).replace(".",",")}%`}function $e(){const e=K.c(59),{profile:t}=re(),l=new Date,[r,c]=te.useState({activeTab:"digitacao",filterMonth:l.getMonth()+1,filterYear:l.getFullYear(),appliedMonth:l.getMonth()+1,appliedYear:l.getFullYear()}),{activeTab:a,filterMonth:u,filterYear:m,appliedMonth:i,appliedYear:p}=r,{report:g,loading:o}=ie(t==null?void 0:t.organization_id,i,p),{daysInMonth:f,digitacao:d,emissao:n,cnpjGeral:b}=g,h=n.porCnpj,x=`${X[i-1]} ${p}`,j=l.getFullYear();let v;e[0]!==j?(v=Array.from({length:j-2022},Ne),e[0]=j,e[1]=v):v=e[1];const y=v;let N;e[2]!==c?(N=function(){c(ve)},e[2]=c,e[3]=N):N=e[3];const _=N,w=function(){const R=l.getMonth()+1,A=l.getFullYear();c(Z=>({...Z,filterMonth:R,filterYear:A,appliedMonth:R,appliedYear:A}))};let E;e[4]!==_||e[5]!==u||e[6]!==m||e[7]!==w||e[8]!==c||e[9]!==y?(E=M=>s.jsx(pe,{month:u,year:m,years:y,onMonth:R=>c(A=>({...A,filterMonth:R})),onYear:R=>c(A=>({...A,filterYear:R})),onApply:_,onCurrentMonth:w,onExport:M}),e[4]=_,e[5]=u,e[6]=m,e[7]=w,e[8]=c,e[9]=y,e[10]=E):E=e[10];const S=E;let O;e[11]===Symbol.for("react.memo_cache_sentinel")?(O=s.jsx(le,{title:"Relatórios"}),e[11]=O):O=e[11];let P;e[12]!==a||e[13]!==c?(P=xe.map(M=>s.jsx("button",{type:"button",onClick:()=>c(R=>({...R,activeTab:M.id})),className:T("px-3 md:px-4 py-2.5 text-sm font-sans border-none bg-transparent cursor-pointer relative outline-none transition-colors -mb-px whitespace-nowrap flex-shrink-0",a===M.id?"font-semibold text-text-primary border-b-2 border-accent":"font-normal text-text-muted hover:text-text-secondary border-b-2 border-transparent"),children:M.label},M.id)),e[12]=a,e[13]=c,e[14]=P):P=e[14];let Y;e[15]!==P?(Y=s.jsx("div",{className:"flex border-b border-border-base mb-6 overflow-x-auto scrollbar-none",children:P}),e[15]=P,e[16]=Y):Y=e[16];let B;e[17]!==o?(B=o&&s.jsx("div",{className:"flex justify-center py-16",children:s.jsx(ae,{})}),e[17]=o,e[18]=B):B=e[18];let L;e[19]!==a||e[20]!==i||e[21]!==p||e[22]!==f||e[23]!==d||e[24]!==o||e[25]!==S||e[26]!==x?(L=!o&&a==="digitacao"&&s.jsxs(s.Fragment,{children:[S(()=>V(`digitacao_${x}.csv`,[["Data","Notas"],...d.daily.map((M,R)=>[`${String(R+1).padStart(2,"0")}/${String(i).padStart(2,"0")}/${p}`,String(M)])])),s.jsxs("div",{className:"grid grid-cols-2 gap-3 mb-5",children:[s.jsx(C,{label:"Notas Digitadas",value:d.total.toLocaleStr
2ing("pt-BR")}),s.jsx(C,{label:"Valor Total",value:q(d.valorCent)})]}),s.jsx(z,{counts:d.daily,daysInMonth:f,label:`Atividade de digitação â ${x}`})]}),e[19]=a,e[20]=i,e[21]=p,e[22]=f,e[23]=d,e[24]=o,e[25]=S,e[26]=x,e[27]=L):L=e[27];let D;e[28]!==a||e[29]!==i||e[30]!==p||e[31]!==f||e[32]!==d||e[33]!==o||e[34]!==S||e[35]!==x?(D=!o&&a==="transmissao"&&s.jsxs(s.Fragment,{children:[S(()=>V(`transmissao_${x}.csv`,[["Data","Transmitidas"],...d.dailySent.map((M,R)=>[`${String(R+1).padStart(2,"0")}/${String(i).padStart(2,"0")}/${p}`,String(M)])])),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-5",children:[s.jsx(C,{label:"Notas Digitadas",value:d.total.toLocaleString("pt-BR")}),s.jsx(C,{label:"Transmitidas",value:d.sent.toLocaleString("pt-BR")}),s.jsx(C,{label:"Com Erro",value:d.error.toLocaleString("pt-BR")}),s.jsx(C,{label:"% Processadas",value:W(d.total,d.sent,d.error)})]}),s.jsx(z,{counts:d.dailySent,daysInMonth:f,label:`Transmissões â ${x}`})]}),e[28]=a,e[29]=i,e[30]=p,e[31]=f,e[32]=d,e[33]=o,e[34]=S,e[35]=x,e[36]=D):D=e[36];let k;e[37]!==a||e[38]!==f||e[39]!==n.daily||e[40]!==n.error||e[41]!==n.sent||e[42]!==n.total||e[43]!==h||e[44]!==o||e[45]!==S||e[46]!==x?(k=!o&&a==="emissao"&&s.jsxs(s.Fragment,{children:[S(()=>V(`emissao_${x}.csv`,[["CNPJ","Notas","Transmitidas"],...h.map(ge)])),s.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-4 gap-3 mb-5",children:[s.jsx(C,{label:"Notas Emitidas",value:n.total.toLocaleString("pt-BR")}),s.jsx(C,{label:"Transmitidas",value:n.sent.toLocaleString("pt-BR")}),s.jsx(C,{label:"Com Erro",value:n.error.toLocaleString("pt-BR")}),s.jsx(C,{label:"% Processadas",value:W(n.total,n.sent,n.error)})]}),s.jsx(z,{counts:n.daily,daysInMonth:f,label:`Emissões por data â ${x}`}),h.length>0?s.jsxs("div",{className:"mt-5 bg-bg-surface border border-border-base rounded-2xl overflow-hidden",children:[s.jsxs("div",{className:"flex justify-between items-center px-4 py-3.5 border-b border-border-base",children:[s.jsx("span",{className:"text-sm font-semibold text-text-primary",children:"Detalhamento por CNPJ"}),s.jsx("span",{className:"text-xs text-text-muted",children:x})]}),s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full border-collapse",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:$,children:"CNPJ"}),s.jsx("th",{className:$,children:"Notas"}),s.jsx("th",{className:$,children:"Transmitidas"})]})}),s.jsx("tbody",{children:h.map(je)})]})})]}):null]}),e[37]=a,e[38]=f,e[39]=n.daily,e[40]=n.error,e[41]=n.sent,e[42]=n.total,e[43]=h,e[44]=o,e[45]=S,e[46]=x,e[47]=k):k=e[47];let J;e[48]!==a||e[49]!==b||e[50]!==o?(J=!o&&a==="creditos"&&s.jsxs(s.Fragment,{children:[s.jsxs("div",{className:"grid grid-cols-3 gap-3 mb-5",children:[s.jsx(C,{label:"Total CNPJs",value:b.totalCnpjs.toLocaleString("pt-BR")}),s.jsx(C,{label:"Notas",value:b.totalNotas.toLocaleString("pt-BR")}),s.jsx(C,{label:"Valor Total NF",value:q(b.valorCent)})]}),s.jsxs("div",{className:"bg-bg-surface border border-border-base rounded-2xl overflow-hidden",children:[s.jsxs("div",{className:"flex justify-between items-center px-4 py-3.5 border-b border-border-base",children:[s.jsx("span",{className:"text-sm font-semibold text-text-primary",children:"Visão por CNPJ"}),s.jsx("button",{type:"button",onClick:()=>V("creditos_cnpj.csv",[["CNPJ","Notas","Total NF"],...b.rows.map(he)]),className:"bg-status-green text-white border-none rounded-lg px-3.5 py-1.5 text-xs font-semibold cursor-pointer font-sans",children:"Exportar Excel"})]}),b.rows.length===0?s.jsx("p",{className:"text-center text-sm text-text-muted py-8",children:"Nenhuma nota encontrada"}):s.jsx("div",{className:"overflow-x-auto",children:s.jsxs("table",{className:"w-full border-collapse",children:[s.jsx("thead",{children:s.jsxs("tr",{children:[s.jsx("th",{className:$,children:"CNPJ"}),s.jsx("th",{className:$,children:"Notas"}),s.jsx("th",{className:$,children:"Transmitidas"}),s.jsx("th",{className:$,children:"Total NF"})]})}),s.jsx("tbody",{children:b.rows.map(fe)})]})}),b.truncated&&s.jsx("p",{className:"px-4 py-3 text-xs text-text-muted border-t border-border-base",children:"Mostrando os 1.000 CNPJs com mais notas. Os totais acima consideram todos."})]})]}),e[48]=a,e[49]=b,e[50]=o,e[51]=J):J=e[51];let U;return e[52]!==J||e[53]!==Y||e[54]!==B||e[55]!==L||e[56]!==D||e[57]!==k?(U=s.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden bg-bg-base",children:[O,s.jsx("div",{className:"flex-1 overflow-auto p-4 md:p-10",children:s.jsxs("div",{className:"max-w-7xl mx-auto",children:[Y,B,L,D,k,J]})})]}),e[52]=J,e[53]=Y,e[54]=B,e[55]=L,e[56]=D,e[57]=k,e[58]=U):U=e[58],U}function fe(e){return s.jsxs("tr",{children:[s.jsx("td",{className:T(F,"font-mono text-xs text-accent"),children:Q(e.cnpj)}),s.jsx("td",{className:F,children:e.notas}),s.jsx("td",{className:F,children:e.sent}),s.jsx("td",{className:T(F,"text-status-green"),children:q(e.valorCent)})]},e.cnpj)}function he(e){return[Q(e.cnpj),String(e.notas),q(e.valorCent)]}function je(e){return s.jsxs("tr",{children:[s.jsx("td",{className:T(F,"font-mono text-xs text-accent"),children:Q(e.cnpj)}),s.jsx("td",{className:F,children:e.notas}),s.jsx("td",{className:F,children:e.sent})]},e.cnpj)}function ge(e){return[Q(e.cnpj),String(e.notas),String(e.sent)]}
2function ve(e){return{...e,appliedMonth:e.filterMonth,appliedYear:e.filterYear}}function Ne(e,t){return 2023+t}export{$e as ReportsPage};
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.