import{_ as L}from"./Imprimer-CqTc6qE9.js";import{f as N,o as u,c as f,b as o,a as i,q as g,z as j,av as B,aP as G,M as z,i as F,d as H,F as U,r as a,e as K}from"./vendor-0kGcmQpG.js";import{_ as O}from"./FavorisSwitch-DD6nTfzi.js";import{u as P,a as w,s as n,S as b,m as W,A as J}from"./index-Bn9WoKhP.js";import{_ as Q}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const X={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Y={class:"btns flex items-center gap-2"},Z={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ee={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-2"},te={class:"sm:col-span-2"},oe={key:0,class:"flex flex-col items-center justify-center p-8 text-center",style:{height:"calc(100vh - 250px)"}},ne={key:1,style:{height:"calc(100vh - 250px)"}},me={__name:"situationApprovisionnement",setup(se){const{showError:v,showWarn:k,showInfo:_}=P(),p=a(),y=a(),h=a(),r=a([]),m=a(""),c=a(!1),x=a(!1),C=K(()=>["stock_total","seuil"]),$=({event:t,ndoc:e})=>{},A=async({data:t})=>{if(!t)return;const e=t.code_art||t.code_art;if(!e)return;const l=await W.HistoriqueDesMouvements();J({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:l.default,props:{ndoc:e,fermerParRetour:!0}})},S=({selectedRows:t})=>{},R=t=>{y.value=t.api};N(async()=>{await D(),d()});const D=async()=>{try{const e=(await w.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:606,mail:n.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(k("Vous n'avez pas le droit, veuillez consulter l'administrateur"),b("SituationApprovisionnement")))}catch(t){v(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},d=async()=>{n.state.afficher_in_progress=!0;try{const t=await w.post(`${n.lienApi}/situationApprovisionnement/${n.db}`,{rechercheLibelle:m.value},{headers:{"Content-Type":"application/json"}});r.value=t.data,x.value=!0}catch{v("Une erreur est survenue lors du chargement des données.")}finally{n.state.afficher_in_progress=!1}},I=()=>{c.value=!0},M=()=>{if(!p.value){_("Grille non initialisée");return}if(r.value.length===0){_("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Situation_approvisionnement_${n.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const l=j,T=B,V=O,q=z,E=L;return u(),f(U,null,[o("div",X,[o("div",Y,[i(l,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=s=>d()),text:"",loading:g(n).state.afficher_in_progress},null,8,["loading"]),i(l,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=s=>h.value.toggle(s))}),i(T,{ref_key:"actionsMenu",ref:h,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>M()},{label:"Imprimer",icon:"pi pi-print",command:()=>I()}],popup:!0},null,8,["model"]),i(l,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=s=>g(b)("SituationApprovisionnement"))})]),o("div",Z,[i(V,{fen:"SituationApprovisionnement",text:"Situation d'approvisionnement"})])]),o("div",null,[o("div",ee,[o("div",te,[e[6]||(e[6]=o("label",{class:"block text-sm"},"Recherche",-1)),i(q,{size:"small",modelValue:m.value,"onUpdate:modelValue":e[3]||(e[3]=s=>m.value=s),placeholder:"Rechercher...",class:"w-full",onKeyup:e[4]||(e[4]=G(s=>d(),["enter"]))},null,8,["modelValue"])])])]),e[8]||(e[8]=o("div",{class:"h-2"},null,-1)),x.value&&r.value.length===0?(u(),f("div",oe,[...e[7]||(e[7]=[o("i",{class:"pi pi-check-circle text-6xl text-green-500 mb-4"},null,-1),o("h3",{class:"text-xl font-semibold text-gray-700 mb-2"},"Aucun article en rupture de stock",-1),o("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)])])):(u(),f("div",ne,[i(Q,{ref_key:"dataGrid",ref:p,"excel-file-name":"Situation approvisionnement","excel-sheet-name":"Situation approvisionnement","row-data":r.value,"document-number-fields":["ndoc"],"excluded-columns":[],"enable-totals":!0,"numeric-columns":C.value,"totals-columns":["stock_total","seuil"],"show-checkbox":!1,onRowClicked:$,onRowDoubleClicked:A,onSelectionChanged:S,onGridReady:R},null,8,["row-data","numeric-columns"])])),c.value?(u(),F(E,{key:2,show:c.value,onClose:e[5]||(e[5]=s=>c.value=!1),data:r.value,modeList:!0,RapportName:"/classique/commercial/situationApprovisionnement"},null,8,["show","data"])):H("",!0)],64)}}};export{me as default};
