feat: simplify dashboard for staff without data access
This commit is contained in:
parent
7e920e999d
commit
08a58d8cfc
16
index.php
16
index.php
@ -2666,7 +2666,6 @@ $page = $_GET['page'] ?? 'dashboard';
|
||||
|
||||
// Permission map for pages
|
||||
$page_permissions = [
|
||||
'dashboard' => 'dashboard_view',
|
||||
'pos' => 'pos_view',
|
||||
'sales' => 'sales_view',
|
||||
'sales_returns' => 'sales_returns_view',
|
||||
@ -3681,6 +3680,7 @@ switch ($page) {
|
||||
$data['users'] = db()->query("SELECT id, username FROM users ORDER BY username ASC")->fetchAll();
|
||||
break;
|
||||
default:
|
||||
if (can('dashboard_view')) {
|
||||
$data['customers'] = db()->query("SELECT * FROM customers ORDER BY id DESC LIMIT 5")->fetchAll();
|
||||
$data['stats'] = [
|
||||
'total_customers' => db()->query("SELECT COUNT(*) FROM customers")->fetchColumn(),
|
||||
@ -3699,6 +3699,7 @@ switch ($page) {
|
||||
// Sales Chart Data
|
||||
$data['monthly_sales'] = db()->query("SELECT DATE_FORMAT(invoice_date, '%M %Y') as label, SUM(total_with_vat) as total FROM invoices GROUP BY DATE_FORMAT(invoice_date, '%Y-%m') ORDER BY invoice_date ASC LIMIT 12")->fetchAll(PDO::FETCH_ASSOC);
|
||||
$data['yearly_sales'] = db()->query("SELECT YEAR(invoice_date) as label, SUM(total_with_vat) as total FROM invoices GROUP BY label ORDER BY label ASC LIMIT 5")->fetchAll(PDO::FETCH_ASSOC);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@ -3859,11 +3860,9 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</div>
|
||||
<nav class="mt-4">
|
||||
<!-- General Section -->
|
||||
<?php if (can('dashboard_view')): ?>
|
||||
<a href="index.php?page=dashboard" class="nav-link <?= !isset($_GET['page']) || $_GET['page'] === 'dashboard' ? 'active' : '' ?>">
|
||||
<i class="fas fa-chart-pie"></i> <span><?= __('dashboard') ?></span>
|
||||
</a>
|
||||
<?php endif; ?>
|
||||
|
||||
<!-- POS Section -->
|
||||
<?php if (can('pos_view')): ?>
|
||||
@ -4264,6 +4263,7 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
<?php endif; ?>
|
||||
<?php if ($page === 'dashboard'): ?>
|
||||
|
||||
<?php if (can('dashboard_view')): ?>
|
||||
<?php
|
||||
$purchaseAlertsCount = count(getPurchaseAlerts());
|
||||
if ($data['stats']['expired_items'] > 0 || $data['stats']['near_expiry_items'] > 0 || $data['stats']['low_stock_items_count'] > 0 || $purchaseAlertsCount > 0): ?>
|
||||
@ -4480,6 +4480,14 @@ $projectDescription = $_SERVER['PROJECT_DESCRIPTION'] ?? 'Accounting System';
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="d-flex flex-column justify-content-center align-items-center h-100" style="min-height: 70vh;">
|
||||
<?php if (!empty($data['settings']['company_logo'])): ?>
|
||||
<img src="<?= htmlspecialchars($data['settings']['company_logo']) ?>" alt="Company Logo" class="mb-4" style="max-height: 200px; max-width: 350px; object-fit: contain;">
|
||||
<?php endif; ?>
|
||||
<h1 class="display-4 fw-bold text-muted text-center mt-3"><?= htmlspecialchars($data['settings']['company_name'] ?? 'Company Name') ?></h1>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php elseif ($page === 'customers' || $page === 'suppliers'): ?>
|
||||
<div class="card p-4">
|
||||
<div class="d-flex justify-content-between align-items-center mb-4">
|
||||
@ -14120,7 +14128,7 @@ document.addEventListener('DOMContentLoaded', function() {
|
||||
observer.observe(document.body, { childList: true, subtree: true });
|
||||
});
|
||||
// -----------------------------
|
||||
<?php if ($page === 'dashboard'): ?>
|
||||
<?php if ($page === 'dashboard' && can('dashboard_view')): ?>
|
||||
const monthlyData = <?= json_encode($data['monthly_sales']) ?>;
|
||||
const yearlyData = <?= json_encode($data['yearly_sales']) ?>;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user