1import{c as de,s as v,j as e,i as Se,C as T,p as D,q as R,v as q,T as Fe,B as h,ag as z,J as f,r as u,D as me,b as ue,d as xe,e as he,I as F,h as Pe,E as U,ah as Y}from"./index-CfdXivVs.js";import{N as ke}from"./Navbar-DJd-olRK.js";import{T as Te,a as De,b as Q,c as X}from"./tabs-B5K18ST2.js";import{u as P,a as $}from"./useMutation-CSjqLTrV.js";import{R as Re,B as qe,C as Be,X as _e,Y as Ae,T as Ee,L as Le,a as le}from"./BarChart-DKlQz8ly.js";import{C as Me}from"./circle-check-DCyHoRWa.js";import{D as oe,u as Ve}from"./use-mobile-B7pqqwCG.js";import{T as je,a as pe,b as G,c as C,d as ge,e as S}from"./table-CEqqqkBM.js";import{C as ye}from"./circle-plus-BfDOGp-J.js";import{P as ve}from"./pencil-CHqPU-Wa.js";import{F as W}from"./file-text-fw9KdRX8.js";import{T as be}from"./trash-2-ER_MKI9w.js";import{L as p}from"./label-lh0Niq16.js";import{S as B,a as _,b as A,c as E,d as o}from"./select-Bb0qWRAF.js";import{P as Z,a as ee,b as se}from"./popover-ykKVr20G.js";import{C as ae}from"./calendar-D101yd5p.js";import{T as fe}from"./textarea-Dk3X051t.js";import{S as Ke}from"./scroll-area-CgAwdVYe.js";import{S as re}from"./search-Dm8xml02.js";import{L as Ie}from"./loader-circle-gfk7pxYo.js";import{S as te}from"./save-brDoiVHB.js";import{C as ne}from"./calendar-KSZPYXRa.js";import{P as Ne}from"./plus-DeNM4Xf2.js";import{C as ie}from"./circle-x-CDCThK0v.js";import{f as K}from"./format-DzEUF7Jh.js";import{p as O}from"./pt-BR-Dj8HXaNw.js";import{F as Oe}from"./file-spreadsheet-1GnPxdPm.js";import"./Logo--bJ5W1ac.js";import"./clipboard-list-lneZM8-5.js";import"./ruler-k4dJLOEO.js";import"./wrench-DGQNQQGE.js";import"./log-out-D-NLOZ1T.js";import"./index-DrLB6t2p.js";import"./index-vmCBgrg4.js";import"./tiny-invariant-BaFNuDhB.js";import"./index-CqqJlhHa.js";import"./chevron-left-DScKS346.js";import"./chevron-right-C20RnG2b.js";/** 2 * @license lucide-react v0.462.0 - ISC 3 * 4 * This source code is licensed under the ISC license. 5 * See the LICENSE file in the root directory of this source tree. 6 */const ze=de("CircleArrowDown",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 8v8",key:"napkw2"}],["path",{d:"m8 12 4 4 4-4",key:"k98ssh"}]]);/** 7 * @license lucide-react v0.462.0 - ISC 8 * 9 * This source code is licensed under the ISC license. 10 * See the LICENSE file in the root directory of this source tree. 11 */const ce=de("CircleArrowUp",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m16 12-4-4-4 4",key:"177agl"}],["path",{d:"M12 16V8",key:"1sbj14"}]]),$e=()=>{const{data:n=[]}=P({queryKey:["financial-chart-real-data"],queryFn:async()=>{const[a,c]=await Promise.allSettled([v.from("payments").select("value, due_date, created_at"),v.from("receipts").select("value, receipt_date, created_at")]),d=["Jan","Fev","Mar","Abr","Mai","Jun","Jul","Ago","Set","Out","Nov","Dez"].map(r=>({month:r,receitas:0,despesas:0}));return a.status==="fulfilled"&&!a.value.error&&(a.value.data||[]).forEach(r=>{const s=r.due_date||r.created_at,l=s?new Date(s).getMonth():-1;l>=0&&(d[l].despesas+=Number(r.value||0))}),c.status==="fulfilled"&&!c.value.error&&(c.value.data||[]).forEach(r=>{const s=r.receipt_date||r.created_at,l=s?new Date(s).getMonth():-1;l>=0&&(d[l].receitas+=Number(r.value||0))}),d}});return n.some(a=>a.receitas>0||a.despesas>0)?e.jsx(Re,{width:"100%",height:300,children:e.jsxs(qe,{data:n,margin:{top:5,right:30,left:20,bottom:5},children:[e.jsx(Be,{strokeDasharray:"3 3"}),e.jsx(_e,{dataKey:"month"}),e.jsx(Ae,{}),e.jsx(Ee,{formatter:a=>`R$ ${Number(a).toLocaleString("pt-BR")}`}),e.jsx(Le,{}),e.jsx(le,{dataKey:"receitas",fill:"#10b981",name:"Receitas"}),e.jsx(le,{dataKey:"despesas",fill:"#ef4444",name:"Despesas"})]})}):e.jsx("div",{className:"flex h-[300px] items-center justify-center text-sm text-muted-foreground",children:"Nenhum dado financeiro encontrado no Supabase."})},Qe=()=>{const n=Se(),{data:i}=P({queryKey:["payments-overview"],queryFn:async()=>{const{data:s,error:l}=await v.from("payments").select("*");if(l)throw l;return s||[]}}),{data:a}=P({queryKey:["receipts-overview"],queryFn:async()=>{const{data:s,error:l}=await v.from("receipts").select("*");if(l)throw l;return s||[]}}),c=(i==null?void 0:i.reduce((s,l)=>s+Number(l.value),0))||0,x=(a==null?void 0:a.reduce((s,l)=>s+Number(l.value),0))||0,d=(i==null?void 0:i.filter(s=>s.status==="Pendente").reduce((s,l)=>s+Number(l.value),0))||0,r=(i==null?void 0:i.filter(s=>s.status==="Pago").reduce((s,l)=>s+Number(l.value),0))||0;return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs(T,{children:[e.jsxs(D,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(R,{className:"text-sm font-medium",children:"Recebimentos Totais"}),e.jsx(ce,{className:"h-4 w-4 text-green-500"})]}),e.jsxs(q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["R$ ",x.toLocaleStr
11ing("pt-BR")]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(a==null?void 0:a.length)||0," recebimentos registrados"]})]})]}),e.jsxs(T,{children:[e.jsxs(D,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(R,{className:"text-sm font-medium",children:"Pagamentos Totais"}),e.jsx(ze,{className:"h-4 w-4 text-red-500"})]}),e.jsxs(q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["R$ ",c.toLocaleString("pt-BR")]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(i==null?void 0:i.length)||0," pagamentos registrados"]})]})]}),e.jsxs(T,{children:[e.jsxs(D,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(R,{className:"text-sm font-medium",children:"Despesas Pendentes"}),e.jsx(Fe,{className:"h-4 w-4 text-yellow-500"})]}),e.jsxs(q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["R$ ",d.toLocaleString("pt-BR")]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(i==null?void 0:i.filter(s=>s.status==="Pendente").length)||0," pagamentos pendentes"]})]})]}),e.jsxs(T,{children:[e.jsxs(D,{className:"flex flex-row items-center justify-between pb-2",children:[e.jsx(R,{className:"text-sm font-medium",children:"Despesas Pagas"}),e.jsx(Me,{className:"h-4 w-4 text-blue-500"})]}),e.jsxs(q,{children:[e.jsxs("div",{className:"text-2xl font-bold",children:["R$ ",r.toLocaleString("pt-BR")]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[(i==null?void 0:i.filter(s=>s.status==="Pago").length)||0," pagamentos realizados"]})]})]})]}),e.jsxs(T,{className:"col-span-4",children:[e.jsx(D,{children:e.jsx(R,{className:"text-marmoraria-burgundy",children:"Receitas vs Despesas"})}),e.jsx(q,{className:"pl-2",children:e.jsx($e,{})})]}),e.jsxs("div",{className:"flex flex-wrap gap-4 mt-6",children:[e.jsxs(h,{className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",onClick:()=>n("/finance?tab=payments"),children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Acessar Pagamentos"]}),e.jsxs(h,{className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",onClick:()=>n("/finance?tab=receipts"),children:[e.jsx(ce,{className:"mr-2 h-4 w-4"}),"Acessar Recebimentos"]}),e.jsxs(h,{variant:"outline",onClick:()=>n("/finance?tab=reports"),children:[e.jsx(oe,{className:"mr-2 h-4 w-4"}),"Gerar Relatórios"]})]})]})},Xe=({onAddNew:n})=>{const i=z(),{data:a=[],isLoading:c}=P({queryKey:["payments"],queryFn:async()=>{const{data:s,error:l}=await v.from("payments").select(` 12 *, 13 bank_accounts ( 14 name 15 ) 16 `).order("created_at",{ascending:!1});if(l)throw l;return s||[]}}),x=$({mutationFn:async s=>{const{error:l}=await v.from("payments").delete().eq("id",s);if(l)throw l},onSuccess:()=>{i.invalidateQueries({queryKey:["payments"]}),f.success("Pagamento excluÃdo com sucesso!")},onError:s=>{console.error("Erro ao excluir pagamento:",s),f.error("Erro ao excluir pagamento")}}),d=s=>{switch(s){case"Pago":return"bg-green-100 text-green-800 border-green-300";case"Em atraso":return"bg-red-100 text-red-800 border-red-300";case"Pendente":return"bg-yellow-100 text-yellow-800 border-yellow-300";default:return"bg-gray-100 text-gray-800 border-gray-300"}},r=s=>{window.confirm("Tem certeza que deseja excluir este pagamento?")&&x.mutate(s)};return c?e.jsx("div",{className:"text-center py-4",children:"Carregando pagamentos..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-bold text-marmoraria-burgundy",children:"Pagamentos"}),e.jsxs(h,{onClick:n,className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),"Novo Pagamento"]})]}),a.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:'Nenhum pagamento cadastrado. Clique em "Novo Pagamento" para começar.'}):e.jsxs(je,{children:[e.jsx(pe,{children:e.jsxs(G,{children:[e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Nome/Descrição"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Tipo"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Vencimento"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Valor (R$)"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Status"}),e.jsx(C,{className:"text-right bg-marmoraria-burgundy",children:"Ações"})]})}),e.jsx(ge,{children:a.map(s=>e.jsxs(G,{children:[e.jsx(S,{className:"font-medium",children:s.name}),e.jsx(S,{children:s.payment_type}),e.jsx(S,{children:new Date(s.due_date).toLocaleDateString("pt-BR")}
16),e.jsx(S,{children:Number(s.value).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}),e.jsx(S,{children:e.jsx("span",{className:`px-2 py-1 rounded-full text-xs font-medium ${d(s.status)}`,children:s.status})}),e.jsx(S,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(h,{variant:"ghost",size:"icon",children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"icon",children:e.jsx(W,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"icon",onClick:()=>r(s.id),disabled:x.isPending,children:e.jsx(be,{className:"h-4 w-4"})})]})})]},s.id))})]})]})},we=({open:n,onOpenChange:i,onSelect:a,includeClients:c=!1})=>{const[x,d]=u.useState(""),{data:r=[]}=P({queryKey:["suppliers-search"],queryFn:async()=>{const{data:m,error:b}=await v.from("suppliers").select("id, name, company_name, trade_name, type, document").order("name");if(b)throw b;return(m||[]).map(j=>({id:j.id,displayName:j.type==="legal"?j.trade_name||j.company_name||"Sem nome":j.name||"Sem nome",document:j.document||"",origin:"Fornecedor"}))},enabled:n}),{data:s=[]}=P({queryKey:["clients-search"],queryFn:async()=>{const{data:m,error:b}=await v.from("clients").select("id, name, company_name, fantasy_name, type, cpf, cnpj").order("name");if(b)throw b;return(m||[]).map(j=>({id:j.id,displayName:j.type==="juridica"?j.fantasy_name||j.company_name||"Sem nome":j.name||"Sem nome",document:j.type==="juridica"?j.cnpj||"":j.cpf||"",origin:"Cliente"}))},enabled:n&&c}),y=(c?[...r,...s]:r).filter(m=>m.displayName.toLowerCase().includes(x.toLowerCase())||m.document.includes(x)),N=m=>{a(m),i(!1),d("")};return e.jsx(me,{open:n,onOpenChange:i,children:e.jsxs(ue,{className:"sm:max-w-[500px]",children:[e.jsx(xe,{children:e.jsx(he,{className:"text-marmoraria-burgundy",children:c?"Buscar Fornecedor ou Cliente":"Buscar Fornecedor"})}),e.jsxs("div",{className:"relative",children:[e.jsx(re,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(F,{placeholder:"Buscar por nome ou documento...",value:x,onChange:m=>d(m.target.value),className:"pl-10"})]}),e.jsx(Ke,{className:"h-[300px]",children:y.length===0?e.jsx("p",{className:"text-center text-muted-foreground py-8 text-sm",children:"Nenhum registro encontrado"}):e.jsx("div",{className:"space-y-1",children:y.map(m=>e.jsxs("button",{type:"button",className:"w-full text-left px-3 py-2 rounded-md hover:bg-accent transition-colors text-sm",onClick:()=>N(m.displayName),children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("span",{className:"font-medium",children:m.displayName}),e.jsx("span",{className:"text-xs text-muted-foreground bg-muted px-2 py-0.5 rounded",children:m.origin})]}),m.document&&e.jsx("span",{className:"text-xs text-muted-foreground",children:m.document})]},`${m.origin}-${m.id}`))})})]})})},Ce=({open:n,onOpenChange:i,onSuccess:a})=>{const c=z(),[x,d]=u.useState(""),[r,s]=u.useState(""),[l,y]=u.useState(""),[N,m]=u.useState(""),[b,j]=u.useState("corrente"),I=()=>{d(""),s(""),y(""),m(""),j("corrente")},L=$({mutationFn:async()=>{const{data:g,error:k}=await v.from("bank_accounts").insert([{name:x,bank_name:r,agency:l,account_number:N,account_type:b}]).select("id").single();if(k)throw k;return g},onSuccess:g=>{c.invalidateQueries({queryKey:["bank-accounts"]}),f.success("Conta bancária cadastrada com sucesso!"),a==null||a(g.id),I(),i(!1)},onError:()=>{f.error("Erro ao cadastrar conta bancária")}}),M=g=>{if(g.preventDefault(),!x||!r){f.error("Preencha o nome e o banco.");return}L.mutate()};return e.jsx(me,{open:n,onOpenChange:i,children:e.jsxs(ue,{className:"sm:max-w-[450px]",children:[e.jsx(xe,{children:e.jsx(he,{className:"text-marmoraria-burgundy",children:"Nova Conta Bancária"})}),e.jsxs("form",{onSubmit:M,className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"acc-name",children:"Nome da Conta*"}),e.jsx(F,{id:"acc-name",value:x,onChange:g=>d(g.target.value),placeholder:"Ex: Conta Principal",required:!0})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"acc-bank",children:"Banco*"}),e.jsx(F,{id:"acc-bank",value:r,onChange:g=>s(g.target.value),placeholder:"Ex: Banco do Brasil",required:!0})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"acc-agency",children:"Agência"}
16),e.jsx(F,{id:"acc-agency",value:l,onChange:g=>y(g.target.value),placeholder:"0000"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"acc-number",children:"Número da Conta"}),e.jsx(F,{id:"acc-number",value:N,onChange:g=>m(g.target.value),placeholder:"00000-0"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"Tipo de Conta"}),e.jsxs(B,{value:b,onValueChange:j,children:[e.jsx(_,{children:e.jsx(A,{})}),e.jsxs(E,{children:[e.jsx(o,{value:"corrente",children:"Conta Corrente"}),e.jsx(o,{value:"poupanca",children:"Conta Poupança"})]})]})]}),e.jsxs(Pe,{children:[e.jsx(h,{type:"button",variant:"outline",onClick:()=>i(!1),children:"Cancelar"}),e.jsx(h,{type:"submit",className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",disabled:L.isPending,children:L.isPending?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"mr-2 h-4 w-4 animate-spin"}),"Salvando..."]}):e.jsxs(e.Fragment,{children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),"Salvar"]})})]})]})]})})},Ge=({onCancel:n,onSuccess:i})=>{const a=z(),[c,x]=u.useState(""),[d,r]=u.useState(""),[s,l]=u.useState(void 0),[y,N]=u.useState(""),[m,b]=u.useState(""),[j,I]=u.useState(""),[L,M]=u.useState(!1),[g,k]=u.useState(!1),{data:J=[]}=P({queryKey:["bank-accounts"],queryFn:async()=>{const{data:t,error:w}=await v.from("bank_accounts").select("*").eq("active",!0).order("name");if(w)throw w;return t||[]}}),V=$({mutationFn:async t=>{const{error:w}=await v.from("payments").insert([t]);if(w)throw w},onSuccess:()=>{a.invalidateQueries({queryKey:["payments"]}),a.invalidateQueries({queryKey:["payments-overview"]}),f.success("Pagamento cadastrado com sucesso!"),i()},onError:t=>{console.error("Erro ao salvar pagamento:",t),f.error("Erro ao cadastrar pagamento")}}),H=t=>{if(t.preventDefault(),!c||!d||!s||!y||!m){f.error("Por favor, preencha todos os campos obrigatórios.");return}V.mutate({name:c,payment_type:d,due_date:K(s,"yyyy-MM-dd"),bank_account_id:y,value:parseFloat(m),observations:j||null,status:"Pendente"})};return e.jsxs(e.Fragment,{children:[e.jsxs(T,{children:[e.jsx(D,{children:e.jsx(R,{className:"text-marmoraria-burgundy",children:"Novo Pagamento"})}),e.jsxs("form",{onSubmit:H,children:[e.jsxs(q,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"name",children:"Nome ou Identificação*"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{id:"name",value:c,onChange:t=>x(t.target.value),placeholder:"Nome do fornecedor ou descrição",required:!0,className:"flex-1"}),e.jsx(h,{type:"button",variant:"outline",size:"icon",onClick:()=>M(!0),title:"Buscar fornecedor",children:e.jsx(re,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"payment-type",children:"Tipo de Pagamento*"}),e.jsxs(B,{value:d,onValueChange:r,required:!0,children:[e.jsx(_,{id:"payment-type",children:e.jsx(A,{placeholder:"Selecione o tipo de pagamento"})}),e.jsxs(E,{children:[e.jsx(o,{value:"Boleto",children:"Boleto"}),e.jsx(o,{value:"Transferência",children:"Transferência Bancária"}),e.jsx(o,{value:"PIX",children:"PIX"}),e.jsx(o,{value:"Débito Automático",children:"Débito Automático"}),e.jsx(o,{value:"Cartão de Crédito",children:"Cartão de Crédito"}),e.jsx(o,{value:"Dinheiro",children:"Dinheiro"}),e.jsx(o,{value:"Cheque",children:"Cheque"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"due-date",children:"Data de Vencimento*"}),e.jsxs(Z,{children:[e.jsx(ee,{asChild:!0,children:e.jsxs(h,{variant:"outline",className:U("w-full justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),s?K(s,"PPP",{locale:O}):"Selecione uma data"]})}),e.jsx(se,{className:"w-auto p-0",children:e.jsx(ae,{mode:"single",selected:s,onSelect:l,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"bank-account",children:"Conta Bancária*"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(B,{value:y,onValueChange:N,required:!0,children:[e.jsx(_,{id:"bank-account",className:"flex-1",children:e.jsx(A,{placeholder:"Selecione a conta bancária"})}),e.jsx(E,{children:J.map(t=>e.jsxs(o,{value:t.id,children:[t.name," - ",t.bank_name]},t.id))})]}),e.jsx(h,{type:"button",variant:"outline",size:"icon",onClick:()=>k(!0),title:"Nova conta bancária",children:e.jsx(Ne,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"value",children:"Valor (R$)*"}),e.jsx(F,{id:"value",value:m,onChange:t=>b(t.target.value),placeholder:"0,00",type:"number",step:"0.01",min:"0",required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"observations",children:"Observações"}),e.jsx(fe,{id:"observations",value:j,onChange:t=>I(t.target.value),placeholder:"Comentários adicionais",rows:3})]})]}),e.jsxs(Y,{className:"flex justify-between",children:[e.jsxs(h,{type:"button",variant:"outline",onClick:n,children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Cancelar"]}),e.jsxs(h,{type:"submit",className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",disabled:V.isPending,children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),V.isPending?"Salvando...":"Salvar"]})]})]})]}),e.jsx(we,{open:L,onOpenChange:M,onSelect:x}),e.jsx(Ce,{open:g,onOpenChange:k,onSuccess:t=>N(t)})]})},Je=({onAddNew:n})=>{const i=z(),{data:a=[],isLoading:c}=P({queryKey:["receipts"],queryFn:async()=>{const{data:r,error:s}=await v.from("receipts").select(` 17 *, 18 bank_accounts ( 19 name 20 ) 21 `).order("created_at",{ascending:!1});if(s)throw s;return r||[]}}),x=$({mutationFn:async r=>{const{error:s}=await v.from("receipts").delete().eq("id",r);
21if(s)throw s},onSuccess:()=>{i.invalidateQueries({queryKey:["receipts"]}),f.success("Recebimento excluÃdo com sucesso!")},onError:r=>{console.error("Erro ao excluir recebimento:",r),f.error("Erro ao excluir recebimento")}}),d=r=>{window.confirm("Tem certeza que deseja excluir este recebimento?")&&x.mutate(r)};return c?e.jsx("div",{className:"text-center py-4",children:"Carregando recebimentos..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsx("h2",{className:"text-xl font-bold text-marmoraria-burgundy",children:"Recebimentos"}),e.jsxs(h,{onClick:n,className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",children:[e.jsx(ye,{className:"mr-2 h-4 w-4"}),"Novo Recebimento"]})]}),a.length===0?e.jsx("div",{className:"text-center py-8 text-gray-500",children:'Nenhum recebimento cadastrado. Clique em "Novo Recebimento" para começar.'}):e.jsxs(je,{children:[e.jsx(pe,{children:e.jsxs(G,{children:[e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Nome/Descrição"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Tipo"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Data"}),e.jsx(C,{className:"bg-marmoraria-burgundy",children:"Valor (R$)"}),e.jsx(C,{className:"text-right bg-marmoraria-burgundy",children:"Ações"})]})}),e.jsx(ge,{children:a.map(r=>e.jsxs(G,{children:[e.jsx(S,{className:"font-medium",children:r.name}),e.jsx(S,{children:r.receipt_type}),e.jsx(S,{children:new Date(r.receipt_date).toLocaleDateString("pt-BR")}),e.jsx(S,{children:Number(r.value).toLocaleString("pt-BR",{style:"currency",currency:"BRL"})}),e.jsx(S,{className:"text-right",children:e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(h,{variant:"ghost",size:"icon",children:e.jsx(ve,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"icon",children:e.jsx(W,{className:"h-4 w-4"})}),e.jsx(h,{variant:"ghost",size:"icon",onClick:()=>d(r.id),disabled:x.isPending,children:e.jsx(be,{className:"h-4 w-4"})})]})})]},r.id))})]})]})},He=({onCancel:n,onSuccess:i})=>{const a=z(),[c,x]=u.useState(""),[d,r]=u.useState(""),[s,l]=u.useState(void 0),[y,N]=u.useState(""),[m,b]=u.useState(""),[j,I]=u.useState(""),[L,M]=u.useState(!1),[g,k]=u.useState(!1),{data:J=[]}=P({queryKey:["bank-accounts"],queryFn:async()=>{const{data:t,error:w}=await v.from("bank_accounts").select("*").eq("active",!0).order("name");if(w)throw w;return t||[]}}),V=$({mutationFn:async t=>{const{error:w}=await v.from("receipts").insert([t]);if(w)throw w},onSuccess:()=>{a.invalidateQueries({queryKey:["receipts"]}),a.invalidateQueries({queryKey:["receipts-overview"]}),f.success("Recebimento registrado com sucesso!"),i()},onError:t=>{console.error("Erro ao salvar recebimento:",t),f.error("Erro ao registrar recebimento")}}),H=t=>{if(t.preventDefault(),!c||!d||!s||!y||!m){f.error("Por favor, preencha todos os campos obrigatórios.");return}V.mutate({name:c,receipt_type:d,receipt_date:K(s,"yyyy-MM-dd"),bank_account_id:y,value:parseFloat(m),observations:j||null})};return e.jsxs(e.Fragment,{children:[e.jsxs(T,{children:[e.jsx(D,{children:e.jsx(R,{className:"text-marmoraria-burgundy",children:"Novo Recebimento"})}),e.jsxs("form",{onSubmit:H,children:[e.jsxs(q,{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"name",children:"Nome ou Identificação*"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(F,{id:"name",value:c,onChange:t=>x(t.target.value),placeholder:"Nome do cliente ou descrição",required:!0,className:"flex-1"}),e.jsx(h,{type:"button",variant:"outline",size:"icon",onClick:()=>M(!0),title:"Buscar fornecedor ou cliente",children:e.jsx(re,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"receipt-type",children:"Tipo de Recebimento*"}),e.jsxs(B,{value:d,onValueChange:r,required:!0,children:[e.jsx(_,{id:"receipt-type",children:e.jsx(A,{placeholder:"Selecione o tipo de recebimento"})}),e.jsxs(E,{children:[e.jsx(o,{value:"Depósito",children:"Depósito"}),e.jsx(o,{value:"Transferência",children:"Transferência Bancária"}),e.jsx(o,{value:"PIX",children:"PIX"}),e.jsx(o,{value:"Cartão de Crédito",children:"Cartão de Crédito"}),e.jsx(o,{value:"Cartão de Débito",children:"Cartão de Débito"}),e.jsx(o,{value:"Dinheiro",children:"Dinheiro"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"receipt-date",children:"Data do Recebimento*"}),e.jsxs(Z,{children:[e.jsx(ee,{asChild:!0,children:e.jsxs(h,{variant:"outline",className:U("w-full justify-start text-left font-normal",!s&&"text-muted-foreground"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),s?K(s,"PPP",{locale:O}):"Selecione uma data"]})}),e.jsx(se,{className:"w-auto p-0",children:e.jsx(ae,{mode:"single",selected:s,onSelect:l,initialFocus:!0})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"bank-account",children:"Conta Bancária*"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(B,{value:y,onValueChange:N,required:!0,children:[e.jsx(_,{id:"bank-account",className:"flex-1",children:e.jsx(A,{placeholder:"Selecione a conta bancária"})}),e.jsx(E,{children:J.map(t=>e.jsxs(o,{value:t.id,children:[t.name," - ",t.bank_name]},t.id))})]}),e.jsx(h,{type:"button",variant:"outline",size:"icon",onClick:()=>k(!0),title:"Nova conta bancária",children:e.jsx(Ne,{className:"h-4 w-4"})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"value",children:"Valor (R$)*"}),e.jsx(F,{id:"value",value:m,onChange:t=>b(t.target.value),placeholder:"0,00",type:"number",step:"0.01",min:"0",required:!0})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"observations",children:"Observações"}),e.jsx(fe,{id:"observations",value:j,onChange:t=>I(t.target.value),placeholder:"Comentários adicionais",rows:3})]})]}),e.jsxs(Y,{className:"flex justify-between",children:[e.jsxs(h,{type:"button",variant:"outline",onClick:n,children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Cancelar"]}),e.jsxs(h,{type:"submit",className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",disabled:V.isPending,children:[e.jsx(te,{className:"mr-2 h-4 w-4"}),V.isPending?"Salvando...":"Salvar"]})]})]})]}),e.jsx(we,{open:L,onOpenChange:M,onSelect:x,includeClients:!0}),e.jsx(Ce,{open:g,onOpenChange:k,onSuccess:t=>N(t)})]})},Ue=()=>{const[n,i]=u.useState(""),[a,c]=u.useState(),[x,d]=u.useState(""),[r,s]=u.useState(""),[l,y]=u.useState(""),N=()=>{console.log("Generating PDF with filters:",{reportType:n,dateRange:a,clientFilter:x,statusFilter:r,paymentTypeFilter:l})},m=()=>{console.log("Generating Excel with filters:",{reportType:n,dateRange:a,clientFilter:x,statusFilter:r,paymentTypeFilter:l})},b=()=>{i(""),c(void 0),d(""),s(""),y("")};return e.jsxs(T,{children:[e.jsx(D,{children:e.jsx(R,{className:"text-marmoraria-burgundy",children:"Relatórios Financeiros"})}),e.jsxs(q,{className:"space-y-6",children:[e.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"report-type",children:"Tipo de Relatório*"}),e.jsxs(B,{value:n,onValueChange:i,children:[e.jsx(_,{id:"report-type",children:e.jsx(A,{placeholder:"Selecione o tipo de relatório"})}),e.jsxs(E,{children:[e.jsx(o,{value:"payments",children:"Pagamentos"}),e.jsx(o,{value:"receipts",children:"Recebimentos"}),e.jsx(o,{value:"consolidated",children:"Despesas e Receitas (Consolidado)"})]})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{children:"PerÃodo"}),e.jsxs(Z,{children:[e.jsx(ee,{asChild:!0,children:e.jsxs(h,{variant:"outline",className:U("w-full justify-start text-left font-normal",!(a!=null&&a.from)&&"text-muted-foreground"),children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}
21),a!=null&&a.from?a.to?e.jsxs(e.Fragment,{children:[K(a.from,"P",{locale:O})," -"," ",K(a.to,"P",{locale:O})]}):K(a.from,"P",{locale:O}):e.jsx("span",{children:"Selecione um perÃodo"})]})}),e.jsx(se,{className:"w-auto p-0",align:"start",children:e.jsx(ae,{initialFocus:!0,mode:"range",defaultMonth:a==null?void 0:a.from,selected:a,onSelect:c,numberOfMonths:2})})]})]}),n==="payments"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"status-filter",children:"Status"}),e.jsxs(B,{value:r,onValueChange:s,children:[e.jsx(_,{id:"status-filter",children:e.jsx(A,{placeholder:"Todos os status"})}),e.jsxs(E,{children:[e.jsx(o,{value:"all",children:"Todos"}),e.jsx(o,{value:"paid",children:"Pagos"}),e.jsx(o,{value:"pending",children:"Pendentes"}),e.jsx(o,{value:"overdue",children:"Em atraso"})]})]})]}),(n==="payments"||n==="receipts")&&e.jsxs("div",{className:"space-y-2",children:[e.jsxs(p,{htmlFor:"type-filter",children:["Tipo de ",n==="payments"?"Pagamento":"Recebimento"]}),e.jsxs(B,{value:l,onValueChange:y,children:[e.jsx(_,{id:"type-filter",children:e.jsx(A,{placeholder:"Todos os tipos"})}),e.jsxs(E,{children:[e.jsx(o,{value:"all",children:"Todos"}),n==="payments"?e.jsxs(e.Fragment,{children:[e.jsx(o,{value:"boleto",children:"Boleto"}),e.jsx(o,{value:"transfer",children:"Transferência"}),e.jsx(o,{value:"pix",children:"PIX"}),e.jsx(o,{value:"credit",children:"Cartão de Crédito"}),e.jsx(o,{value:"debit",children:"Débito Automático"})]}):e.jsxs(e.Fragment,{children:[e.jsx(o,{value:"deposit",children:"Depósito"}),e.jsx(o,{value:"transfer",children:"Transferência"}),e.jsx(o,{value:"pix",children:"PIX"}),e.jsx(o,{value:"credit",children:"Cartão de Crédito"}),e.jsx(o,{value:"debit",children:"Cartão de Débito"})]})]})]})]}),n==="receipts"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(p,{htmlFor:"client-filter",children:"Cliente"}),e.jsx(F,{id:"client-filter",value:x,onChange:j=>d(j.target.value),placeholder:"Nome do cliente"})]})]}),n&&e.jsxs("div",{className:"border rounded-md p-4 bg-gray-50",children:[e.jsx("h3",{className:"font-medium mb-2",children:"Pré-visualização do Relatório"}),e.jsx("p",{className:"text-sm text-gray-500",children:n==="payments"?"Este relatório mostrará todos os pagamentos com os filtros selecionados.":n==="receipts"?"Este relatório mostrará todos os recebimentos com os filtros selecionados.":"Este relatório mostrará uma visão consolidada de despesas e receitas no perÃodo selecionado."})]})]}),e.jsxs(Y,{className:"flex flex-wrap justify-between gap-2",children:[e.jsx("div",{children:e.jsxs(h,{variant:"outline",onClick:b,children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Limpar Filtros"]})}),e.jsxs("div",{className:"flex gap-2",children:[e.jsxs(h,{variant:"outline",onClick:m,disabled:!n,children:[e.jsx(Oe,{className:"mr-2 h-4 w-4"}),"Exportar Excel"]}),e.jsxs(h,{className:"bg-marmoraria-burgundy hover:bg-marmoraria-burgundy/90",onClick:N,disabled:!n,children:[e.jsx(W,{className:"mr-2 h-4 w-4"}),"Gerar PDF"]})]})]})]})},Ye=()=>{const[n,i]=u.useState("overview"),[a,c]=u.useState(!1),[x,d]=u.useState(!1),r=s=>{i(s),c(!1),d(!1)};return e.jsx("div",{className:"bg-white rounded-lg shadow-sm p-4 sm:p-6 w-full",children:e.jsxs(Te,{defaultValue:"overview",value:n,onValueChange:r,children:[e.jsxs(De,{className:"grid grid-cols-2 sm:grid-cols-4 w-full mb-6 bg-marmoraria-burgundy h-auto",children:[e.jsx(Q,{value:"overview",className:"text-xs sm:text-sm py-2 px-2 sm:px-4",children:"Dashboard"}),e.jsx(Q,{value:"payments",className:"text-xs sm:text-sm py-2 px-2 sm:px-4",children:"Pagamentos"}),e.jsx(Q,{value:"receipts",className:"text-xs sm:text-sm py-2 px-2 sm:px-4",children:"Recebimentos"}),e.jsx(Q,{value:"reports",className:"text-xs sm:text-sm py-2 px-2 sm:px-4",children:"Relatórios"})]}),e.jsx(X,{value:"overview",className:"mt-6",children:e.jsx(Qe,{})}),e.jsx(X,{value:"payments",className:"mt-6",children:a?e.jsx(Ge,{onCancel:()=>c(!1),onSuccess:()=>c(!1)}):e.jsx(Xe,{onAddNew:()=>c(!0)})}),e.jsx(X,{value:"receipts",className:"mt-6",children:x?e.jsx(He,{onCancel:()=>d(!1),onSuccess:()=>d(!1)}):e.jsx(Je,{onAddNew:()=>d(!0)})}),e.jsx(X,{value:"reports",className:"mt-6",children:e.jsx(Ue,{})})]})})},Es=()=>{const n=Ve();return e.jsxs("div",{className:"min-h-screen flex bg-gray-50 w-full",children:[e.jsx(ke,{}),e.jsxs("div",{className:`flex-1 ${n?"":"ml-20"} p-4 sm:p-6 flex flex-col w-full`,children:[e.jsx("h1",{className:"text-2xl font-bold mb-6 text-marmoraria-burgundy",children:"Gerenciamento Financeiro"}),e.jsx("div",{className:"overflow-x-auto w-full",children:e.jsx(Ye,{})})]})]})};export{Es 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.