Commit 7888b4110a7204287717eca6d9acd27fd9bcc20d
1 parent
b7ba244196
Exists in
master
and in
2 other branches
validaciones, rechazo remito
Showing
3 changed files
with
67 additions
and
20 deletions
 
Show diff stats
src/js/controller.js
| ... | ... | @@ -17,7 +17,7 @@ angular.module('focaModalDetalleHojaRuta') | 
| 17 | 17 | $scope.articuloSeleccionado = {}; | 
| 18 | 18 | $scope.aDescargar = []; | 
| 19 | 19 | $scope.cargando = true; | 
| 20 | - | |
| 20 | + | |
| 21 | 21 | //Datos | 
| 22 | 22 | var promesaRemito = focaModalDetalleHojaRutaService | 
| 23 | 23 | .getRemitoById(idRemito); | 
| ... | ... | @@ -28,35 +28,54 @@ angular.module('focaModalDetalleHojaRuta') | 
| 28 | 28 | $scope.cargando = false; | 
| 29 | 29 | $scope.remito = res[0].data; | 
| 30 | 30 | $scope.cisternas = res[1].data; | 
| 31 | - $scope.cambio($scope.remito.articulosRemito[0]); | |
| 31 | + var articuloAChequear = $scope.remito.articulosRemito.filter( | |
| 32 | + function(articulo) { | |
| 33 | + return !articulo.descargado; | |
| 34 | + }); | |
| 35 | + if(!articuloAChequear.length || $scope.remito.rechazado) { | |
| 36 | + $scope.readonly = true; | |
| 37 | + $scope.cambio($scope.remito.articulosRemito[0]); | |
| 38 | + }else { | |
| 39 | + $scope.cambio(articuloAChequear[0]); | |
| 40 | + } | |
| 32 | 41 | $scope.$digest(); | 
| 33 | 42 | }, function() { | 
| 34 | 43 | focaModalService.alert('El servicio no responde intente más tarde'); | 
| 35 | 44 | $uibModalInstance.dismiss(); | 
| 36 | 45 | }); | 
| 37 | 46 | $scope.cambio = function(articulo) { | 
| 47 | + if(!$scope.articuloSeleccionado.descargado) { | |
| 48 | + $scope.articuloSeleccionado.cantidadDescargada = 0; | |
| 49 | + } | |
| 38 | 50 | $scope.aDescargar = []; | 
| 39 | 51 | $scope.articuloSeleccionado = articulo; | 
| 40 | 52 | }; | 
| 41 | 53 | $scope.descargar = function(key) { | 
| 42 | - var hojaRutaMovimientos = []; | |
| 43 | - var cisternaMovimientos = []; | |
| 44 | - var cisternaCargas = []; | |
| 45 | - var totalADescargar = 0; | |
| 46 | - for (var i = 0; i < $scope.aDescargar.length; i++) { | |
| 47 | - totalADescargar += $scope.aDescargar[i] || 0; | |
| 48 | - } | |
| 49 | 54 | if(key === 13) { | 
| 55 | + $scope.cargando = true; | |
| 56 | + var hojaRutaMovimientos = []; | |
| 57 | + var cisternaMovimientos = []; | |
| 58 | + var cisternaCargas = []; | |
| 59 | + var totalADescargar = 0; | |
| 60 | + for(var i = 0; i < $scope.aDescargar.length; i++) { | |
| 61 | + totalADescargar += $scope.aDescargar[i] || 0; | |
| 62 | + } | |
| 50 | 63 | focaModalService | 
| 51 | 64 | .confirm('¿Desea descargar ' + totalADescargar + ' litros de ' + | 
| 52 | 65 | $scope.articuloSeleccionado.descripcion + '?') | 
| 53 | 66 | .then(descargar); | 
| 54 | 67 | } | 
| 55 | 68 | function descargar() { | 
| 56 | - for (var i = 0; i < $scope.cisternas.length; i++) { | |
| 69 | + for(var i = 0; i < $scope.cisternas.length; i++) { | |
| 57 | 70 | var descarga = $scope.aDescargar[i]; | 
| 58 | - if(!descarga) continue; | |
| 59 | 71 | var cisternaCarga = $scope.cisternas[i].cisternaCarga; | 
| 72 | + if(!descarga) continue; | |
| 73 | + if(descarga > cisternaCarga.cantidad) { | |
| 74 | + focaModalService.alert('La cantidad a descargar no debe ser ' + | |
| 75 | + 'mayor a la cantidad de la cisterna'); | |
| 76 | + $scope.cargando = false; | |
| 77 | + return; | |
| 78 | + } | |
| 60 | 79 | cisternaCarga.cantidad -= descarga; | 
| 61 | 80 | |
| 62 | 81 | //Guardar | 
| ... | ... | @@ -80,7 +99,8 @@ angular.module('focaModalDetalleHojaRuta') | 
| 80 | 99 | var save = { | 
| 81 | 100 | cisternaCargas: cisternaCargas, | 
| 82 | 101 | cisternaMovimientos: cisternaMovimientos, | 
| 83 | - hojaRutaMovimientos: hojaRutaMovimientos | |
| 102 | + hojaRutaMovimientos: hojaRutaMovimientos, | |
| 103 | + articulo: $scope.articuloSeleccionado | |
| 84 | 104 | }; | 
| 85 | 105 | focaModalDetalleHojaRutaService | 
| 86 | 106 | .postMovimientoHojaRuta(save) | 
| ... | ... | @@ -94,6 +114,15 @@ angular.module('focaModalDetalleHojaRuta') | 
| 94 | 114 | $scope.remito.observaciones); | 
| 95 | 115 | $scope.aDescargar = []; | 
| 96 | 116 | $scope.remito.observaciones = ''; | 
| 117 | + $scope.articuloSeleccionado.descargado = true; | |
| 118 | + var siguienteArticulo = $scope.remito.articulosRemito.filter( | |
| 119 | + function(articulo) { | |
| 120 | + return articulo.id != $scope.articuloSeleccionado.id; | |
| 121 | + } | |
| 122 | + ); | |
| 123 | + if(siguienteArticulo.length) { | |
| 124 | + $scope.cambio(siguienteArticulo[0]); | |
| 125 | + } | |
| 97 | 126 | success(); | 
| 98 | 127 | } | 
| 99 | 128 | } | 
| ... | ... | @@ -119,18 +148,30 @@ angular.module('focaModalDetalleHojaRuta') | 
| 119 | 148 | $scope.rechazar = function() { | 
| 120 | 149 | focaModalService | 
| 121 | 150 | .prompt('Aclare el motivo de rechazo') | 
| 122 | - .then(function() { | |
| 123 | - focaModalService.alert('desarrollo'); | |
| 124 | - $uibModalInstance.dismiss(); | |
| 151 | + .then(function(motivo) { | |
| 152 | + $scope.cargando = true; | |
| 153 | + var remitoRechazado = $.extend(true, {}, $scope.remito); | |
| 154 | + delete remitoRechazado.articulosRemito; | |
| 155 | + delete remitoRechazado.notaPedido; | |
| 156 | + remitoRechazado.rechazado = true; | |
| 157 | + remitoRechazado.motivoRechazo = motivo; | |
| 158 | + remitoRechazado.fechaRemito = | |
| 159 | + remitoRechazado.fechaRemito.slice(0, 19).replace('T', ' '); | |
| 160 | + focaModalDetalleHojaRutaService | |
| 161 | + .rechazarRemito(remitoRechazado) | |
| 162 | + .then(success) | |
| 163 | + .catch(error) | |
| 164 | + $scope.readonly = true; | |
| 125 | 165 | }); | 
| 126 | 166 | }; | 
| 127 | - | |
| 167 | + | |
| 128 | 168 | //funciones | 
| 129 | 169 | function error(error) { | 
| 130 | 170 | focaModalService.alert('Hubo un error ' + error); | 
| 131 | 171 | } | 
| 132 | 172 | function success() { | 
| 133 | 173 | focaModalService.alert('Operación realizada con éxito'); | 
| 174 | + $scope.cargando = false; | |
| 134 | 175 | } | 
| 135 | 176 | } | 
| 136 | 177 | ] | 
src/js/service.js
| ... | ... | @@ -15,6 +15,9 @@ angular.module('focaModalDetalleHojaRuta') | 
| 15 | 15 | }, | 
| 16 | 16 | postMovimientoHojaRuta: function(datos) { | 
| 17 | 17 | return $http.post(API_ENDPOINT.URL + '/hoja-ruta/movimiento', datos); | 
| 18 | + }, | |
| 19 | + rechazarRemito: function(remito) { | |
| 20 | + return $http.post(API_ENDPOINT.URL + '/remito/update', {remito: remito}); | |
| 18 | 21 | } | 
| 19 | 22 | }; | 
| 20 | 23 | } | 
src/views/modal-detalle-hoja-ruta.html
| ... | ... | @@ -76,12 +76,12 @@ | 
| 76 | 76 | name="articuloRadio" | 
| 77 | 77 | id="{{'articulo' + articulo.id}}" | 
| 78 | 78 | ng-click="cambio(articulo)" | 
| 79 | - ng-disabled="articulo.cargado" | |
| 79 | + ng-disabled="articulo.descargado || readonly" | |
| 80 | 80 | ng-checked="articuloSeleccionado.id === articulo.id" | 
| 81 | 81 | ></td> | 
| 82 | 82 | <td ng-bind="articulo.descripcion"></td> | 
| 83 | 83 | <td ng-bind="articulo.cantidad"></td> | 
| 84 | - <td ng-bind="articulo.cantidad - articulo.cantidadDescargada"></td> | |
| 84 | + <td ng-bind="articulo.cantidadDescargada || 0"></td> | |
| 85 | 85 | </tbody> | 
| 86 | 86 | </table> | 
| 87 | 87 | <strong>Cisterna</strong> | 
| ... | ... | @@ -105,7 +105,8 @@ | 
| 105 | 105 | ng-model="aDescargar[key]" | 
| 106 | 106 | ng-change="actualizarArticulo()" | 
| 107 | 107 | foca-focus="articuloSeleccionado.idArticulo == cisterna.cisternaCarga.idProducto" | 
| 108 | - ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto"/></td> | |
| 108 | + ng-disabled="articuloSeleccionado.idArticulo != cisterna.cisternaCarga.idProducto | |
| 109 | + || readonly"/></td> | |
| 109 | 110 | </tr> | 
| 110 | 111 | </tbody> | 
| 111 | 112 | </table> | 
| ... | ... | @@ -117,6 +118,7 @@ | 
| 117 | 118 | <div class="col-12"> | 
| 118 | 119 | <textarea | 
| 119 | 120 | ng-model="remito.observaciones" | 
| 121 | + ng-disabled="readonly" | |
| 120 | 122 | class="form-control form-control-sm" | 
| 121 | 123 | rows="1" | 
| 122 | 124 | ></textarea> | 
| ... | ... | @@ -126,6 +128,7 @@ | 
| 126 | 128 | <input | 
| 127 | 129 | class="form-control form-control-sm col-4" | 
| 128 | 130 | type="number" | 
| 131 | + ng-disabled="readonly" | |
| 129 | 132 | ng-model="numeroRecibo" | 
| 130 | 133 | ng-keypress="descargar($event.keyCode)" | 
| 131 | 134 | foca-focus="distribucionDisponible()"> | 
| ... | ... | @@ -146,7 +149,7 @@ | 
| 146 | 149 | class="btn btn-danger btn-sm" | 
| 147 | 150 | type="button" | 
| 148 | 151 | ng-click="rechazar()" | 
| 149 | - ng-disabled="" | |
| 152 | + ng-disabled="readonly" | |
| 150 | 153 | >Rechazar</button> | 
| 151 | 154 | <button | 
| 152 | 155 | class="btn btn-secondary btn-sm" |