import{f as N,o as z,c as R,b as s,a as n,q as $,z as q,j as L,av as j,ax as G,M as W,F as H,r as a}from"./vendor-BDR7yMJi.js";import{_ as K}from"./selectDate-Dd47YHbm.js";import{_ as Q}from"./FavorisSwitch-DFHH_fud.js";import{u as X,a as p,s as l,S as w}from"./index-BSaHX2oa.js";import{_ as Y}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const Z={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},ee={class:"btns flex items-center gap-2"},te={class:"flex items-center p-2"},se={class:"grid grid-cols-1 md:grid-cols-2 lg:grid-cols-5 gap-4 mb-4"},le={style:{height:"calc(100vh - 240px)"}},pe={__name:"JournalEvenements",setup(ae){const{showError:d,showInfo:x,showWarn:A}=X(),_=a(),m=a([]),y=a([]),f=a([]),T=a(),u=a(),i=a(null),c=a(null),v=a(null),b=a(null),h=a(""),C=a(""),V=a([{label:"Création",value:"Création"},{label:"Modification",value:"Modification"},{label:"Suppression",value:"Suppression"}]),D={article:"Articles",facturec:"Factures clients",facturef:"Factures fournisseurs",avoirc:"Avoirs clients",avoirf:"Avoirs fournisseurs",bonlivr:"Bons de livraison",bonrecep:"Bons de réception",bcomc:"Bons de commande clients",bcomf:"Bons de commande fournisseurs",devis:"Devis",demdevis:"Demandes de devis",demande_achat:"Demandes d'achat",bretourc:"Bons de retour clients",bretourf:"Bons de retour fournisseurs",bretour:"Bons de retour",echange:"Échanges inter-dépôts",sortiePiece:"Sorties de pièces",Ofab:"Ordres de fabrication",inventaire:"Inventaires",Mouvement:"Mouvements de stock",paiementc:"Paiements clients",paiementf:"Paiements fournisseurs",paiement_d:"Paiements divers",client:"Clients",fournisseur:"Fournisseurs",famille:"Familles",sfamille:"Sous-familles",depot:"Dépôts",commercial:"Commerciaux",Employe:"Employés",Calcul:"Bulletins de paie",Rubrique:"Rubriques",Option_paie:"Options paie",Ecriture:"Écritures comptables",Journal:"Journaux comptables",Compte:"Comptes comptables",compte_bancaire:"Comptes bancaires",contrat:"Contrats",facture_recurrente:"Factures récurrentes",opportunite:"Opportunités",Piste:"Pistes",affaire:"Affaires",immo:"Immobilisations",op_caisse:"Opérations de caisse",remise:"Remises en banque",controle_b:"Contrôles bancaires",options_commercial:"Options commerciales",Options_compta:"Options comptabilité",societe:"Société",utilisateur:"Utilisateurs",Droit:"Droits"},k={Table:t=>t.value?D[t.value]||t.value:"",TypeAction:t=>t.value?`<span style="padding: 2px 8px; border-radius: 4px; font-size: 12px; ${{Création:"background-color: #dcfce7; color: #166534;",Modification:"background-color: #fef3c7; color: #92400e;",Suppression:"background-color: #fee2e2; color: #991b1b;"}[t.value]||""}">${t.value}</span>`:"",Utilisateur:t=>t.value?`<div class="flex items-center gap-2"><i class="pi pi-user text-gray-500 text-xs"></i><span>${t.value}</span></div>`:"",Changements:t=>{if(t.value){let e=t.value.replace(/→/g,'<span style="color: #2563eb; font-weight: bold;"> → </span>').replace(/\(vide\)/g,'<span style="color: #9ca3af; font-style: italic;">(vide)</span>');return t.value.startsWith("Nouvel")?`<span style="color: #166534;"><i class="pi pi-plus-circle" style="margin-right: 4px;"></i>${t.value}</span>`:t.value.startsWith("Supprimé")?`<span style="color: #991b1b;"><i class="pi pi-trash" style="margin-right: 4px;"></i>${t.value}</span>`:`<span style="font-size: 12px;">${e}</span>`}return""}},S=t=>{u.value=t.api,u.value.applyColumnState({state:[{colId:"DateAction",sort:"desc"}],defaultState:{sort:null}})},E=(t,e)=>{h.value=t,C.value=e},U=async()=>{if(f.value=[],c.value=null,i.value)try{const t=await p.post(`${l.lienApi}/JournalUtilisateurs/${l.db}`,{tableName:i.value});f.value=t.data}catch{}};N(async()=>{await F();try{const t=await p.post(`${l.lienApi}/JournalTables/${l.db}`,{annee_fiscale:l.state.annee_fiscale});y.value=t.data}catch(t){const e=t.response?.data?.message||t.message;d(`Une erreur est survenue : ${e}`)}});const F=async()=>{try{const e=(await p.post(`${l.lienApi}/verifierDroit/${l.state.dbCommun6}`,{id_utilisateur:l.userId,id_page:1203,mail:l.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(e.lecture||(A("Vous n'avez pas le droit, veuillez consulter l'administrateur"),w("JournalEvenements")))}catch(t){const e=t.response?.data?.message||t.message;d("Une erreur est survenue : "+e)}finally{l.state.afficher_in_progress=!1}},B=async()=>{l.state.afficher_in_progress=!0;try{const t=await p.post(`${l.lienApi}/JournalEvenements/${l.db}`,{tableName:i.value,dateDu:h.value,dateAu:C.value,utilisateur:c.value,cleValeur:b.value,typeAction:v.value},{headers:{"Content-Type":"application/json"}});m.value=t.data.map((e,r)=>({...e,id:`${r}_${e.CleValeur}_${e.DateAction}`}))}catch(t){d(`Erreur lors de l'affichage de l'historique
 ${t}`)}finally{l.state.afficher_in_progress=!1}},J=()=>{if(!u.value){x("Grille non initialisée");return}if(m.value.length===0){x("Aucune donnée à exporter");return}const e=new Date().toISOString().slice(0,19).replace(/[-:]/g,"").replace("T","_");u.value.exportDataAsExcel({fileName:`Historique_${i.value}_${l.state.enreg_societe.Nom}_${e}.xlsx`,sheetName:"Historique",exportedRows:"all",onlySelected:!1,suppressTextAsCDATA:!0})};return(t,e)=>{const r=q,M=Q,P=j,g=G,O=K,I=W;return z(),R(H,null,[s("div",Z,[s("div",ee,[n(r,{icon:"pi pi-search",label:"Rechercher",onClick:e[0]||(e[0]=o=>B()),text:"",loading:$(l).state.afficher_in_progress},null,8,["loading"]),n(r,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=o=>_.value?.toggle(o))}),n(P,{ref_key:"actionsMenu",ref:_,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>J()},{label:"Favoris",icon:"pi pi-star",template:"favorisTemplate"}],popup:!0},{favorisTemplate:L(()=>[s("div",te,[n(M,{fen:"JournalEvenements",text:"Journal des événements"}),e[7]||(e[7]=s("span",{class:"font-semibold ml-2 text-primary"},"Favoris",-1))])]),_:1},8,["model"]),n(r,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=o=>$(w)("JournalEvenements"))})])]),s("div",null,[s("div",se,[s("div",null,[e[8]||(e[8]=s("label",{class:"block text-sm"},"Table",-1)),n(g,{size:"small",modelValue:i.value,"onUpdate:modelValue":e[3]||(e[3]=o=>i.value=o),options:y.value,optionLabel:"Libelle",optionValue:"TableName",placeholder:"Toutes les tables",filter:!0,showClear:!0,class:"w-full",onChange:U},null,8,["modelValue","options"])]),s("div",null,[e[9]||(e[9]=s("label",{class:"block text-sm"},"Période",-1)),n(O,{onSelectDate:E,defaultPeriod:"month",class:"w-full"})]),s("div",null,[e[10]||(e[10]=s("label",{class:"block text-sm"},"Utilisateur",-1)),n(g,{size:"small",modelValue:c.value,"onUpdate:modelValue":e[4]||(e[4]=o=>c.value=o),options:f.value,optionLabel:"NomUtilisateur",optionValue:"id_utilisateur",placeholder:"Tous les utilisateurs",filter:!0,showClear:!0,class:"w-full"},null,8,["modelValue","options"])]),s("div",null,[e[11]||(e[11]=s("label",{class:"block text-sm"},"Type d'action",-1)),n(g,{size:"small",modelValue:v.value,"onUpdate:modelValue":e[5]||(e[5]=o=>v.value=o),options:V.value,optionLabel:"label",optionValue:"value",placeholder:"Toutes les actions",showClear:!0,class:"w-full"},null,8,["modelValue","options"])]),s("div",null,[e[12]||(e[12]=s("label",{class:"block text-sm"},"Clé (ID)",-1)),n(I,{size:"small",modelValue:b.value,"onUpdate:modelValue":e[6]||(e[6]=o=>b.value=o),placeholder:"Valeur de la clé primaire",class:"w-full"},null,8,["modelValue"])])])]),e[13]||(e[13]=s("div",{class:"h-2"},null,-1)),s("div",le,[n(Y,{ref_key:"agGrid",ref:T,"excel-file-name":"Journal evenements","excel-sheet-name":"Journal evenements","row-data":m.value,"excluded-columns":["id"],"date-columns":[],"column-widths":{Table:130,CleValeur:120,DateAction:160,TypeAction:120,Utilisateur:150,Changements:400},"custom-renderers":k,"enable-totals":!1,rowIdField:"id",onGridReady:S},null,8,["row-data"])])],64)}}};export{pe as default};
