Commit 1ea97c8632ff827d1a19a88bacf529cfd0f97987
1 parent
d31279610b
Exists in
master
and in
1 other branch
code review
Showing
1 changed file
with
7 additions
and
7 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.nuevo = ($routeParams.idx > -1) ? 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 | 57 | ||
| 58 | if($scope.formCisterna.$pristine) { | 58 | if ($scope.formCisterna.$pristine) { |
| 59 | $scope.cancelar(); | 59 | $scope.cancelar(); |
| 60 | return; | 60 | return; |
| 61 | } | 61 | } |
| 62 | 62 | ||
| 63 | if(!$scope.cisterna.unidadMedida) { | 63 | if (!$scope.cisterna.unidadMedida) { |
| 64 | focaModalService.alert('Ingrese unidad de medida'); | 64 | focaModalService.alert('Ingrese unidad de medida'); |
| 65 | return; | 65 | return; |
| 66 | } | 66 | } |
| 67 | validaCodigo() | 67 | validaCodigo() |
| 68 | .then(function() { | 68 | .then(function() { |
| 69 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 69 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 70 | delete $scope.cisterna.vehiculo; | 70 | delete $scope.cisterna.vehiculo; |
| 71 | 71 | ||
| 72 | focaAbmVehiculoService | 72 | focaAbmVehiculoService |
| 73 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 73 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
| 74 | 74 | ||
| 75 | $timeout(function() { | 75 | $timeout(function() { |
| 76 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 76 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 77 | '/' + $scope.transportista); | 77 | '/' + $scope.transportista); |
| 78 | }, 0); | 78 | }, 0); |
| 79 | }, function(err) { | 79 | }, function(err) { |
| 80 | focaModalService.alert(err); | 80 | focaModalService.alert(err); |
| 81 | }); | 81 | }); |
| 82 | 82 | ||
| 83 | }; | 83 | }; |
| 84 | 84 | ||
| 85 | $scope.seleccionarUnidadMedida = function() { | 85 | $scope.seleccionarUnidadMedida = function() { |
| 86 | var modalInstance = $uibModal.open( | 86 | var modalInstance = $uibModal.open( |
| 87 | { | 87 | { |
| 88 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 88 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 89 | templateUrl: 'modal-unidad-medida.html', | 89 | templateUrl: 'modal-unidad-medida.html', |
| 90 | controller: 'focaModalUnidadMedidaCtrl', | 90 | controller: 'focaModalUnidadMedidaCtrl', |
| 91 | size: 'lg' | 91 | size: 'lg' |
| 92 | } | 92 | } |
| 93 | ); | 93 | ); |
| 94 | modalInstance.result.then(function(unidaMedida) { | 94 | modalInstance.result.then(function(unidaMedida) { |
| 95 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 95 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 96 | $scope.cisterna.unidadMedida = unidaMedida; | 96 | $scope.cisterna.unidadMedida = unidaMedida; |
| 97 | }); | 97 | }); |
| 98 | }; | 98 | }; |
| 99 | 99 | ||
| 100 | function validaCodigo() { | 100 | function validaCodigo() { |
| 101 | return new Promise(function(resolve, reject) { | 101 | return new Promise(function(resolve, reject) { |
| 102 | focaAbmVehiculoService | 102 | focaAbmVehiculoService |
| 103 | .getCisternas($routeParams.idVehiculo) | 103 | .getCisternas($routeParams.idVehiculo) |
| 104 | .then(function(res) { | 104 | .then(function(res) { |
| 105 | var cisternas = res; | 105 | var cisternas = res; |
| 106 | var totalCargado = 0; | 106 | var totalCargado = 0; |
| 107 | cisternas.forEach(function(cisterna, idx) { | 107 | cisternas.forEach(function(cisterna, idx) { |
| 108 | //SI EL CODIGO YA EXISTE | 108 | //SI EL CODIGO YA EXISTE |
| 109 | if(cisterna.codigo === $scope.cisterna.codigo && | 109 | if (cisterna.codigo === $scope.cisterna.codigo && |
| 110 | idx !== $routeParams.idx && | 110 | idx !== $routeParams.idx && |
| 111 | !cisterna.desactivado) { | 111 | !cisterna.desactivado) { |
| 112 | reject('Código de cisterna existente'); | 112 | reject('Código de cisterna existente'); |
| 113 | } | 113 | } |
| 114 | if(idx !== $routeParams.idx && | 114 | if (idx !== $routeParams.idx && |
| 115 | !cisterna.desactivado) { | 115 | !cisterna.desactivado) { |
| 116 | totalCargado += cisterna.capacidad; | 116 | totalCargado += cisterna.capacidad; |
| 117 | } | 117 | } |
| 118 | }); | 118 | }); |
| 119 | resolve(); | 119 | resolve(); |
| 120 | }); | 120 | }); |
| 121 | }); | 121 | }); |
| 122 | } | 122 | } |
| 123 | } | 123 | } |
| 124 | ]); | 124 | ]); |
| 125 | 125 |