import{_ as J}from"./Imprimer-DluCFs7h.js";import{b as X,B as Y,g as ee}from"./primevue-CfIk0_DY.js";import{_ as te}from"./FavorisSwitch-BFqqA1tj.js";import{o as oe,b as i,c as x,d as l,v as r,a7 as h,k as p,I as le,p as se,F as ne,a as n,y as k}from"./vue-core-Di3IuVqe.js";import{u as ie,b as $,s,S as A,m as ae,A as re}from"./index-BxIwIJfy.js";import{D as ue}from"./DataGrid-CoMfrBJA.js";import{_ as D}from"./ArbreMultiSelect-AgriSkO3.js";import{_ as I}from"./MultiComboDynamique-h6wbTTe2.js";import{u as ce}from"./usePackStockColumns-DyT208Q0.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 me={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},pe={class:"btns flex items-center gap-2"},de={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},fe={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-4 mb-2"},ve={class:"sm:col-span-2"},_e={key:0,class:"flex flex-col items-center justify-center p-8 text-center",style:{height:"calc(100vh - 250px)"}},ge={key:1,style:{height:"calc(100vh - 250px)"}},Be={__name:"situationApprovisionnement",setup(xe){const{showError:b,showWarn:R,showInfo:w}=ie(),{enrichirLignes:T,packNumericColumns:F,packExcludedColumns:N,packColumnTitles:B}=ce({qteField:"stock_total"}),E=["code_art","libelle","stock_total","nbCartons","QuantiteCarton"],v=n(),L=n(),y=n(),u=n([]),d=n(""),c=n([]),m=n([]),C=k(()=>!!s.state.enreg_option_comm?.gestion_sfamille_arbre),f=n(!1),S=n(!1),U=k(()=>["stock_total","seuil",...F.value]),j=k(()=>[...N.value]),q=({event:t,ndoc:e})=>{},G=async({data:t})=>{if(!t)return;const e=t.code_art||t.code_art;if(!e)return;const a=await ae.HistoriqueDesMouvements();re({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:a.default,props:{ndoc:e,fermerParRetour:!0}})},M=({selectedRows:t})=>{},z=t=>{L.value=t.api};oe(async()=>{await H(),_()});const H=async()=>{try{const e=(await $.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:606,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(R("Vous n'avez pas le droit, veuillez consulter l'administrateur"),A("SituationApprovisionnement")))}catch(t){b(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},_=async()=>{s.state.afficher_in_progress=!0;try{const t=await $.post(`${s.lienApi}/situationApprovisionnement/${s.db}`,{rechercheLibelle:d.value,IDfamilles:c.value||[],IDsfamilles:m.value||[]},{headers:{"Content-Type":"application/json"}});u.value=T(t.data),S.value=!0}catch{b("Une erreur est survenue lors du chargement des données.")}finally{s.state.afficher_in_progress=!1}},V=n(""),O=()=>{const t=g=>String(g||"").replace(/[^A-Za-z0-9._-]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),e=t(s.state.enreg_societe?.Nom||""),a=t(d.value);return["SituationApprovisionnement",e,a].filter(Boolean).join("_")},K=()=>{V.value=O(),f.value=!0},P=()=>{if(!v.value){w("Grille non initialisée");return}if(u.value.length===0){w("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel(`Situation_approvisionnement_${s.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const a=X,g=Y,Q=te,W=ee,Z=J;return i(),x(ne,null,[l("div",me,[l("div",pe,[r(a,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=o=>_()),text:"",loading:h(s).state.afficher_in_progress},null,8,["loading"]),r(a,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>y.value.toggle(o))}),r(g,{ref_key:"actionsMenu",ref:y,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>P()},{label:"Imprimer",icon:"pi pi-print",command:()=>K()}],popup:!0},null,8,["model"]),r(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>h(A)("SituationApprovisionnement"))})]),l("div",de,[r(Q,{fen:"SituationApprovisionnement",text:"Situation d'approvisionnement"})])]),l("div",null,[l("div",fe,[l("div",null,[e[10]||(e[10]=l("label",{class:"block text-sm"},"Famille",-1)),C.value?(i(),p(D,{key:0,modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=o=>c.value=o),source:"famille",cle:"IDfamille",unite:"famille",placeholder:"Toutes les familles"},null,8,["modelValue"])):(i(),p(I,{key:1,modelValue:c.value,"onUpdate:modelValue":e[4]||(e[4]=o=>c.value=o),placeholder:"Toutes les familles",table:"famille",class:"w-full"},null,8,["modelValue"]))]),l("div",null,[e[11]||(e[11]=l("label",{class:"block text-sm"},"Sous-famille",-1)),C.value?(i(),p(D,{key:0,modelValue:m.value,"onUpdate:modelValue":e[5]||(e[5]=o=>m.value=o),source:"sfamille",cle:"IDsfamille",parent:"IDsfamille_parent",unite:"sous-famille",placeholder:"Toutes les sous-familles"},null,8,["modelValue"])):(i(),p(I,{key:1,modelValue:m.value,"onUpdate:modelValue":e[6]||(e[6]=o=>m.value=o),placeholder:"Toutes les sous-familles",table:"sfamille",class:"w-full"},null,8,["modelValue"]))]),l("div",ve,[e[12]||(e[12]=l("label",{class:"block text-sm"},"Recherche",-1)),r(W,{size:"small",modelValue:d.value,"onUpdate:modelValue":e[7]||(e[7]=o=>d.value=o),placeholder:"Rechercher...",class:"w-full",onKeyup:e[8]||(e[8]=le(o=>_(),["enter"]))},null,8,["modelValue"])])])]),e[14]||(e[14]=l("div",{class:"h-2"},null,-1)),S.value&&u.value.length===0?(i(),x("div",_e,[...e[13]||(e[13]=[l("i",{class:"pi pi-check-circle text-6xl text-green-500 mb-4"},null,-1),l("h3",{class:"text-xl font-semibold text-gray-700 mb-2"},"Aucun article en rupture de stock",-1),l("p",{class:"text-gray-500 max-w-md"}," Cet etat affiche uniquement les articles dont le stock a atteint le seuil d'approvisionnement. Tous vos articles sont actuellement au-dessus de leur seuil minimum. ",-1)])])):(i(),x("div",ge,[r(ue,{ref_key:"dataGrid",ref:v,"excel-file-name":"Situation approvisionnement","excel-sheet-name":"Situation approvisionnement","row-data":u.value,"document-number-fields":["ndoc"],"excluded-columns":j.value,"enable-totals":!0,"numeric-columns":U.value,"totals-columns":["stock_total","seuil"],"column-titles":h(B),"column-order":E,"show-checkbox":!1,onRowClicked:q,onRowDoubleClicked:G,onSelectionChanged:M,onGridReady:z},null,8,["row-data","excluded-columns","numeric-columns","column-titles"])])),f.value?(i(),p(Z,{key:2,show:f.value,onClose:e[9]||(e[9]=o=>f.value=!1),data:u.value,modeList:!0,RapportName:"/classique/commercial/situationApprovisionnement",nomFichier:V.value},null,8,["show","data","nomFichier"])):se("",!0)],64)}}};export{Be as default};
