import{f as pe,o as r,c as i,b as l,a as b,z as me,av as he,q as fe,G as z,F as v,A as C,h as ve,B as g,d as E,r as m,e as y,ar as ge}from"./vendor-BDR7yMJi.js";import{u as ye,s as u,a as T,S as B}from"./index-BSaHX2oa.js";import{_ as xe}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const be={class:"w-full flex flex-col overflow-hidden overflow-y-auto gap-2",style:{height:"calc(100vh - 108px)"}},_e={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},we={class:"btns flex items-center gap-2 lg:w-1/4 lg:justify-start lg:ml-0"},Ce={key:0,class:"border border-gray-200 rounded-lg p-3 bg-white mx-1"},ke={class:"flex justify-between items-center mb-2"},Ae={class:"text-sm font-semibold text-gray-700"},Me={key:0},Se={class:"overflow-x-auto"},$e=["width"],Fe=["x2"],De=["y1","x2","y2"],Le=["y"],We=["x"],je=["x","y","width","height","fill"],Ee={__name:"analyseDesComptes",setup(Ge){const{showError:L,showInfo:W,showWarn:O}=ye(),A=m([]),j=m(),M=m(),S=m(),c=m([]),k=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#f97316"],h=ge({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),V=y(()=>[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>le()}]),x=["Janvier","Février","Mars","Avril","Mai","Juin","Juillet","Août","Septembre","Octobre","Novembre","Décembre"],H=["Jan","Fév","Mar","Avr","Mai","Jun","Jul","Aoû","Sep","Oct","Nov","Déc"],P=t=>x[t-1]||"",X=t=>(parseFloat(t)||0).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),q=m([...x]),I=m(["CodeCompte","Libelle",...x,"Graphe"]),U=m({CodeCompte:90,Libelle:250,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,Graphe:{flex:1,minWidth:150}}),Y=t=>{if(!t.data)return"";const e=x.map(D=>parseFloat(t.data[D])||0),s=Math.max(...e),a=Math.min(...e),o=s-a||1,n=(t.column?.getActualWidth()||200)-20,p=28,f=2,re=e.map((D,ce)=>{const ue=f+ce*(n-2*f)/11,de=p-f-(D-a)/o*(p-2*f);return`${ue},${de}`}).join(" "),R=e[e.length-1]-e[0],ie=R>0?"#22c55e":R<0?"#ef4444":"#6b7280";return`<svg width="${n}" height="${p}" style="display:block;">
    <polyline points="${re}" fill="none" stroke="${ie}" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
  </svg>`},K=y(()=>A.value.map(t=>{const e={CodeCompte:t.CodeCompte,Libelle:t.Libelle};for(let s=1;s<=12;s++)e[P(s)]=t[String(s)];return e.Graphe="",e})),d={left:65,right:15,top:10,bottom:30},_=220-d.top-d.bottom,w=y(()=>Math.max(700,65+12*c.value.length*20+15)),$=y(()=>{let t=0;return c.value.forEach(e=>{x.forEach(s=>{const a=parseFloat(e[s])||0;a>t&&(t=a)})}),t||1}),Q=y(()=>{const t=$.value,e=Math.pow(10,Math.floor(Math.log10(t||1))),s=t/e<2?e/2:t/e<5?e:e*2,a=[];for(let o=0;o<=t;o+=s){const n=d.top+_-o/t*_;a.push({y:n,label:o>=1e3?`${(o/1e3).toLocaleString("fr-FR")}k`:o.toLocaleString("fr-FR")})}return a}),G=y(()=>c.value.length),F=y(()=>{const t=(w.value-d.left-d.right)/12,e=30,s=(t-8)/G.value;return Math.min(s,e)}),N=t=>{const s=(w.value-d.left-d.right)/12;return d.left+s*t+s/2},Z=(t,e)=>{const s=N(t),a=F.value*G.value;return s-a/2+e*F.value},ee=(t,e)=>{const a=(parseFloat(t[e])||0)/$.value*_;return d.top+_-a},te=(t,e)=>(parseFloat(t[e])||0)/$.value*_,oe=({selectedRows:t})=>{c.value=t||[]},se=()=>{c.value=[],S.value&&S.value.deselectAll()},ne=async()=>{try{const e=(await T.post(`${u.lienApi}/verifierDroit/${u.state.dbCommun6}`,{id_utilisateur:u.userId,id_page:2319,mail:u.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(h.lecture=e.lecture,h.ajout=e.ajout,h.modif=e.modif,h.supp=e.supp,h.devalidation=e.devalidation,h.validation=e.validation),h.lecture||(O("Vous n'avez pas le droit, veuillez consulter l'administrateur"),B("analyseDesComptes"))}catch(t){L("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{u.state.afficher_in_progress=!1}},ae=t=>{S.value=t.api};pe(async()=>{await ne(),J()});const J=async()=>{u.state.afficher_in_progress=!0,c.value=[];try{const{data:t}=await T.post(`${u.lienApi}/SP_AnalyseDesComptes/${u.db}`,{annee_fiscale:u.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});A.value=t}catch(t){L(`${t.message}`)}finally{u.state.afficher_in_progress=!1}},le=()=>{if(!M.value){W("Grille non initialisée");return}if(A.value.length===0){W("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");M.value.exportToExcel(`AnalyseDesComptes_${u.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const s=me,a=he;return r(),i("div",be,[l("div",_e,[l("div",we,[b(s,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=o=>J())}),b(a,{ref_key:"actionsMenu",ref:j,popup:!0,model:V.value},null,8,["model"]),b(s,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>j.value.toggle(o))}),b(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>fe(B)("analyseDesComptes"))})])]),l("div",{style:z({height:c.value.length>0?"calc(100vh - 480px)":"calc(100vh - 200px)"})},[b(xe,{ref_key:"dataGrid",ref:M,"excel-file-name":"Analyse des comptes","excel-sheet-name":"Analyse des comptes","row-data":K.value,"numeric-columns":q.value,"column-widths":U.value,"column-order":I.value,"custom-renderers":{Graphe:Y},onGridReady:ae,onSelectionChanged:oe},null,8,["row-data","numeric-columns","column-widths","column-order","custom-renderers"])],4),c.value.length>0?(r(),i("div",Ce,[l("div",ke,[l("h3",Ae,[(r(!0),i(v,null,C(c.value,(o,n)=>(r(),i("span",{key:n},[l("span",{style:z({color:k[n%k.length]}),class:"font-bold"},"●",4),ve(" "+g(o.CodeCompte)+" - "+g(o.Libelle),1),n<c.value.length-1?(r(),i("span",Me," | ")):E("",!0)]))),128))]),b(s,{icon:"pi pi-times",text:"",rounded:"",size:"small",onClick:se})]),l("div",Se,[(r(),i("svg",{width:w.value,height:"220",class:"block mx-auto"},[e[3]||(e[3]=l("line",{x1:"60",y1:"10",x2:"60",y2:190,stroke:"#e5e7eb","stroke-width":"1"},null,-1)),l("line",{x1:"60",y1:190,x2:w.value-10,y2:190,stroke:"#e5e7eb","stroke-width":"1"},null,8,Fe),(r(!0),i(v,null,C(Q.value,(o,n)=>(r(),i(v,{key:"ytick"+n},[l("line",{x1:"60",y1:o.y,x2:w.value-10,y2:o.y,stroke:"#f3f4f6","stroke-width":"1"},null,8,De),l("text",{x:55,y:o.y+4,"text-anchor":"end",fill:"#6b7280","font-size":"10"},g(o.label),9,Le)],64))),128)),(r(),i(v,null,C(H,(o,n)=>l("text",{key:"xlabel"+n,x:N(n),y:206,"text-anchor":"middle",fill:"#6b7280","font-size":"9"},g(o),9,We)),64)),(r(!0),i(v,null,C(c.value,(o,n)=>(r(),i(v,{key:"series"+n},[(r(),i(v,null,C(x,(p,f)=>l("rect",{key:"bar"+n+f,x:Z(f,n),y:ee(o,p),width:F.value,height:te(o,p),fill:k[n%k.length],rx:"2"},[l("title",null,g(o.CodeCompte)+" - "+g(p)+": "+g(X(o[p])),1)],8,je)),64))],64))),128))],8,$e))])])):E("",!0)])}}};export{Ee as default};
