2017-03-11 03:51:06 +08:00
|
|
|
<?php
|
2023-09-07 11:54:20 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
/**
|
2023-09-07 11:54:20 +08:00
|
|
|
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
|
|
|
|
**/
|
2017-03-11 03:51:06 +08:00
|
|
|
_admin();
|
2022-10-13 15:00:54 +08:00
|
|
|
$ui->assign('_title', $_L['Dashboard']);
|
2017-03-11 03:51:06 +08:00
|
|
|
$admin = Admin::_info();
|
|
|
|
$ui->assign('_admin', $admin);
|
2023-09-07 11:54:20 +08:00
|
|
|
if (!in_array($admin['user_type'], ['Admin', 'Sales'])) {
|
|
|
|
r2(U . "home", 'e', $_L['Do_Not_Access']);
|
2017-03-11 03:51:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
$fdate = date('Y-m-01');
|
|
|
|
$tdate = date('Y-m-t');
|
|
|
|
//first day of month
|
|
|
|
$first_day_month = date('Y-m-01');
|
|
|
|
$mdate = date('Y-m-d');
|
|
|
|
$month_n = date('n');
|
|
|
|
|
2023-09-07 11:54:20 +08:00
|
|
|
$iday = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate)->sum('price');
|
|
|
|
if ($iday == '') {
|
2017-03-11 03:51:06 +08:00
|
|
|
$iday = '0.00';
|
|
|
|
}
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('iday', $iday);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
2023-09-07 11:54:20 +08:00
|
|
|
$imonth = ORM::for_table('tbl_transactions')->where_gte('recharged_on', $first_day_month)->where_lte('recharged_on', $mdate)->sum('price');
|
|
|
|
if ($imonth == '') {
|
2017-03-11 03:51:06 +08:00
|
|
|
$imonth = '0.00';
|
|
|
|
}
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('imonth', $imonth);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
2023-09-07 11:54:20 +08:00
|
|
|
$u_act = ORM::for_table('tbl_user_recharges')->where('status', 'on')->count();
|
2023-09-13 16:50:20 +08:00
|
|
|
if (empty($u_act)) {
|
2017-03-11 03:51:06 +08:00
|
|
|
$u_act = '0';
|
|
|
|
}
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('u_act', $u_act);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
|
|
|
$u_all = ORM::for_table('tbl_user_recharges')->count();
|
2023-09-13 16:50:20 +08:00
|
|
|
if (empty($u_all)) {
|
2017-03-11 03:51:06 +08:00
|
|
|
$u_all = '0';
|
|
|
|
}
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('u_all', $u_all);
|
|
|
|
|
|
|
|
|
|
|
|
$c_all = ORM::for_table('tbl_customers')->count();
|
2023-09-13 16:50:20 +08:00
|
|
|
if (empty($c_all)) {
|
2023-09-07 11:54:20 +08:00
|
|
|
$c_all = '0';
|
|
|
|
}
|
2023-09-13 16:50:20 +08:00
|
|
|
$ui->assign('c_all', $c_all);
|
2023-09-07 11:54:20 +08:00
|
|
|
|
2017-03-11 03:51:06 +08:00
|
|
|
//user expire
|
2023-09-21 15:54:00 +08:00
|
|
|
$expire = ORM::for_table('tbl_user_recharges')->whereLte('expiration', $mdate)->order_by_desc('id')->limit(30)->find_many();
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('expire', $expire);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
|
|
|
//activity log
|
|
|
|
$dlog = ORM::for_table('tbl_logs')->limit(5)->order_by_desc('id')->find_many();
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('dlog', $dlog);
|
2017-03-11 03:51:06 +08:00
|
|
|
$log = ORM::for_table('tbl_logs')->count();
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('log', $log);
|
2017-03-11 03:51:06 +08:00
|
|
|
|
2017-03-15 03:37:15 +08:00
|
|
|
// Count stock
|
|
|
|
$tmp = $v = ORM::for_table('tbl_plans')->select('id')->select('name_plan')->find_many();
|
|
|
|
$plans = array();
|
2023-09-07 11:54:20 +08:00
|
|
|
$stocks = array("used" => 0, "unused" => 0);
|
2017-03-15 03:37:15 +08:00
|
|
|
$n = 0;
|
2023-09-07 11:54:20 +08:00
|
|
|
foreach ($tmp as $plan) {
|
2017-03-15 03:37:15 +08:00
|
|
|
$plans[$n]['name_plan'] = $plan['name_plan'];
|
|
|
|
$plans[$n]['unused'] = ORM::for_table('tbl_voucher')
|
2023-09-07 11:54:20 +08:00
|
|
|
->where('id_plan', $plan['id'])
|
|
|
|
->where('status', 0)->count();;
|
2017-03-15 03:37:15 +08:00
|
|
|
$stocks["unused"] += $plans[$n]['unused'];
|
|
|
|
$plans[$n]['used'] = ORM::for_table('tbl_voucher')
|
2023-09-07 11:54:20 +08:00
|
|
|
->where('id_plan', $plan['id'])
|
|
|
|
->where('status', 1)->count();;
|
2017-03-15 03:37:15 +08:00
|
|
|
$stocks["used"] += $plans[$n]['used'];
|
|
|
|
$n++;
|
|
|
|
}
|
|
|
|
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->assign('stocks', $stocks);
|
|
|
|
$ui->assign('plans', $plans);
|
2017-03-15 03:37:15 +08:00
|
|
|
|
2022-09-18 01:00:40 +08:00
|
|
|
run_hook('view_dashboard'); #HOOK
|
2023-09-07 11:54:20 +08:00
|
|
|
$ui->display('dashboard.tpl');
|