import{r as e}from"./chunk-QTnfLwEv.js";import{n as t,t as n}from"./jsx-runtime-BWRPWl8p.js";import{t as r}from"./InputGroup-RC0btxC4.js";import{Da as i,Ei as a,Ia as o,La as s,Li as c,Ma as l,Mn as u,N as d,da as f,ki as p,ma as m}from"./index-DccLTdzK.js";import{r as h}from"./cajaChica-CW1xVsrz.js";var g=e(t(),1),_=n(),v=({setShow:e,balance:t,origen:n})=>{let[v,y]=(0,g.useState)(``),[b,x]=(0,g.useState)(``),[S,C]=(0,g.useState)(``),[w,T]=(0,g.useState)(``),[E,D]=(0,g.useState)(null),O=e=>{D(e.target.files[0])},[k,A]=(0,g.useState)(``),j=()=>{try{l(s(o())).then(e=>{let{data:t}=e;A(t.nombre+`/`+t.email)}).catch(e=>{e.message})}catch(e){console.log(e)}};(0,g.useEffect)(()=>{j()},[]);let M=()=>{let e=new Date,t=e.getFullYear(),n=e.getMonth()+1,r=e.getDate(),i=e.getHours(),a=e.getMinutes(),o=e.getSeconds();return n=n<10?`0${n}`:n,r=r<10?`0${r}`:r,i=i<10?`0${i}`:i,a=a<10?`0${a}`:a,o=o<10?`0${o}`:o,`${t}-${n}-${r} ${i}:${a}:${o}`};(0,g.useEffect)(()=>{n==`comedor`&&(M(),C(`Salida`),y(`Comedor`))},[n]);function N(e){let t=new Date(Date.UTC(e.getFullYear(),e.getMonth(),e.getDate()));t.setUTCDate(t.getUTCDate()+4-(t.getUTCDay()||7));let n=new Date(Date.UTC(t.getUTCFullYear(),0,1));return Math.ceil(((t-n)/864e5+1)/7)}let P=()=>{!v||!b||!S?i.warning(`Datos incompletos`):S===`Salida`?parseFloat(b)<=t?E?d(E,`laboratorio`).then(e=>{let{data:t}=e,{secure_url:n}=t;F(n)}).catch(e=>{console.log(e)}):F(``):i.warning(`La cantidad de salida excede el balance disponible en caja`):E?d(E,`laboratorio`).then(e=>{let{data:t}=e,{secure_url:n}=t;F(n)}).catch(e=>{console.log(e)}):F(``)},F=t=>{try{let n=M();h({idUsuario:k,fechayHora:n,concepto:v,cantidad:b,tipo:S,semana:N(new Date)+`-`+n.split(`-`)[0],tipoGasto:w,fecha:n.split(` `)[0],comprobante:t,estado:`1`}).then(t=>{let{data:n}=t;i.success(n.mensaje),e(!1)})}catch(e){console.log(e)}};return(0,_.jsxs)(`div`,{children:[(0,_.jsxs)(c,{children:[(0,_.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,_.jsx)(f,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,_.jsxs)(c.Label,{children:[`Tipo: `,(0,_.jsx)(`code`,{children:`*`})]})}),(0,_.jsx)(f,{sm:12,md:8,lg:8,children:n==`comedor`?(0,_.jsx)(c.Control,{type:`text`,value:S,onChange:e=>C(e.target.value),disabled:!0}):(0,_.jsxs)(c.Control,{as:`select`,value:S,onChange:e=>C(e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:`Seleccionar`}),(0,_.jsx)(`option`,{value:`Entrada`,children:`Entrada`}),(0,_.jsx)(`option`,{value:`Salida`,children:`Salida`})]})})]}),(0,_.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,_.jsx)(f,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,_.jsxs)(c.Label,{children:[`Concepto: `,(0,_.jsx)(`code`,{children:`*`})]})}),(0,_.jsx)(f,{sm:12,md:8,lg:8,children:(0,_.jsx)(c.Control,{type:`text`,placeholder:`Ingresa el concepto de la operación`,value:v,onChange:e=>y(e.target.value),disabled:n==`comedor`})})]}),(0,_.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,_.jsx)(f,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,_.jsxs)(c.Label,{children:[`Cantidad: `,(0,_.jsx)(`code`,{children:`*`})]})}),(0,_.jsx)(f,{sm:12,md:8,lg:8,children:(0,_.jsxs)(r,{children:[(0,_.jsx)(r.Text,{children:`$`}),(0,_.jsx)(c.Control,{value:b,onChange:e=>{let t=e.target.value;/^\d*\.?\d*$/.test(t)&&x(t)},placeholder:`Ingresa la cantidad de la operación`})]})})]}),n==`comedor`&&(0,_.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,_.jsx)(f,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,_.jsxs)(c.Label,{children:[`Tipo de gasto: `,(0,_.jsx)(`code`,{children:`*`})]})}),(0,_.jsx)(f,{sm:12,md:8,lg:8,children:(0,_.jsxs)(c.Control,{as:`select`,value:w,onChange:e=>T(e.target.value),children:[(0,_.jsx)(`option`,{value:``,children:`Seleccionar`}),(0,_.jsx)(`option`,{value:`dia`,children:`Día`}),(0,_.jsx)(`option`,{value:`semana`,children:`Semana`})]})})]}),(0,_.jsxs)(p,{className:`mb-2 mb-md-4 mb-lg-7`,children:[(0,_.jsx)(f,{sm:12,md:4,lg:4,className:`d-flex align-items-end justify-content-start justify-content-md-end justify-content-lg-end`,children:(0,_.jsx)(c.Label,{children:`Comprobante:`})}),(0,_.jsx)(f,{sm:12,md:8,lg:8,children:(0,_.jsx)(c.Control,{type:`file`,onChange:O,accept:`image/png, image/jpeg, .pdf`})})]})]}),(0,_.jsx)(`div`,{className:`d-flex justify-content-center`,children:(0,_.jsxs)(m,{variant:`success`,onClick:P,children:[(0,_.jsx)(a,{icon:u}),` Registrar`]})})]})};export{v as t};