import{b as z,B as R,y as U}from"./primevue-CfIk0_DY.js";import{o as H,w as P,j as K,H as Q,b as X,c as Y,d,v as n,a7 as Z,a as r,E as ee,y as c}from"./vue-core-Di3IuVqe.js";import{u as te,s,b as A,S as G}from"./index-BxIwIJfy.js";import{D as se}from"./DataGrid-CoMfrBJA.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const ae={class:"page-wrapper",style:{gap:"0.5rem"}},oe={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},ne={class:"btns flex items-center gap-2"},re={class:"lg:ml-4"},le={class:"grille-container"},_e={__name:"statisitiqueCompta",setup(ie){const{showError:x,showInfo:w,showWarn:M}=te(),u=ee({lecture:!1,ajout:!1}),T=async()=>{try{const e=(await A.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:2320,mail:s.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(u.lecture=e.lecture,u.ajout=e.ajout),u.lecture||(M("Vous n'avez pas le droit, veuillez consulter l'administrateur"),G("statisitiqueCompta"))}catch(t){x("Une erreur est survenue : "+(t.response?.data?.message||t.message))}},v=r([]),y=r(),f=r(),j=r(),a=r("ecritures"),$=[{name:"Écritures",value:"ecritures"},{name:"Journaux",value:"journaux"},{name:"Trésorerie (Solde)",value:"tresorerie"},{name:"Classe 6",value:"classe6"},{name:"Classe 7",value:"classe7"}],l=["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"],D=c(()=>a.value!=="ecritures"),k=c(()=>a.value==="tresorerie"?[...l]:[...l,"Total"]),q=c(()=>a.value==="tresorerie"?["Libelle",...l,"Graphe"]:["Libelle",...l,"Total","Graphe"]),J=r({Libelle:280,Janvier:85,Février:85,Mars:85,Avril:85,Mai:85,Juin:85,Juillet:85,Août:85,Septembre:85,Octobre:85,Novembre:85,Décembre:85,Total:100,Graphe:{flex:1,minWidth:150}}),C=c(()=>`Statistique_${$.find(e=>e.value===a.value)?.name||"Statistique"}`),N=c(()=>[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>O()}]),V=t=>{if(!t.data)return"";const e=l.map(b=>parseFloat(t.data[b])||0),i=Math.max(...e),m=Math.min(...e),_=i-m||1,o=(t.column?.getActualWidth()||200)-20,g=28,p=2,B=e.map((b,I)=>{const L=p+I*(o-2*p)/11,W=g-p-(b-m)/_*(g-2*p);return`${L},${W}`}).join(" "),S=e[e.length-1]-e[0],F=S>0?"#22c55e":S<0?"#ef4444":"#6b7280";return`<svg width="${o}" height="${g}" style="display:block;">
    <polyline points="${B}" fill="none" stroke="${F}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`},E=t=>{j.value=t.api};H(async()=>{await T(),h()}),P(a,()=>{h()});const h=async()=>{s.state.afficher_in_progress=!0;try{const{data:t}=await A.post(`${s.lienApi}/SP_StatistiqueCompta/${s.db}`,{annee_fiscale:s.state.annee_fiscale,type:a.value},{headers:{"Content-Type":"application/json"}});v.value=t.map(e=>({...e,Graphe:""}))}catch(t){x(`${t.message}`)}finally{s.state.afficher_in_progress=!1}},O=()=>{if(!f.value){w("Grille non initialisée");return}if(v.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");f.value.exportToExcel(`Statistique_${a.value}_${s.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const i=z,m=R,_=U;return K((X(),Y("div",ae,[d("div",oe,[d("div",ne,[n(i,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=o=>h())}),n(m,{ref_key:"actionsMenu",ref:y,popup:!0,model:N.value},null,8,["model"]),n(i,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>y.value.toggle(o))}),n(i,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>Z(G)("statisitiqueCompta"))})]),d("div",re,[n(_,{size:"small",modelValue:a.value,"onUpdate:modelValue":e[3]||(e[3]=o=>a.value=o),options:$,optionLabel:"name",optionValue:"value",class:"w-64"},null,8,["modelValue"])])]),d("div",le,[n(se,{ref_key:"dataGrid",ref:f,"excel-file-name":C.value,"excel-sheet-name":C.value,"row-data":v.value,"numeric-columns":k.value,"column-widths":J.value,"column-order":q.value,"enable-totals":D.value,"totals-columns":k.value,"custom-renderers":{Graphe:V},onGridReady:E},null,8,["excel-file-name","excel-sheet-name","row-data","numeric-columns","column-widths","column-order","enable-totals","totals-columns","custom-renderers"])])],512)),[[Q,u.lecture]])}}};export{_e as default};
