diff --git a/src/js/controller.js b/src/js/controller.js index 73bcd6b..415c480 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -90,7 +90,7 @@ angular.module('focaAbmVehiculo') $timeout(function() { focaBotoneraLateralService.showSalir(false); focaBotoneraLateralService.showPausar(false); - focaBotoneraLateralService.showCancelar(true); + focaBotoneraLateralService.showCancelar(true, '/vehiculo'); focaBotoneraLateralService.showGuardar(true, $scope.guardar); }); @@ -140,14 +140,29 @@ angular.module('focaAbmVehiculo') focaModalService.alert('Elija Transportista'); return; } - delete $scope.vehiculo.transportista; - focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo).then(function(res) { - if($scope.nuevo) { - $location.path('/vehiculo/' + res.data.id + '/' + res.data.idTransportista); - } else { - $location.path('/vehiculo'); - } - }); + focaAbmVehiculoService.getVehiculosPorTransportista($routeParams.idTransportista) + .then(function(res) { + var existe = res.data.filter(function(vehiculo) { + return vehiculo.codigo === $scope.vehiculo.codigo && + vehiculo.id !== $scope.vehiculo.id; + }); + + if(existe.length > 0) { + return Promise.reject('Existe codigo de unidad'); + }else { + delete $scope.vehiculo.transportista; + return focaAbmVehiculoService.guerdarVehiculo($scope.vehiculo); + } + }).then(function(res) { + if($scope.nuevo) { + $location.path('/vehiculo/' + res.data.id + + '/' + res.data.idTransportista); + }else { + $location.path('/vehiculo'); + } + }, function(rej) { + focaModalService.alert(rej); + }); }; $scope.solicitarConfirmacionCisterna = function(cisterna) { focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + diff --git a/src/js/controllerCisterna.js b/src/js/controllerCisterna.js index dd03b61..4fd438e 100644 --- a/src/js/controllerCisterna.js +++ b/src/js/controllerCisterna.js @@ -56,12 +56,24 @@ angular.module('focaAbmVehiculo') focaModalService.alert('Ingrese producto'); return; } - $scope.cisterna.idVehiculo = $routeParams.idVehiculo; - delete $scope.cisterna.unidadMedida; - delete $scope.cisterna.cisternaCarga.articulo; - focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function() { - $location.path('/vehiculo/' + $routeParams.idVehiculo); - }); + focaAbmVehiculoService.getCisternadoPorVehiculo($routeParams.idVehiculo) + .then(function(res) { + var existe = res.data.filter(function(cisterna) { + return cisterna.codigo === $scope.cisterna.codigo; + }); + if(existe.length > 0) { + return Promise.reject('Existe codigo de cisterna'); + }else { + $scope.cisterna.idVehiculo = $routeParams.idVehiculo; + delete $scope.cisterna.unidadMedida; + delete $scope.cisterna.cisternaCarga.articulo; + return focaAbmVehiculoService.guardarCisterna($scope.cisterna); + } + }).then(function() { + $location.path('/vehiculo/' + $routeParams.idVehiculo); + }, function(rej) { + focaModalService.alert(rej); + }); }; // $scope.seleccionarArticulo = function() {