Commit 7114ac7e7c22ec55f3af9ad67b8d80f36ee3df55
1 parent
fbb11330ff
Exists in
master
and in
1 other branch
agrego Informe de reparto óptimo detallado
Showing
3 changed files
with
408 additions
and
1 deletions
Show diff stats
src/js/controller-reparto-optimo.js
File was created | 1 | angular.module('focaModalInforme') | |
2 | .controller('focaModalInformeRepartoOptimoController', | ||
3 | [ | ||
4 | '$filter', | ||
5 | '$scope', | ||
6 | '$uibModalInstance', | ||
7 | 'focaModalInformeRepartoOptimoService', | ||
8 | 'i18nService', | ||
9 | 'focaModalService', | ||
10 | '$uibModal', | ||
11 | function($filter, $scope, $uibModalInstance, focaModalInformeRepartoOptimoService, | ||
12 | i18nService, focaModalService, $uibModal | ||
13 | ) { | ||
14 | var fecha = new Date(); | ||
15 | $scope.generando = false; | ||
16 | $scope.buscar = true; | ||
17 | $scope.params = { | ||
18 | fechaHasta: new Date(), | ||
19 | fechaDesde: new Date(fecha.setMonth(fecha.getMonth() - 1)), | ||
20 | sector: undefined, | ||
21 | diferenciarProductos: false, | ||
22 | diferenciarMeses: false | ||
23 | }; | ||
24 | i18nService.setCurrentLang('es'); | ||
25 | $scope.gridOptions = { | ||
26 | enableGridMenu: true, | ||
27 | exporterMenuCsv: false, | ||
28 | exporterPdfPageSize: 'A4', | ||
29 | exporterPdfFooter: function (currentPage, pageCount) { | ||
30 | return { | ||
31 | columns: [ | ||
32 | {text: $filter('date')(new Date(), 'dd/MM/yyyy'), | ||
33 | margin: [40, 0]}, | ||
34 | {text: currentPage + ' de ' + pageCount, | ||
35 | margin: [28, 0], alignment: 'right'} | ||
36 | ] | ||
37 | }; | ||
38 | }, | ||
39 | columnDefs: [ | ||
40 | { | ||
41 | field: 'vehiculo', | ||
42 | enableSorting: false, | ||
43 | cellClass: function(grid, row, col) { | ||
44 | if (grid.getCellValue(row,col).indexOf('Sector:') !== -1) | ||
45 | return 'yellow w-100'; | ||
46 | if (grid.getCellValue(row,col).indexOf('Producto:') !== -1) | ||
47 | return 'red w-100'; | ||
48 | if (grid.getCellValue(row,col).indexOf('Fecha:') !== -1) | ||
49 | return 'green w-100'; | ||
50 | } | ||
51 | }, | ||
52 | { | ||
53 | field: 'ltsRepartidos', | ||
54 | enableSorting: false, | ||
55 | cellClass: function(grid, row, col) { | ||
56 | if (!grid.getCellValue(row,col)) | ||
57 | return 'd-none'; | ||
58 | } | ||
59 | }, | ||
60 | { | ||
61 | field: 'ltsOptimos', | ||
62 | enableSorting: false, | ||
63 | cellClass: function(grid, row, col) { | ||
64 | if (!grid.getCellValue(row,col)) | ||
65 | return 'd-none'; | ||
66 | } | ||
67 | }, | ||
68 | { | ||
69 | field: 'diferencia', | ||
70 | enableSorting: false, | ||
71 | cellClass: function(grid, row, col) { | ||
72 | if (!grid.getCellValue(row,col)) | ||
73 | return 'd-none'; | ||
74 | } | ||
75 | }, | ||
76 | { | ||
77 | field: 'porcentaje', | ||
78 | enableSorting: false, | ||
79 | cellClass: function(grid, row, col) { | ||
80 | if (!grid.getCellValue(row,col)) | ||
81 | return 'd-none'; | ||
82 | } | ||
83 | } | ||
84 | ] | ||
85 | }; | ||
86 | |||
87 | $scope.generarInforme = function() { | ||
88 | $scope.generando = true; | ||
89 | focaModalInformeRepartoOptimoService | ||
90 | .getInformeData($scope.params) | ||
91 | .then(function(res) { | ||
92 | var result = []; | ||
93 | |||
94 | res.data.forEach(function(sector) { | ||
95 | if (!$scope.params.sector || | ||
96 | $scope.params.sector.ID === sector.idSector) { | ||
97 | //AGREGO SECTORES | ||
98 | result.push({ | ||
99 | vehiculo: 'Sector: ' + | ||
100 | $filter('rellenarDigitos')(sector.idSector, 2, '0') + | ||
101 | ' - ' + sector.sector.trim() | ||
102 | }); | ||
103 | if (!$scope.params.diferenciarProductos) | ||
104 | sector.productos = unirProductos(sector.productos); | ||
105 | |||
106 | sector.productos.forEach(function(producto) { | ||
107 | //AGREGO PRODUCTOS | ||
108 | if ($scope.params.diferenciarProductos) { | ||
109 | result.push({ | ||
110 | vehiculo: 'Producto: ' + | ||
111 | producto.idProducto + | ||
112 | ' - ' + producto.producto | ||
113 | }); | ||
114 | } | ||
115 | if (!$scope.params.diferenciarMeses) { | ||
116 | producto.fechas = unirFechas(producto.fechas); | ||
117 | } | ||
118 | producto.fechas.forEach(function(fecha) { | ||
119 | //AGREGO FECHAS | ||
120 | if ($scope.params.diferenciarMeses) { | ||
121 | result.push({ | ||
122 | vehiculo: | ||
123 | 'Fecha: ' + fecha.month + ' - ' + fecha.year | ||
124 | }); | ||
125 | } else { | ||
126 | result.push({ | ||
127 | vehiculo: | ||
128 | 'Fecha: ' + fecha.year | ||
129 | }); | ||
130 | } | ||
131 | fecha.vehiculos.forEach(function(vehiculo) { | ||
132 | //AGREGO VEHICULOS | ||
133 | result.push({ | ||
134 | vehiculo: vehiculo.vehiculo, | ||
135 | ltsRepartidos: | ||
136 | $filter('number') | ||
137 | (vehiculo.data.ltsRepartidos, 2), | ||
138 | ltsOptimos: | ||
139 | $filter('number') | ||
140 | (vehiculo.data.ltsOptimos, 2), | ||
141 | diferencia: | ||
142 | $filter('number') | ||
143 | (vehiculo.data.diferencia, 2), | ||
144 | porcentaje: | ||
145 | $filter('number') | ||
146 | (vehiculo.data.porcentaje, 2) + '%' | ||
147 | }); | ||
148 | }); | ||
149 | }); | ||
150 | }); | ||
151 | } | ||
152 | }); | ||
153 | |||
154 | $scope.gridOptions.data = result; | ||
155 | $scope.generando = false; | ||
156 | $scope.buscar = false; | ||
157 | }); | ||
158 | }; | ||
159 | |||
160 | |||
161 | $scope.seleccionarSector = function(key) { | ||
162 | if (key === 13) { | ||
163 | var parametrosModal = { | ||
164 | titulo: 'Búsqueda de Sector', | ||
165 | query: '/sector', | ||
166 | columnas: [ | ||
167 | { | ||
168 | nombre: 'Código', | ||
169 | propiedad: 'ID' | ||
170 | }, | ||
171 | { | ||
172 | nombre: 'Nombre', | ||
173 | propiedad: 'NOMBRE' | ||
174 | } | ||
175 | ], | ||
176 | size: 'md' | ||
177 | }; | ||
178 | focaModalService.modal(parametrosModal).then( | ||
179 | function(sector) { | ||
180 | $scope.params.sector = sector; | ||
181 | }, function() {} | ||
182 | ); | ||
183 | } | ||
184 | }; | ||
185 | $scope.clearSector = function() { | ||
186 | $scope.params.sector = undefined; | ||
187 | }; | ||
188 | $scope.volver = function() { | ||
189 | $scope.buscar = true; | ||
190 | }; | ||
191 | $scope.cancel = function() { | ||
192 | $uibModalInstance.dismiss('Cancelar'); | ||
193 | }; | ||
194 | |||
195 | function unirProductos(productos) { | ||
196 | var result = [{fechas: []}]; | ||
197 | productos.forEach(function(producto) { | ||
198 | producto.fechas.forEach(function(fecha) { | ||
199 | var existe = result[0].fechas.filter(function(result) { | ||
200 | return result.fecha === fecha.fecha; | ||
201 | }); | ||
202 | if (existe.length) { | ||
203 | existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); | ||
204 | } else { | ||
205 | result[0].fechas.push(fecha); | ||
206 | } | ||
207 | |||
208 | }); | ||
209 | }); | ||
210 | result[0].fechas.forEach(function(fecha) { | ||
211 | fecha.vehiculos = unirVehiculos(fecha.vehiculos); | ||
212 | }); | ||
213 | return result; | ||
214 | } | ||
215 | |||
216 | function unirFechas(fechas) { | ||
217 | var results = []; | ||
218 | fechas.forEach(function(fecha) { | ||
219 | var existe = results.filter(function(result) { | ||
220 | return result.year === fecha.year; | ||
221 | }); | ||
222 | |||
223 | if (existe.length) { | ||
224 | existe[0].vehiculos = existe[0].vehiculos.concat(fecha.vehiculos); | ||
225 | } else { | ||
226 | results.push({ | ||
227 | year: fecha.year, | ||
228 | vehiculos: fecha.vehiculos | ||
229 | }); | ||
230 | } | ||
231 | }); | ||
232 | |||
233 | results.forEach(function(result) { | ||
234 | result.vehiculos = unirVehiculos(result.vehiculos); | ||
235 | }); | ||
236 | return results; | ||
237 | } | ||
238 | |||
239 | function unirVehiculos(vehiculos) { | ||
240 | var results = []; | ||
241 | vehiculos.forEach(function(vehiculo) { | ||
242 | var existe = results.filter(function(result) { | ||
243 | return result.vehiculo === vehiculo.vehiculo; | ||
244 | }); | ||
245 | |||
246 | if (existe.length) { | ||
247 | existe[0].data.kms += vehiculo.data.kms; | ||
248 | existe[0].data.lts += vehiculo.data.lts; | ||
249 | existe[0].data.viajes += vehiculo.data.viajes; | ||
250 | } else { | ||
251 | results.push(vehiculo); | ||
252 | } | ||
253 | }); | ||
254 | return results; | ||
255 | } | ||
256 | } | ||
257 | ] | ||
258 | ); | ||
259 |
src/js/service.js
1 | angular.module('focaModalInforme') | 1 | angular.module('focaModalInforme') |
2 | .factory('focaModalInformeChoferService', [ | 2 | .factory('focaModalInformeChoferService', [ |
3 | '$http', | 3 | '$http', |
4 | 'API_ENDPOINT', | 4 | 'API_ENDPOINT', |
5 | function($http, API_ENDPOINT) { | 5 | function($http, API_ENDPOINT) { |
6 | return { | 6 | return { |
7 | getDescargas: function(fechaDesde, fechaHasta) { | 7 | getDescargas: function(fechaDesde, fechaHasta) { |
8 | return $http.post(API_ENDPOINT.URL + '/informe/chofer', | 8 | return $http.post(API_ENDPOINT.URL + '/informe/chofer', |
9 | {fechaDesde: fechaDesde, fechaHasta: fechaHasta}); | 9 | {fechaDesde: fechaDesde, fechaHasta: fechaHasta}); |
10 | }, | 10 | }, |
11 | getEmpresa: function(id) { | 11 | getEmpresa: function(id) { |
12 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); | 12 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); |
13 | }, | 13 | }, |
14 | getDistanciaPorIdRemito: function(ids) { | 14 | getDistanciaPorIdRemito: function(ids) { |
15 | return $http.post(API_ENDPOINT.URL + '/remito/distancia', {ids: ids}); | 15 | return $http.post(API_ENDPOINT.URL + '/remito/distancia', {ids: ids}); |
16 | } | 16 | } |
17 | }; | 17 | }; |
18 | } | 18 | } |
19 | ]) | 19 | ]) |
20 | .factory('focaModalInformeGeneralUnidadService', [ | 20 | .factory('focaModalInformeGeneralUnidadService', [ |
21 | '$http', | 21 | '$http', |
22 | 'API_ENDPOINT', | 22 | 'API_ENDPOINT', |
23 | function($http, API_ENDPOINT) { | 23 | function($http, API_ENDPOINT) { |
24 | return { | 24 | return { |
25 | getEmpresa: function(id) { | 25 | getEmpresa: function(id) { |
26 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); | 26 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); |
27 | }, | 27 | }, |
28 | getInformeData: function(params) { | 28 | getInformeData: function(params) { |
29 | return $http.post(API_ENDPOINT.URL + '/informe/general-unidad-reparto', {params: params}); | 29 | return $http.post(API_ENDPOINT.URL + '/informe/general-unidad-reparto', |
30 | {params: params}); | ||
30 | } | 31 | } |
31 | }; | 32 | }; |
32 | } | 33 | } |
33 | ]) | 34 | ]) |
34 | .factory('focaModalInformeLitrosKmUnidadService', [ | 35 | .factory('focaModalInformeLitrosKmUnidadService', [ |
35 | '$http', | 36 | '$http', |
36 | 'API_ENDPOINT', | 37 | 'API_ENDPOINT', |
37 | function($http, API_ENDPOINT) { | 38 | function($http, API_ENDPOINT) { |
38 | return { | 39 | return { |
39 | getDescargas: function(idVehiculo, fechaDesde, fechaHasta) { | 40 | getDescargas: function(idVehiculo, fechaDesde, fechaHasta) { |
40 | return $http.post(API_ENDPOINT.URL + '/informe/litros-por-km', | 41 | return $http.post(API_ENDPOINT.URL + '/informe/litros-por-km', |
41 | {idVehiculo: idVehiculo, fechaDesde: fechaDesde, fechaHasta: fechaHasta}); | 42 | {idVehiculo: idVehiculo, fechaDesde: fechaDesde, fechaHasta: fechaHasta}); |
42 | }, | 43 | }, |
43 | getEmpresa: function(id) { | 44 | getEmpresa: function(id) { |
44 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); | 45 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); |
45 | }, | 46 | }, |
46 | getDistanciaPorIdRemito: function(ids) { | 47 | getDistanciaPorIdRemito: function(ids) { |
47 | return $http.post(API_ENDPOINT.URL + '/remito/distancia', {ids: ids}); | 48 | return $http.post(API_ENDPOINT.URL + '/remito/distancia', {ids: ids}); |
48 | } | 49 | } |
49 | }; | 50 | }; |
50 | } | 51 | } |
51 | ]) | 52 | ]) |
52 | .factory('focaModalInformeHojaRutaService', [ | 53 | .factory('focaModalInformeHojaRutaService', [ |
53 | '$http', | 54 | '$http', |
54 | 'API_ENDPOINT', | 55 | 'API_ENDPOINT', |
55 | function($http, API_ENDPOINT) { | 56 | function($http, API_ENDPOINT) { |
56 | return { | 57 | return { |
57 | getHojasRuta: function(fechaDesde, fechaHasta) { | 58 | getHojasRuta: function(fechaDesde, fechaHasta) { |
58 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/listar/' + | 59 | return $http.get(API_ENDPOINT.URL + '/hoja-ruta/listar/' + |
59 | fechaDesde + '/' + fechaHasta); | 60 | fechaDesde + '/' + fechaHasta); |
60 | }, | 61 | }, |
61 | getEmpresa: function(id) { | 62 | getEmpresa: function(id) { |
62 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); | 63 | return $http.get(API_ENDPOINT.URL + '/empresa/' + id); |
63 | } | 64 | } |
64 | }; | 65 | }; |
65 | } | 66 | } |
67 | ]) | ||
68 | .factory('focaModalInformeRepartoOptimoService', [ | ||
69 | '$http', | ||
70 | 'API_ENDPOINT', | ||
71 | function($http, API_ENDPOINT) { | ||
72 | return { | ||
73 | getInformeData: function(params) { | ||
74 | return $http.post(API_ENDPOINT.URL + '/informe/reparto-optimo', | ||
75 | {params: params}); | ||
76 | } | ||
77 | }; | ||
78 | } | ||
66 | ]); | 79 | ]); |
src/views/informe-reparto-optimo.html
File was created | 1 | <div class="modal-header py-1"> | |
2 | <div class="row w-100"> | ||
3 | <div class="col-12"><h5 class="modal-title">Informe de reparto óptimo detallado</h5></div> | ||
4 | <div class="col-12" ng-hide="buscar"> | ||
5 | Filtros: Fecha desde: {{fechaDesde | date: 'dd/MM/yyyy'}}, | ||
6 | Fecha hasta: {{fechaHasta | date: 'dd/MM/yyyy'}}, | ||
7 | Transportista : {{transportista.NOM}}, | ||
8 | Unidad: {{unidad.codigo}} | ||
9 | </div> | ||
10 | </div> | ||
11 | </div> | ||
12 | <div class="modal-body" id="modal-body"> | ||
13 | <div class="input-group row" | ||
14 | ng-show="buscar"> | ||
15 | <small class="col-md-2 col-4 text-left my-1">Fecha Desde</small> | ||
16 | <div class="col-md-4 col-8 input-group mb-2"> | ||
17 | <div class="input-group-prepend"> | ||
18 | <div class="input-group-text form-control-sm"> | ||
19 | <i class="fa fa-calendar"></i> | ||
20 | </div> | ||
21 | </div> | ||
22 | <input | ||
23 | class="form-control form-control-sm" | ||
24 | id="inlineFormInputGroup" | ||
25 | type="text" | ||
26 | ng-model="params.fechaDesde" | ||
27 | ng-required="true" | ||
28 | uib-datepicker-popup="dd/MM/yyyy" | ||
29 | show-button-bar="false" | ||
30 | is-open="datepickerOpen" | ||
31 | on-open-focus="false" | ||
32 | ng-focus="datepickerOpen = true" | ||
33 | datepicker-options="dateOptions" | ||
34 | /> | ||
35 | </div> | ||
36 | <small class="col-md-2 col-4 text-left my-1">Fecha Hasta</small> | ||
37 | <div class="col-md-4 col-8 input-group mb-2"> | ||
38 | <div class="input-group-prepend"> | ||
39 | <div class="input-group-text form-control-sm"> | ||
40 | <i class="fa fa-calendar"></i> | ||
41 | </div> | ||
42 | </div> | ||
43 | <input | ||
44 | class="form-control form-control-sm" | ||
45 | id="inlineFormInputGroup" | ||
46 | type="text" | ||
47 | ng-model="params.fechaHasta" | ||
48 | ng-required="true" | ||
49 | uib-datepicker-popup="dd/MM/yyyy" | ||
50 | show-button-bar="false" | ||
51 | is-open="datepicker2Open" | ||
52 | on-open-focus="false" | ||
53 | ng-focus="datepicker2Open = true" | ||
54 | /> | ||
55 | </div> | ||
56 | <small class="col-md-2 col-4 text-left my-1">Sector</small> | ||
57 | <div class="col-md-4 col-8 input-group mb-2"> | ||
58 | <input | ||
59 | class="form-control form-control-sm" | ||
60 | id="inlineFormInputGroup" | ||
61 | type="text" | ||
62 | ng-model="params.sector.NOMBRE" | ||
63 | ng-required="true" | ||
64 | ng-keypress="seleccionarSector($event.keyCode)" | ||
65 | /> | ||
66 | <button type="button" class="clear-input text-danger" ng-click="clearSector()"> | ||
67 | <i class="fa fa-times"></i> | ||
68 | </button> | ||
69 | <div class="input-group-append"> | ||
70 | <div class="input-group-append" ng-hide="ingreso"> | ||
71 | <button | ||
72 | ladda="searchLoading" | ||
73 | data-spinner-color="#FF0000" | ||
74 | class="btn btn-outline-secondary" | ||
75 | type="button" | ||
76 | ng-click="seleccionarSector(13)"> | ||
77 | <i class="fa fa-search" aria-hidden="true"></i> | ||
78 | </button> | ||
79 | </div> | ||
80 | </div> | ||
81 | </div> | ||
82 | <small class="col-md-4 col-8 text-left my-1">Diferenciar productos</small> | ||
83 | <div class="col-md-2 col-4 input-group mb-2"> | ||
84 | <div class="custom-control custom-checkbox ml-auto"> | ||
85 | <input | ||
86 | type="checkbox" | ||
87 | class="custom-control-input" | ||
88 | ng-model="params.diferenciarProductos" | ||
89 | id="customCheck1"> | ||
90 | <label class="custom-control-label" for="customCheck1"></label> | ||
91 | </div> | ||
92 | </div> | ||
93 | <small class="col-md-4 col-8 text-left my-1">Detallar por mes</small> | ||
94 | <div class="col-md-2 col-4 input-group mb-2"> | ||
95 | <div class="custom-control custom-checkbox ml-auto"> | ||
96 | <input | ||
97 | type="checkbox" | ||
98 | class="custom-control-input" | ||
99 | ng-model="params.diferenciarMeses" | ||
100 | id="customCheck2"> | ||
101 | <label class="custom-control-label" for="customCheck2"></label> | ||
102 | </div> | ||
103 | </div> | ||
104 | </div> | ||
105 | <div | ||
106 | ng-if="!buscar" | ||
107 | class="row"> | ||
108 | <div class="col-12"> | ||
109 | <div | ||
110 | class="gridInforme" | ||
111 | ui-grid="gridOptions" | ||
112 | ui-grid-exporter | ||
113 | ui-grid-resize-columns | ||
114 | ></div> | ||
115 | </div> | ||
116 | </div> | ||
117 | </div> | ||
118 | <div class="modal-footer py-1"> | ||
119 | <button | ||
120 | class="btn btn-sm btn-secondary" | ||
121 | type="button" | ||
122 | ng-click="cancel()" | ||
123 | ng-show="buscar">Cancelar</button> | ||
124 | <button | ||
125 | ladda="generando" | ||
126 | class="btn btn-sm btn-secondary" | ||
127 | type="button" | ||
128 | ng-click="generarInforme()" | ||
129 | ng-show="buscar">Generar</button> | ||
130 | <button | ||
131 | class="btn btn-sm btn-secondary" | ||
132 | type="button" | ||
133 | ng-click="volver()" | ||
134 | ng-hide="buscar">Volver</button> | ||
135 | </div> | ||
136 |