graph report
This commit is contained in:
parent
6765a6b17c
commit
5e080f18fe
@ -21,6 +21,137 @@ $before_30_days = date('Y-m-d', strtotime('today - 30 days'));
|
|||||||
$month_n = date('n');
|
$month_n = date('n');
|
||||||
|
|
||||||
switch ($action) {
|
switch ($action) {
|
||||||
|
case 'ajax':
|
||||||
|
$data = $routes['2'];
|
||||||
|
$reset_day = $config['reset_day'];
|
||||||
|
if (empty($reset_day)) {
|
||||||
|
$reset_day = 1;
|
||||||
|
}
|
||||||
|
//first day of month
|
||||||
|
if (date("d") >= $reset_day) {
|
||||||
|
$start_date = date('Y-m-' . $reset_day);
|
||||||
|
} else {
|
||||||
|
$start_date = date('Y-m-' . $reset_day, strtotime("-1 MONTH"));
|
||||||
|
}
|
||||||
|
$sd = _req('sd', $start_date);
|
||||||
|
$ed = _req('ed', $mdate);
|
||||||
|
$ts = _req('ts', '00:00:00');
|
||||||
|
$te = _req('te', '23:59:59');
|
||||||
|
$types = ORM::for_table('tbl_transactions')->getEnum('type');
|
||||||
|
$tps = ($_GET['tps']) ? $_GET['tps'] : $types;
|
||||||
|
$plans = array_column(ORM::for_table('tbl_transactions')->select('plan_name')->distinct('plan_name')->find_array(), 'plan_name');
|
||||||
|
$plns = ($_GET['plns']) ? $_GET['plns'] : $plans;
|
||||||
|
$methods = array_column(ORM::for_table('tbl_transactions')->rawQuery("SELECT DISTINCT SUBSTRING_INDEX(`method`, ' - ', 1) as method FROM tbl_transactions;")->findArray(), 'method');
|
||||||
|
$mts = ($_GET['mts']) ? $_GET['mts'] : $methods;
|
||||||
|
$routers = array_column(ORM::for_table('tbl_transactions')->select('routers')->distinct('routers')->find_array(), 'routers');
|
||||||
|
$rts = ($_GET['rts']) ? $_GET['rts'] : $routers;
|
||||||
|
$result = [];
|
||||||
|
switch ($data) {
|
||||||
|
case 'type':
|
||||||
|
foreach ($tps as $tp) {
|
||||||
|
$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"))
|
||||||
|
->where('type', $tp);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
$count = $query->count();
|
||||||
|
if ($count > 0) {
|
||||||
|
$result['datas'][] = $count;
|
||||||
|
$result['labels'][] = "$tp ($count)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'plan':
|
||||||
|
foreach ($plns as $pln) {
|
||||||
|
$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"))
|
||||||
|
->where('plan_name', $pln);
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
$count = $query->count();
|
||||||
|
if ($count > 0) {
|
||||||
|
$result['datas'][] = $count;
|
||||||
|
$result['labels'][] = "$pln ($count)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'method':
|
||||||
|
foreach ($mts as $mt) {
|
||||||
|
$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"))
|
||||||
|
->where_like('method', "$mt - %");
|
||||||
|
if (count($tps) > 0) {
|
||||||
|
$query->where_in('type', $tps);
|
||||||
|
}
|
||||||
|
if (count($rts) > 0) {
|
||||||
|
$query->where_in('routers', $rts);
|
||||||
|
}
|
||||||
|
if (count($plns) > 0) {
|
||||||
|
$query->where_in('plan_name', $plns);
|
||||||
|
}
|
||||||
|
if (count($mts) > 0) {
|
||||||
|
if (count($mts) != count($methods)) {
|
||||||
|
foreach ($mts as $mt) {
|
||||||
|
$query->where_like('method', "$mt - %");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$count = $query->count();
|
||||||
|
if ($count > 0) {
|
||||||
|
$result['datas'][] = $count;
|
||||||
|
$result['labels'][] = "$mt ($count)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'router':
|
||||||
|
foreach ($rts as $rt) {
|
||||||
|
$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"))
|
||||||
|
->where('routers', $rt);
|
||||||
|
if (count($tps) > 0) {
|
||||||
|
$query->where_in('type', $tps);
|
||||||
|
}
|
||||||
|
if (count($plns) > 0) {
|
||||||
|
$query->where_in('plan_name', $plns);
|
||||||
|
}
|
||||||
|
$count = $query->count();
|
||||||
|
if ($count > 0) {
|
||||||
|
$result['datas'][] = $count;
|
||||||
|
$result['labels'][] = "$rt ($count)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
$result = ['labels' => [], 'datas' => []];
|
||||||
|
}
|
||||||
|
echo json_encode($result);
|
||||||
|
die();
|
||||||
case 'by-date':
|
case 'by-date':
|
||||||
case 'activation':
|
case 'activation':
|
||||||
$q = (_post('q') ? _post('q') : _get('q'));
|
$q = (_post('q') ? _post('q') : _get('q'));
|
||||||
|
@ -47,14 +47,30 @@
|
|||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-lg-9">
|
<div class="col-lg-9">
|
||||||
|
<div class="box box-primary box-solid">
|
||||||
|
<div class="box-body row">
|
||||||
|
<div class="col-md-3 col-xs-6">
|
||||||
|
<canvas id="cart_type"></canvas>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 col-xs-6">
|
||||||
|
<canvas id="cart_plan"></canvas>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 col-xs-6">
|
||||||
|
<canvas id="cart_method"></canvas>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-3 col-xs-6">
|
||||||
|
<canvas id="cart_router"></canvas>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="box box-primary box-solid">
|
<div class="box box-primary box-solid">
|
||||||
<div class="table-responsive">
|
<div class="table-responsive">
|
||||||
<table class="table table-bordered table-condensed">
|
<table class="table table-bordered table-condensed">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>
|
<th>
|
||||||
<a href="{$_url}export/print-by-date&{$filter}" class="btn btn-default" target="_blank"><i
|
<a href="{$_url}export/print-by-date&{$filter}" class="btn btn-default"
|
||||||
class="ion ion-printer"></i></a>
|
target="_blank"><i class="ion ion-printer"></i></a>
|
||||||
<a href="{$_url}export/pdf-by-date&{$filter}" class="btn btn-default"><i
|
<a href="{$_url}export/pdf-by-date&{$filter}" class="btn btn-default"><i
|
||||||
class="fa fa-file-pdf-o"></i></a>
|
class="fa fa-file-pdf-o"></i></a>
|
||||||
</th>
|
</th>
|
||||||
@ -95,7 +111,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="box-footer">
|
<div class="box-footer">
|
||||||
<p class="text-center small text-info">{Lang::T('All Transactions at Date')}:
|
<p class="text-center small text-info">{Lang::T('All Transactions at Date')}:
|
||||||
{Lang::dateAndTimeFormat($sd, $ts)} - {Lang::dateAndTimeFormat($ed, $te)}</p>
|
{Lang::dateAndTimeFormat($sd, $ts)} - {Lang::dateAndTimeFormat($ed, $te)}</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@ -108,6 +124,9 @@
|
|||||||
<p>Export and Print will show all data without pagination.</p>
|
<p>Export and Print will show all data without pagination.</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chart.js@3.5.1/dist/chart.min.js"></script>
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/chartjs-plugin-autocolors"></script>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
var isShow = false;
|
var isShow = false;
|
||||||
|
|
||||||
@ -125,6 +144,54 @@
|
|||||||
isShow = true;
|
isShow = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
const autocolors = window['chartjs-plugin-autocolors'];
|
||||||
|
Chart.register(autocolors);
|
||||||
|
var options = {
|
||||||
|
responsive: true,
|
||||||
|
aspectRatio: 1,
|
||||||
|
plugins: {
|
||||||
|
autocolors: {
|
||||||
|
mode: 'data'
|
||||||
|
},
|
||||||
|
legend: {
|
||||||
|
position: 'bottom',
|
||||||
|
labels: {
|
||||||
|
boxWidth: 15
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
function create_cart(field, labels, datas, options) {
|
||||||
|
new Chart(document.getElementById(field), {
|
||||||
|
type: 'pie',
|
||||||
|
data: {
|
||||||
|
labels: labels,
|
||||||
|
datasets: [{
|
||||||
|
data: datas,
|
||||||
|
borderWidth: 1
|
||||||
|
}]
|
||||||
|
},
|
||||||
|
options: options
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// get cart one by one
|
||||||
|
$.getJSON("{$_url}reports/ajax/type&{$filter}", function( data ) {
|
||||||
|
create_cart('cart_type', data.labels, data.datas, options);
|
||||||
|
$.getJSON("{$_url}reports/ajax/plan&{$filter}", function( data ) {
|
||||||
|
create_cart('cart_plan', data.labels, data.datas, options);
|
||||||
|
$.getJSON("{$_url}reports/ajax/method&{$filter}", function( data ) {
|
||||||
|
create_cart('cart_method', data.labels, data.datas, options);
|
||||||
|
$.getJSON("{$_url}reports/ajax/router&{$filter}", function( data ) {
|
||||||
|
create_cart('cart_router', data.labels, data.datas, options);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{include file="sections/footer.tpl"}
|
{include file="sections/footer.tpl"}
|
Loading…
x
Reference in New Issue
Block a user