1import{a as de,u as Q,r as c,s as S,j as e,m as me,B as J,w as g,K as p,N as f,x as j,I as ue}from"./index-MoAbC8_9.js";import{O as he}from"./OwnersLayout-Cd0M3dw8.js";import{u as xe}from"./usePersistedYear-CMpOJqHk.js";import{B as M}from"./badge-BHbYeRgi.js";import{B as ge}from"./breadcrumb-CmKLwRya.js";import{E as pe}from"./euro-Cc6O9qjZ.js";import{A as fe}from"./arrow-up-right-CgIWjGgj.js";import{A as je}from"./arrow-down-right-TVCZaAHK.js";import{U as ye}from"./users-xui-UtA1.js";import{R as ve}from"./receipt-DnGXta2k.js";import{T as W}from"./trending-up-Cg9WFJWB.js";import{R as L,C as P,X as R,Y,T,B as X,L as Ne,a as Z}from"./generateCategoricalChart-C2b_mvpD.js";import{B as q}from"./BarChart-FFUEJ1QK.js";import{L as we}from"./LineChart-CgmaZj2v.js";import{L as be}from"./Line-DFydwSLz.js";import{T as Ce}from"./trending-down-EHPUNHPt.js";import{M as De}from"./minus-Dry52jGc.js";import{P as ke,a as Ve}from"./PieChart-C9_Ud7Rw.js";import{S as Se}from"./search-_fcwEKN-.js";import{C as Le}from"./Header-CnJGZ8vQ.js";import"./separator-CQ84aZ0V.js";import"./collapsible-BIxz44zB.js";import"./skeleton-ClxqB572.js";import"./switch-BHj3-8MN.js";import"./index-D9-GACGG.js";import"./house-DjS1WMqx.js";import"./building-crte1H4H.js";import"./file-text-Bif0RP8Y.js";import"./user-Cvsz7Lm_.js";import"./chart-column-Bo5i9GGE.js";import"./upload-BH1HltYO.js";import"./piggy-bank-DP-A2O0m.js";import"./landmark-C0TkBs1l.js";import"./flame-wMx8KIS8.js";import"./eye-DKrvAixa.js";import"./dialog-DrI7Oddz.js";import"./tabs-5EVsfllK.js";import"./textarea-4z16PwID.js";import"./mountain-BHfTfCFy.js";import"./index-Dh4i1-J3.js";const Te=()=>{const A=de(),{language:w}=Q(),[d,B]=c.useState([]),[b,ee]=c.useState([]),[C,te]=c.useState([]),[se,E]=c.useState(!0),[D,ae]=c.useState(""),[y,re]=c.useState([]),{selectedYear:m,setSelectedYear:z,isInitialized:O}=xe(y);c.useEffect(()=>{ne()},[]),c.useEffect(()=>{O&&oe()},[m,O]);const ne=async()=>{const{data:t}=await S.from("house_costs").select("year").order("year",{ascending:!0}),{data:s}=await S.from("house_cost_items").select("item_date").not("item_date","is",null),a=(t==null?void 0:t.map(h=>h.year))||[],l=(s==null?void 0:s.map(h=>new Date(h.item_date).getFullYear()))||[],u=[...new Set([...a,...l])].sort((h,r)=>h-r);re(u)},oe=async()=>{E(!0);const{data:t}=await S.from("house_cost_items").select("vendor, amount, house_cost_id, item_date"),{data:s}=await S.from("house_costs").select("id, year");if(t&&s){const a=new Map(s.map(r=>[r.id,r.year])),l=new Map;t.forEach(r=>{if(r.vendor){let n;r.house_cost_id&&(n=a.get(r.house_cost_id)),!n&&r.item_date&&(n=new Date(r.item_date).getFullYear());const o=l.get(r.vendor)||{total:0,count:0,yearlyData:{}};o.total+=Number(r.amount),o.count+=1,n&&(o.yearlyData[n]||(o.yearlyData[n]={total:0,count:0}),o.yearlyData[n].total+=Number(r.amount),o.yearlyData[n].count+=1),l.set(r.vendor,o)}});const u=Array.from(l.entries()).map(([r,n])=>({vendor:r,...n})).sort((r,n)=>n.total-r.total);ee(u);const h=y.map(r=>{let n=0,o=0,v=0;return u.forEach(N=>{N.yearlyData&&N.yearlyData[r]&&(n+=N.yearlyData[r].total,v+=N.yearlyData[r].count,o++)}),{year:r,total:n,vendorCount:o,invoiceCount:v}});if(te(h),m!=="all"){const r=parseInt(m),n=u.filter(o=>o.yearlyData&&o.yearlyData[r]).map(o=>({vendor:o.vendor,total:o.yearlyData[r].total,count:o.yearlyData[r].count,yearlyData:o.yearlyData})).sort((o,v)=>v.total-o.total);B(n)}else B(u)}E(!1)},x=t=>new Intl.NumberFormat(w==="de"?"de-DE":w==="cs"?"cs-CZ":"en-GB",{style:"currency",currency:"EUR",maximumFractionDigits:0}).format(t),_=c.useMemo(()=>D?d.filter(t=>t.vendor.toLowerCase().includes(D.toLowerCase())):d,[d,D]),F=c.useMemo(()=>_.slice(0,10).map((t,s)=>({...t,shortName:t.vendor.length>15?t.vendor.substring(0,15)+"...":t.vendor})),[_]),$=c.useMemo(()=>{const t=b.slice(0,5);return y.map(s=>{const a={year:s.toString()};return t.forEach(l=>{var h,r;const u=l.vendor.length>12?l.vendor.substring(0,12)+"...":l.vendor;a[u]=((r=(h=l.yearlyData)==null?void 0:h[s])==null?void 0:r.total)||0}),a})},[b,y]),le=c.useMemo(()=>b.slice(0,5).map(t=>t.vendor.length>12?t.vendor.substring(0,12)+"...":t.vendor),[b]),K=c.useMemo(()=>{const t={Personal:0,Gebäudetechnik:0,Energie:0,Wartung:0,Verwaltung:0,Sonstige:0};return d.forEach(s=>{const a=s.vendor.toLowerCase();a.includes("sieberer")||a.includes("lohn")?t.Personal+=s.total:a.includes("hasenauer")||a.includes("otis")||a.includes("höring")||a.includes("miesl")?t.Gebäudetechnik+=s.total:a.includes("salzburg")||a.includes("strom")||a.includes("a1")||a.includes("magenta")?t.Energie+=s.total:a.includes("elektro")||a.includes("stöckl")||a.includes("installateur")||a.includes("lagerhaus")?t.Wartung+=s.total:a.includes("hausverwaltung")||a.includes("versicherung")||a.includes("finanzamt")||a.includes("gemeinde")?t.Verwaltung+=s.total:t.Sonstige+=s.total}),Object.entries(t).map(([s,a])=>({name:s,value:a})).filter(s=>s.value>0).sort((s,a)=>a.value-s.value)},[d]),G=c.useMemo(()=>d.reduce((t,s)=>t+s.total,0),[d]),I=c.useMemo(()=>d.reduce((t,s)=>t+s.count,0),[d]),ie=I>0?G/I:0,k=c.useMemo(()=>{var h,r;if(m==="all"||y.length<2)return null;const t=parseInt(m),s=t-1,a=((h=C.find(n=>n.year===t))==null?void 0:h.total)||0,l=((r=C.find(n=>n.year===s))==null?void 0:r.total)||0;return l===0?null:{change:(a-l)/l*100,previousTotal:l,currentTotal:a}},[m,C,y]),U=c.useMemo(()=>
1{if(m==="all"||y.length<2)return[];const t=parseInt(m),s=t-1;return b.filter(a=>a.yearlyData&&(a.yearlyData[t]||a.yearlyData[s])).map(a=>{var n,o,v,N;const l=((o=(n=a.yearlyData)==null?void 0:n[t])==null?void 0:o.total)||0,u=((N=(v=a.yearlyData)==null?void 0:v[s])==null?void 0:N.total)||0,h=l-u,r=u>0?(l-u)/u*100:l>0?100:0;return{vendor:a.vendor,current:l,previous:u,change:h,changePercent:r}}).sort((a,l)=>Math.abs(l.change)-Math.abs(a.change)).slice(0,5)},[b,m,y]),H={cs:{title:"Analýza dodavatelů",subtitle:"PÅehled výdajů podle dodavatelů a firem",topVendors:"Top 10 dodavatelů",categoryBreakdown:"RozdÄlenà podle kategoriÃ",allVendors:"VÅ¡ichni dodavatelé",totalSpent:"Celkem vyplaceno",vendorCount:"PoÄet dodavatelů",invoiceCount:"PoÄet faktur",avgPerInvoice:"à na fakturu",search:"Hledat dodavatele...",year:"Rok",all:"VÅ¡e",invoices:"faktur",yoyChange:"MeziroÄnà zmÄna",compared:"oproti",vendorTrend:"Vývoj top 5 dodavatelů",biggestChanges:"NejvÄtšà zmÄny oproti loÅsku",yearlyOverview:"PÅehled výdajů po letech",new:"nový",removed:"ukonÄen"},de:{title:"Lieferantenanalyse",subtitle:"Ãbersicht der Ausgaben nach Lieferanten und Firmen",topVendors:"Top 10 Lieferanten",categoryBreakdown:"Kategorienverteilung",allVendors:"Alle Lieferanten",totalSpent:"Gesamt ausgegeben",vendorCount:"Anzahl Lieferanten",invoiceCount:"Anzahl Rechnungen",avgPerInvoice:"à pro Rechnung",search:"Lieferant suchen...",year:"Jahr",all:"Alle",invoices:"Rechnungen",yoyChange:"Jährliche Ãnderung",compared:"gegenüber",vendorTrend:"Top 5 Lieferanten Entwicklung",biggestChanges:"GröÃte Ãnderungen zum V
1orjahr",yearlyOverview:"Jahresübersicht Ausgaben",new:"neu",removed:"beendet"},en:{title:"Vendor Analysis",subtitle:"Overview of expenses by vendors and companies",topVendors:"Top 10 Vendors",categoryBreakdown:"Category Breakdown",allVendors:"All Vendors",totalSpent:"Total Spent",vendorCount:"Vendor Count",invoiceCount:"Invoice Count",avgPerInvoice:"Avg per Invoice",search:"Search vendor...",year:"Year",all:"All",invoices:"invoices",yoyChange:"Year-over-Year Change",compared:"vs",vendorTrend:"Top 5 Vendors Trend",biggestChanges:"Biggest Changes vs Last Year",yearlyOverview:"Yearly Spending Overview",new:"new",removed:"ended"}},i=H[w]||H.de,V=["hsl(var(--primary))","hsl(var(--accent))","hsl(var(--alpine-sunset))","#8884d8","#82ca9d","#ffc658"],ce=["#8884d8","#82ca9d","#ffc658","#ff7c43","#a155b9"];return se?e.jsx("div",{className:"flex items-center justify-center py-12",children:e.jsx(me,{className:"h-8 w-8 animate-spin text-primary"})}):e.jsxs("div",{className:"space-y-8",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("h2",{className:"font-serif text-2xl font-bold flex items-center gap-2",children:[e.jsx(ge,{className:"h-6 w-6 text-primary"}),i.title]}),e.jsx("p",{className:"text-muted-foreground",children:i.subtitle})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground",children:[i.year,":"]}),e.jsx(J,{variant:m==="all"?"default":"outline",size:"sm",onClick:()=>z("all"),children:i.all}),y.map(t=>e.jsx(J,{variant:m===t.toString()?"default":"outline",size:"sm",onClick:()=>z(t.toString()),children:t},t))]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-4",children:[e.jsxs(g,{children:[e.jsx(p,{className:"pb-2",children:e.jsxs(f,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(pe,{className:"h-4 w-4"}),i.totalSpent]})}),e.jsxs(j,{children:[e.jsx("div",{className:"text-2xl font-bold text-primary",children:x(G)}),k&&e.jsxs("div",{className:`flex items-center gap-1 text-sm mt-1 ${k.change>0?"text-destructive":"text-green-600"}`,children:[k.change>0?e.jsx(fe,{className:"h-4 w-4"}):e.jsx(je,{className:"h-4 w-4"}),Math.abs(k.change).toFixed(1),"% ",i.compared," ",parseInt(m)-1]})]})]}),e.jsxs(g,{children:[e.jsx(p,{className:"pb-2",children:e.jsxs(f,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ye,{className:"h-4 w-4"}),i.vendorCount]})}),e.jsx(j,{children:e.jsx("div",{className:"text-2xl font-bold",children:d.length})})]}),e.jsxs(g,{children:[e.jsx(p,{className:"pb-2",children:e.jsxs(f,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(ve,{className:"h-4 w-4"}),i.invoiceCount]})}),e.jsx(j,{children:e.jsx("div",{className:"text-2xl font-bold",children:I})})]}),e.jsxs(g,{children:[e.jsx(p,{className:"pb-2",children:e.jsxs(f,{className:"text-sm font-medium text-muted-foreground flex items-center gap-2",children:[e.jsx(W,{className:"h-4 w-4"}),i.avgPerInvoice]})}),e.jsx(j,{children:e.jsx("div",{className:"text-2xl font-bold",children:x(ie)})})]})]}),m==="all"&&C.length>1&&e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{className:"font-serif",children:i.yearlyOverview})}),e.jsx(j,{children:e.jsx(L,{width:"100%",height:300,children:e.jsxs(q,{data:C,children:[e.jsx(P,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(R,{dataKey:"year"}),e.jsx(Y,{tickFormatter:t=>`â¬${(t/1e3).toFixed(0)}k`}),e.jsx(T,{formatter:t=>x(t),labelFormatter:t=>`${t}`}),e.jsx(X,{dataKey:"total",fill:"hsl(var(--primary))",radius:[4,4,0,0],name:i.totalSpent})]})})})]}),m==="all"&&$.length>1&&e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{className:"font-serif",children:i.vendorTrend})}),e.jsx(j,{children:e.jsx(L,{width:"100%",height:350,children:e.jsxs(we,{data:$,children:[e.jsx(P,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(R,{dataKey:"year"}),e.jsx(Y,{tickFormatter:t=>`â¬${(t/1e3).toFixed(0)}k`}),e.jsx(T,{formatter:t=>x(t)}),e.jsx(Ne,{}),le.map((t,s)=>e.jsx(be,{type:"monotone",dataKey:t,stroke:ce[s],strokeWidth:2,dot:{r:4}},t))]})})})]}),m!=="all"&&U.length>0&&e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{className:"font-serif",children:i.biggestChanges})}),e.jsx(j,{children:e.jsx("div",{className:"space-y-3",children:U.map((t,s)=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground w-6",children:[s+1,"."]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.vendor}),e.jsx("p",{className:"text-sm text-muted-foreground",children:t.previous===0?e.jsx(M,{variant:"outline",className:"text-green-600 border-green-600",children:i.new}):t.current===0?e.jsx(M,{variant:"outline",className:"text-orange-600 border-orange-600",children:i.removed}):e.jsxs(e.Fragment,{children:[x(t.previous)," â ",x(t.current)]})})]})]}),e.jsxs("div",{className:"text-right",children:[e.jsxs("div",{className:`flex items-center gap-1 font-semibold ${t.change>0?"text-destructive":"text-green-600"}`,children:[t.change>0?e.jsx(W,{className:"h-4 w-4"}):t.change<0?e.jsx(Ce,{className:"h-4 w-4"}):e.jsx(De,{className:"h-4 w-4"}),t.change>0?"+":"",x(t.change)]}),t.previous>0&&t.current>0&&e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.changePercent>0?"+":"",t.changePercent.toFixed(0),"%"]})]})]},t.vendor))})})]}),e.jsxs("div",{className:"grid gap-6 lg:grid-cols-2",children:[e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{className:"font-serif",children:i.topVendors})}),e.jsx(j,{children:e.jsx(L,{width:"100%",height:400,children:e.jsxs(q,{data:F,layout:"vertical",children:[e.jsx(P,{strokeDasharray:"3 3",className:"stroke-muted"}),e.jsx(R,{type:"number",tickFormatter:t=>`â¬${(t/1e3).toFixed(0)}k`}),e.jsx(Y,{type:"category",dataKey:"shortName",width:120,tick:{fontSize:12}}),e.jsx(T,{formatter:t=>x(t),labelFormatter:t=>{const s=F.find(a=>a.shortName===t);return(s==null?void 0:s.vendor)||t}}
1),e.jsx(X,{dataKey:"total",radius:[0,4,4,0],children:F.map((t,s)=>e.jsx(Z,{fill:V[s%V.length]},`cell-${s}`))})]})})})]}),e.jsxs(g,{children:[e.jsx(p,{children:e.jsx(f,{className:"font-serif",children:i.categoryBreakdown})}),e.jsx(j,{children:e.jsx(L,{width:"100%",height:400,children:e.jsxs(ke,{children:[e.jsx(Ve,{data:K,cx:"50%",cy:"50%",labelLine:!1,label:({name:t,percent:s})=>`${t} ${(s*100).toFixed(0)}%`,outerRadius:140,fill:"#8884d8",dataKey:"value",children:K.map((t,s)=>e.jsx(Z,{fill:V[s%V.length]},`cell-${s}`))}),e.jsx(T,{formatter:t=>x(t)})]})})})]})]}),e.jsxs(g,{children:[e.jsx(p,{children:e.jsxs("div",{className:"flex flex-col sm:flex-row sm:items-center sm:justify-between gap-4",children:[e.jsx(f,{className:"font-serif",children:i.allVendors}),e.jsxs("div",{className:"relative w-full sm:w-64",children:[e.jsx(Se,{className:"absolute left-3 top-1/2 -translate-y-1/2 h-4 w-4 text-muted-foreground"}),e.jsx(ue,{placeholder:i.search,value:D,onChange:t=>ae(t.target.value),className:"pl-10"})]})]})}),e.jsx(j,{children:e.jsx("div",{className:"space-y-2 max-h-96 overflow-y-auto",children:_.map((t,s)=>e.jsxs("div",{className:"flex items-center justify-between p-3 rounded-lg bg-muted/50 hover:bg-muted transition-colors cursor-pointer group",onClick:()=>A(`/costs/vendor/${encodeURIComponent(t.vendor)}`),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("span",{className:"text-sm font-medium text-muted-foreground w-6",children:[s+1,"."]}),e.jsxs("div",{children:[e.jsx("p",{className:"font-medium",children:t.vendor}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.count," ",i.invoices]})]})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(M,{variant:"secondary",className:"text-base font-semibold",children:x(t.total)}),e.jsx(Le,{className:"h-4 w-4 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity"})]})]},t.vendor))})})]})]})},ft=()=>{const{language:A}=Q(),w={de:{title:"Lieferanten",description:"Analyse aller Lieferanten und deren Ausgaben",costs:"Kosten"},en:{title:"Vendors",description:"Analysis of all vendors and their expenses",costs:"Costs"},cs:{title:"Dodavatelé",description:"Analýza všech dodavatelů a jejich výdajů",costs:"Náklady"}},d=w[A]||w.cs;return e.jsx(he,{title:d.title,description:d.description,breadcrumbs:[{label:d.costs,href:"/owners/costs"},{label:d.title}],children:e.jsx(Te,{})})};export{ft 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.