import{_ as L}from"./Imprimer-CqTc6qE9.js";import{f as M,w as N,o as x,c as R,b as o,a as l,z as S,av as T,q as V,ax as D,i as A,d as F,F as B,r as i}from"./vendor-0kGcmQpG.js";import{u as G,S as j,s as c,a as q}from"./index-Bn9WoKhP.js";import{_ as z}from"./DataGrid-tb6QVwpZ.js";import"./ReportViewer-1Jmo7TFF.js";import"./useAgGridConfig-DjXMc6wb.js";const P={class:"flex flex-row justify-start gap-2"},U={class:"flex-1 min-w-64"},J={style:{height:"calc(100vh - 240px)"}},Z={__name:"echeancierComptable",setup(O){const{showError:g,showWarn:b,showInfo:f}=G(),h=i(),v=i(),a=i([]),u=i(1),m=i(!1),y=i(null),w=t=>{if(!t||t<=0)return"";const e=Math.floor(t/365),n=t%365,d=Math.floor(n/30),p=n%30,s=[];return e>0&&s.push(`${e} ${e>1?"ans":"an"}`),d>0&&s.push(`${d} mois`),(p>0||s.length===0)&&s.push(`${p} ${p>1?"jours":"jour"}`),s.join(", ")},$={Retard:t=>{const e=parseInt(t.value),n=w(e);return e>0?`<span style="color: #dc2626; font-weight: bold;">${n}</span>`:n}},C=()=>{},I=({selectedRows:t})=>{y.value=t.length>0?t[0]:null};M(async()=>{});const _=async()=>{try{c.state.afficher_in_progress=!0;const{data:t}=await q.post(`${c.lienApi}/SP_EcheancierComptable/${c.db}`,{annee_fiscale:c.state.annee_fiscale,Type:u.value},{headers:{"Content-Type":"application/json"}});a.value=t.map((e,n)=>({...e,id:e.id||`temp_id_${n}`})),a.value.length===0&&f({title:"Information",text:"Aucune donnée trouvée pour les critères sélectionnés"})}catch(t){g(t.message||"Une erreur est survenue lors du chargement des données")}finally{c.state.afficher_in_progress=!1}},k=()=>{if(a.value.length===0){b("Aucune donnée à imprimer");return}m.value=!0},E=()=>{if(!v.value){f("Grille non initialisée");return}if(a.value.length===0){f("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportToExcel({fileName:`Echeancier_${u.value===1?"Clients":"Fournisseurs"}_${c.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Données"})};return N(u,async()=>{a.value.length>0&&await _()}),(t,e)=>{const n=S,d=T,p=D,s=L;return x(),R(B,null,[o("div",null,[o("div",P,[l(n,{text:"",icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=r=>_())}),o("div",null,[l(n,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=r=>h.value.toggle(r))}),l(d,{ref_key:"actionsMenu",ref:h,model:[{label:"Imprimer",icon:"pi pi-print",command:()=>k()},{label:"Exporter vers excel",icon:"pi pi-file-excel",command:()=>E()}],popup:!0},null,8,["model"])]),l(n,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=r=>V(j)("echeancierComptable"))})]),o("div",null,[o("div",U,[e[5]||(e[5]=o("label",{for:"type_tiers"},"Type : ",-1)),l(p,{size:"small",modelValue:u.value,"onUpdate:modelValue":e[3]||(e[3]=r=>u.value=r),options:[{Id:1,Libelle:"Clients"},{Id:2,Libelle:"Fournisseurs"}],optionLabel:"Libelle",optionValue:"Id",inputId:"type_tiers"},null,8,["modelValue"])]),e[6]||(e[6]=o("div",{class:"h-2"},null,-1)),o("div",J,[l(z,{ref_key:"agGrid",ref:v,"excel-file-name":"Echeancier comptable","excel-sheet-name":"Echeancier comptable","row-data":a.value,"excluded-columns":["id"],"date-only":["Date","Date_echeance"],"numeric-columns":["Montant"],"custom-renderers":$,"column-widths":{Nfacture:120,Date:120,Date_echeance:120,CodeCompte_ttc:120,Libelle:250,intitule:250,Montant:120,Retard:300},"enable-totals":!0,"show-checkbox":!1,onGridReady:C,onSelectionChanged:I},null,8,["row-data"])])])]),m.value?(x(),A(s,{key:0,show:m.value,onClose:e[4]||(e[4]=r=>m.value=!1),data:a.value,modeList:!0,RapportName:"/classique/compta/echeancierComptable"},null,8,["show","data"])):F("",!0)],64)}}};export{Z as default};
