Reports with chart

This commit is contained in:
Ibnu Maksum
2024-08-13 11:42:22 +07:00
parent 0fa78966ef
commit 0fae434c1b
4 changed files with 249 additions and 78 deletions

View File

@ -147,6 +147,105 @@ switch ($action) {
}
}
break;
case 'line':
$query = ORM::for_table('tbl_transactions')
->whereRaw("UNIX_TIMESTAMP(CONCAT(`recharged_on`,' ',`recharged_time`)) >= " . strtotime("$sd $ts"))
->whereRaw("UNIX_TIMESTAMP(CONCAT(`recharged_on`,' ',`recharged_time`)) <= " . strtotime("$ed $te"))
->order_by_desc('id');
if (count($tps) > 0) {
$query->where_in('type', $tps);
}
if (count($mts) > 0) {
if (count($mts) != count($methods)) {
foreach ($mts as $mt) {
$query->where_like('method', "$mt - %");
}
}
}
if (count($rts) > 0) {
$query->where_in('routers', $rts);
}
if (count($plns) > 0) {
$query->where_in('plan_name', $plns);
}
$datas = $query->find_array();
$period = new DatePeriod(
new DateTime($sd),
new DateInterval('P1D'),
new DateTime($ed)
);
$pos = 0;
$dates = [];
foreach ($period as $key => $value) {
$dates[] = $value->format('Y-m-d');
}
$dates = array_reverse($dates);
$result = [];
$temp;
foreach ($dates as $date) {
$result['labels'][] = $date;
// type
foreach ($tps as $key) {
if (!isset($temp[$key][$date])) {
$temp[$key][$date] = 0;
}
foreach ($datas as $data) {
if ($data['recharged_on'] == date('Y-m-d', strtotime($date)) && $data['type'] == $key) {
$temp[$key][$date] += 1;
}
}
}
//plan
foreach ($plns as $key) {
if (!isset($temp[$key][$date])) {
$temp[$key][$date] = 0;
}
foreach ($datas as $data) {
if ($data['recharged_on'] == date('Y-m-d', strtotime($date)) && $data['plan_name'] == $key) {
$temp[$key][$date] += 1;
}
}
}
//method
foreach ($mts as $key) {
if (!isset($temp[$key][$date])) {
$temp[$key][$date] = 0;
}
foreach ($datas as $data) {
if ($data['recharged_on'] == date('Y-m-d', strtotime($date)) && strpos($data['method'], $key) !== false) {
$temp[$key][$date] += 1;
}
}
}
foreach ($rts as $key) {
if (!isset($temp[$key][$date])) {
$temp[$key][$date] = 0;
}
foreach ($datas as $data) {
if ($data['recharged_on'] == date('Y-m-d', strtotime($date)) && $data['routers'] == $key) {
$temp[$key][$date] += 1;
}
}
}
$pos++;
if ($pos > 29) {
// only 30days
break;
}
}
foreach ($temp as $key => $value) {
$array = ['label' => $key];
$total = 0;
foreach ($value as $k => $v) {
$total += $v;
$array['data'][] = $v;
}
if($total>0){
$result['datas'][] = $array;
}
}
break;
default:
$result = ['labels' => [], 'datas' => []];
}
@ -285,6 +384,6 @@ switch ($action) {
$ui->assign('dr', $dr);
$ui->assign('mdate', $mdate);
run_hook('view_daily_reports'); #HOOK
$ui->display('reports-daily.tpl');
$ui->display('reports.tpl');
break;
}

View File

@ -700,5 +700,6 @@
"User_Cannot_change_this__only_admin__if_it_Empty_it_will_use_Customer_Credentials": "User Cannot change this, only admin. if it Empty it will use Customer Credentials",
"Failed_to_buy_package": "Failed to buy package",
"New_Voucher_Created": "New Voucher Created",
"New_Voucher_for_10mbps_Created": "New Voucher for 10mbps Created"
"New_Voucher_for_10mbps_Created": "New Voucher for 10mbps Created",
"Show_Chart": "Show Chart"
}