import{_ as M}from"./RapportDynamique-xqwJEOK-.js";import{_ as U}from"./ComboDynamique-DbhbUtR4.js";import{f as L,o as f,c as w,b as t,a as n,z as P,av as T,q as J,ax as O,aS as W,d as V,i as H,F as K,r as o,e as y}from"./vendor-BDR7yMJi.js";import{u as Q,a as A,s as a,S as k}from"./index-BSaHX2oa.js";import{_ as X}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const Y={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},Z={class:"btns flex items-center gap-2 lg:w-1/2 lg:justify-start py-2"},ee={class:"grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-2 mb-4"},le={class:"field"},se={key:0,class:"field"},te={class:"field"},oe={style:{height:"calc(100vh - 220px)"}},me={__name:"ArticlesVivants",setup(ae){const{showError:_,showWarn:u}=Q(),c=o(!1),$=[{label:"30 jours",value:30},{label:"60 jours",value:60},{label:"90 jours",value:90},{label:"6 mois",value:180},{label:"1 an",value:365},{label:"Personnalisé",value:0}],r=o(90),d=o(90),m=o(""),i=o([]),g=o(),h=y(()=>r.value===0?d.value:r.value),p=o(),b=o(),C=o([]),S=y(()=>["qte","Jours inactif"]),j=()=>{},D=({selectedRows:l})=>{C.value=l},R=l=>{b.value=l.api};L(async()=>{await q(),x()});const q=async()=>{try{const e=(await A.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:805,mail:a.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(u("Vous n'avez pas le droit, veuillez consulter l'administrateur"),k("ArticlesVivants")))}catch(l){_(`Une erreur s'est produite lors de la vérification des droits.
 ${l}`)}},x=async()=>{a.state.afficher_in_progress=!0;try{const l=await A.post(`${a.lienApi}/ArticlesVivants/${a.db}`,{jours:h.value,IDfamille:m.value||0},{headers:{"Content-Type":"application/json"}});i.value=l.data}catch(l){const e=l.response?.data?.message||l.message;_(`Une erreur est survenue : ${e}`)}finally{a.state.afficher_in_progress=!1}},F=()=>{if(!i.value||i.value.length===0){u("Aucune donnée à imprimer");return}c.value=!0},I=()=>{if(!p.value){u("Grille non initialisée");return}if(i.value.length===0){u("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Articles_vivants_${a.state.enreg_societe.Nom}_${e}.xlsx`)};return(l,e)=>{const v=P,N=T,z=O,B=W,E=U,G=M;return f(),w(K,null,[t("div",Y,[t("div",Z,[n(v,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=s=>x())}),n(v,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=s=>g.value.toggle(s))}),n(N,{ref_key:"actionsMenu",ref:g,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>I()},{label:"Imprimer",icon:"pi pi-print",command:()=>F()}],popup:!0},null,8,["model"]),n(v,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=s=>J(k)("ArticlesVivants"))})])]),t("div",ee,[t("div",le,[e[7]||(e[7]=t("label",{class:"block text-sm"},"Vendus dans les derniers",-1)),n(z,{modelValue:r.value,"onUpdate:modelValue":e[3]||(e[3]=s=>r.value=s),options:$,optionLabel:"label",optionValue:"value",placeholder:"Sélectionner une période",class:"w-full",size:"small"},null,8,["modelValue"])]),r.value===0?(f(),w("div",se,[e[8]||(e[8]=t("label",{class:"block text-sm"},"Nombre de jours",-1)),n(B,{modelValue:d.value,"onUpdate:modelValue":e[4]||(e[4]=s=>d.value=s),min:1,max:3650,class:"w-full",size:"small"},null,8,["modelValue"])])):V("",!0),t("div",te,[e[9]||(e[9]=t("label",{class:"block text-sm"},"Famille",-1)),n(E,{placeholder:"Famille",table:"famille",modelValue:m.value,"onUpdate:modelValue":e[5]||(e[5]=s=>m.value=s),class:"w-full"},null,8,["modelValue"])])]),e[10]||(e[10]=t("div",{class:"h-2"},null,-1)),t("div",oe,[n(X,{ref_key:"dataGrid",ref:p,"excel-file-name":"Articles vivants","excel-sheet-name":"Articles vivants","row-data":i.value,"document-number-fields":["code_art"],"excluded-columns":["ndoc"],"column-widths":{code_art:120,libelle:380,qte:120,"Dernière Vente":150,"Jours inactif":100},"date-columns":["Dernière Vente"],"enable-totals":!0,"numeric-columns":S.value,"totals-columns":["qte"],onRowClicked:j,onSelectionChanged:D,onGridReady:R},null,8,["row-data","numeric-columns"])]),c.value?(f(),H(G,{key:0,show:c.value,dataList:i.value,titre:"Articles vivants",gridApi:b.value,onClose:e[6]||(e[6]=s=>c.value=!1)},null,8,["show","dataList","gridApi"])):V("",!0)],64)}}};export{me as default};
