v.1.7 update
This commit is contained in:
407
web/controllers/orders.js
Normal file
407
web/controllers/orders.js
Normal file
@@ -0,0 +1,407 @@
|
||||
(function () {
|
||||
'use strict';
|
||||
angular
|
||||
.module('app')
|
||||
.controller('OrdersCtrl', OrdersCtrl);
|
||||
|
||||
OrdersCtrl.$inject = ['$scope', 'smartRequest', '$location', 'Notification'];
|
||||
function OrdersCtrl($scope, smartRequest, $location, Notification) {
|
||||
|
||||
|
||||
|
||||
$scope.orders = [];
|
||||
|
||||
$scope.readonlyMode = false;
|
||||
|
||||
$scope.selectedElement = {
|
||||
type: '',
|
||||
value: 0,
|
||||
currentModal: '',
|
||||
param: {},
|
||||
info: '',
|
||||
subtype: ''
|
||||
};
|
||||
|
||||
$scope.defaultCount = 1;
|
||||
$scope.itemDelete = '';
|
||||
$scope.itemDeleteId = '';
|
||||
$scope.inputSearch = '';
|
||||
|
||||
$scope.searchClient = function(text, orderId) {
|
||||
$scope.order_id = orderId;
|
||||
$scope.inputSearch = text;
|
||||
smartRequest.get('v1/order?task=clientsearch&search=' + text, function(data) {
|
||||
$scope.clients = data.clients;
|
||||
if (!data.clients) {
|
||||
$('#edit-client-not-found').modal({
|
||||
backdrop: 'static',
|
||||
keyboard: false
|
||||
});
|
||||
}
|
||||
console.log($scope.clients);
|
||||
});
|
||||
|
||||
};
|
||||
|
||||
$scope.clearClient = function() {
|
||||
$scope.client_name = '';
|
||||
$scope.client_phone = '';
|
||||
$scope.client_address = '';
|
||||
};
|
||||
|
||||
$scope.deleteClient = function(orderId) {
|
||||
$scope.client_name = '';
|
||||
$scope.client_phone = '';
|
||||
$scope.client_address = '';
|
||||
$scope.inputSearch = '';
|
||||
$scope.clients = '';
|
||||
smartRequest.post('v1/order', {
|
||||
task: 'update',
|
||||
order_id: orderId,
|
||||
client_id: null
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.getOrder(orderId);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.createClient = function(orderId) {
|
||||
$scope.searchOrderId = orderId;
|
||||
$('#edit-client-not-found').modal('hide');
|
||||
$('#create-client').modal({
|
||||
backdrop: 'static',
|
||||
keyboard: false
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addClientToOrder = function(orderId, clientGUID) {
|
||||
smartRequest.post('v1/order', {
|
||||
task: 'update',
|
||||
order_id: orderId,
|
||||
client_id: clientGUID
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.getOrder(orderId);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addClient = function(orderId, name, phone, address) {
|
||||
smartRequest.post('v1/createclient', {
|
||||
name: name,
|
||||
phone: phone,
|
||||
address: address,
|
||||
}, function(data) {
|
||||
$scope.addClientToOrder(orderId, data.client.user_code);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.inOrderIncrement = function(item, count) {
|
||||
item.item_count = parseInt(count);
|
||||
item.item_count++;
|
||||
smartRequest.post('v1/orderitem', {
|
||||
task: 'update',
|
||||
id: item.id,
|
||||
order_id: item.order_id,
|
||||
item_count: item.item_count
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.getOrder(item.order_id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.inOrderDecrement = function(item, count) {
|
||||
item.item_count = parseInt(count);
|
||||
item.item_count--;
|
||||
smartRequest.post('v1/orderitem', {
|
||||
task: 'update',
|
||||
id: item.id,
|
||||
order_id: item.order_id,
|
||||
item_count: item.item_count
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.getOrder(item.order_id);
|
||||
});
|
||||
};
|
||||
|
||||
$scope.increment = function(item, count) {
|
||||
item.realCount = parseInt(count);
|
||||
item.realCount++;
|
||||
};
|
||||
$scope.decrement = function(item, count) {
|
||||
item.realCount = parseInt(count);
|
||||
item.realCount--;
|
||||
};
|
||||
|
||||
$scope.deleteItem = function(item) {
|
||||
$scope.itemDelete = item;
|
||||
console.log($scope.itemDelete);
|
||||
$('#edit-item-confirm-delete').modal('toggle');
|
||||
};
|
||||
$scope.deleteItemConfirm = function(item) {
|
||||
smartRequest.post('v1/orderitem', {
|
||||
task: 'delete',
|
||||
order_id: item.order_id,
|
||||
id: item.id,
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.getOrder(item.order_id);
|
||||
$scope.itemDelete = '';
|
||||
});
|
||||
$('#edit-item-confirm-delete').modal('hide');
|
||||
};
|
||||
|
||||
$scope.navigationStack = [];
|
||||
|
||||
$scope.update = function() {
|
||||
smartRequest.get('v1/order?task=list', function(data) {
|
||||
$scope.orders = data.orders;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.delete = function(orderId) {
|
||||
$('#edit-order-confirm-delete').modal('hide');
|
||||
$('#new-order').modal('hide');
|
||||
|
||||
smartRequest.post('v1/order', {
|
||||
task: 'delete',
|
||||
id: orderId
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.create = function() {
|
||||
$('#new-order').modal('toggle');
|
||||
$scope.client_name = '';
|
||||
$scope.client_phone = '';
|
||||
$scope.client_address = '';
|
||||
$scope.items = [];
|
||||
$scope.totalCount = '';
|
||||
$scope.totalPrice = '';
|
||||
smartRequest.post('v1/order', {
|
||||
task: 'create',
|
||||
is_send: 0
|
||||
}, function(data) {
|
||||
$scope.update();
|
||||
$scope.orderId = data.order.id;
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
/* MENU BLOCK */
|
||||
$scope.selectMenuItemParams = {
|
||||
currentMenu: 0,
|
||||
currentFolder: 0,
|
||||
menus: [],
|
||||
folders: [],
|
||||
items: []
|
||||
};
|
||||
|
||||
$scope.selectedMenuElement = {};
|
||||
$scope.selectMenuNavigationStack = [];
|
||||
|
||||
$scope.enterCount = function(orderId, itemId) {
|
||||
$('#edit-selectmenuitem').modal('hide');
|
||||
$('#edit-item-count').modal('toggle');
|
||||
$scope.itemId = itemId;
|
||||
};
|
||||
|
||||
$scope.getOrder = function(orderId, newOrder) {
|
||||
smartRequest.get('v1/order?task=single&order_id=' + orderId, function (data) {
|
||||
$scope.items = data.orderItems;
|
||||
$scope.totalCount = data.totalCount;
|
||||
$scope.totalPrice = data.totalPrice;
|
||||
$scope.client_name = data.client_name;
|
||||
$scope.client_address = data.client_address;
|
||||
$scope.client_phone = data.client_phone;
|
||||
if (newOrder == true) {
|
||||
$('#new-order').modal('toggle');
|
||||
$scope.orderId = orderId;
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
$scope.addItem = function(orderId, itemId, itemCount) {
|
||||
smartRequest.post('v1/order', {
|
||||
task: 'update',
|
||||
item: 'add',
|
||||
order_id: orderId,
|
||||
item_id: itemId,
|
||||
item_count: itemCount
|
||||
}, function(data) {
|
||||
Notification.success('Товар добавлен');
|
||||
$('#edit-selectmenuitem').modal('toggle');
|
||||
$scope.getOrder(orderId);
|
||||
$scope.update();
|
||||
});
|
||||
};
|
||||
|
||||
$scope.selectMenuItem = function(orderId) {
|
||||
$scope.selectMenuItemParams = {
|
||||
currentMenu: 0,
|
||||
currentFolder: 0,
|
||||
menus: [],
|
||||
folders: [],
|
||||
items: []
|
||||
};
|
||||
smartRequest.get('menu/list', function (data) {
|
||||
$scope.selectMenuItemParams.menus = data.menus;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openMenuItem = function(menu) {
|
||||
$scope.selectMenuItemParams.currentMenu = menu.id;
|
||||
|
||||
$scope.selectMenuNavigationStack.push({
|
||||
type: 'menu',
|
||||
value: menu
|
||||
});
|
||||
|
||||
smartRequest.get('menu/folder/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=0', function (data) {
|
||||
$scope.selectMenuItemParams.folders = data.folders;
|
||||
});
|
||||
|
||||
smartRequest.get('menu/dish/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=0', function (data) {
|
||||
$scope.selectMenuItemParams.items = data.dishes;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openFolderItem = function(folder) {
|
||||
$scope.selectMenuItemParams.currentFolder = folder.id;
|
||||
|
||||
$scope.selectMenuNavigationStack.push({
|
||||
type: 'folder',
|
||||
value: folder
|
||||
});
|
||||
|
||||
smartRequest.get('menu/folder/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=' + $scope.selectMenuItemParams.currentFolder, function (data) {
|
||||
$scope.selectMenuItemParams.folders = data.folders;
|
||||
});
|
||||
|
||||
smartRequest.get('menu/dish/list?menu_id=' + $scope.selectMenuItemParams.currentMenu + '&parent_id=' + $scope.selectMenuItemParams.currentFolder, function (data) {
|
||||
$scope.selectMenuItemParams.items = data.dishes;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.upMenuItem = function() {
|
||||
if($scope.selectMenuNavigationStack.length > 1) {
|
||||
$scope.selectMenuNavigationStack.pop();
|
||||
var page = $scope.selectMenuNavigationStack.pop();
|
||||
|
||||
if(page.type === 'menu') {
|
||||
$scope.openMenuItem(page.value);
|
||||
}
|
||||
|
||||
if(page.type === 'folder') {
|
||||
$scope.openFolderItem(page.value);
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.selectMenuItem();
|
||||
}
|
||||
};
|
||||
/* END MENU BLOCK */
|
||||
|
||||
/* CLIENT BLOCK */
|
||||
$scope.selectClientItemParams = {
|
||||
clients: [],
|
||||
groups: [],
|
||||
isParent: true
|
||||
};
|
||||
|
||||
$scope.selectClientItem = function() {
|
||||
$scope.selectClientItemParams = {
|
||||
clients: [],
|
||||
groups: [],
|
||||
isParent: true
|
||||
};
|
||||
$scope.currentPage = 1;
|
||||
$scope.pages = 1;
|
||||
smartRequest.get('v1/clientgroup', function(data) {
|
||||
$scope.selectClientItemParams.groups = data.groups;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.openGroup = function(group) {
|
||||
$scope.selectClientItemParams.isParent = false;
|
||||
$scope.currentGroup = group.id;
|
||||
$scope.currentPage = 1;
|
||||
$scope.selectClientItemParams.groups = [];
|
||||
$scope.selectClientItemParams.clients = [];
|
||||
|
||||
smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) {
|
||||
$scope.selectClientItemParams.clients = data.clients;
|
||||
$scope.pages = data.pages;
|
||||
$scope.currentGroup = data.currentGroup;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.pager = function(currentPage) {
|
||||
$scope.selectClientItemParams.isParent = false;
|
||||
$scope.selectClientItemParams.groups = [];
|
||||
$scope.selectClientItemParams.clients = [];
|
||||
smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function(data) {
|
||||
$scope.selectClientItemParams.clients = data.clients;
|
||||
$scope.pages = data.pages;
|
||||
$scope.currentGroup = data.currentGroup;
|
||||
});
|
||||
};
|
||||
|
||||
$scope.upGroup = function() {
|
||||
$scope.selectClientItemParams = {
|
||||
clients: [],
|
||||
groups: [],
|
||||
isParent: true
|
||||
};
|
||||
|
||||
smartRequest.get('v1/clientgroup', function(data) {
|
||||
$scope.selectClientItemParams.groups = data.groups;
|
||||
});
|
||||
};
|
||||
/* END CLIENT BLOCK */
|
||||
|
||||
$scope.selectItem = function(value, type, info) {
|
||||
$scope.selectedElement.value = value;
|
||||
$scope.selectedElement.type = type;
|
||||
$scope.selectedElement.info = info;
|
||||
};
|
||||
|
||||
$scope.editTermParam = function(param) {
|
||||
$scope.$eval(param.type[0].toLowerCase() + param.type.slice(1) + '()');
|
||||
|
||||
$scope.selectedElement = {
|
||||
type: param.type,
|
||||
value: param.value,
|
||||
currentModal: '#edit-' + param.type.toLowerCase(),
|
||||
param: param,
|
||||
info: param.info,
|
||||
subtype: param.subtype
|
||||
};
|
||||
|
||||
$($scope.selectedElement.currentModal).modal();
|
||||
};
|
||||
|
||||
$scope.confirmSelect = function() {
|
||||
$($scope.selectedElement.currentModal).modal('toggle');
|
||||
|
||||
$scope.selectedElement.param.value = $scope.selectedElement.value;
|
||||
$scope.selectedElement.param.info = $scope.selectedElement.info;
|
||||
$scope.selectedElement.param.subtype = $scope.selectedElement.type;
|
||||
};
|
||||
|
||||
$scope.update();
|
||||
|
||||
smartRequest.get('discount/type/list', function(data) {
|
||||
$scope.terms = data.discount_types;
|
||||
$scope.defaultTerm = data.default.code;
|
||||
});
|
||||
|
||||
smartRequest.get('menu/readonly', function (data) {
|
||||
$scope.readonlyMode = data.readonly;
|
||||
|
||||
if (data.readonly) {
|
||||
Notification.error('Режим просмотра!');
|
||||
}
|
||||
});
|
||||
}
|
||||
})();
|
||||
Reference in New Issue
Block a user