(function() { 'use strict'; angular .module('app') .controller('ReportsCtrl', ReportsCtrl); ReportsCtrl.$inject = ['$scope', 'smartRequest', 'Notification']; function ReportsCtrl($scope, 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.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('v1/reports', function(data) { $scope.history = data.reports; }); smartRequest.get('v1/settings?code=11', function (data) { $scope.delete_shift_value = data.value; }); }; $scope.deleteReport = function (report) { 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(); }, 1000); } if ($scope.status == 'error') { Notification.error(data.message); } }); }; $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($('
').append($(elem).clone()).html()); }; $scope.update(); } })();