import{b as q}from"./primevue-CfIk0_DY.js";import{C as T}from"./ComboDynamique-BzWI4ISP.js";import{u as B,S as h,o as m,b as v,s as t}from"./index-BxIwIJfy.js";import{o as E,h as F,b as g,c as _,d as s,v as i,a7 as b,t as y,p as G,E as I,a as o,y as w}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const M={class:"page-wrapper flex flex-col min-w-full",style:{height:"calc(100vh - 60px)"}},P={class:"flex flex-wrap items-end gap-3 p-2"},W={style:{width:"280px"}},R={class:"ml-auto flex items-center gap-4 whitespace-nowrap"},H={key:0,class:"font-bold text-omag"},L={class:"flex-1 min-h-0 p-2"},Q={class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},ee={__name:"StockParSite",setup(U){const{showError:x,showWarn:C}=B(),r=I({lecture:!1}),D=async()=>{try{const e=await v.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:624,mail:t.state.userCloud.mail});r.lecture=!!e.data?.lecture}catch{r.lecture=!1}r.lecture||(C("Vous n'avez pas le droit, veuillez consulter l'administrateur"),h("StockParSite"))},u=o(0),l=o(!1),n=o([]),p=o(null),k=w(()=>n.value.reduce((e,a)=>e+(a.valeur||0),0)),S=w(()=>[{field:"site",headerName:"Site",flex:1,minWidth:160},{field:"code_art",headerName:"Code",width:130},{field:"libelle",headerName:"Désignation",flex:2,minWidth:220},{field:"qte",headerName:"Quantité",width:130,type:"rightAligned",valueFormatter:e=>m(e.value)},{field:"valeur",headerName:"Valeur",width:140,type:"rightAligned",hide:!l.value,valueFormatter:e=>m(e.value)}]),V=o({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),N=e=>{p.value=e.api},z=()=>{l.value=!l.value,p.value?.setColumnsVisible(["valeur"],l.value)},c=async()=>{t.state.afficher_in_progress=!0;try{const e=await v.post(`${t.lienApi}/stockSite/${t.db}`,{Id_site:u.value||0});n.value=e.data||[]}catch(e){x("Erreur lors du chargement du stock par site : "+(e.response?.data?.message||e.message))}finally{t.state.afficher_in_progress=!1}};return E(async()=>{await D(),r.lecture&&await c()}),(e,a)=>{const A=T,d=q,$=F("ag-grid-vue");return g(),_("div",M,[s("div",P,[s("div",W,[a[2]||(a[2]=s("label",{class:"block mb-1"},"Site",-1)),i(A,{modelValue:u.value,"onUpdate:modelValue":[a[0]||(a[0]=f=>u.value=f),c],table:"site",class:"w-full"},null,8,["modelValue"])]),i(d,{size:"small",icon:"pi pi-refresh",label:"Actualiser",onClick:c}),i(d,{size:"small",text:"",icon:l.value?"pi pi-eye-slash":"pi pi-eye",label:l.value?"Masquer la valeur":"Afficher la valeur",onClick:z},null,8,["icon","label"]),i(d,{size:"small",text:"",icon:"pi pi-times",label:"Fermer",onClick:a[1]||(a[1]=f=>b(h)("StockParSite"))}),s("div",R,[s("span",null,y(n.value.length)+" article(s) en stock",1),l.value?(g(),_("span",H," Valeur totale : "+y(b(m)(k.value)),1)):G("",!0)])]),s("div",L,[s("div",Q,[i($,{rowData:n.value,columnDefs:S.value,defaultColDef:V.value,theme:e.$agGridTheme,localeText:e.$agGridLocale,onGridReady:N,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["rowData","columnDefs","defaultColDef","theme","localeText"])])])])}}};export{ee as default};
