import{_ as N}from"./Imprimer-CqTc6qE9.js";import{u as q,a as g,s as o,S as b,g as G,m as O,A as j}from"./index-Bn9WoKhP.js";import{_ as z}from"./FavorisSwitch-DD6nTfzi.js";import{f as U,o as k,c as Q,b as a,a as n,q as S,z as W,av as J,i as K,d as X,F as Y,r,e as i}from"./vendor-0kGcmQpG.js";import{_ as Z}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const ee={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"},oe={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ae={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-2"},ne={style:"height: calc(100vh - 220px)",class:"mt-2"},pe={__name:"situationDuStockComptable",setup(se){const{showError:f,showWarn:T,showInfo:_}=q(),p=r(),w=r(),v=r(),d=r([]),s=r(new Date),m=r(!1),x=i(()=>o.state.enreg_option_comm?.affichage_prix_doc||"BOTH"),c=i(()=>x.value!=="HT"),h=i(()=>c.value?["date_exercice","date_dernier_inventaire","PMP HT","Montant HT"]:["date_exercice","date_dernier_inventaire","PMP TTC","Montant TTC"]),M=i(()=>c.value?["Stock Comptable","Stock réel","Différence","PMP TTC","Montant TTC"]:["Stock Comptable","Stock réel","Différence","PMP HT","Montant HT"]),D=i(()=>c.value?["Stock Comptable","Stock réel","Différence","Montant TTC"]:["Stock Comptable","Stock réel","Différence","Montant HT"]),F=i(()=>{const t=s.value?new Date(s.value).toLocaleDateString("fr-FR"):new Date().toLocaleDateString("fr-FR");return{Entete:d.value.map(e=>({Code_Article:e["Code Article"]||"",Libelle:e.Libellé||"",Quantité:parseFloat(e["Stock Comptable"])||0,Famille:e.Famille||"",PMP:c.value?parseFloat(e["PMP TTC"])||0:parseFloat(e["PMP HT"])||0,Montant:c.value?parseFloat(e["Montant TTC"])||0:parseFloat(e["Montant HT"])||0})),dateFin:t}}),P=({event:t,ndoc:e})=>{},y=async({data:t})=>{if(!t)return;const e=t["Code Article"];if(!e)return;const u=await O.HistoriqueDesMouvements();j({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:u.default,props:{ndoc:e,fermerParRetour:!0}})},$=({selectedRows:t})=>{},H=t=>{w.value=t.api};U(async()=>{await R(),C()});const R=async()=>{try{const e=(await g.post(`${o.lienApi}/verifierDroit/${o.state.dbCommun6}`,{id_utilisateur:o.userId,id_page:606,mail:o.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(T("Vous n'avez pas le droit, veuillez consulter l'administrateur"),b("SituationDuStockComptable")))}catch(t){f(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},C=async()=>{o.state.afficher_in_progress=!0;try{const t=s.value?new Date(s.value).toISOString().split("T")[0]:new Date().toISOString().split("T")[0],e=await g.post(`${o.lienApi}/situationDuStockComptable/${o.db}`,{dateFin:t},{headers:{"Content-Type":"application/json"}});d.value=e.data}catch{f("Une erreur est survenue lors du chargement des données.")}finally{o.state.afficher_in_progress=!1}},A=()=>{m.value=!0},I=()=>{if(!p.value){_("Grille non initialisée");return}if(d.value.length===0){_("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`Situation_du_stock_comptable_${o.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const u=W,L=J,E=z,V=G,B=N;return k(),Q(Y,null,[a("div",ee,[a("div",te,[n(u,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>C()),text:"",loading:S(o).state.afficher_in_progress},null,8,["loading"]),n(u,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=l=>v.value.toggle(l))}),n(L,{ref_key:"actionsMenu",ref:v,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>I()},{label:"Imprimer",icon:"pi pi-print",command:()=>A()}],popup:!0},null,8,["model"]),n(u,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>S(b)("SituationDuStockComptable"))})]),a("div",oe,[n(E,{fen:"SituationDuStockComptable",text:"Situation du stock comptable"})])]),a("div",null,[a("div",ae,[a("div",null,[e[5]||(e[5]=a("label",{class:"block text-sm"},"Situation au",-1)),n(V,{size:"small",modelValue:s.value,"onUpdate:modelValue":e[3]||(e[3]=l=>s.value=l),"input-class":"w-full"},null,8,["modelValue"])])])]),e[6]||(e[6]=a("div",{class:"h-2"},null,-1)),a("div",ne,[n(Z,{ref_key:"dataGrid",ref:p,"excel-file-name":"Situation du stock comptable","excel-sheet-name":"Situation du stock comptable","row-data":d.value,"document-number-fields":["Code Article"],"excluded-columns":h.value,"enable-totals":!0,"numeric-columns":M.value,"totals-columns":D.value,"show-checkbox":!1,"column-widths":{Libellé:300,"Stock Comptable":130,"Stock réel":120,Différence:100,Famille:150,"Sous-Famille":150,"PMP HT":100,"PMP TTC":100,"Montant HT":130,"Montant TTC":130},onRowClicked:P,onRowDoubleClicked:y,onSelectionChanged:$,onGridReady:H},null,8,["row-data","excluded-columns","numeric-columns","totals-columns"])]),m.value?(k(),K(B,{key:0,show:m.value,onClose:e[4]||(e[4]=l=>m.value=!1),data:F.value,modeList:!0,RapportName:"/classique/commercial/situationDuStockComptable"},null,8,["show","data"])):X("",!0)],64)}}};export{pe as default};
