Fixed reports
This commit is contained in:
miroman-afk
2023-05-02 15:21:54 +03:00
parent 70120653f7
commit fb46c8e739
78 changed files with 21233 additions and 1892 deletions

View File

@@ -116,12 +116,10 @@
};
$scope.editClient = function (client, group) {
$scope.contextElement = client;
$scope.contextGroup = group;
$('#edit-client').modal('toggle');
console.log(client);
console.log($scope.contextGroup);
};
$scope.updateClient = function (group) {
@@ -135,6 +133,8 @@
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') {
@@ -147,12 +147,11 @@
});
};
$scope.removeClient = function () {
$scope.removeClient = function (client) {
$('#client-confirm-delete').modal('toggle');
$('#edit-client').modal('toggle');
smartRequest.post('v1/client', {
id: $scope.contextElement.id,
id: client.id,
task: 'delete'
}, function (data) {
$scope.getGroups();
@@ -166,6 +165,40 @@
});
};
$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;
@@ -179,11 +212,17 @@
if ($scope.search.query.length === 0) {
$scope.openGroup({id: $scope.currentGroupId});
} else {
smartRequest.post('client/search', {
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);
}
});
}
};
@@ -229,7 +268,8 @@
address: $scope.newClient.address,
email: $scope.newClient.email,
barcode: $scope.newClient.barcode,
is_special_price: $scope.newClient.special_price
is_special_price: $scope.newClient.special_price,
is_employee: $scope.newClient.employee
}, function (data) {
$scope.pager($scope.currentGroup);
$scope.closeCard();
@@ -256,6 +296,7 @@
};
$scope.openClientInfo = function (client) {
$('#actions_tab').tab('show')
$scope.currentClientId = client.id;
$scope.isCreateNewGroup = false;
$scope.isCreateNewClient = false;

File diff suppressed because it is too large Load Diff

View File

@@ -1,150 +1,248 @@
(function() {
'use strict';
angular
.module('app')
.controller('ReportsCtrl', ReportsCtrl);
(function () {
'use strict';
angular
.module('app', ['ui.bootstrap', 'ui.utils'])
.controller('ReportsCtrl', ReportsCtrl);
ReportsCtrl.$inject = ['$scope', 'smartRequest', 'Notification'];
function ReportsCtrl($scope, smartRequest, Notification) {
var date = new Date();
ReportsCtrl.$inject = ['$scope', 'smartRequest', 'Notification'];
var formatted = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
function ReportsCtrl($scope, smartRequest, Notification) {
Number.prototype.toDivide = function () {
var float = String(this.toFixed(2));
if (float.length <= 6) return float;
var space = 0;
var number = '';
date.setDate(date.getDate() - 1);
for (var i = float.length - 1; i >= 0; i--) {
if (space == 3) {
number = ' ' + number;
space = 0;
}
number = float.charAt(i) + number;
space++;
}
var formatted_yesterday = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
return number;
};
var date = new Date();
$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 = [];
var formatted = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
$scope.update = function() {
smartRequest.get('v1/reports', function(data) {
$scope.history = data.reports;
});
smartRequest.get('v1/settings?code=11', function (data) {
$scope.delete_shift_value = data.value;
});
};
date.setDate(date.getDate() - 1);
$scope.deleteReport = function (report) {
$('#preload-modal').modal();
Notification.primary('Дождитесь удаления! Страница обновится автоматически.');
smartRequest.post('v1/deletedata', {
value: 'delete_report',
report_id: report.id
}, function (data) {
$scope.status = data.status;
$scope.message = data.message;
if (data.status == 'success') {
Notification.success(data.message);
setTimeout(function() {
//location.reload();
$scope.update();
$('#preload-modal').modal('hide');
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
var formatted_yesterday = ('0' + date.getDate()).slice(-2) + '.' + ('0' + (date.getMonth() + 1)).slice(-2) + '.' + date.getFullYear();
$scope.reportDelete = function() {
smartRequest.get('v1/datareport?type=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.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.dataTableOpt = {
"aoSearchCols": [
null
],
"oLanguage": {
"sUrl": 'https://cdn.datatables.net/plug-ins/1.13.3/i18n/ru.json'
},
"searching": false,
"paging": false,
"info": false,
"order": [[1, 'desc']],
};
$scope.update = function () {
smartRequest.get('v1/reports', function (data) {
$scope.history = data.reports;
$('.modal-body').scrollTop(0);
});
smartRequest.get('v1/settings?code=11', function (data) {
$scope.delete_shift_value = data.value;
});
};
$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.deleteReport = function (report) {
$('#preload-modal').modal();
Notification.primary('Дождитесь удаления! Страница обновится автоматически.');
smartRequest.post('v1/deletedata', {
value: 'delete_report',
report_id: report.id
}, function (data) {
$scope.status = data.status;
$scope.message = data.message;
if (data.status == 'success') {
Notification.success(data.message);
setTimeout(function () {
//location.reload();
$scope.update();
$('#preload-modal').modal('hide');
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$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.closeModal = function (modalName) {
$scope.modalName = '#' + modalName;
$('.modal-body').scrollTop(0);
$($scope.modalName).modal('dispose');
return true;
};
$scope.reportStaff = function() {
smartRequest.get('v1/datareport?type=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.prevModal = function (modalFromName, modalToName) {
$scope.modal_from = '#' + modalFromName;
$scope.modal_to = '#' + modalToName;
$($scope.modal_from).modal('hide');
$($scope.modal_to).modal('toggle');
};
$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.nextModal = function (modalFromName, modalToName) {
$scope.modal_from = '#' + modalFromName;
$scope.modal_to = '#' + modalToName;
$($scope.modal_from).modal('hide');
$($scope.modal_to).modal('toggle');
};
$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.getOrders = function (discount_id, modalFromName, modalToName) {
$scope.discount_id = discount_id;
$scope.orders_list = $scope.orders_info[discount_id].orders;
$scope.nextModal(modalFromName, modalToName);
};
$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.getItems = function (order_id, opened, closed, modalFromName, modalToName) {
smartRequest.get('v1/clientorderinfo?order_id=' + order_id + '&opened=' + opened + '&closed=' + closed, function (data) {
$scope.order_info = data.info;
$scope.nextModal(modalFromName, modalToName);
});
};
$scope.popup = function(data) {
var mywindow = window.open();
mywindow.document.write(data);
mywindow.print();
mywindow.close();
};
$scope.reportDiscounts = function () {
$('#preload-modal').modal();
Notification.primary('Отчет формируется. Ожидайте.');
smartRequest.get('v1/datareport?type=discounts&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.orders_info = data.orders_info;
$scope.orders_count = data.orders_count;
$scope.orders_full_sum = data.orders_full_sum;
$scope.orders_sale_sum = data.orders_sale_sum;
$scope.orders_order_sum = data.orders_order_sum;
$('#preload-modal').modal('hide');
$('#report-discounts').modal();
$scope.update();
});
};
$scope.printElem = function(elem) {
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.reportDelete = function () {
$('#preload-modal').modal();
Notification.primary('Отчет формируется. Ожидайте.');
smartRequest.get('v1/datareport?type=deleted&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.report_delete = data.orders;
$scope.totalSum = data.totalSum;
$scope.totalCount = data.totalCount;
$('#preload-modal').modal('hide');
$('#report-delete').modal();
$scope.update();
});
};
$scope.update();
}
$scope.reportRealisation = function () {
smartRequest.get('v1/datareport?type=realisation&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.update();
$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();
});
};
$scope.reportStatistic = function () {
smartRequest.get('v1/datareport?type=statistic&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.fiscal = data.fiscal;
$scope.realisation = data.realisation;
$scope.returns = data.returns;
$scope.cancellations = data.cancellations;
$scope.statistic = data.statistic;
$scope.presales = data.presales;
$scope.payments = data.payments;
$('#report-statistic').modal();
$scope.update();
});
};
$scope.reportStaff = function () {
smartRequest.get('v1/datareport?type=staff&start_date=' + encodeURIComponent($scope.start_date) + '&end_date=' + encodeURIComponent($scope.end_date), function (data) {
$scope.staffs = data.staffs;
$('#report-staff').modal();
$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();
$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();
$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;
case 'discounts':
$scope.reportDiscounts();
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) {
console.log(elem);
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.update();
}
})();

View File

@@ -1,246 +1,345 @@
(function () {
'use strict';
angular
.module('app')
.controller('ShiftsCtrl', ShiftsCtrl);
'use strict';
angular
.module('app')
.filter('curr', function () { //maybe we should take it to the filter folder
return function (input) {
if (typeof input == 'string') {
input = parseFloat(input.replace(/,/g, '.'));
}
var outputValue = input;
if (typeof outputValue !== 'undefined') {
return outputValue.toFixed(2);
} else {
return 0.00;
}
};
})
.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();
ShiftsCtrl.$inject = ['$scope', '$filter', 'smartRequest', 'Notification'];
$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.parseFloat = parseFloat;
function ShiftsCtrl($scope, $filter, smartRequest, Notification) {
Number.prototype.toDivide = function() {
var float = String(this.toFixed(2));
if(float.length <= 6) return float;
var space = 0;
var number = '';
$scope.add = function() {
$scope.reImport = {};
$('#reImport').modal();
};
for(var i = float.length - 1; i >= 0; i--) {
if(space == 3) {
number = ' ' + number;
space = 0;
}
number = float.charAt(i) + number;
space++;
}
$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();
});
smartRequest.get('v1/settings?code=11', function (data) {
$scope.delete_shift_value = data.value;
});
};
return number;
};
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.deleteShift = function (shift) {
$('#preload-modal').modal();
Notification.primary('Дождитесь удаления! Страница обновится автоматически.');
smartRequest.post('v1/deletedata', {
value: 'delete_shift',
shift_id: shift.id
}, function (data) {
$scope.status = data.status;
$scope.message = data.message;
if (data.status == 'success') {
Notification.success(data.message);
setTimeout(function() {
//location.reload();
$scope.update();
$('#preload-modal').modal('hide');
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$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.parseFloat = parseFloat;
$scope.dataTableOpt = {
"aoSearchCols": [
null
],
"oLanguage": {
"sUrl": 'https://cdn.datatables.net/plug-ins/1.13.3/i18n/ru.json'
},
"searching": false,
"paging": false,
"info": false,
"order": [[1, 'desc']],
};
$scope.reportMerged = function (shift) {
smartRequest.get('v1/datareport?type=merge&shift_id=' + shift.id, function (data) {
$scope.report_merge = data.data;
$scope.report_merge.count = data.count;
$scope.report_merge.shift_id = data.shift_id;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-merge').modal();
});
};
$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.closeModal = function (modalName) {
$scope.modalName = '#' + modalName;
$($scope.modalName).modal('dispose');
};
$scope.update = function () {
smartRequest.get('shift/list?page=' + $scope.currentPage, function (data) {
$scope.shifts = data.shifts;
$scope.countOfPages = data.pages;
$scope.pages = $scope.makePages();
$('.modal-body').scrollTop(0);
});
smartRequest.get('v1/settings?code=11', function (data) {
$scope.delete_shift_value = data.value;
});
};
$scope.deleteShift = function (shift) {
$('#preload-modal').modal();
Notification.primary('Дождитесь удаления! Страница обновится автоматически.');
smartRequest.post('v1/deletedata', {
value: 'delete_shift',
shift_id: shift.id
}, function (data) {
$scope.status = data.status;
$scope.message = data.message;
if (data.status == 'success') {
Notification.success(data.message);
setTimeout(function () {
//location.reload();
$scope.update();
$('#preload-modal').modal('hide');
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$scope.prevModal = function (modalFromName, modalToName) {
$scope.modal_from = '#' + modalFromName;
$scope.modal_to = '#' + modalToName;
$($scope.modal_from).modal('hide');
$($scope.modal_to).modal('toggle');
};
$scope.nextModal = function (modalFromName, modalToName) {
$scope.modal_from = '#' + modalFromName;
$scope.modal_to = '#' + modalToName;
$($scope.modal_from).modal('hide');
$($scope.modal_to).modal('toggle');
};
$scope.getOrders = function (discount_id, modalFromName, modalToName) {
$scope.discount_id = discount_id;
$scope.orders_list = $scope.orders_info[discount_id].orders;
$scope.nextModal(modalFromName, modalToName);
};
$scope.getItems = function (order_id, opened, closed, modalFromName, modalToName) {
smartRequest.get('v1/clientorderinfo?order_id=' + order_id + '&opened=' + opened + '&closed=' + closed, function (data) {
$scope.order_info = data.info;
$scope.nextModal(modalFromName, modalToName);
});
};
$scope.reportDiscounts = function (shift) {
smartRequest.get('v1/datareport?type=discounts&shift_id=' + shift.id, function (data) {
$scope.orders_info = data.orders_info;
$scope.orders_count = data.orders_count;
$scope.orders_full_sum = data.orders_full_sum;
$scope.orders_sale_sum = data.orders_sale_sum;
$scope.orders_order_sum = data.orders_order_sum;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-discounts').modal();
$scope.update();
});
};
$scope.reportMerged = function (shift) {
smartRequest.get('v1/datareport?type=merge&shift_id=' + shift.id, function (data) {
$scope.report_merge = data.data;
$scope.report_merge.count = data.count;
$scope.report_merge.shift_id = data.shift_id;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-merge').modal();
});
};
$scope.reportMoved = function (shift) {
smartRequest.get('v1/datareport?type=move&shift_id=' + shift.id, function (data) {
$scope.report_move = data.data;
$scope.report_move.count = data.count;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-move').modal();
});
};
$scope.reportMoved = function (shift) {
smartRequest.get('v1/datareport?type=move&shift_id=' + shift.id, function (data) {
$scope.report_move = data.data;
$scope.report_move.count = data.count;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-move').modal();
});
};
$scope.reportSliced = function (shift) {
smartRequest.get('v1/datareport?type=slice&shift_id=' + shift.id, function (data) {
$scope.report_slice = data.data;
$scope.report_slice.count = data.count;
$scope.report_slice.shift_id = data.shift_id;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-slice').modal();
});
};
$scope.reportSliced = function (shift) {
smartRequest.get('v1/datareport?type=slice&shift_id=' + shift.id, function (data) {
$scope.report_slice = data.data;
$scope.report_slice.count = data.count;
$scope.report_slice.shift_id = data.shift_id;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-slice').modal();
});
};
$scope.reportDelete = function (shift) {
smartRequest.get('v1/datareport?type=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.reportDelete = function (shift) {
smartRequest.get('v1/datareport?type=deleted&shift_id=' + shift.id, function (data) {
if (data.totalCount > 0) {
$scope.report_delete = data.orders;
$scope.total_sum = data.totalSum;
$scope.total_count = data.totalCount;
$scope.shift_id = shift.id;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$scope.update();
$('#shift-delete').modal();
$('#report-delete').modal();
});
};
} else {
Notification.error(data.message);
}
$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.reportRealisation = function (shift) {
smartRequest.get('v1/datareport?type=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.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;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$scope.update();
$('#report-realisation').modal();
});
};
$('#report-realisation').modal();
});
};
$scope.reportStatistic = function (shift) {
smartRequest.get('v1/datareport?type=statistic&shift_id=' + shift.id, function (data) {
$scope.fiscal = data.fiscal;
$scope.realisation = data.realisation;
$scope.returns = data.returns;
$scope.cancellations = data.cancellations;
$scope.statistic = data.statistic;
$scope.presales = data.presales;
$scope.payments = data.payments;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$scope.update();
$('#report-statistic').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;
$scope.reportStaff = function (shift) {
smartRequest.get('v1/datareport?type=staff&shift_id=' + shift.id, function (data) {
$scope.staffs = data.staffs;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$('#report-statistic').modal();
});
};
$scope.update();
$('#report-staff').modal();
});
};
$scope.reportStaff = function (shift) {
smartRequest.get('v1/datareport?type=staff&shift_id=' + shift.id, function (data) {
$scope.staffs = data.staffs;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$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-staff').modal();
});
};
$scope.update();
$('#report-payment').modal();
});
};
$scope.reportPay = function (shift) {
smartRequest.get('report/payment?shift_id=' + shift.id, function (data) {
$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;
$scope.printers = data.printers;
$scope.start_date = shift.opened;
$scope.end_date = shift.closed;
$scope.update();
$('#report-out').modal();
}
});
};
$('#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;
$scope.restoreShift = function (shift) {
$('#preload-modal').modal();
Notification.primary('Дождитесь загрузки! Страница обновится автоматически.');
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);
setTimeout(function () {
location.reload();
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$('#report-out').modal();
}
$scope.popup = function (data) {
var mywindow = window.open();
mywindow.document.write(data);
}, function (data) {
$scope.update();
});
};
mywindow.print();
mywindow.close();
};
$scope.restoreShift = function (shift) {
$('#preload-modal').modal();
Notification.primary('Дождитесь загрузки! Страница обновится автоматически.');
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);
setTimeout(function() {
location.reload();
}, 1000);
}
if ($scope.status == 'error') {
Notification.error(data.message);
}
});
};
$scope.printElem = function (elem) {
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.popup = function(data) {
var mywindow = window.open();
mywindow.document.write(data);
$scope.makePages = function () {
return Array.from({length: $scope.countOfPages}, (v, k) => k + 1);
};
mywindow.print();
mywindow.close();
};
$scope.showPage = function (index) {
$scope.currentPage = index;
$scope.update();
};
$scope.printElem = function(elem) {
$scope.popup($('<div/>').append($(elem).clone()).html());
};
$scope.nextPage = function () {
$scope.currentPage++;
$scope.update();
};
$scope.makePages = function () {
return Array.from({ length: $scope.countOfPages }, (v, k) => k + 1);
};
$scope.prevPage = function () {
$scope.currentPage--;
$scope.update();
};
$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();
}
$scope.update();
}
})();

271
web/controllers/staff.js Normal file
View File

@@ -0,0 +1,271 @@
(function() {
'use strict';
angular
.module('app')
.controller('StaffCtrl', StaffCtrl);
StaffCtrl.$inject = ['$scope', 'smartRequest', 'Notification', '$timeout'];
function StaffCtrl($scope, smartRequest, Notification, $timeout) {
$scope.groups = [];
$scope.personals = [];
$scope.parentGroup = 0;
$scope.parentGroupCode = '';
$scope.search = {
query: ''
};
$scope.interfaces = [];
$scope.rights = [];
$scope.currentPersonalObject = {
id: 0
};
$scope.currentGroupObject = {
id: 0
};
var promise = 0;
smartRequest.get('v1/clearcache?folder=staff', function () {});
$scope.update = function() {
smartRequest.get('staff/group/list', function(data) {
$scope.groups = data.groups;
});
};
$scope.updateGroups = function (callback, id) {
smartRequest.get('staff/group/list', function(data) {
$scope.groups = data.groups;
if (callback) {
var newGroup = $scope.getItemById($scope.groups, id);
callback(newGroup);
}
});
};
$scope.updatePersonals = function (callback, id) {
smartRequest.get('staff/list?group_code=' + $scope.parentGroupCode, function(data) {
$scope.personals = data.staff;
if (callback) {
var newStaff = $scope.getItemById($scope.personals, id);
callback(newStaff);
}
});
};
$scope.addGroup = function() {
smartRequest.post('staff/group/store', {
name: 'Новая группа'
}, function(data) {
var groupId = data.group_id;
$scope.updateGroups($scope.showGroup, groupId);
});
};
$scope.addPersonal = function() {
smartRequest.post('staff/store', {
name: 'Новый персонал',
group_code: $scope.parentGroupCode
}, function(data) {
var staffId = data.staff_id;
$scope.updatePersonals($scope.showPersonal, staffId);
});
};
$scope.openGroup = function(group) {
$scope.currentGroupObject = {
id: 0
};
$scope.parentGroup = group.id;
$scope.parentGroupCode = group.code;
$scope.personals = [];
$scope.updatePersonal();
};
$scope.showPersonal = function(personal) {
$scope.currentGroupObject = {
id: 0
};
$scope.currentPersonalObject = personal;
};
$scope.showGroup = function(group) {
$scope.currentPersonalObject = {
id: 0
};
$scope.currentGroupObject = group;
for(var i = 0; i < $scope.rights.length; i++) {
$scope.rights[i].is_active = false;
}
smartRequest.get('staff/right/list?group_code=' + $scope.currentGroupObject.code, function(data) {
for(var i = 0; i < data.rights.length; i++) {
for(var j = 0; j < $scope.rights.length; j++) {
if(data.rights[i].code === $scope.rights[j].code) {
$scope.rights[j].is_active = true;
break;
}
}
}
});
};
$scope.updatePersonal = function() {
smartRequest.get('staff/list?group_code=' + $scope.parentGroupCode, function(data) {
$scope.personals = data.staff;
});
};
$scope.closeCard = function() {
$scope.currentPersonalObject = {
id: 0
};
$scope.currentGroupObject = {
id: 0
};
};
$scope.getItemById = function(list, id) {
var res;
list.forEach(function (item) {
if (item.id == id) {
res = item;
return;
}
});
return res;
};
$scope.savePersonal = function() {
smartRequest.post('staff/update', {
id: $scope.currentPersonalObject.id,
name: $scope.currentPersonalObject.name,
password: $scope.currentPersonalObject.password,
interface_code: $scope.currentPersonalObject.interface_code,
group_code: $scope.currentPersonalObject.group_code
},
function(data) {
Notification.success('Персонал сохранен');
$scope.closeCard();
});
};
$scope.saveGroup = function() {
var activeRights = $scope.rights.filter(right => right.is_active);
smartRequest.post('staff/group/update', {
id: $scope.currentGroupObject.id,
name: $scope.currentGroupObject.name,
interface_code: $scope.currentGroupObject.interface_code,
sub_interface_code: $scope.currentGroupObject.sub_interface_code,
rights: JSON.stringify(activeRights.map(activeRight => activeRight.code))
}, function(data) {
Notification.success('Группа сохранена');
$scope.closeCard();
});
};
$scope.upFolder = function() {
$scope.currentPersonalObject = {
id: 0
};
$scope.currentGroupObject = {
id: 0
};
$scope.parentGroup = 0;
$scope.update();
};
$scope.removePersonal = function() {
$('#personal-confirm-delete').modal('toggle');
smartRequest.post('staff/delete', {
id: $scope.currentPersonalObject.id
}, function(data) {
$scope.currentPersonalObject = {
id: 0
};
$scope.updatePersonal();
});
};
$scope.removeGroup = function() {
$('#group-confirm-delete').modal('toggle');
smartRequest.post('staff/group/delete', {
id: $scope.currentGroupObject.id
}, function(data) {
$scope.currentGroupObject = {
id: 0
};
$scope.update();
});
};
$scope.personalSearch = function() {
if(promise){
$timeout.cancel(promise);
}
promise = $timeout(function() {
if($scope.search.query.length > 0) {
smartRequest.post('staff/search', {
name: $scope.search.query
},
function (data) {
$scope.personals = data.staff;
});
}
else {
$scope.upFolder();
}
}, 300);
};
$scope.setRights = function() {
$scope.removeActiveToggle();
$scope.onRightsByTemplate();
};
$scope.removeActiveToggle = function() {
$scope.rights.forEach(function (item) {
if (item.is_active) {
item.is_active = false;
}
});
};
$scope.onRightsByTemplate = function() {
smartRequest.get('staff/rights/template?code=' + $scope.currentGroupObject.interface_code + '&sub_code=' + $scope.currentGroupObject.sub_interface_code, function (data) {
for(var i = 0; i < data.rights.length; i++) {
for(var j = 0; j < $scope.rights.length; j++) {
if(data.rights[i].code === $scope.rights[j].code) {
$scope.rights[j].is_active = true;
break;
}
}
}
});
};
$scope.update();
smartRequest.get('staff/interface/list', function(data) {
$scope.interfaces = data.interfaces;
});
smartRequest.get('staff/right/all', function(data) {
$scope.rights = data.rights;
});
}
})();

View File

@@ -23,7 +23,7 @@
$scope.terminalLogs = [];
$scope.update = function () {
smartRequest.get('settings/terminals', function (data) {
smartRequest.get('v1/settings?method=terminals', function (data) {
$scope.terminals = data.terminals;
});
};