Commit 585a3822db2dfc484c2ec8fad386503aa01025d5

Authored by Eric Fernandez
Exists in master

Merge branch 'master' into 'develop'

Master

See merge request !50
src/js/controller.js
... ... @@ -124,6 +124,7 @@ angular.module('focaAbmVehiculo')
124 124 var codigo = ('00000' + res.data[0].COD).slice(-5);
125 125 $scope.vehiculo.idTransportista = res.data[0].COD;
126 126 $scope.vehiculo.transportista = res.data;
  127 + $scope.vehiculo.capacidad = 0;
127 128 $scope.$broadcast('addCabecera', {
128 129 label: 'Transportista:',
129 130 valor: codigo + ' - ' + res.data[0].ALI
... ... @@ -217,19 +218,22 @@ angular.module('focaAbmVehiculo')
217 218 $scope.crear = true;
218 219 };
219 220  
220   - $scope.seleccionarUnidadMedida = function (cisterna) {
221   - var modalInstance = $uibModal.open(
222   - {
223   - ariaLabelledBy: 'Busqueda de Unidades de medida',
224   - templateUrl: 'modal-unidad-medida.html',
225   - controller: 'focaModalUnidadMedidaCtrl',
226   - size: 'lg'
227   - }
228   - );
229   - modalInstance.result.then(function (unidaMedida) {
230   - cisterna.idUnidadMedida = unidaMedida.ID;
231   - cisterna.unidadMedida = unidaMedida;
232   - });
  221 + $scope.seleccionarUnidadMedida = function (key,cisterna) {
  222 +
  223 + if (key === 13) {
  224 + var modalInstance = $uibModal.open(
  225 + {
  226 + ariaLabelledBy: 'Busqueda de Unidades de medida',
  227 + templateUrl: 'modal-unidad-medida.html',
  228 + controller: 'focaModalUnidadMedidaCtrl',
  229 + size: 'lg'
  230 + }
  231 + );
  232 + modalInstance.result.then(function (unidaMedida) {
  233 + cisterna.idUnidadMedida = unidaMedida.ID;
  234 + cisterna.unidadMedida = unidaMedida;
  235 + });
  236 + }
233 237 };
234 238  
235 239 $scope.guardar = function (key) {
... ... @@ -254,15 +258,6 @@ angular.module('focaAbmVehiculo')
254 258 } else if (!$scope.vehiculo.semi) {
255 259 focaModalService.alert('Ingrese dominio semi');
256 260 return;
257   - } else if (!$scope.vehiculo.capacidad) {
258   - focaModalService.alert('Ingrese capacidad total');
259   - return;
260   - }
261   - //Valida si existe numero de unidad
262   - if (!validaTotalCargas() && !$scope.nuevo) {
263   - focaModalService.alert('La suma de las capacidades de las cisternas' +
264   - ' debe ser igual a la capacidad total del vehículo');
265   - return;
266 261 }
267 262  
268 263 if ($scope.nuevo) {
... ... @@ -280,6 +275,9 @@ angular.module('focaAbmVehiculo')
280 275 focaModalService.alert('Código de unidad existente');
281 276 });
282 277 } else {
  278 + delete $scope.vehiculo.cisternas;
  279 + delete $scope.vehiculo.transportista;
  280 + focaAbmVehiculoService.guardarVehiculo($scope.vehiculo);
283 281 guardarCisternas($scope.cisternas).then(function () {
284 282 angular.element('#guardar').addClass('guardado');
285 283 $timeout(function () {$location.path('/vehiculo');},500);
... ... @@ -325,6 +323,7 @@ angular.module('focaAbmVehiculo')
325 323 .then(function (data) {
326 324 if (data) {
327 325 cisterna.desactivado = true;
  326 + validaTotalCargas();
328 327 }
329 328 });
330 329 return;
... ... @@ -355,9 +354,11 @@ angular.module('focaAbmVehiculo')
355 354 $scope.cisternas.forEach(function (cisterna) {
356 355 if (!cisterna.desactivado) {
357 356 total += parseInt(cisterna.capacidad);
  357 + } else {
  358 + $scope.vehiculo.capacidad -= parseInt(cisterna.capacidad);
358 359 }
359 360 });
360   - return $scope.vehiculo.capacidad >= total;
  361 + return $scope.vehiculo.capacidad = total;
361 362 }
362 363 function guardarCisternas() {
363 364  
... ... @@ -391,7 +392,8 @@ angular.module('focaAbmVehiculo')
391 392 } else if (cisterna.id === undefined) {
392 393 cisterna.id = 0;
393 394 }
394   -
  395 +
  396 + validaTotalCargas();
395 397 validaCodigo(cisterna);
396 398 };
397 399  
src/views/foca-abm-vehiculos-item.html
... ... @@ -67,7 +67,7 @@
67 67 ng-required="true"
68 68 foca-focus="focused == 4"
69 69 ng-focus="focused = 4"
70   - ng-disabled="!nuevo"
  70 + ng-disabled="true"
71 71 />
72 72 </div>
73 73 </div>
... ... @@ -185,6 +185,7 @@
185 185 <input
186 186 ng-model="cisterna.unidadMedida.NOM"
187 187 class="form-control"
  188 + ng-keypress="seleccionarUnidadMedida($event.keyCode, cisterna)"
188 189 readonly
189 190 esc-key="volver(cisterna, key)"
190 191 />
... ... @@ -193,7 +194,7 @@
193 194 ladda="searchLoading"
194 195 class="btn btn-outline-secondary form-control"
195 196 type="button"
196   - ng-click="seleccionarUnidadMedida(cisterna)"
  197 + ng-click="seleccionarUnidadMedida(13, cisterna)"
197 198 foca-focus="focused == 3"
198 199 >
199 200 <i class="fa fa-search" aria-hidden="true"></i>