import{_ as I}from"./Imprimer-Bot4QNbk.js";import{u as M,s as a,S as D,g as R,a as y}from"./index-BSaHX2oa.js";import{r,f as z,an as B,ap as E,o as C,c as G,b as s,a as o,q as w,z as N,j as U,av as L,i as O,d as P,ar as W}from"./vendor-BDR7yMJi.js";import{_ as Y}from"./FavorisSwitch-DFHH_fud.js";import{_ as H}from"./DataGrid-DbeHIyBR.js";import"./ReportViewer-Cmd4kpyP.js";import"./EnvoieDocumentsMail-P3u1QAl1.js";import"./useAgGridConfig-DxO2r97K.js";const J={class:"flex min-w-full flex-col"},K={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Q={class:"btns flex items-center gap-2"},X={class:"flex items-center p-2"},Z={class:"p-4"},ee={class:"grid grid-cols-1 md:grid-cols-2 gap-4"},te={style:{height:"calc(100vh - 220px)",width:"100%"}},de={__name:"StatistiqueContrats",setup(ae){const{showInfo:v,showError:b,showWarn:_}=M(),n=W({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),S=r(),d=r(!1),p=r(a.state.dossier?.dated||new Date),m=r(a.state.dossier?.datef||new Date),i=r([]),g=r(),$=r(),k=t=>{$.value=t.api},A=t=>{},q=t=>{},V=async()=>{try{const e=(await y.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:1634,mail:a.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(n.lecture=e.lecture,n.ajout=e.ajout,n.modif=e.modif,n.supp=e.supp,n.devalidation=e.devalidation,n.validation=e.validation),n.lecture||(_("Vous n'avez pas le droit, veuillez consulter l'administrateur"),D("StatistiqueContrats"))}catch(t){b("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{a.state.afficher_in_progress=!1}};z(async()=>{await V()});const F=async()=>{if(!p.value||!m.value){_("Veuillez sélectionner les deux dates (début et fin)");return}a.state.afficher_in_progress=!0;try{const t=u=>{if(!u)return null;const c=new Date(u),h=c.getFullYear(),f=String(c.getMonth()+1).padStart(2,"0"),x=String(c.getDate()).padStart(2,"0");return`${h}-${f}-${x}`},e=await y.post(`${a.lienApi}/StatistiqueContratsAvecPointage/${a.db}`,{DateDebut:t(p.value),DateFin:t(m.value)},{headers:{"Content-Type":"application/json"}});i.value=e.data,i.value.length===0&&v("Aucune donnée trouvée pour la période sélectionnée")}catch(t){b(`Une erreur est survenue lors du chargement des données: ${t.message}`)}finally{a.state.afficher_in_progress=!1}},j=()=>{if(!i.value||i.value.length===0){_("Aucune donnée à imprimer. Veuillez d'abord afficher les données.");return}d.value=!0},T=()=>{if(!g.value){v("Grille non initialisée");return}if(i.value.length===0){v("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");g.value.exportToExcel(`Statistique_Contrats_${a.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const u=N,c=Y,h=L,f=R,x=I;return B((C(),G("div",J,[s("div",K,[s("div",Q,[o(u,{icon:"pi pi-search",label:"Afficher",onClick:F,text:"",loading:w(a).state.afficher_in_progress},null,8,["loading"]),o(u,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=l=>S.value?.toggle(l))}),o(h,{ref_key:"actionsMenu",ref:S,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>T()},{label:"Imprimer",icon:"pi pi-print",command:()=>j()},{label:"Favoris",icon:"pi pi-star",template:"favorisTemplate"}],popup:!0},{favorisTemplate:U(()=>[s("div",X,[o(c,{fen:"StatistiqueContrats",text:"Statistique Contrats"}),e[5]||(e[5]=s("span",{class:"font-semibold ml-2 text-primary"},"Favoris",-1))])]),_:1},8,["model"]),o(u,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=l=>w(D)("StatistiqueContrats"))})])]),s("div",Z,[s("div",ee,[s("div",null,[e[6]||(e[6]=s("label",{class:"block text-sm font-medium text-gray-700 mb-1"},"Date début",-1)),o(f,{modelValue:p.value,"onUpdate:modelValue":e[2]||(e[2]=l=>p.value=l),placeholder:"Sélectionner une date de début","input-class":"w-full"},null,8,["modelValue"])]),s("div",null,[e[7]||(e[7]=s("label",{class:"block text-sm font-medium text-gray-700 mb-1"},"Date fin",-1)),o(f,{modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=l=>m.value=l),placeholder:"Sélectionner une date de fin","input-class":"w-full"},null,8,["modelValue"])])])]),e[8]||(e[8]=s("div",{class:"h-2"},null,-1)),s("div",te,[o(H,{ref_key:"dataGrid",ref:g,"excel-file-name":"Statistique contrats","excel-sheet-name":"Statistique contrats","row-data":i.value,"numeric-columns":["nb"],"totals-columns":["nb"],"date-columns":["DateDu","DateAu"],"date-only":["DateDu","DateAu"],"column-widths":{statut:150},onRowClicked:A,onSelectionChanged:q,onGridReady:k},null,8,["row-data"])]),d.value?(C(),O(x,{key:0,show:d.value,onClose:e[4]||(e[4]=l=>d.value=!1),data:i.value,modeList:!0,RapportName:"/rh/StatistiqueContrats",nomFichier:`StatistiqueContrats_${w(a).state.annee_fiscale}`},null,8,["show","data","nomFichier"])):P("",!0)],512)),[[E,n.lecture]])}}};export{de as default};
