import{o as _,c as h,a as t,j as b,b as l,z as G,S as H,s as I,q as S,a8 as O,B as U,d as W,F as L,r as a,e as P}from"./vendor-0kGcmQpG.js";import{_ as J}from"./ComboDynamique-CzrtYPe1.js";import{_ as K,u as Q,h as y,S as p,a as C,s as i}from"./index-Bn9WoKhP.js";const X={class:"flex flex-col gap-4 p-4"},Y={class:"flex flex-col gap-2"},Z={class:"flex justify-end gap-2"},ee={key:0,class:"flex justify-center items-center py-8"},se={key:1,class:"flex flex-col gap-3"},ae={class:"ag-theme-quartz",style:{height:"350px",width:"100%"}},te={class:"flex justify-end items-center gap-2 p-2 border-t"},le={class:"text-lg font-bold"},ne={class:"flex justify-center gap-2"},oe={__name:"saisieMonnaie",setup(ie){const{showSuccess:A,showError:w,showWarn:x}=Q(),f=a(!0),m=a(!1),r=a(null),v=a(null),n=a([]),g=a(!1),D=a(null),M=a(null),$=a([{field:"monnaie",headerName:"Monnaie",width:180,editable:!1,valueFormatter:e=>e.data.isAutre?"Autre":y(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?y(e.value||0):(e.value||0).toString(),cellStyle:{textAlign:"right"}}]),j=a({sortable:!1,filter:!1,resizable:!1,suppressHeaderMenuButton:!0}),k=a({suppressHorizontalScroll:!1,suppressMovableColumns:!0,rowSelection:"single",animateRows:!1,singleClickEdit:!0,stopEditingWhenCellsLoseFocus:!0}),E=P(()=>n.value.reduce((e,s)=>e+s.monnaie*(s.nombre||0),0)),V=e=>{M.value=e.api},N=()=>{const e=[...n.value];n.value=e},z=()=>{p("saisieMonnaie")},B=async()=>{if(!r.value){x("Veuillez selectionner une caisse");return}g.value=!0;try{const e=await C.post(`${i.lienApi}/journeeEnCours/${i.db}/${r.value}`);v.value=e.data;const u=(await C.post(`${i.lienApi}/monnaieJournee/${i.db}/${i.state.dbCommun6}/${e.data.n_journee}`)).data.map(o=>({...o,isAutre:!!o.isAutre}));u.some(o=>o.isAutre)||u.push({monnaie:1,nombre:0,isAutre:!0}),n.value=u,f.value=!1,m.value=!0}catch(e){e.response?.status===404&&e.response?.data?.type==="no_journee_ouverte"?(x("Aucune journee ouverte pour cette caisse"),p("saisieMonnaie")):(w(`Erreur lors du chargement des donnees
${e}`),p("saisieMonnaie"))}finally{g.value=!1}},F=async()=>{try{await C.post(`${i.lienApi}/enregistrerMonnaie/${i.db}/${v.value.n_journee}`,{monnaie:n.value},{headers:{"Content-Type":"application/json"}}),A("Monnaie enregistree avec succes"),p("saisieMonnaie")}catch(e){w(`Erreur lors de l'enregistrement
${e}`)}},R=()=>{p("saisieMonnaie")},T=()=>{r.value=null,v.value=null,n.value=[]};return(e,s)=>{const u=J,c=G,o=H,q=I;return _(),h(L,null,[t(o,{visible:f.value,"onUpdate:visible":s[1]||(s[1]=d=>f.value=d),modal:"",header:"Selectionner une caisse",style:{width:"400px"},closable:!0},{footer:b(()=>[l("div",Z,[t(c,{label:"Annuler",text:"",onClick:z}),t(c,{label:"Valider",onClick:B,disabled:!r.value},null,8,["disabled"])])]),default:b(()=>[l("div",X,[l("div",Y,[s[3]||(s[3]=l("label",{for:"caisse",class:"font-semibold"},"Caisse",-1)),t(u,{id:"caisse",modelValue:r.value,"onUpdate:modelValue":s[0]||(s[0]=d=>r.value=d),placeholder:"Selectionner une caisse",table:"caisse",class:"w-full"},null,8,["modelValue"])])])]),_:1},8,["visible"]),t(o,{visible:m.value,"onUpdate:visible":s[2]||(s[2]=d=>m.value=d),modal:"",header:"Saisie monnaie",style:{width:"380px"},closable:!0,onHide:T},{default:b(()=>[g.value?(_(),h("div",ee,[t(q)])):n.value.length>0?(_(),h("div",se,[l("div",ae,[t(S(O),{ref_key:"gridRef",ref:D,localeText:e.$agGridLocale,rowData:n.value,columnDefs:$.value,defaultColDef:j.value,gridOptions:k.value,onGridReady:V,onCellValueChanged:N,class:"ag-theme-quartz",style:{width:"100%",height:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","gridOptions"])]),l("div",te,[s[4]||(s[4]=l("span",{class:"font-semibold"},"Total:",-1)),l("span",le,U(S(y)(E.value)),1)]),l("div",ne,[t(c,{label:"Valider",icon:"pi pi-check",severity:"success",onClick:F,class:"w-32"}),t(c,{label:"Annuler",icon:"pi pi-times",severity:"danger",outlined:"",onClick:R,class:"w-32"})])])):W("",!0)]),_:1},8,["visible"])],64)}}},de=K(oe,[["__scopeId","data-v-f3a5064e"]]);export{de as default};
