import{R as L}from"./RapportDynamique-DI8KNc5X.js";import{b as W,B as O,v as K}from"./primevue-CfIk0_DY.js";import{s as Q}from"./selectDate-Dai2cu2_.js";import{_ as U}from"./FavorisSwitch-BFqqA1tj.js";import{u as J,s,S as V,b as P,f as M}from"./index-BxIwIJfy.js";import{D as X}from"./DataGrid-CoMfrBJA.js";import{a as r,o as Y,b as f,c as Z,d as a,v as n,a7 as h,k as w,p as q,l as ee}from"./vue-core-Di3IuVqe.js";import"./ReportViewer-BNzhW7G2.js";import"./stimulsoft-B2-Y-rC1.js";import"./cjs-helpers-psZwOBky.js";import"./PDFButton-DhVJ6hNy.js";import"./moment-BeHQNF8T.js";import"./vue-cal-DKMVGERa.js";import"./useAgGridConfig-Dp3DkgaV.js";const te={class:"page-wrapper"},se={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between gap-2 p-1"},ae={class:"btns flex items-center gap-2"},oe={class:"flex items-center gap-3 whitespace-nowrap ml-auto"},re={class:"p-2"},le={class:"hidden lg:grid lg:grid-cols-4 gap-3"},ie={class:"flex flex-col",style:{gap:"16px"}},ne={class:"grille-container"},De={__name:"TvaParFacture",props:["masquerFermer"],setup(B){const{showError:A,showInfo:v,showWarn:D}=J(),E=B,F=r(),g=r(),T=r(null),d=r(!1),u=r([]),_=r([]),y=r({}),C=r(0),b=r(s.state.dossier.dated),x=r(s.state.dossier.datef),m=r(!1),G=()=>{m.value=!1,k()},$=(t,e)=>{b.value=t,x.value=e},R=t=>{T.value=t.api},S=t=>{if(!t||t.length===0)return;const e=t[0],o=[],i={code_client:"Code client",client:"Client",nfacturec:"N° Facture",date:"Date",ttc:"TTC"};o.push("ttc"),Object.keys(e).forEach(l=>{if(l.startsWith("HT_")){const p=l.replace("HT_","");o.push(l),i[l]=`HT ${p}%`}if(l.startsWith("TVA_")){const p=l.replace("TVA_","");o.push(l),i[l]=`TVA ${p}%`}}),_.value=o,y.value=i},k=async()=>{s.state.afficher_in_progress=!0;try{const t=b.value?M(b.value):null,e=x.value?M(x.value):null,i=(await P.post(`${s.lienApi}/FacturesClientParTVA/${s.db}`,{dateDu:t,dateAu:e})).data||[];S(i),C.value++,u.value=i,i.length===0&&v("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}},z=()=>{if(!u.value||u.value.length===0){D("Aucune donnée à imprimer");return}d.value=!0},I=()=>{if(!g.value){v("Grille non initialisée");return}if(u.value.length===0){v("Aucune donnée à exporter");return}g.value.exportToExcel()},N=async()=>{try{const e=(await P.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||(D("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 Y(async()=>{await N()}),(t,e)=>{const o=W,i=O,l=U,p=Q,j=K,H=L;return f(),Z("div",te,[a("div",se,[a("div",ae,[n(o,{icon:"pi pi-search",label:"Afficher",onClick:e[0]||(e[0]=c=>k()),text:"",loading:h(s).state.afficher_in_progress},null,8,["loading"]),n(o,{icon:"pi pi-cog",label:"Actions",text:"",onClick:e[1]||(e[1]=c=>F.value.toggle(c))}),n(i,{ref_key:"actionsMenu",ref:F,model:[{label:"Exporter vers Excel",icon:"pi pi-file-excel",command:()=>I()},{label:"Imprimer",icon:"pi pi-print",command:()=>z()}],popup:!0},null,8,["model"]),E.masquerFermer?q("",!0):(f(),w(o,{key:0,icon:"pi pi-times",label:"Fermer",text:"",onClick:e[2]||(e[2]=c=>h(V)("TvaParFacture"))}))]),a("div",oe,[n(o,{icon:"pi pi-filter",text:"",class:"p-button lg:!hidden",onClick:e[3]||(e[3]=c=>m.value=!0),"aria-label":"Filtres"}),n(l,{fen:"TvaParFacture",text:"TVA Par Facture"})])]),a("div",re,[a("div",le,[a("div",null,[e[6]||(e[6]=a("label",{class:"block text-sm font-medium mb-1"},"Période",-1)),n(p,{onSelectDate:$,size:"small"})])])]),n(j,{visible:m.value,"onUpdate:visible":e[4]||(e[4]=c=>m.value=c),position:"right",header:"Filtres",style:{width:"90%","max-width":"360px"}},{default:ee(()=>[a("div",ie,[a("div",null,[e[7]||(e[7]=a("label",{class:"block",style:{"margin-bottom":"4px"}},"Période",-1)),n(p,{onSelectDate:$,size:"small"})]),n(o,{icon:"pi pi-search",label:"Afficher",onClick:G,loading:h(s).state.afficher_in_progress},null,8,["loading"])])]),_:1},8,["visible"]),e[8]||(e[8]=a("div",{class:"h-2"},null,-1)),a("div",ne,[(f(),w(X,{key:C.value,ref_key:"dataGrid",ref:g,"row-data":u.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":y.value,"excel-file-name":"TVA_par_facture","excel-sheet-name":"TVA par facture",onGridReady:R},null,8,["row-data","numeric-columns","totals-columns","column-titles"]))]),d.value?(f(),w(H,{key:0,show:d.value,dataList:u.value,titre:"TVA Par Facture",gridApi:T.value,onClose:e[5]||(e[5]=c=>d.value=!1)},null,8,["show","dataList","gridApi"])):q("",!0)])}}};export{De as default};
