Commit daf0dde40df38f014210e3c84293cf030524030a
1 parent
a3a12f87ed
Exists in
master
espacios 03
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', | 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 | $scope.capacidadVechiulo = 0; | 19 | $scope.capacidadVechiulo = 0; |
| 20 | 20 | ||
| 21 | //SETEO BOTONERA LATERAL | 21 | //SETEO BOTONERA LATERAL |
| 22 | $timeout(function() { | 22 | $timeout(function() { |
| 23 | focaBotoneraLateralService.showSalir(false); | 23 | focaBotoneraLateralService.showSalir(false); |
| 24 | focaBotoneraLateralService.showPausar(false); | 24 | focaBotoneraLateralService.showPausar(false); |
| 25 | focaBotoneraLateralService.showCancelar(true); | 25 | focaBotoneraLateralService.showCancelar(true); |
| 26 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 26 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 27 | }); | 27 | }); |
| 28 | 28 | ||
| 29 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { | 29 | focaAbmVehiculoService.getCisterna($routeParams.id).then(function(res) { |
| 30 | if(res.data) { | 30 | if(res.data) { |
| 31 | $scope.cisterna = res.data; | 31 | $scope.cisterna = res.data; |
| 32 | $scope.editar = true; | 32 | $scope.editar = true; |
| 33 | }else { | 33 | }else { |
| 34 | $scope.editar = false; | 34 | $scope.editar = false; |
| 35 | } | 35 | } |
| 36 | }); | 36 | }); |
| 37 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 37 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 38 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 38 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
| 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 | }); | 48 | }); |
| 49 | $scope.cancelar = function() { | 49 | $scope.cancelar = function() { |
| 50 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 50 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
| 51 | }; | 51 | }; |
| 52 | $scope.guardar = function() { | 52 | $scope.guardar = function() { |
| 53 | if(!$scope.cisterna.unidadMedida) { | 53 | if(!$scope.cisterna.unidadMedida) { |
| 54 | focaModalService.alert('Ingrese unidad de medida'); | 54 | focaModalService.alert('Ingrese unidad de medida'); |
| 55 | return; | 55 | return; |
| 56 | } | 56 | } |
| 57 | validaCodigoCapacidad().then(function() { | 57 | validaCodigoCapacidad().then(function() { |
| 58 | $scope.cisterna.idVehiculo = $routeParams.idVehiculo; | 58 | $scope.cisterna.idVehiculo = $routeParams.idVehiculo; |
| 59 | delete $scope.cisterna.vehiculo; | 59 | delete $scope.cisterna.vehiculo; |
| 60 | delete $scope.cisterna.unidadMedida; | 60 | delete $scope.cisterna.unidadMedida; |
| 61 | delete $scope.cisterna.cisternaCarga.articulo; | 61 | delete $scope.cisterna.cisternaCarga.articulo; |
| 62 | focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ | 62 | focaAbmVehiculoService.guardarCisterna($scope.cisterna).then(function(){ |
| 63 | $location.path('/vehiculo/' + $routeParams.idVehiculo); | 63 | $location.path('/vehiculo/' + $routeParams.idVehiculo); |
| 64 | }); | 64 | }); |
| 65 | }, function(err) { | 65 | }, function(err) { |
| 66 | focaModalService.alert(err); | 66 | focaModalService.alert(err); |
| 67 | }); | 67 | }); |
| 68 | 68 | ||
| 69 | }; | 69 | }; |
| 70 | 70 | ||
| 71 | $scope.seleccionarUnidadMedida = function() { | 71 | $scope.seleccionarUnidadMedida = function() { |
| 72 | var modalInstance = $uibModal.open( | 72 | var modalInstance = $uibModal.open( |
| 73 | { | 73 | { |
| 74 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 74 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 75 | templateUrl: 'modal-unidad-medida.html', | 75 | templateUrl: 'modal-unidad-medida.html', |
| 76 | controller: 'focaModalUnidadMedidaCtrl', | 76 | controller: 'focaModalUnidadMedidaCtrl', |
| 77 | size: 'lg' | 77 | size: 'lg' |
| 78 | } | 78 | } |
| 79 | ); | 79 | ); |
| 80 | modalInstance.result.then(function(unidaMedida) { | 80 | modalInstance.result.then(function(unidaMedida) { |
| 81 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 81 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 82 | $scope.cisterna.unidadMedida = unidaMedida; | 82 | $scope.cisterna.unidadMedida = unidaMedida; |
| 83 | }); | 83 | }); |
| 84 | }; | 84 | }; |
| 85 | 85 | ||
| 86 | function validaCodigoCapacidad() { | 86 | function validaCodigoCapacidad() { |
| 87 | return new Promise(function(resolve, reject) { | 87 | return new Promise(function(resolve, reject) { |
| 88 | focaAbmVehiculoService | 88 | focaAbmVehiculoService |
| 89 | .getCisternadoPorVehiculo($routeParams.idVehiculo) | 89 | .getCisternadoPorVehiculo($routeParams.idVehiculo) |
| 90 | .then(function(res){ | 90 | .then(function(res){ |
| 91 | 91 | ||
| 92 | var totalCargado = 0; | 92 | var totalCargado = 0; |
| 93 | 93 | ||
| 94 | res.data.forEach(function(cisterna) { | 94 | res.data.forEach(function(cisterna) { |
| 95 | //SI EL CODIGO YA EXISTE | 95 | //SI EL CODIGO YA EXISTE |
| 96 | if(cisterna.codigo === $scope.cisterna.codigo && | 96 | if(cisterna.codigo === $scope.cisterna.codigo && |
| 97 | cisterna.id !== $scope.cisterna.id){ | 97 | cisterna.id !== $scope.cisterna.id) { |
| 98 | reject('Código de cisterna existente'); | 98 | reject('Código de cisterna existente'); |
| 99 | } | 99 | } |
| 100 | if(cisterna.id !== $scope.cisterna.id){ | 100 | if(cisterna.id !== $scope.cisterna.id) { |
| 101 | totalCargado += cisterna.capacidad; | 101 | totalCargado += cisterna.capacidad; |
| 102 | } | 102 | } |
| 103 | }); | 103 | }); |
| 104 | 104 | ||
| 105 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO | 105 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO |
| 106 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); | 106 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); |
| 107 | if(totalCargado > $scope.capacidadVechiulo) { | 107 | if(totalCargado > $scope.capacidadVechiulo) { |
| 108 | reject('La capacidad total de las cisternas' + | 108 | reject('La capacidad total de las cisternas' + |
| 109 | ' debe ser menor o igual a la del vehiculo'); | 109 | ' debe ser menor o igual a la del vehiculo'); |
| 110 | }else { | 110 | }else { |
| 111 | resolve(); | 111 | resolve(); |
| 112 | } | 112 | } |
| 113 | }); | 113 | }); |
| 114 | }); | 114 | }); |
| 115 | } | 115 | } |
| 116 | } | 116 | } |
| 117 | ]); | 117 | ]); |
| 118 | 118 |