diff --git a/system/controllers/reports.php b/system/controllers/reports.php index 2f1c85d..a1c4e3c 100644 --- a/system/controllers/reports.php +++ b/system/controllers/reports.php @@ -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; } diff --git a/system/lan/english.json b/system/lan/english.json index eb4b5e4..6fa3250 100644 --- a/system/lan/english.json +++ b/system/lan/english.json @@ -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" } \ No newline at end of file diff --git a/ui/ui/reports-daily.tpl b/ui/ui/reports.tpl similarity index 52% rename from ui/ui/reports-daily.tpl rename to ui/ui/reports.tpl index 49e18fa..234d715 100644 --- a/ui/ui/reports-daily.tpl +++ b/ui/ui/reports.tpl @@ -8,6 +8,13 @@

{Lang::T('Filter')}

-
-
-
- -
-
- -
-
- -
-
- +
+
+
+

{Lang::dateFormat($sd)} - {Lang::dateFormat($ed)} Max 30 days

+
+
+ +
+
+
@@ -127,71 +144,125 @@ - + if (getCookie('show_report_graph') != 'hide') { + $("#chart_area").removeClass("hidden"); + document.getElementById('show_chart').checked = true; + showChart(); + } + + }); + + function setShowChart() { + if (document.getElementById('show_chart').checked) { + setCookie('show_report_graph', 'show', 30); + } else { + setCookie('show_report_graph', 'hide', 30); + } + location.reload(); + } + + function getLineChartData() { + $.getJSON("{/literal}{$_url}{literal}reports/ajax/line&{/literal}{$filter}{literal}", function( data ) { + var linechart = new Chart(document.getElementById('line_cart'), { + type: 'line', + data: { + labels: data.labels, + datasets: data.datas, + }, + options: { + maintainAspectRatio: false, + aspectRatio: 1, + plugins: { + autocolors: { + mode: 'data' + }, + legend: { + position: 'bottom' + } + } + } + }); + }); + } + // [{ + // label: 'a', + // data: [8, 3, 9, 2, 7, 4, 2] + // }, { + // label: 'b', + // data: [6, 4, 5, 5, 9, 6, 3] + // }, { + // label: 'c', + // data: [5, 2, 3, 6, 4, 8, 6] + // }] + +{/literal} {include file="sections/footer.tpl"} \ No newline at end of file diff --git a/version.json b/version.json index 56b6712..89ba0a9 100644 --- a/version.json +++ b/version.json @@ -1,3 +1,3 @@ { - "version": "2024.8.9.1" + "version": "2024.8.13" } \ No newline at end of file