248 lines
9.7 KiB
JavaScript
248 lines
9.7 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
angular
|
|
.module('app', ['ui.bootstrap', 'ui.utils'])
|
|
.controller('ReportsCtrl', ReportsCtrl);
|
|
|
|
ReportsCtrl.$inject = ['$scope', 'smartRequest', 'Notification'];
|
|
|
|
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 = '';
|
|
|
|
for (var i = float.length - 1; i >= 0; i--) {
|
|
if (space == 3) {
|
|
number = ' ' + number;
|
|
space = 0;
|
|
}
|
|
number = float.charAt(i) + number;
|
|
space++;
|
|
}
|
|
|
|
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.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.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.closeModal = function (modalName) {
|
|
$scope.modalName = '#' + modalName;
|
|
$('.modal-body').scrollTop(0);
|
|
$($scope.modalName).modal('dispose');
|
|
return true;
|
|
};
|
|
|
|
$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 () {
|
|
$('#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.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.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();
|
|
}
|
|
})(); |