import{_ as Q}from"./ComboDynamique-DbhbUtR4.js";import{r,f as X,o as p,c as k,b as t,i as _,z as Y,d as m,a as u,av as Z,M as ee,an as se,ap as te,q as le,F as ae,ar as oe}from"./vendor-BDR7yMJi.js";import{u as ie,a as b,s as l,S as A}from"./index-BSaHX2oa.js";import{_ as ne}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const re={key:0},ce={class:"col-12 h-[92vh] rounded"},ue={class:"flex h-full"},de={key:0,class:"flex-1 bg-white"},pe={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},me={class:"w-full bg-white p-3 h-[calc(100vh-180px)]"},fe={class:"grid grid-cols-1 lg:grid-cols-2 gap-4"},ve={class:"col-span-1 mb-3"},ge={class:"p-float-label"},be={class:"col-span-1 mb-3"},_e={class:"p-float-label"},we={class:"mt-4"},he={class:"grid grid-cols-1 lg:grid-cols-2 gap-4"},xe={class:"col-span-1"},ye={class:"p-float-label mb-3"},$e={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},Ce={class:"flex flex-col gap-2 sm:flex-row sm:gap-3 lg:w-1/2 lg:justify-start"},ke={class:"flex flex-wrap gap-2 sm:gap-3"},Ae={style:{height:"calc(100vh - 200px)"}},Re={__name:"Caisse",props:["ndoc"],setup(E){const{confirmAction:T,showError:f,showInfo:w,showWarn:S}=ie(),h=E,j=r(h.ndoc),n=r({}),x=r([]),v=r(!1),y=r(null),d=r(!1),c=r(!1),I=r(""),U=r(""),$=r(),g=r(),B=r([]),o=oe({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),F=({event:s,ndoc:e,rowIndex:a})=>{j.value=e,y.value=a,V()},z=({selectedRows:s})=>{B.value=s},L=s=>{g.value=s.api};X(async()=>{await N(),h.ndoc?(V(),d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):C()});const N=async()=>{try{const e=(await b.post(`${l.lienApi}/verifierDroit/${l.state.dbCommun6}`,{id_utilisateur:l.userId,id_page:220,mail:l.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(o.lecture=e.lecture,o.ajout=e.ajout,o.modif=e.modif,o.supp=e.supp,o.devalidation=e.devalidation,o.validation=e.validation),o.lecture||(S("Vous n'avez pas le droit, veuillez consulter l'administrateur"),A("Caisse"))}catch(s){f(`Une erreur s'est produite lors de la vérification des droits. ${s}`)}},C=async()=>{l.state.afficher_in_progress=!0;try{I.value=U.value;const s=await b.post(`${l.lienApi}/caisse/${l.db}`,{condition:I.value},{headers:{"Content-Type":"application/json"}});x.value=s.data}catch(s){f(`Une erreur est survenue lors de l'affichage des caisses
 ${s}`)}finally{l.state.afficher_in_progress=!1}},D=async()=>{try{const s=await b.post(`${l.lienApi}/AjouterEtRenvoyerCaisse/${l.db}`);n.value=s.data,v.value=!0,d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(s){f(`Une erreur est survenue lors de l'ajout d'une caisse
 ${s}`)}finally{l.state.afficher_in_progress=!1}},G=async()=>{d.value=!0,c.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},q=async()=>{try{const s=`${l.lienApi}/enregistrerCaisse/${l.db}/${n.value.IDcaisse}`;await b.post(s,n.value,{headers:{"Content-Type":"application/json"}}),d.value=!1,c.value=!1}catch(s){const e=s.response?.data?.message||s.message;f("Une erreur est survenue : "+e)}finally{l.state.afficher_in_progress=!1}},O=()=>{d.value=!1,c.value=!1},V=async()=>{try{const s=await b.post(`${l.lienApi}/uncaisse/${l.db}/${j.value}`);n.value=s.data,v.value=!0}catch(s){f(`Une erreur est survenue lors de l'affichage des détails de la caisse
 ${s}`)}finally{l.state.afficher_in_progress=!1}},P=()=>{if(!$.value){w("Grille non initialisée");return}if(x.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");$.value.exportToExcel(`Liste des caisses_${l.state.enreg_societe.Nom}_${e}.xlsx`)},W=()=>{w("Impression de la liste en cours...")},H=async()=>{if(await T({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${l.lienApi}/supprimerCaisse/${l.db}/${n.value.IDcaisse}`;await b.post(e),v.value=!1,d.value=!1,C()}catch(e){const a=e.response?.data?.message||e.message;f("Une erreur est survenue : "+a)}},J=()=>{h.ndoc?A("Caisse"):(v.value=!1,C(),y.value!=null&&g.value&&setTimeout(()=>{const s=g.value.getDisplayedRowCount();if(s>0){const e=Math.min(y.value,s-1),a=g.value.getDisplayedRowAtIndex(e);a&&(g.value.deselectAll(),a.setSelected(!0),g.value.ensureNodeVisible(a,"middle"))}},100))};return(s,e)=>{const a=Y,M=Z,R=ee,K=Q;return p(),k(ae,null,[v.value&&o.lecture?(p(),k("div",re,[t("div",ce,[t("div",ue,[n.value?(p(),k("div",de,[t("div",pe,[c.value?m("",!0):(p(),_(a,{key:0,onClick:e[0]||(e[0]=i=>G()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!o.modif},null,8,["disabled"])),c.value?m("",!0):(p(),_(a,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=i=>s.$refs.actionsMenu.toggle(i)),text:""})),u(M,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:D,disabled:!o.ajout},{label:"Supprimer",icon:"pi pi-trash",class:"text-red-500",command:H,disabled:!o.supp}],popup:!0},null,8,["model"]),c.value?m("",!0):(p(),_(a,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:J})),c.value?(p(),_(a,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=i=>q())})):m("",!0),c.value?(p(),_(a,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=i=>O())})):m("",!0)]),t("div",me,[t("div",fe,[t("div",ve,[t("span",ge,[e[9]||(e[9]=t("label",{for:"idcaisse"},"Numéro",-1)),u(R,{size:"small",id:"idcaisse",modelValue:n.value.IDcaisse,"onUpdate:modelValue":e[4]||(e[4]=i=>n.value.IDcaisse=i),disabled:!0,class:"w-full"},null,8,["modelValue"])])]),t("div",be,[t("span",_e,[e[10]||(e[10]=t("label",{for:"inputFocus"},"Libellé",-1)),u(R,{size:"small",id:"inputFocus",modelValue:n.value.libelle,"onUpdate:modelValue":e[5]||(e[5]=i=>n.value.libelle=i),disabled:!d.value,class:"w-full",maxlength:"50"},null,8,["modelValue","disabled"])])])]),t("div",we,[t("div",he,[t("div",xe,[t("span",ye,[e[11]||(e[11]=t("label",{for:"code_comptable"},"Code comptable",-1)),u(K,{id:"code_comptable",modelValue:n.value.code_comptable,"onUpdate:modelValue":e[6]||(e[6]=i=>n.value.code_comptable=i),placeholder:"Code comptable",table:"compte",disabled:!d.value,class:"w-full"},null,8,["modelValue","disabled"])])])])])])])):m("",!0)])])])):m("",!0),se(t("div",null,[t("div",$e,[t("div",Ce,[t("div",ke,[u(a,{icon:"pi pi-plus",label:"Ajouter",text:"",onClick:D,disabled:!o.ajout},null,8,["disabled"]),u(a,{label:"Actions",icon:"pi pi-cog",onClick:e[7]||(e[7]=i=>s.$refs.actionsMenuList.toggle(i)),text:""}),u(M,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:P},{label:"Imprimer la liste",icon:"pi pi-print",command:W}],popup:!0},null,8,["model"]),u(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[8]||(e[8]=i=>le(A)("caisse"))})])]),e[12]||(e[12]=t("div",{class:"flex items-center gap-3 lg:w-1/2 lg:justify-end whitespace-nowrap"},null,-1))]),t("div",Ae,[u(ne,{ref_key:"dataGrid",ref:$,"excel-file-name":"Caisses","excel-sheet-name":"Caisses","row-data":x.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc","IDcaisse"],"column-widths":{libelle:300},"show-checkbox":!1,onRowClicked:F,onSelectionChanged:z,onGridReady:L},null,8,["row-data"])])],512),[[te,!v.value&&o.lecture]])],64)}}};export{Re as default};
