1import{r as N,j as e}from"./react-vendor-BorBU4Bs.js";import{u as Te,a as ke,m as F,s as B,cg as ze,p as K,cE as De,aX as Be,bM as me,L as se,I as pe,B as Ee,bH as Le,K as w,M as $,ay as Ae,cF as qe,a$ as ge,bF as Oe,bb as Ie,an as W,ao as H,N as U,O as X,Q as m,U as g,V as Q,W as d,aZ as ae,a_ as oe,n as M,az as Ke,S as Ge,d as Ve,f as We,g as He,h as je,b3 as fe,ci as Ne,bV as Ue}from"./index-DkhxOMdR.js";import{a as L}from"./query-vendor-dlntIC_S.js";import{C as Xe}from"./checkbox-Dl2yzLyD.js";import{R as Qe,B as Ye,C as Ze,X as Je,Y as et,T as tt,d as st}from"./charts-vendor-BxJanGhU.js";import"./radix-vendor-CazrR58L.js";import"./supabase-vendor-BxTHC7hl.js";import"./xlsx-vendor-DOnNs5_d.js";import"./qr-vendor-Ca1-Dxvv.js";function R(p){const A=((p==null?void 0:p.tag)||"").toLowerCase(),q=((p==null?void 0:p.nome)||"").toUpperCase();return A==="pesadinha"||q.includes("PESADINHA")}function be(p){const A=Number((p==null?void 0:p.peso_entrada)||0),q=Number((p==null?void 0:p.peso_saida)||0);return A>0&&q>0?Math.abs(q-A):Number((p==null?void 0:p.peso_dosado)||0)}function ut(){const{isAutoRefreshEnabled:p}=Te(),{isMaster:A,userRole:q,allowedPages:_e}=ke(),de=F(new Date,"yyyy-MM-dd"),[S,ye]=N.useState(de),[v,Pe]=N.useState(de),[z,re]=N.useState("all"),[le,Se]=N.useState(!0),[ne,ve]=N.useState(!0),[Ce,we]=N.useState({}),[Y,$e]=N.useState(!0),O=A||q==="admin"||_e.includes("faturamento"),{data:Z=[]}=L({queryKey:["dashboard-clientes"],queryFn:async()=>{const{data:t,error:s}=await B.from("clientes").select("id, nome, logo_url").order("nome");if(s)throw s;return t},enabled:O}),{data:j=[],isLoading:Fe}=L({queryKey:["dashboard-pedidos",S,v],queryFn:async()=>{const{data:t,error:s}=await B.from("pedidos").select("*, clientes(nome), racoes(nome, tag, codigo, is_medicada), produtores(nome)").gte("data_producao",S).lte("data_producao",v).eq("cancelado",!1).order("data_producao",{ascending:!1});if(s)throw s;return t},refetchOnWindowFocus:p("dashboard")}),{data:ce=[]}=L({queryKey:["dashboard-all-pedidos",S,v],queryFn:async()=>{const{data:t,error:s}=await B.from("pedidos").select("id, data_producao, status_producao, cancelado, racoes(nome, tag)").gte("data_producao",S).lte("data_producao",v).order("data_producao",{ascending:!1});if(s)throw s;return t},refetchOnWindowFocus:p("dashboard")}),{data:I=[],isLoading:Me}=L({queryKey:["dashboard-ordens",S,v],queryFn:async()=>{const{data:t,error:s}=await B.from("ordens_carregamento").select("*, racoes(codigo, nome, tag, is_medicada), clientes(nome)").eq("status","finalizado").gte("data_hora",S+"T00:00:00").lte("data_hora",v+"T23:59:59").order("data_hora",{ascending:!1});if(s)throw s;return t},refetchOnWindowFocus:p("dashboard")}),J=N.useMemo(()=>j.map(t=>t.id).filter(Boolean),[j]),{data:ie={ticketPedidos:new Set,ocsPorPedido:{}}}=L({queryKey:["dashboard-silos-saida",J.sort().join(",")],enabled:J.length>0,queryFn:async()=>{const t=(o,l=100)=>{const a=[];for(let c=0;c<o.length;c+=l)a.push(o.slice(c,c+l));return a},s=new Set,n={};for(const o of t(J)){const[l,a]=await Promise.all([B.from("faturamento").select("pedido_id, ticket_pesagem").in("pedido_id",o).not("ticket_pesagem","is",null),B.from("ordens_carregamento").select("pedido_id, ticket_pesagem, status").in("pedido_id",o)]);(l.data||[]).forEach(c=>c.pedido_id&&s.add(c.pedido_id)),(a.data||[]).forEach(c=>{c.pedido_id&&(n[c.pedido_id]||(n[c.pedido_id]=[]),n[c.pedido_id].push({ticket:!!c.ticket_pesagem,finalizado:c.status==="finalizado"}))})}return{ticketPedidos:s,ocsPorPedido:n}},refetchOnWindowFocus:p("dashboard")}),{data:xe=[]}=L({queryKey:["dashboard-faturamento",S,v],queryFn:async()=>{const{data:t,error:s}=await B.from("faturamento").select("*, pedidos(cliente_id, data_producao, peso_solicitado, cancelado, status_producao, numero_grade, racoes(nome, tag))").order("created_at",{ascending:!1});if(s)throw s;return t},enabled:O}),i=N.useMemo(()=>{const t=j.filter(x=>!!x.racoes&&!R(x.racoes));I.filter(x=>!R(x.racoes));const s=t.length,n=x=>x==="finalizado"||x==="concluido",o=t.filter(x=>n(x.status_producao)).length,l=t.filter(x=>x.status_producao==="pendente").length,a=t.filter(x=>["em_producao","em_andamento"].includes(String(x.status_producao||""))).length,c=t.reduce((x,P)=>x+Number(P.peso_solicitado||0),0),u=j.filter(x=>!x.cancelado&&n(x.status_producao)).reduce((x,P)=>x+Number(P.peso_solicitado||0),0),D=I.filter(x=>!!x.pedido_id).reduce((x,P)=>x+(P.qtd_pedido!=null?Number(P.qtd_pedido):be(P)),0),{ticketPedidos:h,ocsPorPedido:y}=ie,k=j.filter(x=>{if(x.cancelado||!x.racoes||!n(x.status_producao)||!x.silo_expedicao_id||h.has(x.id))return!1;const P=y[x.id]||[];return!(P.length>0&&P.every(he=>he.ticket||he.finalizado))}),r=k.length,f=k.reduce((x,P)=>x+Number(P.peso_solicitado||0),0);return{totalPedidos:s,concluidos:o,pendentes:l,emProducao:a,pesoTotal:c,pesoProduzido:u,pesoConcluido:D,nosSilosCount:r,nosSilosPeso:f}},[j,I,ie]),E=N.useMemo(()=>
1{if(!O)return[];const t={};Z.forEach(a=>{t[a.id]={id:a.id,nome:a.nome,logo_url:a.logo_url,totalPedidos:0,pesoSolicitado:0,pesoCarregado:0,faturados:0,aFaturar:0}}),j.forEach(a=>{R(a.racoes)||t[a.cliente_id]&&(t[a.cliente_id].totalPedidos+=1,t[a.cliente_id].pesoSolicitado+=Number(a.peso_solicitado||0))}),I.forEach(a=>{R(a.racoes)||a.pedido_id&&t[a.cliente_id]&&(t[a.cliente_id].pesoCarregado+=be(a))});const s=ze(new Date,90),n=a=>(a!=null&&a.nf_venda?1:0)+(a!=null&&a.nf_retorno?1:0)+(a!=null&&a.peso_produzido?1:0)+(a!=null&&a.ticket_pesagem?1:0),o=new Map;xe.forEach(a=>{if(!(a!=null&&a.pedido_id))return;const c=o.get(a.pedido_id);(!c||n(a)>n(c))&&o.set(a.pedido_id,a)});const l=new Map;return I.forEach(a=>{a!=null&&a.pedido_id&&!l.has(a.pedido_id)&&l.set(a.pedido_id,a)}),j.forEach(a=>{if(a.cancelado||R(a.racoes))return;const c=a.cliente_id;if(!t[c])return;const u=String(a.status_producao||"").toLowerCase();if(!["em_andamento","em_producao","finalizado","concluido"].includes(u))return;const h=o.get(a.id),y=l.get(a.id),k=!!(h!=null&&h.peso_produzido||y!=null&&y.peso_dosado),r=!!(h!=null&&h.ticket_pesagem||y!=null&&y.ticket_pesagem);if(!!(h!=null&&h.nf_venda&&(h!=null&&h.nf_retorno)&&k&&r)){t[c].faturados+=1;return}if(String(a.num_grade||a.numero_grade||"").toLowerCase().startsWith("old"))return;const P=a.data_producao?new Date(a.data_producao+"T00:00:00"):null;P&&P<s||(t[c].aFaturar+=1)}),Object.values(t).filter(a=>a.totalPedidos>0||a.pesoCarregado>0||a.faturados>0||a.aFaturar>0).sort((a,c)=>c.pesoSolicitado-a.pesoSolicitado)},[O,Z,j,I,xe]),C=N.useMemo(()=>z==="all"?null:E.find(t=>t.id===z)||null,[z,E]),ee=N.useMemo(()=>z==="all"?[]:j.filter(t=>t.cliente_id===z&&!R(t.racoes)),[z,j]),G=N.useMemo(()=>j.map(t=>t.lote_producao?parseInt(t.lote_producao):null).filter(t=>!!t&&!isNaN(t)),[j]),{data:ue=[]}=L({queryKey:["dashboard-producoes-lotes",G.sort().join(",")],enabled:G.length>0,queryFn:async()=>{const t=[];for(let s=0;s<G.length;s+=100){const{data:n,error:o}=await B.from("producoes_externas").select("num_producao, total_realizado").in("num_producao",G.slice(s,s+100));if(o)throw o;t.push(...n||[])}return t},refetchOnWindowFocus:p("dashboard")}),{racaoMedicada:b,racaoNaoMedicada:_}=N.useMemo(()=>{const t={};ue.forEach(o=>{o.num_producao!=null&&(t[o.num_producao]=Number(o.total_realizado||0)*1e3)});const s={};j.forEach(o=>{var k,r,f;if(R(o.racoes)||o.cancelado)return;const l=((k=o.racoes)==null?void 0:k.nome)||"Sem ração";if(Y&&l==="Sem ração")return;const a=((r=o.racoes)==null?void 0:r.codigo)||"",c=((f=o.racoes)==null?void 0:f.is_medicada)||!1,u=o.lote_producao?parseInt(o.lote_producao):NaN,D=isNaN(u)?void 0:t[u],h=D&&D>0?D:Number(o.peso_solicitado||0);if(h<=0)return;const y=`${a}_${l}_${c}`;s[y]||(s[y]={codigo:a,nome:l,peso:0,count:0,medicada:c}),s[y].peso+=h,s[y].count+=1});const n=Object.values(s).sort((o,l)=>l.peso-o.peso);return{racaoMedicada:n.filter(o=>o.medicada),racaoNaoMedicada:n.filter(o=>!o.medicada)}},[j,ue,Y]),V=N.useMemo(()=>{if(!S||!v)return[];try{const t=K(S),s=K(v),n=De({start:t,end:s}),o={};return j.forEach(l=>{R(l.racoes)||l.data_producao&&(o[l.data_producao]=(o[l.data_producao]||0)+1)}),n.map(l=>{const a=F(l,"yyyy-MM-dd");return{dia:F(l,"dd/MM",{locale:Be}),pedidos:o[a]||0}})}catch{return[]}},[j,S,v]),T=N.useMemo(()=>{const t=ce.filter(u=>!R(u.racoes)),s=t.length;if(s===0)return{totalAll:0,cancelados:0,pctCancelados:"0.0",atrasados:0,pctAtrasados:"0.0",entregues:0,pctEntregues:"0.0"};const n=t.filter(u=>u.cancelado).length,o=F(new Date,"yyyy-MM-dd"),l=u=>u==="concluido"||u==="finalizado",a=t.filter(u=>!u.cancelado&&u.data_producao<o&&!l(u.status_producao)).length,c=t.filter(u=>!u.cancelado&&l(u.status_producao)).length;return{totalAll:s,cancelados:n,pctCancelados:(n/s*100).toFixed(1),atrasados:a,pctAtrasados:(a/s*100).toFixed(1),entregues:c,pctEntregues:(c/s*100).toFixed(1)}},[ce]),Re=()=>{const t=b.reduce((r,f)=>r+f.peso,0),s=_.reduce((r,f)=>r+f.peso,0),n=t+s,o=b.reduce((r,f)=>r+f.count,0),l=_.reduce((r,f)=>r+f.count,0),a=o+l,c=r=>r.toLocaleString("pt-BR",{maximumFractionDigits:0}),u=r=>
1(r/1e3).toLocaleString("pt-BR",{minimumFractionDigits:2,maximumFractionDigits:2}),D=E.map(r=>`<tr> 2 <td>${r.nome}</td> 3 <td class="text-right mono">${r.totalPedidos}</td> 4 <td class="text-right mono">${c(r.pesoSolicitado)}</td> 5 <td class="text-right mono">${c(r.pesoCarregado)}</td> 6 <td class="text-right mono">${u(r.pesoCarregado)}</td> 7 <td class="text-right mono">${r.faturados}</td> 8 <td class="text-right mono">${r.aFaturar}</td> 9 </tr>`).join(""),h=E.reduce((r,f)=>({totalPedidos:r.totalPedidos+f.totalPedidos,pesoSolicitado:r.pesoSolicitado+f.pesoSolicitado,pesoCarregado:r.pesoCarregado+f.pesoCarregado,faturados:r.faturados+f.faturados,aFaturar:r.aFaturar+f.aFaturar}),{totalPedidos:0,pesoSolicitado:0,pesoCarregado:0,faturados:0,aFaturar:0}),y=V.map(r=>`<tr><td>${r.dia}</td><td class="text-right mono">${r.pedidos}</td></tr>`).join(""),k=` 10 <h2>Resumo Geral</h2> 11 ${Ne([{label:"Total de Pedidos",value:i.totalPedidos},{label:"ConcluÃdos",value:i.concluidos},{label:"Peso Solicitado",value:`${u(i.pesoTotal)} t`},{label:"Peso Produzido",value:`${u(i.pesoProduzido)} t`},{label:"Peso Carregado",value:`${u(i.pesoConcluido)} t`},{label:"Î Produzido vs Solicitado",value:`${i.pesoTotal>0?((i.pesoProduzido-i.pesoTotal)/i.pesoTotal*100).toFixed(1):"0.0"}%`},{label:"Î Carregado vs Produzido",value:`${i.pesoProduzido>0?((i.pesoConcluido-i.pesoProduzido)/i.pesoProduzido*100).toFixed(1):"0.0"}%`},{label:"Produções nos silos s/ carregar",value:i.nosSilosCount},{label:"Peso nos silos s/ carregar",value:`${u(i.nosSilosPeso)} t`}])} 12 13 <h2>Indicadores de Desempenho</h2> 14 ${Ne([{label:`Rações Atrasadas (${T.atrasados} de ${T.totalAll})`,value:`${T.pctAtrasados}%`},{label:`Cancelamentos (${T.cancelados} de ${T.totalAll})`,value:`${T.pctCancelados}%`},{label:`Rações Entregues (${T.entregues} de ${T.totalAll})`,value:`${T.pctEntregues}%`}])} 15 16 <h2>Rações Não Medicadas</h2> 17 <table> 18 <thead><tr><th>Ração</th><th class="text-right">Produções</th><th class="text-right">Peso (kg)</th><th class="text-right">Toneladas</th></tr></thead> 19 <tbody> 20 ${_.map(r=>`<tr><td>${r.codigo?`<span class="mono" style="color:#64748b;font-size:8.5px;margin-right:6px">${r.codigo}</span>`:""}${r.nome}</td><td class="text-right mono">${r.count}</td><td class="text-right mono">${r.peso.toLocaleString("pt-BR")}</td><td class="text-right mono">${(r.peso/1e3).toFixed(2)}</td></tr>`).join("")} 21 <tr class="total-row"><td>Total Não Medicada</td><td class="text-right">${l}</td><td class="text-right">${s.toLocaleString("pt-BR")}</td><td class="text-right">${(s/1e3).toFixed(2)}</td></tr> 22 </tbody> 23 </table> 24 25 <h2>Rações Medicadas</h2> 26 <table> 27 <thead><tr><th>Ração</th><th class="text-right">Produções</th><th class="text-right">Peso (kg)</th><th class="text-right">Toneladas</th></tr></thead> 28 <tbody> 29 ${b.map(r=>`<tr><td>${r.codigo?`<span class="mono" style="color:#64748b;font-size:8.5px;margin-right:6px">${r.codigo}</span>`:""}${r.nome}</td><td class="text-right mono">${r.count}</td><td class="text-right mono">${r.peso.toLocaleString("pt-BR")}</td><td class="text-right mono">${(r.peso/1e3).toFixed(2)}</td></tr>`).join("")} 30 <tr class="total-row"><td>Total Medicada</td><td class="text-right">${o}</td><td class="text-right">${t.toLocaleString("pt-BR")}</td><td class="text-right">${(t/1e3).toFixed(2)}</td></tr> 31 </tbody> 32 </table> 33 34 <h2>Total Geral</h2> 35 <table> 36 <thead><tr><th>Categoria</th><th class="text-right">Produções</th><th class="text-right">Peso (kg)</th><th class="text-right">Toneladas</th></tr></thead> 37 <tbody> 38 <tr><td>Não Medicada</td><td class="text-right mono">${l}</td><td class="text-right mono">${s.toLocaleString("pt-BR")}</td><td class="text-right mono">${(s/1e3).toFixed(2)}</td></tr> 39 <tr><td>Medicada</td><td class="text-right mono">${o}</td><td class="text-right mono">${t.toLocaleString("pt-BR")}</td><td class="text-right mono">${(t/1e3).toFixed(2)}</td></tr> 40 <tr class="total-row"><td>Total Geral</td><td class="text-right">${a}</td><td class="text-right">
40${n.toLocaleString("pt-BR")}</td><td class="text-right">${(n/1e3).toFixed(2)}</td></tr> 41 </tbody> 42 </table> 43 44 ${O&&E.length?` 45 <h2>Produção por Cliente</h2> 46 <table> 47 <thead> 48 <tr> 49 <th>Cliente</th> 50 <th class="text-right">Pedidos</th> 51 <th class="text-right">Solicitado (kg)</th> 52 <th class="text-right">Carregado (kg)</th> 53 <th class="text-right">Ton</th> 54 <th class="text-right">Faturados</th> 55 <th class="text-right">A Faturar</th> 56 </tr> 57 </thead> 58 <tbody> 59 ${D} 60 <tr class="total-row"> 61 <td>Total</td> 62 <td class="text-right">${h.totalPedidos}</td> 63 <td class="text-right">${c(h.pesoSolicitado)}</td> 64 <td class="text-right">${c(h.pesoCarregado)}</td> 65 <td class="text-right">${u(h.pesoCarregado)}</td> 66 <td class="text-right">${h.faturados}</td> 67 <td class="text-right">${h.aFaturar}</td> 68 </tr> 69 </tbody> 70 </table>`:""} 71 72 ${V.length?` 73 <h2>Pedidos por Dia</h2> 74 <table class="compact"> 75 <thead><tr><th>Dia</th><th class="text-right">Pedidos</th></tr></thead> 76 <tbody>${y}</tbody> 77 </table>`:""} 78 `;Ue({title:"Relatório de Produção por PerÃodo",subtitle:`De ${F(K(S),"dd/MM/yyyy")} a ${F(K(v),"dd/MM/yyyy")}`,fileName:`Relatório de Produção por PerÃodo de ${F(K(S),"dd/MM/yyyy")} a ${F(K(v),"dd/MM/yyyy")}`,documentCode:"DASHBOARD",headerVariant:"laudo",orientation:"portrait",content:k})},te=Fe||Me;return e.jsxs("div",{className:"animate-fade-in",children:[e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 mb-6",children:[e.jsx("div",{className:"flex h-12 w-12 items-center justify-center rounded-xl bg-primary/20 text-primary",children:e.jsx(me,{className:"h-6 w-6"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:"Dashboard"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Visão geral de pedidos e produção"})]}),e.jsxs("div",{className:"flex items-end gap-3 mb-6 flex-wrap",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(se,{className:"text-xs",children:"De"}),e.jsx(pe,{type:"date",value:S,onChange:t=>ye(t.target.value),className:"w-40"})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(se,{className:"text-xs",children:"Até"}),e.jsx(pe,{type:"date",value:v,onChange:t=>Pe(t.target.value),className:"w-40"})]}),e.jsxs("div",{className:"flex items-center gap-2 pb-2",children:[e.jsx(Xe,{id:"excluir-sem-racao",checked:Y,onCheckedChange:t=>$e(!!t)}),e.jsx(se,{htmlFor:"excluir-sem-racao",className:"text-xs cursor-pointer",children:'Excluir "Sem ração"'})]}),e.jsxs(Ee,{variant:"outline",size:"sm",onClick:Re,children:[e.jsx(Le,{className:"h-4 w-4 mr-1"})," Relatório PDF"]})]}),i.nosSilosPeso>0&&e.jsx(w,{className:"mb-6 border-amber-500/50 bg-amber-500/10 dark:bg-amber-500/10",children:e.jsx($,{className:"pt-5 pb-5",children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsx("div",{className:"flex h-14 w-14 items-center justify-center rounded-2xl bg-amber-500 text-white shadow-lg",children:e.jsx(Ae,{className:"h-7 w-7"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium text-amber-700 dark:text-amber-300",children:"Aguardando carregamento"}),e.jsxs("p",{className:"text-4xl font-extrabold tracking-tight text-foreground",children:[(i.nosSilosPeso/1e3).toFixed(1),e.jsx("span",{className:"text-lg font-semibold text-muted-foreground ml-1",children:"TON"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[i.nosSilosCount," ",i.nosSilosCount===1?"produção":"produções"," ainda nos silos"]})]})]}),e.jsxs("div",{className:"flex flex-col gap-1 min-w-[180px]",children:[e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Carregado"}),e.jsxs("span",{children:[(i.pesoConcluido/1e3).toFixed(1)," t"]})]}),e.jsx("div",{className:"h-3 w-full rounded-full bg-background overflow-hidden border",children:e.jsx("div",{className:"h-full bg-amber-500 transition-all",style:{width:`${i.pesoProduzido>0?Math.min(100,i.nosSilosPeso/i.pesoProduzido*100):0}%`}})}),e.jsxs("div",{className:"flex justify-between text-xs text-muted-foreground",children:[e.jsx("span",{children:"Produzido"}),e.jsxs("span",{children:[(i.pesoProduzido/1e3).toFixed(1)," t"]})]})]})]})})}),e.jsxs("div",{className:"grid grid-cols-2 md:grid-cols-6 gap-4 mb-6",children:[e.jsx(w,{children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-primary/10",children:e.jsx(qe,{className:"h-5 w-5 text-primary"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.totalPedidos}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Total Pedidos"})]})]})}),e.jsx(w,{children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-emerald-500/10",children:e.jsx(ge,{className:"h-5 w-5 text-emerald-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.concluidos}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"ConcluÃdos"})]})]})}),e.jsx(w,{children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-amber-500/10",children:e.jsx(me,{className:"h-5 w-5 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:i.pendentes+i.emProducao}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Em andamento"})]})]})}),e.jsx(w,{children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-muted",children:e.jsx(Oe,{className:"h-5 w-5 text-muted-foreground"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:(i.pesoConcluido/1e3).toFixed(1)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ton. Carregadas"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:i.pesoProduzido>0?`${((i.pesoConcluido-i.pesoProduzido)/i.pesoProduzido*100).toFixed(1)}% vs produzido`:"â"})]})]})}),e.jsx(w,{children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-blue-500/10",children:e.jsx(ge,{className:"h-5 w-5 text-blue-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:(i.pesoProduzido/1e3).toFixed(1)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ton. Produzidas"}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:i.pesoTotal>0?`${((i.pesoProduzido-i.pesoTotal)/i.pesoTotal*100).toFixed(1)}% vs solicitado`:"â"})]})]})}),e.jsx(w,{className:"border-amber-500/40 bg-amber-500/5 dark:bg-amber-500/5 ring-1 ring-amber-500/20",children:e.jsxs($,{className:"pt-4 flex items-center gap-3",children:[e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-amber-500/20",children:e.jsx(Ie,{className:"h-5 w-5 text-amber-600"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-2xl font-bold",children:(i.nosSilosPeso/1e3).toFixed(1)}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Ton. a carregar (",i.nosSilosCount," prod.)"]})]})]})})]}),e.jsxs(w,{className:"mb-6",children:[e.jsx(W,{children:e.jsx(H,{className:"text-base",children:"Pedidos ConcluÃdos por Dia"})}),e.jsx($,{children:V.length>0?e.jsx(Qe,{width:"100%",height:300,children:e.jsxs(Ye,{data:V,children:[e.jsx(Ze,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(Je,{dataKey:"dia",className:"text-xs",tick:{fontSize:11}}),e.jsx(et,{allowDecimals:!1,tick:{fontSize:11}}),e.jsx(tt,{contentStyle:{borderRadius:"8px",fontSize:"12px"},labelFormatter:t=>`Dia: ${t}`,formatter:t=>[`${t}`,"Pedidos"]}),e.jsx(st,{dataKey:"pedidos",fill:"hsl(var(--primary))",radius:[4,4,0,0]})]})}):e.jsx("p",{className:"text-center text-muted-foreground py-8",children:"Nenhum dado no perÃodo"})})]}),e.jsxs(w,{className:"mb-6",children:[e.jsx(W,{children:e.jsx(H,{className:"text-base",children:"Rações"})}),e.jsx($,{className:"p-0",children:e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(m,{className:"table-header",children:[e.jsx(g,{children:"Ração"}),e.jsx(g,{className:"text-right",children:"Produções"}),e.jsx(g,{className:"text-right",children:"Peso Total (kg)"}),e.jsx(g,{className:"text-right",children:"Toneladas"})]})}),e.jsxs(Q,{children:[e.jsx(m,{className:"bg-muted/40 cursor-pointer hover:bg-muted/60",onClick:()=>Se(t=>!t),children:e.jsx(d,{colSpan:4,className:"font-semibold",children:e.jsxs("div",{className:"flex items-center gap-2",children:[le?e.jsx(ae,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"}),"Rações Não Medicadas",e.jsx(M,{variant:"secondary",className:"ml-2 text-[10px]",children:_.length}),e.jsxs("span",{className:"ml-auto text-xs text-muted-foreground font-normal",children:[_.reduce((t,s)=>t+s.count,0)," produções · ",_.reduce((t,s)=>
78t+s.peso,0).toLocaleString("pt-BR")," kg · ",(_.reduce((t,s)=>t+s.peso,0)/1e3).toFixed(2)," t"]})]})})}),le&&(te?e.jsx(m,{children:e.jsx(d,{colSpan:4,className:"text-center text-muted-foreground",children:"Carregando..."})}):_.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:4,className:"text-center text-muted-foreground",children:"Nenhum dado no perÃodo"})}):e.jsxs(e.Fragment,{children:[_.map(t=>e.jsxs(m,{children:[e.jsxs(d,{className:"font-medium pl-8",children:[t.codigo&&e.jsx("span",{className:"text-muted-foreground font-mono text-xs mr-2",children:t.codigo}),t.nome]}),e.jsx(d,{className:"text-right",children:t.count}),e.jsx(d,{className:"text-right",children:t.peso.toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:(t.peso/1e3).toFixed(2)})]},`nm-${t.codigo}-${t.nome}`)),e.jsxs(m,{className:"bg-muted/30 font-semibold",children:[e.jsx(d,{className:"pl-8",children:"Subtotal Não Medicadas"}),e.jsx(d,{className:"text-right",children:_.reduce((t,s)=>t+s.count,0)}),e.jsx(d,{className:"text-right",children:_.reduce((t,s)=>t+s.peso,0).toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:(_.reduce((t,s)=>t+s.peso,0)/1e3).toFixed(2)})]})]})),e.jsx(m,{className:"bg-muted/40 cursor-pointer hover:bg-muted/60",onClick:()=>ve(t=>!t),children:e.jsx(d,{colSpan:4,className:"font-semibold",children:e.jsxs("div",{className:"flex items-center gap-2",children:[ne?e.jsx(ae,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"}),"Rações Medicadas",e.jsx(M,{variant:"destructive",className:"text-[10px]",children:"Medicada"}),e.jsx(M,{variant:"secondary",className:"text-[10px]",children:b.length}),e.jsxs("span",{className:"ml-auto text-xs text-muted-foreground font-normal",children:[b.reduce((t,s)=>t+s.count,0)," produções · ",b.reduce((t,s)=>t+s.peso,0).toLocaleString("pt-BR")," kg · ",(b.reduce((t,s)=>t+s.peso,0)/1e3).toFixed(2)," t"]})]})})}),ne&&(te?e.jsx(m,{children:e.jsx(d,{colSpan:4,className:"text-center text-muted-foreground",children:"Carregando..."})}):b.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:4,className:"text-center text-muted-foreground",children:"Nenhum dado no perÃodo"})}):e.jsxs(e.Fragment,{children:[b.map(t=>e.jsxs(m,{children:[e.jsxs(d,{className:"font-medium pl-8",children:[t.codigo&&e.jsx("span",{className:"text-muted-foreground font-mono text-xs mr-2",children:t.codigo}),t.nome]}),e.jsx(d,{className:"text-right",children:t.count}),e.jsx(d,{className:"text-right",children:t.peso.toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:(t.peso/1e3).toFixed(2)})]},`m-${t.codigo}-${t.nome}`)),e.jsxs(m,{className:"bg-muted/30 font-semibold",children:[e.jsx(d,{className:"pl-8",children:"Subtotal Medicadas"}),e.jsx(d,{className:"text-right",children:b.reduce((t,s)=>t+s.count,0)}),e.jsx(d,{className:"text-right",children:b.reduce((t,s)=>t+s.peso,0).toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:(b.reduce((t,s)=>t+s.peso,0)/1e3).toFixed(2)})]})]})),(_.length>0||b.length>0)&&e.jsxs(m,{className:"bg-muted/70 font-bold",children:[e.jsx(d,{children:"Total Geral"}),e.jsx(d,{className:"text-right",children:_.reduce((t,s)=>t+s.count,0)+b.reduce((t,s)=>t+s.count,0)}),e.jsx(d,{className:"text-right",children:(_.reduce((t,s)=>t+s.peso,0)+b.reduce((t,s)=>t+s.peso,0)).toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:((_.reduce((t,s)=>t+s.peso,0)+b.reduce((t,s)=>t+s.peso,0))/1e3).toFixed(2)})]})]})]})})]}),O&&e.jsxs(w,{className:"mb-6",children:[e.jsx(W,{children:e.jsxs("div",{className:"flex items-center justify-between flex-wrap gap-3",children:[e.jsxs(H,{
78className:"text-base flex items-center gap-2",children:[e.jsx(Ke,{className:"h-4 w-4"})," Dashboard por Cliente"]}),e.jsxs(Ge,{value:z,onValueChange:re,children:[e.jsx(Ve,{className:"w-60",children:e.jsx(We,{placeholder:"Selecione um cliente"})}),e.jsxs(He,{children:[e.jsx(je,{value:"all",children:"Todos os Clientes"}),Z.map(t=>e.jsx(je,{value:t.id,children:t.nome},t.id))]})]})]})}),e.jsx($,{children:z==="all"?e.jsx("div",{className:"overflow-x-auto",children:e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(m,{className:"table-header",children:[e.jsx(g,{children:"Cliente"}),e.jsx(g,{className:"text-right",children:"Pedidos"}),e.jsx(g,{className:"text-right",children:"Peso Solic. (kg)"}),e.jsx(g,{className:"text-right",children:"Peso Carregado (kg)"}),e.jsx(g,{className:"text-right",children:"Faturados"}),e.jsx(g,{className:"text-right",children:"A Faturar"})]})}),e.jsx(Q,{children:E.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:6,className:"text-center text-muted-foreground",children:"Nenhum dado no perÃodo"})}):E.map(t=>e.jsxs(m,{className:"cursor-pointer hover:bg-muted/50",onClick:()=>re(t.id),children:[e.jsx(d,{children:e.jsxs("div",{className:"flex items-center gap-2",children:[t.logo_url?e.jsx(fe,{src:t.logo_url,alt:"",className:"h-6 w-6 object-contain rounded"}):null,e.jsx("span",{className:"font-medium",children:t.nome})]})}),e.jsx(d,{className:"text-right",children:t.totalPedidos}),e.jsx(d,{className:"text-right",children:t.pesoSolicitado.toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:t.pesoCarregado.toLocaleString("pt-BR")}),e.jsx(d,{className:"text-right",children:e.jsx(M,{variant:"default",children:t.faturados})}),e.jsx(d,{className:"text-right",children:e.jsx(M,{variant:"secondary",children:t.aFaturar})})]},t.id))})]})}):C?e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3 pb-3 border-b",children:[C.logo_url&&e.jsx(fe,{src:C.logo_url,alt:"",className:"h-10 w-10 object-contain rounded"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold",children:C.nome}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Detalhes no perÃodo selecionado"})]})]}),C.totalPedidos===0&&ee.length===0?e.jsxs("div",{className:"rounded-lg border border-dashed p-8 text-center",children:[e.jsx("p",{className:"font-semibold",children:"Cliente sem produção"}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Nenhuma produção registrada para ",C.nome," no perÃodo selecionado."]})]}):e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:[e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold",children:C.totalPedidos}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Pedidos"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold",children:(C.pesoSolicitado/1e3).toFixed(1)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ton. Solicitadas"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsx("p",{className:"text-xl font-bold",children:(C.pesoCarregado/1e3).toFixed(1)}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ton. Carregadas"})]}),e.jsxs("div",{className:"bg-muted/50 rounded-lg p-3 text-center",children:[e.jsxs("p",{className:"text-xl font-bold",children:[C.faturados," / ",C.aFaturar]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Faturados / A Faturar"})]})]}),e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(m,{className:"table-header",children:[e.jsx(g,{children:"Nº"}),e.jsx(g,{children:"Produtor"}),e.jsx(g,{children:"Ração"}),e.jsx(g,{children:"Data Produção"}),e.jsx(g,{className:"text-right",children:"Peso (kg)"}),e.jsx(g,{children:"Status"})]})}),e.jsx(Q,{children:ee.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:6,className:"text-center text-muted-foreground",children:"Nenhum pedido"})}):ee.map(t=>{var s,n;return e.jsxs(m,{children:[e.jsxs(d,{className:"font-mono font-bold",children:["#",t.numero]}),e.jsx(d,{children:((s=t.produtores)==null?void 0:s.nome)||"â"}),e.jsx(d,{children:((n=t.racoes)==null?void 0:n.nome)||"â"}),e.jsx(d,{children:t.data_producao?F(new Date(t.data_producao+"T00:00:00"),"dd/MM/yyyy"):"â"}),e.jsx(d,{className:"text-right",children:Number(t.peso_solicitado).toLocaleStr
78ing("pt-BR")}),e.jsx(d,{children:e.jsx(M,{variant:t.status_producao==="concluido"?"default":t.status_producao==="em_producao"?"secondary":"outline",children:t.status_producao==="concluido"?"ConcluÃdo":t.status_producao==="em_producao"?"Em Produção":"Pendente"})})]},t.id)})})]})]})]}):null})]}),e.jsxs(w,{children:[e.jsx(W,{children:e.jsx(H,{className:"text-base",children:"Pedidos no PerÃodo"})}),e.jsx($,{className:"p-0",children:e.jsxs(U,{children:[e.jsx(X,{children:e.jsxs(m,{className:"table-header",children:[e.jsx(g,{children:"Ração / Nº"}),e.jsx(g,{children:"Cliente"}),e.jsx(g,{children:"Produtor"}),e.jsx(g,{children:"Data Produção"}),e.jsx(g,{className:"text-right",children:"Peso (kg)"}),e.jsx(g,{children:"Status"})]})}),e.jsx(Q,{children:te?e.jsx(m,{children:e.jsx(d,{colSpan:6,className:"text-center text-muted-foreground",children:"Carregando..."})}):j.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:6,className:"text-center text-muted-foreground",children:"Nenhum pedido no perÃodo"})}):(()=>{const t={};j.filter(n=>!R(n.racoes)).forEach(n=>{var a,c;const o=((a=n.racoes)==null?void 0:a.nome)||"â",l=((c=n.racoes)==null?void 0:c.is_medicada)||!1;t[o]||(t[o]={nome:o,medicada:l,pedidos:[],pesoTotal:0}),t[o].pedidos.push(n),t[o].pesoTotal+=Number(n.peso_solicitado)||0});const s=Object.values(t).sort((n,o)=>o.pesoTotal-n.pesoTotal);return s.length===0?e.jsx(m,{children:e.jsx(d,{colSpan:6,className:"text-center text-muted-foreground",children:"Nenhum pedido no perÃodo"})}):s.map(n=>{const o=!!Ce[n.nome];return e.jsxs(N.Fragment,{children:[e.jsx(m,{className:"bg-muted/40 cursor-pointer hover:bg-muted/60",onClick:()=>we(l=>({...l,[n.nome]:!l[n.nome]})),children:e.jsx(d,{colSpan:6,className:"font-semibold",children:e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[o?e.jsx(ae,{className:"h-4 w-4"}):e.jsx(oe,{className:"h-4 w-4"}),e.jsx("span",{children:n.nome}),n.medicada?e.jsx(M,{variant:"destructive",className:"text-[10px]",children:"Medicada"}):e.jsx(M,{variant:"secondary",className:"text-[10px]",children:"Normal"}),e.jsxs(M,{variant:"outline",className:"text-[10px]",children:[n.pedidos.length," pedidos"]}),e.jsxs("span",{className:"ml-auto text-xs text-muted-foreground font-normal",children:[n.pesoTotal.toLocaleString("pt-BR")," kg · ",(n.pesoTotal/1e3).toFixed(2)," t"]})]})})}),o&&n.pedidos.map(l=>{var a,c;return e.jsxs(m,{children:[e.jsxs(d,{className:"font-mono font-bold pl-8",children:["#",l.numero]}),e.jsx(d,{children:((a=l.clientes)==null?void 0:a.nome)||"â"}),e.jsx(d,{children:((c=l.produtores)==null?void 0:c.nome)||"â"}),e.jsx(d,{children:l.data_producao?F(new Date(l.data_producao+"T00:00:00"),"dd/MM/yyyy"):"â"}),e.jsx(d,{className:"text-right",children:Number(l.peso_solicitado).toLocaleString("pt-BR")}),e.jsx(d,{children:e.jsx(M,{variant:l.status_producao==="concluido"?"default":l.status_producao==="em_producao"?"secondary":"outline",children:l.status_producao==="concluido"?"ConcluÃdo":l.status_producao==="em_producao"?"Em Produção":"Pendente"})})]},l.id)})]},n.nome)})})()})]})})]})]})}export{ut 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.