import{R as J}from"./RapportDynamique-DI8KNc5X.js";import{C as O}from"./ComboDynamique-BzWI4ISP.js";import{b as K,B as W,y as Q,K as X}from"./primevue-CfIk0_DY.js";import{u as Y,b as V,s as o,S as $,m as Z,A as ee}from"./index-BxIwIJfy.js";import{D as te}from"./DataGrid-CoMfrBJA.js";import{o as se,b as f,c as _,d as l,v as n,a7 as oe,p as A,k as le,y as r,a}from"./vue-core-Di3IuVqe.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./useAgGridConfig-Dp3DkgaV.js";const ae={class:"page-wrapper"},ne={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},re={class:"btns flex items-center gap-2 lg:w-1/2 lg:justify-start py-2"},ie={class:"grid grid-cols-1 md:grid-cols-3 lg:grid-cols-4 gap-2 mb-4"},ue={class:"field"},ce={key:0,class:"field"},me={class:"field"},de={key:1,class:"field"},pe={class:"grille-container"},he={__name:"ArticlesDormants",setup(ve){const{showError:x,showWarn:m}=Y(),d=a(!1),h=[{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}],u=a(90),g=a(90),p=a(""),v=a(0),q=r(()=>!!o.state.enreg_option_comm?.numerotation_par_agence),w=r(()=>o.state.userCommun6?.id_agence||0),R=r(()=>!!o.state.userCommun6?.Access_Agence),j=r(()=>w.value>0&&!R.value),S=r(()=>q.value),i=a([]),y=a(),M=r(()=>u.value===0?g.value:u.value),b=a(),k=a(),N=a([]),T=r(()=>["qte","Jours inactif"]),B=async({event:t})=>{const e=t.data;if(!e)return;const c=await Z.HistoriqueDesMouvements();ee({id:"HistoriqueDesMouvements",text:"Historique des mouvements",content:c.default,props:{initArticle:e.code_art,initFamille:p.value||void 0}})},F=({selectedRows:t})=>{N.value=t},G=t=>{k.value=t.api};se(async()=>{await I(),v.value=w.value,C()});const I=async()=>{try{const e=(await V.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:806,mail:o.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(m("Vous n'avez pas le droit, veuillez consulter l'administrateur"),$("ArticlesDormants")))}catch(t){x(`Une erreur s'est produite lors de la vérification des droits
 ${t}`)}},C=async()=>{o.state.afficher_in_progress=!0;try{const t=await V.post(`${o.lienApi}/ArticlesDormants/${o.db}`,{jours:M.value,IDfamille:p.value||0,id_agence:v.value},{headers:{"Content-Type":"application/json"}});i.value=t.data}catch(t){const e=t.response?.data?.message||t.message;x(`Une erreur est survenue : ${e}`)}finally{o.state.afficher_in_progress=!1}},P=()=>{if(!i.value||i.value.length===0){m("Aucune donnée à imprimer");return}d.value=!0},U=()=>{if(!b.value){m("Grille non initialisée");return}if(i.value.length===0){m("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");b.value.exportToExcel(`Articles_dormants_${o.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const c=K,z=W,E=Q,L=X,D=O,H=J;return f(),_("div",ae,[l("div",ne,[l("div",re,[n(c,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=s=>C())}),n(c,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=s=>y.value.toggle(s))}),n(z,{ref_key:"actionsMenu",ref:y,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>U()},{label:"Imprimer",icon:"pi pi-print",command:()=>P()}],popup:!0},null,8,["model"]),n(c,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=s=>oe($)("ArticlesDormants"))})])]),l("div",ie,[l("div",ue,[e[8]||(e[8]=l("label",{class:"block text-sm"},"Non vendus depuis",-1)),n(E,{modelValue:u.value,"onUpdate:modelValue":e[3]||(e[3]=s=>u.value=s),options:h,optionLabel:"label",optionValue:"value",placeholder:"Sélectionner une période",class:"w-full",size:"small"},null,8,["modelValue"])]),u.value===0?(f(),_("div",ce,[e[9]||(e[9]=l("label",{class:"block text-sm"},"Nombre de jours",-1)),n(L,{modelValue:g.value,"onUpdate:modelValue":e[4]||(e[4]=s=>g.value=s),min:1,max:3650,class:"w-full",size:"small"},null,8,["modelValue"])])):A("",!0),l("div",me,[e[10]||(e[10]=l("label",{class:"block text-sm"},"Famille",-1)),n(D,{placeholder:"Famille",table:"famille",modelValue:p.value,"onUpdate:modelValue":e[5]||(e[5]=s=>p.value=s),class:"w-full"},null,8,["modelValue"])]),S.value?(f(),_("div",de,[e[11]||(e[11]=l("label",{class:"block text-sm"},"Agence",-1)),n(D,{placeholder:"Toutes les agences",table:"agence",modelValue:v.value,"onUpdate:modelValue":e[6]||(e[6]=s=>v.value=s),class:"w-full",size:"small",disabled:j.value},null,8,["modelValue","disabled"])])):A("",!0)]),e[12]||(e[12]=l("div",{class:"h-2"},null,-1)),l("div",pe,[n(te,{ref_key:"dataGrid",ref:b,"excel-file-name":"Articles dormants","excel-sheet-name":"Articles dormants","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":T.value,"totals-columns":["qte"],onRowClicked:B,onSelectionChanged:F,onGridReady:G},null,8,["row-data","numeric-columns"])]),d.value?(f(),le(H,{key:0,show:d.value,dataList:i.value,titre:"Articles dormants",gridApi:k.value,onClose:e[7]||(e[7]=s=>d.value=!1)},null,8,["show","dataList","gridApi"])):A("",!0)])}}};export{he as default};
