import{o as B,H as R,b as I,A as M,z as U}from"./primevue-CfIk0_DY.js";import{b as q,s as c}from"./index-BxIwIJfy.js";import{I as L}from"./InfoBulle-R_p1ZfIR.js";import{o as T,b as y,c as v,d as l,f as D,t as i,q as k,v as a,l as d,p as A,E,y as p,a as N}from"./vue-core-Di3IuVqe.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const H={class:"max-w-6xl mx-auto"},P={class:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-3",style:{"margin-bottom":"16px"}},Y={class:"text-gray-500",style:{"margin-top":"2px"}},j={class:"flex gap-2 items-end flex-wrap"},G={class:"flex items-center gap-2"},J={key:0,class:"text-red-600"},K={key:0,class:"text-green-600"},le={__name:"PortailClientReleve",setup(O){const _=p(()=>c.state.portailClientDb),h=p(()=>c.state.portailClientClient?.code_client),$=p(()=>c.state.portailClientToken),w=new Date,F=new Date(w.getFullYear(),0,1),s=E({dateDu:F,dateAu:w,nonSolde:!1}),n=N([]),x=N(!1),f=p(()=>{if(!n.value.length)return 0;const o=n.value[n.value.length-1];return Number(o?.solde||0)}),u=o=>o==null?"0,00":Number(o).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),S=o=>{if(!o)return"—";const e=new Date(o);return isNaN(e)?"—":e.toLocaleDateString("fr-FR")},C=o=>{if(!o)return"";const e=o instanceof Date?o:new Date(o),m=e.getFullYear(),g=String(e.getMonth()+1).padStart(2,"0"),b=String(e.getDate()).padStart(2,"0");return`${m}-${g}-${b}`},V=async()=>{if(!(!_.value||!h.value)){x.value=!0;try{const o=await q.post(`${c.lienApi}/portail-client/releve/${_.value}/${encodeURIComponent(h.value)}`,{dateDu:C(s.dateDu),dateAu:C(s.dateAu),nonSolde:s.nonSolde?1:0},{headers:{Authorization:`Bearer ${$.value}`}});n.value=o.data||[]}catch{n.value=[]}finally{x.value=!1}}};return T(V),(o,e)=>{const m=B,g=R,b=I,r=M,z=U;return y(),v("div",H,[l("div",P,[l("div",null,[e[3]||(e[3]=l("h1",{class:"text-2xl font-bold text-gray-800"},"Mon releve",-1)),l("p",Y,[D(" Solde au "+i(S(s.dateAu))+" : ",1),l("span",{class:k(["font-semibold",f.value>0?"text-red-600":f.value<0?"text-green-600":"text-gray-700"])},i(u(f.value))+" DH ",3)])]),l("div",j,[l("div",null,[e[4]||(e[4]=l("label",{class:"block text-xs text-gray-500",style:{"margin-bottom":"2px"}},"Du",-1)),a(m,{modelValue:s.dateDu,"onUpdate:modelValue":e[0]||(e[0]=t=>s.dateDu=t),dateFormat:"dd/mm/yy",size:"small"},null,8,["modelValue"])]),l("div",null,[e[5]||(e[5]=l("label",{class:"block text-xs text-gray-500",style:{"margin-bottom":"2px"}},"Au",-1)),a(m,{modelValue:s.dateAu,"onUpdate:modelValue":e[1]||(e[1]=t=>s.dateAu=t),dateFormat:"dd/mm/yy",size:"small"},null,8,["modelValue"])]),l("div",G,[a(g,{modelValue:s.nonSolde,"onUpdate:modelValue":e[2]||(e[2]=t=>s.nonSolde=t),binary:"",inputId:"non-solde-rc"},null,8,["modelValue"]),e[6]||(e[6]=l("label",{for:"non-solde-rc",class:"cursor-pointer text-sm"},"Non solde",-1)),a(L,{text:"N'affiche que les pièces <b>non totalement réglées</b> (factures en attente de paiement)."})]),a(b,{label:"Rafraichir",icon:"pi pi-refresh",onClick:V,size:"small"})])]),a(z,{value:n.value,loading:x.value,stripedRows:"",size:"small",paginator:"",rows:50,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:d(()=>[...e[7]||(e[7]=[l("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[l("i",{class:"pi pi-list text-3xl block",style:{"margin-bottom":"8px"}}),D(" Aucun mouvement sur la periode. ")],-1)])]),default:d(()=>[a(r,{field:"date",header:"Date",style:{width:"110px"}},{body:d(({data:t})=>[D(i(S(t.date)),1)]),_:1}),a(r,{field:"ndoc",header:"N° doc",style:{width:"110px"}}),a(r,{field:"libelle",header:"Libelle"}),a(r,{header:"Debit",style:{width:"130px"}},{body:d(({data:t})=>[t.debit>0?(y(),v("span",J,i(u(t.debit)),1)):A("",!0)]),_:1}),a(r,{header:"Credit",style:{width:"130px"}},{body:d(({data:t})=>[t.credit>0?(y(),v("span",K,i(u(t.credit)),1)):A("",!0)]),_:1}),a(r,{header:"Solde",style:{width:"140px"}},{body:d(({data:t})=>[l("span",{class:k(["font-semibold",t.solde>0?"text-red-600":t.solde<0?"text-green-600":""])},i(u(t.solde)),3)]),_:1})]),_:1},8,["value","loading"])])}}};export{le as default};
