Files

558 lines
22 KiB
HTML

<!DOCTYPE html>
<html lang="sv">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>BOC Dashboard — Business Operations Center</title>
<link rel="stylesheet" href="assets/boc.css">
<script src="https://cdn.jsdelivr.net/npm/chart.js@4.4.1/dist/chart.umd.min.js"></script>
</head>
<body>
<div class="app">
<!-- Sidebar -->
<aside class="sidebar">
<div class="sidebar-logo">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
<rect x="2" y="7" width="20" height="14" rx="2" ry="2"/>
<path d="M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"/>
</svg>
<span>BOC</span>
</div>
<nav class="sidebar-nav">
<a href="dashboard.html" class="active">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
<span>Dashboard</span>
</a>
<a href="crm.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
<span>CRM</span>
</a>
<a href="sales.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>
<span>Sales</span>
</a>
<a href="finance.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/></svg>
<span>Finance</span>
</a>
<a href="hr.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"/><circle cx="12" cy="7" r="4"/></svg>
<span>HR</span>
</a>
<a href="legal.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="16" y1="13" x2="8" y2="13"/><line x1="16" y1="17" x2="8" y2="17"/></svg>
<span>Legal</span>
</a>
<a href="marketing.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M11 5.08V2a1 1 0 0 0-1-1H2a1 1 0 0 0-1 1v3.08"/><path d="M7 9h12a2 2 0 0 1 2 2v10a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V11a2 2 0 0 1 2-2z"/><path d="M7 9V5a2 2 0 0 1 2-2h6a2 2 0 0 1 2 2v4"/></svg>
<span>Marketing</span>
</a>
<a href="support.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
<span>Support</span>
</a>
<a href="automation.html">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/></svg>
<span>Automation</span>
</a>
</nav>
<div class="sidebar-footer">
<span id="user-email">erik@landvex.com</span>
<button onclick="logout()">Logga ut</button>
</div>
</aside>
<main class="main">
<!-- Header -->
<header class="module-header">
<h1>Dashboard</h1>
<p class="subtitle">Overblick over hela verksamheten</p>
</header>
<!-- Critical Alerts -->
<div id="alerts-container" style="display:none; margin-bottom: var(--space-lg);">
<div class="alert alert-critical">
<strong>Kritiskt:</strong> Momsdeklaration 442,000 kr — deadline 2026-07-26 (14 dagar kvar)
</div>
</div>
<!-- KPI Grid -->
<div class="kpi-grid">
<div class="kpi-card" onclick="navigateTo('sales')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-mrr"></div>
<div class="kpi-label">MRR</div>
<div class="kpi-trend up" id="kpi-mrr-trend">+5%</div>
</div>
</div>
<div class="kpi-card" onclick="navigateTo('sales')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="18" y1="20" x2="18" y2="10"/><line x1="12" y1="20" x2="12" y2="4"/><line x1="6" y1="20" x2="6" y2="14"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-arr"></div>
<div class="kpi-label">ARR</div>
<div class="kpi-trend up" id="kpi-arr-trend">+12%</div>
</div>
</div>
<div class="kpi-card" onclick="navigateTo('crm')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><path d="M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><path d="M23 21v-2a4 4 0 0 0-3-3.87"/><path d="M16 3.13a4 4 0 0 1 0 7.75"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-customers"></div>
<div class="kpi-label">Kunder</div>
<div class="kpi-trend up" id="kpi-customers-trend">+3 nya</div>
</div>
</div>
<div class="kpi-card" onclick="navigateTo('support')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-tickets"></div>
<div class="kpi-label">Oppna arenden</div>
<div class="kpi-trend down" id="kpi-tickets-trend">-2 idag</div>
</div>
</div>
<div class="kpi-card" onclick="navigateTo('finance')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><rect x="2" y="7" width="20" height="14" rx="2" ry="2"/><path d="M16 21V5a2 2 0 0 0-2-2h-4a2 2 0 0 0-2 2v16"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-cash"></div>
<div class="kpi-label">Kassa</div>
<div class="kpi-trend" id="kpi-cash-trend">4 manader runway</div>
</div>
</div>
<div class="kpi-card" onclick="navigateTo('sales')">
<div class="kpi-icon">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"/><path d="M16.2 7.8l-2 6.3l-6.4 2.1l2-6.3z"/></svg>
</div>
<div>
<div class="kpi-value" id="kpi-pipeline"></div>
<div class="kpi-label">Pipeline</div>
<div class="kpi-trend up" id="kpi-pipeline-trend">+15%</div>
</div>
</div>
</div>
<!-- Two Column Layout -->
<div class="dashboard-grid">
<!-- Left: Charts -->
<div>
<div class="panel">
<div class="toolbar">
<h3>Intaktstrend</h3>
<select id="revenue-period" onchange="updateRevenueChart()">
<option value="6m">6 manader</option>
<option value="1y">1 ar</option>
<option value="ytd">Ar till datum</option>
</select>
</div>
<canvas id="revenue-chart" height="200"></canvas>
</div>
<div class="panel">
<div class="toolbar">
<h3>Pipeline</h3>
<a href="sales.html" class="btn-link">Se alla deals</a>
</div>
<canvas id="pipeline-chart" height="200"></canvas>
</div>
</div>
<!-- Right: Activity & Quick Actions -->
<div>
<!-- Quick Actions -->
<div class="panel">
<h3>Snabbatgarder</h3>
<div class="quick-actions">
<button class="btn-action" onclick="createCustomer()">+ Kund</button>
<button class="btn-action" onclick="createDeal()">+ Deal</button>
<button class="btn-action" onclick="createInvoice()">+ Faktura</button>
<button class="btn-action" onclick="createTicket()">+ Arende</button>
<button class="btn-action" onclick="createExpense()">+ Utgift</button>
<button class="btn-action" onclick="createContract()">+ Kontrakt</button>
</div>
</div>
<!-- Recent Activity -->
<div class="panel">
<div class="toolbar">
<h3>Senaste aktivitet</h3>
<span class="badge active" id="live-indicator">Live</span>
</div>
<div id="activity-feed">
<div class="loading">Laddar aktivitet...</div>
</div>
</div>
<!-- Automation Status -->
<div class="panel">
<div class="toolbar">
<h3>Automation</h3>
<a href="automation.html" class="btn-link">Hantera</a>
</div>
<div class="automation-grid" id="automation-status">
<div class="automation-item">
<span class="automation-indicator active"></span>
<span class="automation-name">Kontraktsfornyelser</span>
<span class="automation-schedule">Dagligen 09:00</span>
</div>
<div class="automation-item">
<span class="automation-indicator active"></span>
<span class="automation-name">Fakturapaminnelser</span>
<span class="automation-schedule">Mandagar</span>
</div>
<div class="automation-item">
<span class="automation-indicator warning"></span>
<span class="automation-name">Momsrapport</span>
<span class="automation-schedule">Manuell — deadline 2026-07-26</span>
</div>
<div class="automation-item">
<span class="automation-indicator active"></span>
<span class="automation-name">Backup</span>
<span class="automation-schedule">Dagligen 02:00</span>
</div>
</div>
</div>
</div>
</div>
</main>
</div>
<!-- Modal -->
<div id="modal" class="modal" style="display:none;" onclick="if(event.target===this)hideModal()">
<div class="modal-content">
<div class="modal-header">
<h3 id="modal-title">Skapa</h3>
<button class="modal-close" onclick="hideModal()">&times;</button>
</div>
<div id="modal-body" class="modal-body"></div>
</div>
</div>
<script src="assets/boc.js"></script>
<script>
// Navigation
function navigateTo(module) {
window.location.href = module + '.html';
}
function logout() {
localStorage.removeItem('boc_token');
localStorage.removeItem('boc_user');
window.location.href = '/';
}
// Quick create functions
function createCustomer() {
showModal('Ny kund', `
<div class="form-group">
<label>Foretag / Namn</label>
<input type="text" id="cust-name" placeholder="Acme AB" autofocus>
</div>
<div class="form-group">
<label>E-post</label>
<input type="email" id="cust-email" placeholder="kontakt@acme.se">
</div>
<div class="form-group">
<label>Telefon</label>
<input type="tel" id="cust-phone" placeholder="+46 70 123 45 67">
</div>
<button class="btn-primary" onclick="submitCustomer()" style="width:100%">Skapa kund</button>
`);
}
function createDeal() {
showModal('Ny deal', `
<div class="form-group">
<label>Deal-namn</label>
<input type="text" id="deal-name" placeholder="Q3 Enterprise" autofocus>
</div>
<div class="form-group">
<label>Varde (USD)</label>
<input type="number" id="deal-value" placeholder="50000">
</div>
<div class="form-group">
<label>Steg</label>
<select id="deal-stage">
<option value="prospect">Prospect</option>
<option value="qualified">Qualified</option>
<option value="proposal">Proposal</option>
<option value="negotiation">Negotiation</option>
</select>
</div>
<button class="btn-primary" onclick="submitDeal()" style="width:100%">Skapa deal</button>
`);
}
function createInvoice() {
showModal('Ny faktura', `
<div class="form-group">
<label>Kund</label>
<select id="inv-customer"><option>Laddar...</option></select>
</div>
<div class="form-group">
<label>Belopp (USD)</label>
<input type="number" id="inv-amount" placeholder="10000">
</div>
<div class="form-group">
<label>Forfallodatum</label>
<input type="date" id="inv-due">
</div>
<button class="btn-primary" onclick="submitInvoice()" style="width:100%">Skapa faktura</button>
`);
}
function createTicket() {
showModal('Nytt arende', `
<div class="form-group">
<label>Amne</label>
<input type="text" id="ticket-subject" placeholder="Problem med inloggning" autofocus>
</div>
<div class="form-group">
<label>Beskrivning</label>
<textarea id="ticket-desc" rows="3" placeholder="Beskriv problemet..."></textarea>
</div>
<div class="form-group">
<label>Prioritet</label>
<select id="ticket-priority">
<option value="low">Lag</option>
<option value="medium" selected>Medium</option>
<option value="high">Hog</option>
<option value="critical">Kritisk</option>
</select>
</div>
<button class="btn-primary" onclick="submitTicket()" style="width:100%">Skapa arende</button>
`);
}
function createExpense() {
showModal('Ny utgift', `
<div class="form-group">
<label>Kategori</label>
<select id="exp-cat">
<option>Boende</option>
<option>Mat</option>
<option>Resa</option>
<option>Transport</option>
<option>Tech</option>
<option>Juridik</option>
<option>Kommunikation</option>
<option>Ovrigt</option>
</select>
</div>
<div class="form-group">
<label>Belopp</label>
<input type="number" id="exp-amount" placeholder="0">
</div>
<div class="form-group">
<label>Beskrivning</label>
<input type="text" id="exp-desc" placeholder="Vad galler utgiften?">
</div>
<button class="btn-primary" onclick="submitExpense()" style="width:100%">Registrera utgift</button>
`);
}
function createContract() {
showModal('Nytt kontrakt', `
<div class="form-group">
<label>Titel</label>
<input type="text" id="contract-title" placeholder="Tjansteavtal 2026" autofocus>
</div>
<div class="form-group">
<label>Motpart</label>
<input type="text" id="contract-party" placeholder="Foretagsnamn">
</div>
<div class="form-group">
<label>Typ</label>
<select id="contract-type">
<option value="service">Tjansteavtal</option>
<option value="employment">Anstallning</option>
<option value="nda">NDA</option>
<option value="partnership">Partnerskap</option>
</select>
</div>
<button class="btn-primary" onclick="submitContract()" style="width:100%">Skapa kontrakt</button>
`);
}
// Modal helpers
function showModal(title, html) {
document.getElementById('modal-title').textContent = title;
document.getElementById('modal-body').innerHTML = html;
document.getElementById('modal').style.display = 'flex';
}
function hideModal() {
document.getElementById('modal').style.display = 'none';
}
// Submit functions
async function submitCustomer() { hideModal(); }
async function submitDeal() { hideModal(); }
async function submitInvoice() { hideModal(); }
async function submitTicket() { hideModal(); }
async function submitExpense() { hideModal(); }
async function submitContract() { hideModal(); }
// Get auth token
function getToken() {
return localStorage.getItem('boc_token');
}
// Check auth on load
if (!getToken()) {
window.location.href = '/';
}
// Load dashboard data
async function loadDashboard() {
try {
const token = getToken();
const res = await fetch('/api/v1/analytics/dashboard', {
headers: { 'Authorization': 'Bearer ' + token }
});
const data = await res.json();
if (data.kpis) {
document.getElementById('kpi-mrr').textContent = formatCurrency(data.kpis.mrr?.value);
document.getElementById('kpi-arr').textContent = formatCurrency(data.kpis.arr?.value);
document.getElementById('kpi-customers').textContent = data.kpis.customers?.active || 0;
document.getElementById('kpi-tickets').textContent = data.kpis.tickets?.open || 0;
document.getElementById('kpi-cash').textContent = formatCurrency(data.kpis.cash?.on_hand);
document.getElementById('kpi-pipeline').textContent = formatCurrency(data.kpis.pipeline?.total_value);
}
renderCharts(data.charts);
renderActivity(data.activity || []);
} catch (err) {
console.error('Failed to load dashboard:', err);
}
}
function formatCurrency(value) {
if (!value) return '—';
return new Intl.NumberFormat('sv-SE', { style: 'currency', currency: 'USD', maximumFractionDigits: 0 }).format(value);
}
function renderCharts(charts) {
if (!charts) return;
const revCtx = document.getElementById('revenue-chart');
if (revCtx && charts.revenue_trend) {
new Chart(revCtx, {
type: 'line',
data: {
labels: charts.revenue_trend.map(d => d.month),
datasets: [{
label: 'Intakt',
data: charts.revenue_trend.map(d => d.revenue),
borderColor: '#0066FF',
backgroundColor: 'rgba(0, 102, 255, 0.08)',
fill: true,
tension: 0.4,
pointRadius: 4,
pointHoverRadius: 6
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
plugins: { legend: { display: false } },
scales: {
y: { beginAtZero: true, grid: { color: '#e9ecef' }, ticks: { callback: v => '$' + (v/1000) + 'k' } },
x: { grid: { display: false } }
}
}
});
}
const pipeCtx = document.getElementById('pipeline-chart');
if (pipeCtx && charts.pipeline_by_stage) {
new Chart(pipeCtx, {
type: 'doughnut',
data: {
labels: charts.pipeline_by_stage.map(d => d.stage),
datasets: [{
data: charts.pipeline_by_stage.map(d => d.value),
backgroundColor: ['#0066FF', '#4D94FF', '#80B3FF', '#B3D1FF'],
borderWidth: 0
}]
},
options: {
responsive: true,
maintainAspectRatio: false,
cutout: '65%',
plugins: {
legend: { position: 'right', labels: { usePointStyle: true, padding: 16 } }
}
}
});
}
}
function renderActivity(activities) {
const feed = document.getElementById('activity-feed');
if (activities.length === 0) {
feed.innerHTML = '<div class="empty-state"><p>Ingen aktivitet an</p></div>';
return;
}
feed.innerHTML = activities.slice(0, 8).map(a => `
<div class="list-item">
<div>
<div class="list-item-main">${a.description}</div>
<div class="list-item-meta">${a.user} · ${timeAgo(a.timestamp)}</div>
</div>
<span class="badge ${a.status}">${a.type}</span>
</div>
`).join('');
}
function timeAgo(timestamp) {
const diff = Date.now() - new Date(timestamp).getTime();
const mins = Math.floor(diff / 60000);
if (mins < 1) return 'nyss';
if (mins < 60) return `${mins}m sedan`;
const hours = Math.floor(mins / 60);
if (hours < 24) return `${hours}h sedan`;
return `${Math.floor(hours / 24)}d sedan`;
}
// WebSocket
let ws;
function connectWebSocket() {
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
const token = getToken();
ws = new WebSocket(`${protocol}//${window.location.host}/ws?tenant_id=default&token=***
ws.onopen = () => {
document.getElementById('live-indicator').style.display = 'inline-flex';
};
ws.onmessage = (event) => {
const data = JSON.parse(event.data);
if (data.type === 'deal_updated' || data.type === 'ticket_updated') {
loadDashboard();
}
};
ws.onclose = () => {
document.getElementById('live-indicator').style.display = 'none';
setTimeout(connectWebSocket, 5000);
};
}
// Init
loadDashboard();
connectWebSocket();
setInterval(loadDashboard, 60000);
</script>
</body>
</html>