Commit 74f5232f02bceba4dc23fa865d7ff545e590fa86
1 parent
10b0f94bf6
Exists in
master
fuera validacion producto en editar cisterna
Showing
1 changed file
with
3 additions
and
5 deletions
Show diff stats
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') |
| 2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', |
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | focaModalService, focaBotoneraLateralService, $timeout) { | 6 | focaModalService, focaBotoneraLateralService, $timeout) { |
| 7 | $scope.editar = false; | 7 | $scope.editar = false; |
| 8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); |
| 9 | $scope.cisterna = { | 9 | $scope.cisterna = { |
| 10 | cisternaCarga: { | 10 | cisternaCarga: { |
| 11 | articulo: {} | 11 | articulo: {} |
| 12 | } | 12 | } |
| 13 | }; | 13 | }; |
| 14 | 14 | ||
| 15 | $scope.focused = 1; | 15 | $scope.focused = 1; |
| 16 | $scope.next = function(key) { | 16 | $scope.next = function(key) { |
| 17 | if (key === 13) $scope.focused++; | 17 | if (key === 13) $scope.focused++; |
| 18 | }; | 18 | }; |
| 19 | 19 | ||
| 20 | //SETEO BOTONERA LATERAL | 20 | //SETEO BOTONERA LATERAL |
| 21 | $timeout(function() { | 21 | $timeout(function() { |
| 22 | focaBotoneraLateralService.showSalir(false); | 22 | focaBotoneraLateralService.showSalir(false); |
| 23 | focaBotoneraLateralService.showPausar(false); | 23 | focaBotoneraLateralService.showPausar(false); |
| 24 | focaBotoneraLateralService.showCancelar(true); | 24 | focaBotoneraLateralService.showCancelar(true); |
| 25 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 25 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 26 | }); | 26 | }); |
| 27 | 27 | ||
| 28 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { | 28 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { |
| 29 | if(res.data) { | 29 | if(res.data) { |
| 30 | $scope.cisterna = res.data; | 30 | $scope.cisterna = res.data; |
| 31 | $scope.editar = true; | 31 | $scope.editar = true; |
| 32 | }else { | 32 | }else { |
| 33 | $scope.editar = false; | 33 | $scope.editar = false; |
| 34 | } | 34 | } |
| 35 | }); | 35 | }); |
| 36 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 36 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 37 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 37 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
| 38 | $scope.$broadcast('addCabecera', { | 38 | $scope.$broadcast('addCabecera', { |
| 39 | label: 'Transportista:', | 39 | label: 'Transportista:', |
| 40 | valor: codigo + ' - ' + res.data.transportista.NOM | 40 | valor: codigo + ' - ' + res.data.transportista.NOM |
| 41 | }); | 41 | }); |
| 42 | $scope.$broadcast('addCabecera', { | 42 | $scope.$broadcast('addCabecera', { |
| 43 | label: 'Unidad:', | 43 | label: 'Unidad:', |
| 44 | valor: res.data.codigo | 44 | valor: res.data.codigo |
| 45 | }); | 45 | }); |
| 46 | }); | 46 | }); |
| 47 | $scope.cancelar = function() { | 47 | $scope.cancelar = function() { |
| 48 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 48 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
| 49 | }; | 49 | }; |
| 50 | $scope.guardar = function() { | 50 | $scope.guardar = function() { |
| 51 | if(!$scope.cisterna.unidadMedida) { | 51 | if(!$scope.cisterna.unidadMedida) { |
| 52 | focaModalService.alert('Ingrese unidad de medida'); | 52 | focaModalService.alert('Ingrese unidad de medida'); |
| 53 | return; | 53 | return; |
| 54 | } | 54 | } |
| 55 | if(!$scope.cisterna.cisternaCarga.articulo) { | ||
| 56 | focaModalService.alert('Ingrese producto'); | ||
| 57 | return; | ||
| 58 | } | ||
| 59 | existeCodigoCisterna().then(function() { | 55 | existeCodigoCisterna().then(function() { |
| 60 | $scope.cisterna.idVehiculo = $routeParams.idVehiculo; | 56 | $scope.cisterna.idVehiculo = $routeParams.idVehiculo; |
| 57 | delete $scope.cisterna.vehiculo; | ||
| 61 | delete $scope.cisterna.unidadMedida; | 58 | delete $scope.cisterna.unidadMedida; |
| 62 | delete $scope.cisterna.cisternaCarga.articulo; | 59 | delete $scope.cisterna.cisternaCarga.articulo; |
| 63 | focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ | 60 | focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ |
| 64 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 61 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
| 65 | }); | 62 | }); |
| 66 | }, function() { | 63 | }, function() { |
| 67 | focaModalService.alert('Código de cisterna existente'); | 64 | focaModalService.alert('Código de cisterna existente'); |
| 68 | }); | 65 | }); |
| 69 | 66 | ||
| 70 | }; | 67 | }; |
| 71 | 68 | ||
| 72 | // $scope.seleccionarArticulo = function() { | 69 | // $scope.seleccionarArticulo = function() { |
| 73 | // var modalInstance = $uibModal.open( | 70 | // var modalInstance = $uibModal.open( |
| 74 | // { | 71 | // { |
| 75 | // ariaLabelledBy: 'Busqueda de Productos', | 72 | // ariaLabelledBy: 'Busqueda de Productos', |
| 76 | // templateUrl: 'modal-busqueda-productos.html', | 73 | // templateUrl: 'modal-busqueda-productos.html', |
| 77 | // controller: 'modalBusquedaProductosCtrl', | 74 | // controller: 'modalBusquedaProductosCtrl', |
| 78 | // resolve: { | 75 | // resolve: { |
| 79 | // parametroProducto: { | 76 | // parametroProducto: { |
| 80 | // idLista: -1, | 77 | // idLista: -1, |
| 81 | // cotizacion: 1, | 78 | // cotizacion: 1, |
| 82 | // simbolo: '$' | 79 | // simbolo: '$' |
| 83 | // } | 80 | // } |
| 84 | // }, | 81 | // }, |
| 85 | // size: 'lg' | 82 | // size: 'lg' |
| 86 | // } | 83 | // } |
| 87 | // ); | 84 | // ); |
| 88 | // modalInstance.result.then( | 85 | // modalInstance.result.then( |
| 89 | // function(producto) { | 86 | // function(producto) { |
| 90 | // $scope.cisterna.cisternaCarga.idProducto = producto.id, | 87 | // $scope.cisterna.cisternaCarga.idProducto = producto.id, |
| 91 | // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; | 88 | // $scope.cisterna.cisternaCarga.articulo.DetArt = producto.descripcion; |
| 92 | // }, function() { | 89 | // }, function() { |
| 93 | // // funcion ejecutada cuando se cancela el modal | 90 | // // funcion ejecutada cuando se cancela el modal |
| 94 | // } | 91 | // } |
| 95 | // ); | 92 | // ); |
| 96 | // }; | 93 | // }; |
| 97 | 94 | ||
| 98 | $scope.seleccionarUnidadMedida = function() { | 95 | $scope.seleccionarUnidadMedida = function() { |
| 99 | var modalInstance = $uibModal.open( | 96 | var modalInstance = $uibModal.open( |
| 100 | { | 97 | { |
| 101 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 98 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 102 | templateUrl: 'modal-unidad-medida.html', | 99 | templateUrl: 'modal-unidad-medida.html', |
| 103 | controller: 'focaModalUnidadMedidaCtrl', | 100 | controller: 'focaModalUnidadMedidaCtrl', |
| 104 | size: 'lg' | 101 | size: 'lg' |
| 105 | } | 102 | } |
| 106 | ); | 103 | ); |
| 107 | modalInstance.result.then(function(unidaMedida) { | 104 | modalInstance.result.then(function(unidaMedida) { |
| 108 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 105 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 109 | $scope.cisterna.unidadMedida = unidaMedida; | 106 | $scope.cisterna.unidadMedida = unidaMedida; |
| 110 | }); | 107 | }); |
| 111 | }; | 108 | }; |
| 112 | 109 | ||
| 113 | function existeCodigoCisterna(){ | 110 | function existeCodigoCisterna(){ |
| 114 | return new Promise(function(resolve, reject) { | 111 | return new Promise(function(resolve, reject) { |
| 115 | focaAbmVehiculoService | 112 | focaAbmVehiculoService |
| 116 | .getCisternadoPorVehiculo($routeParams.idVehiculo) | 113 | .getCisternadoPorVehiculo($routeParams.idVehiculo) |
| 117 | .then(function(res){ | 114 | .then(function(res){ |
| 118 | //Valida si existe numero de unidad | 115 | //Valida si existe numero de unidad |
| 119 | var existe = res.data.filter(function(cisterna) { | 116 | var existe = res.data.filter(function(cisterna) { |
| 120 | return cisterna.codigo === $scope.cisterna.codigo; | 117 | return cisterna.codigo === $scope.cisterna.codigo && |
| 118 | cisterna.id !== $scope.cisterna.id; | ||
| 121 | }); | 119 | }); |
| 122 | 120 | ||
| 123 | if(existe.length){ | 121 | if(existe.length){ |
| 124 | reject(existe); | 122 | reject(existe); |
| 125 | } else { | 123 | } else { |
| 126 | resolve(); | 124 | resolve(); |
| 127 | } | 125 | } |
| 128 | }); | 126 | }); |
| 129 | }); | 127 | }); |
| 130 | } | 128 | } |
| 131 | } | 129 | } |