1import{r as S,j as e}from"./vendor-react-DIA7vK4g.js";import{b6 as B,b7 as j,bb as b,bd as g,be as _,q as F,bF as m,bg as f,bY as p,bZ as y,b_ as d,b$ as s,c0 as N,c1 as o,cv as T,bm as D,bG as K,aY as O,bH as Q,ba as C}from"./index-DtUVjOr4.js";import{F as A}from"./FinanceiroLayout-BFNsfPwP.js";import{N as H}from"./NovaDataBoletoDialog-CEiTcsSQ.js";import{c as v}from"./billing-formatters-uNs-HNzw.js";import{U as E}from"./user-cog-DR9BkO8a.js";import"./vendor-docs-BA9xu9ak.js";import"./vendor-utils-DWHjTIse.js";import"./vendor-supabase-_bOAMmkC.js";import"./useSandboxConfig-H_pzAYpM.js";import"./GlobalSearch-CILhhYPj.js";import"./command-8X5Fvwln.js";import"./repeat-sulmqLMn.js";import"./corner-down-left-BYgMx1Bm.js";import"./clock-x8uDBefL.js";import"./edge-function-error-Bg1_3hCh.js";function P(){return new Date().toISOString().slice(0,10)}function ae(){const l=B(),[u,c]=S.useState(null),{data:r,isLoading:q}=j({queryKey:["boletos-aguardando-data"],queryFn:async()=>{const{data:a,error:t}=await C.from("invoices").select("id, invoice_number, customer_id, due_date, total_amount, status, boleto_error, boleto_url, boleto_generated_at, metadata, customers(company_name, document)").in("status",["pending","overdue"]).lt("due_date",P()).gt("total_amount",0).order("due_date",{ascending:!0}).limit(500);if(t)throw t;return(a??[]).filter(i=>!i.boleto_url||!!i.boleto_generated_at&&i.boleto_generated_at.slice(0,10)>String(i.due_date).slice(0,10))}}),{data:n}=j({queryKey:["boletos-dados-desatualizados"],queryFn:async()=>{const{data:a,error:t}=await C.from("invoices").select("id, invoice_number, customer_id, due_date, total_amount, status, boleto_error, boleto_url, boleto_generated_at, metadata, customers(company_name, document)").in("status",["pending","overdue"]).not("metadata->stale_boleto_data","is",null).order("due_date",{ascending:!0}).limit(500);if(t)throw t;return a??[]}}),w=()=>{l.invalidateQueries({queryKey:["boletos-aguardando-data"]}),l.invalidateQueries({queryKey:["boletos-dados-desatualizados"]}),l.invalidateQueries({queryKey:["billing-invoices"]})};return e.jsxs(A,{children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-semibold",children:"Boletos aguardando decisão"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Faturas que já passaram do vencimento não têm boleto emitido automaticamente: o banco registraria o documento com a data de hoje, diferente da fatura. Escolha aqui a nova data e o boleto sai com a mesma data da fatura."})]}),e.jsxs(b,{children:[e.jsxs(g,{className:"flex flex-row items-center justify-between",children:[e.jsxs(_,{className:"flex items-center gap-2 text-base",children:[e.jsx(F,{className:"h-4 w-4"}),"Aguardando nova data de vencimento"]}),e.jsx(m,{variant:"secondary",children:(r==null?void 0:r.length)??0})]}),e.jsx(f,{children:q?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Carregandoâ¦"}):r!=null&&r.length?e.jsxs(p,{children:[e.jsx(y,{children:e.jsxs(d,{children:[e.jsx(s,{children:"Fatura"}),e.jsx(s,{children:"Cliente"}),e.jsx(s,{children:"Vencimento"}),e.jsx(s,{children:"Situação"}),e.jsx(s,{className:"text-right",children:"Valor"}),e.jsx(s,{className:"w-32"})]})}),e.jsx(N,{children:r.map(a=>{var t;return e.jsxs(d,{children:[e.jsx(o,{className:"font-medium",children:a.invoice_number??"â"}),e.jsx(o,{children:((t=a.customers)==null?void 0:t.company_name)??"â"}),e.jsx(o,{children:e.jsx("span",{className:"text-destructive",children:v(a.due_date)})}),e.jsx(o,{children:e.jsx(m,{variant:"outline",children:a.boleto_url?"Boleto com data diferente":"Sem boleto"})}),e.jsx(o,{className:"text-right",children:T(Number(a.total_amount))}),e.jsx(o,{className:"text-right",children:e.jsx(D,{size:"sm",variant:"outline",onClick:()=>c(a),children:"Definir nova data"})})]},a.id)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma fatura aguardando decisão."})})]}),e.jsxs(b,{children:[e.jsxs(g,{className:"flex flex-row items-center justify-between",children:[e.jsxs(_,{className:"flex items-center gap-2 text-base",children:[e.jsx(E,{className:"h-4 w-4"}),"Boletos com dados desatualizados"]}),e.jsx(m,{variant:"secondary",children:(n==null?void 0:n.length)??0})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs(K,{children:[e.jsx(O,{className:"h-4 w-4"}),e.jsx(Q,{children:"O cadastro do cliente mudou depois que o boleto foi emitido. O documento que está com o cliente ainda mostra o nome/CNPJ antigo â reemita se quiser corrigir."})]}),n!=null&&n.length?e.jsxs(p,{children:[e.jsx(y,{children:e.jsxs(d,{children:[e.jsx(s,{children:"Fatura"}),e.jsx(s,{children:"Cliente atual"}),e.jsx(s,{children:"No boleto emitido"}),e.jsx(s,{children:"Vencimento"})]})}),e.jsx(N,{children:n.map(a=>{var i,x,h;const t=((i=a.metadata)==null?void 0:i.stale_boleto_data)??{};return e.jsxs(d,{children:[e.jsx(o,{className:"font-medium",children:a.invoice_number??"â"}),e.jsxs(o,{children:[((x=a.customers)==null?void 0:x.company_name)??"â",e.jsx("div",{className:"text-xs text-muted-foreground",children:((h=a.customers)==null?void 0:h.document)??""})]}),e.jsxs(o,{children:[t.previous_company_name??"â",e.jsx("div",{className:"text-xs text-muted-foreground",children:t.previous_document??""})]}),e.jsx(o,{children:v(a.due_date)})]},a.id)})})]}):e.jsx("p",{className:"text-sm text-muted-foreground",children:"Nenhuma fatura nessa situação."})]})]})]}),e.jsx(H,{open:!!u,onOpenChange:a=>!a&&c(null),invoice:u,onSuccess:()=>{c(null),w()}})]})}export{ae 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.