import{_ as X}from"./Imprimer-CqTc6qE9.js";import{f as Y,o as P,c as Z,an as ee,ap as te,b as t,a as s,q as y,z as le,av as oe,ax as ae,aP as se,M as ne,i as re,d as ie,F as ue,ar as ce,r as n,e as i}from"./vendor-0kGcmQpG.js";import{u as de,a as I,s as r,S as F,g as pe,m as me,A as ve}from"./index-Bn9WoKhP.js";import{_ as fe}from"./ComboDynamique-CzrtYPe1.js";import{_ as _e}from"./FavorisSwitch-DD6nTfzi.js";import{_ as xe}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const 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"},De={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ke={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-2"},we={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4"},Te={style:{height:"calc(100vh - 240px)"}},Ae={__name:"SituationDuStockAUneDate",setup(Se){const{showError:h,showWarn:$,showInfo:C}=de(),A=[{Id:0,Libelle:"Non spécifié"},{Id:1,Libelle:"Produit fini"},{Id:2,Libelle:"Matière première"},{Id:3,Libelle:"Service"},{Id:4,Libelle:" Marchandise"}],x=n(),R=n(),V=n(),p=n([]),g=n(""),m=n(!1),u=n(new Date),b=n(0),D=n(""),k=n(0),w=n(0),T=n(0),c=ce({lecture:!1,ajout:!1}),U=i(()=>r.state.enreg_option_comm?.affichage_prix_doc||"BOTH"),d=i(()=>U.value!=="HT"),H=i(()=>d.value?["pmp_ht","dernier_prix_ht","totalPmpHT","totalDernierPrixHT"]:["pmp_ttc","dernier_prix_ttc","totalPmpTTC","totalDernierPrixTTC"]),L=i(()=>d.value?["stock","pmp_ttc","dernier_prix_ttc","totalPmpTTC","totalDernierPrixTTC"]:["stock","pmp_ht","dernier_prix_ht","totalPmpHT","totalDernierPrixHT"]),z=i(()=>d.value?["totalPmpTTC","totalDernierPrixTTC"]:["totalPmpHT","totalDernierPrixHT"]),M=i(()=>{const o=u.value?new Date(u.value).toLocaleDateString("fr-FR"):new Date().toLocaleDateString("fr-FR");return{Entete:p.value.map(e=>{const a=parseFloat(e.stock)||0,v=d.value?parseFloat(e.pmp_ttc)||0:parseFloat(e.pmp_ht)||0,f=d.value?parseFloat(e.dernier_prix_ttc)||0:parseFloat(e.dernier_prix_ht)||0;return{code_art:e.code_art,libelle:e.libelle,stock:a,pmp:v,dernier_prix:f,totalPmp:a*v,totalDernierPrix:a*f}}),dateSituation:o}}),j=({event:o,ndoc:e})=>{},E=async({data:o})=>{if(!o||!o.code_art)return;const e=o.code_art,a=await me.HistoriqueDesMouvements();ve({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:a.default,props:{ndoc:e,fermerParRetour:!0}})},N=({selectedRows:o})=>{},q=o=>{R.value=o.api};Y(async()=>{await B(),S()});const B=async()=>{try{const e=(await I.post(`${r.lienApi}/verifierDroit/${r.state.dbCommun6}`,{id_utilisateur:r.userId,id_page:606,mail:r.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(c.lecture=e.lecture,c.ajout=e.ajout),c.lecture||($("Vous n'avez pas le droit, veuillez consulter l'administrateur"),F("SituationDuStockAUneDate"))}catch(o){h(`Une erreur s'est produite lors de la vérification des droits.
 ${o}`)}},S=async()=>{if(c.lecture){r.state.afficher_in_progress=!0;try{const o=await I.post(`${r.lienApi}/situationDuStockAUneDate/${r.db}`,{dateSitation:u.value,IDfamille:k.value||0,IDsfamille:w.value||0,code_art:D.value,IDdepot:b.value||0,type_article:T.value||0,rechercheString:g.value||""},{headers:{"Content-Type":"application/json"}});p.value=o.data.map(e=>{const a=parseFloat(e.stock)||0;return{...e,totalPmpHT:a*(parseFloat(e.pmp_ht)||0),totalPmpTTC:a*(parseFloat(e.pmp_ttc)||0),totalDernierPrixHT:a*(parseFloat(e.dernier_prix_ht)||0),totalDernierPrixTTC:a*(parseFloat(e.dernier_prix_ttc)||0)}})}catch{h("Une erreur est survenue lors du chargement des données.")}finally{r.state.afficher_in_progress=!1}}},G=()=>{m.value=!0},O=()=>{if(!x.value){C("Grille non initialisée");return}if(p.value.length===0){C("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");x.value.exportToExcel(`Situation_du_stock_a_une_date_${r.state.enreg_societe.Nom}_${e}.xlsx`)};return(o,e)=>{const a=le,v=oe,f=_e,_=fe,K=ae,W=pe,J=ne,Q=X;return P(),Z(ue,null,[ee(t("div",null,[t("div",ge,[t("div",be,[s(a,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>S()),text:"",loading:y(r).state.afficher_in_progress},null,8,["loading"]),s(a,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=l=>V.value.toggle(l))}),s(v,{ref_key:"actionsMenu",ref:V,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>O()},{label:"Imprimer",icon:"pi pi-print",command:()=>G()}],popup:!0},null,8,["model"]),s(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>y(F)("SituationDuStockAUneDate"))})]),t("div",De,[s(f,{fen:"SituationDuStockAUneDate",text:"Situation du stock à une date"})])]),t("div",null,[t("div",ke,[t("div",null,[e[12]||(e[12]=t("label",{class:"block text-sm"},"Article",-1)),s(_,{modelValue:D.value,"onUpdate:modelValue":e[3]||(e[3]=l=>D.value=l),placeholder:"Tous",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)),s(_,{modelValue:k.value,"onUpdate:modelValue":e[4]||(e[4]=l=>k.value=l),placeholder:"Toutes",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)),s(_,{modelValue:w.value,"onUpdate:modelValue":e[5]||(e[5]=l=>w.value=l),placeholder:"Toutes",table:"sfamille",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[15]||(e[15]=t("label",{class:"block text-sm"},"Type",-1)),s(K,{size:"small",modelValue:T.value,"onUpdate:modelValue":e[6]||(e[6]=l=>T.value=l),options:A,optionLabel:"Libelle",optionValue:"Id",placeholder:"Tous",class:"w-full"},null,8,["modelValue"])])]),t("div",we,[t("div",null,[e[16]||(e[16]=t("label",{class:"block text-sm"},"Date",-1)),s(W,{size:"small",modelValue:u.value,"onUpdate:modelValue":e[7]||(e[7]=l=>u.value=l),"input-class":"w-full"},null,8,["modelValue"])]),t("div",null,[e[17]||(e[17]=t("label",{class:"block text-sm"},"Dépôt",-1)),s(_,{modelValue:b.value,"onUpdate:modelValue":e[8]||(e[8]=l=>b.value=l),placeholder:"Tous",table:"depot",class:"w-full",size:"small"},null,8,["modelValue"])]),t("div",null,[e[18]||(e[18]=t("label",{class:"block text-sm"},"Recherche",-1)),s(J,{size:"small",modelValue:g.value,"onUpdate:modelValue":e[9]||(e[9]=l=>g.value=l),placeholder:"Rechercher...",class:"w-full",onKeyup:e[10]||(e[10]=se(l=>S(),["enter"]))},null,8,["modelValue"])])])]),e[19]||(e[19]=t("div",{class:"h-2"},null,-1)),t("div",Te,[s(xe,{ref_key:"dataGrid",ref:x,"excel-file-name":"Situation du stock a une date","excel-sheet-name":"Situation du stock a une date","row-data":p.value,"document-number-fields":["ndoc"],"excluded-columns":H.value,"enable-totals":!0,"numeric-columns":L.value,"totals-columns":z.value,"custom-status-colors":o.customStatusColors,"show-checkbox":!1,"column-widths":{libelle:350},onRowClicked:j,onRowDoubleClicked:E,onSelectionChanged:N,onGridReady:q},null,8,["row-data","excluded-columns","numeric-columns","totals-columns","custom-status-colors"])])],512),[[te,c.lecture]]),m.value?(P(),re(Q,{key:0,show:m.value,onClose:e[11]||(e[11]=l=>m.value=!1),data:M.value,modeList:!0,RapportName:"/classique/commercial/situationDuStockAUneDate"},null,8,["show","data"])):ie("",!0)],64)}}};export{Ae as default};
