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