Files
admin-php-module/web/controllers/dashboard.js
miroman-afk c4dc6e02a0 v.2.30
Добавлен расширенный отчет по реализации
Добавлен монитор активности
2023-08-03 11:05:15 +03:00

926 lines
38 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// code style: https://github.com/johnpapa/angular-styleguide
(function () {
'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' && outputValue !== null) {
return outputValue.toFixed(2);
} else {
return 0.00;
}
};
})
.controller('DashboardCtrl', DashboardCtrl);
DashboardCtrl.inject = ['$scope', 'smartRequest', '$interval', '$location', 'Notification'];
function DashboardCtrl($scope, smartRequest, $interval, $location, Notification) {
/*$(document).ready(function () {
/!*if (moment(moment().format('YYYY-MM-DD')).isAfter('2021-12-25')) {
if (moment(moment().format('YYYY-MM-DD')).isBefore('2022-01-10')) {
smartRequest.get('v1/topdishesnewyear', function (data) {
$scope.year_count = data.count;
$scope.top_dishes = data.dishes;
$scope.top_shifts = data.top_shift;
$scope.in_file = data.in_file
if ($scope.in_file == 1) {
var delayMs = 1000; // delay in millisecondsget-more-staff
setTimeout(function(){
$('#get-more-newyear').modal('show');
}, delayMs);
if ($( window ).width() < 800) {
$('#get-more-newyear').on('show.bs.modal', function () {
$('.my-modal').css('z-index', 1060);
$('.my-modal-dialog').css('margin-right',$( window ).width()-$( window ).width());
$('.my-modal-dialog').css('margin-left',$( window ).width()-$( window ).width());
$('.my-modal-dialog').css('margin-top',$( window ).height()-$( window ).height());
$('.my-modal-content').css('height',$( window ).height()*0.95);
$('.my-modal-content').css('width',$( window ).width());
$('.myCarousel').css('height', $( window ).height()*0.94);
$('.myCarousel').css('width', 'auto');
$('.myCarousel').css('object-fit', 'cover');
});
} else {
$('#get-more-newyear').on('show.bs.modal', function () {
$('.my-modal').css('z-index', 1060);
$('.my-modal-dialog').css('margin-right',$( window ).width()/4);
$('.my-modal-dialog').css('margin-left',$( window ).width()/4);
$('.my-modal-dialog').css('margin-top',$( window ).height()/8);
$('.my-modal-content').css('height',$( window ).height()*0.7);
$('.my-modal-content').css('width',$( window ).width()*0.5);
$('.myCarousel').css('height', $( window ).height()*0.7);
$('.myCarousel').css('width', 'auto');
$('.myCarousel').css('object-fit', 'cover');
});
}
}
});
}
}*!/
*/
//Отображение текущего времени
$scope.currentDate = new Date();
var timer = $interval(function () {
$scope.currentDate = new Date();
}, 1000);
$scope.nextImage = function () {
$('.carousel').carousel('next');
};
$scope.previousImage = function () {
$('.carousel').carousel('prev');
};
//Автоматическое обновление данных
$scope.timerEnabled = false;
$scope.timeRemaining = new Date(0, 0, 0, 0, 1, 0);
var updateTimer = null;
$scope.toggleTimer = function () {
if ($scope.timerEnabled) {
startTimer();
} else {
stopTimer();
}
};
function startTimer() {
if (updateTimer === null) {
updateTimer = $interval(function () {
$scope.timeRemaining.setSeconds($scope.timeRemaining.getSeconds() - 1);
//console.log($scope.timeRemaining.getSeconds());
if ($scope.timeRemaining.getMinutes() === 0 && $scope.timeRemaining.getSeconds() === 0) {
stopTimer();
$scope.timeRemaining = new Date(0, 0, 0, 0, 1, 0);
console.log('Данные обновлены');
smartRequest.get('v1/clearcache?folder=dashboard', function (data) {
});
$scope.update();
startTimer();
}
}, 1000);
}
}
function stopTimer() {
if (updateTimer !== null) {
$interval.cancel(updateTimer);
updateTimer = null;
}
}
//Остановка таймеров
$scope.$on('$destroy', function () {
$interval.cancel(timer);
$interval.cancel(updateTimer);
});
$scope.dataTablesOpt = {
language: {
url: "https://cdn.datatables.net/plug-ins/1.13.3/i18n/ru.json",
},
autoWidth: false,
searching: true,
paging: false,
info: false,
};
/* $scope.dtoptions = {
/!*dom: "lfBrtip",*!/
language: {
url: "https://cdn.datatables.net/plug-ins/1.13.3/i18n/ru.json",
},
autoWidth: true,
searching: true,
paging: false,
info: false,
aoColumns: [
{title: "#"},
{title: "Гость", visible: false},
{title: "Статус", className: "text-right"},
{title: "Открыт", className: "text-right"},
{title: "Закрыт", className: "text-right"},
{title: "Сумма, BYN", className: "text-right"}
]
/!*buttons: [
{text: 'Экспорт в PDF', className: 'md-btn md-raised m-b-sm blue', extend: 'pdf'},
]*!/
};*/
$scope.orders_closed = {
percent: 0,
total: 0,
sum: 0
};
$scope.orders_waited = {
percent: 0,
total: 0,
sum: 0
};
$scope.orders_cancellations = {
percent: 0,
total: 0,
sum: 0
};
$scope.orders_deleted = {
percent: 0,
total: 0,
sum: 0
};
$scope.orders_returned = {
percent: 0,
total: 0,
sum: 0
};
$scope.middle = 0;
$scope.total = 0;
$scope.guests = 0;
$scope.namedGuests = 0;
$scope.profit = 0;
$scope.deleted = 0;
$scope.deleted_sum = 0;
$scope.discounts = 0;
$scope.discounts_sum = 0;
$scope.bill = 0;
$scope.personals = [];
$scope.dishes = [];
$scope.need_update = false;
$scope.shiftInfo = {};
$scope.folders = {
data: [],
labels: [],
options: {
legend: {
display: true
},
tooltips: {
mode: 'nearest',
displayColors: false
}
}
};
$scope.printers = {
data: [],
labels: [],
options: {
legend: {
display: true
},
tooltips: {
mode: 'nearest',
displayColors: false
}
}
};
$scope.menus = {
data: [],
labels: [],
options: {
legend: {
display: true
},
tooltips: {
mode: 'nearest',
displayColors: false
}
}
};
$scope.payments = {
data: [[]],
labels: [],
options: {
legend: {
display: true
},
tooltips: {
mode: 'nearest',
displayColors: false
}
}
};
$scope.update_time = '';
$scope.colors = [
{
backgroundColor: '#97bbcd',
borderColor: '#97bbcd',
hoverBackgroundColor: '#97bbcd',
hoverBorderColor: '#97bbcd'
},
{
backgroundColor: '#F7464A',
borderColor: '#F7464A',
hoverBackgroundColor: '#F7464A',
hoverBorderColor: '#F7464A'
},
{
backgroundColor: '#46BFBD',
borderColor: '#46BFBD',
hoverBackgroundColor: '#46BFBD',
hoverBorderColor: '#46BFBD'
}
];
//for widget mediana guests
$scope.medianGuests = {
series: ['Количество'],
data: [[]],
labels: [],
options: {
tooltips: {
mode: 'nearest',
displayColors: false,
callbacks: {
title: function (tooltipItems, data) {
var time = tooltipItems[0].xLabel;
var nextTime = moment(time).add(30, 'm');
return time.format('HH:mm') + ' - ' + nextTime.format('HH:mm');
}
}
},
scales: {
xAxes: [{
type: 'time',
bounds: 'ticks',
time: {
unit: 'hour',
unitStepSize: 0.5,
displayFormats: {
'hour': 'HH:mm'
},
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
}
};
//for widget mediana finance
$scope.medianFinance = {
data: [[], [], []],
labels: [],
series: ['Выручка', 'Себестоимость', 'Прибыль'],
options: {
legend: {
display: true
},
scales: {
xAxes: [{
type: 'time',
bounds: 'ticks',
time: {
unit: 'hour',
unitStepSize: 0.5,
displayFormats: {
'hour': 'HH:mm'
}
}
}],
yAxes: [{
ticks: {
beginAtZero: true
}
}]
},
tooltips: {
callbacks: {
title: function (tooltipItems, data) {
var time = tooltipItems[0].xLabel;
var nextTime = moment(time).add(30, 'm');
return time.format('HH:mm') + ' - ' + nextTime.format('HH:mm');
}
}
}
}
};
$scope.NOT_CLOSED = 'не закрыт';
$scope.checkUpdate = function () {
smartRequest.get('dashboard/ping', function (data) {
$scope.need_update = data.data.update;
});
};
$scope.clearCache = function () {
smartRequest.get('v1/clearcache?folder=dashboard', function (data) {
});
};
$scope.update = function () {
smartRequest.get('dashboard/online/updatetime', function (data) {
$scope.update_time = data.updated;
});
smartRequest.get('dashboard/online/folders', function (data) {
$scope.folders.labels = data.folders.map(folder => folder.name);
$scope.folders.data = data.folders.map(folder => Math.roundClearNG(folder.count));
});
smartRequest.get('dashboard/online/printers', function (data) {
$scope.printers.labels = [];
$scope.printers.data = [];
for (var i = 0; i < data.printers.length; i++) {
$scope.printers.labels.push(data.printers[i].name);
$scope.printers.data.push(Math.roundClearNG(data.printers[i].count, -2));
}
});
smartRequest.get('v1/dashboard?method=tables&type=online', function (data) {
$scope.tables = data.tables;
});
smartRequest.get('dashboard/online/menu', function (data) {
$scope.menus.labels = [];
$scope.menus.data = [];
for (var i = 0; i < data.menus.length; i++) {
$scope.menus.labels.push(data.menus[i].menu_name);
$scope.menus.data.push(Math.roundClearNG(data.menus[i].count, -2));
}
});
smartRequest.get('dashboard/online/payments', function (data) {
$scope.payments.labels = data.payments.map(payment => payment.name);
$scope.payments.data = data.payments.map(payment => payment.value);
});
smartRequest.get('v1/dashboard?method=info', function (data) {
$scope.shiftInfo = data;
});
smartRequest.get('v1/dashboard?method=total', function (data) {
$scope.total = data.total;
var total_closed = data.waited_count + data.closed_count + data.cancellations_count;
var total_dr = data.deleted_count + data.returned_count;
$scope.orders_closed.percent = $scope.calcPercentageForGroupOrders(total_closed, data.closed_count);
$scope.orders_closed.total = data.closed_count;
$scope.orders_closed.sum = data.closed_sum;
$scope.orders_waited.percent = $scope.calcPercentageForGroupOrders(total_closed, data.waited_count);
$scope.orders_waited.total = data.waited_count;
$scope.orders_waited.sum = data.waited_sum;
$scope.orders_cancellations.percent = $scope.calcPercentageForGroupOrders(total_closed, data.cancellations_count);
$scope.orders_cancellations.total = data.cancellations_count;
$scope.orders_cancellations.sum = data.cancellations_sum;
$scope.orders_deleted.percent = $scope.calcPercentageForGroupOrders(total_dr, data.deleted_count);
$scope.orders_deleted.total = data.deleted_count;
$scope.orders_deleted.sum = data.deleted_sum;
$scope.orders_returned.percent = $scope.calcPercentageForGroupOrders(total_dr, data.returned_count);
$scope.orders_returned.total = data.returned_count;
$scope.orders_returned.sum = data.returned_sum;
});
smartRequest.get('v1/dashboard?method=staff&type=online', function (data) {
$scope.personals = data.staff;
});
smartRequest.get('v1/topdishes', function (data) {
$scope.dishes = data.dishes;
});
smartRequest.get('v1/dashboard?method=profit', function (data) {
$scope.profit = data.profit;
$scope.middle = data.middle;
$scope.guests = data.guests;
});
smartRequest.get('v1/dashboard?method=guests', function (data) {
$scope.namedGuests = data.namedGuests;
$scope.sumNamedGuests = data.totalSum;
});
smartRequest.get('v1/dashboard?method=discounts&type=online', function (data) {
$scope.discounts = Math.roundNG(data.count, -2);
$scope.discounts_sum = Math.roundNG(data.sum, -2);
$scope.tot_disc_sum = Math.roundNG(data.total_sum, -2);
});
smartRequest.get('v1/dashboard?method=guests&type=median', function (data) {
$scope.medianGuests.labels = [];
$scope.medianGuests.data = [[]];
var tempData = [];
var tempTime = [];
for (var i = 0; i < data.data.length; i++) {
var newDate = $scope.getMomentDate(data.data[i].time);
tempData.push(parseInt(data.data[i].count));
tempTime.push(newDate);
var indexTime = $scope.getIntervals(tempTime[i], $scope.medianGuests.labels);
if (indexTime == -1) {
$scope.medianGuests.labels.push(tempTime[i]);
$scope.medianGuests.data[0].push(tempData[i]);
} else {
$scope.medianGuests.data[0][indexTime] += tempData[i];
}
}
});
smartRequest.get('dashboard/online/finance/median', function (data) {
$scope.medianFinance.labels = [];
$scope.medianFinance.data = [[], [], []];
var tempSum = [];
var tempTotalCost = [];
var tempProffit = [];
var tempTime = [];
for (var i = 0; i < data.data.length; i++) {
var newDate = $scope.getMomentDate(data.data[i].time);
tempSum.push(data.data[i].sum);
tempTotalCost.push(data.data[i].totalCost);
var proffit = parseFloat((tempSum[i] - tempTotalCost[i]).toFixed(2));
tempProffit.push(proffit);
tempTime.push(newDate);
var indexTime = $scope.getIntervals(tempTime[i], $scope.medianFinance.labels);
$scope.fillMedianFinance(indexTime, tempTime[i], tempSum[i], tempTotalCost[i], tempProffit[i]);
}
for (var i = 0; i < $scope.medianFinance.data.length; i++) {
for (var j = 0; j < $scope.medianFinance.data[i].length; j++) {
var data = $scope.medianFinance.data[i][j];
data = Math.round(data * 100) / 100;
$scope.medianFinance.data[i][j] = data;
}
}
});
$scope.checkUpdate();
};
$scope.update();
$scope.ping = function () {
let stop = $interval(function () {
if ($location.url() == '/dashboard') {
smartRequest.get('dashboard/ping', function (data) {
$scope.need_update = data.data.update;
if (!$scope.need_update) {
$scope.update();
$interval.cancel(stop);
}
});
}
}, 10000);
};
$scope.ping();
$scope.all_widgets = [];
$scope.add = function () {
smartRequest.get('settings/widgets/all', function (data) {
$scope.all_widgets = data.widgets;
});
$('#add-widget').modal();
};
$scope.calcPercentageForGroupOrders = function (total, countOrdersGroup) {
return total > 0 ? Math.round(countOrdersGroup * 100 / total) : 0;
};
$scope.addWidget = function () {
$('#add-widget').modal('toggle');
smartRequest.post('settings/widgets/enable', {
code: $scope.add_widget_code
}, function (data) {
$scope.update();
});
};
$scope.deleteWidget = function (code) {
smartRequest.post('settings/widgets/disable', {
code: code
}, function (data) {
$scope.update();
});
};
$scope.getMomentDate = function (date_str) {
var momentTime = moment(date_str, 'DD.MM.YYYY HH:mm:ss'); // Создаем объект Moment из строки времени
var minutes = momentTime.minute(); // Получаем количество минут в объекте Moment
if (minutes > 30) {
minutes = 30;
} else {
minutes = 0;
}
return moment(momentTime).set('minutes', minutes).set('second', 0);
};
$scope.getIntervals = function (momentTime, array) {
for (var i = 0; i < array.length; i++) {
var time = array[i];
if (time.get('hour') == momentTime.get('hour') && time.get('minute') == momentTime.get('minute')) {
return i;
}
}
return -1;
};
$scope.fillMedianFinance = function (index, time, sum, totalCost, proffit) {
if (index == -1) {
$scope.pushToMedianFinance(time, sum, totalCost, proffit);
} else {
$scope.incMedianFinance(index, sum, totalCost, proffit);
}
};
$scope.pushToMedianFinance = function (time, sum, totalCost, proffit) {
$scope.medianFinance.labels.push(time);
$scope.medianFinance.data[0].push(sum);
$scope.medianFinance.data[1].push(totalCost);
$scope.medianFinance.data[2].push(proffit);
};
$scope.incMedianFinance = function (index, sum, totalCost, proffit) {
$scope.medianFinance.data[0][index] += sum;
$scope.medianFinance.data[1][index] += totalCost;
$scope.medianFinance.data[2][index] += proffit;
};
$scope.getMore = function (code) {
smartRequest.get('dashboard/more/' + code, function (data) {
$scope.moreData = data;
$('#get-more-' + code).modal();
});
};
$scope.getOrderInfo = function (order_id, opened, closed) {
$scope.clients_modal = false;
$scope.orders_modal = true;
smartRequest.get('v1/orderhistory?order_id=' + order_id, function (actions) {
$scope.actions = actions;
});
smartRequest.get('v1/orderinfo?order_id=' + order_id + '&opened=' + opened + '&closed=' + closed, function (data) {
$scope.order = data.info;
$scope.cols = 5;
if ($scope.order.returned_count > 0) {
$scope.cols = $scope.cols + 1;
}
if ($scope.order.deleted_count > 0) {
$scope.cols = $scope.cols + 1;
}
$scope.backModal('orders', 'order');
});
};
$scope.closeModal = function (modalName) {
$scope.modalName = '#' + modalName;
$('.modal-body').scrollTop(0);
$($scope.modalName).modal('dispose');
return true;
};
$scope.backModal = function (prevModalName, targetModalName) {
$scope.prevModalName = '#' + prevModalName;
$scope.targetModalName = '#' + targetModalName;
$('.modal-body').scrollTop(0);
$($scope.prevModalName).modal('hide');
$($scope.targetModalName).modal('toggle');
return true;
};
$scope.getMoreTotal = function (type) {
$scope.type = type;
$scope.guests_info = false;
$scope.deleted_info = false;
$scope.discount_info = false;
smartRequest.get('v1/roommap?method=statistic&type=full', function (data) {
$scope.staff_name = false;
$scope.waited_count = data.waited_count;
$scope.waited_sum = data.waited_sum;
$scope.closed_count = data.closed_count;
$scope.closed_sum = data.closed_sum;
$scope.deleted_count = data.deleted_count;
$scope.deleted_sum = data.deleted_sum;
$scope.returned_count = data.returned_count;
$scope.returned_sum = data.returned_sum;
$scope.cancellations_count = data.cancellations_count;
$scope.cancellations_sum = data.cancellations_sum;
$scope.orders = data.orders;
$scope.orders.forEach(function (order) {
$scope.title = '';
if (order.is_printed_before_edit) {
$scope.title = $scope.title + ' Распечатан предчек до удаления позиции!<br>';
}
if (order.hasMove) {
$scope.title = $scope.title + ' Использовался перенос заказа!<br>';
}
if (order.hasMerge) {
$scope.title = $scope.title + ' Использовалось объединение заказов!<br>';
}
if (order.hasSlice) {
$scope.title = $scope.title + ' Использовалось разбиение заказа!<br>';
}
if (order.hasDelete) {
$scope.title = $scope.title + ' Присутствует удаление товаров!<br>';
}
order.title = $scope.title;
});
if ($scope.waited_count + $scope.closed_count + $scope.deleted_count + $scope.returned_count + $scope.cancellations_count > 0) {
$('#orders').modal('show');
} else {
Notification.error('Заказы отсутствуют');
}
});
};
$scope.getMoreGuests = function (type) {
$scope.guests_info = true;
$scope.type = type;
$scope.deleted_info = false;
$scope.discount_info = false;
smartRequest.get('v1/roommap?method=statistic&type=full&guests=true', function (data) {
$scope.staff_name = false;
$scope.waited_count = data.waited_count;
$scope.waited_sum = data.waited_sum;
$scope.closed_count = data.closed_count;
$scope.closed_sum = data.closed_sum;
$scope.deleted_count = data.deleted_count;
$scope.deleted_sum = data.deleted_sum;
$scope.returned_count = data.returned_count;
$scope.returned_sum = data.returned_sum;
$scope.cancellations_count = data.cancellations_count;
$scope.cancellations_sum = data.cancellations_sum;
$scope.orders = data.orders;
$scope.orders.forEach(function (order) {
$scope.title = '';
if (order.is_printed_before_edit) {
$scope.title = $scope.title + ' Распечатан предчек до удаления позиции!<br>';
}
if (order.hasMove) {
$scope.title = $scope.title + ' Использовался перенос заказа!<br>';
}
if (order.hasMerge) {
$scope.title = $scope.title + ' Использовалось объединение заказов!<br>';
}
if (order.hasSlice) {
$scope.title = $scope.title + ' Использовалось разбиение заказа!<br>';
}
if (order.hasDelete) {
$scope.title = $scope.title + ' Присутствует удаление товаров!<br>';
}
order.title = $scope.title;
});
if ($scope.waited_count + $scope.closed_count + $scope.deleted_count + $scope.returned_count + $scope.cancellations_count > 0) {
$('#orders').modal('show');
} else {
Notification.error('Заказы отсутствуют');
}
});
};
$scope.getMoreStaff = function (staff, type) {
$scope.type = type;
$scope.guests_info = false;
$scope.deleted_info = false;
$scope.discount_info = false;
smartRequest.get('v1/roommap?method=statistic&type=full&staff_id=' + staff.code, function (data) {
$scope.staff_name = staff.name;
$scope.waited_count = data.waited_count;
$scope.waited_sum = data.waited_sum;
$scope.closed_count = data.closed_count;
$scope.closed_sum = data.closed_sum;
$scope.deleted_count = data.deleted_count;
$scope.deleted_sum = data.deleted_sum;
$scope.returned_count = data.returned_count;
$scope.returned_sum = data.returned_sum;
$scope.cancellations_count = data.cancellations_count;
$scope.cancellations_sum = data.cancellations_sum;
$scope.orders = data.orders;
$scope.orders.forEach(function (order) {
$scope.title = '';
if (order.is_printed_before_edit) {
$scope.title = $scope.title + ' Распечатан предчек до удаления позиции!<br>';
}
if (order.hasMove) {
$scope.title = $scope.title + ' Использовался перенос заказа!<br>';
}
if (order.hasMerge) {
$scope.title = $scope.title + ' Использовалось объединение заказов!<br>';
}
if (order.hasSlice) {
$scope.title = $scope.title + ' Использовалось разбиение заказа!<br>';
}
if (order.hasDelete) {
$scope.title = $scope.title + ' Присутствует удаление товаров!<br>';
}
order.title = $scope.title;
});
if ($scope.waited_count + $scope.closed_count + $scope.deleted_count + $scope.returned_count + $scope.cancellations_count > 0) {
$('#orders').modal('show');
} else {
Notification.error('Заказы отсутствуют');
}
});
};
$scope.getMoreDeleted = function () {
$scope.guests_info = false;
$scope.deleted_info = true;
$scope.discount_info = false;
smartRequest.get('v1/roommap?method=statistic&type=full&deleted=true', function (data) {
$scope.waited_count = data.waited_count;
$scope.waited_sum = data.waited_sum;
$scope.closed_count = data.closed_count;
$scope.closed_sum = data.closed_sum;
$scope.deleted_count = data.deleted_count;
$scope.deleted_sum = data.deleted_sum;
$scope.returned_count = data.returned_count;
$scope.returned_sum = data.returned_sum;
$scope.cancellations_count = data.cancellations_count;
$scope.cancellations_sum = data.cancellations_sum;
$scope.orders = data.orders;
$scope.orders.forEach(function (order) {
$scope.title = '';
if (order.is_printed_before_edit) {
$scope.title = $scope.title + ' Распечатан предчек до удаления позиции!<br>';
}
if (order.hasMove) {
$scope.title = $scope.title + ' Использовался перенос заказа!<br>';
}
if (order.hasMerge) {
$scope.title = $scope.title + ' Использовалось объединение заказов!<br>';
}
if (order.hasSlice) {
$scope.title = $scope.title + ' Использовалось разбиение заказа!<br>';
}
if (order.hasDelete) {
$scope.title = $scope.title + ' Присутствует удаление товаров!<br>';
}
order.title = $scope.title;
});
if ($scope.waited_count + $scope.closed_count + $scope.deleted_count + $scope.returned_count + $scope.cancellations_count > 0) {
$('#orders').modal('show');
} else {
Notification.error('Заказы отсутствуют');
}
});
};
$scope.getMoreDiscount = function () {
$scope.guests_info = false;
$scope.deleted_info = false;
$scope.discount_info = true;
smartRequest.get('v1/roommap?method=statistic&type=full&discounts=true', function (data) {
$scope.waited_count = data.waited_count;
$scope.waited_sum = data.waited_sum;
$scope.closed_count = data.closed_count;
$scope.closed_sum = data.closed_sum;
$scope.deleted_count = data.deleted_count;
$scope.deleted_sum = data.deleted_sum;
$scope.returned_count = data.returned_count;
$scope.returned_sum = data.returned_sum;
$scope.cancellations_count = data.cancellations_count;
$scope.cancellations_sum = data.cancellations_sum;
$scope.orders = data.orders;
$scope.orders.forEach(function (order) {
$scope.title = '';
if (order.is_printed_before_edit) {
$scope.title = $scope.title + ' Распечатан предчек до удаления позиции!<br>';
}
if (order.hasMove) {
$scope.title = $scope.title + ' Использовался перенос заказа!<br>';
}
if (order.hasMerge) {
$scope.title = $scope.title + ' Использовалось объединение заказов!<br>';
}
if (order.hasSlice) {
$scope.title = $scope.title + ' Использовалось разбиение заказа!<br>';
}
if (order.hasDelete) {
$scope.title = $scope.title + ' Присутствует удаление товаров!<br>';
}
order.title = $scope.title;
});
if ($scope.waited_count + $scope.closed_count + $scope.deleted_count + $scope.returned_count + $scope.cancellations_count > 0) {
$('#orders').modal('show');
} else {
Notification.error('Заказы отсутствуют');
}
});
};
$scope.getItems = function (modal, order) {
$('#get-more-' + modal).modal('toggle');
smartRequest.get('dashboard/' + modal + '/items?order=' + order.number, function (data) {
$scope.order = data;
$('#items-' + modal).modal('toggle');
});
};
$scope.getTableMore = function (table) {
smartRequest.get('dashboard/more/table?place=' + table.place_name + '&table=' + table.table_name, function (data) {
$scope.table_ord = data;
$('#get-more-table').modal('toggle');
});
};
$scope.getClosedDate = function (closeTime) {
if (closeTime == '30.12.1899')
return $scope.NOT_CLOSED;
return closeTime;
};
$scope.getBackClass = function (percentProffit) {
if (percentProffit <= 25) {
return 'green-600';
} else if (percentProffit <= 35) {
return 'green';
} else if (percentProffit <= 50) {
return '';
} else if (percentProffit <= 100) {
return 'red';
}
};
var declOfNum = function (titles, number) {
number = Math.abs(number);
var cases = [2, 0, 1, 1, 1, 2];
return function (number) {
return titles[(number % 100 > 4 && number % 100 < 20) ? 2 : cases[(number % 10 < 5) ? number % 10 : 5]];
};
};
$scope.GetCountNamedGuests = declOfNum(['именованный гость', 'именованных гостя', 'именованных гостей']);
$scope.GetCountDeletedPositions = declOfNum(['товаров', 'товара', 'товаров']);
$scope.GetCountTotalOrders = declOfNum(['заказ', 'заказа', 'заказов']);
}
})();