import{_ as k}from"./Imprimer-CqTc6qE9.js";import{f as F,w as I,o as b,c as S,b as n,a as l,z as T,q as E,av as V,ax as B,aw as M,i as R,d as D,F as G,r}from"./vendor-0kGcmQpG.js";import{u as U,s as i,a as q,S as z}from"./index-Bn9WoKhP.js";import{_ as O}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const W={class:"w-full mb-6 flex flex-col sm:flex-row items-center align-baseline gap-3"},H={class:"flex flex-col gap-3"},J={class:"flex flex-wrap items-center gap-4"},K={class:"p-float-label"},Q={class:"flex items-center gap-2"},X={style:{height:"calc(100vh - 200px)"}},se={__name:"balanceAgeeCompta",setup(Y){const{showError:j,showWarn:w,showInfo:v}=U(),x=r(),m=r(),p=r(!1),c=r(1),d=r(!1),u=r([]),C=r(null),$=(t,e)=>{const a=parseFloat(t)||0;if(a===0)return"text-gray-400";switch(e){case"total":return a>0?"text-blue-600":"text-red-600";case"non-echu":return"text-green-600";case"p1":return"text-yellow-600";case"p2":return"text-orange-500";case"p3":return"text-red-500";case"p4":return"text-red-600";case"p5":return"text-red-700";default:return""}},s=t=>e=>{if(e.value==null||e.value==="")return"";const a=parseFloat(e.value)||0;if(a===0)return"";const _=a.toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),h=$(a,t),g=e.node.rowPinned?"font-weight: bold;":"";return`<span class="${h}" style="${g}">${_}</span>`},y=()=>{},A=({selectedRows:t})=>{C.value=t.length>0?t[0]:null};F(async()=>{await f()});const f=async()=>{try{i.state.afficher_in_progress=!0;const t=await q.post(`${i.lienApi}/SP_BalanceAgeeComptable/${i.db}`,{annee_fiscale:i.state.annee_fiscale,Type:c.value,aPartirEcritures:d.value},{headers:{"Content-Type":"application/json"}});u.value=t.data.map((e,a)=>({...e,id:e.id||`temp_id_${a}`}))}catch(t){const e=t.response?.data?.message||t.message;j(`Une erreur est survenue : ${e}`)}finally{i.state.afficher_in_progress=!1}},N=()=>{if(u.value.length===0){w("Aucune donnée à imprimer");return}p.value=!0},L=()=>{if(!m.value){v("Grille non initialisée");return}if(u.value.length===0){v("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");m.value.exportToExcel({fileName:`BalanceAgee_${c.value===1?"Clients":"Fournisseurs"}_${i.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Données"})};return I(c,async()=>{await f()}),(t,e)=>{const a=T,_=V,h=B,g=M,P=k;return b(),S(G,null,[e[8]||(e[8]=n("div",{class:"btns flex items-center gap-2"},null,-1)),n("div",W,[l(a,{text:"",icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=o=>f())}),n("div",null,[l(a,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=o=>x.value.toggle(o))}),l(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>E(z)("balanceAgeeCompta"))}),l(_,{ref_key:"actionsMenu",ref:x,model:[{label:"Imprimer",icon:"pi pi-print",command:()=>N()},{label:"Exporter vers excel",icon:"pi pi-file-excel",command:()=>L()}],popup:!0},null,8,["model"])])]),n("div",H,[n("div",J,[n("div",K,[e[6]||(e[6]=n("label",{for:"filtre_par"},"Par : ",-1)),l(h,{size:"small",modelValue:c.value,"onUpdate:modelValue":e[3]||(e[3]=o=>c.value=o),options:[{Id:1,Libelle:"Client"},{Id:2,Libelle:"Fournisseur"}],optionLabel:"Libelle",optionValue:"Id",inputId:"filtre_par"},null,8,["modelValue"])]),n("div",Q,[l(g,{modelValue:d.value,"onUpdate:modelValue":e[4]||(e[4]=o=>d.value=o),binary:"",inputId:"a_partir_ecritures"},null,8,["modelValue"]),e[7]||(e[7]=n("label",{for:"a_partir_ecritures",class:"cursor-pointer"},"À partir des écritures comptables (saisie Standard)",-1))])]),n("div",X,[l(O,{ref_key:"agGrid",ref:m,"excel-file-name":"Balance agee compta","excel-sheet-name":"Balance agee compta","row-data":u.value,"excluded-columns":["id"],"document-number-fields":["CodeCompte_ttc"],"numeric-columns":["MontantTotal","NonEch","Echu0_30j","Echu31_60j","Echu61_90j","Echu91_120j","EchuPlus120j"],"column-titles":{CodeCompte_ttc:"Code",Libelle:"Libellé",MontantTotal:"Total",NonEch:"Non échu",Echu0_30j:"0-30j",Echu31_60j:"31-60j",Echu61_90j:"61-90j",Echu91_120j:"91-120j",EchuPlus120j:"+120j"},"column-widths":{CodeCompte_ttc:120,Libelle:200,MontantTotal:120,NonEch:120,Echu0_30j:120,Echu31_60j:120,Echu61_90j:120,Echu91_120j:120,EchuPlus120j:120},"custom-renderers":{MontantTotal:s("total"),NonEch:s("non-echu"),Echu0_30j:s("p1"),Echu31_60j:s("p2"),Echu61_90j:s("p3"),Echu91_120j:s("p4"),EchuPlus120j:s("p5")},"enable-totals":!0,onGridReady:y,onSelectionChanged:A},null,8,["row-data","custom-renderers"])])]),p.value?(b(),R(P,{key:0,show:p.value,onClose:e[5]||(e[5]=o=>p.value=!1),data:{Entete:u.value,Periode:"Exercice "+E(i).state.annee_fiscale},modeList:!0,RapportName:"/classique/compta/balanceAgeeComptable"},null,8,["show","data"])):D("",!0)],64)}}};export{se as default};
