phpnuxbill/system/controllers/reports.php

108 lines
3.8 KiB
PHP
Raw Normal View History

2017-03-11 03:51:06 +08:00
<?php
2023-10-20 15:31:56 +08:00
2017-03-11 03:51:06 +08:00
/**
2023-10-12 16:55:42 +08:00
* PHP Mikrotik Billing (https://github.com/hotspotbilling/phpnuxbill/)
* by https://t.me/ibnux
**/
2017-03-11 03:51:06 +08:00
_admin();
2022-10-13 15:00:54 +08:00
$ui->assign('_title', $_L['Reports']);
2017-03-11 03:51:06 +08:00
$ui->assign('_system_menu', 'reports');
$action = $routes['1'];
$admin = Admin::_info();
$ui->assign('_admin', $admin);
if (!in_array($admin['user_type'], ['SuperAdmin', 'Admin', 'Sales'])) {
2023-10-20 15:31:56 +08:00
r2(U . "dashboard", 'e', $_L['Do_Not_Access']);
2017-03-11 03:51:06 +08:00
}
$mdate = date('Y-m-d');
$mtime = date('H:i:s');
$tdate = date('Y-m-d', strtotime('today - 30 days'));
$firs_day_month = date('Y-m-01');
$this_week_start = date('Y-m-d', strtotime('previous sunday'));
$before_30_days = date('Y-m-d', strtotime('today - 30 days'));
$month_n = date('n');
switch ($action) {
2022-10-16 15:48:21 +08:00
case 'by-date':
2023-10-20 15:31:56 +08:00
case 'activation':
$q = (_post('q') ? _post('q') : _get('q'));
$keep = _post('keep');
if (!empty($keep)) {
ORM::raw_execute("DELETE FROM tbl_transactions WHERE date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL $keep DAY))");
r2(U . "logs/list/", 's', "Delete logs older than $keep days");
}
if ($q != '') {
$paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['invoice' => '%' . $q . '%'], $q);
$d = ORM::for_table('tbl_transactions')->where_like('invoice', '%' . $q . '%')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
} else {
$paginator = Paginator::build(ORM::for_table('tbl_transactions'));
$d = ORM::for_table('tbl_transactions')->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
}
$ui->assign('activation', $d);
$ui->assign('q', $q);
$ui->assign('paginator', $paginator);
$ui->display('reports-activation.tpl');
break;
2017-03-11 03:51:06 +08:00
case 'daily-report':
2023-10-24 13:27:30 +08:00
$paginator = Paginator::build(ORM::for_table('tbl_transactions'), ['recharged_on' => $mdate]);
2023-10-20 15:31:56 +08:00
$d = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate)->offset($paginator['startpoint'])->limit($paginator['limit'])->order_by_desc('id')->find_many();
$dr = ORM::for_table('tbl_transactions')->where('recharged_on', $mdate)->sum('price');
$ui->assign('d', $d);
$ui->assign('dr', $dr);
$ui->assign('mdate', $mdate);
$ui->assign('mtime', $mtime);
$ui->assign('paginator', $paginator);
2022-09-18 01:00:40 +08:00
run_hook('view_daily_reports'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('reports-daily.tpl');
break;
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
case 'by-period':
2023-10-20 15:31:56 +08:00
$ui->assign('mdate', $mdate);
$ui->assign('mtime', $mtime);
$ui->assign('tdate', $tdate);
2022-09-18 01:00:40 +08:00
run_hook('view_reports_by_period'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('reports-period.tpl');
break;
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
case 'period-view':
$fdate = _post('fdate');
$tdate = _post('tdate');
$stype = _post('stype');
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
$d = ORM::for_table('tbl_transactions');
2023-10-20 15:31:56 +08:00
if ($stype != '') {
$d->where('type', $stype);
}
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
$d->where_gte('recharged_on', $fdate);
$d->where_lte('recharged_on', $tdate);
$d->order_by_desc('id');
$x = $d->find_many();
2022-09-18 01:00:40 +08:00
2023-10-20 15:31:56 +08:00
$dr = ORM::for_table('tbl_transactions');
if ($stype != '') {
$dr->where('type', $stype);
}
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
$dr->where_gte('recharged_on', $fdate);
$dr->where_lte('recharged_on', $tdate);
2023-10-20 15:31:56 +08:00
$xy = $dr->sum('price');
2022-09-18 01:00:40 +08:00
2023-10-20 15:31:56 +08:00
$ui->assign('d', $x);
$ui->assign('dr', $xy);
$ui->assign('fdate', $fdate);
$ui->assign('tdate', $tdate);
$ui->assign('stype', $stype);
2022-09-18 01:00:40 +08:00
run_hook('view_reports_period'); #HOOK
2017-03-11 03:51:06 +08:00
$ui->display('reports-period-view.tpl');
break;
2022-09-18 01:00:40 +08:00
2017-03-11 03:51:06 +08:00
default:
2023-09-27 16:01:48 +08:00
$ui->display('a404.tpl');
2023-10-20 15:31:56 +08:00
}