PageSourceSearch

https://appconsultaai.com/assets/_app.admin.revendedores-DtJMG8pQ.js

js appconsultaai.com collected 2026-10-09 21:44:20 UTC 17,521 bytes, 2 lines download raw bytes

1const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/exceljs.min-hdmrRwxC.js","assets/icons-Dlea1YgH.js"])))=>i.map(i=>d[i]);
2import{e as M,r as B,f as P,u as S,A as I,w as q,j as e,n as z,t as y,_ as A,P as Q}from"./index-ypY3K6D-.js";import{u as K}from"./useMutation-Cz55krA4.js";import{r as m,x as W,Q as D,aZ as J,z as $,D as L,E as V,Y as T,$ as X,C as E,H as G,A as H}from"./icons-Dlea1YgH.js";import{r as Y}from"./admin.functions-H79nBdQf.js";import{t as F}from"./download-Q0ki7Lzx.js";import{f as d}from"./format-Cd6b4AK1.js";const Z=M({method:"GET"}).middleware([B]).handler(P("bbbd15a14f6d6af62e306743e2c27686fe71c015644392c65a9d6318d326fae2")),U=M({method:"POST"}).middleware([B]).handler(P("2e224ca2ec9fed7ff0a67776221c61d7a068b9cbad877164dcf328b820af9df5"));function le(){const u=S(Z),h=S(Y),p=I(),[r,_]=m.useState(""),[g,k]=m.useState("faturado"),[f,w]=m.useState(null),{data:x,isLoading:C}=q({queryKey:["admin","reseller-performance"],queryFn:()=>u()}),o=K({mutationFn:()=>h(),onSuccess:a=>{y.success(a.moved>0?`${a.moved} cliente(s) remanejado(s) para a carteira de revenda dos respectivos revendedores.`:"Tudo certo — nenhum indicado pendente de remanejamento."),p.invalidateQueries({queryKey:["admin"]})},onError:a=>y.error(a instanceof Error?a.message:"Falha ao reconciliar carteiras.")}),n=m.useMemo(()=>{const a=r.trim().toLowerCase();return(x??[]).filter(s=>!a||[s.company_name,s.email,s.phone,s.reseller_code].filter(Boolean).some(t=>String(t).toLowerCase().includes(a))).sort((s,t)=>{switch(g){case"clientes":return t.network_count-s.network_count;case"comissao":return t.commission_earned_cents-s.commission_earned_cents;
2case"recente":return new Date(t.created_at).getTime()-new Date(s.created_at).getTime();default:return t.faturado_cents-s.faturado_cents}})},[x,r,g]),b=m.useMemo(()=>{const a=x??[];return{count:a.length,faturado:a.reduce((s,t)=>s+t.faturado_cents,0),earned:a.reduce((s,t)=>s+t.commission_earned_cents,0),payable:a.reduce((s,t)=>s+t.commission_available_cents,0)}},[x]);async function j(){const a=(await A(async()=>{const{default:l}=await import("./exceljs.min-hdmrRwxC.js").then(c=>c.e);return{default:l}},__vite__mapDeps([0,1]))).default,s=new a.Workbook,t=s.addWorksheet("Revendedores");t.columns=[{header:"Revendedor",key:"nome",width:30},{header:"E-mail",key:"email",width:28},{header:"Telefone",key:"fone",width:16},{header:"Comissão %",key:"pct",width:11},{header:"Clientes",key:"cli",width:10},{header:"Ativos",key:"ativos",width:9},{header:"Faturado/Consumo (R$)",key:"fat",width:20},{header:"Consultas",key:"cons",width:10},{header:"Comissão gerada (R$)",key:"ger",width:19},{header:"Comissão a pagar (R$)",key:"disp",width:19}],t.getRow(1).font={bold:!0};for(const l of n)t.addRow({nome:l.company_name,email:l.email??"",fone:l.phone??"",pct:l.commission_pct,cli:l.network_count,ativos:l.active_clients,fat:l.faturado_cents/100,cons:l.consultas,ger:l.commission_earned_cents/100,disp:l.commission_available_cents/100});const i=await s.xlsx.writeBuffer(),R=new Blob([i],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});F(R,`revendedores-${new Date().toISOString().slice(0,10)}.xlsx`),y.success("Revendedores exportados")}return e.jsxs("div",{className:"mx-auto max-w-6xl space-y-6",children:[e.jsxs("header",{className:"relative overflow-hidden rounded-3xl mesh-ambient glass-strong p-6 md:p-8 flex flex-wrap items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("p",{className:"eyebrow text-muted-foreground",children:"Admin · Revenda"}),e.jsx("h2",{className:"mt-2 text-3xl font-bold tracking-tight text-foreground",children:"Revendedores"}),e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Performance por ",e.jsx("strong",{children:"consumo da rede"})," (não recarga). Clique para ver a rede de cada um."]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs("button",{onClick:()=>o.mutate(),disabled:o.isPending,title:"Move todos os indicados de cada revendedor para a carteira de revenda dele (gera comissão sobre consumo). Seguro rodar quantas vezes quiser.",className:"inline-flex items-center gap-1.5 rounded-xl border border-emerald/40 px-4 py-2 text-sm font-semibold text-emerald transition-smooth hover:bg-emerald/10 disabled:opacity-50 dark:text-mint",children:[e.jsx(W,{className:`h-4 w-4 ${o.isPending?"animate-spin":""}`}),o.isPending?"Reconciliando…":"Reconciliar carteiras"]}),e.jsxs("button",{onClick:j,disabled:!x,className:"inline-flex items-center gap-1.5 rounded-xl border border-emerald/40 px-4 py-2 text-sm font-semibold text-emerald transition-smooth hover:bg-emerald/10 disabled:opacity-50 dark:text-mint",children:[e.jsx(D,{className:"h-4 w-4"})," Exportar Excel"]})]})]}),e.jsxs("section",{className:"grid grid-cols-2 gap-3 lg:grid-cols-4",children:[e.jsx(N,{icon:e.jsx(J,{className:"h-4 w-4"}),label:"Revendedores",value:String(b.count)}),e.jsx(N,{icon:e.jsx($,{className:"h-4 w-4"}),label:"Faturado pela rede (consumo)",value:d(b.faturado)}),e.jsx(N,{icon:e.jsx(L,{className:"h-4 w-4"}),label:"Comissão gerada",value:d(b.earned),tone:"text-amber-500"}),e.jsx(N,{icon:e.jsx(V,{className:"h-4 w-4"}),label:"Comissão a pagar",value:d(b.payable),tone:"text-amber-500"})]}),e.jsxs("div",{className:"flex flex-col gap-3 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(T,{className:"pointer-events-none absolute left-3 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:r,onChange:a=>_(a.target.value),placeholder:"Buscar revendedor por nome, e-mail, telefone ou código…",className:"w-full rounded-lg border border-border bg-background py-2 pl-9 pr-3 text-sm text-foreground focus:border-emerald/40 focu
2s:outline-none focus:ring-2 focus:ring-emerald/20"})]}),e.jsxs("select",{value:g,onChange:a=>k(a.target.value),className:"rounded-lg border border-border bg-background px-3 py-2 text-sm text-foreground sm:w-auto [color-scheme:dark]",children:[e.jsx("option",{value:"faturado",children:"Maior faturamento (consumo)"}),e.jsx("option",{value:"comissao",children:"Maior comissão gerada"}),e.jsx("option",{value:"clientes",children:"Mais clientes"}),e.jsx("option",{value:"recente",children:"Mais recentes"})]})]}),C?e.jsx("div",{className:"flex h-32 items-center justify-center",children:e.jsx(z,{size:40})}):e.jsx("div",{className:"overflow-x-auto rounded-2xl glass-strong",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"border-b border-border text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3 text-left",children:"Revendedor"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Clientes"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Faturado (consumo)"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"Comissão gerada"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"A pagar"}),e.jsx("th",{className:"px-4 py-3 text-right",children:"%"})]})}),e.jsxs("tbody",{children:[n.map(a=>e.jsxs("tr",{onClick:()=>w(a.id),className:"cursor-pointer border-t border-border/50 hover:bg-accent/30",children:[e.jsx("td",{className:"px-4 py-2.5",children:e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:`inline-flex h-2 w-2 rounded-full ${a.active?"bg-success":"bg-muted-foreground/40"}`}),e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-foreground",children:a.company_name}),e.jsx("div",{className:"text-[11px] text-muted-foreground",children:a.email??a.phone??a.reseller_code??"—"})]})]})}),e.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums",children:[a.network_count,e.jsxs("span",{className:"ml-1 text-[10px] text-muted-foreground",children:["(",a.active_clients," ativos)"]})]}),e.jsx("td",{className:"px-4 py-2.5 text-right font-semibold tabular-nums",children:d(a.faturado_cents)}),e.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums text-amber-500",children:d(a.commission_earned_cents)}),e.jsx("td",{className:"px-4 py-2.5 text-right tabular-nums",children:d(a.commission_available_cents)}),e.jsxs("td",{className:"px-4 py-2.5 text-right tabular-nums text-muted-foreground",children:[a.commission_pct,"%"]})]},a.id)),!n.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:6,className:"px-4 py-10 text-center text-sm text-muted-foreground",children:"Nenhum revendedor encontrado."})})]})]})}),f&&e.jsx(ee,{resellerId:f,onClose:()=>w(null)})]})}function ee({resellerId:u,onClose:h}){const p=S(U),{data:r,isLoading:_}=q({queryKey:["admin","reseller-network",u],queryFn:()=>p({data:{reseller_id:u}})}),[g,k]=m.useState(""),[f,w]=m.useState("consumo"),[x,C]=m.useState(!1),o=r?.clients??[],n=m.useMemo(()=>({consumo:o.reduce((s,t)=>s+t.consumo_cents,0),recargas:o.reduce((s,t)=>s+t.recargas_cents,0),saldo:o.reduce((s,t)=>s+t.saldo_cents,0),comissao:o.reduce((s,t)=>s+t.commission_cents,0),consultas:o.reduce((s,t)=>s+t.consultas,0),ativos:o.filter(s=>s.active).length,total:o.length}),[o]),b=n.consultas>0?Math.round(n.consumo/n.consultas):0,j=m.useMemo(()=>{const s=g.trim().toLowerCase();return o.filter(t=>!x||t.active).filter(t=>!s||[t.company_name,t.phone].filter(Boolean).some(i=>String(i).toLowerCase().includes(s))).sort((t,i)=>{switch(f){case"comissao":return i.commission_cents-t.commission_cents;
2case"recargas":return i.recargas_cents-t.recargas_cents;case"recente":return new Date(i.created_at).getTime()-new Date(t.created_at).getTime();default:return i.consumo_cents-t.consumo_cents}})},[o,g,f,x]);async function a(){if(!r)return;const s=(await A(async()=>{const{default:c}=await import("./exceljs.min-hdmrRwxC.js").then(O=>O.e);return{default:c}},__vite__mapDeps([0,1]))).default,t=new s.Workbook,i=t.addWorksheet("Rede");i.columns=[{header:"Cliente",key:"nome",width:32},{header:"Telefone",key:"fone",width:16},{header:"Status",key:"status",width:10},{header:"Consultas",key:"consultas",width:11},{header:"Consumo (R$)",key:"consumo",width:15},{header:"Comissão (R$)",key:"comissao",width:15},{header:"Recargas (R$)",key:"recargas",width:15},{header:"Saldo (R$)",key:"saldo",width:13},{header:"Cadastro",key:"cadastro",width:14}],i.getRow(1).font={bold:!0};for(const c of j)i.addRow({nome:c.company_name,fone:c.phone??"",status:c.active?"Ativo":"Inativo",consultas:c.consultas,consumo:c.consumo_cents/100,comissao:c.commission_cents/100,recargas:c.recargas_cents/100,saldo:c.saldo_cents/100,cadastro:new Date(c.created_at).toLocaleDateString("pt-BR")});const R=await t.xlsx.writeBuffer(),l=new Blob([R],{type:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"});F(l,`rede-${(r.reseller.company_name||"revendedor").replace(/[^a-z0-9]+/gi,"-").toLowerCase()}.xlsx`),y.success("Rede exportada")}return e.jsx("div",{className:"fixed inset-0 z-[120] flex justify-end bg-black/60 backdrop-blur-sm",onClick:h,children:e.jsxs("div",{className:"flex h-full w-full max-w-2xl flex-col border-l border-border bg-popover shadow-elegant",onClick:s=>s.stopPropagation(),children:[e.jsxs("div",{className:"flex items-start justify-between gap-3 border-b border-border p-5 md:p-6",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"eyebrow text-muted-foreground",children:"Rede do revendedor"}),e.jsx("h3",{className:"truncate text-xl font-bold text-foreground",children:r?.reseller.company_name??"…"}),r&&e.jsxs("p",{className:"mt-0.5 flex flex-wrap items-center gap-x-2 text-xs text-muted-foreground",children:[e.jsxs("span",{children:["Comissão ",e.jsxs("strong",{className:"text-foreground",children:[r.reseller.commission_pct,"%"]})]}),e.jsxs("span",{children:["· código ",e.jsx("span",{className:"font-mono",children:r.reseller.reseller_code??"—"})]}),r.reseller.phone&&e.jsxs("span",{children:["· ",r.reseller.phone]})]})]}),e.jsxs("div",{className:"flex shrink-0 items-center gap-1.5",children:[e.jsxs("button",{onClick:a,disabled:!r,title:"Exportar rede em Excel",className:"inline-flex items-center gap-1.5 rounded-lg border border-emerald/40 px-2.5 py-1.5 text-xs font-semibold text-emerald transition-smooth hover:bg-emerald/10 disabled:opacity-50 dark:text-mint",children:[e.jsx(D,{className:"h-4 w-4"})," Excel"]}),e.jsx("button",{onClick:h,className:"rounded-lg p-2 text-muted-foreground hover:bg-muted",children:e.jsx(X,{className:"h-5 w-5"})})]})]}),e.jsx("div",{className:"flex-1 overflow-y-auto p-5 md:p-6",children:_||!r?e.jsx(Q,{}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 gap-2 sm:grid-cols-3",children:[e.jsx(v,{icon:e.jsx($,{className:"h-3.5 w-3.5"}),label:"Consumo (base comissão)",value:d(n.consumo),tone:"text-emerald dark:text-mint"}),e.jsx(v,{icon:e.jsx(L,{className:"h-3.5 w-3.5"}),label:"Comissão gerada",value:d(n.comissao),tone:"text-amber-500"}),e.jsx(v,{icon:e.jsx(E,{className:"h-3.5 w-3.5"}),label:"Consultas",value:String(n.consultas)}),e.jsx(v,{icon:e.jsx(G,{className:"h-3.5 w-3.5"}),label:"Clientes (ativos/total)",value:`${n.ativos}/${n.total}`}),e.jsx(v,{icon:e.jsx($,{className:"h-3.5 w-3.5"}),label:"Ticket médio",value:d(b)}),e.jsx(v,{icon:e.jsx(H,{className:"h-3.5 w-3.5"}),label:"Saldo em carteira",value:d(n.saldo)})]}),e.jsxs("p",{className:"mt-3 flex items-center gap-1.5 rounded-lg bg-muted/40 p-2 text-[11px] text-muted-foreground",children:[e.jsx(E,{className:"h-3.5 w-3.5 shrink-0"}),"O revendedor ganha comissão sobre o ",e.jsx("strong",{className:"text-foreground",children:"consumo"})," (consultas). Saldo e recargas são só contexto."]}),e.jsxs("div",{className:"mt-4 flex flex-col gap-2 sm:flex-row sm:items-center",children:[e.jsxs("div",{className:"relative flex-1",children:[e.jsx(T,{className:"pointer-events-none absolute left-2.5 top-1/2 h-3.5 w-3.5 -translate-y-1/2 text-muted-foreground"}),e.jsx("input",{value:g,onChange:s=>k(s.target.value),placeholder:"Buscar cliente...",className:"w-full rounded-lg border border-border bg-background py-2 pl-8 pr-3 text-sm text-foreground outline-none focus:border-primary"})]}),e.jsxs("select",{value:f,onChange:s=>w(s.target.value),className:"rounded-lg border border-border bg-background px-2 py-2 text-sm text-foreground",children:[e.jsx("option",{value:"consumo",children:"Maior consumo"}),e.jsx("option",{value:"comissao",children:"Maior comissão"}),e.jsx("option",{value:"recargas",children:"Maiores recargas"}),e.jsx("option",{value:"recente",children:"Mais recentes"})]}),e.jsx("button",{onClick:()=>C(s=>!s),className:`rounded-lg border px-3 py-2 text-xs font-semibold transition-smooth ${x?"border-emerald/50 bg-emerald/10 text-emerald dark:text-mint":"border-border bg-background text-muted-foreground hover:text-foreground"}`,children:"Só ativos"})]}),e.jsx("div",{className:"mt-3 overflow-x-auto rounded-xl border border-border",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"border-b border-border bg-muted/30 text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-3 py-2 text-left",children:"Cliente"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Consumo"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Comissão"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Recargas"}),e.jsx("th",{className:"px-3 py-2 text-right",children:"Saldo"})]})}),e.jsxs("tbody",{children:[j.map(s=>e.jsxs("tr",{className:"border-t border-border/50",children:[e.jsxs("td",{className:"px-3 py-2",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx("span",{className:`inline-flex h-1.5 w-1.5 rounded-full ${s.active?"bg-success":"bg-muted-foreground
2/40"}`}),e.jsx("span",{className:"font-medium text-foreground",children:s.company_name})]}),e.jsxs("div",{className:"text-[10px] text-muted-foreground",children:[s.consultas," consultas",s.phone?` · ${s.phone}`:""]})]}),e.jsx("td",{className:"px-3 py-2 text-right font-semibold tabular-nums",children:d(s.consumo_cents)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-amber-500",children:d(s.commission_cents)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-muted-foreground",children:d(s.recargas_cents)}),e.jsx("td",{className:"px-3 py-2 text-right tabular-nums text-muted-foreground",children:d(s.saldo_cents)})]},s.id)),!j.length&&e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"px-3 py-8 text-center text-sm text-muted-foreground",children:o.length?"Nenhum cliente no filtro.":"Esse revendedor ainda não tem clientes."})})]})]})}),e.jsxs("p",{className:"mt-2 text-[11px] text-muted-foreground",children:[j.length," de ",n.total," clientes"]})]})})]})})}function N({icon:u,label:h,value:p,tone:r}){return e.jsxs("div",{className:"rounded-2xl glass-strong p-4",children:[e.jsx("div",{className:"flex items-center gap-2 text-emerald dark:text-mint",children:u}),e.jsx("div",{className:`mt-2 text-xl font-bold tabular-nums ${r??"text-foreground"}`,children:p}),e.jsx("div",{className:"mt-0.5 text-[11px] text-muted-foreground",children:h})]})}function v({icon:u,label:h,value:p,tone:r}){return e.jsxs("div",{className:"rounded-xl border border-border/60 bg-[var(--surface-strong)] p-2.5",children:[e.jsx("div",{className:"flex items-center gap-1.5 text-muted-foreground",children:u}),e.jsx("div",{className:`mt-1 text-sm font-bold tabular-nums ${r??"text-foreground"}`,children:p}),e.jsx("div",{className:"text-[10px] text-muted-foreground",children:h})]})}export{le as component};

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.