controller-hoja-ruta.js
5.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
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');
};
}
]
);