1import{u as k,r as i,j as e}from"./react-vendor-BorBU4Bs.js";import{u as q,a as K,b as U}from"./query-vendor-dlntIC_S.js";import{b as V,B as x,A as z,bt as A,K as B,an as E,ao as Q,aP as F,n as H,M as L,ba as M,N as G,O as J,Q as y,U as t,V as W,W as n,m as X,p as $,D as Y,i as Z,j as ee,k as se,L as C,I as P,J as ae,s as R,aX as te}from"./index-DkhxOMdR.js";import{N as w}from"./NfPdfUpload-DE5CIlhN.js";import"./radix-vendor-CazrR58L.js";import"./charts-vendor-BxJanGhU.js";import"./supabase-vendor-BxTHC7hl.js";import"./xlsx-vendor-DOnNs5_d.js";import"./qr-vendor-Ca1-Dxvv.js";function ue(){const S=k(),{toast:d}=V(),h=q(),[a,c]=i.useState(null),[m,j]=i.useState(""),[o,N]=i.useState(""),[p,g]=i.useState(null),[v,b]=i.useState(null),{data:u=[],isLoading:T}=K({queryKey:["ordens_recebimento_nf_pendente"],queryFn:async()=>{const{data:s,error:l}=await R.from("ordens_recebimento").select("id, numero_ordem, tipo, subtipo, cliente, produto, fabricante, placa, nf, nf_remessa, nf_pdf_url, nf_remessa_pdf_url, created_at, status").order("created_at",{ascending:!1});if(l)throw l;return s.filter(r=>{if(r.subtipo==="transito_produtor")return!1;const O=!r.nf||String(r.nf).trim()==="",_=!r.nf_remessa||String(r.nf_remessa).trim()==="";return(r.tipo==="granel"||O)&&_})},refetchInterval:3e4}),f=U({mutationFn:async s=>{const{error:l}=await R.from("ordens_recebimento").update({nf:s.nf,nf_remessa:s.nfRemessa,nf_pdf_url:s.nfPdfUrl,nf_remessa_pdf_url:s.nfRemessaPdfUrl}).eq("id",s.id);if(l)throw l},onSuccess:()=>{h.invalidateQueries({queryKey:["ordens_recebimento_nf_pendente"]}),h.invalidateQueries({queryKey:["ordens_recebimento"]}),d({title:"NF atualizada com sucesso!"}),c(null)},onError:s=>d({title:"Erro ao atualizar NF",description:s.message,variant:"destructive"})}),I=s=>{c(s),j(s.nf||""),N(s.nf_remessa||""),g(s.nf_pdf_url||null),b(s.nf_remessa_pdf_url||null)},D=()=>{if(!a)return;const s=a.tipo==="granel";if(s&&!o.trim()){d({title:"Informe a NF de Remessa",variant:"destructive"});return}if(!s&&!m.trim()&&!o.trim()){d({title:"Informe ao menos uma NF (Fabricante ou Remessa)",variant:"destructive"});return}f.mutate({id:a.id,nf:m.trim()||null,nfRemessa:o.trim()||null,nfPdfUrl:p,nfRemessaPdfUrl:v})};return e.jsxs("div",{className:"container max-w-6xl mx-auto p-4 space-y-4",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs(x,{variant:"ghost",size:"sm",onClick:()=>S("/balanca"),children:[e.jsx(z,{className:"h-4 w-4 mr-1"})," Voltar"]}),e.jsx("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-warning/20 text-warning",children:e.jsx(A,{className:"h-5 w-5"})}),e.jsxs("div",{children:[e.jsx("h1",{className:"text-xl font-bold text-foreground",children:"NFs Pendentes"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ordens de recebimento aguardando inserção da nota fiscal"})]})]}),e.jsxs(B,{children:[e.jsx(E,{className:"pb-3",children:e.jsxs(Q,{className:"text-base flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4"})," Aguardando NF",e.jsx(H,{variant:"secondary",className:"ml-auto",children:u.length})]})}),e.jsx(L,{children:T?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-8",children:"Carregando..."}):u.length===0?e.jsxs("div",{className:"flex flex-col items-center text-center gap-2 py-8 text-muted-foreground",children:[e.jsx(M,{className:"h-10 w-10 text-success"}),e.jsx("p",{className:"text-sm",children:"Nenhuma ordem com NF pendente."})]}):e.jsx("div",{className:"overflow-auto",children:e.jsxs(G,{children:[e.jsx(J,{children:e.jsxs(y,{children:[e.jsx(t,{className:"text-xs",children:"Ordem"}),e.jsx(t,{className:"text-xs",children:"Data"}),e.jsx(t,{className:"text-xs",children:"Tipo"}),e.jsx(t,{className:"text-xs",children:"Cliente"}),e.jsx(t,{className:"text-xs",children:"Produto"}),e.jsx(t,{className:"text-xs",children:"Fornecedor"}),e.jsx(t,{className:"text-xs",children:"Placa"}),e.jsx(t,{className:"text-xs text-right",children:"Ações"})]})}),e.jsx(W,{children:u.map(s=>e.jsxs(y,{children:[e.jsxs(n,{className:"font-mono text-xs",children:["OR-",String(s.numero_ordem).padStart(4,"0")]}),e.jsx(n,{className:"text-xs",children:s.created_at?X($(s.created_at),"dd/MM/yyyy",{locale:te}):"â"}),e.jsxs(n,{className:"text-xs capitalize",children:[s.tipo||"â",s.subtipo?` / ${s.subtipo}`:""]}),e.jsx(n,{className:"text-xs",children:s.cliente||"â"}),e.jsx(n,{className:"text-xs",children:s.produto||"â"}),e.jsx(n,{className:"text-xs",children:s.fabricante||"â"}),e.jsx(n,{className:"text-xs",children:s.placa||"â"}),e.jsx(n,{className:"text-right",children:e.jsxs(x,{size:"sm",variant:"outline",className:"h-7 text-xs",onClick:()=>I(s),children:[e.jsx(F,{className:"h-3 w-3 mr-1"})," Inserir NF"]})})]},s.id))})]})})})]}),e.jsx(Y,{open:!!a,onOpenChange:s=>!s&&c(null),children:e.jsxs(Z,{className:"max-w-lg",children:[e.jsx(ee,{children:e.jsxs(se,{children:["Inserir NF â OR-",a?String(a.numero_ordem).padStart(4,"0"):""]})}),a&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"rounded-md bg-muted/40 p-3 text-xs space-y-1",children:[e.jsxs("div",{children:[e.jsx("strong",{children:"Cliente:"})," ",a.cliente||"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Produto:"})," ",a.produto||"â"]}
1),e.jsxs("div",{children:[e.jsx("strong",{children:"Fornecedor:"})," ",a.fabricante||"â"]}),e.jsxs("div",{children:[e.jsx("strong",{children:"Placa:"})," ",a.placa||"â"]})]}),a.tipo!=="granel"&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(C,{className:"text-sm",children:"NF Fabricante"}),e.jsx(P,{value:m,onChange:s=>j(s.target.value),placeholder:"Número da NF do Fabricante"}),e.jsx(w,{label:"PDF NF Fabricante",value:p,onChange:g,ordemId:a.id,fieldKey:"nf_fabricante"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsxs(C,{className:"text-sm",children:["NF Remessa ",a.tipo==="granel"&&e.jsx("span",{className:"text-destructive",children:"*"})]}),e.jsx(P,{value:o,onChange:s=>N(s.target.value),placeholder:"Número da NF de Remessa"}),e.jsx(w,{label:"PDF NF Remessa",value:v,onChange:b,ordemId:a.id,fieldKey:"nf_remessa"})]})]}),e.jsxs(ae,{children:[e.jsx(x,{variant:"outline",onClick:()=>c(null),children:"Cancelar"}),e.jsx(x,{onClick:D,disabled:f.isPending,children:f.isPending?"Salvando...":"Salvar NF"})]})]})})]})}export{ue 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.