import{_ as pe}from"./Imprimer-DluCFs7h.js";import{C as fe}from"./ComboDynamique-BzWI4ISP.js";import{s as ve}from"./selectDate-Dai2cu2_.js";import{_ as ge}from"./FavorisSwitch-BFqqA1tj.js";import{b as _e,B as be}from"./primevue-CfIk0_DY.js";import{u as xe,b as J,s as a,S as M,o as Ce,m as we,A as he}from"./index-BxIwIJfy.js";import{D as Fe}from"./DataGrid-CoMfrBJA.js";import{ak as De,o as ye,b as w,c as U,d as t,v as n,a7 as q,k as G,p as R,F as Ae,y as u,a as o,E as Ve}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 Ne={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Te={class:"btns flex items-center gap-2"},$e={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ke={class:"grid grid-cols-2 sm:grid-cols-3 lg:grid-cols-6 gap-4"},Re={key:0},Se={style:{height:"calc(100vh - 240px)"}},Oe={__name:"JournalDesCommandesFournisseursNonLivrees",props:["code_frs","fermerParRetour","masquerFermer"],setup(Y){const{showError:S,showWarn:I,showInfo:L}=xe(),i=Ve({lecture:!1,ajout:!1,modif:!1,supp:!1,devalidation:!1,validation:!1}),h=Y,F=o(),v=o(),H=o([]),P=o(),p=o([]),Q=o(0),O=o(""),D=o(""),f=o(""),y=o(""),A=o(""),V=o(""),g=o(0),W=u(()=>!!a.state.enreg_option_comm?.numerotation_par_agence),j=u(()=>a.state.userCommun6?.id_agence||0),Z=u(()=>!!a.state.userCommun6?.Access_Agence),K=u(()=>j.value>0&&!Z.value),X=u(()=>W.value),_=o(!1),N=o(0),b=o(""),x=o(""),T=u(()=>a.state.enreg_option_comm?.affichage_prix_doc),ee=u(()=>{const s=["ndoc"],e=T.value;return e==="TTC"?[...s,"pu_ht"]:e==="HT"?[...s,"pu_ttc"]:s}),se=u(()=>{const s=T.value,e=["Quantité","Reçu","Reste"];return s==="TTC"?[...e,"pu_ttc"]:s==="HT"?[...e,"pu_ht"]:[...e,"pu_ht","pu_ttc"]}),te=u(()=>{const s=T.value,e=["Quantité","Reçu","Reste"];return s==="TTC"?[...e,"pu_ttc"]:s==="HT"?[...e,"pu_ht"]:[...e,"pu_ht","pu_ttc"]}),C=o(-1),oe=({ndoc:s,rowIndex:e})=>{s&&(N.value=s,C.value=e,de())},le=({selectedRows:s})=>{H.value=s},ae=s=>{v.value=s.api};De(()=>{v.value&&C.value>=0&&setTimeout(()=>{const s=v.value.getDisplayedRowAtIndex(C.value);s&&s.setSelected(!0,!1,!0),v.value.ensureIndexVisible(C.value,"middle")},50)});const ne=()=>s=>{if(s.value==null||s.value===""||s.value==="null")return"";const e=parseFloat(s.value);if(isNaN(e))return"";const r=Ce(e);return s.node&&s.node?.rowPinned?`<span style="font-weight: 600;">${r}</span>`:`<span class="bg-cyan-50 px-2 py-1 rounded font-medium">${r}</span>`},re=(s,e)=>{b.value=s,x.value=e};ye(async()=>{await ue(),g.value=j.value,h.code_frs&&(f.value=h.code_frs),z()});const ue=async()=>{try{const e=(await J.post(`${a.lienApi}/verifierDroit/${a.state.dbCommun6}`,{id_utilisateur:a.userId,id_page:811,mail:a.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(i.lecture=e.lecture,i.ajout=e.ajout,i.modif=e.modif,i.supp=e.supp,i.devalidation=e.devalidation,i.validation=e.validation),i.lecture||(I("Vous n'avez pas le droit, veuillez consulter l'administrateur"),M("JournalDesCommandesFournisseursNonLivrees"))}catch(s){S("Une erreur est survenue : "+(s.response?.data?.message||s.message))}finally{a.state.afficher_in_progress=!1}},z=async()=>{a.state.afficher_in_progress=!0;try{const s=await J.post(`${a.lienApi}/JournalCommandeNonLivreFournisseur/${a.db}`,{dateDu:b.value,dateAu:x.value,codeArticle:D.value||"",codeFournisseur:f.value||"",idFamille:parseInt(y.value)||0,idSfamille:parseInt(A.value)||0,idAffaire:parseInt(V.value)||0,rechercheString:O.value||"",id_agence:g.value},{headers:{"Content-Type":"application/json"}});p.value=s.data}catch(s){S(`Impossible de récupérer les données
 ${s}`)}finally{a.state.afficher_in_progress=!1}},B=o(""),E=s=>{if(!s)return"";const e=s instanceof Date?s:new Date(s);if(isNaN(e.getTime()))return"";const r=String(e.getDate()).padStart(2,"0"),c=String(e.getMonth()+1).padStart(2,"0"),m=e.getFullYear();return`${r}${c}${m}`},ie=()=>{const s=k=>String(k||"").replace(/[^A-Za-z0-9._-]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),e=s(a.state.enreg_societe?.Nom||""),r=s(f.value),c=E(b.value),m=E(x.value),$=c&&m?`${c}_${m}`:c||m;return["CommandesFrsNonLivrees",e,r,$].filter(Boolean).join("_")},ce=()=>{if(!p.value||p.value.length===0){I("Aucune donnée à imprimer");return}B.value=ie(),_.value=!0},me=()=>{if(!F.value){L("Grille non initialisée");return}if(p.value.length===0){L("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");F.value.exportToExcel(`JournalCommandesFournisseursNonLivrees_${a.state.enreg_societe.Nom}_${e}.xlsx`)},de=async()=>{let s;s=await we.BonDeCommandeFrsLignes(),he({id:"BonDeCommandeFrsLignes",text:`Bon de commande N° : ${N.value}`,content:s.default,props:{ndoc:N.value,fermerParRetour:!0}})};return(s,e)=>{const r=_e,c=be,m=ge,$=ve,d=fe,k=pe;return w(),U(Ae,null,[t("div",Ne,[t("div",Te,[n(r,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>z()),text:"",loading:q(a).state.afficher_in_progress},null,8,["loading"]),n(r,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=l=>P.value.toggle(l))}),n(c,{ref_key:"actionsMenu",ref:P,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>me()},{label:"Imprimer",icon:"pi pi-print",command:()=>ce()}],popup:!0},null,8,["model"]),h.masquerFermer?R("",!0):(w(),G(r,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>q(M)("JournalDesCommandesFournisseursNonLivrees"))}))]),t("div",$e,[n(m,{fen:"JournalDesCommandesFournisseursNonLivrees",text:"Commandes Fournisseurs Non Livrés"})])]),t("div",null,[t("div",ke,[t("div",null,[e[10]||(e[10]=t("label",{class:"block text-sm"},"Période",-1)),n($,{onSelectDate:re,resetCounter:Q.value,size:"small"},null,8,["resetCounter"])]),t("div",null,[e[11]||(e[11]=t("label",{class:"block text-sm"},"Fournisseur",-1)),n(d,{modelValue:f.value,"onUpdate:modelValue":e[3]||(e[3]=l=>f.value=l),placeholder:"Tous les fournisseurs",table:"fournisseur",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[12]||(e[12]=t("label",{class:"block text-sm"},"Article",-1)),n(d,{modelValue:D.value,"onUpdate:modelValue":e[4]||(e[4]=l=>D.value=l),placeholder:"Tous les articles",table:"article",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[13]||(e[13]=t("label",{class:"block text-sm"},"Famille",-1)),n(d,{modelValue:y.value,"onUpdate:modelValue":e[5]||(e[5]=l=>y.value=l),placeholder:"Toutes les familles",table:"famille",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[14]||(e[14]=t("label",{class:"block text-sm"},"Sous-famille",-1)),n(d,{modelValue:A.value,"onUpdate:modelValue":e[6]||(e[6]=l=>A.value=l),placeholder:"Toutes les sous-familles",table:"sfamille",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[15]||(e[15]=t("label",{class:"block text-sm"},"Affaire",-1)),n(d,{modelValue:V.value,"onUpdate:modelValue":e[7]||(e[7]=l=>V.value=l),placeholder:"Toutes les affaires",table:"affaire",class:"w-full",size:"small"},null,8,["modelValue"])]),X.value?(w(),U("div",Re,[e[16]||(e[16]=t("label",{class:"block text-sm"},"Agence",-1)),n(d,{modelValue:g.value,"onUpdate:modelValue":e[8]||(e[8]=l=>g.value=l),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:K.value},null,8,["modelValue","disabled"])])):R("",!0)])]),e[17]||(e[17]=t("div",{class:"h-2"},null,-1)),t("div",Se,[n(Fe,{ref_key:"dataGrid",ref:F,"excel-file-name":"Journal des commandes fournisseurs non livrees","excel-sheet-name":"Journal des commandes fournisseurs non livrees","row-data":p.value,"document-number-fields":["ndoc","Numéro"],"excluded-columns":ee.value,"column-widths":{Date:120,Numéro:150,"Code Frs":120,Nom:250,"Code article":120,libelle:250,pu_ht:120,pu_ttc:120,Quantité:120,Reçu:120,Reste:120,Date_Livraison:120},"custom-renderers":{Reste:ne()},"enable-totals":!0,"numeric-columns":se.value,"totals-columns":te.value,"show-checkbox":!1,onRowClicked:oe,onSelectionChanged:le,onGridReady:ae},null,8,["row-data","excluded-columns","custom-renderers","numeric-columns","totals-columns"])]),_.value?(w(),G(k,{key:0,show:_.value,onClose:e[9]||(e[9]=l=>_.value=!1),data:{Entete:p.value,Periode:`Du ${b.value} au ${x.value}`},modeList:!0,RapportName:"/classique/commercial/JournalCommandeNonLivreFournisseur",nomFichier:B.value},null,8,["show","data","nomFichier"])):R("",!0)],64)}}};export{Oe as default};
