PageSourceSearch

https://democrata.org.br/sistema/assets/RelatoriosPage-DP4kO7Xb.js

js democrata.org.br collected 2026-10-09 16:58:01 UTC 12,276 bytes, 1 lines download raw bytes

1import{j as e,O as z,m as E,K as L,r as l,o as y,A as P,B as F,T as A,X as q}from"./index-DEXqc8fB.js";import{m as S,A as $,a as B}from"./AvisoFalha-LbRQ-MD5.js";import{B as D}from"./bar-chart-3-CWDaX9Fi.js";import{S as U}from"./scale-CovXOVmC.js";import{D as O}from"./download-D_7tyqTo.js";import{F as T}from"./file-spreadsheet-DdZ3W-np.js";import"./triangle-alert-CEfUEOmw.js";const I=[{id:"dre",nome:"DRE — Demonstração do Resultado",descricao:"Receitas, despesas e resultado do exercício",icone:D,cor:"from-blue-500 to-blue-600",exportavel:!0},{id:"fluxo-caixa",nome:"Fluxo de Caixa",descricao:"Entradas e saídas mês a mês, com saldo acumulado",icone:A,cor:"from-emerald-500 to-emerald-600",exportavel:!0},{id:"balanco",nome:"Balanço Patrimonial",descricao:"Ativo, passivo e patrimônio líquido numa data",icone:U,cor:"from-violet-500 to-violet-600",exportavel:!1}],C=()=>({Authorization:`Bearer ${localStorage.getItem("token")}`}),c=t=>new Intl.NumberFormat("pt-BR",{style:"currency",currency:"BRL"}).format(Number(t||0));function V({def:t,prestador:a,ano:r,onClose:x}){const[d,o]=l.useState(!1),[p,w]=l.useState(!1),[v,i]=l.useState(null),[b,j]=l.useState(null),[h,n]=l.useState(`${r}-12-31`),m=()=>{const s=new URLSearchParams({prestador_id:String(a.id)});return t.id==="balanco"?s.set("data_referencia",h):s.set("ano",String(r)),`/api/v1/financeiro/relatorios/${t.id}?${s}`},u=l.useCallback(async()=>{o(!0),i(null),j(null);try{const s=await fetch(m(),{headers:C()});if(!s.ok){i(await S(s,`o relatório ${t.nome}`));return}j(await s.json())}catch(s){i(`Não consegui falar com o servidor: ${s.message}`)}finally{o(!1)}},[t.id,a.id,r,h]);l.useEffect(()=>{u()},[u]);const g=async()=>{w(!0),i(null);try{const s=await fetch(`/api/v1/financeiro/relatorios/${t.id}/export?prestador_id=${a.id}&ano=${r}&formato=csv`,{headers:C()});if(!s.ok){i(await S(s,`a exportação do relatório ${t.nome}`));return}const f=await s.blob();if(f.size===0){i("O servidor respondeu com sucesso mas o arquivo veio vazio (0 bytes). Não baixei nada.");return}const R=(s.headers.get("Content-Disposition")||"").match(/filename="?([^";]+)"?/),_=window.URL.createObjectURL(f),N=document.createElement("a");N.href=_,N.download=R?R[1]:`${t.id}_${a.cnpj.replace(/\D/g,"")}_${r}.csv`,document.body.appendChild(N),N.click(),N.remove(),window.URL.revokeObjectURL(_)}catch(s){i(`Não consegui falar com o servidor: ${s.message}`)}finally{w(!1)}},k=t.icone;return e.jsx("div",{className:"fixed inset-0 bg-black/50 flex items-center justify-center z-50 p-4",children:e.jsxs("div",{className:"bg-white dark:bg-slate-800 rounded-2xl w-full max-w-2xl shadow-2xl max-h-[90vh] flex flex-col",children:[e.jsxs("div",{className:"p-6 border-b border-slate-200 dark:border-slate-700 flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:`w-12 h-12 bg-gradient-to-br ${t.cor} rounded-xl flex items-center justify-center`,children:e.jsx(k,{size:24,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-slate-800 dark:text-white",children:t.nome}),e.jsxs("p",{className:"text-slate-500 dark:text-slate-400 text-sm",children:[a.nome," • ",r]})]})]}),e.jsx("button",{onClick:x,className:"p-2 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-700 text-slate-500",children:e.jsx(q,{size:20})})]}),e.jsxs("div",{className:"p-6 space-y-4 overflow-y-auto",children:[t.id==="balanco"&&e.jsxs("div",{children:[e.jsx("label",{className:"block text-sm font-medium text-slate-700 dark:text-slate-300 mb-2",children:"Data de referência"}),e.jsx("input",{type:"date",value:h,onChange:s=>n(s.target.value),className:"w-full px-4 py-3 border border-slate-200 dark:border-slate-600 rounded-xl bg-white dark:bg-slate-700 text-slate-800 dark:text-white"})]}),d&&e.jsx("div",{className:"flex items-center justify-center py-10",children:e.jsx(y,{className:"h-8 w-8 animate-spin text-violet-500"})}),v&&e.jsx($,{motivo:v,onTentarDeNovo:u}),b&&!d&&e.jsxs(e.Fragment,{children:[e.jsx(H,{id:t.id,dados:b}),e.jsxs("details",{className:"rounded-xl border border-slate-200 dark:border-slate-700",children:[e.jsx("summary",{className:"cursor-pointer px-4 py-3 text-sm font-medium text-slate-600 dar
1k:text-slate-300",children:"Ver os dados como o servidor devolveu"}),e.jsx("pre",{className:"px-4 pb-4 text-xs overflow-x-auto text-slate-600 dark:text-slate-400",children:JSON.stringify(b,null,2)})]})]})]}),e.jsxs("div",{className:"flex items-center justify-between gap-3 p-6 border-t border-slate-200 dark:border-slate-700",children:[e.jsx("p",{className:"text-xs text-slate-500 dark:text-slate-400",children:t.exportavel?"Exportação disponível apenas em CSV — o servidor recusa PDF e Excel.":"Este relatório ainda não tem rota de exportação no servidor."}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("button",{onClick:x,className:"px-5 py-2.5 text-slate-600 dark:text-slate-300 font-medium hover:bg-slate-100 dark:hover:bg-slate-700 rounded-xl",children:"Fechar"}),t.exportavel&&e.jsxs("button",{onClick:g,disabled:p||!!v,className:"px-5 py-2.5 bg-gradient-to-r from-emerald-500 to-emerald-600 text-white font-medium rounded-xl hover:shadow-lg flex items-center gap-2 disabled:opacity-50",children:[p?e.jsx(y,{size:18,className:"animate-spin"}):e.jsx(T,{size:18}),"Baixar CSV"]})]})]})]})})}function H({id:t,dados:a}){const r=({rot:d,val:o})=>e.jsxs("div",{className:"flex items-center justify-between py-2 border-b border-slate-100 dark:border-slate-700 last:border-0",children:[e.jsx("span",{className:"text-slate-600 dark:text-slate-400",children:d}),e.jsx("span",{className:"font-semibold text-slate-800 dark:text-white",children:o})]});if(t==="dre")return e.jsxs("div",{className:"rounded-xl border border-slate-200 dark:border-slate-700 p-4",children:[e.jsx(r,{rot:"Período",val:String(a.periodo??"-")}),e.jsx(r,{rot:"Receita bruta",val:c(a.receita_bruta)}),e.jsx(r,{rot:"Despesa total",val:c(a.despesa_total)}),e.jsx(r,{rot:"Resultado do período",val:c(a.resultado_periodo)}),Number(a.receita_bruta||0)===0&&Number(a.despesa_total||0)===0&&e.jsxs("p",{className:"text-xs text-amber-700 dark:text-amber-400 mt-3",children:['⚠ Zerada não quer dizer "não houve movimento". A DRE soma as receitas e despesas das prestações do ano ',e.jsx("strong",{children:"agrupando por categoria do TSE"}),"(dre_service.py:66-117): lançamento gravado com categoria fora dessa lista não entra em grupo nenhum e não aparece aqui, mesmo estando no banco. Se o mês teve movimento e isto está zerado, verifique a categoria dos lançamentos."]})]});if(t==="fluxo-caixa"){const d=a.periodos||[];return e.jsx("div",{className:"rounded-xl border border-slate-200 dark:border-slate-700 overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-slate-50 dark:bg-slate-900/40",children:e.jsx("tr",{children:["Período","Entradas","Saídas","Saldo final"].map(o=>e.jsx("th",{className:"px-3 py-2 text-left text-xs font-medium text-slate-500",children:o},o))})}),e.jsx("tbody",{className:"divide-y divide-slate-100 dark:divide-slate-700",children:d.map((o,p)=>e.jsxs("tr",{children:[e.jsx("td",{className:"px-3 py-2 text-slate-700 dark:text-slate-300",children:String(o.periodo)}),e.jsx("td",{className:"px-3 py-2 text-emerald-600",children:c(o.total_entradas)}),e.jsx("td",{className:"px-3 py-2 text-rose-600",children:c(o.total_saidas)}),e.jsx("td",{className:"px-3 py-2 font-medium text-slate-800 dark:text-white",children:c(o.saldo_final)})]},p))})]})})}const x=d=>a[d]||{};return e.jsxs("div",{className:"rounded-xl border border-slate-200 dark:border-slate-700 p-4",children:[e.jsx(r,{rot:"Data de referência",val:String(a.data_referencia??"-")}),e.jsx(r,{rot:"Ativo circulante",val:c(x("ativo_circulante").total)}),e.jsx(r,{rot:"Ativo não circulante",val:c(x("ativo_nao_circulante").total)}),e.jsx(r,{rot:"Passivo circulante",val:c(x("passivo_circulante").total)}),e.jsx(r,{rot:"Patrimônio líquido",val:c(x("patrimonio_liquido").total)})]})}function J(){const t=E(),{orgao:a,periodo:r,isLoading:x}=L(),[d,o]=l.useState(null),[p,w]=l.useState(null),[v,i]=l.useState(null),[b,j]=l.useState(!0),h=l.useCallback(async()=>{var n;if(a){j(!0),i(null);try{const m=new URLSearchParams({ativo:"true",size:"100"});a.tipo&&m.set("nivel",a.tipo.toLowerCase()),a.sigla_uf&&m.set("uf",a.sigla_uf);const u=await fetch(`/api/v1/financeiro/prestadores?${m}`,{headers:C()});if(!u.ok){i(await S(u,"o cadastro de prestador deste órgão"));return}const g=((n=await u.json())==null?void 0:n.items)||[],k=(a.cnpj||"").replace(/\D/g,""),s=k&&g.find(f=>(f.cnpj||"").replace(/\D/g,"")===k)||g.find(f=>(f.municipio||"").toUpperCase()===(a.municipio||"").toUpperCase()&&(f.uf||"")===(a.sigla_uf||""))||g[0]||null;w(s),s||i(`Nenhum prestador de contas cadastrado para ${a.nome}. Todos os relatórios são por prestador — sem ele não há o que calcular.`)}catch(m){i(`Não consegui falar com o servidor: ${m.message}`)}finally{j(!1)}}},[a]);return l.useEffect(()=>{h()}
1,[h]),x||b?e.jsx("div",{className:"flex items-center justify-center h-96",children:e.jsx(y,{className:"h-8 w-8 animate-spin text-violet-500"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("button",{onClick:()=>t("/financeiro/hub"),className:"p-2 rounded-lg hover:bg-slate-100 dark:hover:bg-slate-800",children:e.jsx(P,{className:"h-5 w-5 text-slate-600 dark:text-slate-400"})}),e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-slate-900 dark:text-white flex items-center gap-3","data-tour":"relatorios-titulo",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-violet-500 to-violet-600 rounded-xl flex items-center justify-center",children:e.jsx(D,{size:20,className:"text-white"})}),"Relatórios"]}),e.jsxs("p",{className:"text-slate-500 dark:text-slate-400",children:["Consulte e baixe os relatórios financeiros do exercício ",r.ano]})]})]}),a&&e.jsxs("div",{className:"flex items-center gap-3 px-4 py-2 bg-slate-100 dark:bg-slate-800 rounded-xl",children:[e.jsx("div",{className:"w-10 h-10 bg-gradient-to-br from-blue-500 to-blue-600 rounded-xl flex items-center justify-center",children:e.jsx(F,{size:20,className:"text-white"})}),e.jsxs("div",{children:[e.jsx("p",{className:"font-semibold text-slate-800 dark:text-white text-sm",children:a.nome}),e.jsxs("p",{className:"text-slate-500 dark:text-slate-400 text-xs",children:[r.ano," • Anual"]})]})]})]}),v&&e.jsx($,{motivo:v,onTentarDeNovo:h}),e.jsx(B,{titulo:"Formatos disponíveis: CSV",motivo:'PDF e Excel aparecem no enum do servidor, mas as rotas de exportação recusam os dois com "Formato nao suportado ainda". Por isso não são oferecidos aqui — oferecer e falhar depois seria pior do que não oferecer.'}),e.jsx("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:I.map(n=>{const m=n.icone,u=!!p;return e.jsx("button",{disabled:!u,onClick:()=>o(n),className:"bg-white dark:bg-slate-800 rounded-xl border border-slate-200 dark:border-slate-700 p-5 text-left hover:shadow-lg hover:-translate-y-0.5 transition-all group disabled:opacity-50 disabled:hover:translate-y-0 disabled:hover:shadow-none disabled:cursor-not-allowed",children:e.jsxs("div",{className:"flex items-start gap-4",children:[e.jsx("div",{className:`w-12 h-12 bg-gradient-to-br ${n.cor} rounded-xl flex items-center justify-center group-hover:scale-110 transition-transform`,children:e.jsx(m,{size:24,className:"text-white"})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("h3",{className:"font-semibold text-slate-800 dark:text-white mb-1",children:n.nome}),e.jsx("p",{className:"text-slate-500 dark:text-slate-400 text-sm",children:n.descricao}),e.jsxs("p",{className:"text-xs text-slate-400 dark:text-slate-500 mt-2 flex items-center gap-1",children:[e.jsx(O,{size:12}),n.exportavel?"Visualizar e baixar CSV":"Somente visualização"]})]})]})},n.id)})}),d&&p&&e.jsx(V,{def:d,prestador:p,ano:r.ano,onClose:()=>o(null)})]})}function ee(){return e.jsx(z,{children:e.jsx("div",{className:"p-6",children:e.jsx(J,{})})})}export{ee as default};

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.