import{_ as N}from"./Imprimer-DluCFs7h.js";import{b as T,B as V,y as L}from"./primevue-CfIk0_DY.js";import{o as M,w as R,b as w,c as B,j as G,H as z,d as a,v as u,a7 as U,k as O,p as P,F as q,a as i,E as H}from"./vue-core-Di3IuVqe.js";import{u as J,S as C,b as $,s as n}from"./index-BxIwIJfy.js";import{D as W}from"./DataGrid-CoMfrBJA.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 Z={class:"flex flex-row justify-start gap-2"},K={class:"flex-1 min-w-64"},Q={style:{height:"calc(100vh - 240px)"}},pe={__name:"echeancierComptable",setup(X){const{showError:_,showWarn:g,showInfo:v}=J(),b=i(),h=i(),s=i([]),l=i(1),m=i(!1),I=i(null),d=H({lecture:!1,ajout:!1}),k=async()=>{try{const e=(await $.post(`${n.lienApi}/verifierDroit/${n.state.dbCommun6}`,{id_utilisateur:n.userId,id_page:2305,mail:n.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(d.lecture=e.lecture,d.ajout=e.ajout),d.lecture||(g("Vous n'avez pas le droit, veuillez consulter l'administrateur"),C("echeancierComptable"))}catch(t){_("Une erreur est survenue : "+(t.response?.data?.message||t.message))}},j=t=>{if(!t||t<=0)return"";const e=Math.floor(t/365),o=t%365,f=Math.floor(o/30),p=o%30,r=[];return e>0&&r.push(`${e} ${e>1?"ans":"an"}`),f>0&&r.push(`${f} mois`),(p>0||r.length===0)&&r.push(`${p} ${p>1?"jours":"jour"}`),r.join(", ")},D={Retard:t=>{const e=parseInt(t.value),o=j(e);return e>0?`<span style="color: #dc2626; font-weight: bold;">${o}</span>`:o}},E=()=>{},F=({selectedRows:t})=>{I.value=t.length>0?t[0]:null};M(async()=>{await k()});const y=async()=>{try{n.state.afficher_in_progress=!0;const{data:t}=await $.post(`${n.lienApi}/SP_EcheancierComptable/${n.db}`,{annee_fiscale:n.state.annee_fiscale,Type:l.value},{headers:{"Content-Type":"application/json"}});s.value=t.map((e,o)=>({...e,id:e.id||`temp_id_${o}`})),s.value.length===0&&v({title:"Information",text:"Aucune donnée trouvée pour les critères sélectionnés"})}catch(t){_(t.message||"Une erreur est survenue lors du chargement des données")}finally{n.state.afficher_in_progress=!1}},x=i(""),S=()=>{if(s.value.length===0){g("Aucune donnée à imprimer");return}const t=e=>String(e||"").replace(/[^A-Za-z0-9._-]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"");x.value=["Echeancier",l.value===1?"Clients":"Fournisseurs",t(n.state.enreg_societe?.Nom),n.state.annee_fiscale].filter(Boolean).join("_"),m.value=!0},A=()=>{if(!h.value){v("Grille non initialisée");return}if(s.value.length===0){v("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");h.value.exportToExcel({fileName:`Echeancier_${l.value===1?"Clients":"Fournisseurs"}_${n.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Données"})};return R(l,async()=>{s.value.length>0&&await y()}),(t,e)=>{const o=T,f=V,p=L,r=N;return w(),B(q,null,[G(a("div",null,[a("div",Z,[u(o,{text:"",icon:"pi pi-refresh",label:"Afficher",onClick:e[0]||(e[0]=c=>y())}),a("div",null,[u(o,{text:"",icon:"pi pi-cog",label:"Actions",onClick:e[1]||(e[1]=c=>b.value.toggle(c))}),u(f,{ref_key:"actionsMenu",ref:b,model:[{label:"Imprimer",icon:"pi pi-print",command:()=>S()},{label:"Exporter vers excel",icon:"pi pi-file-excel",command:()=>A()}],popup:!0},null,8,["model"])]),u(o,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=c=>U(C)("echeancierComptable"))})]),a("div",null,[a("div",K,[e[5]||(e[5]=a("label",{for:"type_tiers"},"Type : ",-1)),u(p,{size:"small",modelValue:l.value,"onUpdate:modelValue":e[3]||(e[3]=c=>l.value=c),options:[{Id:1,Libelle:"Clients"},{Id:2,Libelle:"Fournisseurs"}],optionLabel:"Libelle",optionValue:"Id",inputId:"type_tiers"},null,8,["modelValue"])]),e[6]||(e[6]=a("div",{class:"h-2"},null,-1)),a("div",Q,[u(W,{ref_key:"agGrid",ref:h,"excel-file-name":"Echeancier comptable","excel-sheet-name":"Echeancier comptable","row-data":s.value,"excluded-columns":["id"],"date-only":["Date","Date_echeance"],"numeric-columns":["Montant"],"custom-renderers":D,"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:E,onSelectionChanged:F},null,8,["row-data"])])])],512),[[z,d.lecture]]),m.value?(w(),O(r,{key:0,show:m.value,onClose:e[4]||(e[4]=c=>m.value=!1),data:s.value,modeList:!0,RapportName:"/classique/compta/echeancierComptable",nomFichier:x.value},null,8,["show","data","nomFichier"])):P("",!0)],64)}}};export{pe as default};
