dashboart stats: as of date
This commit is contained in:
@@ -3,24 +3,28 @@
|
||||
require '../../../assets/utils/db_auth.php';
|
||||
require '../../../assets/utils/classes/ReportManager.php';
|
||||
|
||||
$month = $data['month'] ?? date('Y-m');
|
||||
$month = date('Y-m');
|
||||
$report = new ReportManager($pdo2, $company_id);
|
||||
|
||||
$stats = $report->getDashboardStats($month);
|
||||
// All-time stock totals
|
||||
$sth = $pdo2->prepare(
|
||||
"SELECT
|
||||
ROUND(COALESCE(SUM(total_in), 0), 2) AS total_in,
|
||||
ROUND(COALESCE(SUM(total_out), 0), 2) AS total_out
|
||||
FROM warehouse_balance
|
||||
WHERE company_id = :company_id"
|
||||
);
|
||||
$sth->execute([':company_id' => $company_id]);
|
||||
$stock_stats = $sth->fetch(PDO::FETCH_ASSOC);
|
||||
|
||||
// Sales stats — query td_order and td_invoice directly
|
||||
$month_start = $month . '-01';
|
||||
$month_end = date('Y-m-t', strtotime($month_start));
|
||||
|
||||
// Total orders this month (excluding cancelled)
|
||||
// All-time orders (excluding cancelled)
|
||||
$sth = $pdo2->prepare(
|
||||
"SELECT COUNT(*), COALESCE(SUM(grand_total), 0)
|
||||
FROM td_order
|
||||
WHERE company_id = :company_id
|
||||
AND status != -1
|
||||
AND order_date BETWEEN :start AND :end"
|
||||
WHERE company_id = :company_id
|
||||
AND status != -1"
|
||||
);
|
||||
$sth->execute([':company_id' => $company_id, ':start' => $month_start, ':end' => $month_end]);
|
||||
$sth->execute([':company_id' => $company_id]);
|
||||
[$total_orders, $total_revenue] = $sth->fetch(PDO::FETCH_NUM);
|
||||
|
||||
// Unpaid invoices (status=0 draft + status=1 issued + status=3 overdue)
|
||||
@@ -50,9 +54,8 @@
|
||||
$healthy_count = max(0, $total_in_stock - $critical_count - $warning_count);
|
||||
|
||||
$answer['output'] = [
|
||||
'total_in' => $stats['total_in'],
|
||||
'total_out' => $stats['total_out'],
|
||||
'active_products' => $stats['active_products'],
|
||||
'total_in' => $stock_stats['total_in'],
|
||||
'total_out' => $stock_stats['total_out'],
|
||||
'low_stock' => count($low_stock_items),
|
||||
'total_orders' => (int)$total_orders,
|
||||
'total_revenue' => (float)$total_revenue,
|
||||
@@ -62,7 +65,6 @@
|
||||
'most_moved' => $report->getMostMovedProducts($month),
|
||||
'low_stock_items' => $low_stock_items,
|
||||
'recent_activity' => $report->getRecentActivity(10),
|
||||
'months' => $report->getAvailableMonths(),
|
||||
'stock_health' => [
|
||||
'healthy' => $healthy_count,
|
||||
'warning' => $warning_count,
|
||||
|
||||
Reference in New Issue
Block a user