import{b as W,U as Q,a5 as D,z as X,A as V,X as Y,a6 as Z}from"./primevue-CfIk0_DY.js";import{C as G}from"./ComboDynamique-BzWI4ISP.js";import{_ as J}from"./FavorisSwitch-BFqqA1tj.js";import{o as K,j as ee,H as ae,b as A,c as S,d as t,v as s,a7 as l,p as z,k as te,l as m,t as se,a as u,y as i,E as le}from"./vue-core-Di3IuVqe.js";import{_ as re,u as ne,S as H,j as P,o as f,b as j,s as c,f as B}from"./index-BxIwIJfy.js";import"./cjs-helpers-psZwOBky.js";import"./vue-cal-DKMVGERa.js";import"./moment-BeHQNF8T.js";const oe={class:"page-wrapper w-full"},ie={class:"flex min-w-full flex-col lg:flex-row lg:items-center lg:justify-between",style:{gap:"8px",padding:"4px"}},ce={class:"flex items-center",style:{gap:"8px"}},ue={class:"flex items-center whitespace-nowrap",style:{gap:"12px"}},de={class:"rounded-lg shrink-0",style:{padding:"12px","margin-bottom":"12px"}},pe={class:"grid grid-cols-1 md:grid-cols-3",style:{gap:"16px"}},ve={key:0},me={class:"flex flex-wrap items-center",style:{gap:"8px","margin-bottom":"8px"}},fe={class:"panel-inner"},ge={class:"panel-card"},he={class:"font-semibold"},_e={class:"panel-inner"},be={class:"panel-card"},ye={style:{flex:"1","min-height":"0",padding:"12px"}},xe={__name:"CAParTrancheHoraire",setup(Ae){const{showError:C,showWarn:w}=ne(),g=le({lecture:!1,ajout:!1}),E=async()=>{try{const e=(await j.post(`${c.lienApi}/verifierDroit/${c.state.dbCommun6}`,{id_utilisateur:c.userId,id_page:1105,mail:c.state.userCloud.mail},{headers:{"Content-Type":"application/json"}})).data;e&&Object.keys(e).length>0&&(g.lecture=e.lecture,g.ajout=e.ajout),g.lecture||(w("Vous n'avez pas le droit, veuillez consulter l'administrateur"),H("CAParTrancheHoraire"))}catch(a){C("Une erreur est survenue : "+(a.response?.data?.message||a.message))}},d=u(new Date),p=u(new Date),h=u(0),F=i(()=>!!c.state.enreg_option_comm?.numerotation_par_agence),$=i(()=>c.state.userCommun6?.id_agence||0),U=i(()=>!!c.state.userCommun6?.Access_Agence),I=i(()=>$.value>0&&!U.value),N=i(()=>F.value),_=u(!1),r=u([]),T=()=>{const a=[];for(let e=0;e<24;e++){const n=e.toString().padStart(2,"0"),v=(e+1).toString().padStart(2,"0");a.push({Tranche:`${n} - ${v}`,heure:e,ca:0})}return a};r.value=T();const R=i(()=>r.value.reduce((a,e)=>a+(e.ca||0),0)),b=i(()=>r.value.filter(a=>(a.ca||0)>0).length),y=i(()=>{const a=r.value.filter(e=>(e.ca||0)>0);return a.length?a.reduce((e,n)=>n.ca>e.ca?n:e,a[0]):null}),k=async()=>{if(!d.value||!p.value){w("Veuillez sélectionner une période");return}_.value=!0;try{r.value=T();const a=await j.post(`${c.lienApi}/CAParTrancheHoraire/${c.db}`,{dateDu:B(d.value),dateAu:B(p.value),id_agence:h.value});a.data&&Array.isArray(a.data)&&a.data.forEach(e=>{const n=r.value.findIndex(v=>v.heure===e.heur);n!==-1&&(r.value[n].ca=e.ca||0)})}catch(a){C(`Erreur lors du chargement des données
${a.response?.data?.message||a.message}`)}finally{_.value=!1}},q=a=>a.ca>0?"bg-blue-50":"",L=i(()=>({labels:r.value.map(a=>a.Tranche),datasets:[{label:"Chiffre d'affaire",data:r.value.map(a=>a.ca),fill:!0,borderColor:"#8b5cf6",backgroundColor:"rgba(139, 92, 246, 0.2)",tension:.4,pointRadius:5,pointHoverRadius:7,pointBackgroundColor:"#8b5cf6",pointBorderColor:"#fff",pointBorderWidth:2}]})),M=u({responsive:!0,maintainAspectRatio:!1,plugins:{legend:{display:!0,position:"top"},tooltip:{callbacks:{label:function(a){return`CA: ${f(a.parsed.y)}`}}}},scales:{y:{beginAtZero:!0,ticks:{callback:function(a){return f(a)}}},x:{grid:{display:!0}}}});return K(async()=>{await E();const a=new Date;d.value=new Date(a.getFullYear(),a.getMonth(),1),p.value=a,h.value=$.value,k()}),(a,e)=>{const n=W,v=J,O=G,x=Q;return ee((A(),S("div",oe,[t("div",ie,[t("div",ce,[s(n,{icon:"pi pi-search",label:"Afficher",onClick:e[0]||(e[0]=o=>k()),text:"",loading:_.value},null,8,["loading"]),s(n,{icon:"pi pi-times",label:"Fermer",text:"",onClick:e[1]||(e[1]=o=>l(H)("CAParTrancheHoraire"))})]),t("div",ue,[s(v,{fen:"CAParTrancheHoraire",text:"Chiffre d'affaire par tranche horaire"})])]),t("div",de,[t("div",pe,[t("div",null,[e[5]||(e[5]=t("label",{class:"block",style:{"margin-bottom":"4px"}},"Du",-1)),s(P,{modelValue:d.value,"onUpdate:modelValue":e[2]||(e[2]=o=>d.value=o),"input-class":"w-full"},null,8,["modelValue"])]),t("div",null,[e[6]||(e[6]=t("label",{class:"block",style:{"margin-bottom":"4px"}},"Au",-1)),s(P,{modelValue:p.value,"onUpdate:modelValue":e[3]||(e[3]=o=>p.value=o),"input-class":"w-full"},null,8,["modelValue"])]),N.value?(A(),S("div",ve,[e[7]||(e[7]=t("label",{class:"block",style:{"margin-bottom":"4px"}},"Agence",-1)),s(O,{modelValue:h.value,"onUpdate:modelValue":e[4]||(e[4]=o=>h.value=o),placeholder:"Toutes les agences",table:"agence",class:"w-full",size:"small",disabled:I.value},null,8,["modelValue","disabled"])])):z("",!0)])]),t("div",me,[s(x,{value:`Total CA : ${l(f)(R.value)}`,severity:"info",icon:"pi pi-wallet"},null,8,["value"]),y.value?(A(),te(x,{key:0,value:`Pic : ${y.value.Tranche} (${l(f)(y.value.ca)})`,severity:"success",icon:"pi pi-arrow-up"},null,8,["value"])):z("",!0),s(x,{value:`${b.value} tranche${b.value>1?"s":""} active${b.value>1?"s":""}`,severity:"secondary",icon:"pi pi-clock"},null,8,["value"])]),s(l(Z),{class:"grille-container"},{default:m(()=>[s(l(D),{size:35,minSize:20},{default:m(()=>[t("div",fe,[t("div",ge,[e[8]||(e[8]=t("div",{class:"panel-header"},[t("i",{class:"pi pi-table"}),t("span",null,"Détail par tranche")],-1)),s(l(X),{value:r.value,scrollable:"",scrollHeight:"flex",size:"small",rowClass:q,class:"flex-1"},{default:m(()=>[s(l(V),{field:"Tranche",header:"Tranche",style:{width:"150px"}}),s(l(V),{field:"ca",header:"Chiffre d'affaire"},{body:m(o=>[t("span",he,se(l(f)(o.data.ca)),1)]),_:1})]),_:1},8,["value"])])])]),_:1}),s(l(D),{size:65,minSize:40},{default:m(()=>[t("div",_e,[t("div",be,[e[9]||(e[9]=t("div",{class:"panel-header"},[t("i",{class:"pi pi-chart-line"}),t("span",null,"Évolution sur 24h")],-1)),t("div",ye,[s(l(Y),{type:"line",data:L.value,options:M.value,style:{height:"100%"}},null,8,["data","options"])])])])]),_:1})]),_:1})],512)),[[ae,g.lecture]])}}},ze=re(xe,[["__scopeId","data-v-c058d6fc"]]);export{ze as default};
