import{f as R,g as A,o as B,c as E,b as l,a as i,z as M,q as L,j as v,S as j,F as q,r as s}from"./vendor-BDR7yMJi.js";import{u as I,s as a,a as b,S as J,k as V,h}from"./index-BSaHX2oa.js";const H={class:"flex flex-col"},W={class:"flex flex-row justify-start gap-3"},U={style:"height: calc(100vh - 240px)",class:"mt-2 ag-theme-quartz"},Q={__name:"Enregistrerabonnements",setup(K){const{showSuccess:C,showError:m,showWarn:f}=I(),_=s(),r=s(),w=s([{headerName:"",checkboxSelection:!0,headerCheckboxSelection:!0,width:50,sortable:!1,filter:!1,resizable:!1},{field:"Date",headerName:"Date",width:120,sortable:!0,filter:"agTextColumnFilter",resizable:!0,valueFormatter:t=>t.value?V(t.value):""},{field:"Compte",headerName:"Compte",width:120,sortable:!0,filter:"agTextColumnFilter",resizable:!0},{field:"Libellé",headerName:"Libellé d'écriture",width:200,sortable:!0,filter:"agTextColumnFilter",resizable:!0},{field:"Debit",headerName:"Debit",width:120,sortable:!0,filter:"agTextColumnFilter",resizable:!0,cellStyle:{textAlign:"right"},valueFormatter:t=>t.value?h(t.value):"",aggFunc:"sum"},{field:"Credit",headerName:"Credit",width:120,sortable:!0,filter:"agTextColumnFilter",resizable:!0,cellStyle:{textAlign:"right"},valueFormatter:t=>t.value?h(t.value):"",aggFunc:"sum"},{field:"Journal",headerName:"Journal",width:120,sortable:!0,filter:"agTextColumnFilter",resizable:!0}]),x=s({sortable:!0,filter:"agTextColumnFilter",resizable:!0,suppressHeaderMenuButton:!0}),y=s({mode:"multiRow",checkboxes:!0,enableClickSelection:!0}),D=t=>{r.value=t.api,setTimeout(()=>{r.value&&r.value.sizeColumnsToFit()},100)},F=()=>{r.value&&(o.value=r.value.getSelectedRows())},u=s(!1),d=s([]),o=s([]),S=s([]);R(async()=>{await p()});const p=async()=>{a.state.afficher_in_progress=!0;try{const t=await b.post(`${a.lienApi}/abonnementsComptaNonGeneres/${a.db}`,{annee_fiscale:a.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});d.value=t.data.map((e,n)=>({_tempId:`db_${e.id_abonnement}_${e.id_ecriture}_${n}`,id_abonnement:e.id_abonnement,Date:e.Date,Compte:e.compte,Libellé:e.description,Debit:e.Debit||0,Credit:e.Credit||0,Journal:e.Journal,id_ecriture:e.id_ecriture}))}catch(t){const e=t.response?.data?.message||t.message;m("Erreur lors du chargement des données : "+e),d.value=[]}finally{a.state.afficher_in_progress=!1}},k=()=>{const t=r.value?r.value.getSelectedNodes():[];if(t.length===0){f("Veuillez sélectionner au moins une ligne");return}o.value=t.map(e=>e.data),u.value=!0},z=()=>["copy","copyWithHeaders","separator","export"],T=()=>{},g=()=>{},$=async()=>{if(u.value=!1,!o.value||o.value.length===0){f("Aucune ligne sélectionnée");return}a.state.afficher_in_progress=!0;try{const t=await b.post(`${a.lienApi}/genererEcrituresAbonnement/${a.db}`,{lignes_selectionnees:o.value,annee_fiscale:a.state.annee_fiscale},{headers:{"Content-Type":"application/json"}});C(`${t.data.nb_ecritures} écriture(s) générée(s) avec succès`),await p(),r.value&&r.value.deselectAll(),o.value=[]}catch(t){const e=t.response?.data?.message||t.message;m("Erreur lors de la génération des écritures : "+e)}finally{a.state.afficher_in_progress=!1}};return(t,e)=>{const n=M,G=A("ag-grid-vue"),N=j;return B(),E(q,null,[l("div",H,[l("div",W,[i(n,{icon:"pi pi-save",label:"Générer les écritures",text:"",onClick:e[0]||(e[0]=c=>k())}),i(n,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=c=>L(J)("Enregistrerabonnements"))})]),l("div",null,[l("div",U,[i(G,{ref_key:"agGrid",ref:_,localeText:t.$agGridLocale,rowData:d.value,columnDefs:w.value,defaultColDef:x.value,theme:t.$agGridTheme,rowSelection:y.value,suppressRowClickSelection:!1,pinnedBottomRowData:S.value,getContextMenuItems:z,onGridReady:D,onRowClicked:T,onSelectionChanged:F,onFilterChanged:g,onSortChanged:g,class:"ag-theme-quartz",style:{height:"100%",width:"100%"}},null,8,["localeText","rowData","columnDefs","defaultColDef","theme","rowSelection","pinnedBottomRowData"])])])]),i(N,{visible:u.value,"onUpdate:visible":e[3]||(e[3]=c=>u.value=c),header:"Génération d'écritures",modal:!0,style:{width:"450px"}},{footer:v(()=>[i(n,{label:"Annuler",icon:"pi pi-times",onClick:e[2]||(e[2]=c=>u.value=!1),text:""}),i(n,{label:"Générer",icon:"pi pi-check",onClick:$,class:"p-button-primary",autofocus:""})]),default:v(()=>[e[4]||(e[4]=l("div",{class:"flex flex-column align-items-center p-4"},[l("i",{class:"pi pi-question-circle mb-3",style:{"font-size":"2rem",color:"var(--blue-500)"}}),l("p",null,"Voulez-vous générer les écritures pour les lignes sélectionnées ?")],-1))]),_:1},8,["visible"])],64)}}};export{Q as default};
