import{y as E,b as F,af as I}from"./primevue-CfIk0_DY.js";import{C as M}from"./ComboDynamique-BzWI4ISP.js";import{s as Q}from"./selectDate-Dai2cu2_.js";import{a as i,o as H,h as R,j as U,H as L,b as j,c as J,d as a,v as r,a7 as g,t as K,E as O,y as p}from"./vue-core-Di3IuVqe.js";import{u as X,s as o,S as D,o as v,b as x}from"./index-BxIwIJfy.js";import"./moment-BeHQNF8T.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";const Y={class:"page-wrapper flex flex-col min-w-full",style:{height:"calc(100vh - 60px)"}},Z={class:"flex flex-wrap items-end gap-3 p-2"},ee={style:{width:"230px"}},te={style:{width:"220px"}},ae={style:{width:"220px"}},le={style:{width:"200px"}},se={class:"ml-auto flex items-center gap-4 whitespace-nowrap"},oe={class:"font-bold text-omag text-lg"},ie={class:"flex-1 min-h-0 p-2"},re={class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},ne=627,ge={__name:"ConsommationSite",setup(ue){const{showError:C,showWarn:A}=X(),c=O({lecture:!1}),d=i([]),h=i(0),b=i(0),n=i("site"),_=i(o.state.dossier.dated),w=i(o.state.dossier.datef),S=i(null),V=[{label:"Par site",value:"site"},{label:"Par affaire / marché",value:"affaire"},{label:"Par article",value:"article"},{label:"Détail",value:"detail"}],N=p(()=>d.value.reduce((t,e)=>t+(e.qte||0),0)),$=p(()=>d.value.reduce((t,e)=>t+(e.valeur||0),0)),q=p(()=>{if(n.value==="detail")return d.value;const t=n.value,e=new Map;for(const s of d.value){const l=t==="site"?s.site||"(site inconnu)":t==="affaire"?s.affaire||"(sans affaire)":s.libelle||s.code_art,f=e.get(l)||{groupe:l,qte:0,valeur:0};f.qte+=s.qte||0,f.valeur+=s.valeur||0,e.set(l,f)}return[...e.values()].sort((s,l)=>l.valeur-s.valeur)}),k=p(()=>{const t={field:"qte",headerName:"Qté consommée",width:160,type:"rightAligned",valueFormatter:l=>v(l.value)},e={field:"valeur",headerName:"Coût (PMP HT)",width:160,type:"rightAligned",valueFormatter:l=>v(l.value),cellStyle:{fontWeight:"bold"}};return n.value==="detail"?[{field:"site",headerName:"Site",flex:1,minWidth:160},{field:"affaire",headerName:"Affaire / marché",flex:1,minWidth:160},{field:"code_art",headerName:"Code",width:120},{field:"libelle",headerName:"Désignation",flex:2,minWidth:220},t,e]:[{field:"groupe",headerName:n.value==="site"?"Site":n.value==="affaire"?"Affaire / marché":"Article",flex:2,minWidth:240},t,e]}),z=i({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),B=t=>{S.value=t.api},P=(t,e)=>{_.value=t,w.value=e,m()},G=async()=>{try{const t=await x.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:ne,mail:o.state.userCloud.mail});c.lecture=!!t.data?.lecture}catch{c.lecture=!1}c.lecture||(A("Vous n'avez pas le droit, veuillez consulter l'administrateur"),D("ConsommationSite"))},m=async()=>{o.state.afficher_in_progress=!0;try{const t=await x.post(`${o.lienApi}/consommationSite/${o.db}`,{dateDu:_.value,dateAu:w.value,Id_site:h.value||0,Id_affaire:b.value||0});d.value=t.data||[]}catch(t){C("Erreur de chargement : "+(t.response?.data?.message||t.message))}finally{o.state.afficher_in_progress=!1}};return H(async()=>{await G(),c.lecture&&await m()}),(t,e)=>{const s=Q,l=M,f=E,y=F,T=I,W=R("ag-grid-vue");return U((j(),J("div",Y,[a("div",Z,[a("div",ee,[e[4]||(e[4]=a("label",{class:"block mb-1"},"Période",-1)),r(s,{onSelectDate:P})]),a("div",te,[e[5]||(e[5]=a("label",{class:"block mb-1"},"Site",-1)),r(l,{modelValue:h.value,"onUpdate:modelValue":[e[0]||(e[0]=u=>h.value=u),m],table:"site",class:"w-full"},null,8,["modelValue"])]),a("div",ae,[e[6]||(e[6]=a("label",{class:"block mb-1"},"Affaire / marché",-1)),r(l,{modelValue:b.value,"onUpdate:modelValue":[e[1]||(e[1]=u=>b.value=u),m],table:"affaire",class:"w-full"},null,8,["modelValue"])]),a("div",le,[e[7]||(e[7]=a("label",{class:"block mb-1"},"Regrouper par",-1)),r(f,{size:"small",modelValue:n.value,"onUpdate:modelValue":e[2]||(e[2]=u=>n.value=u),options:V,optionLabel:"label",optionValue:"value",class:"w-full"},null,8,["modelValue"])]),r(y,{size:"small",icon:"pi pi-refresh",label:"Actualiser",onClick:m}),r(y,{size:"small",text:"",icon:"pi pi-times",label:"Fermer",onClick:e[3]||(e[3]=u=>g(D)("ConsommationSite"))}),a("div",se,[r(T,{label:`Qté consommée : ${g(v)(N.value)}`,icon:"pi pi-box"},null,8,["label"]),a("span",oe,"Coût total : "+K(g(v)($.value)),1)])]),a("div",ie,[a("div",re,[r(W,{rowData:q.value,columnDefs:k.value,defaultColDef:z.value,theme:t.$agGridTheme,localeText:t.$agGridLocale,onGridReady:B,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText"])])])],512)),[[L,c.lecture]])}}};export{ge as default};
