import{b as j,A as L,j as U,U as H,m as G,z as J}from"./primevue-CfIk0_DY.js";import{u as K,b as O,s as m}from"./index-BxIwIJfy.js";import{R as Q}from"./ReportViewer-BNzhW7G2.js";import{u as W}from"./usePortailImpression-o_s9XGOt.js";import{o as X,b as y,c as Y,a7 as r,k as Z,p as ee,d as s,t as l,v as n,l as a,f as b,j as w,a 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 te={class:"max-w-6xl mx-auto"},oe={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"},ae={class:"font-semibold"},re={class:"flex items-center gap-2"},ie={class:"text-xs text-gray-600"},le={class:"flex gap-1"},ye={__name:"PortailClientCommandes",setup(ce){const{showError:f}=K(),{ouvrireReport:u,urlFichierRapport:D,nomFichierImpression:k,dataReport:$,apercuEnCours:N,telechargementEnCours:B,apercevoir:F,telecharger:R}=W(),_=h(()=>m.state.portailClientDb),v=h(()=>m.state.portailClientClient?.code_client),T=h(()=>m.state.portailClientToken),d=C([]),p=C(!1),z=e=>e==null?"0,00":Number(e).toLocaleString("fr-FR",{minimumFractionDigits:2,maximumFractionDigits:2}),A=e=>{if(!e)return"—";const o=new Date(e);return isNaN(o)?"—":o.toLocaleDateString("fr-FR")},E=e=>{const o=Number(e.qte||0),c=Number(e.qte_livre||0);return o>0?Math.round(c/o*100):0},g=async()=>{if(!(!_.value||!v.value)){p.value=!0;try{const e=await O.get(`${m.lienApi}/portail-client/commandes-en-cours/${_.value}/${encodeURIComponent(v.value)}`,{headers:{Authorization:`Bearer ${T.value}`}});d.value=e.data||[]}catch{d.value=[]}finally{p.value=!1}}},M=async e=>{try{await F({type:"bcomc",nDoc:e.ndoc,libelleDocument:"Bon commande client",fileName:`BC_${e.ndoc}`})}catch(o){f(o.message||"Erreur lors de l'apercu.")}},V=async e=>{try{await R({type:"bcomc",nDoc:e.ndoc,libelleDocument:"Bon commande client",fileName:`BC_${e.ndoc}.pdf`})}catch(o){f(o.message||"Erreur lors du telechargement.")}};return X(g),(e,o)=>{const c=j,i=L,q=U,I=H,P=J,x=G;return y(),Y("div",te,[r(u)?(y(),Z(Q,{key:0,show:r(u),onClose:o[0]||(o[0]=t=>u.value=!1),data:r($),urlFichier:r(D),nomFichier:r(k)},null,8,["show","data","urlFichier","nomFichier"])):ee("",!0),s("div",oe,[s("div",null,[o[1]||(o[1]=s("h1",{class:"text-2xl font-bold text-gray-800"},"Commandes en attente",-1)),s("p",ne,l(d.value.length)+" commande(s) en attente de livraison ",1)]),n(c,{label:"Rafraichir",icon:"pi pi-refresh",onClick:g,size:"small"})]),n(P,{value:d.value,loading:p.value,stripedRows:"",size:"small",paginator:"",rows:20,class:"bg-white rounded-xl shadow-sm overflow-hidden"},{empty:a(()=>[...o[2]||(o[2]=[s("div",{class:"text-center text-gray-400",style:{padding:"32px 0"}},[s("i",{class:"pi pi-check-circle text-3xl block",style:{"margin-bottom":"8px"}}),b(" Aucune commande en attente. Tout est livre ! ")],-1)])]),default:a(()=>[n(i,{field:"ndoc",header:"N°",style:{width:"110px"}},{body:a(({data:t})=>[s("span",se,l(t.ndoc),1)]),_:1}),n(i,{field:"date",header:"Date",style:{width:"120px"}},{body:a(({data:t})=>[b(l(A(t.date)),1)]),_:1}),n(i,{field:"ttc_dh",header:"Montant TTC",style:{width:"150px"}},{body:a(({data:t})=>[s("span",ae,l(z(t.ttc_dh))+" DH",1)]),_:1}),n(i,{header:"Avancement livraison",style:{width:"200px"}},{body:a(({data:t})=>[s("div",re,[n(q,{value:E(t),showValue:!1,style:{height:"8px",flex:"1"}},null,8,["value"]),s("span",ie,l(Math.round(t.qte_livre||0))+" / "+l(Math.round(t.qte||0)),1)])]),_:1}),n(i,{field:"statut",header:"Statut",style:{width:"160px"}},{body:a(({data:t})=>[n(I,{value:t.statut,severity:t.statut==="Livre partiellement"?"warn":"info"},null,8,["value","severity"])]),_:1}),n(i,{header:"",style:{width:"110px"}},{body:a(({data:t})=>[s("div",le,[w(n(c,{icon:"pi pi-eye",text:"",rounded:"",size:"small",loading:r(N)===t.ndoc,onClick:S=>M(t)},null,8,["loading","onClick"]),[[x,"Apercu"]]),w(n(c,{icon:"pi pi-download",text:"",rounded:"",size:"small",loading:r(B)===t.ndoc,onClick:S=>V(t)},null,8,["loading","onClick"]),[[x,"Telecharger PDF"]])])]),_:1})]),_:1},8,["value","loading"])])}}};export{ye as default};
