Update RestoreShift frontend
This commit is contained in:
miroman-afk
2022-01-13 15:43:04 +03:00
parent f964aca7a9
commit 61d8b4e1d2
18 changed files with 1973 additions and 126 deletions

352
web/controllers/clients.js Normal file
View File

@@ -0,0 +1,352 @@
(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.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;
$('#edit-client').modal('toggle');
console.log(client);
console.log(group);
};
$scope.updateClient = function () {
$('#edit-client').modal('toggle');
smartRequest.post('v1/client', {
id: $scope.contextElement.id,
name: $scope.contextElement.name,
group_id: $scope.contextElement.client_group,
phone: $scope.contextElement.phone,
address: $scope.contextElement.address,
email: $scope.contextElement.email,
barcode: $scope.contextElement.barcode,
task: 'update'
}, function (data) {
if (data.status == 'success') {
Notification.success(data.message);
$scope.openGroup($scope.contextElement.client_group);
}
if (data.error_message) {
Notification.error(data.error_message);
}
});
};
$scope.removeClient = function () {
$('#client-confirm-delete').modal('toggle');
$('#edit-client').modal('toggle');
smartRequest.post('v1/client', {
id: $scope.contextElement.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.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('client/search', {
name: $scope.search.query
},
function (data) {
$scope.clients = data.clients;
});
}
};
$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
}, 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) {
$scope.currentClientId = client.id;
$scope.isCreateNewGroup = false;
$scope.isCreateNewClient = false;
$scope.isCreateNewBarcode = false;
smartRequest.get('client/client/info?id=' + $scope.currentClientId, function(data) {
$scope.currentClient = data.client;
smartRequest.get('client/orders?client_id=' + $scope.currentClient.id, function(data) {
$scope.orders = data.orders;
});
});
};
$scope.getItems = function(order) {
smartRequest.get('client/order?order_id=' + order.id, function(data) {
$scope.order = data;
$('#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();
}
}
)();

124
web/controllers/reports.js Normal file
View File

@@ -0,0 +1,124 @@
(function() {
'use strict';
angular
.module('app')
.controller('ReportsCtrl', ReportsCtrl);
ReportsCtrl.$inject = ['$scope', 'smartRequest'];
function ReportsCtrl($scope, smartRequest) {
var date = new Date();
var formatted = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
date.setDate(date.getDate() - 1);
var formatted_yesterday = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
$scope.report_delete = [];
$scope.report_realisation = [];
$scope.start_date = formatted_yesterday;
$scope.end_date = formatted;
$scope.report_id = 'realisation';
$scope.history = [];
$scope.statistic = {};
$scope.staffs = [];
$scope.printers = [];
$scope.update = function() {
smartRequest.get('report/history', function(data) {
$scope.history = data.reports;
});
};
$scope.reportDelete = function() {
smartRequest.get('report/deleted?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.report_delete = data.deleted;
$scope.report_delete.total_sum = data.total_sum;
$scope.report_delete.total_count = data.total_count;
$('#report-delete').modal();
}, function(data) {
$scope.update();
});
};
$scope.reportRealisation = function() {
smartRequest.get('report/realisation?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.report_realisation = data.printers;
$scope.return_printers = data.ret_prints;
$scope.report_realisation.total_count = data.total_count;
$scope.report_realisation.total_sum = data.total_sum;
$('#report-realisation').modal();
}, function(data) {
$scope.update();
});
};
$scope.reportStatistic = function() {
smartRequest.get('report/statistics?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.statistic = data.statistic;
$('#report-statistic').modal();
}, function(data) {
$scope.update();
});
};
$scope.reportStaff = function() {
smartRequest.get('report/staff?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.staffs = data.staffs;
$('#report-staff').modal();
}, function(data) {
$scope.update();
});
};
$scope.reportPay = function() {
smartRequest.get('report/payment?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function(data) {
$scope.printers = data.printers;
$('#report-payment').modal();
}, function(data) {
$scope.update();
});
};
$scope.reportOut = function () {
smartRequest.get('v1/outorders?start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.orders = data.orders;
$scope.total = data.total;
$('#report-out').modal();
}, function (data) {
$scope.update();
});
};
$scope.createReport = function() {
switch ($scope.report_id) {
case 'deleted': $scope.reportDelete(); break;
case 'realisation': $scope.reportRealisation(); break;
case 'statistics': $scope.reportStatistic(); break;
case 'staff': $scope.reportStaff(); break;
case 'pay': $scope.reportPay(); break;
case 'out': $scope.reportOut(); break;
}
};
$scope.archiveReport = function(type, start_date, end_date) {
$scope.report_id = type;
$scope.start_date = start_date;
$scope.end_date = end_date;
$scope.createReport();
};
$scope.popup = function(data) {
var mywindow = window.open();
mywindow.document.write(data);
mywindow.print();
mywindow.close();
};
$scope.printElem = function(elem) {
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.update();
}
})();

186
web/controllers/shifts.js Normal file
View File

@@ -0,0 +1,186 @@
(function () {
'use strict';
angular
.module('app')
.controller('ShiftsCtrl', ShiftsCtrl);
ShiftsCtrl.$inject = ['$scope', '$filter', 'smartRequest', 'Notification'];
function ShiftsCtrl($scope, $filter, smartRequest, Notification) {
var date = new Date();
var formatted = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
date.setDate(date.getDate() - 1);
var formatted_yesterday = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
$scope.start_date = formatted;
$scope.end_date = formatted_yesterday;
$scope.response = false;
$scope.shifts = [];
$scope.report_delete = [];
$scope.countOfPages = 1;
$scope.currentPage = 1;
$scope.statistic = {};
$scope.staffs = [];
$scope.add = function() {
$scope.reImport = {};
$('#reImport').modal();
};
$scope.create = function() {
var start_date = document.getElementById("startDate").value;
var end_date = document.getElementById("endDate").value;
console.log(start_date, end_date);
smartRequest.get('v1/import?start_date=' + encodeURIComponent(start_date) + '&end_date=' + encodeURIComponent(end_date), function(data) {
$scope.response = data.message;
if (data.message == 'shifts not found') {
Notification.error('Смены не найдены');
} else {
Notification.success('Задача создана');
$scope.update();
}
});
$('#reImport').modal('toggle');
};
$scope.update = function () {
smartRequest.get('shift/list?page=' + $scope.currentPage, function (data) {
$scope.shifts = data.shifts;
$scope.countOfPages = data.pages;
$scope.pages = $scope.makePages();
});
};
$scope.reportDelete = function (shift) {
smartRequest.get('report/deleted?shift_id=' + shift.id, function (data) {
$scope.report_delete = data.deleted;
$scope.report_delete.total_sum = data.total_sum;
$scope.report_delete.total_count = data.total_count;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-delete').modal();
});
};
$scope.reportRealisation = function (shift) {
smartRequest.get('report/realisation?shift_id=' + shift.id, function (data) {
$scope.report_realisation = data.printers;
$scope.return_printers = data.ret_prints;
$scope.report_realisation.total_count = data.total_count;
$scope.report_realisation.total_sum = data.total_sum;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-realisation').modal();
});
};
$scope.reportStatistic = function (shift) {
smartRequest.get('report/statistics?shift_id=' + shift.id, function (data) {
$scope.statistic = data.statistic;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-statistic').modal();
});
};
$scope.reportStaff = function (shift) {
smartRequest.get('report/staff?shift_id=' + shift.id, function (data) {
$scope.staffs = data.staffs;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-staff').modal();
});
};
$scope.reportPay = function (shift) {
smartRequest.get('report/payment?shift_id=' + shift.id, function (data) {
$scope.printers = data.printers;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-payment').modal();
}, function (data) {
$scope.update();
});
};
$scope.reportOut = function (shift) {
smartRequest.get('v1/outorders?shift_id=' + shift.id, function (data) {
$scope.response = data.message;
if (data.message == 'false') {
Notification.error('Внешние заказы не найдены');
} else {
$scope.orders = data.orders;
$scope.shift = data.shift;
$scope.total = data.total;
$('#report-out').modal();
}
}, function (data) {
$scope.update();
});
};
$scope.restoreShift = function (shift) {
smartRequest.post('v1/restoreshift', {
shift_id: shift.id
}, function (data) {
$scope.status = data.status;
$scope.response = data.message;
if (data.status == 'success') {
Notification.success(data.message);
console.log(data.status);
console.log(data.message);
setTimeout(function() {
location.reload();
}, 2000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$scope.popup = function(data) {
var mywindow = window.open();
mywindow.document.write(data);
mywindow.print();
mywindow.close();
};
$scope.printElem = function(elem) {
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.makePages = function () {
return Array.from({ length: $scope.countOfPages }, (v, k) => k + 1);
};
$scope.showPage = function (index) {
$scope.currentPage = index;
$scope.update();
};
$scope.nextPage = function () {
$scope.currentPage++;
$scope.update();
};
$scope.prevPage = function () {
$scope.currentPage--;
$scope.update();
};
$scope.update();
}
})();