import{u as A,s as u,S as C,g as D,a as R}from"./index-Bn9WoKhP.js";import{_ as S}from"./ComboDynamique-CzrtYPe1.js";import{r as n,o as z,c as U,b as l,a as o,z as B,q as E,F as J}from"./vendor-0kGcmQpG.js";import{_ as N}from"./DataGrid-tb6QVwpZ.js";import"./useAgGridConfig-DjXMc6wb.js";const F={class:"flex flex-row justify-start gap-2 p-1"},G={class:"flex flex-col gap-4"},L={class:"flex flex-wrap items-end gap-3 px-3"},P={class:"field",style:{"min-width":"220px"}},j={class:"field",style:{"min-width":"220px"}},q={class:"field",style:{"min-width":"140px"}},M={class:"field",style:{"min-width":"140px"}},T={class:"field",style:{"min-width":"200px"}},I={class:"px-3",style:{height:"calc(100vh - 240px)"}},Y={__name:"ReimputationComptable",setup(W){const{confirmAction:_,showSuccess:x,showError:w,showWarn:d}=A(),g=n([]),a=n(""),i=n(""),v=n(""),m=n([]),f=n(u.state.dossier.dated||""),b=n(u.state.dossier.datef||""),y=n(),$=s=>{y.value=s.api},k=({selectedRows:s})=>{m.value=s},V=async()=>{if(!a.value){d("Veuillez sélectionner le compte à réimputer");return}try{const s=await R.post(`${u.lienApi}/apercuReimputation/${u.db}`,{compteAncien:a.value,dateDu:f.value||null,dateAu:b.value||null,codeJournal:v.value||null});g.value=s.data,x(`${s.data.length} écriture(s) trouvée(s)`)}catch(s){w(`Erreur lors du chargement : ${s.message}`)}},h=async()=>{if(!a.value||!i.value){d("Veuillez sélectionner les deux comptes");return}if(a.value===i.value){d("Les deux comptes doivent être différents");return}if(m.value.length===0){d("Veuillez sélectionner les lignes à réimputer");return}if(await _(`Réimputer ${m.value.length} écriture(s) du compte ${a.value} vers ${i.value} ? Cette opération est irréversible.`))try{const e=m.value.map(c=>c.idRow),r=(await R.post(`${u.lienApi}/executerReimputation/${u.db}`,{ids:e,compteNouveau:i.value,compteAncien:a.value})).data?.NbLignesModifiees||0;x(`Réimputation terminée : ${r} écriture(s) modifiée(s)`),V()}catch(e){w(`Erreur lors de la réimputation : ${e.response?.data?.message||e.message}`)}};return(s,e)=>{const p=B,r=S,c=D;return z(),U(J,null,[l("div",F,[o(p,{icon:"pi pi-refresh",label:"Afficher",text:"",onClick:e[0]||(e[0]=t=>V())}),o(p,{icon:"pi pi-sync",label:"Réimputer",text:"",onClick:e[1]||(e[1]=t=>h())}),o(p,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=t=>E(C)("ReimputationComptable"))})]),l("div",G,[l("div",L,[l("div",P,[e[8]||(e[8]=l("label",{class:"block mb-1 text-sm"},"Compte à réimputer",-1)),o(r,{placeholder:"Sélectionner un compte",table:"compte",modelValue:a.value,"onUpdate:modelValue":e[3]||(e[3]=t=>a.value=t),class:"w-full"},null,8,["modelValue"])]),l("div",j,[e[9]||(e[9]=l("label",{class:"block mb-1 text-sm"},"Réimputer par",-1)),o(r,{placeholder:"Sélectionner un compte",table:"compte",modelValue:i.value,"onUpdate:modelValue":e[4]||(e[4]=t=>i.value=t),class:"w-full"},null,8,["modelValue"])]),l("div",q,[e[10]||(e[10]=l("label",{class:"block mb-1 text-sm"},"Du",-1)),o(c,{size:"small",modelValue:f.value,"onUpdate:modelValue":e[5]||(e[5]=t=>f.value=t),"input-class":"w-full"},null,8,["modelValue"])]),l("div",M,[e[11]||(e[11]=l("label",{class:"block mb-1 text-sm"},"Au",-1)),o(c,{size:"small",modelValue:b.value,"onUpdate:modelValue":e[6]||(e[6]=t=>b.value=t),"input-class":"w-full"},null,8,["modelValue"])]),l("div",T,[e[12]||(e[12]=l("label",{class:"block mb-1 text-sm"},"Journal",-1)),o(r,{placeholder:"Tous les journaux",table:"Journal",modelValue:v.value,"onUpdate:modelValue":e[7]||(e[7]=t=>v.value=t),class:"w-full"},null,8,["modelValue"])])]),l("div",I,[o(N,{ref:"dataGrid","excel-file-name":"Reimputation","excel-sheet-name":"Réimputation comptable","row-data":g.value,"excluded-columns":["idRow"],"numeric-columns":["debit","credit"],"date-columns":["date"],"date-only":["date"],"totals-columns":["debit","credit"],"column-widths":{libelle:250,intitule:250},onGridReady:$,onSelectionChanged:k},null,8,["row-data"])])])],64)}}};export{Y as default};
