import{_ as I}from"./Imprimer-CqTc6qE9.js";import{f as D,w as L,o as _,c as T,b as t,a as r,z as A,q as x,av as E,ax as R,i as S,d as F,F as G,r as l}from"./vendor-0kGcmQpG.js";import{u as M,s as n,a as P,S as j,h as g}from"./index-Bn9WoKhP.js";import{_ as q}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const z={class:"flex flex-col"},U={class:"flex flex-row justify-start gap-2"},O={class:"flex flex-col md:flex-row md:justify-start gap-3 mt-2"},W={class:"md:w-1/4"},H={class:"p-float-label"},J={style:{height:"calc(100vh - 200px)",width:"100%"}},te={__name:"balanceComparative",setup(K){const{showError:b,showWarn:w,showInfo:f}=M(),v=l(),p=l(),y=l(),i=l([]),u=l(!1),c=l(2);D(async()=>{await d()});const C=a=>{if(!a.value)return"";const e=parseFloat(a.value),o=g(a.value);return`<span class="${e<0?"text-red-600":e>0?"text-green-600":""}">${o}</span>`},$=a=>{if(!a.value)return"";const e=parseFloat(a.value),o=g(a.value);return`<span class="${e<0?"text-red-600":e>0?"text-green-600":""}">${o} %</span>`},V=a=>{y.value=a.api},d=async()=>{try{n.state.afficher_in_progress=!0;const a=await P.post(`${n.lienApi}/SP_BalanceComparatif/${n.db}`,{annee_fiscale:n.state.annee_fiscale,Type:c.value},{headers:{"Content-Type":"application/json"}});i.value=a.data.map((e,o)=>({...e,id:e.id||`temp_id_${o}`}))}catch(a){const e=a.response?.data?.message||a.message;b(`Une erreur est survenue : ${e}`)}finally{n.state.afficher_in_progress=!1}},h=()=>{if(i.value.length===0){w("Aucune donnée à imprimer");return}u.value=!0},B=()=>{if(!p.value){f("Grille non initialisée");return}if(i.value.length===0){f("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");p.value.exportToExcel(`BalanceComparative_${c.value===1?"Regroupee":"Detaillee"}_${n.state.enreg_societe.Nom}_${e}.xlsx`)};return L(c,async()=>{await d()}),(a,e)=>{const o=A,m=E,N=R,k=I;return _(),T(G,null,[t("div",z,[e[7]||(e[7]=t("div",{class:"btns flex items-center gap-2"},null,-1)),t("div",U,[r(o,{text:"",icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=s=>d())}),t("div",null,[r(o,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=s=>v.value.toggle(s))}),r(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=s=>x(j)("balanceComparative"))}),r(m,{ref_key:"actionsMenu",ref:v,model:[{label:"Imprimer",icon:"pi pi-print",command:()=>h()},{label:"Exporter vers excel",icon:"pi pi-file-excel",command:()=>B()}],popup:!0},null,8,["model"])])]),t("div",null,[t("div",O,[t("div",W,[t("span",H,[e[5]||(e[5]=t("label",{for:"type_balance"},"Type : ",-1)),r(N,{size:"small",modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=s=>c.value=s),options:[{Id:1,Libelle:"Regroupée"},{Id:2,Libelle:"Détaillé"}],optionLabel:"Libelle",optionValue:"Id",inputId:"type_balance"},null,8,["modelValue"])])])]),e[6]||(e[6]=t("div",{class:"h-2"},null,-1)),t("div",J,[r(q,{ref_key:"dataGrid",ref:p,"excel-file-name":"Balance comparative","excel-sheet-name":"Balance comparative","row-data":i.value,"numeric-columns":["Debit","Credit","DebitN_1","CreditN_1","VariationValeur","VariationPourcentage"],"totals-columns":["Debit","Credit","DebitN_1","CreditN_1","VariationValeur"],"excluded-columns":["id"],"custom-renderers":{VariationValeur:C,VariationPourcentage:$},"column-widths":{Libelle:350},onGridReady:V},null,8,["row-data","custom-renderers"])])])]),u.value?(_(),S(k,{key:0,show:u.value,onClose:e[4]||(e[4]=s=>u.value=!1),data:{Entete:i.value,Periode:"Exercice "+x(n).state.annee_fiscale},modeList:!0,RapportName:"/classique/compta/balanceComparatif"},null,8,["show","data"])):F("",!0)],64)}}};export{te as default};
