Commit 33fae858fc215061829a2bc885659862f9588d6c
1 parent
0f4ce9054f
Exists in
master
ok parseFloat(capacidad), fuera console.log
Showing
2 changed files
with
1 additions
and
2 deletions
 
Show diff stats
src/js/controller.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') | 
| 2 | .controller('focaAbmVehiculosController', [ | 2 | .controller('focaAbmVehiculosController', [ | 
| 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 
| 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', | 
| 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 
| 6 | $uibModal, focaBotoneraLateralService, $timeout) { | 6 | $uibModal, focaBotoneraLateralService, $timeout) { | 
| 7 | 7 | ||
| 8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); | 
| 9 | $scope.botonera = [{ | 9 | $scope.botonera = [{ | 
| 10 | label: 'Transportista', | 10 | label: 'Transportista', | 
| 11 | image: 'cliente.png' | 11 | image: 'cliente.png' | 
| 12 | }]; | 12 | }]; | 
| 13 | 13 | ||
| 14 | //SETEO BOTONERA LATERAL | 14 | //SETEO BOTONERA LATERAL | 
| 15 | focaBotoneraLateralService.showSalir(false); | 15 | focaBotoneraLateralService.showSalir(false); | 
| 16 | focaBotoneraLateralService.showPausar(false); | 16 | focaBotoneraLateralService.showPausar(false); | 
| 17 | focaBotoneraLateralService.showCancelar(false); | 17 | focaBotoneraLateralService.showCancelar(false); | 
| 18 | focaBotoneraLateralService.showGuardar(false); | 18 | focaBotoneraLateralService.showGuardar(false); | 
| 19 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 19 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 
| 20 | 20 | ||
| 21 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { | 21 | if(focaAbmVehiculoService.transportistaSeleccionado.COD) { | 
| 22 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 22 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 
| 23 | } | 23 | } | 
| 24 | $scope.editar = function(id) { | 24 | $scope.editar = function(id) { | 
| 25 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 25 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 
| 26 | }; | 26 | }; | 
| 27 | $scope.solicitarConfirmacion = function(vehiculo) { | 27 | $scope.solicitarConfirmacion = function(vehiculo) { | 
| 28 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 28 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 
| 29 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 29 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 
| 30 | function(data) { | 30 | function(data) { | 
| 31 | if(data) { | 31 | if(data) { | 
| 32 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 32 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 
| 33 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 33 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 
| 34 | } | 34 | } | 
| 35 | } | 35 | } | 
| 36 | ); | 36 | ); | 
| 37 | }; | 37 | }; | 
| 38 | $scope.seleccionarTransportista = function() { | 38 | $scope.seleccionarTransportista = function() { | 
| 39 | var modalInstance = $uibModal.open( | 39 | var modalInstance = $uibModal.open( | 
| 40 | { | 40 | { | 
| 41 | ariaLabelledBy: 'Busqueda de Transportista', | 41 | ariaLabelledBy: 'Busqueda de Transportista', | 
| 42 | templateUrl: 'modal-proveedor.html', | 42 | templateUrl: 'modal-proveedor.html', | 
| 43 | controller: 'focaModalProveedorCtrl', | 43 | controller: 'focaModalProveedorCtrl', | 
| 44 | size: 'lg', | 44 | size: 'lg', | 
| 45 | resolve: { | 45 | resolve: { | 
| 46 | transportista: function() { | 46 | transportista: function() { | 
| 47 | return true; | 47 | return true; | 
| 48 | } | 48 | } | 
| 49 | } | 49 | } | 
| 50 | } | 50 | } | 
| 51 | ); | 51 | ); | 
| 52 | modalInstance.result.then( | 52 | modalInstance.result.then( | 
| 53 | function(transportista) { | 53 | function(transportista) { | 
| 54 | elegirTransportista(transportista); | 54 | elegirTransportista(transportista); | 
| 55 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 55 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 
| 56 | }, function() { | 56 | }, function() { | 
| 57 | 57 | ||
| 58 | } | 58 | } | 
| 59 | ); | 59 | ); | 
| 60 | }; | 60 | }; | 
| 61 | 61 | ||
| 62 | function elegirTransportista(transportista) { | 62 | function elegirTransportista(transportista) { | 
| 63 | var codigo = ('00000' + transportista.COD).slice(-5); | 63 | var codigo = ('00000' + transportista.COD).slice(-5); | 
| 64 | $scope.idTransportista = transportista.COD; | 64 | $scope.idTransportista = transportista.COD; | 
| 65 | $scope.filtros = transportista.NOM.trim(); | 65 | $scope.filtros = transportista.NOM.trim(); | 
| 66 | $timeout(function() { | 66 | $timeout(function() { | 
| 67 | $scope.$broadcast('addCabecera', { | 67 | $scope.$broadcast('addCabecera', { | 
| 68 | label: 'Transportista:', | 68 | label: 'Transportista:', | 
| 69 | valor: codigo + ' - ' + transportista.NOM | 69 | valor: codigo + ' - ' + transportista.NOM | 
| 70 | }); | 70 | }); | 
| 71 | }); | 71 | }); | 
| 72 | buscar(transportista.COD); | 72 | buscar(transportista.COD); | 
| 73 | } | 73 | } | 
| 74 | 74 | ||
| 75 | function buscar(idTransportista) { | 75 | function buscar(idTransportista) { | 
| 76 | focaAbmVehiculoService | 76 | focaAbmVehiculoService | 
| 77 | .getVehiculosPorTransportista(idTransportista) | 77 | .getVehiculosPorTransportista(idTransportista) | 
| 78 | .then(function(datos) { | 78 | .then(function(datos) { | 
| 79 | $scope.vehiculos = datos.data; | 79 | $scope.vehiculos = datos.data; | 
| 80 | }); | 80 | }); | 
| 81 | } | 81 | } | 
| 82 | function salir() { | 82 | function salir() { | 
| 83 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 83 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 
| 84 | $location.path('/'); | 84 | $location.path('/'); | 
| 85 | } | 85 | } | 
| 86 | } | 86 | } | 
| 87 | ]) | 87 | ]) | 
| 88 | .controller('focaAbmVehiculoController', [ | 88 | .controller('focaAbmVehiculoController', [ | 
| 89 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 89 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 
| 90 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 90 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', | 
| 91 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 91 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 
| 92 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 92 | focaModalService, $timeout, focaBotoneraLateralService, $window) { | 
| 93 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 93 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 
| 94 | $scope.now = new Date(); | 94 | $scope.now = new Date(); | 
| 95 | $scope.focused = 1; | 95 | $scope.focused = 1; | 
| 96 | $scope.transportistaStamp = ''; | 96 | $scope.transportistaStamp = ''; | 
| 97 | $scope.cisternas = []; | 97 | $scope.cisternas = []; | 
| 98 | 98 | ||
| 99 | $timeout(function() { | 99 | $timeout(function() { | 
| 100 | focaBotoneraLateralService.showSalir(false); | 100 | focaBotoneraLateralService.showSalir(false); | 
| 101 | focaBotoneraLateralService.showPausar(false); | 101 | focaBotoneraLateralService.showPausar(false); | 
| 102 | focaBotoneraLateralService.showCancelar(false); | 102 | focaBotoneraLateralService.showCancelar(false); | 
| 103 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 103 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 
| 104 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 104 | focaBotoneraLateralService.addCustomButton('Salir', $scope.cancelar); | 
| 105 | }); | 105 | }); | 
| 106 | 106 | ||
| 107 | if($scope.nuevo) { | 107 | if($scope.nuevo) { | 
| 108 | focaAbmVehiculoService | 108 | focaAbmVehiculoService | 
| 109 | .getTransportistaPorId($routeParams.idTransportista) | 109 | .getTransportistaPorId($routeParams.idTransportista) | 
| 110 | .then(function(res) { | 110 | .then(function(res) { | 
| 111 | var codigo = ('00000' + res.data.COD).slice(-5); | 111 | var codigo = ('00000' + res.data.COD).slice(-5); | 
| 112 | $scope.vehiculo.idTransportista = res.data.COD; | 112 | $scope.vehiculo.idTransportista = res.data.COD; | 
| 113 | $scope.vehiculo.transportista = res.data; | 113 | $scope.vehiculo.transportista = res.data; | 
| 114 | $scope.$broadcast('addCabecera', { | 114 | $scope.$broadcast('addCabecera', { | 
| 115 | label: 'Transportista:', | 115 | label: 'Transportista:', | 
| 116 | valor: codigo + ' - ' + res.data.NOM | 116 | valor: codigo + ' - ' + res.data.NOM | 
| 117 | }); | 117 | }); | 
| 118 | }); | 118 | }); | 
| 119 | } | 119 | } | 
| 120 | $scope.vehiculo = {}; | 120 | $scope.vehiculo = {}; | 
| 121 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 121 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 
| 122 | if(res.data) { | 122 | if(res.data) { | 
| 123 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 123 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 
| 124 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 124 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 
| 125 | 125 | ||
| 126 | $scope.vehiculo = res.data; | 126 | $scope.vehiculo = res.data; | 
| 127 | $scope.$broadcast('addCabecera', { | 127 | $scope.$broadcast('addCabecera', { | 
| 128 | label: 'Transportista:', | 128 | label: 'Transportista:', | 
| 129 | valor: $scope.transportistaStamp | 129 | valor: $scope.transportistaStamp | 
| 130 | }); | 130 | }); | 
| 131 | $scope.$broadcast('addCabecera', { | 131 | $scope.$broadcast('addCabecera', { | 
| 132 | label: 'Unidad:', | 132 | label: 'Unidad:', | 
| 133 | valor: res.data.codigo | 133 | valor: res.data.codigo | 
| 134 | }); | 134 | }); | 
| 135 | focaAbmVehiculoService | 135 | focaAbmVehiculoService | 
| 136 | .getCisternas($routeParams.idVehiculo) | 136 | .getCisternas($routeParams.idVehiculo) | 
| 137 | .then(function(res) { | 137 | .then(function(res) { | 
| 138 | $scope.cisternas = res; | 138 | $scope.cisternas = res; | 
| 139 | $scope.$apply(); | 139 | $scope.$apply(); | 
| 140 | }); | 140 | }); | 
| 141 | } | 141 | } | 
| 142 | }); | 142 | }); | 
| 143 | 143 | ||
| 144 | $scope.next = function(key) { | 144 | $scope.next = function(key) { | 
| 145 | if (key === 13) $scope.focused++; | 145 | if (key === 13) $scope.focused++; | 
| 146 | }; | 146 | }; | 
| 147 | $scope.cancelar = function() { | 147 | $scope.cancelar = function() { | 
| 148 | $location.path('/vehiculo'); | 148 | $location.path('/vehiculo'); | 
| 149 | }; | 149 | }; | 
| 150 | $scope.editar = function(key) { | 150 | $scope.editar = function(key) { | 
| 151 | if(key) { | 151 | if(key) { | 
| 152 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 152 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 
| 153 | '/cisterna/' + key); | 153 | '/cisterna/' + key); | 
| 154 | }else { | 154 | }else { | 
| 155 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 155 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 
| 156 | } | 156 | } | 
| 157 | }; | 157 | }; | 
| 158 | $scope.guardar = function(key) { | 158 | $scope.guardar = function(key) { | 
| 159 | key = (typeof key === 'undefined') ? 13 : key; | 159 | key = (typeof key === 'undefined') ? 13 : key; | 
| 160 | if(key === 13) { | 160 | if(key === 13) { | 
| 161 | //Valida si existe numero de unidad | 161 | //Valida si existe numero de unidad | 
| 162 | if(!validaTotalCargas() && !$scope.nuevo) { | 162 | if(!validaTotalCargas() && !$scope.nuevo) { | 
| 163 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 163 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 
| 164 | ' debe ser igual a la capacidad total del vehículo'); | 164 | ' debe ser igual a la capacidad total del vehículo'); | 
| 165 | return; | 165 | return; | 
| 166 | } | 166 | } | 
| 167 | validaCodigoUnidad().then(function() { | 167 | validaCodigoUnidad().then(function() { | 
| 168 | delete $scope.vehiculo.transportista; | 168 | delete $scope.vehiculo.transportista; | 
| 169 | delete $scope.vehiculo.cisternas; | 169 | delete $scope.vehiculo.cisternas; | 
| 170 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 170 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 
| 171 | .then(function(res) { | 171 | .then(function(res) { | 
| 172 | if($scope.nuevo) { | 172 | if($scope.nuevo) { | 
| 173 | $location.path('/vehiculo/' + res.data.id + | 173 | $location.path('/vehiculo/' + res.data.id + | 
| 174 | '/' + res.data.idTransportista); | 174 | '/' + res.data.idTransportista); | 
| 175 | }else { | 175 | }else { | 
| 176 | guardarCisternas().then(function() { | 176 | guardarCisternas().then(function() { | 
| 177 | $window.location.assign('/#!/vehiculo'); | 177 | $window.location.assign('/#!/vehiculo'); | 
| 178 | }); | 178 | }); | 
| 179 | } | 179 | } | 
| 180 | }); | 180 | }); | 
| 181 | }, function() { | 181 | }, function() { | 
| 182 | focaModalService.alert('Código de unidad existente'); | 182 | focaModalService.alert('Código de unidad existente'); | 
| 183 | }); | 183 | }); | 
| 184 | } | 184 | } | 
| 185 | 185 | ||
| 186 | }; | 186 | }; | 
| 187 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 187 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 
| 188 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 188 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 
| 189 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 189 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 
| 190 | function(data) { | 190 | function(data) { | 
| 191 | if(data) { | 191 | if(data) { | 
| 192 | focaAbmVehiculoService.deleteCisterna(idx); | 192 | focaAbmVehiculoService.deleteCisterna(idx); | 
| 193 | focaAbmVehiculoService | 193 | focaAbmVehiculoService | 
| 194 | .getCisternas($routeParams.idVehiculo) | 194 | .getCisternas($routeParams.idVehiculo) | 
| 195 | .then(function(res) { | 195 | .then(function(res) { | 
| 196 | $scope.cisternas = res; | 196 | $scope.cisternas = res; | 
| 197 | }); | 197 | }); | 
| 198 | } | 198 | } | 
| 199 | } | 199 | } | 
| 200 | ); | 200 | ); | 
| 201 | }; | 201 | }; | 
| 202 | 202 | ||
| 203 | function validaCodigoUnidad() { | 203 | function validaCodigoUnidad() { | 
| 204 | return new Promise(function(resolve, reject) { | 204 | return new Promise(function(resolve, reject) { | 
| 205 | focaAbmVehiculoService | 205 | focaAbmVehiculoService | 
| 206 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 206 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 
| 207 | .then(function(res) { | 207 | .then(function(res) { | 
| 208 | //Valida si existe numero de unidad | 208 | //Valida si existe numero de unidad | 
| 209 | var existe = res.data.filter(function(vehiculo) { | 209 | var existe = res.data.filter(function(vehiculo) { | 
| 210 | return vehiculo.codigo === $scope.vehiculo.codigo && | 210 | return vehiculo.codigo === $scope.vehiculo.codigo && | 
| 211 | vehiculo.id !== $scope.vehiculo.id; | 211 | vehiculo.id !== $scope.vehiculo.id; | 
| 212 | }); | 212 | }); | 
| 213 | 213 | ||
| 214 | if(existe.length) { | 214 | if(existe.length) { | 
| 215 | reject(existe); | 215 | reject(existe); | 
| 216 | }else { | 216 | }else { | 
| 217 | resolve(); | 217 | resolve(); | 
| 218 | } | 218 | } | 
| 219 | }); | 219 | }); | 
| 220 | }); | 220 | }); | 
| 221 | } | 221 | } | 
| 222 | 222 | ||
| 223 | function validaTotalCargas() { | 223 | function validaTotalCargas() { | 
| 224 | var total = 0; | 224 | var total = 0; | 
| 225 | $scope.cisternas.forEach(function(cisterna) { | 225 | $scope.cisternas.forEach(function(cisterna) { | 
| 226 | if(!cisterna.desactivado) { | 226 | if(!cisterna.desactivado) { | 
| 227 | total += parseInt(cisterna.capacidad); | 227 | total += parseInt(cisterna.capacidad); | 
| 228 | } | 228 | } | 
| 229 | }); | 229 | }); | 
| 230 | return $scope.vehiculo.capacidad == total; | 230 | return $scope.vehiculo.capacidad == total; | 
| 231 | } | 231 | } | 
| 232 | 232 | ||
| 233 | function guardarCisternas() { | 233 | function guardarCisternas() { | 
| 234 | var cisternas = $scope.cisternas.map(function(cisterna) { | 234 | var cisternas = $scope.cisternas.map(function(cisterna) { | 
| 235 | return { | 235 | return { | 
| 236 | id: cisterna.id, | 236 | id: cisterna.id, | 
| 237 | capacidad: parseInt(cisterna.capacidad), | 237 | capacidad: parseFloat(cisterna.capacidad), | 
| 238 | codigo: cisterna.codigo, | 238 | codigo: cisterna.codigo, | 
| 239 | idUnidadMedida: cisterna.idUnidadMedida, | 239 | idUnidadMedida: cisterna.idUnidadMedida, | 
| 240 | idVehiculo: $routeParams.idVehiculo, | 240 | idVehiculo: $routeParams.idVehiculo, | 
| 241 | desactivado: cisterna.desactivado | 241 | desactivado: cisterna.desactivado | 
| 242 | }; | 242 | }; | 
| 243 | }); | 243 | }); | 
| 244 | 244 | ||
| 245 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 245 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 
| 246 | } | 246 | } | 
| 247 | } | 247 | } | 
| 248 | ]); | 248 | ]); | 
| 249 | 249 | 
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.id > 0) ? 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 | validaCodigoCapacidad() | 61 | validaCodigoCapacidad() | 
| 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 validaCodigoCapacidad() { | 92 | function validaCodigoCapacidad() { | 
| 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 | console.log(cisternas); | ||
| 100 | cisternas.forEach(function(cisterna, idx) { | 99 | cisternas.forEach(function(cisterna, idx) { | 
| 101 | //SI EL CODIGO YA EXISTE | 100 | //SI EL CODIGO YA EXISTE | 
| 102 | if(cisterna.codigo === $scope.cisterna.codigo && | 101 | if(cisterna.codigo === $scope.cisterna.codigo && | 
| 103 | idx != $routeParams.idx && | 102 | idx != $routeParams.idx && | 
| 104 | !cisterna.desactivado) { | 103 | !cisterna.desactivado) { | 
| 105 | reject('Código de cisterna existente'); | 104 | reject('Código de cisterna existente'); | 
| 106 | } | 105 | } | 
| 107 | if(idx != $routeParams.idx && | 106 | if(idx != $routeParams.idx && | 
| 108 | !cisterna.desactivado) { | 107 | !cisterna.desactivado) { | 
| 109 | totalCargado += cisterna.capacidad; | 108 | totalCargado += cisterna.capacidad; | 
| 110 | } | 109 | } | 
| 111 | }); | 110 | }); | 
| 112 | 111 | ||
| 113 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO | 112 | //SI EL TOTAL DE CAPACIDAD DE CISTERNAS ES MAYOR QUE LA DEL VEHICULO | 
| 114 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); | 113 | totalCargado = totalCargado + parseInt($scope.cisterna.capacidad); | 
| 115 | if(totalCargado > $scope.capacidadVechiulo) { | 114 | if(totalCargado > $scope.capacidadVechiulo) { | 
| 116 | reject('La capacidad total de las cisternas' + | 115 | reject('La capacidad total de las cisternas' + | 
| 117 | ' no debe ser mayor a la del vehiculo'); | 116 | ' no debe ser mayor a la del vehiculo'); | 
| 118 | }else { | 117 | }else { | 
| 119 | resolve(); | 118 | resolve(); | 
| 120 | } | 119 | } | 
| 121 | }); | 120 | }); | 
| 122 | }); | 121 | }); | 
| 123 | } | 122 | } | 
| 124 | } | 123 | } | 
| 125 | ]); | 124 | ]); | 
| 126 | 125 |