import{b as S,B as A}from"./primevue-CfIk0_DY.js";import{o as F,b as D,c as G,j as _,H as v,d as u,v as o,a7 as B,F as E,a as n,E as T}from"./vue-core-Di3IuVqe.js";import{u as I,s,b as g,S as h}from"./index-BxIwIJfy.js";import{D as M}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const N={class:"flex flex-row justify-start gap-2"},R={style:{height:"calc(100vh - 200px)"}},J={__name:"facturesCreusesCompta",setup(V){const{showError:p,showWarn:d,showInfo:x}=I(),m=n(),i=n(),C=n(),c=n([]),w=n(null),a=T({lecture:!1,ajout:!1}),y=async()=>{try{const e=(await g.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:2311,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(a.lecture=e.lecture,a.ajout=e.ajout),a.lecture||(d("Vous n'avez pas le droit, veuillez consulter l'administrateur"),h("facturesCreusesCompta"))}catch(t){p("Une erreur est survenue : "+(t.response?.data?.message||t.message))}},b=t=>{C.value=t.api},$=({selectedRows:t})=>{w.value=t[0]||null};F(async()=>{await y(),await f()});const f=async()=>{try{s.state.afficher_in_progress=!0;const{data:t}=await g.post(`${s.lienApi}/SP_FactureCreuseCompta/${s.db}`,{annee_fiscale:s.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});c.value=t.map((e,r)=>({...e,id:e.id||`temp_id_${r}`}))}catch(t){p(t.message||"Une erreur est survenue lors du chargement des données")}finally{s.state.afficher_in_progress=!1}},j=()=>{if(!i.value){x("Grille non initialisée");return}if(c.value.length===0){d("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");i.value.exportToExcel(`Facture_Creuse_${s.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const r=S,k=A;return D(),G(E,null,[_(u("div",N,[o(r,{text:"",icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=l=>f())}),u("div",null,[o(r,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=l=>m.value.toggle(l))}),o(k,{ref_key:"actionsMenu",ref:m,model:[{label:"Exporter vers excel",icon:"pi pi-file-excel",command:()=>j()}],popup:!0},null,8,["model"])]),o(r,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>B(h)("facturesCreusesCompta"))})],512),[[v,a.lecture]]),_(u("div",R,[o(M,{ref_key:"dataGrid",ref:i,"excel-file-name":"Factures creuses compta","excel-sheet-name":"Factures creuses compta","row-data":c.value,"excluded-columns":["id"],onGridReady:b,onSelectionChanged:$},null,8,["row-data"])],512),[[v,a.lecture]])],64)}}};export{J as default};
