PageSourceSearch

https://cacttus.cl/_next/static/chunks/pages/admin/billing/invoices/[id]-a9974b6867b2f0ce.js

js cacttus.cl collected 2026-10-01 23:55:45 UTC 45,752 bytes, 1 lines download raw bytes

1!function(){try{var e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:{},a=(new e.Error).stack;a&&(e._sentryDebugIds=e._sentryDebugIds||{},e._sentryDebugIds[a]="934ca121-1f28-4722-889c-2aae2a746ef6",e._sentryDebugIdIdentifier="sentry-dbid-934ca121-1f28-4722-889c-2aae2a746ef6")}catch(e){}}(),(self.webpackChunk_N_E=self.webpackChunk_N_E||[]).push([[6781],{78753:function(e,a,s){(window.__NEXT_P=window.__NEXT_P||[]).push(["/admin/billing/invoices/[id]",function(){return s(76510)}])},94040:function(e,a,s){"use strict";s.d(a,{o:function(){return InvoiceHistoryList}});var n=s(52322);s(2784);var t=s(70333),i=s(37903),r=s(66682);function formatValue(e){return null==e||""===e?"-":e}function InvoiceHistoryList(e){let{invoiceId:a}=e,{data:s,isLoading:l,isError:d,error:o,refetch:c}=(0,r.s4)(a);return(0,n.jsxs)(t.o,{isLoading:l,isError:d,error:o,refetch:()=>void c(),children:[s&&0===s.history.length&&(0,n.jsx)("div",{className:"p-3 text-sm text-admin-muted-foreground",children:"Sin cambios registrados"}),s&&s.history.length>0&&(0,n.jsx)("div",{className:"divide-y divide-admin-border",children:s.history.map((e,a)=>(0,n.jsxs)("div",{className:"px-3 py-2.5 hover:bg-admin-muted/50 transition-colors",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between gap-2 mb-1",children:[(0,n.jsx)("span",{className:"text-xs font-semibold text-admin-foreground",children:e.field}),(0,n.jsx)("span",{className:"text-2xs text-admin-muted-foreground tabular-nums shrink-0",children:(0,i.o0)(e.date)})]}),(0,n.jsxs)("div",{className:"flex items-center gap-1 text-xs text-admin-foreground",children:[(0,n.jsx)("span",{className:"text-admin-muted-foreground",children:formatValue(e.old_value)}),(0,n.jsx)("span",{className:"text-admin-muted-foreground",children:"→"}),(0,n.jsx)("span",{className:"font-medium",children:formatValue(e.new_value)})]}),e.source&&(0,n.jsx)("div",{className:"text-2xs text-admin-foreground truncate mt-1",title:e.source,children:e.source}),e.user_email&&(0,n.jsx)("div",{className:"text-2xs text-admin-muted-foreground truncate mt-0.5",title:e.user_email,children:e.user_email})]},a))})]})}},76510:function(e,a,s){"use strict";s.r(a),s.d(a,{default:function(){return V}});var n=s(52322),t=s(2784),i=s(37903),r=s(97729),l=s.n(r),d=s(39097),o=s.n(d),c=s(5632),u=s(83878),m=s(28857),x=s(66682),h=s(55830),p=s(62350),j=s(89644),g=s(53538),_=s(14016),f=s(67669),v=s(44994),y=s(13346),b=s(68344);let N=g.Ry({success:g.O7(),message:g.Z_(),invoice_id:g.Rx()}),C=g.Ry({success:g.O7(),invoice:g.Ry({id:g.Rx(),status:g.Z_(),amount:g.Rx()}),payment:g.Ry({id:g.Rx(),amount:g.Rx(),payment_processor:g.Z_()}).nullable(),settlement:g.Ry({id:g.Rx(),amount:g.Rx()}).nullable()}),R=g.Ry({success:g.O7(),message:g.Z_()}),useRetryChargeInvoiceMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(N,{method:"post",url:y.Z.admin.invoices.retryCharge(e.invoice_id)});return a.data}catch(e){if(e instanceof j.AxiosError&&e.response){let a=e.response.status,s=e.response.data,n=(null==s?void 0:s.message)||(null==s?void 0:s.error)||"Error al recobrar el invoice";throw new b.o(n,{statusCode:a,code:null==s?void 0:s.type,details:null==s?void 0:s.details,isExpected:a<500})}throw(0,_.rj)(e),new b.o("Hubo un error al recobrar el invoice. Por favor, intenta nuevamente.")}},onSuccess:(a,s)=>{e.invalidateQueries({queryKey:f.a.adminInvoices.show(s.invoice_id)}),e.invalidateQueries({queryKey:f.a.adminInvoices.list()})}})},useMarkPaidByTransferMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(C,{method:"post",url:y.Z.admin.invoices.markPaidByTransfer(e.invoice_id),data:{paid_amount:e.paid_amount,transfer_type:e.transfer_type}});return a.data}catch(e){if(e instanceof j.AxiosError&&e.response){let a=e.response.status,s=e.response.data,n=(null==s?void 0:s.message)||(null==s?void 0:s.error)||"Error al marcar el invoice como pagado";throw new b.o(n,{statusCode:a,code:null==s?void 0:s.type,details:null==s?void 0:s.details,isExpected:a<500})}throw(0,_.rj)(e),new b.o("Hubo un error al marcar el invoice como pagado. Por favor, intenta nuevamente.")}},onSuccess:(a,s)=>
1{e.invalidateQueries({queryKey:f.a.adminInvoices.show(s.invoice_id)}),e.invalidateQueries({queryKey:f.a.adminInvoices.list()})}})},useDeleteRefundMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(R,{method:"delete",url:"".concat(y.Z.admin.invoices.list(),"/refunds/").concat(e.refundId,"/")});return a.data}catch(e){if(e instanceof j.AxiosError&&e.response){let a=e.response.status,s=e.response.data,n=(null==s?void 0:s.message)||(null==s?void 0:s.error)||"Error al eliminar el refund";throw new b.o(n,{statusCode:a,code:null==s?void 0:s.type,details:null==s?void 0:s.details,isExpected:a<500})}throw(0,_.rj)(e),new b.o("Hubo un error al eliminar el refund. Por favor, intenta nuevamente.")}},onSuccess:()=>{e.invalidateQueries({queryKey:f.a.adminInvoices.list()}),e.invalidateQueries({queryKey:f.a.adminRefunds.list()})}})};var E=s(98543);let w=E.LD,useCreateChargebackMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(w,{method:"post",url:y.Z.admin.refunds.createChargeback(),data:e});return a.data}catch(e){(0,_.zG)(e,"Error al registrar el contracargo")}},onSuccess:(a,s)=>{e.invalidateQueries({queryKey:f.a.adminPayments.list()}),e.invalidateQueries({queryKey:f.a.adminPayments.show(s.payment_id)}),e.invalidateQueries({queryKey:f.a.adminRefunds.list()}),e.invalidateQueries({queryKey:f.a.adminRefunds.list({payment_id:s.payment_id})}),e.invalidateQueries({queryKey:["adminChargebacks"]})}})},useCreateRefundMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(w,{method:"post",url:y.Z.admin.refunds.create(),data:e});return a.data}catch(e){if(e instanceof j.AxiosError&&e.response){let a=e.response.status,s=e.response.data,n=(null==s?void 0:s.message)||(null==s?void 0:s.error)||"Error al crear el refund";throw new b.o(n,{statusCode:a,code:null==s?void 0:s.type,details:null==s?void 0:s.details,isExpected:a<500})}throw(0,_.rj)(e),new b.o("Hubo un error al crear el refund. Por favor, intenta nuevamente.")}},onSuccess:(a,s)=>{e.invalidateQueries({queryKey:f.a.adminPayments.list()}),e.invalidateQueries({queryKey:f.a.adminPayments.show(s.payment_id)}),e.invalidateQueries({queryKey:f.a.adminRefunds.list()}),e.invalidateQueries({queryKey:f.a.adminRefunds.list({payment_id:s.payment_id})})}})},useCreateMpRefundMutation=()=>{let e=(0,h.NL)();return(0,p.D)({mutationFn:async e=>{try{let a=await (0,v.h)(w,{method:"post",url:y.Z.admin.refunds.createMp(),data:e});return a.data}catch(e){if(e instanceof j.AxiosError&&e.response){let a=e.response.status,s=e.response.data,n=(null==s?void 0:s.message)||(null==s?void 0:s.error)||"Error al crear el refund (Mercado Pago)";throw new b.o(n,{statusCode:a,code:null==s?void 0:s.type,details:null==s?void 0:s.details,isExpected:a<500})}throw(0,_.rj)(e),new b.o("Hubo un error al crear el refund (Mercado Pago). Por favor, intenta nuevamente.")}},onSuccess:(a,s)=>{e.invalidateQueries({queryKey:f.a.adminPayments.list()}),e.invalidateQueries({queryKey:f.a.adminPayments.show(s.payment_id)}),e.invalidateQueries({queryKey:f.a.adminRefunds.list()}),e.invalidateQueries({queryKey:f.a.adminRefunds.list({payment_id:s.payment_id})})}})};var Z=s(78134),I=s(84713),D=s(35882),M=s(69405),k=s(70333),P=s(94040),S=s(87779),F=s(93829),q=s(47994),O=s(25766),z=s(97141),A=s(5289),L=s(676),Q=s(68471),K=s(27773),T=s(84355),U=s(26025),B=s(20085);let H=["notified_to_aspor","notified_to_aspor_via_api","paid_to_aspor","received_by_aspor","paid"];var V=(0,u.Z)(function(){let e=(0,c.useRouter)(),{id:a}=e.query,s="string"==typeof a?parseInt(a,10):void 0,{toast:r}=(0,L.pm)(),[d,u]=(0,t.useState)(""),[h,p]=(0,t.useState)(!1),[j,g]=(0,t.useState)(!1),[_,f]=(0,t.useState)("transfer"),[v,y]=(0,t.useState)(!1),[b,N]=(0,t.useState)(null),[C,R]=(0,t.useState)("manual"),[E,w]=(0,t.useState)(""),[V,X]=(0,t.useState)(""),[J,G]=(0,t.useState)(""),[Y,$]=(0,t.useState)(""),[W,ee]=(0,t.useState)("0"),[ea,es]=(0,t.useState)("0"),[en,et]=(0,t.useState)("none"),[ei,er]=(0,t.useState)(!1),[el,ed]=(0,t.useState)(null),[eo,ec]=(0,t.useState)(""),[eu,em]=(0,t.useState)(""),[ex,eh]=(0,t.useState)(""),[ep,ej]=(0,t.useState)(new Set),{data:eg,isLoading:e_,isError:ef,error:ev,refetch:ey}=(0,x.qN)(s),eb=useMarkPaidByTransferMutation(),eN=useCreateRefundMutation(),eC=useCreateMpRefundMutation(),eR=useCreateChargebackMutation(),eE=useDeleteRefundMutation(),ew=useRetryChargeInvoiceMutation(),formatCurrency=e=>null===e?"-":new Intl.NumberFormat("es-CL",{style:"currency",currency:"CLP",minimumFractionDigits:0}).format(e),getPaymentProcessorBadgeColor=e=>({toku:"bg-blue-100 text-blue-800",transbank:"bg-green-100 text-green-800",mercadopago:"bg-yellow-100 text-yellow-800",oneclick:"bg-purple-100 text-purple-800",transfer:"bg-admin-muted text-admin-foreground",direct_to_company:"bg-orange-100 text-orange-800",cacttus:"bg-indigo-100 text-indigo-800"})[e]||"bg-admin-muted text-admin-foreground",togglePaymentExpansion=e=>{let a=new Set(ep);a.has(e)?a.delete(e):a.add(e),ej(a)},getStatusBadgeColor=e=>e&&({AUTHORIZED:"bg-green-100 text-green-800",PENDING:"bg-yellow-100 text-yellow-800",FAILED:"bg-red-100 text-red-800",paid:"bg-green-100 text-green-800",not_paid:"bg-red-100 text-red-800"})[e]||"bg-admin-muted text-admin-foreground",handleMarkPaid=async()=>
1{if(!(null==eg?void 0:eg.id)||!d)return;let e=parseInt(d.replace(/[.,]/g,""),10);if(isNaN(e)||e<=0){r({description:"El monto debe ser un n\xfamero mayor a 0",variant:"warning"});return}try{await eb.mutateAsync({invoice_id:s,paid_amount:e,transfer_type:_}),r({variant:"success",description:"El invoice ha sido marcado como pagado correctamente"}),p(!1),g(!1),u(""),ey()}catch(s){let e="Error al marcar el invoice como pagado",a="";if(s instanceof Error&&(e=s.message,s.details)){let e=JSON.stringify(s.details,null,2);a="\n\nDetalles: ".concat(e)}r({title:"Error",description:e+a,variant:"destructive"})}},handleOpenRefundDialog=(e,a,s)=>{N(e),X((null==s?void 0:s.toString())||"");let n="mercadopago"===a;R(n?"mercadopago":"manual"),w(a||"manual"),"toku"===a?et("TOKU_REFUND"):"mercadopago"===a?et("MERCADOPAGO_REFUND"):"manual"===a?et("Devoluci\xf3n manual"):et("none"),y(!0)},handleCreateRefund=async()=>{var e;if(!b)return;let a=null==eg?void 0:eg.payments.find(e=>e.id===b);if(!a)return;let s=V?parseFloat(V):null!==(e=a.amount)&&void 0!==e?e:0;if("manual"===C&&(isNaN(s)||s<=0)){r({description:"El monto debe ser un n\xfamero mayor a 0",variant:"warning"});return}let n=W?parseFloat(W):void 0,t=ea?parseInt(ea,10):void 0;try{"mercadopago"===C?await eC.mutateAsync({payment_id:b}):await eN.mutateAsync({payment_id:b,nullified_amount:s,authorization_code:J||void 0,authorization_date:Y||void 0,balance:n,response_code:t,type:"none"===en?void 0:en||void 0,payment_processor:E}),r({variant:"success",description:"El refund ha sido creado correctamente"}),y(!1),N(null),X(""),G(""),$(""),ee("0"),es("0"),et("none"),ey()}catch(s){let e="Error al crear el refund",a="";if(s instanceof Error&&(e=s.message,s.details)){let e=JSON.stringify(s.details,null,2);a="\n\nDetalles: ".concat(e)}r({title:"Error",description:e+a,variant:"destructive"})}},handleOpenChargebackDialog=(e,a,s)=>{ed(e),ec(a||"manual"),em((null==s?void 0:s.toString())||""),eh(""),er(!0)},handleCreateChargeback=async()=>{var e;if(!el)return;let a=null==eg?void 0:eg.payments.find(e=>e.id===el);if(!a)return;let s=eu?parseFloat(eu):null!==(e=a.amount)&&void 0!==e?e:0;if(isNaN(s)||s<=0){r({description:"El monto debe ser un n\xfamero mayor a 0",variant:"warning"});return}if(!ex.trim()){r({description:"Debes ingresar el motivo del contracargo",variant:"warning"});return}try{await eR.mutateAsync({payment_id:el,nullified_amount:s,reason:ex.trim(),payment_processor:eo}),r({variant:"success",description:"El contracargo ha sido registrado correctamente"}),er(!1),ed(null),ec(""),em(""),eh(""),ey()}catch(s){let e="Error al registrar el contracargo",a="";if(s instanceof Error&&(e=s.message,s.details)){let e=JSON.stringify(s.details,null,2);a="\n\nDetalles: ".concat(e)}r({title:"Error",description:e+a,variant:"destructive"})}},handleDeleteRefund=async e=>{if(confirm("\xbfEst\xe1s seguro de que quieres eliminar este refund?"))try{await eE.mutateAsync({refundId:e}),r({variant:"success",description:"El refund ha sido eliminado correctamente"}),ey()}catch(s){let e="Error al eliminar el refund",a="";if(s instanceof Error&&(e=s.message,s.details)){let e=JSON.stringify(s.details,null,2);a="\n\nDetalles: ".concat(e)}r({title:"Error",description:e+a,variant:"destructive"})}},handleRetryCharge=async()=>{if(s&&confirm("\xbfEst\xe1s seguro de que quieres recobrar este invoice a trav\xe9s de Mercado Pago?"))try{let e=await ew.mutateAsync({invoice_id:s});r({variant:e.success?"success":"destructive",description:e.message}),e.success&&ey()}catch(e){r({description:e instanceof Error?e.message:"Error al recobrar el invoice",variant:"destructive"})}};if(e_)return(0,n.jsx)(k.o,{isLoading:!0,isError:!1,refetch:()=>void ey()});if(ef||!eg)return(0,n.jsx)(k.o,{isLoading:!1,isError:!0,error:ev,refetch:()=>void ey()});let eZ=eg.status,eI=H.includes(eZ),eD=eg.payments.map(e=>{var a,s;return null!==(s=null===(a=e.outgoing_settlement)||void 0===a?void 0:a.id)&&void 0!==s?s:e.outgoing_settlement_id}).filter(e=>null!=e),eM=eD.length>0?Math.max(...eD):null,ek=eg.payments.find(e=>e.id===b),eP=(null==ek?void 0:ek.payment_processor)==="mercadopago"?eg.payments.find(e=>"cacttus"===e.payment_processor&&"AUTHORIZED"===e.status&&0===e.refunds.length&&null!=ek.amount&&null!=e.amount&&null!=eg.amount&&99>=Math.abs(ek.amount+e.amount-eg.amount)):void 0;return(0,n.jsxs)(m.Z,{children:[(0,n.jsx)(l(),{children:(0,n.jsxs)("title",{children:["Invoice #",eg.id," - Admin"]})}),(0,n.jsxs)("div",{className:"space-y-6",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center space-x-4",children:[(0,n.jsxs)(F.z,{variant:"ghost",size:"sm",onClick:()=>e.back(),children:[(0,n.jsx)(Z.Z,{className:"h-4 w-4 mr-2"}),"Volver"]}),(0,n.jsxs)("h1",{className:"text-3xl font-bold",children:["Invoice #",eg.id]}),(0,n.jsx)(S.C,{className:getStatusBadgeColor(eg.status),children:eg.status}),eg.has_chargeback&&(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)("button",{type:"button",children:(0,n.jsx)(S.C,{variant:"warning-subtle",children:"Contracargo"})})}),(0,n.jsx)(U.yk,{className:"w-72",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Contracargo"}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Fecha"}),(0,n.jsx)("p",{className:"text-sm",children:(0,i.p6)(eg.chargeback_date)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Motivo"}),(0,n.jsx)("p",{className:"text-sm",children:eg.chargeback_reason||"-"})]})]})})]})]}),(0,n.jsxs)(K.h_,{children:[(0,n.jsx)(K.$F,{asChild:!0,children:(0,n.jsxs)(F.z,{children:["Acciones",(0,n.jsx)(I.Z,{className:"ml-2 h-4 w-4"})]})}),(0,n.jsxs)(K.AW,{align:"end",className:"w-64",children:[(0,n.jsx)(K.Xi,{onClick:()=>{f("transfer"),u(null!=eg.amount?Math.round(eg.amount).toString():""),p(!0)},children:"Marcar como Pagado (Transferencia)"}),(0,n.jsx)(K.Xi,{onClick:()=>{f("direct_to_company"),u(null!=eg.amount?Math.round(eg.amount).toString():""),g(!0)},children:"Marcar como Pagado (Directo a Compa\xf1\xeda)"}),"not_paid"===eg.status&&(0,n.jsx)(K.Xi,{onClick:()=>void handleRetryCharge(),disabled:ew.isLoading,children:ew.isLoading?"Cobrando...":"Recobrar con Mercado Pago"})]})]})]}),(0,n.jsxs)("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[(0,n.jsxs)(z.Zb,{children:[(0,n.jsx)(z.Ol,{children:(0,n.jsx)(z.ll,{children:"Informaci\xf3n del Invoice"})}),(0,n.jsxs)(z.aY,{className:"space-y-3",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"ID"}),(0,n.jsx)("p",{className:"font-medium",children:eg.id})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Monto"}),(0,n.jsx)("p",{className:"font-medium text-lg",children:formatCurrency(eg.amount)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Estado"}),(0,n.jsx)(S.C,{className:getStatusBadgeColor(eg.status),children:eg.status})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Fecha de Vencimiento"}),(0,n.jsx)("p",{className:"font-medium",children:(0,i.p6)(eg.due_date)})]}),null!==eg.price&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Precio (UF)"}),(0,n.jsxs)("p",{className:"font-medium",children:[eg.price.toFixed(4)," UF"]})]}),null!==eg.interest_rate&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Tasa de Inter\xe9s"}),(0,n.jsxs)("p",{className:"font-medium",children:[(100*eg.interest_rate).toFixed(2),"%"]})]}),eg.toku_invoice_id&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Toku Invoice ID"}),(0,n.jsx)("p",{className:"font-medium text-sm font-mono",children:eg.toku_invoice_id})]}),null!=eM&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Liquidaci\xf3n 
1Saliente"}),(0,n.jsxs)("p",{className:"font-medium text-sm font-mono",children:["#",eM]})]})]})]}),(0,n.jsxs)(z.Zb,{children:[(0,n.jsx)(z.Ol,{children:(0,n.jsx)(z.ll,{children:"Informaci\xf3n del Usuario y P\xf3liza"})}),(0,n.jsxs)(z.aY,{className:"space-y-3",children:[eg.user&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"Usuario"}),(0,n.jsx)("p",{className:"font-medium",children:eg.user.email})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"RUT"}),(0,n.jsx)("p",{className:"font-medium",children:eg.user.rut})]})]}),eg.policy&&(0,n.jsx)(n.Fragment,{children:(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-sm text-admin-muted-foreground",children:"P\xf3liza"}),(0,n.jsx)(o(),{href:eg.user?"/admin/support/customers/".concat(eg.user.id,"?cd_tab=policies&pd_policy_id=").concat(eg.policy.id):"/admin/portfolio/policies/".concat(eg.policy.id),className:"text-admin-primary hover:underline font-medium",children:eg.policy.document_number||eg.policy.readable_id||eg.policy.id})]})})]})]})]}),(0,n.jsxs)(z.Zb,{children:[(0,n.jsx)(z.Ol,{children:(0,n.jsxs)(z.ll,{children:["Pagos Asociados (",eg.payments.length,")"]})}),(0,n.jsx)(z.aY,{children:0===eg.payments.length?(0,n.jsx)("p",{className:"text-admin-muted-foreground text-center py-4",children:"No hay pagos asociados a este invoice"}):(0,n.jsx)("div",{className:"space-y-4",children:eg.payments.map(e=>{let a=ep.has(e.id),s=e.mp_payment_id||e.mp_payment_method_id,t=e.refunds.length>0,r="cacttus"===e.payment_processor&&eg.is_fully_cacttus_paid,l=("cacttus"!==e.payment_processor||r)&&!t,d=eI&&"cacttus"!==e.payment_processor&&!t&&"AUTHORIZED"===e.status;return(0,n.jsxs)("div",{className:"border rounded-lg",children:[(0,n.jsxs)("div",{className:"p-4 bg-admin-muted",children:[(0,n.jsxs)("div",{className:"flex items-center justify-between",children:[(0,n.jsxs)("div",{className:"flex items-center space-x-4 flex-1",children:[(0,n.jsx)(F.z,{variant:"ghost",size:"sm",onClick:()=>togglePaymentExpansion(e.id),className:"h-8 w-8 p-0",children:a?(0,n.jsx)(I.Z,{className:"h-4 w-4"}):(0,n.jsx)(D.Z,{className:"h-4 w-4"})}),(0,n.jsxs)("div",{className:"flex items-center space-x-3",children:[(0,n.jsxs)("span",{className:"font-medium text-sm",children:["Payment #",e.id]}),(0,n.jsx)(S.C,{className:getPaymentProcessorBadgeColor(e.payment_processor),children:e.payment_processor}),s&&(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-6 w-6 p-0",children:(0,n.jsx)(M.Z,{className:"h-4 w-4 text-admin-primary"})})}),(0,n.jsx)(U.yk,{className:"w-80",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Mercado Pago Info"}),e.mp_payment_id&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Payment ID"}),(0,n.jsx)("p",{className:"text-sm font-mono",children:e.mp_payment_id})]}),e.mp_payment_method_id&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Method"}),(0,n.jsx)("p",{className:"text-sm",children:e.mp_payment_method_id})]}),e.mp_payment_type_id&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Type"}),(0,n.jsx)("p",{className:"text-sm",children:e.mp_payment_type_id})]}),e.mp_status&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Status"}),(0,n.jsx)("p",{className:"text-sm",children:e.mp_status})]}),e.mp_status_detail&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Status Detail"}),(0,n.jsx)("p",{className:"text-sm",children:e.mp_status_detail})]})]})})]})]}),(0,n.jsxs)("div",{className:"flex items-center space-x-6 text-sm",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-admin-muted-foreground",children:"Monto: "}),(0,n.jsx)("span",{className:"font-medium",children:formatCurrency(e.amount)})]}),(0,n.jsx)("div",{children:(0,n.jsx)(S.C,{className:getStatusBadgeColor(e.status),children:e.status||"N/A"})}),(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-admin-muted-foreground",children:"Fecha: "}),(0,n.jsx)("span",{children:(0,i.p6)(e.created_at)})]}),t&&(0,n.jsxs)("div",{children:[(0,n.jsx)("span",{className:"text-admin-muted-foreground",children:"Refunds: "}),(0,n.jsx)(S.C,{variant:"outline",children:e.refunds.length})]}),e.incoming_settlement&&(0,n.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,n.jsx)(S.C,{variant:"secondary",className:"bg-green-50 text-green-700",children:"↓ Liquidaci\xf3n Entrante"}),(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",children:(0,n.jsx)(M.Z,{className:"h-3 w-3 text-green-600"})})}),(0,n.jsx)(U.yk,{className:"w-60",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Liquidaci\xf3n Entrante"}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"ID"}),(0,n.jsxs)("p",{className:"text-sm",children:["#",e.incoming_settlement.i
1d]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Monto"}),(0,n.jsx)("p",{className:"text-sm",children:formatCurrency(e.incoming_settlement.amount)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Fecha"}),(0,n.jsx)("p",{className:"text-sm",children:(0,i.p6)(e.incoming_settlement.created_at)})]}),e.incoming_settlement.comment&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Comentario"}),(0,n.jsx)("p",{className:"text-sm",children:e.incoming_settlement.comment})]})]})})]})]}),e.outgoing_settlement&&(0,n.jsxs)("div",{className:"flex items-center space-x-1",children:[(0,n.jsx)(S.C,{variant:"secondary",className:"bg-red-50 text-red-700",children:"↑ Liquidaci\xf3n Saliente"}),(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",children:(0,n.jsx)(M.Z,{className:"h-3 w-3 text-red-600"})})}),(0,n.jsx)(U.yk,{className:"w-60",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Liquidaci\xf3n Saliente"}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"ID"}),(0,n.jsxs)("p",{className:"text-sm",children:["#",e.outgoing_settlement.id]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Monto"}),(0,n.jsx)("p",{className:"text-sm",children:formatCurrency(e.outgoing_settlement.amount)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Fecha"}),(0,n.jsx)("p",{className:"text-sm",children:(0,i.p6)(e.outgoing_settlement.created_at)})]}),e.outgoing_settlement.comment&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Comentario"}),(0,n.jsx)("p",{className:"text-sm",children:e.outgoing_settlement.comment})]})]})})]})]})]})]}),(0,n.jsxs)("div",{className:"flex items-center space-x-2",children:[l&&(0,n.jsx)(F.z,{size:"sm",variant:"outline",onClick:()=>handleOpenRefundDialog(e.id,e.payment_processor,e.amount),disabled:"AUTHORIZED"!==e.status,children:"Crear Refund"}),d&&(0,n.jsx)(F.z,{size:"sm",variant:"outline",onClick:()=>handleOpenChargebackDialog(e.id,e.payment_processor,e.amount),children:"Registrar Contracargo"})]})]}),e.external_id&&(0,n.jsxs)("div",{className:"mt-2 text-xs text-admin-muted-foreground",children:["External ID: ",(0,n.jsx)("span",{className:"font-mono",children:e.external_id})]})]}),a&&t&&(0,n.jsxs)("div",{className:"p-4 border-t",children:[(0,n.jsxs)("h4",{className:"font-semibold text-sm mb-3",children:["Refunds (",e.refunds.length,")"]}),(0,n.jsxs)(B.iA,{children:[(0,n.jsx)(B.xD,{children:(0,n.jsxs)(B.SC,{children:[(0,n.jsx)(B.ss,{children:"ID"}),(0,n.jsx)(B.ss,{children:"Monto"}),(0,n.jsx)(B.ss,{children:"Tipo"}),(0,n.jsx)(B.ss,{children:"Procesador"}),(0,n.jsx)(B.ss,{children:"Liquidaciones"}),(0,n.jsx)(B.ss,{children:"Auth Code"}),(0,n.jsx)(B.ss,{children:"Fecha Auth"}),(0,n.jsx)(B.ss,{children:"Fecha Creaci\xf3n"}),(0,n.jsx)(B.ss,{children:"Acciones"})]})}),(0,n.jsx)(B.RM,{children:e.refunds.map(e=>(0,n.jsxs)(B.SC,{children:[(0,n.jsx)(B.pj,{className:"font-medium",children:e.id}),(0,n.jsx)(B.pj,{children:formatCurrency(e.nullified_amount)}),(0,n.jsx)(B.pj,{children:e.type?(0,n.jsx)(S.C,{variant:"outline",children:e.type}):"-"}),(0,n.jsx)(B.pj,{children:(0,n.jsxs)("div",{className:"flex items-center space-x-2",children:[(0,n.jsx)(S.C,{className:getPaymentProcessorBadgeColor(e.payment_processor),children:e.payment_processor}),e.mp_refund_id&&(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-5 w-5 p-0",children:(0,n.jsx)(M.Z,{className:"h-3 w-3 text-admin-primary"})})}),(0,n.jsx)(U.yk,{className:"w-60",children:(0,n.jsxs)("div",{className:"space-y-1",children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"MP Refund ID"}),(0,n.jsx)("p",{className:"text-sm font-mono",children:e.mp_refund_id})]})})]})]})}),(0,n.jsx)(B.pj,{children:(0,n.jsxs)("div",{className:"flex flex-col space-y-1",children:[e.incoming_settlement&&(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-auto p-1 justify-start",children:(0,n.jsxs)(S.C,{variant:"secondary",className:"bg-green-50 text-green-700 text-xs",children:["↓ #",e.incoming_settlement.i
1d]})})}),(0,n.jsx)(U.yk,{className:"w-60",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Liquidaci\xf3n Entrante"}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Monto"}),(0,n.jsx)("p",{className:"text-sm",children:formatCurrency(e.incoming_settlement.amount)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Fecha"}),(0,n.jsx)("p",{className:"text-sm",children:(0,i.p6)(e.incoming_settlement.created_at)})]}),e.incoming_settlement.comment&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Comentario"}),(0,n.jsx)("p",{className:"text-sm",children:e.incoming_settlement.comment})]})]})})]}),e.outgoing_settlement&&(0,n.jsxs)(U.J2,{children:[(0,n.jsx)(U.xo,{asChild:!0,children:(0,n.jsx)(F.z,{variant:"ghost",size:"sm",className:"h-auto p-1 justify-start",children:(0,n.jsxs)(S.C,{variant:"secondary",className:"bg-red-50 text-red-700 text-xs",children:["↑ #",e.outgoing_settlement.id]})})}),(0,n.jsx)(U.yk,{className:"w-60",children:(0,n.jsxs)("div",{className:"space-y-2",children:[(0,n.jsx)("h4",{className:"font-semibold text-sm",children:"Liquidaci\xf3n Saliente"}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Monto"}),(0,n.jsx)("p",{className:"text-sm",children:formatCurrency(e.outgoing_settlement.amount)})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Fecha"}),(0,n.jsx)("p",{className:"text-sm",children:(0,i.p6)(e.outgoing_settlement.created_at)})]}),e.outgoing_settlement.comment&&(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{className:"text-xs text-admin-muted-foreground",children:"Comentario"}),(0,n.jsx)("p",{className:"text-sm",children:e.outgoing_settlement.comment})]})]})})]}),!e.incoming_settlement&&!e.outgoing_settlement&&"-"]})}),(0,n.jsx)(B.pj,{className:"font-mono text-xs",children:e.authorization_code||"-"}),(0,n.jsx)(B.pj,{children:(0,i.p6)(e.authorization_date)}),(0,n.jsx)(B.pj,{children:(0,i.p6)(e.created_at)}),(0,n.jsx)(B.pj,{children:(0,n.jsx)(F.z,{variant:"destructive",size:"sm",onClick:()=>void handleDeleteRefund(e.id),disabled:eE.isLoading,children:"Eliminar"})})]},e.id))})]})]}),a&&!t&&(0,n.jsx)("div",{className:"p-4 border-t text-center text-admin-muted-foreground text-sm",children:"No hay refunds asociados a este pago"})]},e.id)})})})]}),eg.payment_intents&&eg.payment_intents.length>0&&(0,n.jsxs)(z.Zb,{children:[(0,n.jsx)(z.Ol,{children:(0,n.jsxs)(z.ll,{children:["Intentos de Pago (",eg.payment_intents.length,")"]})}),(0,n.jsx)(z.aY,{children:(0,n.jsxs)(B.iA,{children:[(0,n.jsx)(B.xD,{children:(0,n.jsxs)(B.SC,{children:[(0,n.jsx)(B.ss,{children:"ID"}),(0,n.jsx)(B.ss,{children:"Processor"}),(0,n.jsx)(B.ss,{children:"Estado"}),(0,n.jsx)(B.ss,{children:"Monto"}),(0,n.jsx)(B.ss,{children:"External ID"}),(0,n.jsx)(B.ss,{children:"Error"}),(0,n.jsx)(B.ss,{children:"Fecha"})]})}),(0,n.jsx)(B.RM,{children:eg.payment_intents.map(e=>(0,n.jsxs)(B.SC,{children:[(0,n.jsxs)(B.pj,{children:["#",e.id]}),(0,n.jsx)(B.pj,{children:(0,n.jsx)(S.C,{children:e.payment_processor})}),(0,n.jsx)(B.pj,{children:(0,n.jsx)(S.C,{variant:"success"===e.status?"default":"pending"===e.status||"pending_challenge"===e.status?"outline":"destructive",children:e.status})}),(0,n.jsx)(B.pj,{children:formatCurrency(e.amount_clp)}),(0,n.jsx)(B.pj,{className:"font-mono text-xs",children:e.external_payment_id||"-"}),(0,n.jsx)(B.pj,{className:"max-w-xs",children:e.error_message?(0,n.jsx)("div",{className:"text-xs text-red-600 truncate",title:e.error_message,children:e.error_message}):"-"}),(0,n.jsx)(B.pj,{children:(0,i.p6)(e.created_at)})]},e.id))})]})})]}),(0,n.jsxs)(z.Zb,{children:[(0,n.jsx)(z.Ol,{children:(0,n.jsx)(z.ll,{children:"Historial de Cambios"})}),(0,n.jsx)(z.aY,{className:"px-0",children:(0,n.jsx)(P.o,{invoiceId:eg.id})})]})]}),(0,n.jsx)(T.Vq,{open:h,onOpenChange:p,children:(0,n.jsxs)(T.cZ,{children:[(0,n.jsxs)(T.fK,{children:[(0,n.jsx)(T.$N,{
1children:"Marcar Invoice como Pagado por Transferencia"}),(0,n.jsxs)(T.Be,{children:["Esto crear\xe1 un pago y una liquidaci\xf3n entrante para el invoice ",eg.id,"."]})]}),(0,n.jsx)("div",{className:"space-y-4 py-4",children:(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"paid-amount",children:"Monto Pagado"}),(0,n.jsx)(q.I,{id:"paid-amount",type:"text",inputMode:"numeric",value:d,onChange:e=>u(e.target.value),placeholder:"Ej: 10.000"})]})}),(0,n.jsxs)(T.cN,{children:[(0,n.jsx)(F.z,{variant:"outline",onClick:()=>p(!1),children:"Cancelar"}),(0,n.jsx)(F.z,{onClick:()=>void handleMarkPaid(),disabled:eb.isLoading,children:eb.isLoading?"Marcando...":"Marcar como Pagado"})]})]})}),(0,n.jsx)(T.Vq,{open:j,onOpenChange:g,children:(0,n.jsxs)(T.cZ,{children:[(0,n.jsxs)(T.fK,{children:[(0,n.jsx)(T.$N,{children:"Marcar Invoice como Pagado Directo a Compa\xf1\xeda"}),(0,n.jsxs)(T.Be,{children:["Esto crear\xe1 un pago directo a la compa\xf1\xeda de seguros para el invoice ",eg.id,"."]})]}),(0,n.jsx)("div",{className:"space-y-4 py-4",children:(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"direct-paid-amount",children:"Monto Pagado"}),(0,n.jsx)(q.I,{id:"direct-paid-amount",type:"text",inputMode:"numeric",value:d,onChange:e=>u(e.target.value),placeholder:"Ej: 10.000"})]})}),(0,n.jsxs)(T.cN,{children:[(0,n.jsx)(F.z,{variant:"outline",onClick:()=>g(!1),children:"Cancelar"}),(0,n.jsx)(F.z,{onClick:()=>void handleMarkPaid(),disabled:eb.isLoading,children:eb.isLoading?"Marcando...":"Marcar como Pagado"})]})]})}),(0,n.jsx)(T.Vq,{open:v,onOpenChange:y,children:(0,n.jsxs)(T.cZ,{className:"max-w-2xl",children:[(0,n.jsxs)(T.fK,{children:[(0,n.jsxs)(T.$N,{children:["Crear Refund para Payment #",b]}),(0,n.jsx)(T.Be,{children:"Selecciona el m\xe9todo de refund y completa los datos necesarios."})]}),(0,n.jsxs)("div",{className:"space-y-4 py-4",children:["paid"===eZ&&(()=>{let e=eg.payments.filter(e=>e.id!==b&&"AUTHORIZED"===e.status&&"cacttus"!==e.payment_processor&&0===e.refunds.length).length;return e>0?(0,n.jsx)("div",{className:"rounded-md bg-blue-50 border border-blue-200 p-4",children:(0,n.jsxs)("p",{className:"text-sm text-blue-800",children:["ℹ️ ",(0,n.jsx)("strong",{children:"Comportamiento:"}),' El invoice se mantendr\xe1 en estado "paid" porque ',1===e?"queda otro pago autorizado":"quedan ".concat(e," pagos autorizados")," sin refund. Se re-apuntar\xe1 al siguiente pago autorizado."]})}):(0,n.jsx)("div",{className:"rounded-md bg-amber-50 border border-amber-200 p-4",children:(0,n.jsxs)("p",{className:"text-sm text-amber-800",children:["⚠️ ",(0,n.jsx)("strong",{children:"Advertencia:"}),' Este es el \xfaltimo pago autorizado del invoice. Al crear este refund, el invoice pasar\xe1 a estado "not_paid".']})})})(),(null==ek?void 0:ek.payment_processor)!=="mercadopago"&&(0,n.jsx)("div",{className:"rounded-md bg-blue-50 border border-blue-200 p-4",children:(0,n.jsxs)("p",{className:"text-sm text-blue-800",children:["ℹ️ ",(0,n.jsx)("strong",{children:"Informaci\xf3n:"})," Este pago fue procesado con ",(0,n.jsx)("strong",{children:null==ek?void 0:ek.payment_processor}),". Solo est\xe1 disponible el refund manual."]})}),eP&&(0,n.jsx)("div",{className:"rounded-md bg-indigo-50 border border-indigo-200 p-4",children:(0,n.jsxs)("p",{className:"text-sm text-indigo-800",children:["ℹ️ ",(0,n.jsx)("strong",{children:"Subsidio Cacttus:"})," Este refund tambi\xe9n crear\xe1 autom\xe1ticamente un refund del pago Cacttus #",eP.id," por ",formatCurrency(eP.amount),"."]})}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"refund-method",children:"M\xe9todo de Refund"}),(0,n.jsxs)(Q.Ph,{value:C,onValueChange:e=>R(e),disabled:(null==ek?void 0:ek.payment_processor)!=="mercadopago",children:[(0,n.jsx)(Q.i4,{id:"refund-method",children:(0,n.jsx)(Q.ki,{})}),(0,n.jsxs)(Q.Bw,{children:[(0,n.jsx)(Q.Ql,{value:"manual",children:"Refund Manual"}),(null==ek?void 0:ek.payment_processor)==="mercadopago"&&(0,n.jsx)(Q.Ql,{value:"mercadopago",children:"Refund a trav\xe9s de Mercado Pago (Autom\xe1tico)"})]})]}),(0,n.jsx)("p",{className:"text-xs text-admin-muted-foreground mt-1",children:"manual"===C?"Registra el refund manualmente sin procesarlo autom\xe1ticamente":"Procesa el refund autom\xe1ticamente a trav\xe9s de la API de Mercado Pago"})]}),"mercadopago"===C&&"paid"!==eZ&&(0,n.jsx)("div",{className:"rounded-md bg-red-50 border border-red-200 p-4",children:(0,n.jsxs)("p",{className:"text-sm text-red-800",children:["❌ ",(0,n.jsx)("strong",{children:"Error:"}),' No se puede crear un refund de Mercado Pago para un invoice en estado "',eZ,'". El invoice debe estar en estado "paid".']})}),"manual"===C&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"refund-processor",children:"Procesador del Refund"}),(0,n.jsxs)(Q.Ph,{value:E,onValueChange:e=>{w(e),"toku"===e?et("TOKU_REFUND"):"mercadopago"===e?et("MERCADOPAGO_REFUND"):"manual"===e?et("Devoluci\xf3n manual"):et("none")},children:[(0,n.jsx)(Q.i4,{id:"refund-processor",children:(0,n.jsx)(Q.ki,{})}),(0,n.jsxs)(Q.Bw,{children:[(0,n.jsxs)(Q.Ql,{value:(null==ek?void 0:ek.payment_processor)||"manual",children:[(null==ek?void 0:ek.payment_processor)||"Manual"," (Original)"]}),(0,n.jsx)(Q.Ql,{value:"manual",children:"Manual (Devoluci\xf3n fuera del sistema)"})]})]}),(0,n.jsx)("p",{className:"text-xs text-admin-muted-foreground mt-1",children:'Selecciona el procesador original o "Manual" si la devoluci\xf3n se hizo fuera del sistema'})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"refund-amount",children:"Monto a Devolver"}),(0,n.jsx)(q.I,{id:"refund-amount",type:"number",value:V,onChange:e=>X(e.target.value),placeholder:"Ej: 5000"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"auth-code",children:"C\xf3digo de Autorizaci\xf3n (opcional)"}),(0,n.jsx)(q.I,{id:"auth-code",value:J,onChange:e=>G(e.target.value),placeholder:"Ej: AUTH123"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"auth-date",children:"Fecha de Autorizaci\xf3n (opcional)"}),(0,n.jsx)(q.I,{id:"auth-date",type:"date",value:Y,onChange:e=>$(e.target.value)})]}),(0,n.jsxs)("div",{className:"grid grid-cols-2 gap-4",children:[(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"balance",children:"Balance (opcional)"}),(0,n.jsx)(q.I,{id:"balance",type:"number",value:W,onChange:e=>ee(e.target.value),placeholder:"Ej: 0"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"response-code",children:"C\xf3digo de Respuesta (opcional)"}),(0,n.jsx)(q.I,{id:"response-code",type:"number",value:ea,onChange:e=>es(e.target.value),placeholder:"Ej: 0"})]})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"refund-type",children:"Tipo de Refund (opcional)"}),(0,n.jsxs)(Q.Ph,{value:en,onValueChange:et,children:[(0,n.jsx)(Q.i4,{id:"refund-type",children:(0,n.jsx)(Q.ki,{placeholder:"Selecciona un tipo"})}),(0,n.jsxs)(Q.Bw,{children:[(0,n.jsx)(Q.Ql,{value:"none",children:"Ninguno"}),"toku"===E&&(0,n.jsxs)(n.Fragment,{children:[(0,n.jsx)(Q.Ql,{value:"TOKU_REFUND",children:"TOKU_REFUND"}),(0,n.jsx)(Q.Ql,{value:"TOKU_CHARGEBACK",children:"TOKU_CHARGEBACK"})]}),"mercadopago"===E&&(0,n.jsx)(Q.Ql,{value:"MERCADOPAGO_REFUND",children:"MERCADOPAGO_REFUND"}),(0,n.jsx)(Q.Ql,{value:"NULLIFIED",children:"NULLIFIED"}),(0,n.jsx)(Q.Ql,{value:"REVERSED",children:"REVERSED"}),(0,n.jsx)(Q.Ql,{value:"Devoluci\xf3n manual",children:"Devoluci\xf3n manual"})]})]}),(0,n.jsxs)("p",{className:"text-xs text-admin-muted-foreground mt-1",children:["toku"===E&&"Opciones espec\xedficas de Toku disponibles","mercadopago"===E&&"Opciones espec\xedficas de Mercado Pago disponibles","manual"===E&&"Opciones gen\xe9ricas para refund manual"]})]})]})]}),(0,n.jsxs)(T.cN,{children:[(0,n.jsx)(F.z,{variant:"outline",onClick:()=>y(!1),children:"Cancelar"}),(0,n.jsx)(F.z,{onClick:()=>void handleCreateRefund(),disabled:eN.isLoading||eC.isLoading,children:eN.isLoading||eC.isLoading?"Creando...":"Crear Refund"})]})]})}),(0,n.jsx)(T.Vq,{open:ei,onOpenChange:er,children:(0,n.jsxs)(T.cZ,{className:"max-w-lg",children:[(0,n.jsxs)(T.fK,{children:[(0,n.jsxs)(T.$N,{
1children:["Registrar Contracargo para Payment #",el]}),(0,n.jsx)(T.Be,{children:"Registra un contracargo sobre este pago para gestionar su cobro desde la cola de Contracargos."})]}),(0,n.jsxs)("div",{className:"space-y-4 py-4",children:[(0,n.jsx)("div",{className:"rounded-md bg-admin-warning/15 border border-admin-warning/30 p-4",children:(0,n.jsx)("p",{className:"text-sm text-admin-warning",children:"El contracargo queda registrado y entra a la cola de Contracargos. No cambia el estado del invoice ni bloquea el cobro autom\xe1tico."})}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"chargeback-amount",children:"Monto a Contracargar"}),(0,n.jsx)(q.I,{id:"chargeback-amount",type:"number",value:eu,onChange:e=>em(e.target.value),placeholder:"Ej: 28586"})]}),(0,n.jsxs)("div",{children:[(0,n.jsx)(A._,{htmlFor:"chargeback-reason",children:"Motivo del Contracargo"}),(0,n.jsx)(O.g,{id:"chargeback-reason",value:ex,onChange:e=>eh(e.target.value),placeholder:"Describe el motivo del contracargo"})]})]}),(0,n.jsxs)(T.cN,{children:[(0,n.jsx)(F.z,{variant:"outline",onClick:()=>er(!1),children:"Cancelar"}),(0,n.jsx)(F.z,{onClick:()=>void handleCreateChargeback(),disabled:eR.isLoading,children:eR.isLoading?"Registrando...":"Registrar Contracargo"})]})]})})]})},["staff"])},66682:function(e,a,s){"use strict";s.d(a,{qN:function(){return useAdminInvoiceQuery},SK:function(){return useAdminInvoicesQuery},s4:function(){return useInvoiceHistoryQuery}});var n=s(7040),t=s(53538),i=s(44994),r=s(13346),l=s(67669),d=s(14016);let o=t.Ry({id:t.Z_(),document_number:t.Z_().nullable(),readable_id:t.Z_().nullable()}),c=t.Ry({id:t.Rx(),email:t.Z_(),rut:t.Z_()}),u=t.Ry({id:t.Rx(),amount:t.Rx(),created_at:t.Z_(),comment:t.Z_().nullable()}),m=t.Ry({id:t.Rx(),payment_processor:t.Z_(),status:t.Z_(),external_payment_id:t.Z_().nullable(),amount_clp:t.Rx(),error_message:t.Z_().nullable(),processor_status:t.Z_().nullable(),created_at:t.Z_()}),x=t.Ry({id:t.Rx(),nullified_amount:t.Rx(),authorization_date:t.Z_().nullable(),authorization_code:t.Z_().nullable(),type:t.Z_().nullable(),payment_processor:t.Z_(),balance:t.Rx().nullable(),response_code:t.Rx().nullable(),created_at:t.Z_(),mp_refund_id:t.Z_().nullable(),incoming_settlement:u.nullable(),outgoing_settlement:u.nullable()}),h=t.Ry({id:t.Rx(),external_id:t.Z_().nullable(),amount:t.Rx().nullable(),status:t.Z_().nullable(),payment_processor:t.Z_(),created_at:t.Z_(),incoming_settlement_id:t.Rx().nullable(),outgoing_settlement_id:t.Rx().nullable(),refunds_count:t.Rx(),mp_payment_id:t.Z_().nullable(),mp_payment_method_id:t.Z_().nullable(),mp_payment_type_id:t.Z_().nullable(),mp_status:t.Z_().nullable(),mp_status_detail:t.Z_().nullable(),incoming_settlement:u.nullable(),outgoing_settlement:u.nullable(),refunds:t.IX(x)}),p=t.Ry({id:t.Rx(),status:t.Z_(),amount:t.Rx().nullable(),price:t.Rx().nullable(),interest_rate:t.Rx().nullable(),due_date:t.Z_().nullable(),toku_invoice_id:t.Z_().nullable(),policy:o.nullable(),user:c.nullable(),payments:t.IX(h),payment_intents:t.IX(m),is_fully_cacttus_paid:t.O7(),has_chargeback:t.O7().default(!1),chargeback_date:t.Z_().nullish(),chargeback_reason:t.Z_().nullish()}),j=t.Ry({id:t.Rx(),status:t.Z_(),amount:t.Rx(),price:t.Rx().nullable(),due_date:t.Z_().nullable(),paid_at:t.Z_().nullable(),created_at:t.Z_(),policy_id:t.Z_().nullable(),policy_readable_id:t.Z_().nullable(),policy_document_number:t.Z_().nullable(),user_email:t.Z_().nullable(),user_rut:t.Z_().nullable(),payments_count:t.Rx(),refunds_count:t.Rx(),has_incoming_settlement:t.O7(),has_outgoing_settlement:t.O7(),fee_payment_number:t.Rx().nullable(),fee_payment_type:t.Rx().nullable()}),g=t.Ry({items:t.IX(j),total_items:t.Rx(),page:t.Rx(),page_size:t.Rx(),total_pages:t.Rx()});function useAdminInvoicesQuery(e){return(0,n.a)({queryKey:l.a.adminInvoices.list(e),queryFn:async()=>{let a=r.Z.admin.invoices.list(e),s=await (0,i.h)(g,{method:"get",url:a});return s.data},keepPreviousData:!0,meta:{onError:d.rj}})}let _=t.Ry({date:t.Z_(),field:t.Z_(),old_value:t.Z_().nullable(),new_value:t.Z_().nullable(),user_email:t.Z_().nullable(),source:t.Z_().nullish()}),f=t.Ry({history:t.IX(_)});function useInvoiceHistoryQuery(e){return(0,n.a)({queryKey:["invoiceHistory",String(e)],queryFn:async()=>
1{if(!e)throw Error("Invoice ID is required");let a=await (0,i.h)(f,{method:"get",url:r.Z.admin.invoices.history(e)},{failSilently:!1});return a.data},enabled:!!e})}function useAdminInvoiceQuery(e){return(0,n.a)({queryKey:l.a.adminInvoices.show(e),queryFn:async()=>{if(!e)throw Error("Invoice ID is required");let a=r.Z.admin.invoices.show(e),s=await (0,i.h)(p,{method:"get",url:a});return s.data},enabled:!!e,retry:(e,a)=>{var s;return(null==a||null===(s=a.response)||void 0===s||!s.status||!(a.response.status>=400)||!(a.response.status<500))&&e<3},meta:{onError:d.rj},refetchOnWindowFocus:!1,refetchOnMount:!0,staleTime:0})}},98543:function(e,a,s){"use strict";s.d(a,{LD:function(){return d},t4:function(){return o}});var n=s(53538);let t=n.Ry({id:n.Rx(),external_id:n.Z_().nullable(),amount:n.Rx().nullable()}),i=n.Ry({id:n.Z_(),document_number:n.Z_().nullable(),readable_id:n.Z_().nullable()}),r=n.Ry({id:n.Rx(),status:n.Z_(),policy:i.nullable()}),l=n.Ry({id:n.Rx(),email:n.Z_(),rut:n.Z_()}),d=n.Ry({id:n.Rx(),nullified_amount:n.Rx().nullable(),authorization_date:n.Z_().nullable(),payment_processor:n.Z_(),type:n.Z_().nullable(),created_at:n.Z_(),payment:t,invoice:r.nullable(),user:l.nullable(),incoming_settlement_id:n.Rx().nullable(),outgoing_settlement_id:n.Rx().nullable()}),o=n.Ry({page:n.Rx().optional(),page_size:n.Rx().optional(),total_items:n.Rx().optional(),total_pages:n.Rx().optional(),items:n.IX(d).optional(),count:n.Rx().optional(),next:n.Z_().nullable().optional(),previous:n.Z_().nullable().optional(),results:n.IX(d).optional()})}},function(e){e.O(0,[6495,8897,2128,95,7127,8857,9774,2888,179],function(){return e(e.s=78753)}),_N_E=e.O()}]);

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.