Commit b4db11912b253544aa08c655dd9668aed1c8abbc
1 parent
65e7ac5fe5
Exists in
master
and in
1 other branch
filtros informe general unidad
Showing
2 changed files
with
91 additions
and
11 deletions
Show diff stats
src/js/controller-general-unidad.js
... | ... | @@ -20,7 +20,7 @@ angular.module('focaModalInforme') |
20 | 20 | fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), |
21 | 21 | sector: undefined, |
22 | 22 | diferenciarProductos: false, |
23 | - detallarPorMes: false | |
23 | + diferenciarMeses: false | |
24 | 24 | }; |
25 | 25 | $scope.gridOptions = { |
26 | 26 | enableGridMenu: true, |
... | ... | @@ -45,7 +45,7 @@ angular.module('focaModalInforme') |
45 | 45 | return 'yellow w-100'; |
46 | 46 | if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) |
47 | 47 | return 'red w-100'; |
48 | - if (grid.getCellValue(row,col).indexOf('Mes:') !== -1) | |
48 | + if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1) | |
49 | 49 | return 'green w-100'; |
50 | 50 | } |
51 | 51 | }, |
... | ... | @@ -91,18 +91,34 @@ angular.module('focaModalInforme') |
91 | 91 | $filter('rellenarDigitos')(sector.idSector, 2, '0') + |
92 | 92 | ' - ' + sector.sector.trim() |
93 | 93 | }); |
94 | + if (!$scope.params.diferenciarProductos) | |
95 | + sector.productos = unirProductos(sector.productos); | |
96 | + | |
94 | 97 | sector.productos.forEach(function(producto) { |
95 | 98 | //AGREGO PRODUCTOS |
96 | - result.push({ | |
97 | - vehiculo: 'Producto: ' + | |
98 | - producto.idProducto + | |
99 | - ' - ' + producto.producto | |
100 | - }); | |
101 | - producto.fechas.forEach(function(fecha) { | |
102 | - //AGREGO FECHAS | |
99 | + if ($scope.params.diferenciarProductos){ | |
103 | 100 | result.push({ |
104 | - vehiculo: 'Mes: ' + fecha.fecha | |
101 | + vehiculo: 'Producto: ' + | |
102 | + producto.idProducto + | |
103 | + ' - ' + producto.producto | |
105 | 104 | }); |
105 | + } | |
106 | + if (!$scope.params.diferenciarMeses) { | |
107 | + producto.fechas = unirFechas(producto.fechas); | |
108 | + } | |
109 | + producto.fechas.forEach(function(fecha) { | |
110 | + //AGREGO FECHAS | |
111 | + if ($scope.params.diferenciarMeses) { | |
112 | + result.push({ | |
113 | + vehiculo: | |
114 | + 'Fecha: ' + fecha.month + ' - ' + fecha.year | |
115 | + }); | |
116 | + } else { | |
117 | + result.push({ | |
118 | + vehiculo: | |
119 | + 'Fecha: ' + fecha.year | |
120 | + }); | |
121 | + } | |
106 | 122 | fecha.vehiculos.forEach(function(vehiculo) { |
107 | 123 | //AGREGO VEHICULOS |
108 | 124 | result.push({ |
... | ... | @@ -156,6 +172,70 @@ angular.module('focaModalInforme') |
156 | 172 | $scope.cancel = function() { |
157 | 173 | $uibModalInstance.dismiss('Cancelar'); |
158 | 174 | }; |
175 | + | |
176 | + function unirProductos(productos) { | |
177 | + var result = [{fechas: []}]; | |
178 | + productos.forEach(function(producto) { | |
179 | + producto.fechas.forEach(function(fecha) { | |
180 | + var existe = result[0].fechas.filter(function(result) { | |
181 | + return result.fecha === fecha.fecha; | |
182 | + }); | |
183 | + if (existe.length) { | |
184 | + existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); | |
185 | + } else { | |
186 | + result[0].fechas.push(fecha); | |
187 | + } | |
188 | + | |
189 | + }); | |
190 | + }); | |
191 | + result[0].fechas.forEach(function(fecha) { | |
192 | + fecha.vehiculos = unirVehiculos(fecha.vehiculos); | |
193 | + }); | |
194 | + return result; | |
195 | + } | |
196 | + | |
197 | + function unirFechas(fechas) { | |
198 | + var results = []; | |
199 | + fechas.forEach(function(fecha) { | |
200 | + var existe = results.filter(function(result) { | |
201 | + return result.year === fecha.year; | |
202 | + }); | |
203 | + | |
204 | + if (existe.length) { | |
205 | + existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); | |
206 | + } else { | |
207 | + results.push({ | |
208 | + year: fecha.year, | |
209 | + vehiculos: fecha.vehiculos | |
210 | + }); | |
211 | + } | |
212 | + }); | |
213 | + | |
214 | + results.forEach(function(result) { | |
215 | + result.vehiculos = unirVehiculos(result.vehiculos); | |
216 | + }); | |
217 | + return results; | |
218 | + } | |
219 | + | |
220 | + function unirVehiculos(vehiculos) { | |
221 | + var results = []; | |
222 | + vehiculos.forEach(function(vehiculo) { | |
223 | + var existe = results.filter(function(result) { | |
224 | + return result.vehiculo === vehiculo.vehiculo; | |
225 | + }); | |
226 | + | |
227 | + if (existe.length) { | |
228 | + existe[0].data.kms += vehiculo.data.kms; | |
229 | + existe[0].data.lts += vehiculo.data.lts; | |
230 | + existe[0].data.viajes += vehiculo.data.viajes; | |
231 | + } else { | |
232 | + results.push(vehiculo); | |
233 | + } | |
234 | + }); | |
235 | + return results; | |
236 | + } | |
237 | + | |
238 | + | |
159 | 239 | } |
160 | 240 | ] |
161 | 241 | ); |
src/views/informe-general-unidad.html