restaurant order placement: dashboard #3353
added option to admin's select a restaurant to order from
This commit is contained in:
parent
58d7deefd5
commit
79565e606a
@ -11,7 +11,13 @@ class Controller_api_order extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
case 'restaurant-list-last':
|
||||
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
if( is_numeric( c::getPagePiece( 3 ) ) && c::admin()->permission()->check( [ 'global' ] ) ){
|
||||
$restaurant = Restaurant::o( intval( c::getPagePiece( 3 ) ) );
|
||||
}
|
||||
|
||||
if( !$restaurant->id_restaurant ){
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
}
|
||||
if( $restaurant->id_restaurant ){
|
||||
$out = [];
|
||||
$orders = Order::q( 'SELECT * FROM `order` o WHERE id_restaurant = "' . $restaurant->id_restaurant . '" AND o.date BETWEEN NOW() - INTERVAL 7 DAY AND NOW() ORDER BY id_order DESC' );
|
||||
@ -57,7 +63,14 @@ class Controller_api_order extends Crunchbutton_Controller_RestAccount {
|
||||
|
||||
case 'post':
|
||||
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
if( is_numeric( $_POST[ 'restaurant' ] ) && c::admin()->permission()->check( [ 'global' ] ) ){
|
||||
$restaurant = Restaurant::o( intval( $_POST[ 'restaurant' ] ) );
|
||||
}
|
||||
|
||||
if( !$restaurant->id_restaurant ){
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
}
|
||||
|
||||
if( $restaurant && $restaurant->id_restaurant && $_POST[ 'restaurant' ] == $restaurant->id_restaurant ){
|
||||
$order = new Order;
|
||||
// card, subtotal, tip, name, phone, address
|
||||
|
@ -9,11 +9,28 @@ class Controller_api_restaurant extends Crunchbutton_Controller_Rest {
|
||||
case 'get':
|
||||
|
||||
switch ( c::getPagePiece( 3 ) ) {
|
||||
|
||||
case 'all':
|
||||
$out = [];
|
||||
$restaurants = Restaurant::q( 'SELECT * FROM restaurant WHERE active_restaurant_order_placement = 1 ORDER BY name ASC' );
|
||||
foreach( $restaurants as $restaurant ){
|
||||
$out[] = [ 'id_restaurant' => intval( $restaurant->id_restaurant ), 'name' => $restaurant->name ];
|
||||
}
|
||||
echo json_encode( $out );exit;
|
||||
break;
|
||||
default:
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
|
||||
if( is_numeric( c::getPagePiece( 3 ) ) && c::admin()->permission()->check( [ 'global' ] ) ){
|
||||
$restaurant = Restaurant::o( intval( c::getPagePiece( 3 ) ) );
|
||||
}
|
||||
|
||||
if( !$restaurant->id_restaurant ){
|
||||
$restaurant = Admin::restaurantOrderPlacement();
|
||||
}
|
||||
|
||||
if( $restaurant ){
|
||||
$out = [];
|
||||
$out[ 'id_restaurant' ] = $restaurant->id_restaurant;
|
||||
$out[ 'id_restaurant' ] = intval( $restaurant->id_restaurant );
|
||||
$out[ 'name' ] = $restaurant->name;
|
||||
$out[ 'address' ] = $restaurant->address;
|
||||
$out[ 'lat' ] = $restaurant->loc_lat;
|
||||
|
@ -4,61 +4,10 @@
|
||||
|
||||
<h1 class="title left"><i class="fa fa-credit-card"></i><span>Last Orders</span></h1>
|
||||
|
||||
<div class="box-filter right">
|
||||
<button class="button orange" ng-click="new()">New</button>
|
||||
<div class="divider"></div>
|
||||
</div>
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
|
||||
<div ng-show="!error">
|
||||
|
||||
<h2 class="title">{{restaurant.name}}</h2>
|
||||
|
||||
<div ng-if="orders.length">
|
||||
|
||||
<h3 class="title">Showing orders from last 7 days. Total {{orders.length}} orders. </h3>
|
||||
|
||||
<table class="tb-grid">
|
||||
<thead>
|
||||
<tr>
|
||||
<td>#</td>
|
||||
<td class="td-medium">Customer</td>
|
||||
<td>Date</td>
|
||||
<td class="td-medium">Driver / Status</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr ng-repeat="order in orders">
|
||||
<td class="link orange" ng-click="open( order.id_order )">
|
||||
{{order.id_order}}
|
||||
</td>
|
||||
<td>
|
||||
{{order.name}} / {{order.phone}}
|
||||
</td>
|
||||
<td>
|
||||
{{order.date}}
|
||||
</td>
|
||||
<td>
|
||||
<span ng-show="order.lastStatus.name">
|
||||
{{order.lastStatus.name}} / {{order.lastStatus.status}}
|
||||
</span>
|
||||
<span ng-show="!order.lastStatus.name">
|
||||
new
|
||||
</span>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<div ng-if="!orders.length" class="box-content">
|
||||
No orders.
|
||||
</div>
|
||||
|
||||
<div>
|
||||
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
||||
<spinner-loading></spinner-loading>
|
||||
|
@ -11,6 +11,17 @@
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<form name="form" ng-show="restaurants">
|
||||
|
||||
<ul class="ul-inputs box-content">
|
||||
<li class="li-input">
|
||||
<div class="label">Select a restaurant:</div>
|
||||
<div class="input">
|
||||
<select name="restaurantSelect" ng-model="id_restaurant" ng-change="load_restaurant()" ng-options="opt.id_restaurant as opt.name for opt in restaurants"></select>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<div ng-show="!error">
|
||||
|
||||
|
@ -11,6 +11,17 @@
|
||||
|
||||
<div class="divider"></div>
|
||||
|
||||
<form name="form" ng-show="restaurants">
|
||||
|
||||
<ul class="ul-inputs box-content">
|
||||
<li class="li-input">
|
||||
<div class="label">Select a restaurant:</div>
|
||||
<div class="input">
|
||||
<select name="restaurantSelect" ng-model="id_restaurant" ng-change="load_restaurant()" ng-options="opt.id_restaurant as opt.name for opt in restaurants"></select>
|
||||
</div>
|
||||
</li>
|
||||
</ul>
|
||||
</form>
|
||||
|
||||
<h2 class="title" ng-show="!restaurant.id_restaurant">
|
||||
Select a restaurant
|
||||
|
@ -89,11 +89,21 @@ NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $l
|
||||
controller: 'RestaurantOrderPlacementNew',
|
||||
templateUrl: 'assets/view/restaurant-order-placement-new.html'
|
||||
})
|
||||
.when('/restaurant/order/placement/new/:id', {
|
||||
action: 'restaurant-order-placement',
|
||||
controller: 'RestaurantOrderPlacementNew',
|
||||
templateUrl: 'assets/view/restaurant-order-placement-new.html'
|
||||
})
|
||||
.when('/restaurant/order/placement/list', {
|
||||
action: 'restaurant-order-placement',
|
||||
controller: 'RestaurantOrderPlacementList',
|
||||
templateUrl: 'assets/view/restaurant-order-placement-list.html'
|
||||
})
|
||||
.when('/restaurant/order/placement/list/:id', {
|
||||
action: 'restaurant-order-placement',
|
||||
controller: 'RestaurantOrderPlacementList',
|
||||
templateUrl: 'assets/view/restaurant-order-placement-list.html'
|
||||
})
|
||||
.when('/restaurant/order/placement/:id', {
|
||||
action: 'restaurant-order-placement',
|
||||
controller: 'RestaurantOrderPlacementView',
|
||||
|
@ -17,48 +17,88 @@ NGApp.controller('RestaurantOrderPlacementView', function ( $scope, RestaurantOr
|
||||
RestaurantOrderPlacementService.get( function( json ){
|
||||
if( json.id_order ){
|
||||
$scope.order = json;
|
||||
if( $scope.account.isAdmin ){
|
||||
$scope.id_restaurant = json.id_restaurant;
|
||||
}
|
||||
} else {
|
||||
$scope.error = true;
|
||||
}
|
||||
$scope.ready = true;
|
||||
} );
|
||||
$scope.list = function(){
|
||||
$scope.navigation.link( '/restaurant/order/placement/list' );
|
||||
$scope.navigation.link( '/restaurant/order/placement/list/' + $scope.id_restaurant );
|
||||
}
|
||||
} );
|
||||
|
||||
NGApp.controller('RestaurantOrderPlacementList', function ( $scope, RestaurantOrderPlacementService ) {
|
||||
RestaurantOrderPlacementService.list( function( json ){
|
||||
if( !json.error ){
|
||||
$scope.orders = json;
|
||||
}
|
||||
$scope.ready = true;
|
||||
} );
|
||||
NGApp.controller('RestaurantOrderPlacementList', function ( $scope, RestaurantOrderPlacementService, $routeParams ) {
|
||||
|
||||
// Load restaurants that are allowed to place orders
|
||||
var restaurants = function(){
|
||||
RestaurantOrderPlacementService.restaurant.all( function( json ){
|
||||
$scope.restaurants = json;
|
||||
} );
|
||||
}
|
||||
|
||||
var start = function(){
|
||||
RestaurantOrderPlacementService.list( $scope.id_restaurant, function( json ){
|
||||
if( !json.error ){
|
||||
$scope.orders = json;
|
||||
}
|
||||
$scope.ready = true;
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.new = function(){
|
||||
$scope.navigation.link( '/restaurant/order/placement/new' );
|
||||
$scope.navigation.link( '/restaurant/order/placement/new/' + $scope.id_restaurant );
|
||||
}
|
||||
$scope.open = function( id_order ){
|
||||
$scope.navigation.link( '/restaurant/order/placement/' + id_order );
|
||||
}
|
||||
|
||||
$scope.load_restaurant = function(){
|
||||
$scope.navigation.link( '/restaurant/order/placement/list/' + $scope.id_restaurant );
|
||||
}
|
||||
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
if( $scope.account.isAdmin ){
|
||||
restaurants();
|
||||
if( $routeParams.id ){
|
||||
$scope.id_restaurant = parseInt( $routeParams.id );
|
||||
}
|
||||
}
|
||||
start();
|
||||
}
|
||||
|
||||
} );
|
||||
|
||||
NGApp.controller( 'RestaurantOrderPlacementNew', function ( $scope, RestaurantService, RestaurantOrderPlacementService, PositionService ) {
|
||||
NGApp.controller( 'RestaurantOrderPlacementNew', function ( $scope, RestaurantService, RestaurantOrderPlacementService, PositionService, $routeParams ) {
|
||||
|
||||
$scope.order = { 'tip_type': 'dollar', 'pay_type': 'card' };
|
||||
$scope.tip = { 'dollar' : '', 'percent': '10' };
|
||||
$scope.card = { 'month': 0, 'year': 0 };
|
||||
$scope.map = {};
|
||||
|
||||
var start = function(){
|
||||
// Load restaurants that are allowed to place orders
|
||||
var restaurants = function(){
|
||||
RestaurantOrderPlacementService.restaurant.all( function( json ){
|
||||
$scope.restaurants = json;
|
||||
} );
|
||||
}
|
||||
|
||||
$scope.load_restaurant = function(){
|
||||
$scope.navigation.link( '/restaurant/order/placement/new/' + $scope.id_restaurant );
|
||||
}
|
||||
|
||||
var start = function(){
|
||||
$scope.card._months = RestaurantOrderPlacementService.cardMonths();
|
||||
$scope.card._years = RestaurantOrderPlacementService.cardYears();
|
||||
$scope.tip._percents = RestaurantOrderPlacementService.tipPercents();
|
||||
|
||||
// get info about the restaurant
|
||||
RestaurantOrderPlacementService.restaurant.get( function( json ){
|
||||
RestaurantOrderPlacementService.restaurant.get( $scope.id_restaurant, function( json ){
|
||||
if( json.id_restaurant ){
|
||||
$scope.restaurant = json;
|
||||
$scope.id_restaurant = $scope.restaurant.id_restaurant;
|
||||
PositionService.bounding( $scope.restaurant.lat, $scope.restaurant.lon );
|
||||
App.config.processor = { type: 'balanced' };
|
||||
}
|
||||
@ -180,7 +220,7 @@ NGApp.controller( 'RestaurantOrderPlacementNew', function ( $scope, RestaurantSe
|
||||
}
|
||||
|
||||
$scope.list = function(){
|
||||
$scope.navigation.link( '/restaurant/order/placement/list' );
|
||||
$scope.navigation.link( '/restaurant/order/placement/list/' + $scope.id_restaurant );
|
||||
}
|
||||
|
||||
$scope.test = function (){
|
||||
@ -192,6 +232,12 @@ NGApp.controller( 'RestaurantOrderPlacementNew', function ( $scope, RestaurantSe
|
||||
}
|
||||
|
||||
if( $scope.account.isLoggedIn() ){
|
||||
if( $scope.account.isAdmin ){
|
||||
restaurants();
|
||||
if( $routeParams.id ){
|
||||
$scope.id_restaurant = parseInt( $routeParams.id );
|
||||
}
|
||||
}
|
||||
start();
|
||||
}
|
||||
|
||||
|
@ -36,15 +36,16 @@ NGApp.factory( 'RestaurantOrderPlacementService', function( $rootScope, $resourc
|
||||
|
||||
var service = {};
|
||||
|
||||
var orders = $resource( App.service + 'order/:action', { action: '@action' }, {
|
||||
var orders = $resource( App.service + 'order/:action/:id_restaurant', { action: '@action', id_restaurant: '@id_restaurant' }, {
|
||||
'process' : { 'method': 'POST' },
|
||||
'get' : { 'method': 'GET' },
|
||||
'list' : { 'method': 'GET' , params : { 'action' : 'restaurant-list-last' }, isArray: true },
|
||||
'list' : { 'method': 'GET', params : { 'action' : 'restaurant-list-last' }, isArray: true },
|
||||
}
|
||||
);
|
||||
|
||||
var restaurant = $resource( App.service + 'restaurant/orderplacement/:action', { action: '@action' }, {
|
||||
'get' : { 'method': 'GET' }
|
||||
var restaurant = $resource( App.service + 'restaurant/orderplacement/:action/:id_restaurant', { action: '@action', id_restaurant: '@id_restaurant' }, {
|
||||
'get' : { 'method': 'GET' },
|
||||
'all' : { 'method': 'GET', params : { 'action' : 'all' }, isArray: true },
|
||||
}
|
||||
);
|
||||
|
||||
@ -54,15 +55,20 @@ NGApp.factory( 'RestaurantOrderPlacementService', function( $rootScope, $resourc
|
||||
} );
|
||||
}
|
||||
|
||||
service.list = function( callback ){
|
||||
orders.list( function( data ){
|
||||
service.list = function( id_restaurant, callback ){
|
||||
orders.list( { id_restaurant: id_restaurant }, function( data ){
|
||||
callback( data );
|
||||
} );
|
||||
}
|
||||
|
||||
service.restaurant = {
|
||||
get : function( callback ){
|
||||
restaurant.get( function( data ){
|
||||
get : function( id_restaurant, callback ){
|
||||
restaurant.get( { id_restaurant: id_restaurant }, function( data ){
|
||||
callback( data );
|
||||
} );
|
||||
},
|
||||
all : function ( callback ){
|
||||
restaurant.all( function( data ){
|
||||
callback( data );
|
||||
} );
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user