import{b as pe,B as me}from"./primevue-CfIk0_DY.js";import{u as he,s as u,b as E,S as T}from"./index-BxIwIJfy.js";import{D as fe}from"./DataGrid-CoMfrBJA.js";import{o as ve,b as r,c as i,d as l,v as x,a7 as ge,G as z,F as v,C as k,f as ye,t as g,p as B,a as m,y,E as be}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const xe={class:"page-wrapper",style:{gap:"0.5rem"}},_e={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},Ce={class:"btns flex items-center gap-2 lg:w-1/4 lg:justify-start lg:ml-0"},ke={key:0,class:"border border-gray-200 rounded-lg p-3 bg-white mx-1"},we={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"},Fe=["width"],$e=["x2"],De=["y1","x2","y2"],Le=["y"],We=["x"],Ge=["x","y","width","height","fill"],Ve={__name:"analyseDesComptes",setup(je){const{showError:L,showInfo:W,showWarn:O}=he(),A=m([]),G=m(),M=m(),S=m(),c=m([]),w=["#3b82f6","#ef4444","#22c55e","#f59e0b","#8b5cf6","#ec4899","#06b6d4","#f97316"],h=be({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()}]),b=["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=>b[t-1]||"",X=t=>(parseFloat(t)||0).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),I=m([...b]),U=m(["CodeCompte","Libelle",...b,"Graphe"]),Y=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}}),q=t=>{if(!t.data)return"";const e=b.map(D=>parseFloat(t.data[D])||0),s=Math.max(...e),n=Math.min(...e),o=s-n||1,a=(t.column?.getActualWidth()||200)-20,p=28,f=2,re=e.map((D,ce)=>{const ue=f+ce*(a-2*f)/11,de=p-f-(D-n)/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="${a}" 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,C=y(()=>Math.max(700,65+12*c.value.length*20+15)),F=y(()=>{let t=0;return c.value.forEach(e=>{b.forEach(s=>{const n=parseFloat(e[s])||0;n>t&&(t=n)})}),t||1}),Q=y(()=>{const t=F.value,e=Math.pow(10,Math.floor(Math.log10(t||1))),s=t/e<2?e/2:t/e<5?e:e*2,n=[];for(let o=0;o<=t;o+=s){const a=d.top+_-o/t*_;n.push({y:a,label:o>=1e3?`${(o/1e3).toLocaleString("fr-FR")}k`:o.toLocaleString("fr-FR")})}return n}),j=y(()=>c.value.length),$=y(()=>{const t=(C.value-d.left-d.right)/12,e=30,s=(t-8)/j.value;return Math.min(s,e)}),N=t=>{const s=(C.value-d.left-d.right)/12;return d.left+s*t+s/2},Z=(t,e)=>{const s=N(t),n=$.value*j.value;return s-n/2+e*$.value},ee=(t,e)=>{const n=(parseFloat(t[e])||0)/F.value*_;return d.top+_-n},te=(t,e)=>(parseFloat(t[e])||0)/F.value*_,oe=({selectedRows:t})=>{c.value=t||[]},se=()=>{c.value=[],S.value&&S.value.deselectAll()},ae=async()=>{try{const e=(await E.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"),T("analyseDesComptes"))}catch(t){L("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{u.state.afficher_in_progress=!1}},ne=t=>{S.value=t.api};ve(async()=>{await ae(),J()});const J=async()=>{u.state.afficher_in_progress=!0,c.value=[];try{const{data:t}=await E.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=pe,n=me;return r(),i("div",xe,[l("div",_e,[l("div",Ce,[x(s,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=o=>J())}),x(n,{ref_key:"actionsMenu",ref:G,popup:!0,model:V.value},null,8,["model"]),x(s,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>G.value.toggle(o))}),x(s,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>ge(T)("analyseDesComptes"))})])]),l("div",{style:z({height:c.value.length>0?"calc(100vh - 480px)":"calc(100vh - 200px)"})},[x(fe,{ref_key:"dataGrid",ref:M,"excel-file-name":"Analyse des comptes","excel-sheet-name":"Analyse des comptes","row-data":K.value,"numeric-columns":I.value,"column-widths":Y.value,"column-order":U.value,"custom-renderers":{Graphe:q},onGridReady:ne,onSelectionChanged:oe},null,8,["row-data","numeric-columns","column-widths","column-order","custom-renderers"])],4),c.value.length>0?(r(),i("div",ke,[l("div",we,[l("h3",Ae,[(r(!0),i(v,null,k(c.value,(o,a)=>(r(),i("span",{key:a},[l("span",{style:z({color:w[a%w.length]}),class:"font-bold"},"●",4),ye(" "+g(o.CodeCompte)+" - "+g(o.Libelle),1),a<c.value.length-1?(r(),i("span",Me," | ")):B("",!0)]))),128))]),x(s,{icon:"pi pi-times",text:"",rounded:"",size:"small",onClick:se})]),l("div",Se,[(r(),i("svg",{width:C.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:C.value-10,y2:190,stroke:"#e5e7eb","stroke-width":"1"},null,8,$e),(r(!0),i(v,null,k(Q.value,(o,a)=>(r(),i(v,{key:"ytick"+a},[l("line",{x1:"60",y1:o.y,x2:C.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,k(H,(o,a)=>l("text",{key:"xlabel"+a,x:N(a),y:206,"text-anchor":"middle",fill:"#6b7280","font-size":"9"},g(o),9,We)),64)),(r(!0),i(v,null,k(c.value,(o,a)=>(r(),i(v,{key:"series"+a},[(r(),i(v,null,k(b,(p,f)=>l("rect",{key:"bar"+a+f,x:Z(f,a),y:ee(o,p),width:$.value,height:te(o,p),fill:w[a%w.length],rx:"2"},[l("title",null,g(o.CodeCompte)+" - "+g(p)+": "+g(X(o[p])),1)],8,Ge)),64))],64))),128))],8,Fe))])])):B("",!0)])}}};export{Ve as default};
