diff --git a/system/controllers/dashboard.php b/system/controllers/dashboard.php index 1adbe93a..063ca0f1 100644 --- a/system/controllers/dashboard.php +++ b/system/controllers/dashboard.php @@ -90,7 +90,7 @@ foreach ($tmp as $plan) { $used = ORM::for_table('tbl_voucher') ->where('id_plan', $plan['id']) ->where('status', 1)->count(); - if($unused>0 || $used>0){ + if ($unused > 0 || $used > 0) { $plans[$n]['name_plan'] = $plan['name_plan']; $plans[$n]['unused'] = $unused; $plans[$n]['used'] = $used; @@ -100,6 +100,68 @@ foreach ($tmp as $plan) { } } +//Monthly Registered Customers +$result = ORM::for_table('tbl_customers') + ->select_expr('MONTH(created_at)', 'month') + ->select_expr('COUNT(*)', 'count') + ->where_raw('YEAR(created_at) = YEAR(NOW())') + ->group_by_expr('MONTH(created_at)') + ->find_many(); + +$counts = []; +foreach ($result as $row) { + $counts[] = [ + 'date' => $row->month, + 'count' => $row->count + ]; +} + +// Query to retrieve monthly data +$query = ORM::for_table('tbl_transactions') + ->select_expr('MONTH(recharged_on)', 'month') + ->select_expr('SUM(price)', 'total') + ->where_raw("YEAR(recharged_on) = YEAR(CURRENT_DATE())") // Filter by the current year + ->group_by_expr('MONTH(recharged_on)') + ->find_many(); + +// Execute the query and retrieve the monthly sales data +$results = $query->find_many(); + +// Create an array to hold the monthly sales data +$monthlySales = array(); + +// Iterate over the results and populate the array +foreach ($results as $result) { + $month = $result->month; + $totalSales = $result->total; + + $monthlySales[$month] = array( + 'month' => $month, + 'totalSales' => $totalSales + ); +} + +// Fill in missing months with zero sales +for ($month = 1; $month <= 12; $month++) { + if (!isset($monthlySales[$month])) { + $monthlySales[$month] = array( + 'month' => $month, + 'totalSales' => 0 + ); + } +} + +// Sort the array by month +ksort($monthlySales); + +// Reindex the array +$monthlySales = array_values($monthlySales); + +// Assign the monthly sales data to Smarty +$ui->assign('monthlySales', $monthlySales); +$ui->assign('xheader', ''); +$ui->assign('xfooter', ''); +$ui->assign('counts', $counts); $ui->assign('stocks', $stocks); $ui->assign('plans', $plans); diff --git a/ui/ui/dashboard.tpl b/ui/ui/dashboard.tpl index 77b45d13..26a6abed 100644 --- a/ui/ui/dashboard.tpl +++ b/ui/ui/dashboard.tpl @@ -1,5 +1,6 @@ {include file="sections/header.tpl"} +
{$_L['Plan_Name']} | -unused | -used | -|||
---|---|---|---|---|---|
{$stok['name_plan']} | -{$stok['unused']} | -{$stok['used']} | -
Total | -{$stocks['unused']} | -{$stocks['used']} | +{$_L['Plan_Name']} | +unused | +used |
---|
{$dlogs['description']}
-{$dlogs['description']}
+