405 lines
15 KiB
JavaScript
405 lines
15 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
angular
|
|
.module('app')
|
|
.controller('ClientsCtrl', ClientsCtrl);
|
|
|
|
ClientsCtrl.$inject = ['$scope', 'smartRequest', 'Notification', '$rootScope', '$timeout'];
|
|
|
|
function ClientsCtrl($scope, smartRequest, Notification, $rootScope, $timeout) {
|
|
$scope.clients = [];
|
|
$scope.groups = [];
|
|
$scope.statuses = [];
|
|
$scope.filedate = '';
|
|
$scope.currentGroupId = 0;
|
|
$scope.currentClientId = 0;
|
|
|
|
$scope.currentClient = {};
|
|
|
|
$scope.orders = [];
|
|
$scope.order = {};
|
|
|
|
$scope.isCreateNewGroup = false;
|
|
$scope.newGroup = {};
|
|
$scope.newBarcode = {};
|
|
|
|
$scope.isCreateNewClient = false;
|
|
$scope.newClient = {};
|
|
|
|
$scope.search = {
|
|
query: ''
|
|
};
|
|
|
|
var promise = 0;
|
|
|
|
$scope.clientsSearch = function () {
|
|
|
|
}
|
|
|
|
$scope.update = function () {
|
|
smartRequest.get('client/list?page=' + $scope.currentPage, function (data) {
|
|
$scope.clients = data.clients;
|
|
$scope.countOfPages = data.pages;
|
|
$scope.pages = $scope.makePages();
|
|
});
|
|
};
|
|
|
|
$scope.getGroups = function () {
|
|
smartRequest.get('v1/clientgroup', function (data) {
|
|
$scope.groups = data.groups;
|
|
$scope.filedate = data.filedate;
|
|
$scope.openGroup({id: 0});
|
|
});
|
|
};
|
|
|
|
|
|
$scope.openGroup = function (group) {
|
|
if (typeof group === 'object') {
|
|
$scope.currentGroup = group.id;
|
|
} else {
|
|
$scope.currentGroup = group;
|
|
}
|
|
$scope.currentPage = 1;
|
|
smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function (data) {
|
|
$scope.clients = data.clients;
|
|
$scope.pages = data.pages;
|
|
$scope.currentGroup = data.currentGroup;
|
|
$scope.total = data.total;
|
|
$scope.closeCard();
|
|
$scope.orders = [];
|
|
$scope.currentClient = [];
|
|
$scope.clientLogs = [];
|
|
});
|
|
|
|
};
|
|
|
|
$scope.editGroup = function (group) {
|
|
$scope.contextElement = group;
|
|
|
|
$('#edit-group').modal('toggle');
|
|
console.log(group);
|
|
};
|
|
|
|
$scope.updateGroup = function () {
|
|
$('#edit-group').modal('toggle');
|
|
|
|
smartRequest.post('v1/clientgroup', {
|
|
id: $scope.contextElement.id,
|
|
name: $scope.contextElement.name,
|
|
task: 'update'
|
|
}, function (data) {
|
|
if (data.status == 'success') {
|
|
Notification.success(data.message);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.removeGroup = function () {
|
|
$('#group-confirm-delete').modal('toggle');
|
|
$('#edit-group').modal('toggle');
|
|
|
|
smartRequest.post('v1/clientgroup', {
|
|
id: $scope.contextElement.id,
|
|
task: 'delete'
|
|
}, function (data) {
|
|
$scope.getGroups();
|
|
if (data.message) {
|
|
Notification.success(data.message);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.editClient = function (client, group) {
|
|
$scope.contextElement = client;
|
|
$scope.contextGroup = group;
|
|
$('#edit-client').modal('toggle');
|
|
console.log(client);
|
|
};
|
|
|
|
$scope.updateClient = function (group) {
|
|
$('#edit-client').modal('toggle');
|
|
|
|
smartRequest.post('v1/client', {
|
|
id: $scope.contextElement.id,
|
|
name: $scope.contextElement.name,
|
|
group_id: group,
|
|
phone: $scope.contextElement.phone,
|
|
address: $scope.contextElement.address,
|
|
email: $scope.contextElement.email,
|
|
barcode: $scope.contextElement.barcode,
|
|
is_special_price: $scope.contextElement.special_price,
|
|
is_employee: $scope.contextElement.employee,
|
|
task: 'update'
|
|
}, function (data) {
|
|
if (data.status == 'success') {
|
|
Notification.success(data.message);
|
|
$scope.openGroup(group);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.removeClient = function (client) {
|
|
$('#client-confirm-delete').modal('toggle');
|
|
|
|
smartRequest.post('v1/client', {
|
|
id: client.id,
|
|
task: 'delete'
|
|
}, function (data) {
|
|
$scope.getGroups();
|
|
$scope.openGroup($scope.currentGroup);
|
|
if (data.message) {
|
|
Notification.success(data.message);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.lockClient = function (client) {
|
|
smartRequest.post('v1/client', {
|
|
id: client.id,
|
|
task: 'lock'
|
|
}, function (data) {
|
|
//$scope.getGroups();
|
|
//$scope.openGroup($scope.currentGroup);
|
|
if (data.message) {
|
|
Notification.success(data.message);
|
|
$scope.openClientInfo(client);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.unlockClient = function (client) {
|
|
smartRequest.post('v1/client', {
|
|
id: client.id,
|
|
task: 'unlock'
|
|
}, function (data) {
|
|
//$scope.getGroups();
|
|
//$scope.openGroup($scope.currentGroup);
|
|
if (data.message) {
|
|
Notification.success(data.message);
|
|
$scope.openClientInfo(client);
|
|
}
|
|
if (data.error_message) {
|
|
Notification.error(data.error_message);
|
|
}
|
|
});
|
|
};
|
|
|
|
$scope.pager = function (currentPage) {
|
|
smartRequest.get('v1/clients?group_id=' + $scope.currentGroup + '&page=' + $scope.currentPage, function (data) {
|
|
$scope.clients = data.clients;
|
|
$scope.pages = data.pages;
|
|
$scope.currentGroup = data.currentGroup;
|
|
$scope.total = data.total;
|
|
});
|
|
};
|
|
|
|
$scope.getClients = function () {
|
|
if ($scope.search.query.length === 0) {
|
|
$scope.openGroup({id: $scope.currentGroupId});
|
|
} else {
|
|
smartRequest.post('v1/client', {
|
|
task: 'search',
|
|
name: $scope.search.query
|
|
},
|
|
function (data) {
|
|
$scope.clients = data.clients;
|
|
if (data.clients.length > 0) {
|
|
Notification.success(data.message);
|
|
} else {
|
|
Notification.error(data.message);
|
|
}
|
|
});
|
|
}
|
|
};
|
|
|
|
$scope.openFormCreateGroup = function () {
|
|
$scope.currentClientId = 0;
|
|
$scope.isCreateNewClient = false;
|
|
$scope.isCreateNewBarcode = false;
|
|
$scope.isCreateNewGroup = !$scope.isCreateNewGroup;
|
|
};
|
|
|
|
$scope.openFormCreateClient = function () {
|
|
$scope.currentClientId = 0;
|
|
$scope.isCreateNewGroup = false;
|
|
$scope.isCreateNewBarcode = false;
|
|
$scope.isCreateNewClient = !$scope.isCreateNewClient;
|
|
};
|
|
|
|
$scope.openFormCreateBarcode = function () {
|
|
$scope.currentClientId = 0;
|
|
$scope.isCreateNewGroup = false;
|
|
$scope.isCreateNewClient = false;
|
|
$scope.isCreateNewBarcode = !$scope.isCreateNewBarcode;
|
|
smartRequest.get('v1/clientgroup', function (data) {
|
|
$scope.groups = data.groups;
|
|
});
|
|
};
|
|
|
|
$scope.createGroup = function () {
|
|
smartRequest.post('client/group/create', {
|
|
name: $scope.newGroup.name
|
|
}, function (data) {
|
|
$scope.getGroups();
|
|
$scope.closeCard();
|
|
});
|
|
};
|
|
|
|
$scope.createClient = function () {
|
|
smartRequest.post('v1/createclient/', {
|
|
name: $scope.newClient.name,
|
|
group_id: $scope.currentGroup,
|
|
phone: $scope.newClient.phone,
|
|
address: $scope.newClient.address,
|
|
email: $scope.newClient.email,
|
|
barcode: $scope.newClient.barcode,
|
|
is_special_price: $scope.newClient.special_price,
|
|
is_employee: $scope.newClient.employee
|
|
}, function (data) {
|
|
$scope.pager($scope.currentGroup);
|
|
$scope.closeCard();
|
|
});
|
|
};
|
|
|
|
$scope.createBarcode = function () {
|
|
console.log($scope.newBarcode.group_id);
|
|
smartRequest.post('v1/createbarcode/', {
|
|
group_id: $scope.newBarcode.group_id,
|
|
start: $scope.newBarcode.start,
|
|
end: $scope.newBarcode.end,
|
|
}, function (data) {
|
|
$scope.getGroups();
|
|
$scope.closeCard();
|
|
});
|
|
};
|
|
|
|
$scope.closeCard = function () {
|
|
$scope.isCreateNewGroup = false;
|
|
$scope.isCreateNewClient = false;
|
|
$scope.isCreateNewBarcode = false;
|
|
$scope.currentClientId = 0;
|
|
};
|
|
|
|
$scope.openClientInfo = function (client) {
|
|
$('#actions_tab').tab('show')
|
|
$scope.currentClientId = client.id;
|
|
$scope.isCreateNewGroup = false;
|
|
$scope.isCreateNewClient = false;
|
|
$scope.isCreateNewBarcode = false;
|
|
$scope.orders = [];
|
|
$scope.currentClient = [];
|
|
$scope.clientLogs = [];
|
|
smartRequest.get('v1/clientinfo?id=' + $scope.currentClientId, function (data) {
|
|
$scope.currentClient = data.client;
|
|
smartRequest.get('v1/clientlog?id=' + $scope.currentClient.id, function (data) {
|
|
$scope.clientLogs = data.client.info;
|
|
});
|
|
});
|
|
};
|
|
|
|
$scope.getOrders = function (client_id) {
|
|
smartRequest.get('v1/clientorders?id=' + client_id, function (data) {
|
|
$scope.orders = data.orders;
|
|
});
|
|
};
|
|
|
|
$scope.getItems = function (order_id, opened, closed) {
|
|
smartRequest.get('v1/clientorderinfo?order_id=' + order_id + '&opened=' + opened + '&closed=' + closed, function (data) {
|
|
$scope.order = data.info;
|
|
$('#order').modal('toggle');
|
|
});
|
|
};
|
|
|
|
var mergeFiles = function (statuses) {
|
|
if (statuses == 4) {
|
|
smartRequest.get('v1/clientfile?complete=1', function (data) {
|
|
$scope.filedate = data.filedate;
|
|
$scope.filename = data.filename;
|
|
$scope.terminalkey = data.terminalKey;
|
|
$scope.downloadClientFile();
|
|
$scope.statuses = [];
|
|
});
|
|
}
|
|
};
|
|
|
|
$scope.createClientFile = function (count) {
|
|
smartRequest.get('v1/clientfile?th=1', function (data) {
|
|
if (data.status == 'success') {
|
|
$scope.statuses.push(data.status);
|
|
console.log($scope.statuses);
|
|
$scope.statusCount = $scope.statuses.length;
|
|
mergeFiles($scope.statusCount);
|
|
}
|
|
});
|
|
smartRequest.get('v1/clientfile?th=2', function (data) {
|
|
if (data.status == 'success') {
|
|
$scope.statuses.push(data.status);
|
|
console.log($scope.statuses);
|
|
$scope.statusCount = $scope.statuses.length;
|
|
mergeFiles($scope.statusCount);
|
|
}
|
|
});
|
|
smartRequest.get('v1/clientfile?th=3', function (data) {
|
|
if (data.status == 'success') {
|
|
$scope.statuses.push(data.status);
|
|
console.log($scope.statuses);
|
|
$scope.statusCount = $scope.statuses.length;
|
|
mergeFiles($scope.statusCount);
|
|
}
|
|
});
|
|
smartRequest.get('v1/clientfile?th=4', function (data) {
|
|
if (data.status == 'success') {
|
|
$scope.statuses.push(data.status);
|
|
console.log($scope.statuses);
|
|
$scope.statusCount = $scope.statuses.length;
|
|
mergeFiles($scope.statusCount);
|
|
}
|
|
});
|
|
};
|
|
|
|
|
|
$scope.downloadClientFile = function () {
|
|
smartRequest.get('v1/clientgroup', function (data) {
|
|
window.open(window.location.protocol + '//' + window.location.hostname + '/Exchange/' + $scope.terminalkey + '/' + $scope.filename);
|
|
});
|
|
};
|
|
|
|
$scope.clientsSearch = function () {
|
|
if (promise) {
|
|
$timeout.cancel(promise);
|
|
}
|
|
promise = $timeout(function () {
|
|
if ($scope.search.query.length === 0) {
|
|
$scope.getGroups();
|
|
} else {
|
|
$scope.groups = [];
|
|
}
|
|
|
|
$scope.getClients();
|
|
}, 300);
|
|
};
|
|
|
|
$scope.clearSearchInput = function () {
|
|
$scope.search.query = '';
|
|
$scope.clientsSearch();
|
|
};
|
|
|
|
$scope.getGroups();
|
|
}
|
|
}
|
|
)(); |