1"use strict";(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6156],{6156:(e,a,t)=>{t.r(a),t.d(a,{default:()=>A});var s=t(95155),o=t(12115),l=t(14272),r=t(67592),i=t(78384),n=t(28394),c=t(27937),d=t(56154),u=t(6191),p=t(21190),x=t(71360),m=t(89559),b=t(48314),h=t(45345),g=t(1524),f=t(26921),v=t(65229),j=t(38971);let N={"1.1.1":"Recebimento de pedidos de delivery","1.1.2":"Recebimento de pedidos presenciais (mesa/sal\xe3o)","1.1.3":"Recebimento de pedidos de retirada","1.2.2":"Contas a receber sem categoria e suprimento de caixa","2.1":"CMV: baixa de estoque na venda e compras classificadas como CMV","2.2":"Perdas e desperd\xedcio registrados no estoque","3.1.3":"Acerto e comiss\xe3o de entregadores","3.1.4":"Acerto e comiss\xe3o de gar\xe7ons","3.6.1":"Impostos do tipo DAS / Simples Nacional","3.6.2":"Impostos do tipo ISS","3.6.3":"Demais impostos e taxas","3.8.1":"Compras de insumo antigas (conta legada, antes da separa\xe7\xe3o por tipo de custo)","3.8.2":"Compras classificadas como Embalagem","3.9.1":"Sangria de caixa","3.10.1":"Compras classificadas como Operacional"};function k(e){var a;return e&&null!=(a=N[e])?a:null}async function w(){var e,a;let{data:t}=await (0,l.U)("admin").auth.getSession();return null!=(a=null==(e=t.session)?void 0:e.access_token)?a:""}let y=[{value:"receita",label:"Receitas",tipo:"receita"},{value:"fixa",label:"Despesas Fixas",tipo:"despesa"},{value:"variavel",label:"Despesas Vari\xe1veis",tipo:"despesa"},{value:"fornecedor",label:"Fornecedores (CMV e Embalagens)",tipo:"despesa"},{value:"imposto",label:"Impostos",tipo:"despesa"},{value:"financeira",label:"Despesas Financeiras",tipo:"despesa"},{value:"frota",label:"Despesas da Frota",tipo:"despesa"},{value:"investimento",label:"Investimentos",tipo:"despesa"},{value:"nao_operacional",label:"N\xe3o Operacional",tipo:"ambos"}],C=e=>"receita"===e?"receita":"fixa",z=()=>({codigo:"",nome:"",tipo:"despesa",natureza:"variavel",nivel:1,aceita_lancamento:!0,ativo:!0,grupo_fluxo:"fixa"});function A(){var e,a,t,l,N,A,S;let{showToast:E}=(0,r.d)(),{restaurantId:_}=(0,i.p)(),[F,R]=(0,o.useState)([]),[D,I]=(0,o.useState)(!0),[O,q]=(0,o.useState)(!1),[V,M]=(0,o.useState)(null),[P,T]=(0,o.useState)(z()),[B,H]=(0,o.useState)(!1),[L,G]=(0,o.useState)(new Set),J=(0,o.useCallback)(async()=>{let e=(0,n.H)("/api/admin/financeiro/plano-contas",_);if(!e)return void I(!1);I(!0);let a=await w(),t=await fetch(e,{headers:{authorization:"Bearer ".concat(a)}});t.ok&&R(await t.json()),I(!1)},[_]);(0,o.useEffect)(()=>{J()},[J]);let U=e=>{var a,t;M(null);let s=null!=(a=null==e?void 0:e.tipo)?a:"despesa";T({...z(),pai_id:null==e?void 0:e.id,nivel:e?e.nivel+1:1,tipo:s,grupo_fluxo:null!=(t=null==e?void 0:e.grupo_fluxo)?t:C(s)}),q(!0)},K=async()=>{var e,a,t;if(!(null==(e=P.codigo)?void 0:e.trim())||!(null==(a=P.nome)?void 0:a.trim()))return E("C\xf3digo e nome s\xe3o obrigat\xf3rios.","error");H(!0);let s=await w(),o=!!V,l=(0,n.H)("/api/admin/financeiro/plano-contas",_,o?{id:V.id}:{});if(!l)return H(!1),E("Restaurante n\xe3o carregado.","error");let r=await fetch(l,{method:o?"PUT":"POST",headers:{authorization:"Bearer ".concat(s),"content-type":"application/json"},body:JSON.stringify((0,n.o)(_,P))});H(!1),r.ok?(E(o?"Conta atualizada!":"Conta criada!","success"),q(!1),J()):E(null!=(t=(await r.json()).error)?t:"Erro ao salvar","error")},Q=async()=>{if(!window.confirm("Restaurar o plano de contas padr\xe3o? As categorias existentes ser\xe3o mantidas e as faltantes adicionadas."))return;let e=(0,n.H)("/api/admin/financeiro/plano-contas",_,{action:"seed"});if(!e)return E("Restaurante n\xe3o carregado.","error");let a=await w(),t=await fetch(e,{method:"POST",headers:{authorization:"Bearer ".concat(a),"content-type":"application/json"},body:JSON.stringify((0,n.o)(_,{}))});if(t.ok)E("Plano de contas padr\xe3o restaurado!","success"),J();else{var s;E(null!=(s=(await t.json().catch(()=>({}))).error)?s:"Erro ao restaurar padr\xe3o.","error")}},W=async e=>{var a;if(!window.confirm('Excluir a categoria "'.concat(e.nome,'"?\n\nEsta a\xe7\xe3o n\xe3o pode ser desfeita.')))return;let t=(0,n.H)("/api/admin/financeiro/plano-contas",_,{id:e.id});if(!t)return E("Restaurante n\xe3o carregado.","error");let s=await w(),o=await fetch(t,{method:"DELETE",headers:{authorization:"Bearer ".concat(s)}});if(o.ok){E("Categoria exclu\xedda!","success"),J();return}E(null!=(a=(await o.json().catch(()=>({}))).error)?a:"Erro ao excluir categoria.","error")},X=F.filter(e=>!e.pai_id),Y=F.filter(e=>"receita"===e.tipo&&e.ativo).length,Z=F.filter(e=>"despesa"===e.tipo&&e.ativo).length,$=function(e){let a,t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:0,o=(a=e.id,F.filter(e=>e.pai_id===a)),l=L.has(e.id),r="receita"===e.tipo,i=k(e.codigo);return(0,s.jsxs)("div",{children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 px-4 py-2.5 border-b border-slate-100 hover:bg-blue-50/20 transition-colors group ".concat(e.ativo?"":"opacity-40"),style:{paddingLeft:"".concat(16+20*t,"px")},children:[o.length>0&&(0,s.jsx)("button",{onClick:()=>{let a;return a=e.id,G(e=>{let t=new Set(e);return t.has(a)?t.delete(a):t.add(a),t})},className:"p-0.5 text-slate-400 hover:text-slate-600 cursor-pointer",children:(0,s.jsx)(c.A,{size:12,className:"transition-transform ".concat(l?"rotate-90":"")})}),0===o.length&&(0,s.jsx)("span",{className:"w-4"}),(0,s.jsx)("span",{className:"text-[10px] font-black text-slate-400 font-mono w-16 shrink-0",children:e.codigo}),(0,s.jsx)("span",{className:"w-2 h-2 rounded-full shrink-0 ".concat(r?"bg-emerald-400":"bg-red-400")}),(0,s.jsx)("span",{className:"flex-1 min-w-0 truncate text-sm font-".concat(0===t?"black":"semibold"," text-slate-").concat(0===t?"900":"700"),children:e.nome}),i&&(0,s.jsxs)("span",{title:"O sistema lan\xe7a automaticamente aqui: ".concat(i,". O destino \xe9 o C\xd3DIGO ").concat(e.codigo," â se voc\xea renomear ou usar esta conta para outra coisa, esses lan\xe7amentos continuam vindo para c\xe1."),className:"inline-flex items-center gap-1 text-[10px] font-black px-2 py-0.5 rounded-full bg-amber-100 text-amber-700 shrink-0",children:[(0,s.jsx)(d.A,{size:10})," Autom\xe1tica"]}),(0,s.jsx)("span",{className:"text-[10px] font-black px-2 py-0.5 rounded-full ".concat(r?"bg-emerald-100 text-emerald-700":"bg-red-100 text-red-600"),children:r?"Receita":"Despesa"}),e.natureza&&(0,s.jsx)("span",{className:"text-[10px] text-slate-400 hidden group-hover:inline",children:e.natureza}),!e.aceita_lancamento&&(0,s.jsx)("span",{className:"text-[10px] bg-slate-100 text-slate-500 px-1.5 py-0.5 rounded-full hidden group-hover:inline",children:"grupo"}),(0,s.jsxs)("div",{className:"flex items-center gap-1 opacity-0 max-md:opacity-100 group-hover:opacity-100 transition-opacity",children:[(0,s.jsx)("button",{onClick:()=>U(e),title:"Adicionar sub-conta",className:"p-1 rounded-lg hover:bg-blue-100 text-slate-400 hover:text-blue-600 cursor-pointer",children:(0,s.jsx)(u.A,{size:12})}),(0,s.jsx)("button",{onClick:()=>{M(e),T({...e}),q(!0)},title:"Editar",className:"p-1 rounded-lg hover:bg-slate-200 text-slate-400 hover:text-slate-600 cursor-pointer",children:(0,s.jsx)(p.A,{size:12})}),(0,s.jsx)("button",{onClick:()=>W(e),title:"Excluir",className:"p-1 rounded-lg hover:bg-red-100 text-slate-400 hover:text-red-600 cursor-pointer",children:(0,s.jsx)(x.A,{size:12})})]})]}),l&&o.map(e=>$(e,t+1))]},e.id)};return(0,s.jsxs)("div",{className:"space-y-6",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h2",{className:"text-xl font-black text-slate-900 inline-flex items-center gap-2",children:["Categorias Financeiras",(0,s.jsx)(j.V,{title:"Categorias Financeiras",size:"sm",children:"Plano de contas que organiza seus lan\xe7amentos (Aluguel, Folha, Marketing, Insumosâ¦). Sem categorias bem estruturadas, o DRE fica gen\xe9rico e imposs\xedvel de analisar â defina aqui antes de come\xe7ar a lan\xe7ar."})]}),(0,s.jsx)("p",{className:"text-xs text-slate-400 mt-0.5",children:"Plano de contas hier\xe1rquico"})]}),(0,s.jsxs)("div",{className:"flex gap-2 flex-wrap",children:[(0,s.jsxs)("button",{onClick:J,className:"flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 rounded-xl text-sm font-bold text-slate-600 hover:bg-slate-50 cursor-pointer transition-colors",children:[(0,s.jsx)(m.A,{size:14})," Atualizar"]}),(0,s.jsxs)("button",{onClick:Q,className:"flex items-center gap-2 px-4 py-2 bg-white border border-slate-200 rounded-xl text-sm font-bold text-slate-600 hover:bg-slate-50 cursor-pointer transition-colors",title:"Adiciona as categorias padr\xe3o que estiverem faltando.",children:[(0,s.jsx)(b.A,{size:14})," Restaurar padr\xe3o"]}),(0,s.jsxs)("button",{onClick:()=>U(),className:"flex items-center gap-2 px-4 py-2 bg-blue-600 text-white rounded-xl text-sm font-black cursor-pointer hover:bg-blue-700 transition-colors shadow-md",children:[(0,s.jsx)(u.A,{size:14})," Nova Categoria"]})]})]}),(0,s.jsx)("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-3",children:[{label:"Total de Contas",value:F.length,Icon:h.A,cls:"text-slate-700",bg:"bg-slate-50 border-slate-200"},{label:"Receitas",value:Y,Icon:g.A,cls:"text-emerald-600",bg:"bg-emerald-50 border-emerald-200"},{label:"Despesas",value:Z,Icon:f.A,cls:"text-red-600",bg:"bg-red-50 border-red-200"}
1].map((e,a)=>(0,s.jsxs)("div",{className:"rounded-2xl border p-4 ".concat(e.bg),children:[(0,s.jsxs)("div",{className:"flex items-center gap-2 mb-2",children:[(0,s.jsx)(e.Icon,{size:14,className:e.cls}),(0,s.jsx)("p",{className:"text-[10px] font-black uppercase tracking-widest text-slate-400",children:e.label})]}),(0,s.jsx)("p",{className:"text-2xl font-black ".concat(e.cls),children:e.value})]},a))}),D?(0,s.jsx)("div",{className:"flex justify-center py-16",children:(0,s.jsx)("div",{className:"w-8 h-8 border-4 border-blue-200 border-t-blue-600 rounded-full animate-spin"})}):(0,s.jsxs)("div",{className:"bg-white rounded-2xl border border-slate-200 shadow-sm overflow-hidden",children:[(0,s.jsxs)("div",{className:"px-4 py-3 bg-slate-50 border-b border-slate-200 flex items-center gap-4 text-[10px] font-black uppercase tracking-widest text-slate-400",children:[(0,s.jsx)("span",{className:"w-16",children:"C\xf3digo"}),(0,s.jsx)("span",{className:"flex-1",children:"Nome"}),(0,s.jsx)("span",{children:"Tipo"})]}),0===X.length?(0,s.jsx)("div",{className:"p-10 text-center text-slate-400",children:"Nenhuma categoria cadastrada."}):X.map(e=>$(e,0))]}),O&&(0,s.jsx)("div",{className:"fixed inset-0 bg-black/50 z-[200] flex items-center justify-center p-4",children:(0,s.jsxs)("div",{className:"bg-white rounded-2xl w-full max-w-md
1shadow-2xl",children:[(0,s.jsxs)("div",{className:"flex items-center justify-between p-6 border-b border-slate-100",children:[(0,s.jsx)("h3",{className:"text-lg font-black text-slate-800",children:V?"Editar Categoria":"Nova Categoria"}),(0,s.jsx)("button",{onClick:()=>q(!1),className:"text-slate-400 hover:text-slate-600 cursor-pointer",children:(0,s.jsx)(v.A,{size:20})})]}),(0,s.jsxs)("div",{className:"p-6 space-y-4",children:[k(P.codigo)&&(0,s.jsxs)("div",{className:"rounded-xl border border-amber-200 bg-amber-50 p-3",children:[(0,s.jsxs)("p",{className:"flex items-center gap-1.5 text-[11px] font-black text-amber-800 uppercase tracking-wide",children:[(0,s.jsx)(d.A,{size:12})," Categoria autom\xe1tica"]}),(0,s.jsxs)("p",{className:"mt-1.5 text-xs leading-5 text-amber-900",children:["O sistema lan\xe7a sozinho nesta conta: ",(0,s.jsx)("strong",{children:k(P.codigo)}),". O destino \xe9 o c\xf3digo ",(0,s.jsx)("strong",{className:"font-mono",children:P.codigo}),", n\xe3o o nome â se voc\xea usar esta categoria para outra coisa, esses lan\xe7amentos continuam caindo aqui e v\xe3o aparecer com o nome novo no DRE e no Fluxo de Caixa."]})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5",children:"C\xf3digo *"}),(0,s.jsx)("input",{value:null!=(e=P.codigo)?e:"",onChange:e=>T(a=>({...a,codigo:e.target.value})),placeholder:"Ex: 3.1.1",className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400 font-mono"})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5",children:"Tipo *"}),(0,s.jsxs)("select",{value:null!=(a=P.tipo)?a:"despesa",onChange:e=>{let a=e.target.value;T(e=>{let t=e.grupo_fluxo,s=y.find(e=>e.value===t),o=s&&(s.tipo===a||"ambos"===s.tipo);return{...e,tipo:a,grupo_fluxo:o?t:C(a)}})},className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400 bg-white cursor-pointer",children:[(0,s.jsx)("option",{value:"receita",children:"Receita"}),(0,s.jsx)("option",{value:"despesa",children:"Despesa"})]})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5",children:"Nome *"}),(0,s.jsx)("input",{value:null!=(t=P.nome)?t:"",onChange:e=>T(a=>({...a,nome:e.target.value})),placeholder:"Ex: Custo de Mercadoria Vendida",className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400"})]}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5 inline-flex items-center gap-1.5",children:["Grupo do Fluxo de Caixa *",(0,s.jsx)(j.V,{title:"Grupo do Fluxo de Caixa",size:"sm",children:'Define em qual linha da matriz mensal do Fluxo de Caixa a categoria entra (Receitas, Fixas, Vari\xe1veis, Fornecedor, Impostos, Financeiras, Frota, Investimentos ou N\xe3o Operacional). Sem isso, vai pra "N\xe3o Operacional" por padr\xe3o.'})]}),(0,s.jsx)("select",{value:null!=(l=P.grupo_fluxo)?l:"",onChange:e=>T(a=>({...a,grupo_fluxo:e.target.value||null})),className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400 bg-white cursor-pointer",children:y.filter(e=>{var a;return e.tipo===(null!=(a=P.tipo)?a:"despesa")||"ambos"===e.tipo}).map(e=>(0,s.jsx)("option",{value:e.value,children:e.label},e.value))})]}),(0,s.jsxs)("div",{className:"grid grid-cols-2 gap-3",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5",children:"Natureza"}),(0,s.jsxs)("select",{value:null!=(N=P.natureza)?N:"variavel",onCh
1ange:e=>T(a=>({...a,natureza:e.target.value})),className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400 bg-white cursor-pointer",children:[(0,s.jsx)("option",{value:"fixo",children:"Fixo"}),(0,s.jsx)("option",{value:"variavel",children:"Vari\xe1vel"})]})]}),(0,s.jsxs)("div",{children:[(0,s.jsx)("label",{className:"block text-[10px] font-black text-slate-400 uppercase tracking-widest mb-1.5",children:"N\xedvel"}),(0,s.jsx)("input",{type:"number",min:1,max:5,value:null!=(A=P.nivel)?A:1,onChange:e=>T(a=>({...a,nivel:Number(e.target.value)})),className:"w-full px-3 py-2.5 border border-slate-200 rounded-xl text-sm focus:outline-none focus:border-blue-400"})]})]}),(0,s.jsxs)("label",{className:"flex items-center gap-2 cursor-pointer",children:[(0,s.jsx)("input",{type:"checkbox",checked:null==(S=P.aceita_lancamento)||S,onChange:e=>T(a=>({...a,aceita_lancamento:e.target.checked})),className:"rounded"}),(0,s.jsx)("span",{className:"text-sm text-slate-700",children:"Aceita lan\xe7amentos diretos"})]}),(0,s.jsxs)("div",{className:"flex gap-3 pt-2",children:[(0,s.jsx)("button",{onClick:()=>q(!1),className:"flex-1 py-3 border border-slate-200 rounded-xl text-sm font-bold cursor-pointer hover:bg-slate-50",children:"Cancelar"}),(0,s.jsx)("button",{onClick:K,disabled:B,className:"flex-1 py-3 bg-blue-600 text-white rounded-xl text-sm font-black cursor-pointer hover:bg-blue-700 disabled:opacity-50",children:B?"Salvando...":"Salvar"})]})]})]})})]})}},21190:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(71847).A)("pen",[["path",{d:"M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z",key:"1a8usu"}]])},26921:(e,a,t)=>{t.d(a,{A:()=>s});let s=(0,t(71847).A)("trending-down",[["path",{d:"M16 17h6v-6",key:"t6n2it"}],["path",{d:"m22 17-8.5-8.5-5 5L2 7",key:"x473p"}]])}}]);
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.