From 359d51a957a54a1ff666773500c952711b2fa366 Mon Sep 17 00:00:00 2001 From: Jose Pinto Date: Fri, 4 Jan 2019 17:45:47 -0300 Subject: [PATCH] capacidad total vehiculo, formato tabla y crear cisternas --- src/js/controller.js | 7 ++-- src/js/controllerCisterna.js | 59 +++++++++++++--------------------- src/views/foca-abm-cisterna-item.html | 33 ------------------- src/views/foca-abm-vehiculos-item.html | 31 ++++++++++++------ 4 files changed, 49 insertions(+), 81 deletions(-) diff --git a/src/js/controller.js b/src/js/controller.js index cf17dc2..78cf826 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -89,6 +89,7 @@ angular.module('focaAbmVehiculo') $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; $scope.now = new Date(); $scope.focused = 1; + $scope.transportistaStamp = ''; $timeout(function() { focaBotoneraLateralService.showSalir(false); @@ -113,11 +114,13 @@ angular.module('focaAbmVehiculo') $scope.vehiculo = {}; focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { if(res.data) { - var codigo = ('00000' + res.data.transportista.COD).slice(-5); + $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); + $scope.transportistaStamp += ' - ' + res.data.transportista.NOM + $scope.vehiculo = res.data; $scope.$broadcast('addCabecera', { label: 'Transportista:', - valor: codigo + ' - ' + res.data.transportista.NOM + valor: $scope.transportistaStamp }); $scope.$broadcast('addCabecera', { label: 'Unidad:', diff --git a/src/js/controllerCisterna.js b/src/js/controllerCisterna.js index 2ca1c18..a307c42 100644 --- a/src/js/controllerCisterna.js +++ b/src/js/controllerCisterna.js @@ -16,6 +16,7 @@ angular.module('focaAbmVehiculo') $scope.next = function(key) { if (key === 13) $scope.focused++; }; + $scope.capacidadVechiulo = 0; //SETEO BOTONERA LATERAL $timeout(function() { @@ -35,6 +36,7 @@ angular.module('focaAbmVehiculo') }); focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { var codigo = ('00000' + res.data.transportista.COD).slice(-5); + $scope.capacidadVechiulo = res.data.capacidad; $scope.$broadcast('addCabecera', { label: 'Transportista:', valor: codigo + ' - ' + res.data.transportista.NOM @@ -52,7 +54,7 @@ angular.module('focaAbmVehiculo') focaModalService.alert('Ingrese unidad de medida'); return; } - existeCodigoCisterna().then(function() { + validaCodigoCapacidad().then(function() { $scope.cisterna.idVehiculo = $routeParams.idVehiculo; delete $scope.cisterna.vehiculo; delete $scope.cisterna.unidadMedida; @@ -60,38 +62,12 @@ angular.module('focaAbmVehiculo') focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ $location.path('/vehiculo/' + $routeParams.idVehiculo); }); - }, function() { - focaModalService.alert('Código de cisterna existente'); + }, function(err) { + focaModalService.alert(err); }); }; - // $scope.seleccionarArticulo = function() { - // var modalInstance = $uibModal.open( - // { - // ariaLabelledBy: 'Busqueda de Productos', - // templateUrl: 'modal-busqueda-productos.html', - // controller: 'modalBusquedaProductosCtrl', - // resolve: { - // parametroProducto: { - // idLista: -1, - // cotizacion: 1, - // simbolo: '$' - // } - // }, - // size: 'lg' - // } - // ); - // modalInstance.result.then( - // function(producto) { - // $scope.cisterna.cisternaCarga.idProducto = producto.id, - // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; - // }, function() { - // // funcion ejecutada cuando se cancela el modal - // } - // ); - // }; - $scope.seleccionarUnidadMedida = function() { var modalInstance = $uibModal.open( { @@ -107,19 +83,30 @@ angular.module('focaAbmVehiculo') }); }; - function existeCodigoCisterna(){ + function validaCodigoCapacidad(){ return new Promise(function(resolve, reject) { focaAbmVehiculoService .getCisternadoPorVehiculo($routeParams.idVehiculo) .then(function(res){ - //Valida si existe numero de unidad - var existe = res.data.filter(function(cisterna) { - return cisterna.codigo === $scope.cisterna.codigo && - cisterna.id !== $scope.cisterna.id; + + var totalCargado = 0; + + res.data.forEach(function(cisterna) { + //SI EL CODIGO YA EXISTE + if(cisterna.codigo === $scope.cisterna.codigo && + cisterna.id !== $scope.cisterna.id){ + reject('Código de cisterna existente'); + } + if(cisterna.id !== $scope.cisterna.id){ + totalCargado += cisterna.capacidad; + } }); - if(existe.length){ - reject(existe); + //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO + totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); + if(totalCargado > $scope.capacidadVechiulo){ + reject('La capacidad total de las cisternas' + + ' debe ser menor o igual a la del vehiculo'); } else { resolve(); } diff --git a/src/views/foca-abm-cisterna-item.html b/src/views/foca-abm-cisterna-item.html index 6e845ce..80d687a 100644 --- a/src/views/foca-abm-cisterna-item.html +++ b/src/views/foca-abm-cisterna-item.html @@ -59,37 +59,4 @@ -
- -
- -
-
-
- -
- - -
-
diff --git a/src/views/foca-abm-vehiculos-item.html b/src/views/foca-abm-vehiculos-item.html index 6f94eb7..c8df567 100644 --- a/src/views/foca-abm-vehiculos-item.html +++ b/src/views/foca-abm-vehiculos-item.html @@ -16,7 +16,7 @@ @@ -29,8 +29,8 @@ type="text" teclado-virtual ng-model="vehiculo.codigo" - foca-focus="focused == 2" - ng-focus="focused = 2" + foca-focus="focused == 3" + ng-focus="focused = 3" ng-keypress="next($event.keyCode)" /> @@ -59,8 +59,23 @@ teclado-virtual ng-model="vehiculo.semi" ng-required="true" - foca-focus="focused == 3" - ng-focus="focused = 3" + foca-focus="focused == 4" + ng-focus="focused = 4" + ng-keypress="next($event.keyCode)" + /> + + +
+ +
+
@@ -74,8 +89,6 @@ Código Capacidad - Unidad de Medida - Carga