import{_ as X}from"./RapportDynamique-xqwJEOK-.js";import{f as Y,o as C,c as Z,b as l,a,z as ee,av as le,i as F,q as se,d as I,aP as te,M as oe,aw as ae,F as ne,r as o,e as re,ar as ie}from"./vendor-BDR7yMJi.js";import{_ as ue}from"./ComboDynamique-DbhbUtR4.js";import{_ as ce}from"./selectDate-Dd47YHbm.js";import{_ as de}from"./FavorisSwitch-DFHH_fud.js";import{u as me,s as n,a as M,S as j}from"./index-BSaHX2oa.js";import{_ as pe}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const fe={class:"flex min-w-full flex-col lg:flex-row lg:items-center gap-2 p-1"},ve={class:"btns flex items-center gap-2 lg:w-1/4 lg:justify-start lg:ml-0"},xe={class:"flex items-center gap-3 lg:w-1/4 lg:justify-end whitespace-nowrap"},_e={class:"flex flex-col gap-4 px-4"},be={class:"flex flex-row gap-3 items-end"},ge={class:"flex flex-col w-48"},he={class:"flex flex-col"},we={class:"flex flex-col w-64"},ye={class:"flex flex-col w-48"},Ce={class:"flex flex-col"},Ve={class:"flex gap-2"},ke={class:"flex items-center gap-1"},$e={class:"flex items-center gap-1"},Ae={class:"flex items-center gap-1"},De={class:"flex items-center gap-1"},Te={class:"flex flex-col justify-end"},Re={style:{height:"calc(100vh - 260px)"}},Be={__name:"CumulDesAchats",props:["code_frs","fermerParRetour","masquerFermer"],setup(P){const{showError:V,showWarn:k,showInfo:$}=me(),f=P,v=o(),A=o(),U=o([]),D=o(),i=o([]),d=o(!1),x=o(""),T=o(""),R=o(""),m=o(null),u=o(null),_=o(!1),b=o(!1),g=o(!1),h=o(!0),r=ie({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),c=o(""),z=re(()=>["Quantité","Montant HT","Montant TTC"]),B=()=>{},q=({selectedRows:s})=>{U.value=s},E=s=>{A.value=s.api},G=(s,e)=>{T.value=s,R.value=e},N=async()=>{try{const e=(await M.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:812,mail:n.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||(k("Vous n'avez pas le droit, veuillez consulter l'administrateur"),j("CumulDesAchats"))}catch(s){V("Une erreur est survenue : "+(s.response?.data?.message||s.message))}finally{n.state.afficher_in_progress=!1}};Y(async()=>{await N(),f.code_frs&&(u.value=f.code_frs),w()});const w=async()=>{n.state.afficher_in_progress=!0;try{c.value=`and cast(date as date) between '${T.value}' and '${R.value}'`;const s=[];_.value&&s.push("'bonrecep'"),b.value&&s.push("'facturef'"),h.value&&s.push("'bretourf'"),g.value&&s.push("'avoirf'"),s.length>0&&(c.value+=` and doc in (${s.join(",")})`),u.value!==null&&(c.value+=` and code_frs='${u.value}'`),m.value!==null&&(c.value+=` and code_art='${m.value}'`);const e=await M.post(`${n.lienApi}/CumulDesAchats/${n.db}`,{condition:c.value,rechercheString:x.value},{headers:{"Content-Type":"application/json"}});i.value=e.data}catch(s){V(`Impossible de récupérer les données
 ${s}`)}finally{n.state.afficher_in_progress=!1}},L=()=>{if(!i.value||i.value.length===0){k("Aucune donnée à imprimer");return}d.value=!0},H=()=>{if(!v.value){$("Grille non initialisée");return}if(i.value.length===0){$("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel(`CumulDesAchats_${n.state.enreg_societe.Nom}_${e}.xlsx`)};return(s,e)=>{const y=ee,Q=le,K=de,O=oe,W=ce,S=ue,p=ae,J=X;return C(),Z(ne,null,[l("div",fe,[l("div",ve,[a(y,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=t=>D.value.toggle(t))}),a(Q,{ref_key:"actionsMenu",ref:D,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>H()},{label:"Imprimer",icon:"pi pi-print",command:()=>L()}],popup:!0},null,8,["model"]),f.masquerFermer?I("",!0):(C(),F(y,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=t=>se(j)("CumulDesAchats"))}))]),e[12]||(e[12]=l("div",{class:"w-full lg:w-2/4"},null,-1)),l("div",xe,[a(K,{fen:"CumulDesAchats",text:"Cumul des achats"})])]),l("div",_e,[l("div",be,[l("div",ge,[e[13]||(e[13]=l("label",{class:"text-sm"},"Recherche",-1)),a(O,{size:"small",modelValue:x.value,"onUpdate:modelValue":e[2]||(e[2]=t=>x.value=t),placeholder:"Rechercher...",class:"w-full",onKeyup:e[3]||(e[3]=te(t=>w(),["enter"]))},null,8,["modelValue"])]),l("div",he,[e[14]||(e[14]=l("label",{class:"text-sm"},"Période",-1)),a(W,{onSelectDate:G})]),l("div",we,[e[15]||(e[15]=l("label",{class:"text-sm"},"Fournisseur",-1)),a(S,{modelValue:u.value,"onUpdate:modelValue":e[4]||(e[4]=t=>u.value=t),placeholder:"Sélectionner...",table:"fournisseur",class:"w-full",size:"small"},null,8,["modelValue"])]),l("div",ye,[e[16]||(e[16]=l("label",{class:"text-sm"},"Article",-1)),a(S,{modelValue:m.value,"onUpdate:modelValue":e[5]||(e[5]=t=>m.value=t),placeholder:"Sélectionner...",table:"article",class:"w-full",size:"small"},null,8,["modelValue"])]),l("div",Ce,[e[21]||(e[21]=l("label",{class:"text-sm"},"Types de documents",-1)),l("div",Ve,[l("div",ke,[a(p,{modelValue:_.value,"onUpdate:modelValue":e[6]||(e[6]=t=>_.value=t),binary:"",inputId:"checkbox_bonrecep"},null,8,["modelValue"]),e[17]||(e[17]=l("label",{for:"checkbox_bonrecep",class:"text-xs cursor-pointer"},"BR",-1))]),l("div",$e,[a(p,{modelValue:b.value,"onUpdate:modelValue":e[7]||(e[7]=t=>b.value=t),binary:"",inputId:"checkbox_facturef"},null,8,["modelValue"]),e[18]||(e[18]=l("label",{for:"checkbox_facturef",class:"text-xs cursor-pointer"},"FF",-1))]),l("div",Ae,[a(p,{modelValue:h.value,"onUpdate:modelValue":e[8]||(e[8]=t=>h.value=t),binary:"",inputId:"checkbox_bretourf"},null,8,["modelValue"]),e[19]||(e[19]=l("label",{for:"checkbox_bretourf",class:"text-xs cursor-pointer"},"BRet",-1))]),l("div",De,[a(p,{modelValue:g.value,"onUpdate:modelValue":e[9]||(e[9]=t=>g.value=t),binary:"",inputId:"checkbox_avoirf"},null,8,["modelValue"]),e[20]||(e[20]=l("label",{for:"checkbox_avoirf",class:"text-xs cursor-pointer"},"AF",-1))])])]),l("div",Te,[e[22]||(e[22]=l("div",{class:"h-2"},null,-1)),a(y,{size:"small",icon:"pi pi-search",label:"Rechercher",class:"whitespace-nowrap",onClick:e[10]||(e[10]=t=>w())})])])]),e[23]||(e[23]=l("div",{class:"h-2"},null,-1)),l("div",Re,[a(pe,{ref_key:"dataGrid",ref:v,"excel-file-name":"Cumul des achats","excel-sheet-name":"Cumul des achats","row-data":i.value,"document-number-fields":["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":z.value,"totals-columns":["Quantité","Montant HT","Montant TTC"],onRowClicked:B,onSelectionChanged:q,onGridReady:E},null,8,["row-data","numeric-columns"])]),d.value?(C(),F(J,{key:0,show:d.value,dataList:i.value,titre:"Cumul des achats",gridApi:A.value,onClose:e[11]||(e[11]=t=>d.value=!1)},null,8,["show","dataList","gridApi"])):I("",!0)],64)}}};export{Be as default};
