PageSourceSearch

https://talleres.deportesanjoaquin.cl/assets/PaginaVentaNueva-BEGh4xeZ.js

js deportesanjoaquin.cl collected 2026-10-09 17:25:56 UTC 11,375 bytes, 1 lines download raw bytes

1import{u as Oe,c as le,j as a,T as w,z as m,bD as Re,bz as Ie,B as S,aL as we,I as A,a4 as x,cr as Ae,cs as Be,s as B,g as Ge,q as b,C as $e,y as De,D as ie,aD as ke,ct as Ve,a as v,e as y,bK as Fe,bL as Ue,b as p,cu as Me,cv as ce,cw as _e,cx as ze}from"./index-DgTlfza0.js";import{u as Qe,b as t}from"./vendor-1PmRW4tM.js";import{a as Le}from"./PaginaAdmin-CKTN9nF2.js";const He=Me.map(l=>({valor:l,etiqueta:ce[l]})),Ke=Fe.map(l=>({valor:l,etiqueta:Ue[l]})),Je=l=>l.charAt(0).toUpperCase()+l.slice(1),Ze=()=>{var te,oe,re,ne;const l=Qe(),{sesion:q}=Oe(),ue=!!(q!=null&&q.usuario.esAdmin),de=le(e=>v.get("/admin/ventas?limite=1",{signal:e}),[]),[E,G]=t.useState(""),[r,$]=t.useState(null),[me,D]=t.useState(!1),[pe,k]=t.useState(null),[V,F]=t.useState(""),[U,M]=t.useState(""),[_,z]=t.useState(""),[Q,L]=t.useState(""),[H,T]=t.useState(""),[g,K]=t.useState(null),ge=async e=>{e.preventDefault(),D(!0),k(null),u(null);try{const o=await v.post("/admin/ventas/consultar-persona",{rut:E.trim()});$(o),K(null),F(o.nombre??""),M(o.fechaNacimiento?o.fechaNacimiento.slice(0,10):""),z(o.email??""),L(o.telefono??""),T("")}catch(o){$(null),k(y(o)?o.mensaje:"No se pudo consultar el RUT.")}finally{D(!1)}},xe=r?g?((te=r.familiares.find(e=>e.id===g))==null?void 0:te.genero)??null:r.genero:null,j=Ve(xe),J=j??(H||null),s=(()=>{if(!r)return null;if(!g)return{rut:r.rut,nombre:V,fechaNacimiento:U,email:_,telefono:Q,genero:J};const e=r.familiares.find(o=>o.id===g);return e?{rut:e.rut,nombre:e.nombre,fechaNacimiento:"",email:"",telefono:"",genero:J}:null})(),[c,be]=t.useState(""),[h,W]=t.useState(""),[f,X]=t.useState(""),[P,ve]=t.useState(""),d=le(async e=>c?v.get(`/admin/ventas/talleres/${c}`,{signal:e}):null,[c]),[i,u]=t.useState(null),[he,Y]=t.useState(!1),[Z,fe]=t.useState("efectivo"),[ee,je]=t.useState(""),[O,Ne]=t.useState(""),[N,Ce]=t.useState(!1),[ae,Se]=t.useState(""),[ye,C]=t.useState(!1),R=!!(s!=null&&s.rut&&s.nombre&&c&&h&&f),se=async()=>{if(!(!s||!R)){Y(!0);try{u(await v.post("/admin/ventas/simular",{tallerId:c,horarioId:h,plan:f,inscrito:{rut:s.rut,nombre:s.nombre,fechaNacimiento:s.fechaNacimiento||null,genero:s.genero},cupon:P.trim()||null}))}catch(e){u(null),p.error(y(e)?e.mensaje:"No se pudo calcular el precio.")}finally{Y(!1)}}},qe=async()=>{var o;if(!s)return;const e=ze.safeParse({tallerId:c,horarioId:h,plan:f,motivo:ae.trim(),inscrito:{rut:s.rut,nombre:s.nombre,fechaNacimiento:s.fechaNacimiento||null,email:s.email||null,telefono:s.telefono||null,genero:s.genero},observaciones:O.trim()||null});if(!e.success){p.error(((o=e.error.issues[0])==null?void 0:o.message)??"Revisa los datos.");return}C(!0);try{const n=await v.post("/admin/ventas/sin-cobro",e.data);p.exito(`Inscripción ${n.numero} registrada sin cobro`,{descripcion:`Se otorgó un cupo de ${b(n.valorLista)}`}),l("/admin/ventas/historial")}catch(n){p.error(y(n)?n.mensaje:"No se pudo registrar la inscripción.")}finally{C(!1)}},Ee=async()=>{var o;if(!s)return;if(N)return qe();const e=_e.safeParse({tallerId:c,horarioId:h,plan:f,metodoPago:Z,referenciaPago:ee.trim()||null,inscrito:{rut:s.rut,nombre:s.nombre,fechaNacimiento:s.fechaNacimiento||null,email:s.email||null,telefono:s.telefono||null,genero:s.genero},cupon:P.trim()||null,observaciones:O.trim()||null});if(!e.success){p.error(((o=e.error.issues[0])==null?void 0:o.message)??"Revisa los datos.");return}C(!0);try{const n=await v.post("/admin/ventas",e.data);p.exito(`Venta ${n.numero} registrada`,{descripcion:[b(n.montoTotal),n.metodoPago?ce[n.metodoPago]:null].filter(Boolean).join(" · ")}),l("/admin/ventas/historial")}catch(n){p.error(y(n)?n.mensaje:"No se pudo registrar la venta.")}finally{C(!1)}},Te=((oe=d.datos)==null?void 0:oe.horarios)??[],Pe=((re=d.datos)==null?void 0:re.taller.planes)??[],I=((i==null?void 0:i.problemas.length)??0)>0;return a.jsx(Le,{titulo:"Nueva venta",descripcion:"Inscribe y cobra en el mostrador. El precio lo calcula el sistema.",migas:[{etiqueta:"Nueva venta"}],children:a.jsxs("div",{className:"max-w-3xl space-y-6 pb-8",children:[a.jsxs(w,{className:"p-6",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"1 · ¿Quién se inscribe?"}),a.jsx("p",{className:"mt-0.5 text-sm text-muted-foreground",children:"El RUT decide la tarifa: con Tarjeta Vecino vigente paga menos."}),a.jsxs("form",{onSubmit:ge,className:"mt-4 flex items-start gap-2",children:[a.jsx(m,{etiqueta:"RUT",etiquetaOculta:!0,value:E,onChange:e=>G(e.target.value),onBlur:e=>G(Ie(e.target.value)),placeholder:"12.345.678-5",error:pe??void 0,contenedorClassName:"flex-1",icono:a.jsx(Re,{"aria-hidden":"true"}),autoComplete:"off"}),a.jsxs(S,{type:"submit",variante:"contorno",cargando:me,disabled:!E.trim(),children:[a.jsx(we,{"aria-hidden":"true"}),"Consultar"]})]}),r?a.jsxs("div",{className:"mt-4 space-y-4",children:[a.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[a.jsx(A,{tono:r.esVecino?"exito":"neutro",children:r.esVecino?"Tarjeta Vecino vigente":"Sin Tarjeta Vecino"}),r.usuario?a.jsx(A,{tono:"info",children:"Tiene cuenta en el portal"}):a.jsx(A,{tono:"neutro",children:"Sin cuenta: se registra aquí"})]}),r.familiares.length>0?a.jsx(x,{etiqueta:"Se inscribe",opciones:[{valor:"",etiqueta:`${r.nombre??"El titular"} (titular)`},...r.familiares.map(e=>({valor:e.id,etiqueta:`${e.nombre} · ${e.edad} años`}
1))],valor:g??"",alCambiar:e=>{K(e||null),T(""),u(null)},ayuda:"Esta cuenta tiene cargas familiares registradas."}):null,g?null:a.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[a.jsx(m,{etiqueta:"Nombre completo",requerido:!0,value:V,onChange:e=>F(e.target.value),icono:a.jsx(Ae,{"aria-hidden":"true"})}),a.jsx(m,{etiqueta:"Fecha de nacimiento",type:"date",max:new Date().toISOString().slice(0,10),value:U,onChange:e=>M(e.target.value),ayuda:"Necesaria si el taller tiene rango de edad."}),a.jsx(m,{etiqueta:"Correo",type:"email",value:_,onChange:e=>z(e.target.value),ayuda:"Opcional. Para enviarle la boleta."}),a.jsx(m,{etiqueta:"Teléfono",type:"tel",value:Q,onChange:e=>L(e.target.value),ayuda:"Opcional."})]})]}):null]}),r?a.jsxs(w,{className:"p-6",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"2 · ¿Qué taller?"}),a.jsxs("div",{className:"mt-4 space-y-4",children:[a.jsx(x,{etiqueta:"Taller",opciones:(((ne=de.datos)==null?void 0:ne.talleres)??[]).map(e=>({valor:e.id,etiqueta:Be(e)})),valor:c||null,alCambiar:e=>{be(e),W(""),X(""),u(null)},placeholder:"Elige un taller"}),d.datos?a.jsxs(a.Fragment,{children:[d.datos.taller.soloTarjetaVecino?a.jsx(B,{tono:"aviso",titulo:"Solo para vecinos con tarjeta vigente",children:"Este taller no admite inscripciones sin Tarjeta Vecino."}):null,d.datos.taller.soloGenero?a.jsxs("div",{className:"space-y-3",children:[a.jsx(B,{tono:"aviso",titulo:Ge(d.datos.taller.soloGenero,d.datos.taller.edadMax),children:"Este taller solo admite inscripciones de un género."}),a.jsx(x,{etiqueta:"Género de quien se inscribe",opciones:Ke,valor:j??(H||null),alCambiar:e=>{T(e),u(null)},deshabilitado:!!j,placeholder:"Indica el género",ayuda:j?"Es el que figura en su registro. Si está mal, corrígelo desde su ficha en Usuarios.":"No figura en su registro: indícalo para poder comprobar el requisito.",contenedorClassName:"sm:max-w-xs"})]}):null,a.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[a.jsx(x,{etiqueta:"Horario",opciones:Te.map(e=>({valor:e.id,etiqueta:e.cuposIlimitados?`${e.etiqueta} · sin límite`:`${e.etiqueta} · ${e.cuposDisponibles} ${e.cuposDisponibles===1?"cupo":"cupos"}`,deshabilitada:!e.disponible})),valor:h||null,alCambiar:e=>{W(e),u(null)},placeholder:"Elige un horario"}),a.jsx(x,{etiqueta:"Plan",opciones:Pe.map(e=>({valor:e,etiqueta:Je(e)})),valor:f||null,alCambiar:e=>{X(e),u(null)},placeholder:"Elige un plan"})]}),a.jsx(m,{etiqueta:"Cupón",value:P,onChange:e=>ve(e.target.value.toUpperCase()),onBlur:()=>void(R&&se()),ayuda:"Opcional. Si el vecino trae un código.",contenedorClassName:"sm:max-w-xs"})]}):null,a.jsx(S,{variante:"contorno",onClick:()=>void se(),disabled:!R,cargando:he,textoCargando:"Calculando…",children:"Calcular el precio"})]})]}):null,i?a.jsxs(w,{className:"p-6",children:[a.jsx("h2",{className:"text-lg font-semibold",children:"3 · Cobro"}),I?a.jsx(B,{tono:"peligro",titulo:"No se puede cobrar",className:"mt-4",children:a.jsx("ul",{className:"list-inside list-disc space-y-1",children:i.problemas.map(e=>a.jsx("li",{children:e},e))})}):null,a.jsxs("div",{className:"mt-4 rounded-lg border border-border bg-muted/40 p-4",children:[a.jsxs("div",{className:"flex items-baseline justify-between gap-4",children:[a.jsx("span",{className:"text-sm text-muted-foreground",children:"Total a cobrar"}),a.jsx("span",{className:"tabular text-2xl font-semibold",children:i.valorFinal===0?"Gratuito":b(i.valorFinal)})]}),i.totalDescuento>0?a.jsxs("div",{className:"mt-3 space-y-1 border-t border-border pt-3",children:[a.jsxs("p",{className:"flex items-baseline justify-between gap-4 text-sm",children:[a.jsx("span",{className:"text-muted-foreground",children:"Precio de lista"}),a.jsx("span",{className:"tabular line-through text-muted-foreground",children:b(i.valorLista)})]}),i.motivosAhorro.map(e=>a.jsxs("p",{className:"flex items-baseline justify-between gap-4 text-sm",children:[a.jsxs("span",{className:"flex items-center gap-1.5 text-exito",children:[a.jsx($e,{className:"size-4","aria-hidden":"true"}),e.etiqueta]}),a.jsxs("span",{className:"tabular text-exito",children:["−",b(e.monto)]})]},e.etiqueta))]}):null]}),a.jsx(De,{className:"my-5"}),ue?a.jsxs("label",{className:"mb-4 flex cursor-pointer items-start gap-3 rounded-lg border-2 border-border bg-card p-4 transition-colors hover:bg-muted",children:[a.jsx("input",{type:"checkbox",checked:N,onChange:e=>Ce(e.target.checked),className:"mt-0.5 size-4"}),a.jsxs("span",{className:"min-w-0 flex-1",children:[a.jsx("span",{className:"block font-medium",children:"Inscribir sin cobro"}),a.jsx("span",{className:"block text-sm text-muted-foreground",children:"Beca, convenio o cortesía. No se cobra 
1ni se emite boleta, pero ocupa cupo igual que cualquier inscripción."})]})]}):null,N?a.jsx(ie,{etiqueta:"Motivo de la inscripción sin cobro",requerido:!0,value:ae,onChange:e=>Se(e.target.value),ayuda:"Al menos 10 caracteres. Queda registrado con tu nombre."}):a.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[a.jsx(x,{etiqueta:"Método de pago",opciones:He,valor:Z,alCambiar:e=>fe(e)}),a.jsx(m,{etiqueta:"Referencia",value:ee,onChange:e=>je(e.target.value),ayuda:"Número de voucher o folio de la transferencia."})]}),a.jsx(ie,{etiqueta:"Observaciones",className:"mt-4",value:O,onChange:e=>Ne(e.target.value),ayuda:"Opcional. Queda en la ficha de la venta."}),a.jsxs("div",{className:"mt-5 flex flex-col-reverse gap-2 border-t border-border pt-5 sm:flex-row sm:justify-end",children:[a.jsx(S,{type:"button",variante:"contorno",onClick:()=>l("/admin/ventas/historial"),children:"Cancelar"}),a.jsx(S,{onClick:()=>void Ee(),cargando:ye,textoCargando:"Registrando…",disabled:I,children:N?"Inscribir sin cobro":i.valorFinal===0?"Registrar inscripción":`Cobrar ${b(i.valorFinal)}`})]}),I?a.jsxs("p",{className:"mt-3 flex items-start gap-1.5 text-sm text-muted-foreground",children:[a.jsx(ke,{className:"mt-0.5 size-4 shrink-0","aria-hidden":"true"}),"Resuelve lo de arriba y vuelve a calcular el precio."]}):null]}):null]})})};export{Ze as PaginaVentaNueva};

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.