angular.module('focaModalInforme') .controller('focaModalInformeHojaRutaController', [ '$filter', '$scope', '$uibModalInstance', 'focaModalInformeHojaRutaService', 'i18nService', 'uiGridConstants', function($filter, $scope, $uibModalInstance, focaModalInformeHojaRutaService, i18nService, uiGridConstants ) { var fecha = new Date(); $scope.fechaHasta = new Date(); $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); $scope.buscar = true; $scope.informe = {}; i18nService.setCurrentLang('es'); $scope.gridOptions = { enableHorizontalScrollbar: uiGridConstants.scrollbars.ALWAYS, enableVerticalScrollbar: uiGridConstants.scrollbars.WHEN_NEEDED, enableGridMenu: true, exporterMenuCsv: false, exporterPdfPageSize: 'A4', exporterPdfFooter: function (currentPage, pageCount) { return { columns: [ {text: $filter('date')(new Date(), 'dd/MM/yyyy'), margin: [40, 0]}, {text: currentPage + ' de ' + pageCount, margin: [28, 0], alignment: 'right'} ] }; }, }; $scope.generarInforme = function() { focaModalInformeHojaRutaService .getHojasRuta( $scope.fechaDesde.toISOString().split('.')[0], $scope.fechaHasta.toISOString().split('.')[0] ) .then(function(res) { $scope.gridOptions.data = res.data.map(function(hojaRuta) { return { sucursal: hojaRuta.sucursal, numero: hojaRuta.numeroHojaRuta, transportista: hojaRuta.transportista.NOM, unidad: hojaRuta.vehiculo.codigo, chofer: hojaRuta.chofer.nombre, fechaDeReparto: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') }; }); //TODO: sacar id empresa hardcodeado return focaModalInformeHojaRutaService.getEmpresa(1); }) .then(function(res) { var filenameStamp = 'Informe de correlatividad de hojas de ruta - ' + $filter('date')(new Date(), 'dd/MM/yyyy'); $scope.informe.nombreEmpresa = res.data.NOM.trim(); $scope.informe.direccionEmpresa = res.data.DIR.trim(); $scope.gridOptions.exporterPdfFilename = filenameStamp + '.pdf'; $scope.gridOptions.exporterExcelFilename = filenameStamp + '.xlsx'; $scope.gridOptions.exporterPdfHeader = { columns: [ { text: $scope.informe.nombreEmpresa, margin: [40, 0], fontSize: 9 }, { text: '\nInforme de correlatividad de hojas de ruta', margin: [-170, -4, 0, 0], fontSize: 12 }, { text: [ '\n\nFiltros: ', 'Fecha desde: ', $filter('date')($scope.fechaDesde, 'dd/MM/yyyy'), ' Fecha hasta: ', $filter('date')($scope.fechaHasta, 'dd/MM/yyyy') ], margin: [-380, 2, 0, 0], fontSize: 9 }, { text: $scope.informe.direccionEmpresa, margin: [28, 0], alignment: 'right', fontSize: 9 } ] }; $scope.buscar = false; }); }; $scope.volver = function() { $scope.buscar = true; }; $scope.cancel = function() { $uibModalInstance.dismiss('Cancelar'); }; } ] );