(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') { return outputValue.toFixed(2); } else { return 0.00; } }; }) .controller('ShiftsCtrl', ShiftsCtrl); ShiftsCtrl.$inject = ['$scope', '$filter', 'smartRequest', 'Notification']; 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 = ''; 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.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.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.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) { 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.update(); $('#shift-delete').modal(); } else { Notification.error(data.message); } }); }; $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.start_date = shift.opened; $scope.end_date = shift.closed; $scope.update(); $('#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.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.update(); $('#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; $scope.update(); $('#report-payment').modal(); }); }; $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.update(); $('#report-out').modal(); } }); }; $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.popup = function (data) { var mywindow = window.open(); mywindow.document.write(data); mywindow.print(); mywindow.close(); }; $scope.printElem = function (elem) { $scope.popup($('
').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(); } })();