Commit 4145681338195ce6d55816b5b8d71b7650607bac
1 parent
12a3efbb58
Exists in
master
rechazo
Showing
2 changed files
with
10 additions
and
9 deletions
Show diff stats
src/js/controller.js
1 | angular.module('focaModalDetalleHojaRuta') | 1 | angular.module('focaModalDetalleHojaRuta') |
2 | .controller('focaModalDetalleHojaRutaController', | 2 | .controller('focaModalDetalleHojaRutaController', |
3 | [ | 3 | [ |
4 | '$filter', | 4 | '$filter', |
5 | '$scope', | 5 | '$scope', |
6 | '$uibModalInstance', | 6 | '$uibModalInstance', |
7 | 'idRemito', | 7 | 'idRemito', |
8 | 'focaModalDetalleHojaRutaService', | 8 | 'focaModalDetalleHojaRutaService', |
9 | 'focaModalService', | 9 | 'focaModalService', |
10 | 'focaSeguimientoService', | 10 | 'focaSeguimientoService', |
11 | '$uibModal', | 11 | '$uibModal', |
12 | function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService, | 12 | function($filter, $scope, $uibModalInstance, idRemito, focaModalDetalleHojaRutaService, |
13 | focaModalService, focaSeguimientoService, $uibModal) | 13 | focaModalService, focaSeguimientoService, $uibModal) |
14 | { | 14 | { |
15 | //Seteo variables | 15 | //Seteo variables |
16 | $scope.remito = {}; | 16 | $scope.remito = {}; |
17 | $scope.cisternas = []; | 17 | $scope.cisternas = []; |
18 | $scope.articuloSeleccionado = {}; | 18 | $scope.articuloSeleccionado = {}; |
19 | $scope.aDescargar = []; | 19 | $scope.aDescargar = []; |
20 | $scope.cargando = true; | 20 | $scope.cargando = true; |
21 | 21 | ||
22 | //Datos | 22 | //Datos |
23 | var promesaRemito = focaModalDetalleHojaRutaService | 23 | var promesaRemito = focaModalDetalleHojaRutaService |
24 | .getRemitoById(idRemito); | 24 | .getRemitoById(idRemito); |
25 | var promesaCisternas = focaModalDetalleHojaRutaService | 25 | var promesaCisternas = focaModalDetalleHojaRutaService |
26 | .getCisternasByIdRemito(idRemito); | 26 | .getCisternasByIdRemito(idRemito); |
27 | 27 | ||
28 | Promise.all([promesaRemito, promesaCisternas]).then(function(res) { | 28 | Promise.all([promesaRemito, promesaCisternas]).then(function(res) { |
29 | $scope.cargando = false; | 29 | $scope.cargando = false; |
30 | $scope.remito = res[0].data; | 30 | $scope.remito = res[0].data; |
31 | $scope.cisternas = res[1].data; | 31 | $scope.cisternas = res[1].data; |
32 | var articuloAChequear = $scope.remito.articulosRemito.filter( | 32 | var articuloAChequear = $scope.remito.articulosRemito.filter( |
33 | function(articulo) { | 33 | function(articulo) { |
34 | return !articulo.descargado; | 34 | return !articulo.descargado; |
35 | }); | 35 | }); |
36 | if(!articuloAChequear.length || $scope.remito.rechazado) { | 36 | if(!articuloAChequear.length || $scope.remito.rechazado) { |
37 | $scope.readonly = true; | 37 | $scope.readonly = true; |
38 | $scope.cambio($scope.remito.articulosRemito[0]); | 38 | $scope.cambio($scope.remito.articulosRemito[0]); |
39 | }else { | 39 | }else { |
40 | $scope.cambio(articuloAChequear[0]); | 40 | $scope.cambio(articuloAChequear[0]); |
41 | } | 41 | } |
42 | $scope.$digest(); | 42 | $scope.$digest(); |
43 | }, function() { | 43 | }, function() { |
44 | focaModalService.alert('El servicio no responde intente más tarde'); | 44 | focaModalService.alert('El servicio no responde intente más tarde'); |
45 | $uibModalInstance.dismiss(); | 45 | $uibModalInstance.dismiss(); |
46 | }); | 46 | }); |
47 | $scope.cambio = function(articulo) { | 47 | $scope.cambio = function(articulo) { |
48 | if(!$scope.articuloSeleccionado.descargado) { | 48 | if(!$scope.articuloSeleccionado.descargado) { |
49 | $scope.articuloSeleccionado.cantidadDescargada = 0; | 49 | $scope.articuloSeleccionado.cantidadDescargada = 0; |
50 | } | 50 | } |
51 | $scope.aDescargar = []; | 51 | $scope.aDescargar = []; |
52 | $scope.articuloSeleccionado = articulo; | 52 | $scope.articuloSeleccionado = articulo; |
53 | }; | 53 | }; |
54 | $scope.descargar = function(key) { | 54 | $scope.descargar = function(key) { |
55 | if(key === 13) { | 55 | if(key === 13) { |
56 | $scope.cargando = true; | 56 | $scope.cargando = true; |
57 | var hojaRutaMovimientos = []; | 57 | var hojaRutaMovimientos = []; |
58 | var cisternaMovimientos = []; | 58 | var cisternaMovimientos = []; |
59 | var cisternaCargas = []; | 59 | var cisternaCargas = []; |
60 | var totalADescargar = 0; | 60 | var totalADescargar = 0; |
61 | for(var i = 0; i < $scope.aDescargar.length; i++) { | 61 | for(var i = 0; i < $scope.aDescargar.length; i++) { |
62 | totalADescargar += $scope.aDescargar[i] || 0; | 62 | totalADescargar += $scope.aDescargar[i] || 0; |
63 | } | 63 | } |
64 | focaModalService | 64 | focaModalService |
65 | .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + | 65 | .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + |
66 | $scope.articuloSeleccionado.descripcion + '?') | 66 | $scope.articuloSeleccionado.descripcion + '?') |
67 | .then(descargar, function() { | 67 | .then(descargar, function() { |
68 | $scope.cargando = false; | 68 | $scope.cargando = false; |
69 | }); | 69 | }); |
70 | } | 70 | } |
71 | function descargar() { | 71 | function descargar() { |
72 | for(var i = 0; i < $scope.cisternas.length; i++) { | 72 | for(var i = 0; i < $scope.cisternas.length; i++) { |
73 | var descarga = $scope.aDescargar[i]; | 73 | var descarga = $scope.aDescargar[i]; |
74 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; | 74 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; |
75 | if(!descarga) continue; | 75 | if(!descarga) continue; |
76 | if(descarga > cisternaCarga.cantidad) { | 76 | if(descarga > cisternaCarga.cantidad) { |
77 | focaModalService.alert('La cantidad a descargar no debe ser ' + | 77 | focaModalService.alert('La cantidad a descargar no debe ser ' + |
78 | 'mayor a la cantidad de la cisterna'); | 78 | 'mayor a la cantidad de la cisterna'); |
79 | $scope.cargando = false; | 79 | $scope.cargando = false; |
80 | return; | 80 | return; |
81 | } | 81 | } |
82 | cisternaCarga.cantidad -= descarga; | 82 | cisternaCarga.cantidad -= descarga; |
83 | 83 | ||
84 | //Guardar | 84 | //Guardar |
85 | var now = new Date(); | 85 | var now = new Date(); |
86 | var cisternaMovimiento = { | 86 | var cisternaMovimiento = { |
87 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), | 87 | fecha: now.toISOString().slice(0, 19).replace('T', ' '), |
88 | cantidad: descarga, | 88 | cantidad: descarga, |
89 | metodo: 'descarga', | 89 | metodo: 'descarga', |
90 | idCisternaCarga: cisternaCarga.id, | 90 | idCisternaCarga: cisternaCarga.id, |
91 | idRemito: $scope.remito.id | 91 | idRemito: $scope.remito.id |
92 | }; | 92 | }; |
93 | var hojaRutaMovimiento = { | 93 | var hojaRutaMovimiento = { |
94 | reciboDescarga: $scope.numeroRecibo, | 94 | reciboDescarga: $scope.numeroRecibo, |
95 | idRemito: $scope.remito.id | 95 | idRemito: $scope.remito.id |
96 | }; | 96 | }; |
97 | delete cisternaCarga.articulo; | 97 | delete cisternaCarga.articulo; |
98 | cisternaCargas.push(cisternaCarga); | 98 | cisternaCargas.push(cisternaCarga); |
99 | cisternaMovimientos.push(cisternaMovimiento); | 99 | cisternaMovimientos.push(cisternaMovimiento); |
100 | hojaRutaMovimientos.push(hojaRutaMovimiento); | 100 | hojaRutaMovimientos.push(hojaRutaMovimiento); |
101 | } | 101 | } |
102 | var save = { | 102 | var save = { |
103 | cisternaCargas: cisternaCargas, | 103 | cisternaCargas: cisternaCargas, |
104 | cisternaMovimientos: cisternaMovimientos, | 104 | cisternaMovimientos: cisternaMovimientos, |
105 | hojaRutaMovimientos: hojaRutaMovimientos, | 105 | hojaRutaMovimientos: hojaRutaMovimientos, |
106 | articulo: $scope.articuloSeleccionado | 106 | articulo: $scope.articuloSeleccionado |
107 | }; | 107 | }; |
108 | focaModalDetalleHojaRutaService | 108 | focaModalDetalleHojaRutaService |
109 | .postMovimientoHojaRuta(save) | 109 | .postMovimientoHojaRuta(save) |
110 | .then(guardarSeguimiento) | 110 | .then(guardarSeguimiento) |
111 | .catch(error); | 111 | .catch(error); |
112 | function guardarSeguimiento(res) { | 112 | function guardarSeguimiento(res) { |
113 | focaSeguimientoService | 113 | focaSeguimientoService |
114 | .guardarPosicion( | 114 | .guardarPosicion( |
115 | 'Entrega de producto', | 115 | 'Entrega de producto', |
116 | res.data[0].id, | 116 | res.data[0].id, |
117 | $scope.remito.observaciones); | 117 | $scope.remito.observaciones); |
118 | $scope.aDescargar = []; | 118 | $scope.aDescargar = []; |
119 | $scope.remito.observaciones = ''; | 119 | $scope.remito.observaciones = ''; |
120 | $scope.articuloSeleccionado.descargado = true; | 120 | $scope.articuloSeleccionado.descargado = true; |
121 | var siguienteArticulo = $scope.remito.articulosRemito.filter( | 121 | var siguienteArticulo = $scope.remito.articulosRemito.filter( |
122 | function(articulo) { | 122 | function(articulo) { |
123 | return articulo.id != $scope.articuloSeleccionado.id; | 123 | return articulo.id != $scope.articuloSeleccionado.id; |
124 | } | 124 | } |
125 | ); | 125 | ); |
126 | if(siguienteArticulo.length) { | 126 | if(siguienteArticulo.length) { |
127 | $scope.cambio(siguienteArticulo[0]); | 127 | $scope.cambio(siguienteArticulo[0]); |
128 | } | 128 | } |
129 | $scope.actualizarPuntoDescarga(); | 129 | $scope.actualizarPuntoDescarga(); |
130 | } | 130 | } |
131 | } | 131 | } |
132 | }; | 132 | }; |
133 | 133 | ||
134 | $scope.cancel = function() { | 134 | $scope.cancel = function() { |
135 | $uibModalInstance.dismiss('cancel'); | 135 | $uibModalInstance.dismiss('cancel'); |
136 | }; | 136 | }; |
137 | 137 | ||
138 | $scope.distribucionDisponible = function() { | 138 | $scope.distribucionDisponible = function() { |
139 | return $scope.articuloSeleccionado.cantidadDescargada && | 139 | return $scope.articuloSeleccionado.cantidadDescargada && |
140 | $scope.articuloSeleccionado.cantidadDescargada <= | 140 | $scope.articuloSeleccionado.cantidadDescargada <= |
141 | $scope.articuloSeleccionado.cantidad; | 141 | $scope.articuloSeleccionado.cantidad; |
142 | }; | 142 | }; |
143 | 143 | ||
144 | $scope.actualizarArticulo = function() { | 144 | $scope.actualizarArticulo = function() { |
145 | $scope.articuloSeleccionado.cantidadDescargada = 0; | 145 | $scope.articuloSeleccionado.cantidadDescargada = 0; |
146 | for(var i = 0; i < $scope.aDescargar.length; i++) { | 146 | for(var i = 0; i < $scope.aDescargar.length; i++) { |
147 | $scope.articuloSeleccionado.cantidadDescargada += | 147 | $scope.articuloSeleccionado.cantidadDescargada += |
148 | parseFloat($scope.aDescargar[i]) || 0; | 148 | parseFloat($scope.aDescargar[i]) || 0; |
149 | } | 149 | } |
150 | }; | 150 | }; |
151 | 151 | ||
152 | $scope.actualizarPuntoDescarga = function() { | 152 | $scope.actualizarPuntoDescarga = function() { |
153 | var modalInstance = $uibModal.open( | 153 | var modalInstance = $uibModal.open( |
154 | { | 154 | { |
155 | ariaLabelledBy: 'Actualizar punto de descarga', | 155 | ariaLabelledBy: 'Actualizar punto de descarga', |
156 | templateUrl: 'modal-actualizar-punto-descarga.html', | 156 | templateUrl: 'modal-actualizar-punto-descarga.html', |
157 | controller: 'focaModalActualizarPuntoDescargaController', | 157 | controller: 'focaModalActualizarPuntoDescargaController', |
158 | resolve: { | 158 | resolve: { |
159 | puntosDescarga: function() { | 159 | puntosDescarga: function() { |
160 | return $scope.remito.notaPedido.notaPedidoPuntoDescarga; | 160 | return $scope.remito.notaPedido.notaPedidoPuntoDescarga; |
161 | } | 161 | } |
162 | }, | 162 | }, |
163 | size: 'lg' | 163 | size: 'lg' |
164 | } | 164 | } |
165 | ); | 165 | ); |
166 | modalInstance.result.then(function() { | 166 | modalInstance.result.then(function() { |
167 | success(); | 167 | success(); |
168 | }, function() { | 168 | }, function() { |
169 | success(); | 169 | success(); |
170 | }); | 170 | }); |
171 | }; | 171 | }; |
172 | 172 | ||
173 | $scope.rechazar = function() { | 173 | $scope.rechazar = function() { |
174 | focaModalService | 174 | focaModalService |
175 | .prompt('Aclare el motivo de rechazo') | 175 | .prompt('Aclare el motivo de rechazo') |
176 | .then(function(motivo) { | 176 | .then(function(motivo) { |
177 | $scope.cargando = true; | 177 | $scope.cargando = true; |
178 | var remitoRechazado = $.extend(true, {}, $scope.remito); | 178 | var remitoRechazado = $.extend(true, {}, $scope.remito); |
179 | delete remitoRechazado.articulosRemito; | 179 | delete remitoRechazado.articulosRemito; |
180 | delete remitoRechazado.notaPedido; | 180 | delete remitoRechazado.notaPedido; |
181 | remitoRechazado.rechazado = true; | 181 | remitoRechazado.rechazado = true; |
182 | remitoRechazado.motivoRechazo = motivo; | 182 | remitoRechazado.motivoRechazo = motivo; |
183 | remitoRechazado.fechaRemito = | 183 | remitoRechazado.fechaRemito = |
184 | remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' '); | 184 | remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' '); |
185 | Promise.all([ | 185 | focaModalDetalleHojaRutaService.rechazarRemito(remitoRechazado) |
186 | focaModalDetalleHojaRutaService | 186 | .then(function(res) { |
187 | .rechazarRemito(remitoRechazado), | 187 | focaSeguimientoService.guardarPosicion( |
188 | focaSeguimientoService.guardarPosicion( | 188 | 'Entrega de producto', |
189 | 'Entrega de producto', | 189 | res.data[1].id, |
190 | remitoRechazado.id, | 190 | motivo); |
191 | motivo) | 191 | success(); |
192 | ]).then(success).catch(error); | 192 | }) |
193 | .catch(error); | ||
193 | $scope.readonly = true; | 194 | $scope.readonly = true; |
194 | }); | 195 | }); |
195 | }; | 196 | }; |
196 | 197 | ||
197 | //funciones | 198 | //funciones |
198 | function error(error) { | 199 | function error(error) { |
199 | focaModalService.alert('Hubo un error ' + error); | 200 | focaModalService.alert('Hubo un error ' + error); |
200 | } | 201 | } |
201 | function success() { | 202 | function success() { |
202 | focaModalService.alert('Operación realizada con éxito'); | 203 | focaModalService.alert('Operación realizada con éxito'); |
203 | $scope.cargando = false; | 204 | $scope.cargando = false; |
204 | } | 205 | } |
205 | } | 206 | } |
206 | ] | 207 | ] |
207 | ) | 208 | ) |
208 | .controller('focaModalActualizarPuntoDescargaController', | 209 | .controller('focaModalActualizarPuntoDescargaController', |
209 | [ | 210 | [ |
210 | '$scope', | 211 | '$scope', |
211 | '$uibModalInstance', | 212 | '$uibModalInstance', |
212 | 'focaSeguimientoService', | 213 | 'focaSeguimientoService', |
213 | 'focaModalService', | 214 | 'focaModalService', |
214 | 'puntosDescarga', | 215 | 'puntosDescarga', |
215 | 'focaModalDetalleHojaRutaService', | 216 | 'focaModalDetalleHojaRutaService', |
216 | function($scope, $uibModalInstance, focaSeguimientoService, | 217 | function($scope, $uibModalInstance, focaSeguimientoService, |
217 | focaModalService, puntosDescarga, focaModalDetalleHojaRutaService) | 218 | focaModalService, puntosDescarga, focaModalDetalleHojaRutaService) |
218 | { | 219 | { |
219 | $scope.puntosDescarga = puntosDescarga; | 220 | $scope.puntosDescarga = puntosDescarga; |
220 | focaSeguimientoService.obtenerPosicion(function(res) { | 221 | focaSeguimientoService.obtenerPosicion(function(res) { |
221 | $scope.posicion = res.coords; | 222 | $scope.posicion = res.coords; |
222 | }); | 223 | }); |
223 | 224 | ||
224 | $scope.cancel = function() { | 225 | $scope.cancel = function() { |
225 | $uibModalInstance.dismiss(); | 226 | $uibModalInstance.dismiss(); |
226 | }; | 227 | }; |
227 | 228 | ||
228 | $scope.select = function(puntoDescarga) { | 229 | $scope.select = function(puntoDescarga) { |
229 | if(!$scope.posicion){ | 230 | if(!$scope.posicion){ |
230 | focaModalService.alert('No se pudo obtener la ubicacion'); | 231 | focaModalService.alert('No se pudo obtener la ubicacion'); |
231 | return; | 232 | return; |
232 | } | 233 | } |
233 | puntoDescarga.latitud = $scope.posicion.latitude; | 234 | puntoDescarga.latitud = $scope.posicion.latitude; |
234 | puntoDescarga.longitud = $scope.posicion.longitude; | 235 | puntoDescarga.longitud = $scope.posicion.longitude; |
235 | focaModalDetalleHojaRutaService | 236 | focaModalDetalleHojaRutaService |
236 | .updatePuntoDescarga(puntoDescarga) | 237 | .updatePuntoDescarga(puntoDescarga) |
237 | .then(function(res) { | 238 | .then(function(res) { |
238 | $uibModalInstance.close(res.data); | 239 | $uibModalInstance.close(res.data); |
239 | }); | 240 | }); |
240 | }; | 241 | }; |
241 | } | 242 | } |
242 | ] | 243 | ] |
243 | ); | 244 | ); |
244 | 245 |
src/js/service.js
1 | angular.module('focaModalDetalleHojaRuta') | 1 | angular.module('focaModalDetalleHojaRuta') |
2 | .service('focaModalDetalleHojaRutaService', [ | 2 | .service('focaModalDetalleHojaRutaService', [ |
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 | getDetallesHojaRuta: function() { | 7 | getDetallesHojaRuta: function() { |
8 | return $http.get(API_ENDPOINT.URL + '/transportista'); | 8 | return $http.get(API_ENDPOINT.URL + '/transportista'); |
9 | }, | 9 | }, |
10 | getCisternasByIdRemito: function(idRemito) { | 10 | getCisternasByIdRemito: function(idRemito) { |
11 | return $http.get(API_ENDPOINT.URL + '/cisternas/obtener/remito/' + idRemito); | 11 | return $http.get(API_ENDPOINT.URL + '/cisternas/obtener/remito/' + idRemito); |
12 | }, | 12 | }, |
13 | getRemitoById: function(idRemito) { | 13 | getRemitoById: function(idRemito) { |
14 | return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito + '/punto'); | 14 | return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito + '/punto'); |
15 | }, | 15 | }, |
16 | postMovimientoHojaRuta: function(datos) { | 16 | postMovimientoHojaRuta: function(datos) { |
17 | return $http.post(API_ENDPOINT.URL + '/hoja-ruta/movimiento', datos); | 17 | return $http.post(API_ENDPOINT.URL + '/hoja-ruta/movimiento', datos); |
18 | }, | 18 | }, |
19 | rechazarRemito: function(remito) { | 19 | rechazarRemito: function(remito) { |
20 | return $http.post(API_ENDPOINT.URL + '/remito/update', {remito: remito}); | 20 | return $http.post(API_ENDPOINT.URL + '/remito/rechazar', {remito: remito}); |
21 | }, | 21 | }, |
22 | updatePuntoDescarga: function(puntoDescarga) { | 22 | updatePuntoDescarga: function(puntoDescarga) { |
23 | return $http.post(API_ENDPOINT.URL + '/punto-descarga', | 23 | return $http.post(API_ENDPOINT.URL + '/punto-descarga', |
24 | {puntoDescarga: puntoDescarga}); | 24 | {puntoDescarga: puntoDescarga}); |
25 | } | 25 | } |
26 | }; | 26 | }; |
27 | } | 27 | } |
28 | ]); | 28 | ]); |
29 | 29 |