partial #3365
This commit is contained in:
arzynik 2014-06-17 11:14:34 -07:00
parent 1a544d2cb3
commit abd549dc3c
11 changed files with 336 additions and 47 deletions

View File

@ -0,0 +1,3 @@
ALTER TABLE `order` ADD `type` ENUM( 'web', 'restaurant', 'admin') NULL DEFAULT 'web';
INSERT INTO `group` (`name`, `description`) VALUES ( 'restaurant', 'Restaurant group' );

View File

@ -0,0 +1,69 @@
<?php
class Controller_api_order extends Crunchbutton_Controller_RestAccount {
public function init() {
$order = Order::uuid(c::getPagePiece(2));
/* @var $order Crunchbutton_Order */
if (!$order->id_order) {
$order = Order::o(c::getPagePiece(2));
}
$_POST = [
'name' => 'MR TEST DEVIN',
'subtotal' => '11.50',
'tip' => '2.00',
'phone' => '_PHONE_',
'address' => '123 main santa monica',
'card' => [
'id' => 'CC1yW7tINe5OHE77eplt5hPs',
'uri' => '/cards/CC1yW7tINe5OHE77eplt5hPs',
'lastfour' => '4242',
'card_type' => 'visa',
'month' => '2',
'year' => '2016'
],
'pay_type' => 'card',
'delivery_type' => 'delivery',
'restaurant' => '26',
'notes' => 'test'
];
switch ($this->method()) {
case 'get':
if (get_class($order) != 'Cockpit_Order') {
$order = $order->get(0);
}
if ($order->id_order) {
echo $order->json();
break;
} else {
echo json_encode(['error' => 'invalid object']);
}
break;
case 'post':
$order = new Order;
// card, subtotal, tip, name, phone, address
$charge = $order->process($_POST, 'restaurant');
if ($charge === true) {
echo json_encode([
'id_user' => c::auth()->session()->id_user,
'txn' => $order->txn,
'final_price' => $order->final_price,
'uuid' => (new Order($order->id_order))->uuid,
'token' => c::auth()->session()->token
]);
} else {
echo json_encode(['status' => 'false', 'errors' => $charge]);
}
break;
}
}
}

View File

@ -30,7 +30,7 @@ class Crunchbutton_Order extends Cana_Table {
* @todo Add more security here
* @todo It looks like if there are orders not set as delivery nor takeout, we need to log them.
*/
public function process($params)
public function process($params, $processType = 'web')
{
$this->pay_type = ($params['pay_type'] == 'cash') ? 'cash' : 'card';
$this->address = $params['address'];
@ -107,36 +107,49 @@ class Crunchbutton_Order extends Cana_Table {
$delivery_service_markup = ( $this->restaurant()->delivery_service_markup ) ? $this->restaurant()->delivery_service_markup : 0;
$this->delivery_service_markup = $delivery_service_markup;
if ($processType == 'restaurant') {
$subtotal = $params['subtotal'];
$delivery_service_markup = $this->restaurant()->delivery_service_markup ? $this->restaurant()->delivery_service_markup : 0;
$price_delivery_markup = number_format($subtotal * $delivery_service_markup / 100, 2);
$subtotal_plus_delivery_service_markup = $subtotal + $price_delivery_markup;
$this->type = 'restaurant';
} else {
foreach ($params['cart'] as $d) {
$dish = new Order_Dish;
$dish->id_dish = $d['id'];
$price = $dish->dish()->price;
$price_delivery_markup = $price;
if( $delivery_service_markup ){
$price_delivery_markup = $price_delivery_markup + ( $price_delivery_markup * $delivery_service_markup / 100 );
$price_delivery_markup = number_format( $price_delivery_markup, 2 );
}
$subtotal += $price;
$subtotal_plus_delivery_service_markup += $price_delivery_markup;
if ($d['options']) {
foreach ($d['options'] as $o) {
$option = new Order_Dish_Option;
$option->id_option = $o;
$price = $option->option()->price;
$price_delivery_markup = $price;
if( $delivery_service_markup ){
$price_delivery_markup = $price_delivery_markup + ( $price_delivery_markup * $delivery_service_markup / 100 );
$price_delivery_markup = number_format( $price_delivery_markup, 2 );
}
$subtotal_plus_delivery_service_markup += $price_delivery_markup;
$subtotal += $price;
// $subtotal += $option->option()->optionPrice($d['options']);
$dish->_options[] = $option;
foreach ($params['cart'] as $d) {
$dish = new Order_Dish;
$dish->id_dish = $d['id'];
$price = $dish->dish()->price;
$price_delivery_markup = $price;
if( $delivery_service_markup ){
$price_delivery_markup = $price_delivery_markup + ( $price_delivery_markup * $delivery_service_markup / 100 );
$price_delivery_markup = number_format( $price_delivery_markup, 2 );
}
$subtotal += $price;
$subtotal_plus_delivery_service_markup += $price_delivery_markup;
if ($d['options']) {
foreach ($d['options'] as $o) {
$option = new Order_Dish_Option;
$option->id_option = $o;
$price = $option->option()->price;
$price_delivery_markup = $price;
if( $delivery_service_markup ){
$price_delivery_markup = $price_delivery_markup + ( $price_delivery_markup * $delivery_service_markup / 100 );
$price_delivery_markup = number_format( $price_delivery_markup, 2 );
}
$subtotal_plus_delivery_service_markup += $price_delivery_markup;
$subtotal += $price;
// $subtotal += $option->option()->optionPrice($d['options']);
$dish->_options[] = $option;
}
}
$this->_dishes[] = $dish;
}
$this->_dishes[] = $dish;
$this->type = 'web';
}
// to make sure the value will be 2 decimals
$this->delivery_service_markup_value = number_format( $subtotal_plus_delivery_service_markup - $subtotal, 2 );
@ -440,13 +453,15 @@ class Crunchbutton_Order extends Cana_Table {
}
}
c::auth()->session()->id_user = $user->id_user;
c::auth()->session()->generateAndSaveToken();
if ($processType != 'restaurant') {
c::auth()->session()->id_user = $user->id_user;
c::auth()->session()->generateAndSaveToken();
}
$agent = Crunchbutton_Agent::getAgent();
$this->id_agent = $agent->id_agent;
if( c::auth()->session()->id_session != '' ){
if (c::auth()->session()->id_session != '') {
$this->id_session = c::auth()->session()->id_session;
}
@ -481,16 +496,18 @@ class Crunchbutton_Order extends Cana_Table {
}
}
foreach ($this->_dishes as $dish) {
$dish->id_order = $this->id_order;
$dish->save();
$_Dish = Dish::o( $dish->id_dish );
foreach ($dish->options() as $option) {
# Issue 1437 - https://github.com/crunchbutton/crunchbutton/issues/1437#issuecomment-20561023
# 1 - When an option is removed, it should NEVER appear in the order or on the fax.
if( $_Dish->dish_has_option( $option->id_option ) ){
$option->id_order_dish = $dish->id_order_dish;
$option->save();
if ($this->_dishes) {
foreach ($this->_dishes as $dish) {
$dish->id_order = $this->id_order;
$dish->save();
$_Dish = Dish::o( $dish->id_dish );
foreach ($dish->options() as $option) {
# Issue 1437 - https://github.com/crunchbutton/crunchbutton/issues/1437#issuecomment-20561023
# 1 - When an option is removed, it should NEVER appear in the order or on the fax.
if( $_Dish->dish_has_option( $option->id_option ) ){
$option->id_order_dish = $dish->id_order_dish;
$option->save();
}
}
}
}

View File

@ -30,6 +30,7 @@
<script src="/assets/cockpit/js/controllers.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/cockpit/js/controllers.drivers.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/cockpit/js/controllers.settlement.js?v=<?=Cana_Util::gitVersion()?>"></script>
<script src="/assets/cockpit/js/controllers.restaurants.js?v=<?=Cana_Util::gitVersion()?>"></script>
<!-- AngularJS Filters -->
<script src="/assets/js/filters.js?v=<?=Cana_Util::gitVersion()?>"></script>

View File

@ -0,0 +1,80 @@
<div class="top-pad"></div>
<div class="content-padding">
<h1 class="title"><i class="fa fa-credit-card"></i><span>New Order</span></h1>
<p>Please fill out all of the customer's information. Their name and phone number will be sent to the delivery drivers.</p>
<br><br>
<ul class="ul-inputs box-content">
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Name</div>
<div class="input">
<input type="text" name="name" ng-model="order.name" required="" placeholder="Customer Name" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
<div class="box-error">
<small ng-show="form.driverName.$error.required" class="ng-hide">Required.</small>
<small ng-show="form.driverName.$error.minlength" class="ng-hide">Name is too short. Name is required to be at least 5 characters.</small>
<small ng-show="form.driverName.$error.maxlength" class="ng-hide">Name cannot be longer than 40 characters.</small>
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Phone</div>
<div class="input">
<input type="text" name="name" ng-model="order.phone" required="" placeholder="646-783-1444" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Address</div>
<div class="input">
<input type="text" name="name" ng-model="order.address" required="" placeholder="1120 Princeton Drive, Marina del Rey CA 90292" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Notes</div>
<div class="input">
<input type="text" name="name" ng-model="order.notes" required="" placeholder="Building name, or dial code" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Subtotal</div>
<div class="input">
<input type="text" name="name" ng-model="order.subtotal" required="" placeholder="0.00" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Tip</div>
<div class="input">
<input type="text" name="name" ng-model="order.tip" required="" placeholder="0.00" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Card Number</div>
<div class="input">
<input type="text" name="name" ng-model="card.number" required="" placeholder="0000-0000-0000-0000" ng-minlength="5" ng-maxlength="80" class="ng-pristine ng-valid-maxlength ng-valid-minlength ng-valid ng-valid-required">
</div>
</li>
<li class="li-input" ng-class="{'error':form.driverName.$invalid}">
<div class="label">Card Expiration</div>
<div class="input">
<select ng-model="card.month" ng-options="month.value as month.label for month in card._months()" class=""></select>
<select ng-model="order.year" ng-options="year.value as year.label for year in card._years()" class=""></select>
</div>
</li>
<li class="li-input" ng-show="!isSubmitting"><button class="button orange" ng-click="submit();">Submit New Order</button></li>
</ul>
</div>

View File

@ -4,7 +4,7 @@
<div class="user-initials"><span>{{account.user.initials}}</span></div>
<ul>
<li ng-click="navigation.link('/drivers/orders')" ng-class="{'nav-active': (navigation.page == 'drivers-orders')}">
<li ng-if="account.user.permissions.GLOBAL || account.isDriver" ng-click="navigation.link('/drivers/orders')" ng-class="{'nav-active': (navigation.page == 'drivers-orders')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-car"></i></td>
@ -12,7 +12,7 @@
</tr>
</table>
</li>
<li ng-click="navigation.link('/drivers/shifts')" ng-class="{'nav-active': (navigation.page == 'drivers-shifts')}">
<li ng-if="account.user.permissions.GLOBAL || account.isDriver" ng-click="navigation.link('/drivers/shifts')" ng-class="{'nav-active': (navigation.page == 'drivers-shifts')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-calendar"></i></td>
@ -21,6 +21,15 @@
</table>
</li>
<li ng-if="account.user.permissions.GLOBAL || account.isRestaurant" ng-click="navigation.link('/restaurant/order/new')" ng-class="{'nav-active': (navigation.page == 'restaurant-order-new')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-credit-card"></i></td>
<td class="side-menu-label">New Order</a></td>
</tr>
</table>
</li>
<?/* Permission GLOBAL hard coded for while | todo: remove it and apply the correct permission @pererinha */?>
<li ng-if="account.user.permissions.GLOBAL" ng-click="navigation.link('/settlement/')" ng-class="{'nav-active': (navigation.page == 'settlement')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
@ -41,7 +50,7 @@
</table>
</li>
<li ng-click="navigation.link('/drivers/docs/')" ng-class="{'nav-active': (navigation.page == 'drivers-documents')}">
<li ng-if="account.user.permissions.GLOBAL || account.isDriver" ng-click="navigation.link('/drivers/docs/')" ng-class="{'nav-active': (navigation.page == 'drivers-documents')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-briefcase"></i></td>
@ -50,7 +59,15 @@
</table>
</li>
<li ng-click="navigation.link('/drivers/help')" ng-class="{'nav-active': (navigation.page == 'drivers-help')}">
<li ng-if="account.isDriver" ng-click="navigation.link('/drivers/help')" ng-class="{'nav-active': (navigation.page == 'drivers-help')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-support"></i></td>
<td class="side-menu-label">Help</a></td>
</tr>
</table>
</li>
<li ng-if="account.isRestaurant" ng-click="navigation.link('/restaurants/help')" ng-class="{'nav-active': (navigation.page == 'restaurants-help')}">
<table cellpadding="0" cellspacing="0" class="side-menu-wrap">
<tr>
<td class="side-menu-icon"><i class="fa fa-support"></i></td>

View File

@ -78,6 +78,12 @@ NGApp.config(function($compileProvider){
NGApp.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider ) {
$routeProvider
/* Restaurants */
.when('/restaurant/order/new', {
action: 'restaurant-order-new',
controller: 'RestaurantOrderNew',
templateUrl: 'assets/view/restaurant-order-new.html'
})
/* Settlement */
.when('/settlement', {
action: 'settlement',

View File

@ -3,7 +3,15 @@ NGApp.controller('DefaultCtrl', function ($scope, $http, $location, $routeParams
if( !isNaN( parseInt( id_order ) ) ){
MainNavigationService.link('/drivers/order/' + id_order);
} else {
MainNavigationService.link('/drivers/orders');
if (AccountService.isRestaurant) {
MainNavigationService.link('/restaurant/order/new');
} else if (AccountService.isDriver) {
MainNavigationService.link('/drivers/orders');
} else {
MainNavigationService.link('/drivers/help');
}
}
});

View File

@ -0,0 +1,58 @@
NGApp.controller('RestaurantOrderNew', function ($scope, $http) {
$scope.isSubmitting = false;
$scope.order = {};
$scope.submit = function() {
$scope.isSubmitting = true;
$http({
method: 'POST',
url: '/api/order',
data: $scope.order,
headers: {'Content-Type': 'application/x-www-form-urlencoded'}
}).success(function(data) {
console.log(data);
$scope.isSubmitting = false;
});
}
$scope.card = {};
// Credit card years
$scope.card._years = function () {
var years = [];
years.push({
value: '',
label: 'Year'
});
var date = new Date().getFullYear();
for (var x = date; x <= date + 20; x++) {
years.push({
value: x.toString(),
label: x.toString()
});
}
return years;
}
// Credit card months
$scope.card._months = function () {
var months = [];
months.push({
value: '',
label: 'Month'
});
for (var x = 1; x <= 12; x++) {
months.push({
value: x.toString(),
label: x.toString()
});
}
return months;
}
});

View File

@ -10,7 +10,12 @@ NGApp.factory( 'AccountService', function($http, $rootScope, $resource) {
var service = {
permissions: {},
user: null
user: null,
// used to change how to display the menu
isRestaurant: false,
isDriver: false,
isSupport: false,
isAdmin: false
};
service.isLoggedIn = function(){
@ -41,8 +46,31 @@ NGApp.factory( 'AccountService', function($http, $rootScope, $resource) {
};
$rootScope.$on('userAuth', function(e, data) {
service.user = data;
service.isRestaurant = service.isDriver = service.isSupport = service.isAdmin = false;
if (service.user.permissions.GLOBAL) {
service.isAdmin = true;
}
if (service.user.permissions.RESTAURANT) {
service.isRestaurant = true;
}
for (var x in service.user.groups) {
if (service.user.groups[x].indexOf('drivers-') == 0) {
service.isDriver = true;
break;
}
}
for (var x in service.user.groups) {
if (service.user.groups[x].indexOf('restaurants-') == 0) {
service.isRestaurant = true;
break;
}
}
if (service.user && service.user.id_admin) {
App.snap.enable();
var name = service.user.name.split(' ');

View File

@ -742,8 +742,10 @@ input {
.li-input .button, .li-input .button-big{
border-radius: 0;
width: 6em;
width: auto;
margin-right: .8em;
padding-right: 1em;
padding-left: 1em;
}
.li-input .button-big{
width: 12em;