PageSourceSearch

https://liefersoft.de/assets/KpiDashboard-C3sRNz-f.js

js liefersoft.de collected 2026-09-24 12:03:42 UTC 35,772 bytes, 6 lines download raw bytes

1import{h as Oe,bk as Ke,r as m,ef as G,at as Me,j as e,C as Ve,f7 as Be,cD as B,ct as Ge,d8 as Ue,cx as De,cv as me,O as Qe,df as qe,G as E,Z as Ze,b9 as Ye,k as Ce,y as He,s as T,dk as ke,ad as Je,af as Xe,ag as et,ah as tt,aj as st,bR as at,cw as Se,bY as Te,g as rt,dq as nt}from"./index-C3wyiG4j.js";import{a as lt}from"./addMonths-C9TK39az.js";import{B as ot}from"./briefcase-iT5ObAXt.js";import{R as fe,B as $e,C as pe,X as be,Y as je,T as Ne,a as ve,b as dt}from"./BarChart-CT4Ufhav.js";import{A as ct,a as ye}from"./AreaChart-sjB9WaNx.js";import{f as k}from"./format-CRNufvVK.js";import{d as le}from"./differenceInDays-c3dYH8lX.js";import{s as Fe}from"./startOfMonth-uoIDQ344.js";import{T as it,a as mt,b as oe,c as de}from"./tabs-BpFB6M4d.js";import{fetchAll as O}from"./useFetchAll-4P6wT-eM.js";import{F as Le}from"./flame-CadE1dv4.js";import{A as xt}from"./award-AfA6tVYe.js";import"./string-Dx7P_S-w.js";import"./linear-DGECpK-G.js";import"./init-Dmth1JHB.js";import"./defaultLocale-C4B-KCzX.js";import"./time-ByyzYylg.js";import"./band-CquvqAHh.js";import"./ordinal-DILIJJjt.js";/**
2 * @license lucide-react v0.462.0 - ISC
3 *
4 * This source code is licensed under the ISC license.
5 * See the LICENSE file in the root directory of this source tree.
6 */const ut=Oe("Medal",[["path",{d:"M7.21 15 2.66 7.14a2 2 0 0 1 .13-2.2L4.4 2.8A2 2 0 0 1 6 2h12a2 2 0 0 1 1.6.8l1.6 2.14a2 2 0 0 1 .14 2.2L16.79 15",key:"143lza"}],["path",{d:"M11 12 5.12 2.2",key:"qhuxz6"}],["path",{d:"m13 12 5.88-9.8",key:"hbye0f"}],["path",{d:"M8 7h8",key:"i86dvs"}],["circle",{cx:"12",cy:"17",r:"5",key:"qbz8iq"}],["path",{d:"M12 18v-2h-.5",key:"fawc4q"}]]);function J(a,f){return lt(a,-f)}const Ae={qualification:"Qualifizierung",proposal:"Angebot",negotiation:"Verhandlung",won:"Gewonnen",lost:"Verloren"},ht={qualification:"#3b82f6",proposal:"#f59e0b",negotiation:"#8b5cf6",won:"#22c55e",lost:"#ef4444"},gt={qualification:"bg-blue-500",proposal:"bg-amber-500",negotiation:"bg-purple-500",won:"bg-green-500",lost:"bg-red-500"},ft=({selectedMonth:a})=>{const{user:f,roles:c}=Ke(),x=c.includes("admin")||c.includes("head_of_sales")||c.includes("senior_manager"),[v,_]=m.useState([]),[M,$]=m.useState([]),[W,X]=m.useState([]),[U,ee]=m.useState([]),[xe,K]=m.useState(!0),[te,z]=m.useState([]);m.useEffect(()=>{(async()=>{K(!0);const[i,h,s,o,g]=await Promise.all([T.from("deals").select("id, stage, value, created_at, closed_at, created_by, assigned_to, lead_id, customer_id"),T.from("leads").select("id, status, created_at, assigned_to, converted_customer_id, full_name, last_contacted_at").is("deleted_at",null),T.from("quotes").select("id, status, created_by, follow_up_date, follow_up_note, created_at, quote_number").is("deleted_at",null),T.from("customers").select("id, status, created_at, created_by").is("deleted_at",null),x?T.from("profiles").select("user_id, full_name"):Promise.resolve({data:null})]);_(i.data||[]),$(h.data||[]),X(s.data||[]),z(o.data||[]),g.data&&ee(g.data),K(!1)})()},[x]);const l=m.useMemo(()=>{const t=`${a}-01`,i=k(G(new Date(t)),"yyyy-MM-dd")+"T23:59:59",h=v.filter(r=>r.created_at<=i&&(r.created_at>=t||r.closed_at&&r.closed_at>=t&&r.closed_at<=i)),s=h.filter(r=>r.stage==="won"||r.stage==="lost"),o=h.filter(r=>r.stage==="won"),g=h.filter(r=>r.stage==="lost"),R=s.length>0?Math.round(o.length/s.length*100):0,p=o.filter(r=>r.closed_at).map(r=>le(new Date(r.closed_at),new Date(r.created_at))),N=p.length>0?Math.round(p.reduce((r,C)=>r+C,0)/p.length):0,b=o.length>0?Math.round(o.reduce((r,C)=>r+(Number(C.value)||0),0)/o.length):0,u=M.filter(r=>r.created_at>=t&&r.created_at<=i),n=u.filter(r=>["qualifiziert","angebot_offen","vertrag_offen","gewonnen"].includes(r.status)),j=u.filter(r=>r.status==="gewonnen"||r.converted_customer_id),y=u.filter(r=>!!r.converted_customer_id),S=u.length>0?Math.round(n.length/u.length*100):0,ue=u.length>0?Math.round(j.length/u.length*100):0,re=u.length>0?Math.round(y.length/u.length*100):0,I=te.filter(r=>r.created_at>=t&&r.created_at<=i),Z=new Set(v.filter(r=>r.customer_id).map(r=>r.customer_id)),Y=I.filter(r=>Z.has(r.id)),he=I.length>0?Math.round(Y.length/I.length*100):0,d=["qualification","proposal","negotiation"].map(r=>{const C=v.filter(A=>A.stage===r),q=C.length>0?Math.round(C.reduce((A,P)=>A+le(new Date,new Date(P.created_at)),0)/C.length):0;return{stage:r,count:C.length,avgDays:q}}),D=Array.from({length:6},(r,C)=>{const q=J(new Date,5-C),A=k(Fe(q),"yyyy-MM-dd"),P=k(G(q),"yyyy-MM-dd")+"T23:59:59",ne=v.filter(w=>w.closed_at&&w.closed_at>=A&&w.closed_at<=P&&(w.stage==="won"||w.stage==="lost")),Re=ne.filter(w=>w.stage==="won"),F=M.filter(w=>w.created_at>=A&&w.created_at<=P),Ie=F.filter(w=>w.status==="gewonnen"||w.converted_customer_id),Pe=F.filter(w=>!!w.converted_customer_id);return{month:k(q,"MMM",{locale:Me}),winRate:ne.length>0?Math.round(Re.length/ne.length*100):0,deals:ne.length,wonDeals:Re.length,leads:F.length,convRate:F.length>0?Math.round(Ie.length/F.length*100):0,leadToCustRate:F.length>0?Math.round(Pe.length/F.length*100):0}}),ze=["qualification","proposal","negotiation"].map(r=>{const C=v.filter(A=>A.stage===r),q=C.reduce((A,P)=>A+(Number(P.value)||0),0);return{stage:r,label:Ae[r],count:C.length,totalValue:q,fill:ht[r]}});return{totalDeals:h.length,wonDeals:o.length,lostDeals:g.length,winRate:R,avgCycleDays:N,avgWonValue:b,leadToQualRate:S,leadToDealRate:ue,leadToCustomerRate:re,customerToDealRate:he,totalLeads:u.length,qualifiedLeads:n.length,convertedLeads:j.length,leadsToCustomersCount:y.length,totalCustomers:I.length,customersConvertedToDealCount:Y.length,stageBreakdown:d,monthlyWinRates:D,pipelineByStage:ze}},[v,M,te,a]),se=m.useMemo(()=>
6{if(!x||U.length===0)return[];const t=`${a}-01`,i=k(G(new Date(t)),"yyyy-MM-dd")+"T23:59:59";return U.map(h=>{const s=h.user_id,o=v.filter(n=>(n.assigned_to===s||n.created_by===s)&&n.created_at<=i&&n.created_at>=t),g=o.filter(n=>n.stage==="won"),R=o.filter(n=>n.stage==="lost"),p=g.length+R.length,N=M.filter(n=>n.assigned_to===s&&n.created_at>=t&&n.created_at<=i),b=W.filter(n=>n.created_by===s&&n.created_at>=t&&n.created_at<=i),u=g.reduce((n,j)=>n+(Number(j.value)||0),0);return{userId:s,fullName:h.full_name||"–",deals:o.length,won:g.length,lost:R.length,winRate:p>0?Math.round(g.length/p*100):0,leads:N.length,quotes:b.length,totalValue:u}}).filter(h=>h.deals>0||h.leads>0||h.quotes>0).sort((h,s)=>s.won-h.won||s.totalValue-h.totalValue)},[x,U,v,M,W,a]),Q=m.useMemo(()=>{const t=new Date;return M.filter(i=>i.status==="neu"&&le(t,new Date(i.created_at))>7).sort((i,h)=>new Date(i.created_at).getTime()-new Date(h.created_at).getTime()).slice(0,10)},[M]),ae=m.useMemo(()=>W.filter(t=>["gesendet","entwurf"].includes(t.status)&&!t.follow_up_date).sort((t,i)=>new Date(t.created_at).getTime()-new Date(i.created_at).getTime()).slice(0,10),[W]);if(xe)return e.jsx("div",{className:"flex items-center justify-center h-32",children:e.jsx("div",{className:"animate-spin rounded-full h-6 w-6 border-b-2 border-primary"})});const L=t=>t.toLocaleString("de-DE",{style:"currency",currency:"EUR",minimumFractionDigits:0});return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-3 xl:grid-cols-6 gap-3",children:[e.jsx(V,{label:"Win-Rate",value:`${l.winRate}%`,icon:Ve,color:"text-green-500",subtitle:`${l.wonDeals} Won / ${l.wonDeals+l.lostDeals} Closed`}),e.jsx(V,{label:"Ø Durchlaufzeit",value:`${l.avgCycleDays} Tage`,icon:Be,color:"text-blue-500",subtitle:"Erstellung → Abschluss"}),e.jsx(V,{label:"Lead → Qualifiziert",value:`${l.leadToQualRate}%`,icon:B,color:"text-orange-500",subtitle:`${l.qualifiedLeads} / ${l.totalLeads} Leads`}),e.jsx(V,{label:"Lead → Kunde",value:`${l.leadToCustomerRate}%`,icon:Ge,color:"text-cyan-500",subtitle:`${l.leadsToCustomersCount}
6 konvertiert`}),e.jsx(V,{label:"Kunde → Deal",value:`${l.customerToDealRate}%`,icon:ot,color:"text-indigo-500",subtitle:`${l.customersConvertedToDealCount} / ${l.totalCustomers} Kunden`}),e.jsx(V,{label:"Lead → Deal",value:`${l.leadToDealRate}%`,icon:Ue,color:"text-purple-500",subtitle:`${l.convertedLeads} konvertiert`})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(De,{className:"h-5 w-5 text-primary"})," Pipeline-Wert nach Stage"]}),e.jsx("div",{className:"h-48",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs($e,{data:l.pipelineByStage,layout:"vertical",margin:{left:20,right:20},children:[e.jsx(pe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(be,{type:"number",tickFormatter:t=>`${(t/1e3).toFixed(0)}k €`,tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"}}),e.jsx(je,{type:"category",dataKey:"label",width:100,tick:{fontSize:12,fill:"hsl(var(--foreground))"}}),e.jsx(Ne,{formatter:t=>[L(t),"Wert"],contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(ve,{dataKey:"totalValue",radius:[0,6,6,0],children:l.pipelineByStage.map(t=>e.jsx(dt,{fill:t.fill},t.stage))})]})})}),e.jsxs("div",{className:"mt-4 pt-4 border-t flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-medium text-muted-foreground",children:"Pipeline gesamt"}),e.jsx("span",{className:"text-lg font-bold text-foreground",children:L(l.pipelineByStage.reduce((t,i)=>t+i.totalValue,0))})]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-2 gap-4",children:[e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(me,{className:"h-5 w-5 text-primary"})," Win-Rate Trend"]}),e.jsx("div",{className:"h-48",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs(ct,{data:l.monthlyWinRates,margin:{top:5,right:5,bottom:5,left:-10},children:[e.jsx(pe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(be,{dataKey:"month",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"}}),e.jsx(je,{domain:[0,100],tickFormatter:t=>`${t}%`,tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ne,{formatter:(t,i)=>{const h=i==="winRate"?"Win-Rate":i==="convRate"?"Lead → Deal":"Lead → Kunde";return[`${t}%`,h]},contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(ye,{type:"monotone",dataKey:"winRate",stroke:"#22c55e",fill:"#22c55e",fillOpacity:.15,strokeWidth:2,name:"Win-Rate"}),e.jsx(ye,{type:"monotone",dataKey:"convRate",stroke:"#8b5cf6",fill:"#8b5cf6",fillOpacity:.1,strokeWidth:2,name:"Lead → Deal"}),e.jsx(ye,{type:"monotone",dataKey:"leadToCustRate",stroke:"#06b6d4",fill:"#06b6d4",fillOpacity:.1,strokeWidth:2,name:"Lead → Kunde"})]})})})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(B,{className:"h-5 w-5 text-primary"})," Deals & Leads pro Monat"]}),e.jsx("div",{className:"h-48",children:e.jsx(fe,{width:"100%",height:"100%",children:e.jsxs($e,{data:l.monthlyWinRates,margin:{top:5,right:5,bottom:5,left:-10},children:[e.jsx(pe,{strokeDasharray:"3 3",stroke:"hsl(var(--border))"}),e.jsx(be,{dataKey:"month",tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"}}),e.jsx(je,{tick:{fontSize:11,fill:"hsl(var(--muted-foreground))"}}),e.jsx(Ne,{contentStyle:{background:"hsl(var(--card))",border:"1px solid hsl(var(--border))",borderRadius:8,fontSize:12}}),e.jsx(ve,{dataKey:"wonDeals",fill:"#22c55e",radius:[4,4,0,0],name:"Won"}),e.jsx(ve,{dataKey:"leads",fill:"#3b82f6",radius:[4,4,0,0],name:"Leads",opacity:.5})]})})})]})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(De,{className:"h-5 w-5 text-primary"})," Conversion-Funnel"]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(H,{label:"Leads (gesamt)",count:l.totalLeads,percentage:100,color:"bg-blue-500"}),e.jsx(H,{label:"Qualifiziert",count:l.qualifiedLeads,percentage:l.leadToQualRate,color:"bg-orange-500"}),e.jsx(H,{label:"Lead → Kunde",count:l.leadsToCustomersCount,percentage:l.leadToCustomerRate,color:"bg-cyan-500"}
6),e.jsx(H,{label:"Konvertiert (Deal)",count:l.convertedLeads,percentage:l.leadToDealRate,color:"bg-green-500"}),e.jsx(H,{label:"Won",count:l.wonDeals,percentage:l.totalLeads>0?Math.round(l.wonDeals/l.totalLeads*100):0,color:"bg-emerald-600"})]})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(Qe,{className:"h-5 w-5 text-primary"})," Durchlaufzeit pro Pipeline-Stufe"]}),e.jsx("div",{className:"space-y-3",children:l.stageBreakdown.map(t=>e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs("div",{className:"flex items-center gap-2 w-32",children:[e.jsx("div",{className:`w-3 h-3 rounded-full ${gt[t.stage]}`}),e.jsx("span",{className:"text-sm font-medium text-foreground",children:Ae[t.stage]||t.stage})]}),e.jsx("div",{className:"flex-1",children:e.jsx(qe,{value:Math.min(t.avgDays*2,100),className:"h-3"})}),e.jsxs("span",{className:"text-sm font-semibold text-foreground w-16 text-right",children:[t.count," Deals"]}),e.jsxs(E,{variant:"outline",className:"text-[10px] w-20 justify-center",children:["Ø ",t.avgDays," Tage"]})]},t.stage))})]}),x&&se.length>0&&e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(Ze,{className:"h-5 w-5 text-primary"})," Pro-Mitarbeiter Performance"]}),e.jsx("div",{className:"overflow-x-auto",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{children:e.jsxs("tr",{className:"border-b text-xs text-muted-foreground",children:[e.jsx("th",{className:"text-left py-2 pr-4",children:"Mitarbeiter"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Leads"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Angebote"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Deals"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Won"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Lost"}),e.jsx("th",{className:"text-right py-2 px-2",children:"Win-Rate"}),e.jsx("th",{className:"text-right py-2 pl-2",children:"Wert"})]})}),e.jsx("tbody",{children:se.map(t=>e.jsxs("tr",{className:"border-b last:border-0 hover:bg-muted/30",children:[e.jsx("td",{className:"py-2 pr-4 font-medium text-foreground",children:t.fullName}),e.jsx("td",{className:"text-right py-2 px-2 text-foreground",children:t.leads}),e.jsx("td",{className:"text-right py-2 px-2 text-foreground",children:t.quotes}),e.jsx("td",{className:"text-right py-2 px-2 text-foreground",children:t.deals}),e.jsx("td",{className:"text-right py-2 px-2 text-green-600 font-semibold",children:t.won}),e.jsx("td",{className:"text-right py-2 px-2 text-red-500",children:t.lost}),e.jsx("td",{className:"text-right py-2 px-2",children:e.jsxs(E,{variant:t.winRate>=50?"default":"secondary",className:t.winRate>=50?"bg-green-500/10 text-green-600 border-green-500/20":"",children:[t.winRate,"%"]})}),e.jsx("td",{className:"text-right py-2 pl-2 font-semibold text-foreground",children:L(t.totalValue)})]},t.userId))})]})})]}),x&&Q.length>0&&e.jsxs("div",{className:"rounded-2xl border border-amber-500/30 bg-amber-500/5 p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(Ye,{className:"h-5 w-5 text-amber-500"})," Unbearbeitete Leads (",">","7 Tage)"]}),e.jsx("div",{className:"space-y-2",children:Q.map(t=>e.jsxs(Ce,{to:`/dashboard/leads/${t.id}`,className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.full_name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Status: ",t.status]})]}),e.jsxs(E,{variant:"outline",className:"text-amber-600 border-amber-500/30 shrink-0",children:[le(new Date,new Date(t.created_at))," Tage"]})]},t.id))})]}),x&&ae.length>0&&e.jsxs("div",{className:"rounded-2xl border border-blue-500/30 bg-blue-500/5 p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-3 flex items-center gap-2",children:[e.jsx(He,{className:"h-5 w-5 text-blue-500"})," Angebote ohne Follow-up"]}),e.jsx("div",{className:"space-y-2",children:ae.map(t=>e.jsxs(Ce,{to:`/dashboard/quotes/${t.id}`,className:"flex items-center justify-between p-3 rounded-lg border bg-card hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("p",{className:"text-sm font-medium text-foreground truncate",children:t.quote_number}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Status: ",t.status]})]}),e.jsx(E,{variant:"outline",className:"text-blue-600 border-blue-500/30 shrink-0",children:"Kein Follow-up"})]},t.id))})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6 grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-foreground",children:l.totalDeals}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Deals gesamt"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-green-600",children:l.wonDeals}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Gewonnen"})]}),e.jsxs("div",{className:"text-center",children:[e.jsx("p",{className:"text-2xl font-bold text-red-500",children:l.lostDeals}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Verloren"})]}),e.jsxs("div",{className:"text-center",children:[e.jsxs("p",{className:"text-2xl font-bold text-primary",children:[l.avgWonValue.toLocaleStr
6ing("de-DE")," €"]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Ø Deal-Wert (Won)"})]})]})]})},V=({label:a,value:f,icon:c,color:x,subtitle:v})=>e.jsxs("div",{className:"rounded-2xl border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a}),e.jsx(c,{className:`h-4 w-4 ${x}`})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:f}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:v})]}),H=({label:a,count:f,percentage:c,color:x})=>e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-foreground font-medium",children:a}),e.jsxs("span",{className:"text-muted-foreground",children:[f," (",c,"%)"]})]}),e.jsx("div",{className:"h-3 rounded-full bg-muted/50 overflow-hidden",children:e.jsx("div",{className:`h-full rounded-full ${x} transition-all duration-500`,style:{width:`${c}%`}})})]}),Ee={admin:"Admin",head_of_sales:"Head of Sales",senior_manager:"Senior Manager",manager:"Manager",vertriebsmitarbeiter:"Vertriebsmitarbeiter",exklusivpartner:"Exklusivpartner",partner:"Partner",ambassador:"Ambassador",tipgeber:"Tipgeber"},ce=[{icon:ke,color:"text-yellow-500",bg:"bg-yellow-500/10"},{icon:ut,color:"text-gray-400",bg:"bg-gray-400/10"},{icon:xt,color:"text-amber-700",bg:"bg-amber-700/10"}],qt=()=>{var h;const{user:a,roles:f}=Ke(),c=f.includes("admin")||f.includes("head_of_sales")||f.includes("senior_manager"),[x,v]=m.useState([]),[_,M]=m.useState({}),[$,W]=m.useState([]),[X,U]=m.useState([]),[ee,xe]=m.useState([]),[K,te]=m.useState([]),[z,l]=m.useState(()=>k(new Date,"yyyy-MM")),[se,Q]=m.useState(!0),ae=m.useMemo(()=>Array.from({length:6},(s,o)=>{const g=J(new Date,o);return{value:k(g,"yyyy-MM"),label:k(g,"MMMM yyyy",{locale:Me})}}),[]);m.useEffect(()=>{(async()=>{Q(!0);const[o,g,R,p,N,b]=await Promise.all([O((n,j)=>T.from("profiles").select("user_id, full_name, company").range(n,j)),O((n,j)=>T.from("user_roles").select("user_id, role").range(n,j)),O((n,j)=>T.from("quotes").select("id, created_by, status, software_config, totals, created_at").is("deleted_at",null).range(n,j)),O((n,j)=>T.from("customers").select("id, created_by, status, created_at").is("deleted_at",null).range(n,j)),O((n,j)=>T.from("commission_snapshots").select("user_id, month, total_deals, total_earnings, total_commission").range(n,j)),O((n,j)=>T.from("contracts").select("id, assigned_to, created_by, status, signed_at, contract_signed_at, created_at, actual_mrr_cents, target_mrr_cents").is("deleted_at",null).range(n,j))]);v(o);const u={};g.forEach(n=>{u[n.user_id]||(u[n.user_id]=[]),u[n.user_id].push(n.role)}),M(u),W(R),U(p),xe(N),te(b),Q(!1)})()},[]);const L=m.useMemo(()=>{const s=`${z}-01`,o=k(G(new Date(s)),"yyyy-MM-dd"),g=k(Fe(J(new Date(s),1)),"yyyy-MM-dd"),R=k(G(J(new Date(s),1)),"yyyy-MM-dd"),p=x.map(N=>{const b=N.user_id,u=$.filter(d=>d.created_by===b&&d.created_at>=s&&d.created_at<=o+"T23:59:59"),n=u.filter(d=>d.status==="angenommen"),j=d=>d.assigned_to||d.created_by,y=d=>d.contract_signed_at||d.signed_at||d.created_at,S=K.filter(d=>{if(j(d)!==b||d.status!=="unterschrieben")return!1;const D=y(d);return D&&D>=s&&D<=o+"T23:59:59"});X.filter(d=>d.created_by===b&&d.created_at>=s&&d.created_at<=o+"T23:59:59"),$.filter(d=>d.created_by===b&&d.created_at>=g&&d.created_at<=R+"T23:59:59");const ue=K.filter(d=>{if(j(d)!==b||d.status!=="unterschrieben")return!1;const D=y(d);return D&&D>=g&&D<=R+"T23:59:59"}),re=S.reduce((d,D)=>d+Number(D.actual_mrr_cents??D.target_mrr_cents??0)/100,0),I=re*12,Z=S.length,Y=ue.length,he=ee.filter(d=>d.user_id===b).sort((d,D)=>D.month.localeCompare(d.month));let ge=0;for(const d of he)if(d.total_deals>0)ge++;else break;return{userId:b,fullName:N.full_name||"–",company:N.company||"",roles:_[b]||[],dealCount:Z,totalMrr:re,totalRevenue:I,quoteCount:u.length,conversionRate:u.length>0?Math.round(n.length/u.length*100):0,rank:0,trend:Z>Y?"up":Z<Y?"down":"same",streak:ge}});return p.sort((N,b)=>b.dealCount-N.dealCount||b.totalMrr-N.totalMrr),p.forEach((N,b)=>N.rank=b+1),p.filter(N=>N.quoteCount>0||N.dealCount>0||(c?!0:N.userId===(a==null?void 0:a.id)))},[x,$,K,X,ee,_,z,c,a==null?void 0:a.id]),t=L.find(s=>s.userId===(a==null?void 0:a.id)),i=m.useMemo(()=>Array.from({length:6},(s,o)=>{const g=J(new Date,5-o),p=`${k(g,"yyyy-MM")}-01`,N=k(G(g),"yyyy-MM-dd"),b=y=>y.assigned_to||y.created_by,u=y=>y.contract_signed_at||y.signed_at||y.created_at,n=K.filter(y=>{if(b(y)!==(a==null?void 0:a.id)||y.status!=="unterschrieben")return!1;const S=u(y);return S&&S>=p&&S<=N+"T23:59:59"}),j=n.reduce((y,S)=>y+Number(S.actual_mrr_cents??S.target_mrr_cents??0)/100,0);return{month:k(g,"MMM",{locale:Me}),deals:n.length,revenue:Math.round(j),target:5}}),[K,a==null?void 0:a.id]);return se?e.jsx("div",{className:"flex items-center justify-center h-64",children:e.jsx("div",{className:"animate-spin rounded-full h-8 w-8 border-b-2 border-primary"})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-2xl font-bold text-foreground flex items-center gap-2",children:[e.jsx(ke,{className:"h-6 w-6 text-primary"}),"KPIs & Leaderboard"]}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Zielerreichung, Rankings und Gam
6ification"})]}),e.jsxs(Je,{value:z,onValueChange:l,children:[e.jsx(Xe,{className:"w-48",children:e.jsx(et,{})}),e.jsx(tt,{children:ae.map(s=>e.jsx(st,{value:s.value,children:s.label},s.value))})]})]}),e.jsxs(it,{defaultValue:"overview",className:"space-y-4",children:[e.jsxs(mt,{className:"grid w-full grid-cols-4",children:[e.jsxs(oe,{value:"overview",className:"gap-1.5",children:[e.jsx(B,{className:"h-4 w-4"})," Meine KPIs"]}),e.jsxs(oe,{value:"metrics",className:"gap-1.5",children:[e.jsx(at,{className:"h-4 w-4"})," Metriken"]}),e.jsxs(oe,{value:"leaderboard",className:"gap-1.5",children:[e.jsx(ke,{className:"h-4 w-4"})," Leaderboard"]}),e.jsxs(oe,{value:"monthly",className:"gap-1.5",children:[e.jsx(me,{className:"h-4 w-4"})," Monatsübersicht"]})]}),e.jsx(de,{value:"overview",className:"space-y-4",children:t?e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"grid grid-cols-2 lg:grid-cols-4 gap-4",children:[e.jsx(ie,{label:"Abschlüsse",value:t.dealCount,icon:B,color:"text-primary",subtitle:`${t.quoteCount} Angebote erstellt`}),e.jsx(ie,{label:"MRR",value:`${t.totalMrr.toFixed(0)} €`,icon:De,color:"text-green-500",subtitle:"Monatl. wiederkehrend"}),e.jsx(ie,{label:"Conversion",value:`${t.conversionRate} %`,icon:me,color:"text-blue-500",subtitle:"Angebote → Abschlüsse"}),e.jsx(ie,{label:"Streak",value:`${t.streak} Mon.`,icon:Le,color:"text-orange-500",subtitle:"Aktive Monate in Folge"})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6 flex items-center gap-6",children:[e.jsx("div",{className:`w-16 h-16 rounded-2xl flex items-center justify-center ${t.rank<=3&&((h=ce[t.rank-1])==null?void 0:h.bg)||"bg-muted"}`,children:t.rank<=3?(()=>{const s=ce[t.rank-1];return e.jsx(s.icon,{className:`h-8 w-8 ${s.color}`})})():e.jsxs("span",{className:"text-2xl font-bold text-muted-foreground",children:["#",t.rank]})}),e.jsxs("div",{className:"flex-1",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Dein aktuelles Ranking"}),e.jsxs("p",{className:"text-2xl font-bold text-foreground",children:["Platz ",t.rank," von ",L.length]}),e.jsxs("div",{className:"flex items-center gap-2 mt-1",children:[t.trend==="up"&&e.jsxs(E,{variant:"default",className:"bg-green-500/10 text-green-600 border-green-500/20",children:[e.jsx(Se,{className:"h-3 w-3"})," Aufgestiegen"]}),t.trend==="down"&&e.jsxs(E,{variant:"default",className:"bg-red-500/10 text-red-600 border-red-500/20",children:[e.jsx(Te,{className:"h-3 w-3"})," Abgestiegen"]}),t.trend==="same"&&e.jsx(E,{variant:"secondary",children:"Unverändert"}),t.streak>=3&&e.jsxs(E,{variant:"default",className:"bg-orange-500/10 text-orange-600 border-orange-500/20",children:[e.jsx(Le,{className:"h-3 w-3"})," ",t.streak,"-Monats-Streak!"]})]})]})]}),e.jsxs("div",{className:"rounded-2xl border bg-card p-6 space-y-4",children:[e.jsxs("h3",{className:"font-semibold text-foreground flex items-center gap-2",children:[e.jsx(B,{className:"h-5 w-5 text-primary"})," Zielerreichung"]}),e.jsx(_e,{label:"Abschlüsse",current:t.dealCount,target:5,unit:"Deals"}),e.jsx(_e,{label:"MRR",current:t.totalMrr,target:2e3,unit:"€",format:"currency"}),e.jsx(_e,{label:"Conversion-Rate",current:t.conversionRate,target:50,unit:"%"})]}),e.jsx(pt,{entry:t})]}):e.jsxs("div",{className:"rounded-2xl border bg-card p-12 text-center",children:[e.jsx(B,{className:"h-12 w-12 text-muted-foreground mx-auto mb-4"}),e.jsx("p",{className:"text-lg font-semibold text-foreground",children:"Noch keine Aktivität"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Erstelle dein erstes Angebot, um deine KPIs zu tracken."})]})}),e.jsx(de,{value:"metrics",children:e.jsx(ft,{selectedMonth:z})}),e.jsxs(de,{value:"leaderboard",className:"space-y-4",children:[L.length>=3&&e.jsx("div",{className:"grid grid-cols-3 gap-3 mb-2",children:[1,0,2].map(s=>{var R;const o=L[s];if(!o)return null;const g=s===0;return e.jsxs("div",{className:`rounded-2xl border p-4 text-center transition-all ${g?"bg-gradient-to-b from-yellow-500/10 to-card border-yellow-500/30 -mt-2 pb-6":"bg-card"} ${o.userId===(a==null?void 0:a.id)?"ring-2 ring-primary":""}`,children:[e.jsx("div",{className:`w-12 h-12 rounded-full flex items-center justify-center mx-auto mb-2 ${((R=ce[o.rank-1])==null?void 0:R.bg)||"bg-muted"}`,children:(()=>{const p=ce[o.rank-1];return p?e.jsx(p.icon,{className:`h-6 w-6 ${p.color}`}):e.jsxs("span",{className:"font-bold",children:["#",o.rank]})})()}),e.jsx("p",{className:"text-sm font-bold text-foreground truncate",children:o.fullName}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:o.roles.map(p=>Ee[p]||p).join(", ")}),e.jsxs("p",{className:"text-lg font-bold text-primary mt-2",children:[o.dealCount," Deals"]}
6),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[o.totalMrr.toFixed(0)," € MRR"]})]},o.userId)})}),e.jsxs("div",{className:"rounded-2xl border bg-card overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-[3rem_1fr_4rem_5rem_4rem] sm:grid-cols-[3rem_1fr_5rem_6rem_5rem_5rem] gap-2 px-4 py-3 bg-muted/50 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:"#"}),e.jsx("span",{children:"Partner"}),e.jsx("span",{className:"text-right",children:"Deals"}),e.jsx("span",{className:"text-right hidden sm:block",children:"MRR"}),e.jsx("span",{className:"text-right",children:"Conv."}),e.jsx("span",{className:"text-right hidden sm:block",children:"Trend"})]}),L.map(s=>e.jsxs("div",{className:`grid grid-cols-[3rem_1fr_4rem_5rem_4rem] sm:grid-cols-[3rem_1fr_5rem_6rem_5rem_5rem] gap-2 px-4 py-3 border-t items-center transition-colors ${s.userId===(a==null?void 0:a.id)?"bg-primary/5":"hover:bg-muted/30"}`,children:[e.jsx("span",{className:`text-sm font-bold ${s.rank<=3?"text-primary":"text-muted-foreground"}`,children:s.rank}),e.jsxs("div",{className:"min-w-0",children:[e.jsxs("p",{className:"text-sm font-medium text-foreground truncate",children:[s.fullName,s.userId===(a==null?void 0:a.id)&&e.jsx("span",{className:"text-xs text-primary ml-1",children:"(Du)"})]}),e.jsx("p",{className:"text-xs text-muted-foreground truncate",children:s.roles.map(o=>Ee[o]||o).join(", ")})]}),e.jsx("span",{className:"text-sm font-semibold text-foreground text-right",children:s.dealCount}),e.jsxs("span",{className:"text-sm text-foreground text-right hidden sm:block",children:[s.totalMrr.toFixed(0)," €"]}),e.jsxs("span",{className:"text-sm text-foreground text-right",children:[s.conversionRate,"%"]}),e.jsxs("span",{className:"text-right hidden sm:block",children:[s.trend==="up"&&e.jsx(Se,{className:"h-4 w-4 text-green-500 inline"}),s.trend==="down"&&e.jsx(Te,{className:"h-4 w-4 text-red-500 inline"}),s.trend==="same"&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"–"})]})]},s.userId)),L.length===0&&e.jsx("div",{className:"p-8 text-center text-muted-foreground",children:"Noch keine Daten für diesen Monat vorhanden."})]})]}),e.jsxs(de,{value:"monthly",className:"space-y-4",children:[e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground mb-4 flex items-center gap-2",children:[e.jsx(me,{className:"h-5 w-5 text-primary"})," Deine Entwicklung (6 Monate)"]}),e.jsx("div",{className:"grid grid-cols-6 gap-2 mb-6",children:i.map(s=>e.jsxs("div",{className:"text-center",children:[e.jsx("div",{className:"relative h-32 bg-muted/30 rounded-lg overflow-hidden flex flex-col justify-end",children:e.jsx("div",{className:"bg-primary/80 rounded-t-md transition-all duration-500",style:{height:`${Math.min(s.deals/Math.max(...i.map(o=>o.target),1)*100,100)}%`}})}),e.jsx("p",{className:"text-xs font-medium text-foreground mt-1",children:s.deals}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:s.month})]},s.month))})]}),e.jsxs("div",{className:"rounded-2xl border bg-card overflow-hidden",children:[e.jsxs("div",{className:"grid grid-cols-4 gap-2 px-4 py-3 bg-muted/50 text-xs font-medium text-muted-foreground",children:[e.jsx("span",{children:"Monat"}),e.jsx("span",{className:"text-right",children:"Deals"}),e.jsx("span",{className:"text-right",children:"MRR"}),e.jsx("span",{className:"text-right",children:"Ziel"})]}),i.map(s=>e.jsxs("div",{className:"grid grid-cols-4 gap-2 px-4 py-3 border-t items-center",children:[e.jsx("span",{className:"text-sm font-medium text-foreground",children:s.month}),e.jsx("span",{className:"text-sm text-right text-foreground",children:s.deals}),e.jsxs("span",{className:"text-sm text-right text-foreground",children:[s.revenue," €"]}),e.jsx("span",{className:"text-right",children:e.jsx("span",{className:`text-xs px-2 py-0.5 rounded-full ${s.deals>=s.target?"bg-green-500/10 text-green-600":"bg-red-500/10 text-red-600"}`,children:s.deals>=s.target?"✓ Erreicht":`${s.target-s.deals} fehlen`})})]},s.month))]})]})]})]})},ie=({label:a,value:f,icon:c,color:x,subtitle:v})=>e.jsxs("div",{className:"rounded-2xl border bg-card p-4",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("span",{className:"text-xs text-muted-foreground",children:a}),e.jsx(c,{className:`h-4 w-4 ${x}`})]}),e.jsx("p",{className:"text-2xl font-bold text-foreground",children:f}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:v})]}),_e=({label:a,current:f,target:c,unit:x,format:v})=>{const _=Math.min(Math.round(f/c*100),100),M=f>=c;return e.jsxs("div",{className:"space-y-1.5",children:[e.jsxs("div",{className:"flex items-center justify-between text-sm",children:[e.jsx("span",{className:"text-foreground font-medium",children:a}),e.jsx("span",{className:`text-xs font-semibold ${M?"text-green-600":"text-muted-foreground"}`,children:v==="currency"?`${f.toFixed(0)} / ${c} ${x}`:`${f} / ${c} ${x}`})]}),e.jsxs("div",{className:"relative",children:[e.jsx(qe,{value:_,className:"h-3"}),M&&e.jsx("span",{className:"absolute right-1 top-0 text-[10px] text-green-600 font-bold",children:"✓"})]}),e.jsxs("p",{className:"text-xs text-muted-foreground text-right",children:[_,"%"]})]})},we=[{id:"first_deal",title:"Erster Deal",desc:"1. Abschluss",icon:"🎯",check:a=>a.dealCount>=1},{id:"power_seller",title:"Power Seller",desc:"5+ Deals/Monat",icon:"⚡",check:a=>a.dealCount>=5},{id:"streak_master",title:"Streak Master",desc:"3+ Monate aktiv",icon:"🔥",check:a=>a.streak>=3},{id:"closer",title:"Closer",desc:"50%+ Conversion",icon:"💎",check:a=>a.conversionRate>=50},{id:"mrr_hunter",title:"MRR Hunter",desc:"2.000€+ MRR",icon:"🏆",check:a=>a.totalMrr>=2e3},{id:"top3",title:"Top 3",desc:"Unter den Top 3",icon:"🥇",check:a=>a.rank<=3},{id:"ten_club",title:"10er Club",desc:"10+ Deals/Monat",icon:"🚀",check:a=>a.dealCount>=10},{id:"networker",title:"Networker",desc:"20+ Angebote",icon:"🌐",check:a=>a.quoteCount>=20}],We="liefersoft_achievements_unlocked",pt=({entry:a})=>{const f=m.useRef(!1);return m.useEffect(()=>{const c=JSON.parse(localStorage.getItem(We)||"[]"),x=we.filter(_=>_.check(a)).map(_=>_.id),v=x.filter(_=>!c.includes(_));v.length>0&&!f.current&&(f.current=!0,setTimeout(()=>{v.forEach((_,M)=>{const $=we.find(W=>W.id===_);$&&setTimeout(()=>{rt.success(`${$.icon} Achievement freigeschaltet!`,{description:`${$.title} – ${$.desc}`,duration:5e3})},M*800)})},500),localStorage.setItem(We,JSON.stringify([...new Set([...c,...x])])))},[a]),e.jsxs("div",{className:"rounded-2xl border bg-card p-6",children:[e.jsxs("h3",{className:"font-semibold text-foreground flex items-center gap-2 mb-4",children:[e.jsx(nt,{className:"h-5 w-5 text-yellow-500"})," Achievements"]}),e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-4 gap-3",children:we.map(c=>
6e.jsx(bt,{title:c.title,desc:c.desc,unlocked:c.check(a),icon:c.icon},c.id))})]})},bt=({title:a,desc:f,unlocked:c,icon:x})=>e.jsxs("div",{className:`rounded-xl border p-3 text-center transition-all ${c?"bg-gradient-to-b from-yellow-500/5 to-card border-yellow-500/20":"bg-muted/30 opacity-50 grayscale"}`,children:[e.jsx("span",{className:"text-2xl block mb-1",children:x}),e.jsx("p",{className:"text-xs font-semibold text-foreground",children:a}),e.jsx("p",{className:"text-[10px] text-muted-foreground",children:f}),c&&e.jsx(E,{variant:"default",className:"mt-1 text-[9px] bg-green-500/10 text-green-600 border-green-500/20",children:"Freigeschaltet"})]});export{qt as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.