import{R as se}from"./RapportDynamique-DI8KNc5X.js";import{b as ae,B as oe,ac as le}from"./primevue-CfIk0_DY.js";import{C as ne}from"./ComboDynamique-BzWI4ISP.js";import{s as re}from"./selectDate-Dai2cu2_.js";import{_ as ie}from"./FavorisSwitch-BFqqA1tj.js";import{u as ue,s as a,b as F,S as M,m as ce,A as de}from"./index-BxIwIJfy.js";import{D as me}from"./DataGrid-CoMfrBJA.js";import{o as pe,b as f,c as $,d as s,v as n,a7 as S,k as q,p as x,y as u,a as o,E as fe}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"./moment-BeHQNF8T.js";import"./vue-cal-DKMVGERa.js";import"./useAgGridConfig-Dp3DkgaV.js";const ve={class:"page-wrapper"},ge={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},be={class:"btns flex items-center gap-2"},_e={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},Ce={class:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-2"},he={key:0},we={class:"grille-container"},Be={__name:"CumulDesAchats",props:["code_frs","fermerParRetour","masquerFermer"],setup(j){const{showError:A,showWarn:y,showInfo:D}=ue(),v=j,g=o(),T=o(),z=o([]),k=o(),i=o([]),m=o(!1),B=o(""),b=o(""),_=o(""),C=o(null),c=o(null),h=o([]),p=o(0),E=u(()=>!!a.state.enreg_option_comm?.numerotation_par_agence),V=u(()=>a.state.userCommun6?.id_agence||0),P=u(()=>!!a.state.userCommun6?.Access_Agence),G=u(()=>V.value>0&&!P.value),H=u(()=>E.value),I=[{label:"Bon Réception",value:"bonrecep"},{label:"Facture Frs",value:"facturef"},{label:"Retour Frs",value:"bretourf"},{label:"Avoir Frs",value:"avoirf"}],r=fe({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),L=u(()=>["Quantité","Montant HT","Montant TTC"]),N=async({event:t})=>{const e=t.data;if(!e)return;const d=await ce.HistoriqueDesMouvements();de({id:"HistoriqueDesMouvements",text:"Historique des mouvements",content:d.default,props:{initArticle:e["Code article"]||void 0,code_frs:e["Code Frs"]||c.value||void 0,initDateDu:b.value,initDateAu:_.value}})},U=({selectedRows:t})=>{z.value=t},Q=t=>{T.value=t.api},O=(t,e)=>{b.value=t,_.value=e},W=async()=>{try{const e=(await F.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:812,mail:a.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(r.lecture=e.lecture,r.ajout=e.ajout,r.modif=e.modif,r.supp=e.supp,r.devalidation=e.devalidation,r.validation=e.validation),r.lecture||(y("Vous n'avez pas le droit, veuillez consulter l'administrateur"),M("CumulDesAchats"))}catch(t){A("Une erreur est survenue : "+(t.response?.data?.message||t.message))}finally{a.state.afficher_in_progress=!1}};pe(async()=>{await W(),p.value=V.value,v.code_frs&&(c.value=v.code_frs),R()});const R=async()=>{a.state.afficher_in_progress=!0;try{const t=await F.post(`${a.lienApi}/CumulDesAchats/${a.db}`,{dateDu:b.value,dateAu:_.value,typesDoc:h.value||[],code_frs:c.value||"",code_art:C.value||"",rechercheString:B.value,id_agence:p.value},{headers:{"Content-Type":"application/json"}});i.value=t.data}catch(t){A(`Impossible de récupérer les données
 ${t}`)}finally{a.state.afficher_in_progress=!1}},J=()=>{if(!i.value||i.value.length===0){y("Aucune donnée à imprimer");return}m.value=!0},K=()=>{if(!g.value){D("Grille non initialisée");return}if(i.value.length===0){D("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");g.value.exportToExcel(`CumulDesAchats_${a.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const d=ae,X=oe,Y=ie,Z=re,w=ne,ee=le,te=se;return f(),$("div",ve,[s("div",ge,[s("div",be,[n(d,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>R()),text:"",loading:S(a).state.afficher_in_progress},null,8,["loading"]),n(d,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=l=>k.value.toggle(l))}),n(X,{ref_key:"actionsMenu",ref:k,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>K()},{label:"Imprimer",icon:"pi pi-print",command:()=>J()}],popup:!0},null,8,["model"]),v.masquerFermer?x("",!0):(f(),q(d,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>S(M)("CumulDesAchats"))}))]),s("div",_e,[n(Y,{fen:"CumulDesAchats",text:"Cumul des achats"})])]),s("div",null,[s("div",Ce,[s("div",null,[e[8]||(e[8]=s("label",{class:"block text-sm"},"Période",-1)),n(Z,{onSelectDate:O,size:"small"})]),s("div",null,[e[9]||(e[9]=s("label",{class:"block text-sm"},"Fournisseur",-1)),n(w,{modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=l=>c.value=l),placeholder:"Tous les fournisseurs",table:"fournisseur",class:"w-full",size:"small"},null,8,["modelValue"])]),s("div",null,[e[10]||(e[10]=s("label",{class:"block text-sm"},"Article",-1)),n(w,{modelValue:C.value,"onUpdate:modelValue":e[4]||(e[4]=l=>C.value=l),placeholder:"Tous les articles",table:"article",class:"w-full",size:"small"},null,8,["modelValue"])]),s("div",null,[e[11]||(e[11]=s("label",{class:"block text-sm"},"Types de documents",-1)),n(ee,{size:"small",modelValue:h.value,"onUpdate:modelValue":e[5]||(e[5]=l=>h.value=l),options:I,optionLabel:"label",optionValue:"value",placeholder:"Tous",display:"chip",maxSelectedLabels:2,class:"w-full"},null,8,["modelValue"])]),H.value?(f(),$("div",he,[e[12]||(e[12]=s("label",{class:"block text-sm"},"Agence",-1)),n(w,{modelValue:p.value,"onUpdate:modelValue":e[6]||(e[6]=l=>p.value=l),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:G.value},null,8,["modelValue","disabled"])])):x("",!0)])]),e[13]||(e[13]=s("div",{class:"h-2"},null,-1)),s("div",we,[n(me,{ref_key:"dataGrid",ref:g,"excel-file-name":"Cumul des achats","excel-sheet-name":"Cumul des achats","row-data":i.value,"document-number-fields":["Code article","ndoc"],"excluded-columns":["ndoc"],"column-widths":{"Code Frs":120,Nom:200,"Code article":130,Libelle:250,Quantité:100,"Montant HT":120,"Montant TTC":120},"enable-totals":!0,"show-checkbox":!1,"numeric-columns":L.value,"totals-columns":["Quantité","Montant HT","Montant TTC"],onRowClicked:N,onSelectionChanged:U,onGridReady:Q},null,8,["row-data","numeric-columns"])]),m.value?(f(),q(te,{key:0,show:m.value,dataList:i.value,titre:"Cumul des achats",gridApi:T.value,onClose:e[7]||(e[7]=l=>m.value=!1)},null,8,["show","dataList","gridApi"])):x("",!0)])}}};export{Be as default};
