import{f as J,o as b,c as M,i as T,d as A,an as U,ap as z,b as l,a as m,z as O,av as Y,q as H,ax as K,F as Q,r}from"./vendor-BDR7yMJi.js";import{_ as W}from"./ComboDynamique-DbhbUtR4.js";import{u as X,s,a as R,S as Z}from"./index-BSaHX2oa.js";import ee from"./SaisieReglementsLignes-Cp_1Mb10.js";import{_ as te}from"./DataGrid-DbeHIyBR.js";import"./PiecesJointes-BVFc0aqb.js";import"./consultationEcriture-B-0c1nDo.js";import"./SelectCompte-05OnLt5y.js";import"./useAgGridConfig-DxO2r97K.js";const ae={class:"flex flex-col"},ne={class:"flex flex-row justify-start gap-3"},oe={key:0},le={class:"w-full mb-3 flex flex-col sm:flex-row items-center align-baseline gap-3"},se={class:"mx-3 md:w-1/4"},ie={class:"p-float-label"},re={class:"mx-3 md:w-1/4"},ce={class:"p-float-label"},ue={style:{height:"calc(100vh - 240px)"},class:"mt-2"},be={__name:"SaisieReglements",props:["fermerParRetour"],setup(V){const{showError:C,showInfo:I}=X(),D=r(),$=r(!1),E=[{label:"Exporter Excel",icon:"pi pi-file-excel",command:()=>{G()}}],u=r([]),g=r();g.value=`${new Date().getFullYear()}${String(new Date().getMonth()+1).padStart(2,"0")}`;const w=r(),a=r(),j=t=>{a.value=t.api},y=r(null),F=({ndoc:t})=>{p.value=t,a.value&&a.value.forEachNode(e=>{e.data&&String(e.data.ndoc)===String(t)&&(y.value=e.rowIndex)}),k()},N=()=>{},h=r(" and 1=1 "),p=r(""),_=r(!1),L=[{Id:" and 1=1 ",Libelle:"-----"},{Id:" and t.Reliquat>0 ",Libelle:"Avec Reliquat"},{Id:" and t.Reliquat=0 ",Libelle:"Rapproché totalement"}],P=async(t=[])=>{const e=p.value;_.value=!1,t.length>0&&await q(t),a.value&&setTimeout(()=>{let n=null;if(a.value.forEachNode(o=>{o.data&&String(o.data.ndoc)===String(e)&&(n=o)}),!n&&y.value!==null){const o=a.value.getDisplayedRowCount();if(o>0){const c=Math.min(y.value,o-1);n=a.value.getDisplayedRowAtIndex(c)}}n&&(a.value.deselectAll(),n.setSelected(!0),a.value.ensureNodeVisible(n,"middle"))},100),s.dispatch("tabs/changeTab",{id:"SaisieReglements",newProps:{text:"Saisie Réglements",iconFermer:!0}})};J(async()=>{await x()});const x=async()=>{s.state.afficher_in_progress=!0;try{const t=await R.post(`${s.lienApi}/tva_reglements/${s.db}`,{annee_fiscale:s.state.annee_fiscale,Combo_Periode:g.value,condition1:h.value},{headers:{"Content-Type":"application/json"}});u.value=t.data}catch(t){const e=t.response?.data?.message||t.message;C(`Une erreur est survenue 
 ${e}`)}finally{s.state.afficher_in_progress=!1}},q=async t=>{try{const n=(await R.post(`${s.lienApi}/tva_reglements/${s.db}`,{ndocs:t,condition1:h.value})).data;if(!a.value)return;const o=[],c=[],d=[];for(const i of t){const f=n.find(S=>String(S.ndoc)===String(i)),v=u.value.find(S=>String(S.ndoc)===String(i));f?v?(Object.assign(v,f),o.push(v)):c.push(f):v&&d.push(v)}o.length>0&&a.value.applyTransaction({update:o}),c.length>0&&(u.value.unshift(...c),a.value.applyTransaction({add:c,addIndex:0})),d.length>0&&(u.value=u.value.filter(i=>!d.some(f=>f.ndoc===i.ndoc)),a.value.applyTransaction({remove:d}))}catch{await x()}},k=async()=>{_.value=!0,s.dispatch("tabs/changeTab",{id:"SaisieReglements",newProps:{text:`Saisie réglement N°${p.value}`,iconFermer:!1}})},B=async()=>{try{const e=(await R.post(`${s.lienApi}/AjouterEtRenvoyer_tva_reglements/${s.db}`,{annee_fiscale:s.state.annee_fiscale},{headers:{"Content-Type":"application/json"}})).data;p.value=e.ntva_reglements,k()}catch(t){C(`Erreur lors de l'ajout de la TVA Règlements
 ${t}`)}},G=()=>{if(w.value){if(u.value.length===0){I("Aucune donnée à exporter");return}w.value.exportToExcel()}};return(t,e)=>{const n=O,o=Y,c=W,d=K;return b(),M(Q,null,[_.value?(b(),T(ee,{key:0,modeModification:$.value,ndoc:p.value,onClose:P},null,8,["modeModification","ndoc"])):A("",!0),U(l("div",ae,[l("div",ne,[m(n,{icon:"pi pi-plus-circle",label:"Ajouter",text:"",onClick:B}),$.value?A("",!0):(b(),M("span",oe,[m(n,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[0]||(e[0]=i=>D.value.toggle(i))}),m(o,{ref_key:"menu",ref:D,model:E,popup:!0},null,512)])),V.fermerParRetour?A("",!0):(b(),T(n,{key:1,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=i=>H(Z)("SaisieReglements"))}))]),l("div",null,[l("div",le,[l("div",se,[l("span",ie,[e[4]||(e[4]=l("label",null,"Période",-1)),m(c,{modelValue:g.value,"onUpdate:modelValue":e[2]||(e[2]=i=>g.value=i),table:"MoisFiscalePeriode",class:"w-full",style:{width:"200px"},onChange:x},null,8,["modelValue"])])]),l("div",re,[l("span",ce,[e[5]||(e[5]=l("label",null,"Situation",-1)),m(d,{size:"small",modelValue:h.value,"onUpdate:modelValue":e[3]||(e[3]=i=>h.value=i),options:L,optionLabel:"Libelle",optionValue:"Id",class:"w-full",onChange:x},null,8,["modelValue"])])])]),e[6]||(e[6]=l("div",{class:"h-2"},null,-1)),l("div",ue,[m(te,{ref_key:"dataGrid",ref:w,"excel-file-name":"Saisie reglements","excel-sheet-name":"Saisie reglements","row-data":u.value,"numeric-columns":["Montant","Non rapproché"],"date-columns":["Date"],"date-only":["Date"],"totals-columns":["Montant","Non rapproché"],"document-number-fields":["ndoc"],"excluded-columns":["ndoc"],"column-widths":{fournisseur:250,Libelle:300,Numéro:100,Date:100,Code:100,Mode:100,Journal:100},"show-checkbox":!1,onGridReady:j,onRowClicked:F,onFilterChanged:N},null,8,["row-data"])])])],512),[[z,!_.value]])],64)}}};export{be as default};
