Commit 6ee3665d8851821c7396c51a672bb901258d99bf
1 parent
14c1200cc8
Exists in
master
and in
1 other branch
ok disabled codigo cisterna si no es nuevo
Showing
1 changed file
with
2 additions
and
2 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', '$window', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | 
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $window) { | 
| 7 | $scope.nuevo = ($routeParams.id > 0) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 
| 8 | $scope.editar = false; | 8 | $scope.editar = false; | 
| 9 | $scope.now = new Date(); | 9 | $scope.now = new Date(); | 
| 10 | $scope.cisterna = {}; | 10 | $scope.cisterna = {}; | 
| 11 | 11 | ||
| 12 | $scope.focused = $scope.nuevo ? 1 : 2; | 12 | $scope.focused = $scope.nuevo ? 1 : 2; | 
| 13 | $scope.next = function(key) { | 13 | $scope.next = function(key) { | 
| 14 | if (key === 13) $scope.focused++; | 14 | if (key === 13) $scope.focused++; | 
| 15 | }; | 15 | }; | 
| 16 | $scope.capacidadVechiulo = 0; | 16 | $scope.capacidadVechiulo = 0; | 
| 17 | $scope.transportista = ''; | 17 | $scope.transportista = ''; | 
| 18 | 18 | ||
| 19 | //SETEO BOTONERA LATERAL | 19 | //SETEO BOTONERA LATERAL | 
| 20 | $timeout(function() { | 20 | $timeout(function() { | 
| 21 | focaBotoneraLateralService.showSalir(false); | 21 | focaBotoneraLateralService.showSalir(false); | 
| 22 | focaBotoneraLateralService.showPausar(false); | 22 | focaBotoneraLateralService.showPausar(false); | 
| 23 | focaBotoneraLateralService.showCancelar(true); | 23 | focaBotoneraLateralService.showCancelar(true); | 
| 24 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 24 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 
| 25 | }); | 25 | }); | 
| 26 | 26 | ||
| 27 | if($routeParams.idx !== -1) { | 27 | if($routeParams.idx !== -1) { | 
| 28 | $scope.cisterna = [$routeParams.idx] | 28 | $scope.cisterna = [$routeParams.idx]; | 
| 29 | focaAbmVehiculoService | 29 | focaAbmVehiculoService | 
| 30 | .getCisternas($routeParams.idVehiculo) | 30 | .getCisternas($routeParams.idVehiculo) | 
| 31 | .then(function(res) { | 31 | .then(function(res) { | 
| 32 | $scope.cisterna = res[$routeParams.idx]; | 32 | $scope.cisterna = res[$routeParams.idx]; | 
| 33 | }); | 33 | }); | 
| 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.transportista = res.data.transportista.COD; | 38 | $scope.transportista = res.data.transportista.COD; | 
| 39 | $scope.capacidadVechiulo = res.data.capacidad; | 39 | $scope.capacidadVechiulo = res.data.capacidad; | 
| 40 | $scope.$broadcast('addCabecera', { | 40 | $scope.$broadcast('addCabecera', { | 
| 41 | label: 'Transportista:', | 41 | label: 'Transportista:', | 
| 42 | valor: codigo + ' - ' + res.data.transportista.NOM | 42 | valor: codigo + ' - ' + res.data.transportista.NOM | 
| 43 | }); | 43 | }); | 
| 44 | $scope.$broadcast('addCabecera', { | 44 | $scope.$broadcast('addCabecera', { | 
| 45 | label: 'Unidad:', | 45 | label: 'Unidad:', | 
| 46 | valor: res.data.codigo | 46 | valor: res.data.codigo | 
| 47 | }); | 47 | }); | 
| 48 | $scope.$broadcast('addCabecera', { | 48 | $scope.$broadcast('addCabecera', { | 
| 49 | label: 'Capacidad total vehículo:', | 49 | label: 'Capacidad total vehículo:', | 
| 50 | valor: res.data.capacidad | 50 | valor: res.data.capacidad | 
| 51 | }); | 51 | }); | 
| 52 | }); | 52 | }); | 
| 53 | $scope.cancelar = function() { | 53 | $scope.cancelar = function() { | 
| 54 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 54 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 
| 55 | }; | 55 | }; | 
| 56 | $scope.guardar = function() { | 56 | $scope.guardar = function() { | 
| 57 | if(!$scope.cisterna.unidadMedida) { | 57 | if(!$scope.cisterna.unidadMedida) { | 
| 58 | focaModalService.alert('Ingrese unidad de medida'); | 58 | focaModalService.alert('Ingrese unidad de medida'); | 
| 59 | return; | 59 | return; | 
| 60 | } | 60 | } | 
| 61 | validaCodigo() | 61 | validaCodigo() | 
| 62 | .then(function() { | 62 | .then(function() { | 
| 63 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 63 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 
| 64 | delete $scope.cisterna.vehiculo; | 64 | delete $scope.cisterna.vehiculo; | 
| 65 | 65 | ||
| 66 | focaAbmVehiculoService | 66 | focaAbmVehiculoService | 
| 67 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 67 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 
| 68 | 68 | ||
| 69 | $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + | 69 | $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + | 
| 70 | '/' + $scope.transportista); | 70 | '/' + $scope.transportista); | 
| 71 | }, function(err) { | 71 | }, function(err) { | 
| 72 | focaModalService.alert(err); | 72 | focaModalService.alert(err); | 
| 73 | }); | 73 | }); | 
| 74 | 74 | ||
| 75 | }; | 75 | }; | 
| 76 | 76 | ||
| 77 | $scope.seleccionarUnidadMedida = function() { | 77 | $scope.seleccionarUnidadMedida = function() { | 
| 78 | var modalInstance = $uibModal.open( | 78 | var modalInstance = $uibModal.open( | 
| 79 | { | 79 | { | 
| 80 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 80 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 
| 81 | templateUrl: 'modal-unidad-medida.html', | 81 | templateUrl: 'modal-unidad-medida.html', | 
| 82 | controller: 'focaModalUnidadMedidaCtrl', | 82 | controller: 'focaModalUnidadMedidaCtrl', | 
| 83 | size: 'lg' | 83 | size: 'lg' | 
| 84 | } | 84 | } | 
| 85 | ); | 85 | ); | 
| 86 | modalInstance.result.then(function(unidaMedida) { | 86 | modalInstance.result.then(function(unidaMedida) { | 
| 87 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 87 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 
| 88 | $scope.cisterna.unidadMedida = unidaMedida; | 88 | $scope.cisterna.unidadMedida = unidaMedida; | 
| 89 | }); | 89 | }); | 
| 90 | }; | 90 | }; | 
| 91 | 91 | ||
| 92 | function validaCodigo() { | 92 | function validaCodigo() { | 
| 93 | return new Promise(function(resolve, reject) { | 93 | return new Promise(function(resolve, reject) { | 
| 94 | focaAbmVehiculoService | 94 | focaAbmVehiculoService | 
| 95 | .getCisternas($routeParams.idVehiculo) | 95 | .getCisternas($routeParams.idVehiculo) | 
| 96 | .then(function(res) { | 96 | .then(function(res) { | 
| 97 | var cisternas = res; | 97 | var cisternas = res; | 
| 98 | var totalCargado = 0; | 98 | var totalCargado = 0; | 
| 99 | cisternas.forEach(function(cisterna, idx) { | 99 | cisternas.forEach(function(cisterna, idx) { | 
| 100 | //SI EL CODIGO YA EXISTE | 100 | //SI EL CODIGO YA EXISTE | 
| 101 | if(cisterna.codigo === $scope.cisterna.codigo && | 101 | if(cisterna.codigo === $scope.cisterna.codigo && | 
| 102 | idx != $routeParams.idx && | 102 | idx != $routeParams.idx && | 
| 103 | !cisterna.desactivado) { | 103 | !cisterna.desactivado) { | 
| 104 | reject('Código de cisterna existente'); | 104 | reject('Código de cisterna existente'); | 
| 105 | } | 105 | } | 
| 106 | if(idx != $routeParams.idx && | 106 | if(idx != $routeParams.idx && | 
| 107 | !cisterna.desactivado) { | 107 | !cisterna.desactivado) { | 
| 108 | totalCargado += cisterna.capacidad; | 108 | totalCargado += cisterna.capacidad; | 
| 109 | } | 109 | } | 
| 110 | }); | 110 | }); | 
| 111 | resolve(); | 111 | resolve(); | 
| 112 | }); | 112 | }); | 
| 113 | }); | 113 | }); | 
| 114 | } | 114 | } | 
| 115 | } | 115 | } | 
| 116 | ]); | 116 | ]); | 
| 117 | 117 |