import{b as G,f as W,s as L}from"./primevue-CfIk0_DY.js";import{C as P}from"./ComboDynamique-BzWI4ISP.js";import{o as J,b as C,c as w,j as A,H as D,v as o,l as S,d as l,a7 as j,t as K,p as Q,F as X,E as Y,a,y as Z}from"./vue-core-Di3IuVqe.js";import{S as ee}from"./ag-grid-B5G7j3Qp.js";import{_ as se,u as ae,o as x,b as f,s as t,S as u}from"./index-BxIwIJfy.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const te={class:"flex flex-col gap-4 p-4"},oe={class:"flex flex-col gap-2"},le={class:"flex justify-end gap-2"},ne={key:0,class:"flex justify-center items-center py-8"},ie={key:1,class:"flex flex-col gap-3"},re={class:"ag-theme-quartz",style:{height:"350px",width:"100%"}},ue={class:"flex justify-end items-center gap-2 p-2 border-t"},ce={class:"text-lg font-bold"},de={class:"flex justify-center gap-2"},pe={__name:"saisieMonnaie",setup(me){const{showSuccess:M,showError:v,showWarn:g}=ae(),c=Y({lecture:!1,ajout:!1}),$=async()=>{try{const s=(await f.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:1103,mail:t.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;s&&Object.keys(s).length>0&&(c.lecture=s.lecture,c.ajout=s.ajout),c.lecture||(g("Vous n'avez pas le droit, veuillez consulter l'administrateur"),u("saisieMonnaie"))}catch(e){v("Une erreur est survenue : "+(e.response?.data?.message||e.message))}};J(async()=>{await $()});const b=a(!0),h=a(!1),r=a(null),_=a(null),n=a([]),y=a(!1),k=a(null),E=a(null),V=a([{field:"monnaie",headerName:"Monnaie",width:180,editable:!1,valueFormatter:e=>e.data.isAutre?"Autre":x(e.value),cellStyle:e=>({textAlign:"right",fontWeight:"500",fontStyle:e.data.isAutre?"italic":"normal"})},{field:"nombre",headerName:"Nombre",width:180,editable:!0,cellEditor:"agNumberCellEditor",cellEditorParams:e=>({min:0,precision:e.data.isAutre?2:0}),valueFormatter:e=>e.data.isAutre?x(e.value||0):(e.value||0).toString(),cellStyle:{textAlign:"right"}}]),N=a({sortable:!1,filter:!1,resizable:!1,suppressHeaderMenuButton:!0}),z=a({suppressHorizontalScroll:!1,suppressMovableColumns:!0,rowSelection:"single",animateRows:!1,singleClickEdit:!0,stopEditingWhenCellsLoseFocus:!0}),T=Z(()=>n.value.reduce((e,s)=>e+s.monnaie*(s.nombre||0),0)),B=e=>{E.value=e.api},F=()=>{const e=[...n.value];n.value=e},R=()=>{u("saisieMonnaie")},q=async()=>{if(!r.value){g("Veuillez selectionner une caisse");return}y.value=!0;try{const e=await f.post(`${t.lienApi}/journeeEnCours/${t.db}/${r.value}`);_.value=e.data;const d=(await f.post(`${t.lienApi}/monnaieJournee/${t.db}/${t.state.dbCommun6}/${e.data.n_journee}`)).data.map(i=>({...i,isAutre:!!i.isAutre}));d.some(i=>i.isAutre)||d.push({monnaie:1,nombre:0,isAutre:!0}),n.value=d,b.value=!1,h.value=!0}catch(e){e.response?.status===404&&e.response?.data?.type==="no_journee_ouverte"?(g("Aucune journee ouverte pour cette caisse"),u("saisieMonnaie")):(v(`Erreur lors du chargement des donnees
${e}`),u("saisieMonnaie"))}finally{y.value=!1}},H=async()=>{try{await f.post(`${t.lienApi}/enregistrerMonnaie/${t.db}/${_.value.n_journee}`,{monnaie:n.value},{headers:{"Content-Type":"application/json"}}),M("Monnaie enregistree avec succes"),u("saisieMonnaie")}catch(e){v(`Erreur lors de l'enregistrement
${e}`)}},I=()=>{u("saisieMonnaie")},O=()=>{r.value=null,_.value=null,n.value=[]};return(e,s)=>{const d=P,p=G,i=W,U=L;return C(),w(X,null,[A(o(i,{visible:b.value,"onUpdate:visible":s[1]||(s[1]=m=>b.value=m),modal:"",header:"Selectionner une caisse",style:{width:"400px"},closable:!0},{footer:S(()=>[l("div",le,[o(p,{label:"Annuler",text:"",onClick:R}),o(p,{label:"Valider",onClick:q,disabled:!r.value},null,8,["disabled"])])]),default:S(()=>[l("div",te,[l("div",oe,[s[3]||(s[3]=l("label",{for:"caisse",class:"font-semibold"},"Caisse",-1)),o(d,{id:"caisse",modelValue:r.value,"onUpdate:modelValue":s[0]||(s[0]=m=>r.value=m),placeholder:"Selectionner une caisse",table:"caisse",class:"w-full"},null,8,["modelValue"])])])]),_:1},8,["visible"]),[[D,c.lecture]]),A(o(i,{visible:h.value,"onUpdate:visible":s[2]||(s[2]=m=>h.value=m),modal:"",header:"Saisie monnaie",style:{width:"380px"},closable:!0,onHide:O},{default:S(()=>[y.value?(C(),w("div",ne,[o(U)])):n.value.length>0?(C(),w("div",ie,[l("div",re,[o(j(ee),{ref_key:"gridRef",ref:k,localeText:e.$agGridLocale,rowData:n.value,columnDefs:V.value,defaultColDef:N.value,gridOptions:z.value,onGridReady:B,onCellValueChanged:F,class:"ag-theme-quartz",style:{width:"100%",height:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","gridOptions"])]),l("div",ue,[s[4]||(s[4]=l("span",{class:"font-semibold"},"Total:",-1)),l("span",ce,K(j(x)(T.value)),1)]),l("div",de,[o(p,{label:"Valider",icon:"pi pi-check",severity:"success",onClick:H,class:"w-32"}),o(p,{label:"Annuler",icon:"pi pi-times",severity:"danger",outlined:"",onClick:I,class:"w-32"})])])):Q("",!0)]),_:1},8,["visible"]),[[D,c.lecture]])],64)}}},we=se(pe,[["__scopeId","data-v-5a460d5a"]]);export{we as default};
