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"} +
@@ -59,38 +60,73 @@
+ +
+
+ +

{Lang::T('Monthly Registered Customers')}

+ +
+ + +
+
+
+ +
+
+ +
+
+ + +

{Lang::T('Total Monthly Sales')}

+ +
+ + +
+
+
+ +
+
{if $_c['disable_voucher'] != 'yes' && $stocks['unused']>0 || $stocks['used']>0} -
-
Vouchers Stock
-
- - - - - - - - - - {foreach $plans as $stok} - - - - - - - {/foreach} +
+
Vouchers Stock
+
+
{$_L['Plan_Name']}unusedused
{$stok['name_plan']}{$stok['unused']}{$stok['used']}
+ - - - + + + -
Total{$stocks['unused']}{$stocks['used']}{$_L['Plan_Name']}unusedused
-
+ + + {foreach $plans as $stok} + + {$stok['name_plan']} + {$stok['unused']} + {$stok['used']} + + + {/foreach} + + Total + {$stocks['unused']} + {$stocks['used']} + +
+
{/if}
{$_L['User_Expired_Today']}
@@ -107,15 +143,15 @@ {$no = 1} {foreach $expire as $expired} - - {$no++} - {$expired['username']} - {Lang::dateAndTimeFormat($expired['recharged_on'],$expired['recharged_time'])} - - {Lang::dateAndTimeFormat($expired['expiration'],$expired['time'])} - - - + + {$no++} + {$expired['username']} + {Lang::dateAndTimeFormat($expired['recharged_on'],$expired['recharged_time'])} + + {Lang::dateAndTimeFormat($expired['expiration'],$expired['time'])} + + + {/foreach}
@@ -123,38 +159,201 @@
+
{Lang::T('Payment Gateway')}: {$_c['payment_gateway']}
+
+
{Lang::T('Active Users')}
+
+ +
+
    {foreach $dlog as $dlogs} -
  • - - {time_elapsed_string($dlogs['date'],true)} -

    {$dlogs['description']}

    -
  • +
  • + + {time_elapsed_string($dlogs['date'],true)} +

    {$dlogs['description']}

    +
  • {/foreach}
+ + + +{literal} + + + +{/literal}