Merge branch 'refs/heads/master' into Issue_2494
Conflicts: include/controllers/default/cockpit/charts/community.php
This commit is contained in:
commit
fc0d053b3d
@ -7,28 +7,53 @@ class Controller_charts_community extends Crunchbutton_Controller_Account {
|
||||
return ;
|
||||
}
|
||||
|
||||
$hasPermissionFullPermission = c::admin()->permission()->check( [ 'global', 'metrics-all', 'metrics-communities-all' ] );
|
||||
switch ( c::getPagePiece( 2 ) ) {
|
||||
case 'delivery-tips':
|
||||
$this->data();
|
||||
c::view()->display( 'charts/community/delivery_tips' );
|
||||
break;
|
||||
|
||||
case 'orders-per-day':
|
||||
|
||||
$hasPermissionFullPermission = c::admin()->permission()->check( [ 'global', 'metrics-all', 'metrics-communities-all' ] );
|
||||
$communities = Crunchbutton_Community::q( 'SELECT * FROM community ORDER BY name ASC' );
|
||||
|
||||
$communities = Crunchbutton_Community::q( 'SELECT * FROM community ORDER BY name ASC' );
|
||||
|
||||
if( !$hasPermissionFullPermission ){
|
||||
$_communities = [];
|
||||
foreach ( $communities as $community ) {
|
||||
$permission_name = strtolower( $community->name );
|
||||
$permission_name = str_replace( ' ' , '-', $permission_name );
|
||||
$permission_name = "metrics-communities-{$permission_name}";
|
||||
if( c::admin()->permission()->check( [ $permission_name ] ) ){
|
||||
$_communities[] = $community;
|
||||
if( !$hasPermissionFullPermission ){
|
||||
$_communities = [];
|
||||
foreach ( $communities as $community ) {
|
||||
$permission_name = strtolower( $community->name );
|
||||
$permission_name = str_replace( ' ' , '-', $permission_name );
|
||||
$permission_name = "metrics-communities-{$permission_name}";
|
||||
if( c::admin()->permission()->check( [ $permission_name ] ) ){
|
||||
$_communities[] = $community;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$_communities = $communities;
|
||||
}
|
||||
}
|
||||
$communities = $_communities;
|
||||
}
|
||||
c::view()->communities = $communities;
|
||||
c::view()->communities = $_communities;
|
||||
c::view()->display( 'charts/community/orders_per_day' );
|
||||
break;
|
||||
|
||||
if( c::getPagePiece( 2 ) == 'delivery-tips' ){
|
||||
c::view()->display( 'charts/community/delivery_tips' );
|
||||
} else {
|
||||
c::view()->display( 'charts/community/index' );
|
||||
default:
|
||||
$this->data();
|
||||
c::view()->display( 'charts/community/index' );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public function data(){
|
||||
$hasPermissionFullPermission = c::admin()->permission()->check( [ 'global', 'metrics-all', 'metrics-communities-all' ] );
|
||||
$communities = Restaurant::getCommunitiesWithRestaurantsNumber();
|
||||
$_communities = [];
|
||||
foreach ( $communities as $community ) {
|
||||
$permission_name = strtolower( $community->community );
|
||||
$permission_name = str_replace( ' ' , '-', $permission_name );
|
||||
$permission_name = "metrics-communities-{$permission_name}";
|
||||
if( $hasPermissionFullPermission || c::admin()->permission()->check( [ $permission_name ] ) ){
|
||||
$_communities[] = $community;
|
||||
}
|
||||
}
|
||||
c::view()->communities = $communities;
|
||||
}
|
||||
}
|
||||
@ -32,6 +32,13 @@ class Crunchbutton_Chart_Order extends Crunchbutton_Chart {
|
||||
'orders-repeat-per-active-user-per-month' => array( 'title' => 'Month', 'interval' => 'month', 'type' => 'column', 'method' => 'repeatByActiveuserByMonth', 'filters' => array( array( 'title' => 'Community', 'type' => 'community', 'method' => 'repeatByActiveuserByMonthByCommunity' ) ) )
|
||||
)
|
||||
),
|
||||
'group-orders-per-day-per-community' => array(
|
||||
'title' => 'Orders per Day By Community',
|
||||
'tags' => array( 'especial' ),
|
||||
'charts' => array(
|
||||
'orders-per-day-per-community' => array( 'title' => 'Last 14 Days', 'interval' => 'day', 'type' => 'column', 'method' => 'byDayPerCommunitySelective' ),
|
||||
)
|
||||
),
|
||||
/*
|
||||
'group-orders-repeat' => array(
|
||||
'title' => 'Repeat Orders',
|
||||
@ -448,6 +455,79 @@ public function byDayPerRestaurant( $render = false ){
|
||||
return $parsedData;
|
||||
}
|
||||
|
||||
public function byDayPerCommunitySelective(){
|
||||
|
||||
$communities = $_REQUEST[ 'communities' ];
|
||||
$communities = explode( ',' , $communities );
|
||||
|
||||
if( count( $communities ) == 0 ){
|
||||
echo 'Please select one or more communities';
|
||||
}
|
||||
|
||||
$where = ' AND ( ';
|
||||
$or = '';
|
||||
foreach ( $communities as $community ) {
|
||||
$where .= $or . " c.id_community = '{$community}'";
|
||||
$or = ' OR ';
|
||||
}
|
||||
$where .= ' ) ';
|
||||
|
||||
$now = new DateTime( 'now', new DateTimeZone( c::config()->timezone ) );
|
||||
$this->dayTo = $now->format( 'Y-m-d' );
|
||||
$now->modify( '- 14 day' );
|
||||
$this->dayFrom = $now->format( 'Y-m-d' );
|
||||
|
||||
$query = "SELECT DATE_FORMAT( date ,'%Y-%m-%d') AS Day,
|
||||
COUNT(*) AS Total,
|
||||
c.name AS `Group`
|
||||
FROM `order` o
|
||||
INNER JOIN restaurant r ON r.id_restaurant = o.id_restaurant
|
||||
INNER JOIN restaurant_community rc ON r.id_restaurant = rc.id_restaurant
|
||||
INNER JOIN community c ON c.id_community = rc.id_community AND c.name NOT LIKE 'test%'
|
||||
WHERE o.date >= '{$this->dayFrom}' AND o.date <= '{$this->dayTo}'
|
||||
{$this->queryExcludeUsers}
|
||||
{$where}
|
||||
GROUP BY DATE_FORMAT( date ,'%Y-%m-%d'), c.name
|
||||
ORDER BY DATE_FORMAT( date ,'%Y-%m-%d') DESC";
|
||||
|
||||
$data = c::db()->get( $query );
|
||||
|
||||
$_days = [];
|
||||
|
||||
foreach ( $data as $item ) {
|
||||
$_days[ $item->Day ][ $item->Group ] = $item->Total;
|
||||
}
|
||||
|
||||
$data = [];
|
||||
|
||||
// Get the communities
|
||||
$query = "SELECT DISTINCT( c.name ) AS community FROM community c WHERE 1 = 1 $where";
|
||||
$results = c::db()->get( $query );
|
||||
$communities = array();
|
||||
foreach ( $results as $result ) {
|
||||
if( !$result->community ){
|
||||
continue;
|
||||
}
|
||||
$communities[] = $result->community;
|
||||
}
|
||||
|
||||
$groups = $communities;
|
||||
|
||||
// echo '<pre>';var_dump( $this->from_day );exit();
|
||||
|
||||
$allDays = $this->allDays();
|
||||
|
||||
for( $i = 0; $i < 14; $i++ ){
|
||||
$now->modify( '+ 1 day' );
|
||||
$day = $now->format( 'Y-m-d' );
|
||||
foreach( $groups as $group ){
|
||||
$total = ( $_days[ $day ][ $group ] ) ? $_days[ $day ][ $group ] : 0;
|
||||
$data[] = ( object ) array( 'Label' => $this->parseDay( $day ), 'Total' => $total, 'Type' => $group );
|
||||
}
|
||||
}
|
||||
return array( 'data' => $data, 'unit' => $this->unit, 'interval' => 'day' );
|
||||
}
|
||||
|
||||
public function byDayPerCommunity( $render = false, $_community = false ){
|
||||
|
||||
$community = ( $_REQUEST[ 'community' ] ) ? $_REQUEST[ 'community' ] : false;
|
||||
|
||||
@ -36,6 +36,9 @@
|
||||
<div>
|
||||
<a href="/charts/community/delivery-tips">
|
||||
Delivery fees + Tips Graphs
|
||||
</a> |
|
||||
<a href="/charts/community/orders-per-day">
|
||||
Orders per Day By Community - Last 14 Days
|
||||
</a>
|
||||
</div>
|
||||
<hr/>
|
||||
|
||||
@ -0,0 +1,61 @@
|
||||
<?
|
||||
$this->title = 'Community metrics';
|
||||
$this->subtitle = 'Crunchbutton overview';
|
||||
$this->titleicon = 'bar-chart';
|
||||
|
||||
$communities = $this->communities;
|
||||
|
||||
?>
|
||||
<div class="container-fluid padded">
|
||||
<div class="box">
|
||||
<div class="box-header">
|
||||
<span class="title">Select the communities</span>
|
||||
</div>
|
||||
<div class="box-content padded">
|
||||
<div class="row-fluid">
|
||||
<h3>Communities</h3>
|
||||
|
||||
<?php foreach( $communities as $community ) { ?>
|
||||
<div class="span4">
|
||||
<div>
|
||||
<input type="checkbox"
|
||||
class="icheck"
|
||||
value="<?php echo $community->id_community;?>"
|
||||
id="checkbox-<?php echo $community->id_community;?>"
|
||||
community="<?php echo $community->id_community;?>"
|
||||
name="checkbox-<?php echo $community->id_community;?>">
|
||||
<label for="checkbox-<?php echo $community->id_community;?>"><?php echo $community->name; ?></label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<hr/>
|
||||
<div id="chart"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
|
||||
$( document ).ready( function(){
|
||||
$( '.icheck' ).on( 'ifChanged', function( event ){
|
||||
$( '#chart' ).html( '<i class="icon-spinner icon-spin"></i> Loading </div>' );
|
||||
var communities = [];
|
||||
$( 'input[type=checkbox]' ).each( function( ){
|
||||
var checkbox = $( this );
|
||||
if( checkbox.is( ':checked' ) ){
|
||||
communities.push( checkbox.val() );
|
||||
}
|
||||
} );
|
||||
var url = '/home/charts/orders-per-day-per-community/?communities=' + communities.toString();
|
||||
$.ajax( { url: url, } ).done( function( data ) { $( '#chart' ).html( data ); } );
|
||||
|
||||
} );
|
||||
|
||||
} );
|
||||
|
||||
</script>
|
||||
<style type="text/css">
|
||||
#options-{ display: none;}
|
||||
</style>
|
||||
@ -22,6 +22,10 @@
|
||||
<br/><br/><br/>
|
||||
<a class="btn btn-default" href="/community/report/">
|
||||
<i class="icon-cloud-download"></i> Report (orders for the past 14 days by community)</a>
|
||||
|
||||
<a class="btn btn-default" href="/charts/community/orders-per-day">
|
||||
<i class="icon-bar-chart"></i> Chart: Orders per Day By Community - Last 14 Days
|
||||
</a>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1127,7 +1127,7 @@ p {
|
||||
width: 29.7em;
|
||||
height: 12em;
|
||||
border-radius: 4px;
|
||||
padding: 2px;
|
||||
padding: 2px 2px .2em 2px;
|
||||
display: inline-block;
|
||||
|
||||
margin-bottom: 2px;
|
||||
@ -1143,6 +1143,7 @@ p {
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@media screen and (min-width: 1025px) {
|
||||
.restaurants-item .restaurants-open:hover {
|
||||
border: 1px solid #f78256;
|
||||
@ -1169,8 +1170,8 @@ p {
|
||||
}
|
||||
.restaurants-pic {
|
||||
height: 8em;
|
||||
border-top-left-radius:1px;
|
||||
border-top-right-radius:1px;
|
||||
border-top-left-radius:.2em;
|
||||
border-top-right-radius:.2em;
|
||||
overflow:hidden;
|
||||
background-size:cover !important;
|
||||
background-position: center center !important;
|
||||
@ -1225,6 +1226,44 @@ p {
|
||||
background: #d44235;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@media screen and (min-width: 740px) {
|
||||
.restaurants-item .restaurants-open {
|
||||
width: 25.5em;
|
||||
height: 16.2em;
|
||||
border-radius: 6px;
|
||||
}
|
||||
.restaurants-pic {
|
||||
height: 12em;
|
||||
border-top-left-radius:4px;
|
||||
border-top-right-radius:4px;
|
||||
}
|
||||
.restaurants-item-content {
|
||||
height: 16em;
|
||||
}
|
||||
.restaurants-open .restaurants-name {
|
||||
font-size: 1.3em;
|
||||
padding-bottom: .15em;
|
||||
}
|
||||
.restaurants-item {
|
||||
margin: 0 7px 12px 7px ;
|
||||
}
|
||||
.restaurants-closed {
|
||||
border-radius: 5px;
|
||||
width: 23.4em;
|
||||
}
|
||||
.meal-item-closed:first-child:before {
|
||||
content: " ";
|
||||
display: block;
|
||||
height: 20px;
|
||||
width: 20px;
|
||||
background: green;
|
||||
border: 2px solid green;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
.meal-item-tag {
|
||||
background: #00bd9e;
|
||||
box-shadow: 0 2px 0 #018872;
|
||||
|
||||
@ -428,8 +428,9 @@ NGApp.controller( 'LocationCtrl', function ($scope, $http, $location, $rootScope
|
||||
if ( $scope.location.form.address == '' ) {
|
||||
var locSpin = $( '.location-detect' ).data( 'spinner' );
|
||||
locSpin.start();
|
||||
$scope.location.getLocationByBrowser( function(loc) {
|
||||
locSpin.stop();
|
||||
$scope.location.getLocationByBrowser(
|
||||
// Success, got location
|
||||
function(loc) {
|
||||
// As it should return a new loc we can remove the previous geolocation
|
||||
// that way we don't have two equals location
|
||||
$scope.location.position.removeNotServedLocation();
|
||||
@ -441,9 +442,9 @@ NGApp.controller( 'LocationCtrl', function ($scope, $http, $location, $rootScope
|
||||
proceed,
|
||||
// Error not served
|
||||
function(){
|
||||
var error = function(){
|
||||
locSpin.stop();
|
||||
$scope.$broadcast( 'locationNotServed' );
|
||||
var error = function() {
|
||||
locSpin.stop();
|
||||
$scope.$broadcast( 'locationNotServed' );
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user