partial #1447
This commit is contained in:
parent
2bd9a6d438
commit
4d453bd39c
@ -3,7 +3,7 @@
|
||||
class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
|
||||
public $activeUsersInterval = 45; // Days
|
||||
public $queryIncludeCommunties = 'AND c.id_community IN (1, 4)';
|
||||
public $queryOnlyCommunties = 'AND c.id_community IN (1, 4)';
|
||||
public $queryExcludeCommunties = "AND c.name != 'Testing' AND c.name IS NOT NULL";
|
||||
public $queryExcludeUsers = "AND o.name NOT LIKE '%test%' and o.name != 'Judd' and o.name != 'dave' and o.name != 'Nick' and o.name != 'Devin'";
|
||||
|
||||
@ -11,6 +11,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
|
||||
$chart = c::getPagePiece(2);
|
||||
$title = c::getPagePiece(3);
|
||||
$number = c::getPagePiece(4);
|
||||
|
||||
switch ( $chart ) {
|
||||
|
||||
@ -54,6 +55,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -90,7 +92,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
WHERE o.date <= STR_TO_DATE('{$week} Saturday', '%X%V %W')
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY u.phone HAVING orders = 1) Orders
|
||||
WHERE Orders.date BETWEEN STR_TO_DATE('{$week} Sunday', '%X%V %W') AND STR_TO_DATE('{$week} Saturday', '%X%V %W')
|
||||
GROUP BY Orders.name";
|
||||
@ -101,6 +103,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -145,6 +148,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -212,6 +216,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -256,7 +261,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
AND o.date >= STR_TO_DATE('{$week} Saturday', '%X%V %W') - INTERVAL {$this->activeUsersInterval} DAY
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY u.phone) ActiveUsers
|
||||
GROUP BY Community) ActiveUsers
|
||||
LEFT JOIN
|
||||
@ -275,7 +280,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
WHERE o.date <= STR_TO_DATE('{$week} Saturday', '%X%V %W')
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY u.phone HAVING orders = 1) Orders
|
||||
WHERE Orders.date BETWEEN STR_TO_DATE('{$week} Sunday', '%X%V %W') AND STR_TO_DATE('{$week} Saturday', '%X%V %W')
|
||||
GROUP BY Orders.name ) NewUsers ON NewUsers.Label = ActiveUsers.Label
|
||||
@ -289,6 +294,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -325,7 +331,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
AND o.date >= STR_TO_DATE('{$week} Saturday', '%X%V %W') - INTERVAL {$this->activeUsersInterval} DAY
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY u.phone) ActiveUsers
|
||||
GROUP BY ActiveUsers.name";
|
||||
$union = ' UNION ';
|
||||
@ -335,6 +341,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -371,7 +378,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
AND o.date >= STR_TO_DATE('{$week} Saturday', '%X%V %W') - INTERVAL {$this->activeUsersInterval} DAY
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY u.phone) ActiveUsers";
|
||||
$union = ' UNION ';
|
||||
$count++;
|
||||
@ -406,6 +413,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => $data,
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'active users lost',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -422,13 +430,14 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
WHERE o.date BETWEEN CURDATE() - INTERVAL {$this->activeUsersInterval} DAY AND CURDATE()
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY o.id_community";
|
||||
|
||||
c::view()->display('charts/pie', ['set' => [
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => 'Active users per community',
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -449,7 +458,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
WHERE YEARWEEK(o.date) >= {$actual}
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
{$this->queryIncludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
GROUP BY YEARWEEK(o.date),
|
||||
o.id_community
|
||||
ORDER BY YEARWEEK(o.date) DESC";
|
||||
@ -457,6 +466,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'ignoreWeekSum' => true,
|
||||
@ -483,7 +493,8 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
c::view()->display('charts/column', ['set' => [
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => 'Unique users per week',
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'users',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'weeks' => $weeks,
|
||||
@ -512,6 +523,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'orders',
|
||||
'ignoreWeekSum' => true,
|
||||
'maxWeeks' => $maxWeeks,
|
||||
@ -540,6 +552,66 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'orders',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'ignoreWeekSum' => true,
|
||||
'weeks' => $weeks,
|
||||
]]);
|
||||
break;
|
||||
|
||||
case 'orders-per-week-by-community':
|
||||
$maxMinWeeks = $this->maxMinWeeks();
|
||||
$maxWeeks = sizeof( $maxMinWeeks );
|
||||
$weeks = ( $_REQUEST[ 'weeks' ] ? $_REQUEST[ 'weeks' ] : $maxWeeks );
|
||||
$actual = $maxMinWeeks[ ( $weeks >= $maxWeek ? ( $weeks - 1 ) : $weeks ) ];
|
||||
$query = "SELECT CONCAT('Week ', YEARWEEK(date)) AS `week`,
|
||||
COUNT(*) AS Orders,
|
||||
c.name AS 'Community'
|
||||
FROM `order` o
|
||||
INNER JOIN user u ON u.id_user = o.id_user
|
||||
LEFT JOIN community c ON o.id_community = c.id_community
|
||||
WHERE YEARWEEK(o.date) >= {$actual}
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryOnlyCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
GROUP BY YEARWEEK(date), c.name
|
||||
ORDER BY YEARWEEK(date) DESC";
|
||||
|
||||
c::view()->display('charts/column', ['set' => [
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'orders',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'ignoreWeekSum' => true,
|
||||
'weeks' => $weeks,
|
||||
]]);
|
||||
break;
|
||||
|
||||
case 'orders-using-giftcard-per-week':
|
||||
$maxMinWeeks = $this->maxMinWeeks();
|
||||
$maxWeeks = sizeof( $maxMinWeeks );
|
||||
$weeks = ( $_REQUEST[ 'weeks' ] ? $_REQUEST[ 'weeks' ] : $maxWeeks );
|
||||
$actual = $maxMinWeeks[ ( $weeks >= $maxWeek ? ( $weeks - 1 ) : $weeks ) ];
|
||||
$query = "SELECT CONCAT('Week ', YEARWEEK(date)) AS `week`,
|
||||
COUNT(*) AS Orders,
|
||||
'Orders' AS label
|
||||
FROM `order` o
|
||||
INNER JOIN user u ON u.id_user = o.id_user
|
||||
LEFT JOIN community c ON o.id_community = c.id_community
|
||||
WHERE YEARWEEK(o.date) >= {$actual}
|
||||
{$this->queryExcludeCommunties}
|
||||
{$this->queryExcludeUsers}
|
||||
GROUP BY YEARWEEK(date)
|
||||
ORDER BY YEARWEEK(date) DESC";
|
||||
echo $query ;exit;
|
||||
c::view()->display('charts/column', ['set' => [
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'orders',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'ignoreWeekSum' => true,
|
||||
@ -566,6 +638,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => '',
|
||||
'maxWeeks' => $maxWeeks,
|
||||
'ignoreWeekSum' => true,
|
||||
@ -591,6 +664,7 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
|
||||
'chartId' => $chart,
|
||||
'data' => c::db()->get( $query ),
|
||||
'title' => $title,
|
||||
'number' => $number,
|
||||
'unit' => 'orders',
|
||||
]]);
|
||||
break;
|
||||
|
||||
@ -47,9 +47,16 @@ class Controller_home extends Crunchbutton_Controller_Account {
|
||||
'orders-by-user-week' => 'Orders by Users per Week',
|
||||
'orders-per-week' => 'Orders per Week',
|
||||
'gross-revenue' => 'Gross Revenue',
|
||||
'orders-by-weekday-by-community' => 'Orders by Weekday by Community',
|
||||
'active-users-by-community' => 'Active users by community',
|
||||
),
|
||||
'Tracking Marketing Efforts' => array(
|
||||
'active-users-per-week' => 'Active Users per Week',
|
||||
'active-users-by-community' => 'Active users by community',
|
||||
'orders-by-weekday-by-community' => 'Orders by Weekday by Community',
|
||||
'orders-per-week' => 'Orders per Week',
|
||||
'orders-per-week-by-community' => 'Orders per Week by Community',
|
||||
// 'orders-using-giftcard-per-week' => 'Orders using Gift Card per Week',
|
||||
),
|
||||
);
|
||||
|
||||
c::view()->graphs = $graphs;
|
||||
|
||||
@ -80,21 +80,21 @@
|
||||
<h4 style="text-align:center;"><?php echo $title; ?></h4>
|
||||
</div>
|
||||
</div>
|
||||
<div id="chart-<?=$chartId?>" style="min-width: 100%; height:300px; margin: 0 auto"></div>
|
||||
<div id="chart-<?=$chartId?>-<?php echo $number; ?>" style="min-width: 100%; height:300px; margin: 0 auto"></div>
|
||||
<br/>
|
||||
<div class="row-fluid">
|
||||
<div class="span3" id="week-<?=$chartId?>">
|
||||
<div class="span3" id="week-<?=$chartId?>-<?php echo $number; ?>">
|
||||
<!-- Week <?php echo $weeks; ?> of <?php echo $maxWeeks; ?>: -->
|
||||
</div>
|
||||
<div class="span8">
|
||||
<div id="slider-<?=$chartId?>"></div>
|
||||
<div id="slider-<?=$chartId?>-<?php echo $number; ?>"></div>
|
||||
</div>
|
||||
</div>
|
||||
<hr />
|
||||
<script type="text/javascript">
|
||||
$(function () {
|
||||
var data = <?=json_encode($jsData, JSON_NUMERIC_CHECK)?>;
|
||||
$('#chart-<?=$chartId?>').highcharts({
|
||||
$('#chart-<?=$chartId?>-<?php echo $number; ?>').highcharts({
|
||||
chart: {
|
||||
type: 'column',
|
||||
backgroundColor:'rgba(255, 255, 255, 0.1)'
|
||||
@ -140,16 +140,15 @@ $(function () {
|
||||
},
|
||||
series: data.ys
|
||||
});
|
||||
$("#slider-<?=$chartId?>").slider({
|
||||
$("#slider-<?=$chartId?>-<?php echo $number; ?>").slider({
|
||||
range: "min",
|
||||
min: 1,
|
||||
max: <?php echo $maxWeeks; ?>,
|
||||
value: <?php echo $weeks; ?>,
|
||||
change: function( event, ui ) {
|
||||
$( '#week-<?=$chartId?>' ).html( '<i class="icon-spinner icon-spin"></i> Loading: <?php echo $title; ?>' );
|
||||
var self = $( '#<?=$chartId?>' );
|
||||
var id = self.attr( 'id' );
|
||||
var url = '/home/charts/' + id + '/<?php echo $title; ?>?weeks=' + ui.value;
|
||||
$( '#week-<?=$chartId?>-<?php echo $number; ?>' ).html( '<i class="icon-spinner icon-spin"></i> Loading: <?php echo $title; ?>' );
|
||||
var self = $( '#<?=$chartId?>-<?php echo $number; ?>' );
|
||||
var url = '/home/charts/<?=$chartId?>/<?php echo $title; ?>/<?php echo $number; ?>/?weeks=' + ui.value;
|
||||
$.ajax( { url: url, }).done(function( data ) { self.html( data ); } );
|
||||
}
|
||||
});
|
||||
|
||||
@ -128,20 +128,23 @@
|
||||
</div>
|
||||
<div class="box-content padded">
|
||||
<?php
|
||||
$chart_count_checkbox = 0;
|
||||
$chart_count_div = 0;
|
||||
foreach ($this->graphs as $category => $graphs ){
|
||||
?>
|
||||
|
||||
<h5><?php echo $category; ?></h5><?php
|
||||
$count = 1;
|
||||
foreach ($graphs as $id => $graph ){
|
||||
$chart_count_checkbox++;
|
||||
if( $count == 1 ){
|
||||
echo '<div class="row-fluid">';
|
||||
}
|
||||
?>
|
||||
<div class="span4">
|
||||
<div>
|
||||
<input type="checkbox" class="icheck" id="checkbox-<?php echo $id;?>" data-id="<?php echo $id;?>" data-title="<?php echo $graph;?>" name="checkbox-<?php echo $id;?>">
|
||||
<label for="checkbox-<?php echo $id;?>"><?php echo $graph; ?></label>
|
||||
<input type="checkbox" class="icheck" id="checkbox-<?php echo $id;?>-<?php echo $chart_count_checkbox; ?>" data-id="<?php echo $id;?>" data-count="<?php echo $chart_count_checkbox; ?>" data-title="<?php echo $graph;?>" name="checkbox-<?php echo $id;?>">
|
||||
<label for="checkbox-<?php echo $id;?>-<?php echo $chart_count_checkbox; ?>"><?php echo $graph; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
<?
|
||||
@ -158,7 +161,8 @@
|
||||
<hr/>
|
||||
<?
|
||||
foreach ($graphs as $id => $graph ){
|
||||
echo '<div id="' . $id . '" class="chart" style="display:none;"><i class="icon-spinner icon-spin"></i> Loading: ' . $graph . '</div>';
|
||||
$chart_count_div++;
|
||||
echo '<div id="' . $id . '-' . $chart_count_div .'" class="chart" style="display:none;"><i class="icon-spinner icon-spin"></i> Loading: ' . $graph . '</div>';
|
||||
} ?>
|
||||
|
||||
<?php
|
||||
@ -172,13 +176,14 @@
|
||||
$( '.icheck' ).on( 'ifChanged', function( event ){
|
||||
var check = $(this);
|
||||
var id = check.attr( 'data-id' );
|
||||
var chart = $( '#' + id );
|
||||
var count = check.attr( 'data-count' );
|
||||
var chart = $( '#' + id + '-' + count );
|
||||
var title = check.attr( 'data-title' );
|
||||
if( check.is( ':checked' ) ){
|
||||
chart.show();
|
||||
if( !chart.attr( 'loaded' ) ){
|
||||
chart.attr( 'loaded', true );
|
||||
var url = '/home/charts/' + id + '/' + title;
|
||||
/*chart.attr( 'loaded', true ); */
|
||||
var url = '/home/charts/' + id + '/' + title + '/' + count;
|
||||
$.ajax( { url: url, }).done( function( data ) { chart.html( data ); } );
|
||||
}
|
||||
} else {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user