import{_ as G}from"./Imprimer-Bot4QNbk.js";import{u as O,a as b,s as o,S as k,g as j,m as z,A as U}from"./index-BSaHX2oa.js";import{_ as Q}from"./FavorisSwitch-DFHH_fud.js";import{f as W,o as x,c as J,b as n,a as r,q as S,z as K,av as X,i as Y,d as Z,F as ee,r as i,e as c}from"./vendor-BDR7yMJi.js";import{_ as te}from"./DataGrid-DbeHIyBR.js";import"./ReportViewer-Cmd4kpyP.js";import"./EnvoieDocumentsMail-P3u1QAl1.js";import"./useAgGridConfig-DxO2r97K.js";const oe={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},ne={class:"btns flex items-center gap-2"},ae={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},re={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-4 mb-2"},se={style:"height: calc(100vh - 220px)",class:"mt-2"},ve={__name:"situationDuStockComptable",setup(le){const{showError:f,showWarn:w,showInfo:T}=O(),p=i(),M=i(),v=i(),d=i([]),s=i(new Date),m=i(!1),h=c(()=>o.state.enreg_option_comm?.affichage_prix_doc||"BOTH"),u=c(()=>h.value!=="HT"),P=c(()=>u.value?["date_exercice","date_dernier_inventaire","PMP HT","Montant HT","Prix Vente HT","Marge HT %"]:["date_exercice","date_dernier_inventaire","PMP TTC","Montant TTC","Prix Vente TTC","Marge TTC %"]),D=c(()=>u.value?["Stock Comptable","Stock réel","Différence","PMP TTC","Prix Vente TTC","Montant TTC","Marge TTC %"]:["Stock Comptable","Stock réel","Différence","PMP HT","Prix Vente HT","Montant HT","Marge HT %"]),F=c(()=>u.value?["Stock Comptable","Stock réel","Différence","Montant TTC"]:["Stock Comptable","Stock réel","Différence","Montant HT"]),g=t=>{if(t.node?.rowPinned)return t.value;const e=parseFloat(t.value);if(isNaN(e))return"";const a=e.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2});return`<span style="color: ${e<0?"red":"inherit"}">${a} %</span>`},H={"Marge HT %":g,"Marge TTC %":g},y=c(()=>{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:u.value?parseFloat(e["PMP TTC"])||0:parseFloat(e["PMP HT"])||0,Montant:u.value?parseFloat(e["Montant TTC"])||0:parseFloat(e["Montant HT"])||0})),dateFin:t}}),R=({event:t,ndoc:e})=>{},$=async({data:t})=>{if(!t)return;const e=t["Code Article"];if(!e)return;const a=await z.HistoriqueDesMouvements();U({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:a.default,props:{ndoc:e,fermerParRetour:!0}})},V=({selectedRows:t})=>{},A=t=>{M.value=t.api};W(async()=>{await L(),_()});const L=async()=>{try{const e=(await b.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||(w("Vous n'avez pas le droit, veuillez consulter l'administrateur"),k("SituationDuStockComptable")))}catch(t){f(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},_=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 b.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}},I=()=>{m.value=!0},N=()=>{if(!p.value){T("Grille non initialisée");return}if(d.value.length===0){T("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 a=K,C=X,E=Q,B=j,q=G;return x(),J(ee,null,[n("div",oe,[n("div",ne,[r(a,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=l=>_()),text:"",loading:S(o).state.afficher_in_progress},null,8,["loading"]),r(a,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=l=>v.value.toggle(l))}),r(C,{ref_key:"actionsMenu",ref:v,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>N()},{label:"Imprimer",icon:"pi pi-print",command:()=>I()}],popup:!0},null,8,["model"]),r(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=l=>S(k)("SituationDuStockComptable"))})]),n("div",ae,[r(E,{fen:"SituationDuStockComptable",text:"Situation du stock comptable"})])]),n("div",null,[n("div",re,[n("div",null,[e[5]||(e[5]=n("label",{class:"block text-sm"},"Situation au",-1)),r(B,{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]=n("div",{class:"h-2"},null,-1)),n("div",se,[r(te,{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":P.value,"enable-totals":!0,"numeric-columns":D.value,"totals-columns":F.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,"Prix Vente HT":120,"Prix Vente TTC":120,"Marge HT %":100,"Marge TTC %":100,"Montant HT":130,"Montant TTC":130},"custom-renderers":H,onRowClicked:R,onRowDoubleClicked:$,onSelectionChanged:V,onGridReady:A},null,8,["row-data","excluded-columns","numeric-columns","totals-columns"])]),m.value?(x(),Y(q,{key:0,show:m.value,onClose:e[4]||(e[4]=l=>m.value=!1),data:y.value,modeList:!0,RapportName:"/classique/commercial/situationDuStockComptable"},null,8,["show","data"])):Z("",!0)],64)}}};export{ve as default};
