This commit is contained in:
pererinha 2013-07-06 16:35:53 -03:00
parent 577a972957
commit 374f6c6c00
9 changed files with 143 additions and 15 deletions

View File

@ -132,6 +132,11 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
$this->renderColumn( $chart->repeatByActiveuserByWeek( true ), $chart->getGroupedCharts() );
break;
case 'orders-per-restaurant-by-community':
$chart = new Crunchbutton_Chart_Order();
$this->renderPieCommunities( $chart->perRestaurantPerCommunity( true ), $chart->getGroupedCharts() );
break;
/* Churn */
case 'churn-rate-per-active-user-per-month':
@ -211,6 +216,18 @@ class Controller_home_charts extends Crunchbutton_Controller_Account {
}
}
private function renderPieCommunities( $params, $groups ){
c::view()->display('charts/pie_communities', ['set' => [
'chartId' => $this->chartId,
'data' => $params[ 'data' ],
'title' => $this->title,
'number' => $this->number,
'unit' => $params[ 'unity' ],
'groups' => $groups,
'divId' => $this->divId
]]);
}
private function renderArea( $params, $groups ){
c::view()->display('charts/area', ['set' => [
'chartId' => $this->chartId,

View File

@ -33,17 +33,14 @@ class Controller_home extends Crunchbutton_Controller_Account {
c::view()->data = $data;
$graphs = array(
'' => array(
// Groups
array( 'divId' => 'chart-orders', 'title-group' => 'Orders', 'chart-url' => 'orders-per-week' ),
array( 'divId' => 'chart-users', 'title-group' => 'Users', 'chart-url' => 'users-new-per-day' ),
array( 'divId' => 'chart-gross', 'title-group' => 'Gross Revenue', 'chart-url' => 'gross-revenue-per-week' ),
array( 'divId' => 'chart-churn', 'title-group' => 'Churn Rate', 'chart-url' => 'churn-rate-per-week' ),
array( 'divId' => 'chart-gift-cards', 'title-group' => 'Gift Cards', 'chart-url' => 'gift-cards-created-per-day' ),
),
// Groups
array( 'divId' => 'chart-orders', 'title-group' => 'Orders', 'chart-url' => 'orders-per-week' ),
array( 'divId' => 'chart-users', 'title-group' => 'Users', 'chart-url' => 'users-new-per-day' ),
array( 'divId' => 'chart-gross', 'title-group' => 'Gross Revenue', 'chart-url' => 'gross-revenue-per-week' ),
array( 'divId' => 'chart-churn', 'title-group' => 'Churn Rate', 'chart-url' => 'churn-rate-per-week' ),
array( 'divId' => 'chart-gift-cards', 'title-group' => 'Gift Cards', 'chart-url' => 'gift-cards-created-per-day' ),
)
);
c::view()->graphs = $graphs;

View File

@ -132,6 +132,19 @@ class Crunchbutton_Chart extends Cana_Model {
return sizeof( $months );
}
public function allCommunities(){
$query = "SELECT DISTINCT( r.community ) AS community FROM restaurant r WHERE r.community IS NOT NULL ORDER BY r.community ASC";
$results = c::db()->get( $query );
$communities = array();
foreach ( $results as $result ) {
if( !$result->community ){
continue;
}
$communities[] = $result->community;
}
return $communities;
}
public function allDays(){
$query = "SELECT DISTINCT( DATE_FORMAT( o.date ,'%Y-%m-%d') ) day FROM `order` o WHERE o.date IS NOT NULL ORDER BY day ASC";
$results = c::db()->get( $query );

View File

@ -15,6 +15,7 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
'orders-per-week-by-community' => 'Orders per Week by Community',
'orders-repeat-per-active-user' => 'Repeat Orders per Active User',
'orders-by-weekday-by-community' => 'Orders by Weekday by Community',
'orders-per-restaurant-by-community' => 'Orders per Restaurant by Community',
)
);
@ -98,7 +99,6 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
{$this->queryExcludeUsers}
GROUP BY YEARWEEK(date), r.community
ORDER BY YEARWEEK(date) DESC";
$parsedData = $this->parseDataWeeksGroup( $query, $this->description );
if( $render ){
return array( 'data' => $parsedData, 'unit' => $this->unity );
@ -106,6 +106,32 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
return $parsedData;
}
public function perRestaurantPerCommunity( $render = false ){
$query = "SELECT
r.name AS Restaurant,
orders.orders AS Total,
r.community AS 'Group'
FROM
(SELECT count(*) AS orders,
o.id_restaurant
FROM `order` o
-- WHERE o.date BETWEEN CURDATE() - INTERVAL 60 DAY AND CURDATE()
GROUP BY o.id_restaurant) orders
INNER JOIN restaurant r ON r.id_restaurant = orders.id_restaurant";
$data = c::db()->get( $query );
$groups = [];
foreach( $data as $item ){
$groups[ $item->Group ][] = array( 'Restaurant' => $item->Restaurant, 'Orders' => $item->Total );
}
if( $render ){
return array( 'data' => $groups, 'unit' => $this->unity );
}
return $data;
}
public function byUsersPerMonth( $render = false ){
$query = "SELECT DATE_FORMAT( o.date ,'%Y-%m') AS Month,

View File

@ -22,7 +22,7 @@ class Crunchbutton_Chart_User extends Crunchbutton_Chart {
'users-new-per-week-by-community' => 'New Users per Week by Community',
'users-new-per-active-users-by-community' => 'New Users per Active Users By Community',
'users-unique-per-week-by-community' => 'Unique Users per Week by Community',
'users-reclaimed-per-week' => 'Reclaimed Users per Week',
'users-reclaimed-per-week' => 'Reclaimed Users per Week'
)
);

View File

@ -81,7 +81,6 @@
'ys' => array_values($ys)
];
}
?>
<div class="row-fluid">
<div class="row-fluid">
@ -103,6 +102,8 @@
<?php if( $hasResults ){ ?>
<div id="chart-<?=$chartId?>" style="min-width: 100%; height:300px; margin: 0 auto"></div>
<br/>
<br/>
<br/>
<div class="row-fluid">
<div class="span3" id="week-<?=$chartId?>">
<?php

View File

@ -0,0 +1,75 @@
<div class="row-fluid">
<div class="row-fluid">
<div class="span12">
<h4 style="text-align:center;">Orders by Restaurant</h4>
</div>
</div>
<?php if( $groups ){ ?>
<span class="pull-right">
<select class="charts-select" id="select-<?=$chartId?>" data-divId="<?php echo $divId; ?>" onchange="loadSubChart( this.id )">
<?php foreach ( $groups as $key => $value ) {
$selected = ( $key == $chartId ) ? 'selected="selected"' : '';
?>
<option <?php echo $selected; ?> value="<?php echo $key; ?>"><?php echo $value; ?></option>
<?php } ?>
</select>
</span>
<?php } ?>
<?
$count = 1;
foreach( $data as $group => $restaurants ){
// $restaurants
$info = '';
foreach( $restaurants as $restaurant ){
$info .= '["' . $restaurant['Restaurant'] . '",' . $restaurant['Orders'] . '],';
}
?>
<div class="span12">
<h5 style="text-align:center;"><?php echo $group; ?></h5>
</div>
<div id="chart-<?=$chartId?><?php echo $count; ?>" style="min-width: 100%; height:300px; margin: 0 auto"></div>
<script type="text/javascript">
$(function () {
var data = <?=json_encode($jsData, JSON_NUMERIC_CHECK)?>;
$('#chart-<?=$chartId?><?php echo $count; ?>').highcharts({
chart: {
plotBackgroundColor: null,
plotBorderWidth: null,
plotShadow: false,
backgroundColor:'rgba(255, 255, 255, 0.1)'
},
title: {
text: ''
},
tooltip: {
pointFormat: '{series.name}: <b>{point.y}</b> ({point.percentage:.1f}%)'
},
plotOptions: {
pie: {
allowPointSelect: true,
cursor: 'pointer',
dataLabels: {
enabled: true,
color: '#000000',
connectorColor: '#000000',
format: '<b>{point.name}</b>: {point.percentage:.1f} %'
}
}
},
series: [{
type: 'pie',
name: 'Orders',
data: [<?php echo $info; ?>]
}]
});
});
</script>
<?php
$count++;
}
?>
</div>
</div>

View File

@ -908,7 +908,6 @@ input:disabled {
height: 450px;
overflow: scroll;
}
#admin-dish-lightning-modal{
background: #FFF;
border: 1px solid #CCC;