import{y as j,A as L,U as H,b as q,m as G,z as J}from"./primevue-CfIk0_DY.js";import{u as K,b as O,s as c}from"./index-BxIwIJfy.js";import{R as Q}from"./ReportViewer-BNzhW7G2.js";import{u as W}from"./usePortailImpression-o_s9XGOt.js";import{a as u,o as X,b,c as Z,a7 as s,k as ee,p as te,d as n,t as d,v as a,l,f as D,j as C,y as h}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";import"./stimulsoft-B2-Y-rC1.js";import"./PDFButton-DhVJ6hNy.js";const oe={class:"max-w-5xl mx-auto"},ae={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},ne={class:"text-gray-500",style:{"margin-top":"2px"}},se={class:"font-mono font-bold text-blue-700"},le={class:"font-semibold"},re={class:"flex gap-1"},xe={__name:"PortailClientAvoirs",setup(ie){const{showError:f}=K(),{ouvrireReport:p,urlFichierRapport:F,nomFichierImpression:$,dataReport:k,apercuEnCours:A,telechargementEnCours:N,apercevoir:R,telecharger:T}=W(),g=h(()=>c.state.portailClientDb),y=h(()=>c.state.portailClientClient?.code_client),V=h(()=>c.state.portailClientToken),m=u(new Date().getFullYear()),B=u([new Date().getFullYear(),new Date().getFullYear()-1,new Date().getFullYear()-2]),i=u([]),v=u(!1),z=t=>t==null?"0,00":Number(t).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),E=t=>{if(!t)return"—";const o=new Date(t);return isNaN(o)?"—":o.toLocaleDateString("fr-FR")},x=async()=>{if(!(!g.value||!y.value)){v.value=!0;try{const t=await O.get(`${c.lienApi}/portail-client/avoirs/${g.value}/${encodeURIComponent(y.value)}`,{params:{annee:m.value},headers:{Authorization:`Bearer ${V.value}`}});i.value=t.data||[]}catch{i.value=[]}finally{v.value=!1}}},S=async t=>{try{await R({type:"avoir",nDoc:t.ndoc,libelleDocument:"Avoir Client",fileName:`Avoir_${t.ndoc}`})}catch(o){f(o.message||"Erreur lors de l'apercu.")}},I=async t=>{try{await T({type:"avoir",nDoc:t.ndoc,libelleDocument:"Avoir Client",fileName:`Avoir_${t.ndoc}.pdf`})}catch(o){f(o.message||"Erreur lors du telechargement.")}};return X(x),(t,o)=>{const M=j,r=L,Y=H,_=q,P=J,w=G;return b(),Z("div",oe,[s(p)?(b(),ee(Q,{key:0,show:s(p),onClose:o[0]||(o[0]=e=>p.value=!1),data:s(k),urlFichier:s(F),nomFichier:s($)},null,8,["show","data","urlFichier","nomFichier"])):te("",!0),n("div",ae,[n("div",null,[o[2]||(o[2]=n("h1",{class:"text-2xl font-bold text-gray-800"},"Mes avoirs",-1)),n("p",ne,d(i.value.length)+" resultat(s)",1)]),a(M,{modelValue:m.value,"onUpdate:modelValue":o[1]||(o[1]=e=>m.value=e),options:B.value,onChange:x,size:"small",style:{"min-width":"100px"}},null,8,["modelValue","options"])]),a(P,{value:i.value,loading:v.value,stripedRows:"",size:"small",paginator:"",rows:20,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:l(()=>[...o[3]||(o[3]=[n("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[n("i",{class:"pi pi-inbox text-3xl block",style:{"margin-bottom":"8px"}}),D(" Aucun avoir pour cette annee. ")],-1)])]),default:l(()=>[a(r,{field:"ndoc",header:"N°",style:{width:"110px"}},{body:l(({data:e})=>[n("span",se,d(e.ndoc),1)]),_:1}),a(r,{field:"date",header:"Date",style:{width:"120px"}},{body:l(({data:e})=>[D(d(E(e.date)),1)]),_:1}),a(r,{field:"ttc_dh",header:"Montant TTC",style:{width:"150px"}},{body:l(({data:e})=>[n("span",le,d(z(e.ttc_dh))+" DH",1)]),_:1}),a(r,{field:"statut",header:"Statut",style:{width:"130px"}},{body:l(({data:e})=>[a(Y,{value:e.statut,severity:e.statut==="Brouillon"?"secondary":"success"},null,8,["value","severity"])]),_:1}),a(r,{header:"",style:{width:"110px"}},{body:l(({data:e})=>[n("div",re,[C(a(_,{icon:"pi pi-eye",text:"",rounded:"",size:"small",loading:s(A)===e.ndoc,onClick:U=>S(e)},null,8,["loading","onClick"]),[[w,"Apercu"]]),C(a(_,{icon:"pi pi-download",text:"",rounded:"",size:"small",loading:s(N)===e.ndoc,onClick:U=>I(e)},null,8,["loading","onClick"]),[[w,"Telecharger PDF"]])])]),_:1})]),_:1},8,["value","loading"])])}}};export{xe as default};
