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