import{_ as q}from"./Imprimer-DluCFs7h.js";import{C as P}from"./ComboDynamique-BzWI4ISP.js";import{b as O,B as H}from"./primevue-CfIk0_DY.js";import{o as W,j as Z,H as K,b,c as y,d as s,v as r,a7 as A,p as k,k as Q,y as c,a as l,E as X}from"./vue-core-Di3IuVqe.js";import{u as Y,S as D,s as t,b as J}from"./index-BxIwIJfy.js";import{D as ee}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 te={class:"page-wrapper"},oe={class:"flex flex-row justify-start gap-3"},ae={class:"flex flex-col gap-4",style:{flex:"1","min-height":"0"}},se={class:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-8 gap-4 mx-3"},le={class:"field"},ne={class:"field"},re={key:0,class:"field"},ie={class:"grille-container"},ye={__name:"JournauxComptables",setup(ue){const{showError:x,showInfo:f,showWarn:V}=Y(),m=X({lecture:!1,ajout:!1}),h=l(),j=l(),v=l(),d=l(!1),$=[{label:"Imprimer",icon:"pi pi-print",command:()=>z()},{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>M()}],g=l(""),i=l(""),p=l(0),I=c(()=>!!t.state.enreg_option_compta?.gestion_agence),C=c(()=>t.state.userCommun6?.id_agence||0),E=c(()=>!!t.state.userCommun6?.Access_Agence),R=c(()=>C.value>0&&!E.value),T=c(()=>I.value),u=l([]),S=l(null),N=({event:o})=>{S.value=o?.data},B=o=>{v.value=o.api},F=async()=>{try{const e=(await J.post(`${t.lienApi}/verifierDroit/${t.state.dbCommun6}`,{id_utilisateur:t.userId,id_page:2303,mail:t.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(m.lecture=e.lecture,m.ajout=e.ajout),m.lecture||(V("Vous n'avez pas le droit, veuillez consulter l'administrateur"),D("JournauxComptables"))}catch(o){x("Une erreur est survenue : "+(o.response?.data?.message||o.message))}};W(async()=>{await F(),p.value=C.value});const G=async()=>{t.state.afficher_in_progress=!0;let o=0,e=0;if(i.value&&i.value!=="----"){const a=String(i.value);e=parseInt(a.substring(0,4))||0,o=parseInt(a.substring(4,6))||0}try{const a=await J.post(`${t.lienApi}/journauxComptable/${t.db}`,{annee_fiscale:t.state.annee_fiscale,codeJournal:g.value||"",mois:o,annee:e,id_agence:p.value},{headers:{"Content-Type":"application/json"}});u.value=a.data}catch(a){x(`Erreur lors de l'affichage des journaux comptables
 ${a}`)}finally{t.state.afficher_in_progress=!1}},M=()=>{if(!v.value){f("Grille non initialisée");return}if(u.value.length===0){f("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");v.value.exportDataAsExcel({fileName:`Journaux_${t.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Journaux",exportedRows:"all",onlySelected:!1,suppressTextAsCDATA:!0})},w=l(""),z=()=>{if(u.value.length===0){f("Aucune donnée à imprimer");return}const o=e=>String(e||"").replace(/[^A-Za-z0-9._-]/g,"_").replace(/_+/g,"_").replace(/^_|_$/g,"");w.value=["Journaux",o(t.state.enreg_societe?.Nom),t.state.annee_fiscale].filter(Boolean).join("_"),d.value=!0};return(o,e)=>{const a=O,L=H,_=P,U=q;return Z((b(),y("div",te,[s("div",oe,[r(a,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:G}),s("span",null,[r(a,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=n=>h.value.toggle(n))}),r(a,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=n=>A(D)("JournauxComptables"))}),r(L,{ref_key:"menu",ref:h,model:$,popup:!0},null,512)])]),s("div",ae,[s("div",se,[s("div",le,[e[6]||(e[6]=s("label",{class:"block mb-1"},"Journal",-1)),r(_,{modelValue:g.value,"onUpdate:modelValue":e[2]||(e[2]=n=>g.value=n),table:"Journal",placeholder:"Tous les journaux",class:"w-full"},null,8,["modelValue"])]),s("div",ne,[e[7]||(e[7]=s("label",{class:"block mb-1"},"Mois",-1)),r(_,{modelValue:i.value,"onUpdate:modelValue":e[3]||(e[3]=n=>i.value=n),table:"MoisExercice",placeholder:"Tous les mois","exclude-values":["----"],class:"w-full"},null,8,["modelValue"])]),T.value?(b(),y("div",re,[e[8]||(e[8]=s("label",{class:"block mb-1"},"Agence",-1)),r(_,{modelValue:p.value,"onUpdate:modelValue":e[4]||(e[4]=n=>p.value=n),placeholder:"Toutes les agences",table:"agence",size:"small",disabled:R.value,class:"w-full"},null,8,["modelValue","disabled"])])):k("",!0)]),s("div",ie,[r(ee,{ref_key:"dataGrid",ref:j,"excel-file-name":"Journaux","excel-sheet-name":"Journaux","row-data":u.value,"numeric-columns":["Débit","Crédit"],"date-columns":["Date"],"date-only":["Date"],"totals-columns":["Débit","Crédit"],"excluded-columns":["CodeJournal"],"show-checkbox":!1,"column-widths":{Date:90,Référence:120,Pièce:100,Compte:120,Intitulé:350,Libellé:350,Journal:120,Débit:90,Crédit:90},onRowClicked:N,onGridReady:B},null,8,["row-data"])])]),d.value?(b(),Q(U,{key:0,show:d.value,onClose:e[5]||(e[5]=n=>d.value=!1),data:{Entete:u.value,Periode:"Exercice "+A(t).state.annee_fiscale},modeList:!0,RapportName:"/classique/compta/JournauxComptables",nomFichier:w.value},null,8,["show","data","nomFichier"])):k("",!0)],512)),[[K,m.lecture]])}}};export{ye as default};
