<?php
require_once('../wu_init.php');
if (!wu_token()) { exit('wu-error'); }
include('wu_checkadmin.php');
//Исправление бага с шириной графика
sleep(1);
//Рассчёт дней
$qin = mysqli_query($connect_db, "SELECT id,sum(s) AS `s`, YEAR(FROM_UNIXTIME(dt)) AS `iyear`, MONTH(FROM_UNIXTIME(dt)) AS `imonth`, DAY(FROM_UNIXTIME(dt)) AS `iday` FROM `".DB_PREFIX."_adm_profit` GROUP BY iyear,imonth,iday");
$timeline = array();
while($rowi = mysqli_fetch_assoc($qin)) {
if ($rowi['iday'] < 10) { $rowi['iday'] = '0'.$rowi['iday']; }
if ($rowi['imonth'] < 10) { $rowi['imonth'] = '0'.$rowi['imonth']; }
$timeline[$rowi['iday'].'.'.$rowi['imonth'].'.'.$rowi['iyear']]['profit'] = $rowi['s'];
}
//Создание строк
$timeline_e = '';
$iprofit = '';
$iprofit_all = '';
foreach ($timeline as $key => $val)
{
$timeline_e .= "'".$key."', ";
$iprofit .= $timeline[$key]['profit'].", ";
$iprofit_all = $iprofit_all + $timeline[$key]['profit'];
}
$timeline_e = substr($timeline_e,0,-2);
$iprofit = substr($iprofit,0,-2);
if (empty($iprofit_all)) { $iprofit_all = 0; }
$prf = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,adm_profit FROM `".DB_PREFIX."_config` LIMIT 1"));
$exp_week = $dt-604800; $profit_week = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,sum(s) AS `s` FROM `".DB_PREFIX."_adm_profit` WHERE `dt` > '$exp_week'"));
$exp_month = $dt-2678400; $profit_month = mysqli_fetch_assoc(mysqli_query($connect_db, "SELECT id,sum(s) AS `s` FROM `".DB_PREFIX."_adm_profit` WHERE `dt` > '$exp_month'"));
?>
<div class="info-buttons">
<div class="row block">
<div class="col-md-3">
<a href="javascript://"><span class="full_label_content"><?php echo number_format($prf['adm_profit'],2,'.',','); ?> руб.</span> <strong class="label full_label_top label-success">Заработано сегодня</strong></a>
</div>
<div class="col-md-3">
<a href="javascript://"><span class="full_label_content"><?php echo number_format($profit_week['s'],2,'.',','); ?> руб.</span> <strong class="label full_label_top label-warning">Заработано за последнюю неделю</strong></a>
</div>
<div class="col-md-3">
<a href="javascript://"><span class="full_label_content"><?php echo number_format($profit_month['s'],2,'.',','); ?> руб.</span> <strong class="label full_label_top label-info">Заработано за последний месяц</strong></a>
</div>
<div class="col-md-3">
<a href="javascript://"><span class="full_label_content"><?php echo number_format($iprofit_all,2,'.',','); ?> руб.</span> <strong class="label full_label_top label-primary">Заработано всего</strong></a>
</div>
</div>
</div>
<div id="wu-stat"></div>
<script type='text/javascript'>
$('#wu-stat').highcharts({
title: {
text: 'Прибыль системы',
x: -20
},
xAxis: {
title: {
text: 'Дата'
},
categories: [<?php echo $timeline_e; ?>]
},
yAxis: {
title: {
text: 'Руб.'
},
plotLines: [{
value: 0,
width: 1,
color: '#808080'
}]
},
tooltip: {
valueSuffix: ' руб.',
shared: true,
crosshairs: true
},
legend: {
borderWidth: 0
},
series: [{
name: 'Прибыль',
data: [<?php echo $iprofit; ?>]
}
]
});
setTimeout(function() {
$('#wu-stat').highcharts().reflow();
}, 1000);
</script>