import{C as se}from"./ComboDynamique-BzWI4ISP.js";import{b as oe,y as ne}from"./primevue-CfIk0_DY.js";import{_ as re,u as ie,s as n,S as R,o as f,b as B}from"./index-BxIwIJfy.js";import{a as u,o as ue,h as M,b as g,c as C,d as s,v as c,k as ce,a7 as k,p as T,t as v,G as de,F as pe,y as d}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const me={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},ve={class:"btns flex items-center gap-2 py-2 flex-wrap"},fe={class:"flex items-center gap-3 flex-wrap"},ge={key:0,style:{width:"180px"}},be={key:0,class:"kpi-row"},he={class:"kpi-card"},ye={class:"kpi-label"},Ae={class:"kpi-value"},_e={class:"kpi-card"},Ce={class:"kpi-value"},ke={class:"kpi-card"},we={class:"kpi-value"},xe={class:"kpi-sub"},$e={class:"kpi-card"},Ve={class:"kpi-value kpi-value--text"},De={class:"kpi-sub"},Fe={key:0,style:{height:"100%",width:"100%"}},Te={key:1,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},Ne={__name:"AnalysePareto",props:["masquerFermer"],setup(G){const{showError:V,showWarn:q}=ie(),E=G,U=u(),b=u(),D=u([]),h=u(!1),y=u("Client"),w=u("CA_HT"),A=u("all"),_=u(n.state.annee_fiscale),x=u(0),L=d(()=>!!n.state.enreg_option_comm?.numerotation_par_agence),N=d(()=>n.state.userCommun6?.id_agence||0),H=d(()=>!!n.state.userCommun6?.Access_Agence),I=d(()=>N.value>0&&!H.value),K=d(()=>L.value),j=[{label:"Client",value:"Client"},{label:"Article",value:"Article"},{label:"Famille",value:"Famille"},{label:"Sous-famille",value:"SousFamille"},{label:"Commercial",value:"Commercial"},{label:"Ville",value:"Ville"},{label:"Secteur",value:"Secteur"},{label:"Agence",value:"Agence"}],P=[{label:"CA HT",value:"CA_HT"},{label:"CA TTC",value:"CA_TTC"},{label:"Marge",value:"Marge"},{label:"Quantité",value:"Qte"}],O=[{label:"Tout",value:"all"},{label:"Top 10",value:"top10"},{label:"Top 20",value:"top20"},{label:"Flop 10",value:"flop10"}],$=d(()=>P.find(l=>l.value===w.value)?.label||""),F=d(()=>{const l=y.value,e=w.value,o=new Map;for(const t of D.value){const a=String(t[l]??"—");o.set(a,(o.get(a)||0)+(Number(t[e])||0))}let r=[...o.entries()].map(([t,a])=>({label:t,valeur:a})).filter(t=>t.valeur!==0).sort((t,a)=>a.valeur-t.valeur);const i=r.reduce((t,a)=>t+a.valeur,0);let m=0;return r.forEach((t,a)=>{t.rang=a+1,t.pct=i?t.valeur/i*100:0,m+=t.valeur,t.pctCumul=i?m/i*100:0,t.classe=t.pctCumul<=80?"A":t.pctCumul<=95?"B":"C"}),r}),z=d(()=>{const l=F.value;return A.value==="top10"?l.slice(0,10):A.value==="top20"?l.slice(0,20):A.value==="flop10"?l.slice(-10):l}),p=d(()=>{const l=F.value;if(!l.length)return null;const e=l.reduce((i,m)=>i+m.valeur,0),o=l.filter(i=>i.classe==="A"),r=o.reduce((i,m)=>i+m.valeur,0);return{total:e,nb:l.length,nbA:o.length,partA:e?r/e*100:0,pctElemA:l.length?f(o.length/l.length*100):0}}),Q=({value:l})=>new Intl.NumberFormat("fr-FR",{maximumFractionDigits:0}).format(l),W=d(()=>({data:F.value.slice(0,20).map(e=>({label:e.label,valeur:e.valeur,cumul:Number(e.pctCumul.toFixed(1))})),title:{text:`Pareto — ${$.value} par ${y.value} — ${_.value}`},series:[{type:"bar",xKey:"label",yKey:"valeur",yName:$.value,fill:"#1675C7"},{type:"line",xKey:"label",yKey:"cumul",yName:"% cumulé",stroke:"#ef4444",marker:{fill:"#ef4444",stroke:"#ef4444"}}],axes:[{type:"category",position:"bottom",label:{rotation:-40}},{type:"number",position:"left",keys:["valeur"],label:{formatter:Q}},{type:"number",position:"right",keys:["cumul"],min:0,max:100,label:{formatter:({value:e})=>`${e}%`}}]})),S={A:{bg:"#dcfce7",fg:"#166534"},B:{bg:"#fef9c3",fg:"#854d0e"},C:{bg:"#f1f5f9",fg:"#64748b"}},Y={sortable:!0,filter:!0,resizable:!0,suppressHeaderMenuButton:!0},J=u([{field:"rang",headerName:"Rang",width:90,type:"rightAligned"},{field:"label",headerName:"Élément",flex:1,minWidth:240},{field:"valeur",headerName:"Valeur",width:150,type:"rightAligned",valueFormatter:l=>f(l.value)},{field:"pct",headerName:"%",width:100,type:"rightAligned",valueFormatter:l=>`${f(l.value)} %`},{field:"pctCumul",headerName:"% cumulé",width:120,type:"rightAligned",valueFormatter:l=>`${f(l.value)} %`},{field:"classe",headerName:"Classe",width:100,cellRenderer:l=>{const e=S[l.value]||S.C;return`<span style="background:${e.bg}; color:${e.fg}; padding:2px 10px; border-radius:10px; font-weight:700;">${l.value}</span>`}}]),X=()=>"",Z=l=>{b.value=l.api},ee=()=>{b.value&&b.value.sizeColumnsToFit()},le=async()=>{n.state.afficher_in_progress=!0;try{const l=`${_.value}-01-01`,e=`${_.value+1}-01-01`,o=await B.post(`${n.lienApi}/VentesAPlat/${n.db}`,{DateDebut:l,DateFin:e,id_agence:x.value});D.value=Array.isArray(o.data)?o.data:[]}catch(l){V(`Une erreur s'est produite lors de la récupération des données.
 ${l}`),D.value=[]}finally{n.state.afficher_in_progress=!1}},ae=()=>{if(!b.value||z.value.length===0){V("Aucune donnée à exporter");return}const l=new Date,e=r=>String(r).padStart(2,"0"),o=`${l.getFullYear()}${e(l.getMonth()+1)}${e(l.getDate())}_${e(l.getHours())}${e(l.getMinutes())}`;b.value.exportDataAsExcel({fileName:`Pareto_${y.value}_${n.state.enreg_societe?.Nom||""}_${o}.xlsx`,sheetName:"Pareto ABC"})},te=async()=>{try{const e=(await B.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:827,mail:n.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&!e.lecture&&(q("Vous n'avez pas le droit, veuillez consulter l'administrateur"),R("AnalysePareto"))}catch(l){V("Une erreur est survenue : "+(l.response?.data?.message||l.message))}};return ue(async()=>{await te(),x.value=N.value}),(l,e)=>{const o=oe,r=ne,i=se,m=M("AgCharts"),t=M("ag-grid-vue");return g(),C(pe,null,[s("div",me,[s("div",ve,[c(o,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=a=>le())}),c(o,{icon:h.value?"pi pi-table":"pi pi-chart-bar",label:h.value?"Tableau":"Courbe Pareto",text:"",onClick:e[1]||(e[1]=a=>h.value=!h.value)},null,8,["icon","label"]),c(o,{icon:"pi pi-file-excel",label:"Excel",text:"",onClick:e[2]||(e[2]=a=>ae())}),E.masquerFermer?T("",!0):(g(),ce(o,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[3]||(e[3]=a=>k(R)("AnalysePareto"))}))]),s("div",fe,[c(r,{size:"small",modelValue:y.value,"onUpdate:modelValue":e[4]||(e[4]=a=>y.value=a),options:j,optionLabel:"label",optionValue:"value",placeholder:"Analyser par",style:{width:"150px"}},null,8,["modelValue"]),c(r,{size:"small",modelValue:w.value,"onUpdate:modelValue":e[5]||(e[5]=a=>w.value=a),options:P,optionLabel:"label",optionValue:"value",placeholder:"Mesure",style:{width:"130px"}},null,8,["modelValue"]),c(r,{size:"small",modelValue:A.value,"onUpdate:modelValue":e[6]||(e[6]=a=>A.value=a),options:O,optionLabel:"label",optionValue:"value",style:{width:"130px"}},null,8,["modelValue"]),c(r,{size:"small",modelValue:_.value,"onUpdate:modelValue":e[7]||(e[7]=a=>_.value=a),options:k(n).state.Annees,optionLabel:"Annee",optionValue:"Annee",placeholder:"Année",style:{width:"110px"}},null,8,["modelValue","options"]),K.value?(g(),C("div",ge,[c(i,{modelValue:x.value,"onUpdate:modelValue":e[8]||(e[8]=a=>x.value=a),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:I.value},null,8,["modelValue","disabled"])])):T("",!0)])]),p.value?(g(),C("div",be,[s("div",he,[s("div",ye,"Total "+v($.value),1),s("div",Ae,v(k(f)(p.value.total)),1)]),s("div",_e,[e[9]||(e[9]=s("div",{class:"kpi-label"},"Nombre d'éléments",-1)),s("div",Ce,v(p.value.nb),1)]),s("div",ke,[e[10]||(e[10]=s("div",{class:"kpi-label"},"Classe A (les 20 % vitaux)",-1)),s("div",we,v(p.value.nbA),1),s("div",xe,v(k(f)(p.value.partA))+" % du total",1)]),s("div",$e,[e[11]||(e[11]=s("div",{class:"kpi-label"},"Concentration",-1)),s("div",Ve,v(p.value.pctElemA)+" % des éléments",1),s("div",De,"font "+v(k(f)(p.value.partA))+" % du "+v($.value),1)])])):T("",!0),e[12]||(e[12]=s("div",{class:"h-2"},null,-1)),s("div",{style:de(`height:${p.value?"calc(100vh - 320px)":"calc(100vh - 230px)"}`),class:"mt-2"},[h.value?(g(),C("div",Fe,[c(m,{options:W.value,style:{height:"100%",width:"100%"}},null,8,["options"])])):(g(),C("div",Te,[c(t,{ref_key:"agGrid",ref:U,rowData:z.value,columnDefs:J.value,defaultColDef:Y,theme:l.$agGridTheme,localeText:l.$agGridLocale,getRowClass:X,onGridReady:Z,onFirstDataRendered:ee,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","theme","localeText"])]))],4)],64)}}},qe=re(Ne,[["__scopeId","data-v-da7c8cf9"]]);export{qe as default};
