import{_ as R}from"./RapportDynamique-xqwJEOK-.js";import{_ as j}from"./selectDate-Dd47YHbm.js";import{_ as H}from"./FavorisSwitch-DFHH_fud.js";import{r as o,f as L,o as d,c as W,b as l,a as u,q as C,z as O,av as K,i as x,d as D,F as Q}from"./vendor-BDR7yMJi.js";import{u as J,s,S as V,a as $,f as k}from"./index-BSaHX2oa.js";import{_ as U}from"./DataGrid-DbeHIyBR.js";import"./useAgGridConfig-DxO2r97K.js";const X={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},Y={class:"btns flex items-center gap-2"},Z={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},ee={class:"p-2"},te={class:"grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-4 gap-3"},se={style:{height:"calc(100vh - 280px)"}},ue={__name:"TvaParFacture",props:["masquerFermer"],setup(P){const{showError:A,showInfo:f,showWarn:b}=J(),E=P,T=o(),v=o(),w=o(null),m=o(!1),i=o([]),_=o([]),F=o({}),y=o(0),g=o(s.state.dossier.dated),h=o(s.state.dossier.datef),M=(t,e)=>{g.value=t,h.value=e},q=t=>{w.value=t.api},B=t=>{if(!t||t.length===0)return;const e=t[0],n=[],r={code_client:"Code client",client:"Client",nfacturec:"N° Facture",date:"Date",ttc:"TTC"};n.push("ttc"),Object.keys(e).forEach(a=>{if(a.startsWith("HT_")){const c=a.replace("HT_","");n.push(a),r[a]=`HT ${c}%`}if(a.startsWith("TVA_")){const c=a.replace("TVA_","");n.push(a),r[a]=`TVA ${c}%`}}),_.value=n,F.value=r},G=async()=>{s.state.afficher_in_progress=!0;try{const t=g.value?k(g.value):null,e=h.value?k(h.value):null,r=(await $.post(`${s.lienApi}/FacturesClientParTVA/${s.db}`,{dateDu:t,dateAu:e})).data||[];B(r),y.value++,i.value=r,r.length===0&&f("Aucune donnée trouvée pour cette période")}catch(t){const e=t.response?.data?.message||t.message;A(e)}finally{s.state.afficher_in_progress=!1}},S=()=>{if(!i.value||i.value.length===0){b("Aucune donnée à imprimer");return}m.value=!0},z=()=>{if(!v.value){f("Grille non initialisée");return}if(i.value.length===0){f("Aucune donnée à exporter");return}v.value.exportToExcel()},I=async()=>{try{const e=(await $.post(`${s.lienApi}/verifierDroit/${s.state.dbCommun6}`,{id_utilisateur:s.userId,id_page:413,mail:s.state.userCloud.mail})).data;e&&Object.keys(e).length>0&&(e.lecture||(b("Vous n'avez pas le droit, veuillez consulter l'administrateur"),V("TvaParFacture")))}catch(t){const e=t.response?.data?.message||t.message;A(e)}};return L(async()=>{await I()}),(t,e)=>{const n=O,r=K,a=H,c=j,N=R;return d(),W(Q,null,[l("div",X,[l("div",Y,[u(n,{icon:"pi pi-search",label:"Afficher",onClick:e[0]||(e[0]=p=>G()),text:"",loading:C(s).state.afficher_in_progress},null,8,["loading"]),u(n,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=p=>T.value.toggle(p))}),u(r,{ref_key:"actionsMenu",ref:T,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>z()},{label:"Imprimer",icon:"pi pi-print",command:()=>S()}],popup:!0},null,8,["model"]),E.masquerFermer?D("",!0):(d(),x(n,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=p=>C(V)("TvaParFacture"))}))]),l("div",Z,[u(a,{fen:"TvaParFacture",text:"TVA Par Facture"})])]),l("div",ee,[l("div",te,[l("div",null,[e[4]||(e[4]=l("label",{class:"block text-sm font-medium mb-1"},"Période",-1)),u(c,{onSelectDate:M,size:"small"})])])]),e[5]||(e[5]=l("div",{class:"h-2"},null,-1)),l("div",se,[(d(),x(U,{key:y.value,ref_key:"dataGrid",ref:v,"row-data":i.value,"numeric-columns":_.value,"totals-columns":_.value,"date-columns":["date"],"date-only":["date"],"enable-totals":!0,"show-checkbox":!1,"column-widths":{client:200,nfacturec:130},"column-titles":F.value,"excel-file-name":"TVA_par_facture","excel-sheet-name":"TVA par facture",onGridReady:q},null,8,["row-data","numeric-columns","totals-columns","column-titles"]))]),m.value?(d(),x(N,{key:0,show:m.value,dataList:i.value,titre:"TVA Par Facture",gridApi:w.value,onClose:e[3]||(e[3]=p=>m.value=!1)},null,8,["show","dataList","gridApi"])):D("",!0)],64)}}};export{ue as default};
