created the new users (last users) to reps
This commit is contained in:
parent
64d6738b74
commit
581a4200fc
@ -4,7 +4,8 @@ class Controller_orders_content extends Crunchbutton_Controller_Account {
|
||||
public function init() {
|
||||
|
||||
$restaurant_id = $_REQUEST['restaurant'];
|
||||
if( !c::admin()->permission()->check( [ 'global', 'orders-all', "orders-list-restaurant-{$restaurant_id}" ] ) ){
|
||||
|
||||
if( !c::admin()->permission()->check( [ 'global', 'orders-all', 'orders-list-page', "orders-list-restaurant-{$restaurant_id}" ] ) ){
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
17
include/controllers/default/cockpit/orders/lastusers.php
Normal file
17
include/controllers/default/cockpit/orders/lastusers.php
Normal file
@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
class Controller_orders_lastusers extends Crunchbutton_Controller_Account {
|
||||
public function init() {
|
||||
if (!c::admin()->permission()->check(['global','orders-all','orders-new-users'])) {
|
||||
return ;
|
||||
}
|
||||
if( c::getPagePiece(2) == 'content' ){
|
||||
$limit = c::getPagePiece(3);
|
||||
c::view()->orders = Crunchbutton_Newusers::getLastOnes( $limit );
|
||||
c::view()->layout('layout/ajax');
|
||||
c::view()->display('orders/lastusers/content');
|
||||
exit;
|
||||
}
|
||||
c::view()->display('orders/lastusers/index');
|
||||
}
|
||||
}
|
||||
@ -45,6 +45,34 @@ class Crunchbutton_Admin extends Cana_Table {
|
||||
return array_unique( $restaurants_ids );
|
||||
}
|
||||
|
||||
public function getRestaurantsUserHasPermissionToSeeTheirOrders(){
|
||||
$restaurants_ids = [];
|
||||
$_permissions = new Crunchbutton_Admin_Permission();
|
||||
$all = $_permissions->all();
|
||||
// Get all restaurants permissions
|
||||
$restaurant_permissions = $all[ 'order' ][ 'permissions' ];
|
||||
$permissions = $this->getAllPermissionsName();
|
||||
$restaurants_id = array();
|
||||
foreach ( $permissions as $permission ) {
|
||||
$permission = $permission->permission;
|
||||
$info = $_permissions->getPermissionInfo( $permission );
|
||||
$name = $info[ 'permission' ];
|
||||
foreach( $restaurant_permissions as $restaurant_permission_name => $meta ){
|
||||
if( $restaurant_permission_name == $name ){
|
||||
if( strstr( $name, 'ID' ) ){
|
||||
$regex = str_replace( 'ID' , '((.)*)', $name );
|
||||
$regex = '/' . $regex . '/';
|
||||
preg_match( $regex, $permission, $matches );
|
||||
if( count( $matches ) > 0 ){
|
||||
$restaurants_ids[] = $matches[ 1 ];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return array_unique( $restaurants_ids );
|
||||
}
|
||||
|
||||
public function getPermissionsByGroups(){
|
||||
return c::db()->get( "SELECT ap.*, g.name as group_name FROM admin_permission ap
|
||||
INNER JOIN admin_group ag ON ap.id_group = ap.id_group and ag.id_admin = {$this->id_admin}
|
||||
|
||||
@ -92,6 +92,23 @@ class Crunchbutton_Newusers extends Cana_Table {
|
||||
$config->save();
|
||||
}
|
||||
|
||||
public static function getLastOnes( $limit = 25 ){
|
||||
$hasPermissionToAllRestaurants = c::admin()->permission()->check( [ 'global', 'orders-all' ] );
|
||||
if( !$hasPermissionToAllRestaurants ){
|
||||
$restaurants = c::admin()->getRestaurantsUserHasPermissionToSeeTheirOrders();
|
||||
$where = ' WHERE id_restaurant IN (' . join( $restaurants, ',' ) . ')';
|
||||
}
|
||||
$query = "SELECT *
|
||||
FROM `order` o
|
||||
WHERE id_order IN
|
||||
(SELECT id_order
|
||||
FROM
|
||||
(SELECT count(*) AS orders, id_order, phone, date
|
||||
FROM `order` o
|
||||
GROUP BY phone HAVING orders = 1) orders {$where}) ORDER BY id_order DESC LIMIT {$limit}";
|
||||
return Crunchbutton_Order::q( $query );
|
||||
}
|
||||
|
||||
public static function getNewOnes(){
|
||||
$query = 'SELECT *
|
||||
FROM `order` o
|
||||
|
||||
@ -578,14 +578,22 @@ class Crunchbutton_Order extends Cana_Table {
|
||||
$query .= ' and DATE(`date`)<="'.$s->format('Y-m-d').'" ';
|
||||
}
|
||||
|
||||
$hasPermissionToAllRestaurants = c::admin()->permission()->check( [ 'global', 'orders-all' ] );
|
||||
|
||||
if ($search['restaurant']) {
|
||||
$query .= ' and `order`.id_restaurant="'.$search['restaurant'].'" ';
|
||||
if( $hasPermissionToAllRestaurants || c::admin()->permission()->check( [ "orders-list-restaurant-{$search['restaurant']}" ] ) ){
|
||||
$query .= ' and `order`.id_restaurant="'.$search['restaurant'].'" ';
|
||||
} else {
|
||||
exit;
|
||||
}
|
||||
} else {
|
||||
// If the user doesnt have permission to all restaurants show just the ones he could see
|
||||
if( !$hasPermissionToAllRestaurants ){
|
||||
$restaurants = c::admin()->getRestaurantsUserHasPermissionToSeeTheirOrders();
|
||||
$query .= ' and `order`.id_restaurant IN (' . join( $restaurants, ',' ) . ')';
|
||||
}
|
||||
}
|
||||
/*
|
||||
if ($search['community']) {
|
||||
$query .= ' and `order`.id_community="'.$search['community'].'" ';
|
||||
}
|
||||
*/
|
||||
|
||||
if ($search['community']) {
|
||||
$query .= ' and `restaurant`.community="'.$search['community'].'" ';
|
||||
}
|
||||
|
||||
@ -34,7 +34,7 @@
|
||||
<div class="clearfix"></div>
|
||||
</li>
|
||||
<li>
|
||||
<label class="span3">Limit</label>
|
||||
<label class="span3"># Orders displayed</label>
|
||||
<span class="span8 pull-right">
|
||||
<? $envs = ['live','beta','dev','local']; ?>
|
||||
<input type="number" name="limit" value="25" min="0">
|
||||
@ -46,19 +46,13 @@
|
||||
<div class="span6 separate-sections">
|
||||
<ul class="padded separate-sections">
|
||||
<li class="input">
|
||||
<?
|
||||
$date = new DateTime('now');
|
||||
$start = $date->format('m/d/Y');
|
||||
$date->modify('14 days ago');
|
||||
$end = $date->format('m/d/Y');
|
||||
?>
|
||||
<label class="span3">Date range</label>
|
||||
<span class="span8 pull-right">
|
||||
<span class="dates">
|
||||
from <input name="date-range-end" class="date-picker" type="text" style="width: 90px;" value="<?=$end?>">
|
||||
to <input name="date-range-start" class="date-picker" type="text" style="width: 90px;" value="<?=$start?>">
|
||||
<span class="dates" style="display:none;">
|
||||
from <input name="date-range-end" class="date-picker" disabled="disabled" type="text" style="width: 90px;" value="">
|
||||
to <input name="date-range-start" class="date-picker" disabled="disabled" type="text" style="width: 90px;" value="">
|
||||
</span>
|
||||
<label><input type="checkbox" name="date-range-all"> All Dates</label>
|
||||
<label><input type="checkbox" checked="checked" name="date-range-all"> All Dates</label>
|
||||
</span>
|
||||
<div class="clearfix"></div>
|
||||
|
||||
@ -78,10 +72,10 @@
|
||||
<label class="span3">Restaurant</label>
|
||||
<span class="span8 pull-right">
|
||||
<select name="restaurant" class="chzn-select">
|
||||
echo '<option value="" selected>[ All ]</option>';
|
||||
<?php
|
||||
$restaurants = Restaurant::q('select * from restaurant order by name');
|
||||
if( $hasPermissionToAllRestaurants ){
|
||||
echo '<option value="" selected>[ All ]</option>';
|
||||
foreach ( $restaurants as $restaurant ) {
|
||||
?><option value="<?=$restaurant->id_restaurant?>"><?=$restaurant->name?></option><?php
|
||||
}
|
||||
@ -122,7 +116,7 @@
|
||||
<button type="submit" class="btn btn-blue admin-order-search"> Search </button>
|
||||
|
||||
<?php if( c::admin()->permission()->check(['global','orders-all','orders-new-users']) ) { ?>
|
||||
<a class="btn btn-green" href="/orders/newusers/">New users</a>
|
||||
<a class="btn btn-green" href="/orders/lastusers/">New users</a>
|
||||
<?php } ?>
|
||||
</center>
|
||||
<br />
|
||||
@ -236,5 +230,6 @@
|
||||
$( 'input[name="date-range-end"]').datepicker( "option", "maxDate", selectedDate );
|
||||
}
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
|
||||
71
include/views/default/cockpit/orders/lastusers/content.phtml
Normal file
71
include/views/default/cockpit/orders/lastusers/content.phtml
Normal file
@ -0,0 +1,71 @@
|
||||
<?php
|
||||
$orders = $this->orders;
|
||||
if( $orders && $orders->count() > 0 ) { ?>
|
||||
<div class="box-header">
|
||||
<span class="title">Showing last <?php echo $orders->count(); ?> new users</span>
|
||||
</div>
|
||||
<table class="list-orders table table-normal">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>Order info</td>
|
||||
<td>Dishes</td>
|
||||
<td>User info</td>
|
||||
<td>Payment info</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<?php
|
||||
foreach ( $orders as $order ) {
|
||||
$user = $order->user();
|
||||
$restaurant = $order->restaurant();
|
||||
?>
|
||||
<tr>
|
||||
<td valign="top">
|
||||
<?php $date = $order->date();?>
|
||||
<?=$date->format('M jS Y')?> <?=$date->format('g:i:s A')?>
|
||||
<br/>
|
||||
Restaurant: <?php echo $restaurant->name; ?>
|
||||
<br/>
|
||||
Delivery: <?php echo $order->delivery_type; ?>
|
||||
<br/>
|
||||
Estimated delivery: <?php if( $order->restaurant()->delivery_estimated_time ){ echo $order->restaurant()->delivery_estimated_time . ' min.'; } else { echo '-'; } ?>
|
||||
<br/>
|
||||
# <?php echo $order->id_order; ?>
|
||||
</td>
|
||||
<td valign="top">
|
||||
<ul>
|
||||
<?php foreach ($order->dishes() as $dish) : ?>
|
||||
<li>
|
||||
<?
|
||||
$food = $dish->dish()->name;
|
||||
$cartPrice = $dish->dish()->price;
|
||||
$options = $dish->options();?>
|
||||
<?=$food?>
|
||||
|
||||
</li>
|
||||
<? endforeach ; ?>
|
||||
</ul>
|
||||
</td>
|
||||
<td valign="top">
|
||||
Name: <?php echo $user->name; ?>
|
||||
<br/>
|
||||
Phone: <?php echo $user->phone; ?>
|
||||
<br/>
|
||||
<?php if( $user->email ){ ?>
|
||||
Email: <?php echo $user->email; ?>
|
||||
<br/>
|
||||
<?php } ?>
|
||||
Address: <?php echo $order->address; ?>
|
||||
</td>
|
||||
<td valign="top">
|
||||
Type: <?php echo $order->pay_type; ?>
|
||||
<br />
|
||||
Tip: $<?=$order->tip()?> <?php if( $order->tip_type != Crunchbutton_Order::TIP_NUMBER ) { echo '(' . $order->tip . '%)'; } ?>
|
||||
<br />
|
||||
Total: $<?=number_format($order->final_price,2)?>
|
||||
</td>
|
||||
</tr>
|
||||
<?
|
||||
}
|
||||
?>
|
||||
</table>
|
||||
<?php } ?>
|
||||
61
include/views/default/cockpit/orders/lastusers/index.phtml
Normal file
61
include/views/default/cockpit/orders/lastusers/index.phtml
Normal file
@ -0,0 +1,61 @@
|
||||
<?
|
||||
$this->title = 'Orders';
|
||||
$this->subtitle = 'people order shit! then eat it!';
|
||||
$this->titleicon = 'truck';
|
||||
$orders = $this->orders;
|
||||
?>
|
||||
<!-- content -->
|
||||
<div class="container-fluid padded">
|
||||
<div class="row-fluid">
|
||||
<div class="box">
|
||||
<div class="box-header">
|
||||
<span class="title">New users</span></div>
|
||||
<div class="box-content padded">
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span1">
|
||||
<label>Limit</label>
|
||||
</div>
|
||||
<div class="span2">
|
||||
<input type="number" name="limit" id="limit" value="25" class="span12">
|
||||
</div>
|
||||
<div class="span4">
|
||||
<button type="button" id="search-restaurants" class="search-restaurants btn btn-green">Load</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="box">
|
||||
<div id="results"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
$(function() {
|
||||
|
||||
$(document).on('click', '.search-restaurants', function() {
|
||||
loadOrders();
|
||||
} );
|
||||
loadOrders();
|
||||
});
|
||||
|
||||
function loadOrders(){
|
||||
|
||||
var url = '/orders/lastusers/content/' + $( '#limit' ).val() ;
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: url,
|
||||
success: function( data ) {
|
||||
$( '#results' ).html( data );
|
||||
},
|
||||
error: function( ){
|
||||
alert( 'Oops, something bad happened!' );
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
Loading…
x
Reference in New Issue
Block a user