diff --git a/src/app/dashboard/settings/billing/page.tsx b/src/app/dashboard/settings/billing/page.tsx new file mode 100644 index 0000000..23ff333 --- /dev/null +++ b/src/app/dashboard/settings/billing/page.tsx @@ -0,0 +1,125 @@ +'use client'; + +import { useQuery } from '@tanstack/react-query'; +import Link from 'next/link'; +import { apiFetch } from '../../../lib/api'; +import { useSession } from '../../../components/session-provider'; + +interface Transaction { id: string; amount: string; type: string; description: string | null; category: string | null; date: string; currency: string | null; } + +const PLAN_FEATURES = [ + { label: 'CEO OS Platform', included: true }, + { label: 'Hetzner CAX41 (16vCPU/32GB)', included: true }, + { label: 'Coolify self-hosted', included: true }, + { label: 'AnythingLLM + ClickHouse', included: true }, + { label: 'n8n self-hosted', included: true }, + { label: 'Forgejo + Hermes', included: true }, + { label: 'Claude Pro', included: true }, + { label: 'ChatGPT Plus + Gemini', included: true }, + { label: 'OpenRouter credit', included: true }, +]; + +const INFRA_COSTS = [ + { name: 'Hetzner CAX41', cost: 35, currency: 'EUR', period: 'lună' }, + { name: 'Claude Pro', cost: 20, currency: 'USD', period: 'lună' }, + { name: 'ChatGPT Plus', cost: 20, currency: 'USD', period: 'lună' }, + { name: 'Gemini Advanced', cost: 20, currency: 'USD', period: 'lună' }, + { name: 'OpenRouter credit', cost: 15, currency: 'USD', period: 'lună (estimat)' }, +]; + +export default function BillingPage() { + const { activeTenant } = useSession(); + const tenantId = activeTenant?.tenantId ?? ''; + + const { data: transactions = [] } = useQuery({ + queryKey: ['billing-txns', tenantId], + queryFn: () => apiFetch('/v1/transactions?limit=100', { tenantId }), + enabled: Boolean(tenantId), staleTime: 120_000, + }); + + const infraCosts = transactions.filter((t) => { + const desc = (t.description ?? t.category ?? '').toLowerCase(); + return desc.includes('hetzner') || desc.includes('claude') || desc.includes('openai') || desc.includes('openrouter') || desc.includes('gemini') || desc.includes('anthropic'); + }); + + const totalMonthlyEUR = INFRA_COSTS.filter((c) => c.currency === 'EUR').reduce((s, c) => s + c.cost, 0); + const totalMonthlyUSD = INFRA_COSTS.filter((c) => c.currency === 'USD').reduce((s, c) => s + c.cost, 0); + + return ( +
+
+

Facturare & Plan

+

Overview costuri infrastructură și plan CEO OS.

+
+ + {/* Current plan */} +
+
+
+

CEO OS Self-Hosted

+

Plan personal — AI Impact SRL + ADA MarkAI UG

+
+ Activ +
+
+ {PLAN_FEATURES.map((f) => ( +
+ {f.included ? '✓' : '○'} + {f.label} +
+ ))} +
+
+ + {/* Cost breakdown */} +
+

Costuri infrastructură estimate

+
+ {INFRA_COSTS.map((c) => ( +
+ {c.name} + {c.cost} {c.currency}/{c.period} +
+ ))} +
+
+ Total EUR + ≈ {totalMonthlyEUR} EUR/lună +
+
+ Total USD + ≈ {totalMonthlyUSD} USD/lună +
+
+
+
+ + {/* From transactions */} + {infraCosts.length > 0 && ( +
+

+ Plăți infrastructură din tranzacții ({infraCosts.length}) +

+
+ {infraCosts.slice(0, 10).map((t) => ( +
+
+

{t.description ?? t.category}

+

{new Date(t.date).toLocaleDateString('ro-RO')}

+
+ + {parseFloat(t.amount) < 0 ? '' : '-'}{Math.abs(parseFloat(t.amount)).toFixed(2)} {t.currency ?? 'RON'} + +
+ ))} +
+
+ )} + +
+ Toate tranzacțiile → + Setări +
+
+ ); +}