import{r,f as Y,o as m,c as A,b as a,i as x,z as Z,d as f,a as u,av as ee,M as te,aw as se,an as oe,ap as ae,q as le,F as ie,ar as ne}from"./vendor-0kGcmQpG.js";import{u as re,a as b,s,S as C}from"./index-Bn9WoKhP.js";import{_ as de}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const ue={key:0},ce={class:"w-full pb-3 flex flex-row items-center justify-start gap-3 pt-2 ml-2"},me={class:"justify-self-end ml-auto mr-3 font-bold text-xl"},pe={class:"w-full bg-white p-3"},fe={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-4 gap-4"},ve={class:"field"},ge={class:"field"},be={class:"field flex items-center pt-6"},xe={class:"flex flex-col gap-3 sm:flex-row sm:justify-between sm:items-center"},we={class:"flex flex-col gap-2 sm:flex-row sm:gap-3"},ye={class:"flex flex-wrap gap-2 sm:gap-3"},_e={style:{height:"calc(100vh - 220px)"}},$e={key:1,class:"p-4 text-red-600 font-semibold text-center"},Ce={__name:"ModePaiment",props:["ndoc"],setup(N){const{confirmAction:T,showSuccess:j,showError:v,showInfo:w,showWarn:V}=re(),y=N,_=r(y.ndoc),n=r({}),$=r([]),p=r(!1),h=r(null),c=r(!1),d=r(!1),k=r(),g=r(),U=r([]),z=({event:t,ndoc:e,rowIndex:o})=>{t?.target?.closest(".ag-selection-checkbox, .ag-checkbox, input")||(window.getSelection&&window.getSelection().removeAllRanges(),_.value=e,h.value=o,P())},B=({selectedRows:t})=>{U.value=t},F=t=>{g.value=t.api},S=r(""),L=r(""),I=r(!1),l=ne({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1});Y(async()=>{await G(),y.ndoc?(P(),c.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)):M()});const G=async()=>{try{const e=(await b.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:1417,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(l.lecture=e.lecture,l.ajout=e.ajout,l.modif=e.modif,l.supp=e.supp,l.devalidation=e.devalidation,l.validation=e.validation),l.lecture||(V("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("ModePaiment"))}catch(t){v(`Une erreur s'est produite lors de la vérification des droits. ${t}`)}},M=async()=>{s.state.afficher_in_progress=!0;try{p.value=!1,S.value=L.value;const t=await b.post(`${s.lienApi}/modePaiements/${s.db}`,{condition:S.value});$.value=t.data.map(e=>({...e,ndoc:e.id_modepaiement}))}catch(t){v(`Une erreur est survenue lors de l'affichage des modes de paiement ${t}`)}finally{s.state.afficher_in_progress=!1}},R=async()=>{try{const t=await b.post(`${s.lienApi}/AjouterEtRenvoyermodePaiement/${s.db}`);n.value=t.data,_.value=n.value.id_modepaiement,p.value=!0,c.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)}catch(t){v(`Une erreur est survenue lors de l'ajout d'un mode de paiement
 ${t}`)}},O=async()=>{try{if(!n.value.Nom){V("Le nom est obligatoire");return}const t=`${s.lienApi}/enregistrerModePaiement/${s.db}/${n.value.id_modepaiement}`;await b.post(t,n.value,{headers:{"Content-Type":"application/json"}}),c.value=!1,d.value=!1,j("Les modifications ont été enregistrées avec succès")}catch(t){const e=t.response?.data?.message||t.message;v("Une erreur est survenue : "+e)}finally{s.state.afficher_in_progress=!1}},q=()=>{c.value=!1,d.value=!1},W=()=>{if(!k.value){w("Grille non initialisée");return}if($.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Liste des mode de paiements_${s.state.enreg_societe.Nom}_${e}.xlsx`)},H=()=>{w("Impression de la liste en cours...")},P=async()=>{try{const t=await b.post(`${s.lienApi}/unmodePaiement/${s.db}/${_.value}`);n.value=t.data,p.value=!0}catch(t){v(`Une erreur est survenue lors de l'affichage des détails du mode de paiement ${t}`)}},J=async()=>{c.value=!0,d.value=!0,setTimeout(()=>{document.getElementById("inputFocus").focus()},200)},K=async()=>{if(await T({message:"Voulez-vous vraiment supprimer ?"}))try{const e=`${s.lienApi}/supprimerModePaiement/${s.db}/${n.value.id_modepaiement}`;await b.post(e),p.value=!1,c.value=!1,M(),j("Suppression effectuée avec succès")}catch(e){const o=e.response?.data?.message||e.message;v("Une erreur est survenue : "+o)}},Q=()=>{y.ndoc?C("ModePaiment"):(p.value=!1,M(),h.value!=null&&g.value&&setTimeout(()=>{const t=g.value.getDisplayedRowCount();if(t>0){const e=Math.min(h.value,t-1),o=g.value.getDisplayedRowAtIndex(e);o&&(g.value.deselectAll(),o.setSelected(!0),g.value.ensureNodeVisible(o,"middle"))}},100))};return(t,e)=>{const o=Z,E=ee,D=te,X=se;return m(),A(ie,null,[p.value&&l.lecture?(m(),A("div",ue,[a("div",ce,[d.value?f("",!0):(m(),x(o,{key:0,onClick:e[0]||(e[0]=i=>J()),icon:"pi pi-pencil",label:"Modifier",text:"",disabled:!l.modif},null,8,["disabled"])),d.value?f("",!0):(m(),x(o,{key:1,label:"Actions",icon:"pi pi-cog",onClick:e[1]||(e[1]=i=>t.$refs.actionsMenu.toggle(i)),text:""})),u(E,{ref:"actionsMenu",model:[{label:"Ajouter",icon:"pi pi-plus-circle",command:R,disabled:!l.ajout},{label:"Supprimer",icon:"pi pi-trash",command:K,disabled:!l.supp,class:"text-red-500"}],popup:!0},null,8,["model"]),d.value?f("",!0):(m(),x(o,{key:2,icon:"pi pi-arrow-left",label:"Retour",text:"",onClick:Q})),d.value?(m(),x(o,{key:3,icon:"pi pi-save",label:"Enregistrer",text:"",onClick:e[2]||(e[2]=i=>O())})):f("",!0),d.value?(m(),x(o,{key:4,icon:"pi pi-times",label:"Annuler",text:"",onClick:e[3]||(e[3]=i=>q())})):f("",!0),a("div",me,[u(o,{icon:"pi pi-paperclip",text:"",class:"p-button-rounded",onClick:e[4]||(e[4]=i=>I.value=!I.value)})])]),a("div",pe,[a("div",fe,[a("div",ve,[e[10]||(e[10]=a("label",{for:"inputFocus",class:"block mb-1"},"ID ModePaiement",-1)),u(D,{size:"small",id:"inputFocus",modelValue:n.value.id_modepaiement,"onUpdate:modelValue":e[5]||(e[5]=i=>n.value.id_modepaiement=i),disabled:!c.value,class:"w-full"},null,8,["modelValue","disabled"])]),a("div",ge,[e[11]||(e[11]=a("label",{for:"nom",class:"block mb-1"},"Nom",-1)),u(D,{size:"small",id:"nom",modelValue:n.value.Nom,"onUpdate:modelValue":e[6]||(e[6]=i=>n.value.Nom=i),disabled:!c.value,class:"w-full"},null,8,["modelValue","disabled"])]),a("div",be,[u(X,{id:"arrondie",modelValue:n.value.arrondie,"onUpdate:modelValue":e[7]||(e[7]=i=>n.value.arrondie=i),disabled:!c.value,binary:""},null,8,["modelValue","disabled"]),e[12]||(e[12]=a("label",{for:"arrondie",class:"ml-2"},"Arrondie",-1))])])])])):f("",!0),oe(a("div",null,[a("div",xe,[a("div",we,[a("div",ye,[u(o,{icon:"pi pi-plus",label:"Ajouter",onClick:R,text:"",disabled:!l.ajout},null,8,["disabled"]),u(o,{label:"Actions",icon:"pi pi-cog",onClick:e[8]||(e[8]=i=>t.$refs.actionsMenuList.toggle(i)),text:""}),u(E,{ref:"actionsMenuList",model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:W},{label:"Imprimer la liste",icon:"pi pi-print",command:H}],popup:!0},null,8,["model"]),u(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[9]||(e[9]=i=>le(C)("ModePaiment"))})])])]),a("div",_e,[u(de,{ref_key:"dataGrid",ref:k,"excel-file-name":"Mode de paiement","excel-sheet-name":"Mode de paiement","row-data":$.value,"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{id_modepaiement:100,Nom:200,arrondie:100},"enable-totals":!0,onRowClicked:z,onSelectionChanged:B,onGridReady:F},null,8,["row-data"])])],512),[[ae,!p.value&&l.lecture]]),l.lecture?f("",!0):(m(),A("div",$e," Vous n'avez pas le droit, veuillez consulter l'administrateur "))],64)}}};export{Ce as default};
