Commit c3e03fa155abaace284afa01dca01f75a4ac3223

Authored by Jose Pinto
Exists in master and in 1 other branch develop

Merge branch 'develop' into 'master'

Develop

See merge request !7
src/js/controller-general-unidad.js
1 angular.module('focaModalInforme') 1 angular.module('focaModalInforme')
2 .controller('focaModalInformeGeneralUnidadController', 2 .controller('focaModalInformeGeneralUnidadController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalInformeGeneralUnidadService', 7 'focaModalInformeGeneralUnidadService',
8 'i18nService', 8 'i18nService',
9 'focaModalService', 9 'focaModalService',
10 function($filter, $scope, $uibModalInstance, 10 function($filter, $scope, $uibModalInstance,
11 focaModalInformeGeneralUnidadService, i18nService, focaModalService 11 focaModalInformeGeneralUnidadService, i18nService, focaModalService
12 ) { 12 ) {
13 i18nService.setCurrentLang('es'); 13 i18nService.setCurrentLang('es');
14 var fecha = new Date(); 14 var fecha = new Date();
15 $scope.generando = false; 15 $scope.generando = false;
16 $scope.buscar = true; 16 $scope.buscar = true;
17 $scope.informe = {}; 17 $scope.informe = {};
18 $scope.params = { 18 $scope.params = {
19 fechaHasta: new Date(), 19 fechaHasta: new Date(),
20 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), 20 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)),
21 sector: undefined, 21 sector: undefined,
22 diferenciarProductos: false, 22 diferenciarProductos: false,
23 diferenciarMeses: false 23 diferenciarMeses: false
24 }; 24 };
25 $scope.gridOptions = { 25 $scope.gridOptions = {
26 enableGridMenu: true, 26 enableGridMenu: true,
27 exporterMenuCsv: false, 27 exporterMenuCsv: false,
28 exporterPdfPageSize: 'A4', 28 exporterPdfPageSize: 'A4',
29 exporterPdfFooter: function (currentPage, pageCount) { 29 exporterPdfFooter: function (currentPage, pageCount) {
30 return { 30 return {
31 columns: [ 31 columns: [
32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'), 32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
33 margin: [40, 0]}, 33 margin: [40, 0]},
34 {text: currentPage + ' de ' + pageCount, 34 {text: currentPage + ' de ' + pageCount,
35 margin: [28, 0], alignment: 'right'} 35 margin: [28, 0], alignment: 'right'}
36 ] 36 ]
37 }; 37 };
38 }, 38 },
39 columnDefs: [ 39 columnDefs: [
40 { 40 {
41 field: 'vehiculo', 41 field: 'vehiculo',
42 enableSorting: false, 42 enableSorting: false,
43 cellClass: function(grid, row, col) { 43 cellClass: function(grid, row, col) {
44 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) 44 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1)
45 return 'yellow w-100'; 45 return 'yellow w-100';
46 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) 46 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1)
47 return 'red w-100'; 47 return 'red w-100';
48 if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1) 48 if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1)
49 return 'green w-100'; 49 return 'green w-100';
50 } 50 }
51 }, 51 },
52 { 52 {
53 field: 'kmRecorridos', 53 field: 'kmRecorridos',
54 enableSorting: false, 54 enableSorting: false,
55 cellClass: function(grid, row, col) { 55 cellClass: function(grid, row, col) {
56 if (!grid.getCellValue(row,col)) 56 if (!grid.getCellValue(row,col))
57 return 'd-none'; 57 return 'd-none';
58 } 58 }
59 }, 59 },
60 { 60 {
61 field: 'litrosRepartidos', 61 field: 'litrosRepartidos',
62 enableSorting: false, 62 enableSorting: false,
63 cellClass: function(grid, row, col) { 63 cellClass: function(grid, row, col) {
64 if (!grid.getCellValue(row,col)) 64 if (!grid.getCellValue(row,col))
65 return 'd-none'; 65 return 'd-none';
66 } 66 }
67 }, 67 },
68 { 68 {
69 field: 'viajes', 69 field: 'viajes',
70 enableSorting: false, 70 enableSorting: false,
71 cellClass: function(grid, row, col) { 71 cellClass: function(grid, row, col) {
72 if (!grid.getCellValue(row,col)) 72 if (!grid.getCellValue(row,col))
73 return 'd-none'; 73 return 'd-none';
74 } 74 }
75 } 75 }
76 ] 76 ]
77 }; 77 };
78 $scope.generarInforme = function() { 78 $scope.generarInforme = function() {
79 $scope.generando = true; 79 $scope.generando = true;
80 focaModalInformeGeneralUnidadService 80 focaModalInformeGeneralUnidadService
81 .getInformeData($scope.params) 81 .getInformeData($scope.params)
82 .then(function(res) { 82 .then(function(res) {
83 var result = []; 83 var result = [];
84 84
85 res.data.forEach(function(sector) { 85 res.data.forEach(function(sector) {
86 if (!$scope.params.sector || 86 if (!$scope.params.sector ||
87 $scope.params.sector.ID === sector.idSector) { 87 $scope.params.sector.ID === sector.idSector) {
88 //AGREGO SECTORES 88 //AGREGO SECTORES
89 result.push({ 89 result.push({
90 vehiculo: 'Sector: ' + 90 vehiculo: 'Sector: ' +
91 $filter('rellenarDigitos')(sector.idSector, 2, '0') + 91 $filter('rellenarDigitos')(sector.idSector, 2, '0') +
92 ' - ' + sector.sector.trim() 92 ' - ' + sector.sector.trim()
93 }); 93 });
94 if (!$scope.params.diferenciarProductos) 94 if (!$scope.params.diferenciarProductos)
95 sector.productos = unirProductos(sector.productos); 95 sector.productos = unirProductos(sector.productos);
96 96
97 sector.productos.forEach(function(producto) { 97 sector.productos.forEach(function(producto) {
98 //AGREGO PRODUCTOS 98 //AGREGO PRODUCTOS
99 if ($scope.params.diferenciarProductos){ 99 if ($scope.params.diferenciarProductos){
100 result.push({ 100 result.push({
101 vehiculo: 'Producto: ' + 101 vehiculo: 'Producto: ' +
102 producto.idProducto + 102 producto.idProducto +
103 ' - ' + producto.producto 103 ' - ' + producto.producto
104 }); 104 });
105 } 105 }
106 if (!$scope.params.diferenciarMeses) { 106 if (!$scope.params.diferenciarMeses) {
107 producto.fechas = unirFechas(producto.fechas); 107 producto.fechas = unirFechas(producto.fechas);
108 } 108 }
109 producto.fechas.forEach(function(fecha) { 109 producto.fechas.forEach(function(fecha) {
110 //AGREGO FECHAS 110 //AGREGO FECHAS
111 if ($scope.params.diferenciarMeses) { 111 if ($scope.params.diferenciarMeses) {
112 result.push({ 112 result.push({
113 vehiculo: 113 vehiculo:
114 'Fecha: ' + fecha.month + ' - ' + fecha.year 114 'Fecha: ' + fecha.month + ' - ' + fecha.year
115 }); 115 });
116 } else { 116 } else {
117 result.push({ 117 result.push({
118 vehiculo: 118 vehiculo:
119 'Fecha: ' + fecha.year 119 'Fecha: ' + fecha.year
120 }); 120 });
121 } 121 }
122 fecha.vehiculos.forEach(function(vehiculo) { 122 fecha.vehiculos.forEach(function(vehiculo) {
123 //AGREGO VEHICULOS 123 //AGREGO VEHICULOS
124 result.push({ 124 result.push({
125 vehiculo: vehiculo.vehiculo, 125 vehiculo: vehiculo.vehiculo,
126 kmRecorridos: 126 kmRecorridos:
127 $filter('number')(vehiculo.data.kms, 2), 127 $filter('number')(vehiculo.data.kms, 2),
128 litrosRepartidos: 128 litrosRepartidos:
129 $filter('number')(vehiculo.data.lts, 2), 129 $filter('number')(vehiculo.data.lts, 2),
130 viajes: 130 viajes:
131 $filter('number')(vehiculo.data.viajes, 0) 131 $filter('number')(vehiculo.data.viajes, 0)
132 }); 132 });
133 }); 133 });
134 }); 134 });
135 }); 135 });
136 } 136 }
137 }); 137 });
138 138
139 $scope.gridOptions.data = result; 139 $scope.gridOptions.data = result;
140 $scope.generando = false; 140 $scope.generando = false;
141 $scope.buscar = false; 141 $scope.buscar = false;
142 }); 142 });
143 }; 143 };
144 144
145 $scope.seleccionarSector = function(key) { 145 $scope.seleccionarSector = function(key) {
146 if (key === 13) { 146 if (key === 13) {
147 var parametrosModal = { 147 var parametrosModal = {
148 titulo: 'Búsqueda de Sector', 148 titulo: 'Búsqueda de Sector',
149 searchText: $scope.params.sector.NOMBRE,
149 query: '/sector', 150 query: '/sector',
150 columnas: [ 151 columnas: [
151 { 152 {
152 nombre: 'Código', 153 nombre: 'Código',
153 propiedad: 'ID' 154 propiedad: 'ID'
154 }, 155 },
155 { 156 {
156 nombre: 'Nombre', 157 nombre: 'Nombre',
157 propiedad: 'NOMBRE' 158 propiedad: 'NOMBRE'
158 } 159 }
159 ], 160 ],
160 size: 'md' 161 size: 'md'
161 }; 162 };
162 focaModalService.modal(parametrosModal).then( 163 focaModalService.modal(parametrosModal).then(
163 function(sector) { 164 function(sector) {
164 $scope.params.sector = sector; 165 $scope.params.sector = sector;
165 }, function() {} 166 }, function() {}
166 ); 167 );
167 } 168 }
168 }; 169 };
169 $scope.volver = function() { 170 $scope.volver = function() {
170 $scope.buscar = true; 171 $scope.buscar = true;
171 }; 172 };
172 $scope.cancel = function() { 173 $scope.cancel = function() {
173 $uibModalInstance.dismiss('Cancelar'); 174 $uibModalInstance.dismiss('Cancelar');
174 }; 175 };
175 $scope.clearSector = function() { 176 $scope.clearSector = function() {
176 $scope.params.sector = undefined; 177 $scope.params.sector = undefined;
177 }; 178 };
178 179
179 function unirProductos(productos) { 180 function unirProductos(productos) {
180 var result = [{fechas: []}]; 181 var result = [{fechas: []}];
181 productos.forEach(function(producto) { 182 productos.forEach(function(producto) {
182 producto.fechas.forEach(function(fecha) { 183 producto.fechas.forEach(function(fecha) {
183 var existe = result[0].fechas.filter(function(result) { 184 var existe = result[0].fechas.filter(function(result) {
184 return result.fecha === fecha.fecha; 185 return result.fecha === fecha.fecha;
185 }); 186 });
186 if (existe.length) { 187 if (existe.length) {
187 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); 188 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos);
188 } else { 189 } else {
189 result[0].fechas.push(fecha); 190 result[0].fechas.push(fecha);
190 } 191 }
191 192
192 }); 193 });
193 }); 194 });
194 result[0].fechas.forEach(function(fecha) { 195 result[0].fechas.forEach(function(fecha) {
195 fecha.vehiculos = unirVehiculos(fecha.vehiculos); 196 fecha.vehiculos = unirVehiculos(fecha.vehiculos);
196 }); 197 });
197 return result; 198 return result;
198 } 199 }
199 200
200 function unirFechas(fechas) { 201 function unirFechas(fechas) {
201 var results = []; 202 var results = [];
202 fechas.forEach(function(fecha) { 203 fechas.forEach(function(fecha) {
203 var existe = results.filter(function(result) { 204 var existe = results.filter(function(result) {
204 return result.year === fecha.year; 205 return result.year === fecha.year;
205 }); 206 });
206 207
207 if (existe.length) { 208 if (existe.length) {
208 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); 209 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos);
209 } else { 210 } else {
210 results.push({ 211 results.push({
211 year: fecha.year, 212 year: fecha.year,
212 vehiculos: fecha.vehiculos 213 vehiculos: fecha.vehiculos
213 }); 214 });
214 } 215 }
215 }); 216 });
216 217
217 results.forEach(function(result) { 218 results.forEach(function(result) {
218 result.vehiculos = unirVehiculos(result.vehiculos); 219 result.vehiculos = unirVehiculos(result.vehiculos);
219 }); 220 });
220 return results; 221 return results;
221 } 222 }
222 223
223 function unirVehiculos(vehiculos) { 224 function unirVehiculos(vehiculos) {
224 var results = []; 225 var results = [];
225 vehiculos.forEach(function(vehiculo) { 226 vehiculos.forEach(function(vehiculo) {
226 var existe = results.filter(function(result) { 227 var existe = results.filter(function(result) {
227 return result.vehiculo === vehiculo.vehiculo; 228 return result.vehiculo === vehiculo.vehiculo;
228 }); 229 });
229 230
230 if (existe.length) { 231 if (existe.length) {
231 existe[0].data.kms += vehiculo.data.kms; 232 existe[0].data.kms += vehiculo.data.kms;
232 existe[0].data.lts += vehiculo.data.lts; 233 existe[0].data.lts += vehiculo.data.lts;
233 existe[0].data.viajes += vehiculo.data.viajes; 234 existe[0].data.viajes += vehiculo.data.viajes;
234 } else { 235 } else {
235 results.push(vehiculo); 236 results.push(vehiculo);
236 } 237 }
237 }); 238 });
238 return results; 239 return results;
239 } 240 }
240
241
242 } 241 }
243 ] 242 ]
244 ); 243 );
src/js/controller-hoja-ruta.js
1 angular.module('focaModalInforme') 1 angular.module('focaModalInforme')
2 .controller('focaModalInformeHojaRutaController', 2 .controller('focaModalInformeHojaRutaController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalInformeHojaRutaService', 7 'focaModalInformeHojaRutaService',
8 'i18nService', 8 'i18nService',
9 'uiGridConstants', 9 'uiGridConstants',
10 function($filter, $scope, $uibModalInstance, 10 function($filter, $scope, $uibModalInstance,
11 focaModalInformeHojaRutaService, i18nService, uiGridConstants 11 focaModalInformeHojaRutaService, i18nService, uiGridConstants
12 ) { 12 ) {
13 var fecha = new Date(); 13 var fecha = new Date();
14 $scope.fechaHasta = new Date(); 14 $scope.fechaHasta = new Date();
15 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 15 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
16 $scope.buscar = true; 16 $scope.buscar = true;
17 $scope.informe = {}; 17 $scope.informe = {};
18 i18nService.setCurrentLang('es'); 18 i18nService.setCurrentLang('es');
19 $scope.gridOptions = { 19 $scope.gridOptions = {
20 enableHorizontalScrollbar: uiGridConstants.scrollbars.ALWAYS, 20 enableHorizontalScrollbar: uiGridConstants.scrollbars.ALWAYS,
21 enableVerticalScrollbar: uiGridConstants.scrollbars.WHEN_NEEDED, 21 enableVerticalScrollbar: uiGridConstants.scrollbars.WHEN_NEEDED,
22 enableGridMenu: true, 22 enableGridMenu: true,
23 exporterMenuCsv: false, 23 exporterMenuCsv: false,
24 exporterPdfPageSize: 'A4', 24 exporterPdfPageSize: 'A4',
25 exporterPdfFooter: function (currentPage, pageCount) { 25 exporterPdfFooter: function (currentPage, pageCount) {
26 return { 26 return {
27 columns: [ 27 columns: [
28 {text: $filter('date')(new Date(), 'dd/MM/yyyy'), 28 {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
29 margin: [40, 0]}, 29 margin: [40, 0]},
30 {text: currentPage + ' de ' + pageCount, 30 {text: currentPage + ' de ' + pageCount,
31 margin: [28, 0], alignment: 'right'} 31 margin: [28, 0], alignment: 'right'}
32 ] 32 ]
33 }; 33 };
34 }, 34 },
35
36 }; 35 };
37 $scope.generarInforme = function() { 36 $scope.generarInforme = function() {
38 focaModalInformeHojaRutaService 37 focaModalInformeHojaRutaService
39 .getHojasRuta( 38 .getHojasRuta(
40 $scope.fechaDesde.toISOString().split('.')[0], 39 $scope.fechaDesde.toISOString().split('.')[0],
41 $scope.fechaHasta.toISOString().split('.')[0] 40 $scope.fechaHasta.toISOString().split('.')[0]
42 ) 41 )
43 .then(function(res) { 42 .then(function(res) {
44 $scope.gridOptions.data = res.data.map(function(hojaRuta) { 43 $scope.gridOptions.data = res.data.map(function(hojaRuta) {
45 return { 44 return {
46 sucursal: hojaRuta.sucursal, 45 sucursal: hojaRuta.sucursal,
47 numero: hojaRuta.numeroHojaRuta, 46 numero: hojaRuta.numeroHojaRuta,
48 transportista: hojaRuta.transportista.NOM, 47 transportista: hojaRuta.transportista.NOM,
49 unidad: hojaRuta.vehiculo.codigo, 48 unidad: hojaRuta.vehiculo.codigo,
50 chofer: hojaRuta.chofer.nombre, 49 chofer: hojaRuta.chofer.nombre,
51 fechaDeReparto: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') 50 fechaDeReparto: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
52 }; 51 };
53 }); 52 });
54
55 //TODO: sacar id empresa hardcodeado 53 //TODO: sacar id empresa hardcodeado
56 return focaModalInformeHojaRutaService.getEmpresa(1); 54 return focaModalInformeHojaRutaService.getEmpresa(1);
57 }) 55 })
58 .then(function(res) { 56 .then(function(res) {
59 var filenameStamp = 'Informe de correlatividad de hojas de ruta - ' + 57 var filenameStamp = 'Informe de correlatividad de hojas de ruta - ' +
60 $filter('date')(new Date(), 'dd/MM/yyyy'); 58 $filter('date')(new Date(), 'dd/MM/yyyy');
61 $scope.informe.nombreEmpresa = res.data.NOM.trim(); 59 $scope.informe.nombreEmpresa = res.data.NOM.trim();
62 $scope.informe.direccionEmpresa = res.data.DIR.trim(); 60 $scope.informe.direccionEmpresa = res.data.DIR.trim();
63 $scope.gridOptions.exporterPdfFilename = filenameStamp + '.pdf'; 61 $scope.gridOptions.exporterPdfFilename = filenameStamp + '.pdf';
64 $scope.gridOptions.exporterExcelFilename = filenameStamp + '.xlsx'; 62 $scope.gridOptions.exporterExcelFilename = filenameStamp + '.xlsx';
65 $scope.gridOptions.exporterPdfHeader = { 63 $scope.gridOptions.exporterPdfHeader = {
66 columns: [ 64 columns: [
67 { 65 {
68 text: $scope.informe.nombreEmpresa, 66 text: $scope.informe.nombreEmpresa,
69 margin: [40, 0], 67 margin: [40, 0],
70 fontSize: 9 68 fontSize: 9
71 }, 69 },
72 { 70 {
73 text: '\nInforme de correlatividad de hojas de ruta', 71 text: '\nInforme de correlatividad de hojas de ruta',
74 margin: [-170, -4, 0, 0], 72 margin: [-170, -4, 0, 0],
75 fontSize: 12 73 fontSize: 12
76 }, 74 },
77 { 75 {
78 text: [ 76 text: [
79 '\n\nFiltros: ', 77 '\n\nFiltros: ',
80 'Fecha desde: ', 78 'Fecha desde: ',
81 $filter('date')($scope.fechaDesde, 'dd/MM/yyyy'), 79 $filter('date')($scope.fechaDesde, 'dd/MM/yyyy'),
82 ' Fecha hasta: ', 80 ' Fecha hasta: ',
83 $filter('date')($scope.fechaHasta, 'dd/MM/yyyy') 81 $filter('date')($scope.fechaHasta, 'dd/MM/yyyy')
84 ], 82 ],
85 margin: [-380, 2, 0, 0], 83 margin: [-380, 2, 0, 0],
86 fontSize: 9 84 fontSize: 9
87 }, 85 },
88 { 86 {
89 text: $scope.informe.direccionEmpresa, 87 text: $scope.informe.direccionEmpresa,
90 margin: [28, 0], 88 margin: [28, 0],
91 alignment: 'right', 89 alignment: 'right',
92 fontSize: 9 90 fontSize: 9
93 } 91 }
94 ] 92 ]
95 }; 93 };
96 $scope.buscar = false; 94 $scope.buscar = false;
97 }); 95 });
98 }; 96 };
99 $scope.volver = function() { 97 $scope.volver = function() {
100 $scope.buscar = true; 98 $scope.buscar = true;
101 }; 99 };
102 $scope.cancel = function() { 100 $scope.cancel = function() {
103 $uibModalInstance.dismiss('Cancelar'); 101 $uibModalInstance.dismiss('Cancelar');
104 }; 102 };
105 } 103 }
106 ] 104 ]
107 ); 105 );
108 106
src/js/controller-litros-km-unidad.js
1 angular.module('focaModalInforme') 1 angular.module('focaModalInforme')
2 .controller('focaModalInformeLitrosKmUnidadController', 2 .controller('focaModalInformeLitrosKmUnidadController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalInformeLitrosKmUnidadService', 7 'focaModalInformeLitrosKmUnidadService',
8 'i18nService', 8 'i18nService',
9 'focaModalService', 9 'focaModalService',
10 '$uibModal', 10 '$uibModal',
11 function($filter, $scope, $uibModalInstance, focaModalInformeLitrosKmUnidadService, 11 function($filter, $scope, $uibModalInstance, focaModalInformeLitrosKmUnidadService,
12 i18nService, focaModalService, $uibModal 12 i18nService, focaModalService, $uibModal
13 ) { 13 ) {
14 var meses = ['ene', 'feb', 'mar', 'abr', 'may', 'jun', 14 var meses = ['ene', 'feb', 'mar', 'abr', 'may', 'jun',
15 'jul', 'ago', 'sep', 'oct', 'nov', 'dic']; 15 'jul', 'ago', 'sep', 'oct', 'nov', 'dic'];
16 var fecha = new Date(); 16 var fecha = new Date();
17 $scope.generando = false; 17 $scope.generando = false;
18 $scope.fechaHasta = new Date(); 18 $scope.fechaHasta = new Date();
19 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1)); 19 $scope.fechaDesde = new Date(fecha.setMonth(fecha.getMonth() - 1));
20 $scope.buscar = true; 20 $scope.buscar = true;
21 $scope.informe = {}; 21 $scope.informe = {};
22 i18nService.setCurrentLang('es'); 22 i18nService.setCurrentLang('es');
23 $scope.gridOptions = { 23 $scope.gridOptions = {
24 enableGridMenu: true, 24 enableGridMenu: true,
25 exporterMenuCsv: false, 25 exporterMenuCsv: false,
26 exporterPdfPageSize: 'A4', 26 exporterPdfPageSize: 'A4',
27 exporterPdfFooter: function (currentPage, pageCount) { 27 exporterPdfFooter: function (currentPage, pageCount) {
28 return { 28 return {
29 columns: [ 29 columns: [
30 {text: $filter('date')(new Date(), 'dd/MM/yyyy'), 30 {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
31 margin: [40, 0]}, 31 margin: [40, 0]},
32 {text: currentPage + ' de ' + pageCount, 32 {text: currentPage + ' de ' + pageCount,
33 margin: [28, 0], alignment: 'right'} 33 margin: [28, 0], alignment: 'right'}
34 ] 34 ]
35 }; 35 };
36 }, 36 },
37 columnDefs: [ 37 columnDefs: [
38 { 38 {
39 field: 'fecha', 39 field: 'fecha',
40 enableSorting: false, 40 enableSorting: false,
41 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 41 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
42 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) 42 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1)
43 return 'yellow w-100'; 43 return 'yellow w-100';
44 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) 44 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1)
45 return 'red w-100'; 45 return 'red w-100';
46 } 46 }
47 }, 47 },
48 { 48 {
49 field: 'litrosRepartidos', 49 field: 'litrosRepartidos',
50 enableSorting: false, 50 enableSorting: false,
51 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 51 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
52 if (!grid.getCellValue(row,col)) 52 if (!grid.getCellValue(row,col))
53 return 'd-none'; 53 return 'd-none';
54 } 54 }
55 }, 55 },
56 { 56 {
57 field: 'kmRecorridos', 57 field: 'kmRecorridos',
58 enableSorting: false, 58 enableSorting: false,
59 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 59 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
60 if (!grid.getCellValue(row,col)) 60 if (!grid.getCellValue(row,col))
61 return 'd-none'; 61 return 'd-none';
62 } 62 }
63 }, 63 },
64 { 64 {
65 field: 'lts/Km', 65 field: 'lts/Km',
66 enableSorting: false, 66 enableSorting: false,
67 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) { 67 cellClass: function(grid, row, col, rowRenderIndex, colRenderIndex) {
68 if (!grid.getCellValue(row,col)) 68 if (!grid.getCellValue(row,col))
69 return 'd-none'; 69 return 'd-none';
70 } 70 }
71 } 71 }
72 ] 72 ]
73 73
74 }; 74 };
75 $scope.generarInforme = function() { 75 $scope.generarInforme = function() {
76 if(!$scope.unidad){ 76 if(!$scope.unidad){
77 focaModalService.alert('Primero seleccione una unidad'); 77 focaModalService.alert('Primero seleccione una unidad');
78 return; 78 return;
79 } 79 }
80 $scope.generando = true; 80 $scope.generando = true;
81 focaModalInformeLitrosKmUnidadService 81 focaModalInformeLitrosKmUnidadService
82 .getDescargas( 82 .getDescargas(
83 $scope.unidad.id, 83 $scope.unidad.id,
84 $scope.fechaDesde.toISOString().split('.')[0], 84 $scope.fechaDesde.toISOString().split('.')[0],
85 $scope.fechaHasta.toISOString().split('.')[0] 85 $scope.fechaHasta.toISOString().split('.')[0]
86 ) 86 )
87 .then(function(res) { 87 .then(function(res) {
88 var result = []; 88 var result = [];
89 res.data.forEach(function(sector) { 89 res.data.forEach(function(sector) {
90 result.push({ 90 result.push({
91 fecha: 'Sector: ' + 91 fecha: 'Sector: ' +
92 $filter('rellenarDigitos')(sector[0].articulo.CodSec, 2, '0') + 92 $filter('rellenarDigitos')(sector[0].articulo.CodSec, 2, '0') +
93 ' - ' + sector[0].articulo.sector.NOMBRE.trim() 93 ' - ' + sector[0].articulo.sector.NOMBRE.trim()
94 }); 94 });
95 sector.forEach(function(cisternaCarga) { 95 sector.forEach(function(cisternaCarga) {
96 result.push({ 96 result.push({
97 fecha: 'Producto: ' + 97 fecha: 'Producto: ' +
98 cisternaCarga.articulo.CodArt + 98 cisternaCarga.articulo.CodArt +
99 ' - ' + cisternaCarga.articulo.DetArt 99 ' - ' + cisternaCarga.articulo.DetArt
100 }); 100 });
101 cisternaCarga.cisternaMovimientos.forEach(function(cisternaMovimiento) { 101 cisternaCarga.cisternaMovimientos.forEach(function(cisternaMovimiento) {
102 var lts = cisternaMovimiento.lts; 102 var lts = cisternaMovimiento.lts;
103 var kms = cisternaMovimiento.kms; 103 var kms = cisternaMovimiento.kms;
104 104
105 result.push({ 105 result.push({
106 fecha: meses[cisternaMovimiento.month] + ' - ' + cisternaMovimiento.year, 106 fecha: meses[cisternaMovimiento.month] + ' - ' + cisternaMovimiento.year,
107 litrosRepartidos: $filter('number')(lts, 2), 107 litrosRepartidos: $filter('number')(lts, 2),
108 kmRecorridos: $filter('number')(kms, 2), 108 kmRecorridos: $filter('number')(kms, 2),
109 'lts/Km': (kms) ? $filter('number')(lts / kms, 2) : lts 109 'lts/Km': (kms) ? $filter('number')(lts / kms, 2) : lts
110 }); 110 });
111 }); 111 });
112 }); 112 });
113 }); 113 });
114 $scope.gridOptions.data = result; 114 $scope.gridOptions.data = result;
115 $scope.generando = false; 115 $scope.generando = false;
116 $scope.buscar = false; 116 $scope.buscar = false;
117 }); 117 });
118 }; 118 };
119 $scope.seleccionarTransportista = function() { 119 $scope.seleccionarTransportista = function() {
120 var parametrosModal = { 120 var parametrosModal = {
121 titulo: 'Búsqueda de Transportista', 121 titulo: 'Búsqueda de Transportista',
122 query: '/transportista', 122 query: '/transportista',
123 columnas: [ 123 columnas: [
124 { 124 {
125 propiedad: 'COD', 125 propiedad: 'COD',
126 nombre: 'Código', 126 nombre: 'Código',
127 filtro: { 127 filtro: {
128 nombre: 'rellenarDigitos', 128 nombre: 'rellenarDigitos',
129 parametro: 5 129 parametro: 5
130 } 130 }
131 }, 131 },
132 { 132 {
133 propiedad: 'NOM', 133 propiedad: 'NOM',
134 nombre: 'Nombre' 134 nombre: 'Nombre'
135 }, 135 },
136 { 136 {
137 propiedad: 'CUIT', 137 propiedad: 'CUIT',
138 nombre: 'CUIT' 138 nombre: 'CUIT'
139 } 139 }
140 ], 140 ],
141 size: 'md' 141 size: 'md'
142 }; 142 };
143 return focaModalService.modal(parametrosModal) 143 return focaModalService.modal(parametrosModal)
144 }; 144 };
145 145
146 $scope.seleccionarUnidad = function() { 146 $scope.seleccionarUnidad = function(key) {
147 $scope.seleccionarTransportista().then( 147 if (key === 13) {
148 function(transportista) { 148 $scope.seleccionarTransportista().then(
149 $scope.transportista = transportista; 149 function(transportista) {
150 var parametrosModal = { 150 $scope.transportista = transportista;
151 titulo: 'Búsqueda de vehículos', 151 var parametrosModal = {
152 query: '/vehiculo/transportista/' + transportista.COD, 152 titulo: 'Búsqueda de vehículos',
153 columnas: [ 153 searchText: $scope.unidad.codigo,
154 { 154 query: '/vehiculo/transportista/' + transportista.COD,
155 propiedad: 'codigo', 155 columnas: [
156 nombre: 'Código' 156 {
157 }, 157 propiedad: 'codigo',
158 { 158 nombre: 'Código'
159 propiedad: 'tractor', 159 },
160 nombre: 'Tractor' 160 {
161 }, 161 propiedad: 'tractor',
162 { 162 nombre: 'Tractor'
163 propiedad: 'semi', 163 },
164 nombre: 'Semi' 164 {
165 }, 165 propiedad: 'semi',
166 { 166 nombre: 'Semi'
167 propiedad: 'tractor', 167 },
168 nombre: 'Tractor' 168 {
169 } 169 propiedad: 'tractor',
170 ], 170 nombre: 'Tractor'
171 size: 'md' 171 }
172 }; 172 ],
173 focaModalService.modal(parametrosModal).then( 173 size: 'md'
174 function(unidad) { 174 };
175 $scope.unidad = unidad; 175 focaModalService.modal(parametrosModal).then(
176 }, function() { 176 function(unidad) {
177 $scope.seleccionarUnidad(); 177 $scope.unidad = unidad;
178 }); 178 }, function() {
179 }); 179 $scope.seleccionarUnidad();
180 });
181 });
182 }
180 }; 183 };
181 $scope.volver = function() { 184 $scope.volver = function() {
182 $scope.buscar = true; 185 $scope.buscar = true;
183 }; 186 };
184 $scope.cancel = function() { 187 $scope.cancel = function() {
185 $uibModalInstance.dismiss('Cancelar'); 188 $uibModalInstance.dismiss('Cancelar');
186 }; 189 };
187 } 190 }
188 ] 191 ]
189 ); 192 );
190 193
src/js/controller-productividad.js
1 angular.module('focaModalInforme') 1 angular.module('focaModalInforme')
2 .controller('focaModalInformeProductividadController', 2 .controller('focaModalInformeProductividadController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalInformeProductividadService', 7 'focaModalInformeProductividadService',
8 'i18nService', 8 'i18nService',
9 'focaModalService', 9 'focaModalService',
10 function($filter, $scope, $uibModalInstance, 10 function($filter, $scope, $uibModalInstance,
11 focaModalInformeProductividadService, i18nService, focaModalService 11 focaModalInformeProductividadService, i18nService, focaModalService
12 ) { 12 ) {
13 i18nService.setCurrentLang('es'); 13 i18nService.setCurrentLang('es');
14 var fecha = new Date(); 14 var fecha = new Date();
15 $scope.generando = false; 15 $scope.generando = false;
16 $scope.buscar = true; 16 $scope.buscar = true;
17 $scope.informe = {}; 17 $scope.informe = {};
18 $scope.params = { 18 $scope.params = {
19 fechaHasta: new Date(), 19 fechaHasta: new Date(),
20 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), 20 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)),
21 sector: undefined, 21 sector: undefined,
22 diferenciarProductos: false, 22 diferenciarProductos: false,
23 diferenciarMeses: false 23 diferenciarMeses: false
24 }; 24 };
25 $scope.gridOptions = { 25 $scope.gridOptions = {
26 enableGridMenu: true, 26 enableGridMenu: true,
27 exporterMenuCsv: false, 27 exporterMenuCsv: false,
28 exporterPdfPageSize: 'A4', 28 exporterPdfPageSize: 'A4',
29 exporterPdfFooter: function (currentPage, pageCount) { 29 exporterPdfFooter: function (currentPage, pageCount) {
30 return { 30 return {
31 columns: [ 31 columns: [
32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'), 32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
33 margin: [40, 0]}, 33 margin: [40, 0]},
34 {text: currentPage + ' de ' + pageCount, 34 {text: currentPage + ' de ' + pageCount,
35 margin: [28, 0], alignment: 'right'} 35 margin: [28, 0], alignment: 'right'}
36 ] 36 ]
37 }; 37 };
38 }, 38 },
39 columnDefs: [ 39 columnDefs: [
40 { 40 {
41 field: 'cliente', 41 field: 'cliente',
42 enableSorting: false, 42 enableSorting: false,
43 cellClass: function(grid, row, col) { 43 cellClass: function(grid, row, col) {
44 var value = grid.getCellValue(row,col); 44 var value = grid.getCellValue(row,col);
45 45
46 if (value.indexOf('Vendedores') !== -1 || 46 if (value.indexOf('Vendedores') !== -1 ||
47 value.indexOf('Cobradores') !== -1 || 47 value.indexOf('Cobradores') !== -1 ||
48 value.indexOf('Transportistas') !== -1) 48 value.indexOf('Transportistas') !== -1)
49 return 'yellow w-100'; 49 return 'yellow w-100';
50 if (value.indexOf('Vendedor:') !== -1 || 50 if (value.indexOf('Vendedor:') !== -1 ||
51 value.indexOf('Cobrador:') !== -1 || 51 value.indexOf('Cobrador:') !== -1 ||
52 value.indexOf('Transportista:') !== -1) 52 value.indexOf('Transportista:') !== -1)
53 return 'red w-100'; 53 return 'red w-100';
54 if (value.indexOf('Fecha:') !== -1) 54 if (value.indexOf('Fecha:') !== -1)
55 return 'green w-100'; 55 return 'green w-100';
56 } 56 }
57 }, 57 },
58 { 58 {
59 field: 'fecha', 59 field: 'fecha',
60 enableSorting: false, 60 enableSorting: false,
61 cellClass: function(grid, row, col) { 61 cellClass: function(grid, row, col) {
62 if (!grid.getCellValue(row,col)) 62 if (!grid.getCellValue(row,col))
63 return 'd-none'; 63 return 'd-none';
64 } 64 }
65 }, 65 },
66 { 66 {
67 field: 'kmRecorridos', 67 field: 'kmRecorridos',
68 enableSorting: false, 68 enableSorting: false,
69 cellClass: function(grid, row, col) { 69 cellClass: function(grid, row, col) {
70 if (!grid.getCellValue(row,col)) 70 if (!grid.getCellValue(row,col))
71 return 'd-none'; 71 return 'd-none';
72 } 72 }
73 }, 73 },
74 { 74 {
75 field: 'geolocalizacion', 75 field: 'geolocalizacion',
76 enableSorting: false, 76 enableSorting: false,
77 cellClass: function(grid, row, col) { 77 cellClass: function(grid, row, col) {
78 if (!grid.getCellValue(row,col)) 78 if (!grid.getCellValue(row,col))
79 return 'd-none'; 79 return 'd-none';
80 } 80 }
81 } 81 }
82 ] 82 ]
83 }; 83 };
84 $scope.seleccionarTipo = function() { 84 $scope.seleccionarTipo = function() {
85 var data = [ 85 var data = [
86 { 86 {
87 id: 0, 87 id: 0,
88 label: 'Todos' 88 label: 'Todos'
89 }, 89 },
90 { 90 {
91 id: 1, 91 id: 1,
92 label: 'Vendedores' 92 label: 'Vendedores'
93 }, 93 },
94 { 94 {
95 id: 2, 95 id: 2,
96 label: 'Cobradores' 96 label: 'Cobradores'
97 }, 97 },
98 { 98 {
99 id: 3, 99 id: 3,
100 label: 'Transportistas' 100 label: 'Transportistas'
101 } 101 }
102 ]; 102 ];
103 focaModalService.modal({ 103 focaModalService.modal({
104 titulo: 'Seleccionar entidad', 104 titulo: 'Seleccionar entidad',
105 data: data, 105 data: data,
106 columnas: [ 106 columnas: [
107 { 107 {
108 propiedad: 'label', 108 propiedad: 'label',
109 nombre: 'Entidad' 109 nombre: 'Entidad'
110 } 110 }
111 ], 111 ],
112 }).then(function(res) { 112 }).then(function(res) {
113 $scope.params.entidad = res; 113 $scope.params.entidad = res;
114 }); 114 });
115 }; 115 };
116 $scope.generarInforme = function() { 116 $scope.generarInforme = function() {
117 if (!$scope.params.entidad) { 117 if (!$scope.params.entidad) {
118 focaModalService.alert('Seleccione una entidad'); 118 focaModalService.alert('Seleccione una entidad');
119 return; 119 return;
120 } 120 }
121 $scope.generando = true; 121 $scope.generando = true;
122 focaModalInformeProductividadService 122 focaModalInformeProductividadService
123 .getInformeData($scope.params) 123 .getInformeData($scope.params)
124 .then(function(res) { 124 .then(function(res) {
125 var result = []; 125 var result = [];
126 126
127 if ($scope.params.entidad.id === 1 || !$scope.params.entidad.id) { 127 if ($scope.params.entidad.id === 1 || !$scope.params.entidad.id) {
128 result.push({ 128 result.push({
129 cliente: 'Vendedores' 129 cliente: 'Vendedores'
130 }); 130 });
131 res.data.vendedores.forEach(function(vendedor) { 131 res.data.vendedores.forEach(function(vendedor) {
132 result.push({ 132 result.push({
133 cliente: 'Vendedor: ' + vendedor.NOM 133 cliente: 'Vendedor: ' + vendedor.NOM
134 }); 134 });
135 vendedor.notasPedido.forEach(function(notaPedido) { 135 vendedor.notasPedido.forEach(function(notaPedido) {
136 var seguimiento = notaPedido.seguimiento; 136 var seguimiento = notaPedido.seguimiento;
137 result.push({ 137 result.push({
138 cliente: notaPedido.cliente.NOM, 138 cliente: notaPedido.cliente.NOM,
139 fecha: seguimiento ? $filter('date')(seguimiento.fecha) : $filter('date')(notaPedido.fechaCarga), 139 fecha: seguimiento ? $filter('date')(seguimiento.fecha) : $filter('date')(notaPedido.fechaCarga),
140 kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2), 140 kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2),
141 geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : '' 141 geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : ''
142 }); 142 });
143 }); 143 });
144 }); 144 });
145 } 145 }
146 if ($scope.params.entidad.id === 2 || !$scope.params.entidad.id) { 146 if ($scope.params.entidad.id === 2 || !$scope.params.entidad.id) {
147 result.push({ 147 result.push({
148 cliente: 'Cobradores' 148 cliente: 'Cobradores'
149 }); 149 });
150 res.data.cobradores.forEach(function(cobrador) { 150 res.data.cobradores.forEach(function(cobrador) {
151 result.push({ 151 result.push({
152 cliente: 'Cobrador: ' + cobrador.NOM 152 cliente: 'Cobrador: ' + cobrador.NOM
153 }); 153 });
154 cobrador.cobranzas.forEach(function(cobranza) { 154 cobrador.cobranzas.forEach(function(cobranza) {
155 var seguimiento = cobranza.seguimiento; 155 var seguimiento = cobranza.seguimiento;
156 result.push({ 156 result.push({
157 cliente: cobranza.cliente.NOM, 157 cliente: cobranza.cliente.NOM,
158 fecha: seguimiento ? $filter('date')(seguimiento.fecha, 'dd/MM/yyyy') : $filter('date')(cobranza.FEC), 158 fecha: seguimiento ? $filter('date')(seguimiento.fecha, 'dd/MM/yyyy') : $filter('date')(cobranza.FEC),
159 kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2), 159 kmRecorridos: seguimiento ? $filter('number')(seguimiento.kmRecorridos || 0, 2) : $filter('number')(0, 2),
160 geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : '' 160 geolocalizacion: seguimiento ? seguimiento.latitud + ', ' + seguimiento.longitud : ''
161 }); 161 });
162 }); 162 });
163 }); 163 });
164 } 164 }
165 if ($scope.params.entidad.id === 3 || !$scope.params.entidad.id) { 165 if ($scope.params.entidad.id === 3 || !$scope.params.entidad.id) {
166 result.push({ 166 result.push({
167 cliente: 'Transportistas' 167 cliente: 'Transportistas'
168 }); 168 });
169 res.data.transportistas.forEach(function(transportista) { 169 res.data.transportistas.forEach(function(transportista) {
170 result.push({ 170 result.push({
171 cliente: 'Transportista: ' + transportista.NOM 171 cliente: 'Transportista: ' + transportista.NOM
172 }); 172 });
173 transportista.remitos.forEach(function(remito) { 173 transportista.remitos.forEach(function(remito) {
174 var kms = 0, 174 var kms = 0,
175 geolocalizacion; 175 geolocalizacion;
176 remito.hojaRutaMovimiento.forEach(function(movimiento) { 176 remito.hojaRutaMovimiento.forEach(function(movimiento) {
177 kms += movimiento.seguimiento.kmRecorridos || 0; 177 kms += movimiento.seguimiento.kmRecorridos || 0;
178 geolocalizacion = geolocalizacion || 178 geolocalizacion = geolocalizacion ||
179 movimiento.seguimiento.latitud + ', ' + 179 movimiento.seguimiento.latitud + ', ' +
180 movimiento.seguimiento.longitud; 180 movimiento.seguimiento.longitud;
181 }); 181 });
182 result.push({ 182 result.push({
183 cliente: remito.cliente.NOM, 183 cliente: remito.cliente.NOM,
184 fecha: $filter('date')(remito.fechaRemito, 'dd/MM/yyyy'), 184 fecha: $filter('date')(remito.fechaRemito, 'dd/MM/yyyy'),
185 kmRecorridos: $filter('number')(kms, 2), 185 kmRecorridos: $filter('number')(kms, 2),
186 geolocalizacion: geolocalizacion 186 geolocalizacion: geolocalizacion
187 }); 187 });
188 }); 188 });
189 }); 189 });
190 } 190 }
191 $scope.gridOptions.data = result; 191 $scope.gridOptions.data = result;
192 $scope.generando = false; 192 $scope.generando = false;
193 $scope.buscar = false; 193 $scope.buscar = false;
194 }); 194 });
195 }; 195 };
196 196
197
198 $scope.volver = function() { 197 $scope.volver = function() {
199 $scope.buscar = true; 198 $scope.buscar = true;
200 }; 199 };
201 $scope.cancel = function() { 200 $scope.cancel = function() {
202 $uibModalInstance.dismiss('Cancelar'); 201 $uibModalInstance.dismiss('Cancelar');
203 }; 202 };
204 $scope.clearEntidad = function() { 203 $scope.clearEntidad = function() {
205 $scope.params.entidad = undefined; 204 $scope.params.entidad = undefined;
206 }; 205 };
207
208 } 206 }
209 ] 207 ]
210 ); 208 );
211 209
src/js/controller-reparto-optimo.js
1 angular.module('focaModalInforme') 1 angular.module('focaModalInforme')
2 .controller('focaModalInformeRepartoOptimoController', 2 .controller('focaModalInformeRepartoOptimoController',
3 [ 3 [
4 '$filter', 4 '$filter',
5 '$scope', 5 '$scope',
6 '$uibModalInstance', 6 '$uibModalInstance',
7 'focaModalInformeRepartoOptimoService', 7 'focaModalInformeRepartoOptimoService',
8 'i18nService', 8 'i18nService',
9 'focaModalService', 9 'focaModalService',
10 '$uibModal', 10 '$uibModal',
11 function($filter, $scope, $uibModalInstance, focaModalInformeRepartoOptimoService, 11 function($filter, $scope, $uibModalInstance, focaModalInformeRepartoOptimoService,
12 i18nService, focaModalService, $uibModal 12 i18nService, focaModalService, $uibModal
13 ) { 13 ) {
14 var fecha = new Date(); 14 var fecha = new Date();
15 $scope.generando = false; 15 $scope.generando = false;
16 $scope.buscar = true; 16 $scope.buscar = true;
17 $scope.params = { 17 $scope.params = {
18 fechaHasta: new Date(), 18 fechaHasta: new Date(),
19 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), 19 fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)),
20 sector: undefined, 20 sector: undefined,
21 diferenciarProductos: false, 21 diferenciarProductos: false,
22 diferenciarMeses: false 22 diferenciarMeses: false
23 }; 23 };
24 i18nService.setCurrentLang('es'); 24 i18nService.setCurrentLang('es');
25 $scope.gridOptions = { 25 $scope.gridOptions = {
26 enableGridMenu: true, 26 enableGridMenu: true,
27 exporterMenuCsv: false, 27 exporterMenuCsv: false,
28 exporterPdfPageSize: 'A4', 28 exporterPdfPageSize: 'A4',
29 exporterPdfFooter: function (currentPage, pageCount) { 29 exporterPdfFooter: function (currentPage, pageCount) {
30 return { 30 return {
31 columns: [ 31 columns: [
32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'), 32 {text: $filter('date')(new Date(), 'dd/MM/yyyy'),
33 margin: [40, 0]}, 33 margin: [40, 0]},
34 {text: currentPage + ' de ' + pageCount, 34 {text: currentPage + ' de ' + pageCount,
35 margin: [28, 0], alignment: 'right'} 35 margin: [28, 0], alignment: 'right'}
36 ] 36 ]
37 }; 37 };
38 }, 38 },
39 columnDefs: [ 39 columnDefs: [
40 { 40 {
41 field: 'vehiculo', 41 field: 'vehiculo',
42 enableSorting: false, 42 enableSorting: false,
43 cellClass: function(grid, row, col) { 43 cellClass: function(grid, row, col) {
44 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) 44 if (grid.getCellValue(row,col).indexOf('Sector:') !== -1)
45 return 'yellow w-100'; 45 return 'yellow w-100';
46 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) 46 if (grid.getCellValue(row,col).indexOf('Producto:') !== -1)
47 return 'red w-100'; 47 return 'red w-100';
48 if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1) 48 if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1)
49 return 'green w-100'; 49 return 'green w-100';
50 } 50 }
51 }, 51 },
52 { 52 {
53 field: 'ltsRepartidos', 53 field: 'ltsRepartidos',
54 enableSorting: false, 54 enableSorting: false,
55 cellClass: function(grid, row, col) { 55 cellClass: function(grid, row, col) {
56 if (!grid.getCellValue(row,col)) 56 if (!grid.getCellValue(row,col))
57 return 'd-none'; 57 return 'd-none';
58 } 58 }
59 }, 59 },
60 { 60 {
61 field: 'ltsOptimos', 61 field: 'ltsOptimos',
62 enableSorting: false, 62 enableSorting: false,
63 cellClass: function(grid, row, col) { 63 cellClass: function(grid, row, col) {
64 if (!grid.getCellValue(row,col)) 64 if (!grid.getCellValue(row,col))
65 return 'd-none'; 65 return 'd-none';
66 } 66 }
67 }, 67 },
68 { 68 {
69 field: 'diferencia', 69 field: 'diferencia',
70 enableSorting: false, 70 enableSorting: false,
71 cellClass: function(grid, row, col) { 71 cellClass: function(grid, row, col) {
72 if (!grid.getCellValue(row,col)) 72 if (!grid.getCellValue(row,col))
73 return 'd-none'; 73 return 'd-none';
74 } 74 }
75 }, 75 },
76 { 76 {
77 field: 'porcentaje', 77 field: 'porcentaje',
78 enableSorting: false, 78 enableSorting: false,
79 cellClass: function(grid, row, col) { 79 cellClass: function(grid, row, col) {
80 if (!grid.getCellValue(row,col)) 80 if (!grid.getCellValue(row,col))
81 return 'd-none'; 81 return 'd-none';
82 } 82 }
83 } 83 }
84 ] 84 ]
85 }; 85 };
86 86
87 $scope.generarInforme = function() { 87 $scope.generarInforme = function() {
88 $scope.generando = true; 88 $scope.generando = true;
89 focaModalInformeRepartoOptimoService 89 focaModalInformeRepartoOptimoService
90 .getInformeData($scope.params) 90 .getInformeData($scope.params)
91 .then(function(res) { 91 .then(function(res) {
92 var result = []; 92 var result = [];
93 93
94 res.data.forEach(function(sector) { 94 res.data.forEach(function(sector) {
95 if (!$scope.params.sector || 95 if (!$scope.params.sector ||
96 $scope.params.sector.ID === sector.idSector) { 96 $scope.params.sector.ID === sector.idSector) {
97 //AGREGO SECTORES 97 //AGREGO SECTORES
98 result.push({ 98 result.push({
99 vehiculo: 'Sector: ' + 99 vehiculo: 'Sector: ' +
100 $filter('rellenarDigitos')(sector.idSector, 2, '0') + 100 $filter('rellenarDigitos')(sector.idSector, 2, '0') +
101 ' - ' + sector.sector.trim() 101 ' - ' + sector.sector.trim()
102 }); 102 });
103 if (!$scope.params.diferenciarProductos) 103 if (!$scope.params.diferenciarProductos)
104 sector.productos = unirProductos(sector.productos); 104 sector.productos = unirProductos(sector.productos);
105 105
106 sector.productos.forEach(function(producto) { 106 sector.productos.forEach(function(producto) {
107 //AGREGO PRODUCTOS 107 //AGREGO PRODUCTOS
108 if ($scope.params.diferenciarProductos) { 108 if ($scope.params.diferenciarProductos) {
109 result.push({ 109 result.push({
110 vehiculo: 'Producto: ' + 110 vehiculo: 'Producto: ' +
111 producto.idProducto + 111 producto.idProducto +
112 ' - ' + producto.producto 112 ' - ' + producto.producto
113 }); 113 });
114 } 114 }
115 if (!$scope.params.diferenciarMeses) { 115 if (!$scope.params.diferenciarMeses) {
116 producto.fechas = unirFechas(producto.fechas); 116 producto.fechas = unirFechas(producto.fechas);
117 } 117 }
118 producto.fechas.forEach(function(fecha) { 118 producto.fechas.forEach(function(fecha) {
119 //AGREGO FECHAS 119 //AGREGO FECHAS
120 if ($scope.params.diferenciarMeses) { 120 if ($scope.params.diferenciarMeses) {
121 result.push({ 121 result.push({
122 vehiculo: 122 vehiculo:
123 'Fecha: ' + fecha.month + ' - ' + fecha.year 123 'Fecha: ' + fecha.month + ' - ' + fecha.year
124 }); 124 });
125 } else { 125 } else {
126 result.push({ 126 result.push({
127 vehiculo: 127 vehiculo:
128 'Fecha: ' + fecha.year 128 'Fecha: ' + fecha.year
129 }); 129 });
130 } 130 }
131 fecha.vehiculos.forEach(function(vehiculo) { 131 fecha.vehiculos.forEach(function(vehiculo) {
132 //AGREGO VEHICULOS 132 //AGREGO VEHICULOS
133 result.push({ 133 result.push({
134 vehiculo: vehiculo.vehiculo, 134 vehiculo: vehiculo.vehiculo,
135 ltsRepartidos: 135 ltsRepartidos:
136 $filter('number') 136 $filter('number')
137 (vehiculo.data.ltsRepartidos, 2), 137 (vehiculo.data.ltsRepartidos, 2),
138 ltsOptimos: 138 ltsOptimos:
139 $filter('number') 139 $filter('number')
140 (vehiculo.data.ltsOptimos, 2), 140 (vehiculo.data.ltsOptimos, 2),
141 diferencia: 141 diferencia:
142 $filter('number') 142 $filter('number')
143 (vehiculo.data.diferencia, 2), 143 (vehiculo.data.diferencia, 2),
144 porcentaje: 144 porcentaje:
145 $filter('number') 145 $filter('number')
146 (vehiculo.data.porcentaje, 2) + '%' 146 (vehiculo.data.porcentaje, 2) + '%'
147 }); 147 });
148 }); 148 });
149 }); 149 });
150 }); 150 });
151 } 151 }
152 }); 152 });
153 153
154 $scope.gridOptions.data = result; 154 $scope.gridOptions.data = result;
155 $scope.generando = false; 155 $scope.generando = false;
156 $scope.buscar = false; 156 $scope.buscar = false;
157 }); 157 });
158 }; 158 };
159 159
160
161 $scope.seleccionarSector = function(key) { 160 $scope.seleccionarSector = function(key) {
162 if (key === 13) { 161 if (key === 13) {
163 var parametrosModal = { 162 var parametrosModal = {
164 titulo: 'Búsqueda de Sector', 163 titulo: 'Búsqueda de Sector',
164 searchText: $scope.params.sector.NOMBRE,
165 query: '/sector', 165 query: '/sector',
166 columnas: [ 166 columnas: [
167 { 167 {
168 nombre: 'Código', 168 nombre: 'Código',
169 propiedad: 'ID' 169 propiedad: 'ID'
170 }, 170 },
171 { 171 {
172 nombre: 'Nombre', 172 nombre: 'Nombre',
173 propiedad: 'NOMBRE' 173 propiedad: 'NOMBRE'
174 } 174 }
175 ], 175 ],
176 size: 'md' 176 size: 'md'
177 }; 177 };
178 focaModalService.modal(parametrosModal).then( 178 focaModalService.modal(parametrosModal).then(
179 function(sector) { 179 function(sector) {
180 $scope.params.sector = sector; 180 $scope.params.sector = sector;
181 }, function() {} 181 }, function() {}
182 ); 182 );
183 } 183 }
184 }; 184 };
185 $scope.clearSector = function() { 185 $scope.clearSector = function() {
186 $scope.params.sector = undefined; 186 $scope.params.sector = undefined;
187 }; 187 };
188 $scope.volver = function() { 188 $scope.volver = function() {
189 $scope.buscar = true; 189 $scope.buscar = true;
190 }; 190 };
191 $scope.cancel = function() { 191 $scope.cancel = function() {
192 $uibModalInstance.dismiss('Cancelar'); 192 $uibModalInstance.dismiss('Cancelar');
193 }; 193 };
194 194
195 function unirProductos(productos) { 195 function unirProductos(productos) {
196 var result = [{fechas: []}]; 196 var result = [{fechas: []}];
197 productos.forEach(function(producto) { 197 productos.forEach(function(producto) {
198 producto.fechas.forEach(function(fecha) { 198 producto.fechas.forEach(function(fecha) {
199 var existe = result[0].fechas.filter(function(result) { 199 var existe = result[0].fechas.filter(function(result) {
200 return result.fecha === fecha.fecha; 200 return result.fecha === fecha.fecha;
201 }); 201 });
202 if (existe.length) { 202 if (existe.length) {
203 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); 203 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos);
204 } else { 204 } else {
205 result[0].fechas.push(fecha); 205 result[0].fechas.push(fecha);
206 } 206 }
207 207
208 }); 208 });
209 }); 209 });
210 result[0].fechas.forEach(function(fecha) { 210 result[0].fechas.forEach(function(fecha) {
211 fecha.vehiculos = unirVehiculos(fecha.vehiculos); 211 fecha.vehiculos = unirVehiculos(fecha.vehiculos);
212 }); 212 });
213 return result; 213 return result;
214 } 214 }
215 215
216 function unirFechas(fechas) { 216 function unirFechas(fechas) {
217 var results = []; 217 var results = [];
218 fechas.forEach(function(fecha) { 218 fechas.forEach(function(fecha) {
219 var existe = results.filter(function(result) { 219 var existe = results.filter(function(result) {
220 return result.year === fecha.year; 220 return result.year === fecha.year;
221 }); 221 });
222 222
223 if (existe.length) { 223 if (existe.length) {
224 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); 224 existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos);
225 } else { 225 } else {
226 results.push({ 226 results.push({
227 year: fecha.year, 227 year: fecha.year,
228 vehiculos: fecha.vehiculos 228 vehiculos: fecha.vehiculos
229 }); 229 });
230 } 230 }
231 }); 231 });
232 232
233 results.forEach(function(result) { 233 results.forEach(function(result) {
234 result.vehiculos = unirVehiculos(result.vehiculos); 234 result.vehiculos = unirVehiculos(result.vehiculos);
235 }); 235 });
236 return results; 236 return results;
237 } 237 }
238 238
239 function unirVehiculos(vehiculos) { 239 function unirVehiculos(vehiculos) {
240 var results = []; 240 var results = [];
241 vehiculos.forEach(function(vehiculo) { 241 vehiculos.forEach(function(vehiculo) {
242 var existe = results.filter(function(result) { 242 var existe = results.filter(function(result) {
243 return result.vehiculo === vehiculo.vehiculo; 243 return result.vehiculo === vehiculo.vehiculo;
244 }); 244 });
245 245
246 if (existe.length) { 246 if (existe.length) {
247 existe[0].data.kms += vehiculo.data.kms; 247 existe[0].data.kms += vehiculo.data.kms;
248 existe[0].data.lts += vehiculo.data.lts; 248 existe[0].data.lts += vehiculo.data.lts;
249 existe[0].data.viajes += vehiculo.data.viajes; 249 existe[0].data.viajes += vehiculo.data.viajes;
250 } else { 250 } else {
251 results.push(vehiculo); 251 results.push(vehiculo);
252 } 252 }
253 }); 253 });
254 return results; 254 return results;
255 } 255 }
256 } 256 }
257 ] 257 ]
258 ); 258 );