Commit c28654bef64d39099709ad3c513ccf6f1812321c
1 parent
65bab73095
Exists in
master
recibo fecha reparto, distribuyo funciones, refactor guardado de cisternas
Showing
3 changed files
with
44 additions
and
34 deletions
Show diff stats
src/js/controllerDetalleVehiculo.js
... | ... | @@ -7,27 +7,33 @@ angular.module('focaLogisticaPedidoRuta') |
7 | 7 | 'focaModalService', |
8 | 8 | '$filter', |
9 | 9 | 'focaLogisticaPedidoRutaService', |
10 | + 'fechaReparto', | |
10 | 11 | function($scope, $uibModalInstance, idVehiculo, idRemito, focaModalService, $filter, |
11 | - focaLogisticaPedidoRutaService | |
12 | + focaLogisticaPedidoRutaService, fechaReparto | |
12 | 13 | ) { |
13 | 14 | //seteo variables |
14 | 15 | $scope.cargandoDatos = true; |
15 | 16 | $scope.idRemito = idRemito; |
16 | 17 | $scope.articulos = []; |
17 | 18 | $scope.vehiculo = {}; |
19 | + $scope.cisternas = []; | |
20 | + $scope.cisternasCarga = []; | |
18 | 21 | $scope.remito = {}; |
19 | 22 | $scope.aCargar = []; |
20 | 23 | var cisternaMovimientos = []; |
21 | - var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); | |
22 | 24 | var promesaRemito; |
25 | + var promesaVehiculo = focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo); | |
26 | + var promesaCisternas = focaLogisticaPedidoRutaService | |
27 | + .obtenerCisternasPorFecha(idVehiculo, fechaReparto); | |
23 | 28 | if(idRemito !== -1) { |
24 | 29 | promesaRemito = focaLogisticaPedidoRutaService.obtenerRemitoById(idRemito); |
25 | 30 | } |
26 | - Promise.all([promesaVehiculo, promesaRemito]).then(function(res) { | |
31 | + Promise.all([promesaVehiculo, promesaCisternas, promesaRemito]).then(function(res) { | |
27 | 32 | $scope.cargandoDatos = false; |
28 | 33 | $scope.vehiculo = res[0].data; |
29 | - if(!res[1]) return; | |
30 | - $scope.remito = res[1].data; | |
34 | + $scope.cisternas = res[1].data; | |
35 | + if(!res[2]) return; | |
36 | + $scope.remito = res[2].data; | |
31 | 37 | if($scope.remito.idUsuarioProceso) { |
32 | 38 | focaModalService.alert('Remito ya asignado'); |
33 | 39 | $uibModalInstance.close(); |
... | ... | @@ -37,14 +43,12 @@ angular.module('focaLogisticaPedidoRuta') |
37 | 43 | }); |
38 | 44 | $scope.aceptar = function() { |
39 | 45 | $scope.cargando = true; |
40 | - var cisternaCargas = []; | |
41 | - for (var i = 0; i < $scope.vehiculo.cisternas.length; i++) { | |
42 | - delete $scope.vehiculo.cisternas[i].cisternaCarga.articulo; | |
43 | - cisternaCargas.push($scope.vehiculo.cisternas[i].cisternaCarga); | |
46 | + for (var i = 0; i < $scope.cisternasCarga.length; i++) { | |
47 | + delete $scope.cisternasCarga[i].articulo; | |
44 | 48 | } |
45 | 49 | var cisterna = { |
46 | 50 | cisternaMovimientos: cisternaMovimientos, |
47 | - cisternaCargas: cisternaCargas, | |
51 | + cisternaCargas: $scope.cisternasCarga, | |
48 | 52 | idVehiculo: $scope.vehiculo.id |
49 | 53 | }; |
50 | 54 | focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) |
... | ... | @@ -69,19 +73,14 @@ angular.module('focaLogisticaPedidoRuta') |
69 | 73 | $scope.cancelar = function() { |
70 | 74 | $uibModalInstance.close(); |
71 | 75 | }; |
72 | - $scope.cargarACisternas = function(vehiculo) { | |
73 | - for(var i = 0; i < vehiculo.cisternas.length; i++) { | |
74 | - var cisterna = vehiculo.cisternas[i]; | |
76 | + $scope.cargarACisternas = function() { | |
77 | + for(var i = 0; i < $scope.cisternas.length; i++) { | |
78 | + var cisterna = $scope.cisternas[i]; | |
75 | 79 | var aCargar = parseFloat($scope.aCargar[i]); |
76 | 80 | //validaciones |
77 | 81 | if(!aCargar) { |
78 | 82 | continue; |
79 | 83 | } |
80 | - if(aCargar > cisterna.disponible) { | |
81 | - focaModalService.alert('La cantidad cargada supera la capacidad de la' + | |
82 | - 'cisterna ' + cisterna.codigo); | |
83 | - return; | |
84 | - } | |
85 | 84 | //cargar |
86 | 85 | if(cisterna.cisternaCarga.cantidad) { |
87 | 86 | cisterna.cisternaCarga.cantidad += aCargar; |
... | ... | @@ -107,6 +106,9 @@ angular.module('focaLogisticaPedidoRuta') |
107 | 106 | idCisternaCarga: cisterna.cisternaCarga.id, |
108 | 107 | idRemito: $scope.remito.id |
109 | 108 | }; |
109 | + cisterna.cisternaCarga.fechaReparto = fechaReparto; | |
110 | + cisterna.cisternaCarga.idCisterna = cisterna.id; | |
111 | + $scope.cisternasCarga.push(cisterna.cisternaCarga); | |
110 | 112 | cisternaMovimientos.push(cisternaMovimiento); |
111 | 113 | } |
112 | 114 | var articuloSiguiente = $scope.articulos.filter( |
... | ... | @@ -131,7 +133,7 @@ angular.module('focaLogisticaPedidoRuta') |
131 | 133 | }; |
132 | 134 | $scope.seleccionarArticulo = function(articulo) { |
133 | 135 | $scope.articuloSeleccionado = articulo; |
134 | - $scope.cisternaDisabled(); | |
136 | + $scope.cisternaDisponible(); | |
135 | 137 | $scope.autoCompletar(); |
136 | 138 | $scope.actualizarArticulo(); |
137 | 139 | }; |
... | ... | @@ -144,21 +146,24 @@ angular.module('focaLogisticaPedidoRuta') |
144 | 146 | }; |
145 | 147 | $scope.autoCompletar = function() { |
146 | 148 | $scope.aCargar = []; |
147 | - var disponible = $filter('filter')($scope.vehiculo.cisternas, {disabled: false}); | |
148 | - var index = $scope.vehiculo.cisternas.indexOf(disponible[0]); | |
149 | + var disponible = $filter('filter')($scope.cisternas, {disabled: false}); | |
150 | + var index = $scope.cisternas.indexOf(disponible[0]); | |
149 | 151 | $scope.aCargar[index] = $scope.articuloSeleccionado.cantidad; |
150 | 152 | }; |
151 | - $scope.cisternaDisabled = function() { | |
152 | - for(var i = 0; i < $scope.vehiculo.cisternas.length; i++) { | |
153 | - var cisterna = $scope.vehiculo.cisternas[i]; | |
154 | - if(!$scope.articuloSeleccionado || ($scope.articuloSeleccionado.idArticulo !== | |
155 | - cisterna.cisternaCarga.idProducto && cisterna.cisternaCarga.idProducto) || | |
156 | - !$scope.tieneArticulosPendientes()|| $scope.articuloSeleccionado.cantidad > | |
157 | - cisterna.disponible) { | |
158 | - cisterna.disabled = true; | |
159 | - }else { | |
160 | - cisterna.disabled = false; | |
161 | - } | |
153 | + $scope.cisternaDisponible = function() { | |
154 | + for(var i = 0; i < $scope.cisternas.length; i++) { | |
155 | + if($scope.articuloSeleccionado.cantidad > $scope.cisternas[i].disponible) { | |
156 | + $scope.cisternas[i].disabled = true; | |
157 | + continue; | |
158 | + } | |
159 | + if($scope.cisternas[i].cisternaCarga.idProducto && | |
160 | + $scope.articuloSeleccionado.idArticulo !== | |
161 | + $scope.cisternas[i].cisternaCarga.idProducto) | |
162 | + { | |
163 | + $scope.cisternas[i].disabled = true; | |
164 | + continue; | |
165 | + } | |
166 | + $scope.cisternas[i].disabled = false; | |
162 | 167 | } |
163 | 168 | }; |
164 | 169 | $scope.rellenarInput = function(input) { |
... | ... | @@ -192,6 +197,7 @@ angular.module('focaLogisticaPedidoRuta') |
192 | 197 | return filter.cargado === true; |
193 | 198 | }); |
194 | 199 | if(articulosDescargados.length === $scope.articulos.length) { |
200 | + $scope.aCargar = []; | |
195 | 201 | return false; |
196 | 202 | } |
197 | 203 | return true; |
src/js/service.js
... | ... | @@ -68,6 +68,10 @@ angular.module('focaLogisticaPedidoRuta') |
68 | 68 | }, |
69 | 69 | getVehiculosByIdUsuario: function() { |
70 | 70 | return $http.get(API_ENDPOINT.URL + '/vehiculo/usuario/' + this.idUsuario); |
71 | + }, | |
72 | + obtenerCisternasPorFecha: function(idVehiculo, fecha) { | |
73 | + return $http.post(API_ENDPOINT.URL + '/cisterna/listar/fecha', | |
74 | + {idVehiculo: idVehiculo, fechaReparto: fecha}); | |
71 | 75 | } |
72 | 76 | }; |
73 | 77 | }]); |
src/views/foca-detalle-vehiculo.html
... | ... | @@ -57,7 +57,7 @@ |
57 | 57 | </tr> |
58 | 58 | </thead> |
59 | 59 | <tbody> |
60 | - <tr ng-repeat="(key, cisterna) in vehiculo.cisternas"> | |
60 | + <tr ng-repeat="(key, cisterna) in cisternas"> | |
61 | 61 | <td class="py-3" ng-bind="cisterna.codigo"></td> |
62 | 62 | <td class="py-3" ng-bind="cisterna.capacidad"></td> |
63 | 63 | <td class="py-3" ng-bind="cisterna.cisternaCarga.articulo.DetArt || 'Sin asignar'"></td> |
... | ... | @@ -68,7 +68,7 @@ |
68 | 68 | foca-teclado |
69 | 69 | placeholder="A cargar..." |
70 | 70 | ng-model="aCargar[key]" |
71 | - ng-disabled="cisterna.disabled" | |
71 | + ng-disabled="cisterna.disabled || !tieneArticulosPendientes()" | |
72 | 72 | ng-focus="aCargar[key] = rellenarInput(aCargar[key]); actualizarArticulo()" |
73 | 73 | ng-change="actualizarArticulo()" |
74 | 74 | > |