PageSourceSearch

https://maestro.pontua.com.br/assets/NfseNegotiationMonitorCard-D4pOTQ_m.js

js pontua.com.br collected 2026-10-01 14:16:56 UTC 8,231 bytes, 1 lines download raw bytes

1import{u as S,r as N,j as e}from"./vendor-react-DIA7vK4g.js";import{b7 as k,bb as A,bd as M,be as D,aY as F,bm as w,ax as q,bg as P,z as T,T as $,bF as b,bq as E,br as I,bs as B,bt as O,bu as z,bv as L,bw as R,bx as H,ba as p,b9 as y}from"./index-DtUVjOr4.js";import{f as j,a as K}from"./billing-formatters-uNs-HNzw.js";import{C as Q}from"./clock-x8uDBefL.js";import"./vendor-docs-BA9xu9ak.js";import"./vendor-utils-DWHjTIse.js";import"./vendor-supabase-_bOAMmkC.js";async function U(){const{data:c,error:n}=await p.from("collection_cases").select("id, customer_id, recovered_at, invoice_ids, valor_recuperado").eq("status","recovered").not("invoice_ids","is",null).order("recovered_at",{ascending:!1}).limit(200);if(n)throw n;if(!c||c.length===0)return{pending:[],duplicates:[]};const u=Array.from(new Set(c.flatMap(a=>a.invoice_ids??[])));if(u.length===0)return{pending:[],duplicates:[]};const[{data:h},{data:v},{data:r}]=await Promise.all([p.from("invoices").select("id, invoice_number, total_amount, gateway, status, nfse_numero, gateway_invoice_id, stripe_voided_at").in("id",u),p.from("nfse_processing_queue").select("invoice_id, status, created_at, last_error").in("invoice_id",u),p.from("customers").select("id, company_name, trade_name").in("id",Array.from(new Set(c.map(a=>a.customer_id))))]),x=new Map((h??[]).map(a=>[a.id,a])),d=new Map;for(const a of v??[])d.has(a.invoice_id)||d.set(a.invoice_id,a);const f=new Map((r??[]).map(a=>[a.id,a])),g=[],l=[],m=Date.now();for(const a of c){const t=f.get(a.customer_id),_=(t==null?void 0:t.company_name)??(t==null?void 0:t.trade_name)??a.customer_id.slice(0,8);for(const o of a.invoice_ids??[]){const i=x.get(o);if(!i)continue;if(i.gateway==="stripe"&&i.status==="paid"&&i.gateway_invoice_id&&!i.stripe_voided_at){l.push({case_id:a.id,customer_id:a.customer_id,customer_name:_,invoice_id:i.id,invoice_number:i.invoice_number,amount:i.total_amount,stripe_invoice_id:i.gateway_invoice_id,recovered_at:a.recovered_at});continue}if(i.nfse_numero||i.gateway==="stripe"&&!i.stripe_voided_at)continue;const s=d.get(o),C=(s==null?void 0:s.status)==="pending"&&(s!=null&&s.created_at)?m-new Date(s.created_at).getTime()>2*3600*1e3:!1;g.push({case_id:a.id,customer_id:a.customer_id,customer_name:_,invoice_id:i.id,invoice_number:i.invoice_number,amount:i.total_amount,gateway:i.gateway,queue_status:(s==null?void 0:s.status)??null,queue_error:(s==null?void 0:s.last_error)??null,queue_created_at:(s==null?void 0:s.created_at)??null,is_stale:C,recovered_at:a.recovered_at})}}return{pending:g,duplicates:l}}function ee(){const c=S(),{data:n,isLoading:u,refetch:h,isFetching:v}=k({queryKey:["nfse-negotiation-monitor"],queryFn:U,refetchInterval:5*60*1e3}),[r,x]=N.useState(null),[d,f]=N.useState(!1),g=async()=>{var a;if(r){f(!0);try{const{data:t,error:_}=await p.functions.invoke(`collection-stripe-mark-paid?dry_run=false&strategy=paid_out_of_band&invoice_id=${r.invoice_id}`,{method:"POST"});if(_)throw _;const o=(a=t==null?void 0:t.results)==null?void 0:a[0];if(!(t!=null&&t.ok))throw new Error((t==null?void 0:t.error)??"Falha na chamada");if(o&&o.ok===!1)throw new Error(o.error??"Stripe recusou paid_out_of_band");y.success(`Fatura ${r.invoice_number} marcada como paga no Stripe (${(o==null?void 0:o.action)??"ok"})`),x(null),h()}catch(t){y.error(`Erro: ${(t==null?void 0:t.message)??"desconhecido"}`)}finally{f(!1)}}},l=(n==null?void 0:n.pending)??[],m=(n==null?void 0:n.duplicates)??[];return u||l.length===0&&m.length===0?null:e.jsxs(A,{children:[e.jsxs(M,{className:"pb-3 flex flex-row items-center justify-between",children:[e.jsxs("div",{children:[e.jsxs(D,{className:"text-base flex items-center gap-2",children:[e.jsx(F,{className:"h-4 w-4 text-amber-600"}),"NFS-e de Negociações — Monitor"]}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:[l.length," pendente(s) · ",m.length," pagamento(s) duplicado(s) no Stripe"]})]}),e.jsx(w,{variant:"ghost",size:"sm",onClick:()=>h(),disabled:v,children:e.jsx(q,{className:`h-3.5 w-3.5 ${v?"animate-spin":""}`})})]}),e.jsxs(P,{className:"space-y-4",children:[m.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-2 text-destructive",children:"Pagamentos duplicados no Stripe"}),e.jsx("p",{className:"text-xs text-muted-foreground mb-2",children:'Cliente pagou a negociação (Pagar.me) e a fatura Stripe permanece aberta. Use "Marcar paga" para registrar c
1omo paga no Stripe (paid_out_of_band, sem cobrar cartão) ou abra o Stripe para tratar reembolso quando houve cobrança real.'}),e.jsx("div",{className:"space-y-1.5",children:m.map(a=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs border rounded p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{onClick:()=>c(`/financeiro/clientes/${a.customer_id}`),className:"font-medium hover:underline truncate block text-left",children:a.customer_name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono",children:[a.invoice_number," · ",a.stripe_invoice_id]})]}),e.jsx("div",{className:"font-mono tabular-nums text-[11px]",children:j(a.amount)}),e.jsxs(w,{variant:"outline",size:"sm",className:"h-6 px-2 text-[10px] gap-1",onClick:()=>x({invoice_id:a.invoice_id,invoice_number:a.invoice_number,amount:a.amount,stripe_invoice_id:a.stripe_invoice_id,customer_name:a.customer_name}),children:[e.jsx(T,{className:"h-3 w-3"})," Marcar paga"]}),e.jsxs("a",{href:`https://dashboard.stripe.com/invoices/${a.stripe_invoice_id}`,target:"_blank",rel:"noreferrer",className:"text-primary hover:underline flex items-center gap-1 text-[10px]",children:["Stripe ",e.jsx($,{className:"h-3 w-3"})]})]},a.invoice_id))})]}),l.length>0&&e.jsxs("div",{children:[e.jsx("h4",{className:"text-sm font-semibold mb-2",children:"NFS-e pendentes de emissão"}),e.jsx("div",{className:"space-y-1.5 max-h-80 overflow-y-auto",children:l.map(a=>e.jsxs("div",{className:"flex items-center justify-between gap-2 text-xs border rounded p-2",children:[e.jsxs("div",{className:"min-w-0 flex-1",children:[e.jsx("button",{onClick:()=>c(`/financeiro/clientes/${a.customer_id}`),className:"font-medium hover:underline truncate block text-left",children:a.customer_name}),e.jsxs("div",{className:"text-[10px] text-muted-foreground font-mono",children:[a.invoice_number," · ",a.gateway," · recuperada ",K(a.recovered_at)]}),a.queue_error&&e.jsx("div",{className:"text-[10px] text-destructive truncate",title:a.queue_error,children:a.queue_error})]}),e.jsx("div",{className:"font-mono tabular-nums text-[11px]",children:j(a.amount)}),e.jsx("div",{className:"w-24 flex justify-end",children:a.is_stale?e.jsxs(b,{variant:"destructive",className:"gap-1 text-[10px]",children:[e.jsx(Q,{className:"h-3 w-3"})," >2h"]}):a.queue_status?e.jsx(b,{variant:"outline",className:"text-[10px]",children:a.queue_status}):e.jsx(b,{variant:"outline",className:"text-[10px]",children:"sem fila"})})]},a.invoice_id))})]})]}),e.jsx(E,{open:!!r,onOpenChange:a=>!a&&x(null),children:e.jsxs(I,{children:[e.jsxs(B,{children:[e.jsx(O,{children:"Marcar fatura como paga no Stripe?"}),e.jsx(z,{asChild:!0,children:e.jsxs("div",{className:"space-y-2 text-sm",children:[e.jsxs("p",{children:["Isso chama ",e.jsxs("code",{children:["POST /invoices/","{id}","/pay"]})," com ",e.jsx("code",{children:"paid_out_of_band=true"}),". A fatura fica ",e.jsx("b",{children:"paid"})," no Stripe sem cobrar cartão nem gerar charge/refund."]}),r&&e.jsxs("div",{className:"rounded border p-2 bg-muted/40 text-xs space-y-0.5",children:[e.jsxs("div",{children:[e.jsx("b",{children:"Cliente:"})," ",r.customer_name]}),e.jsxs("div",{children:[e.jsx("b",{children:"Fatura:"})," ",r.invoice_number]}),e.jsxs("div",{children:[e.jsx("b",{children:"Stripe:"})," ",e.jsx("code",{children:r.stripe_invoice_id})]}),e.jsxs("div",{children:[e.jsx("b",{children:"Valor:"})," ",j(r.amount)]})]}),e.jsx("p",{className:"text-xs text-destructive",children:"Ação não reversível via API. Se houve cobrança real (boleto/cartão), use estorno manual no Stripe."})]})})]}),e.jsxs(L,{children:[e.jsx(R,{disabled:d,children:"Cancelar"}),e.jsx(H,{onClick:g,disabled:d,children:d?"Marcando...":"Confirmar"})]})]})})]})}export{ee as NfseNegotiationMonitorCard};

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.