import{_ as le}from"./Imprimer-DluCFs7h.js";import{u as ae,b as H,s as l,S as $,j as ne,m as se,A as re}from"./index-BxIwIJfy.js";import{_ as ie}from"./FavorisSwitch-BFqqA1tj.js";import{b as ue,B as ce}from"./primevue-CfIk0_DY.js";import{D as me}from"./DataGrid-CoMfrBJA.js";import{u as de}from"./usePackStockColumns-DyT208Q0.js";import{_ as I}from"./ArbreMultiSelect-AgriSkO3.js";import{_ as R}from"./MultiComboDynamique-h6wbTTe2.js";import{o as pe,b as m,c as fe,d as a,v as u,a7 as x,k as g,p as ve,F as ge,a as s,y as r}from"./vue-core-Di3IuVqe.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 Te={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Ce={class:"btns flex items-center gap-2"},_e={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ke={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-6 gap-4 mb-2"},be={style:"height: calc(100vh - 220px)",class:"mt-2"},je={__name:"situationDuStockComptable",setup(Se){const{showError:w,showWarn:A,showInfo:D}=ae(),{enrichirLignes:L,packNumericColumns:N,packExcludedColumns:j,packColumnTitles:B}=de({qteField:"Stock réel"}),E=["Code Article","Libellé","Stock Comptable","Stock réel","nbCartons","QuantiteCarton"],k=s(),U=s(),M=s(),T=s([]),i=s(new Date),d=s([]),p=s([]),h=r(()=>!!l.state.enreg_option_comm?.gestion_sfamille_arbre),C=s(!1),F=r(()=>l.state.enreg_option_comm?.affichage_prix_doc||"BOTH"),b=r(()=>F.value!=="TTC"),f=r(()=>F.value!=="HT"),G=r(()=>{const t=["date_exercice","date_dernier_inventaire"];return b.value||t.push("PMP HT","Montant HT","Prix Vente HT","Marge HT %"),f.value||t.push("PMP TTC","Montant TTC","Prix Vente TTC","Marge TTC %"),[...t,...j.value]}),O=r(()=>{const t=["Stock Comptable","Stock réel","Différence"];return b.value&&t.push("PMP HT","Prix Vente HT","Montant HT","Marge HT %"),f.value&&t.push("PMP TTC","Prix Vente TTC","Montant TTC","Marge TTC %"),[...t,...N.value]}),q=r(()=>{const t=["Stock Comptable","Stock réel","Différence"];return b.value&&t.push("Montant HT"),f.value&&t.push("Montant TTC"),t}),P=t=>{if(t.node?.rowPinned)return t.value;const e=parseFloat(t.value);if(isNaN(e))return"";const n=e.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2});return`<span style="color: ${e<0?"red":"inherit"}">${n} %</span>`},Y={"Marge HT %":P,"Marge TTC %":P},z=r(()=>{const t=i.value?new Date(i.value).toLocaleDateString("fr-FR"):new Date().toLocaleDateString("fr-FR");return{Entete:T.value.map(e=>({Code_Article:e["Code Article"]||"",Libelle:e.Libellé||"",Quantité:parseFloat(e["Stock Comptable"])||0,Famille:e.Famille||"",PMP:f.value?parseFloat(e["PMP TTC"])||0:parseFloat(e["PMP HT"])||0,Montant:f.value?parseFloat(e["Montant TTC"])||0:parseFloat(e["Montant HT"])||0})),dateFin:t}}),Q=({event:t,ndoc:e})=>{},W=async({data:t})=>{if(!t)return;const e=t["Code Article"];if(!e)return;const n=await se.HistoriqueDesMouvements();re({id:"HistoriqueDesMouvements",text:`Historique : ${e}`,content:n.default,props:{ndoc:e,fermerParRetour:!0}})},Z=({selectedRows:t})=>{},J=t=>{U.value=t.api};pe(async()=>{await K(),V()});const K=async()=>{try{const e=(await H.post(`${l.lienApi}/verifierDroit/${l.state.dbCommun6}`,{id_utilisateur:l.userId,id_page:606,mail:l.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(A("Vous n'avez pas le droit, veuillez consulter l'administrateur"),$("SituationDuStockComptable")))}catch(t){w(`Une erreur s'est produite lors de la vérification des droits.
 ${t}`)}},V=async()=>{l.state.afficher_in_progress=!0;try{const t=i.value?new Date(i.value).toISOString().split("T")[0]:new Date().toISOString().split("T")[0],e=await H.post(`${l.lienApi}/situationDuStockComptable/${l.db}`,{dateFin:t,IDfamilles:d.value||[],IDsfamilles:p.value||[]},{headers:{"Content-Type":"application/json"}});T.value=L(e.data)}catch{w("Une erreur est survenue lors du chargement des données.")}finally{l.state.afficher_in_progress=!1}},y=s(""),X=()=>{const t=c=>String(c||"").replace(/[^A-Za-z0-9._-]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,""),e=c=>{const v=c?new Date(c):new Date,S=String(v.getDate()).padStart(2,"0"),o=String(v.getMonth()+1).padStart(2,"0"),oe=v.getFullYear();return`${S}${o}${oe}`},n=t(l.state.enreg_societe?.Nom||""),_=e(i.value);return["SituationStockComptable",n,_].filter(Boolean).join("_")},ee=()=>{y.value=X(),C.value=!0},te=()=>{if(!k.value){D("Grille non initialisée");return}if(T.value.length===0){D("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");k.value.exportToExcel(`Situation_du_stock_comptable_${l.state.enreg_societe.Nom}_${e}.xlsx`)};return(t,e)=>{const n=ue,_=ce,c=ie,v=ne,S=le;return m(),fe(ge,null,[a("div",Te,[a("div",Ce,[u(n,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=o=>V()),text:"",loading:x(l).state.afficher_in_progress},null,8,["loading"]),u(n,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>M.value.toggle(o))}),u(_,{ref_key:"actionsMenu",ref:M,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>te()},{label:"Imprimer",icon:"pi pi-print",command:()=>ee()}],popup:!0},null,8,["model"]),u(n,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>x($)("SituationDuStockComptable"))})]),a("div",_e,[u(c,{fen:"SituationDuStockComptable",text:"Situation du stock comptable"})])]),a("div",null,[a("div",ke,[a("div",null,[e[9]||(e[9]=a("label",{class:"block text-sm"},"Situation au",-1)),u(v,{size:"small",modelValue:i.value,"onUpdate:modelValue":e[3]||(e[3]=o=>i.value=o),"input-class":"w-full"},null,8,["modelValue"])]),a("div",null,[e[10]||(e[10]=a("label",{class:"block text-sm"},"Famille",-1)),h.value?(m(),g(I,{key:0,modelValue:d.value,"onUpdate:modelValue":e[4]||(e[4]=o=>d.value=o),source:"famille",cle:"IDfamille",unite:"famille",placeholder:"Toutes les familles"},null,8,["modelValue"])):(m(),g(R,{key:1,modelValue:d.value,"onUpdate:modelValue":e[5]||(e[5]=o=>d.value=o),placeholder:"Toutes les familles",table:"famille",class:"w-full"},null,8,["modelValue"]))]),a("div",null,[e[11]||(e[11]=a("label",{class:"block text-sm"},"Sous-famille",-1)),h.value?(m(),g(I,{key:0,modelValue:p.value,"onUpdate:modelValue":e[6]||(e[6]=o=>p.value=o),source:"sfamille",cle:"IDsfamille",parent:"IDsfamille_parent",unite:"sous-famille",placeholder:"Toutes les sous-familles"},null,8,["modelValue"])):(m(),g(R,{key:1,modelValue:p.value,"onUpdate:modelValue":e[7]||(e[7]=o=>p.value=o),placeholder:"Toutes les sous-familles",table:"sfamille",class:"w-full"},null,8,["modelValue"]))])])]),e[12]||(e[12]=a("div",{class:"h-2"},null,-1)),a("div",be,[u(me,{ref_key:"dataGrid",ref:k,"excel-file-name":"Situation du stock comptable","excel-sheet-name":"Situation du stock comptable","row-data":T.value,"document-number-fields":["Code Article"],"excluded-columns":G.value,"enable-totals":!0,"numeric-columns":O.value,"totals-columns":q.value,"column-titles":x(B),"column-order":E,"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":Y,onRowClicked:Q,onRowDoubleClicked:W,onSelectionChanged:Z,onGridReady:J},null,8,["row-data","excluded-columns","numeric-columns","totals-columns","column-titles"])]),C.value?(m(),g(S,{key:0,show:C.value,onClose:e[8]||(e[8]=o=>C.value=!1),data:z.value,modeList:!0,RapportName:"/classique/commercial/situationDuStockComptable",nomFichier:y.value},null,8,["show","data","nomFichier"])):ve("",!0)],64)}}};export{je as default};
