Commit a08de32e4bdf887b82e237bfd4590930637583fc
Exists in
master
Merge branch 'master' into 'develop'
Master See merge request !44
Showing
1 changed file
Show diff stats
src/js/controller.js
| ... | ... | @@ -2,7 +2,7 @@ angular.module('focaAbmVehiculo') |
| 2 | 2 | .controller('focaAbmVehiculosController', [ |
| 3 | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', |
| 4 | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
| 5 | - function($scope, focaAbmVehiculoService, $location, focaModalService, | |
| 5 | + function ($scope, focaAbmVehiculoService, $location, focaModalService, | |
| 6 | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
| 7 | 7 | |
| 8 | 8 | $scope.now = new Date(); |
| ... | ... | @@ -23,13 +23,13 @@ angular.module('focaAbmVehiculo') |
| 23 | 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
| 24 | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 25 | 25 | } |
| 26 | - $scope.editar = function(id) { | |
| 26 | + $scope.editar = function (id) { | |
| 27 | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
| 28 | 28 | }; |
| 29 | - $scope.solicitarConfirmacion = function(vehiculo) { | |
| 29 | + $scope.solicitarConfirmacion = function (vehiculo) { | |
| 30 | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
| 31 | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
| 32 | - function(data) { | |
| 32 | + function (data) { | |
| 33 | 33 | if (data) { |
| 34 | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
| 35 | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| ... | ... | @@ -37,7 +37,7 @@ angular.module('focaAbmVehiculo') |
| 37 | 37 | } |
| 38 | 38 | ); |
| 39 | 39 | }; |
| 40 | - $scope.seleccionarTransportista = function() { | |
| 40 | + $scope.seleccionarTransportista = function () { | |
| 41 | 41 | var parametrosModal = { |
| 42 | 42 | titulo: 'Búsqueda de Transportista', |
| 43 | 43 | query: '/transportista', |
| ... | ... | @@ -57,10 +57,10 @@ angular.module('focaAbmVehiculo') |
| 57 | 57 | ] |
| 58 | 58 | }; |
| 59 | 59 | focaModalService.modal(parametrosModal).then( |
| 60 | - function(transportista) { | |
| 60 | + function (transportista) { | |
| 61 | 61 | elegirTransportista(transportista); |
| 62 | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
| 63 | - }, function() { | |
| 63 | + }, function () { | |
| 64 | 64 | |
| 65 | 65 | } |
| 66 | 66 | ); |
| ... | ... | @@ -69,7 +69,7 @@ angular.module('focaAbmVehiculo') |
| 69 | 69 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 70 | 70 | $scope.idTransportista = transportista.COD; |
| 71 | 71 | $scope.filtros = transportista.NOM.trim(); |
| 72 | - $timeout(function() { | |
| 72 | + $timeout(function () { | |
| 73 | 73 | $scope.$broadcast('addCabecera', { |
| 74 | 74 | label: 'Transportista:', |
| 75 | 75 | valor: codigo + ' - ' + transportista.NOM |
| ... | ... | @@ -81,7 +81,7 @@ angular.module('focaAbmVehiculo') |
| 81 | 81 | function buscar(idTransportista) { |
| 82 | 82 | focaAbmVehiculoService |
| 83 | 83 | .getVehiculosPorTransportista(idTransportista) |
| 84 | - .then(function(datos) { | |
| 84 | + .then(function (datos) { | |
| 85 | 85 | $scope.vehiculos = datos.data; |
| 86 | 86 | }); |
| 87 | 87 | } |
| ... | ... | @@ -94,8 +94,8 @@ angular.module('focaAbmVehiculo') |
| 94 | 94 | .controller('focaAbmVehiculoController', [ |
| 95 | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 96 | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
| 97 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 98 | - focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
| 97 | + function ($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 98 | + focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
| 99 | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | 100 | $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; |
| 101 | 101 | $scope.now = new Date(); |
| ... | ... | @@ -105,7 +105,7 @@ angular.module('focaAbmVehiculo') |
| 105 | 105 | $scope.transportistaStamp = ''; |
| 106 | 106 | $scope.cisternas = []; |
| 107 | 107 | |
| 108 | - $timeout(function() { | |
| 108 | + $timeout(function () { | |
| 109 | 109 | focaBotoneraLateralService.showSalir(false); |
| 110 | 110 | focaBotoneraLateralService.showPausar(true); |
| 111 | 111 | focaBotoneraLateralService.showCancelar(false); |
| ... | ... | @@ -116,7 +116,7 @@ angular.module('focaAbmVehiculo') |
| 116 | 116 | if ($scope.nuevo) { |
| 117 | 117 | focaAbmVehiculoService |
| 118 | 118 | .getTransportistaPorId($routeParams.idTransportista) |
| 119 | - .then(function(res) { | |
| 119 | + .then(function (res) { | |
| 120 | 120 | var codigo = ('00000' + res.data.COD).slice(-5); |
| 121 | 121 | $scope.vehiculo.idTransportista = res.data.COD; |
| 122 | 122 | $scope.vehiculo.transportista = res.data; |
| ... | ... | @@ -128,8 +128,8 @@ angular.module('focaAbmVehiculo') |
| 128 | 128 | } |
| 129 | 129 | $scope.vehiculo = {}; |
| 130 | 130 | |
| 131 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 132 | - | |
| 131 | + focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function (res) { | |
| 132 | + | |
| 133 | 133 | if (res.data) { |
| 134 | 134 | var vehiculoSeteado = getLSVehiculo(); |
| 135 | 135 | if (vehiculoSeteado === false) { |
| ... | ... | @@ -146,25 +146,25 @@ angular.module('focaAbmVehiculo') |
| 146 | 146 | valor: res.data.codigo |
| 147 | 147 | }); |
| 148 | 148 | } |
| 149 | - | |
| 149 | + | |
| 150 | 150 | focaAbmVehiculoService |
| 151 | 151 | .getCisternas($routeParams.idVehiculo) |
| 152 | - .then(function(res) { | |
| 152 | + .then(function (res) { | |
| 153 | 153 | $scope.cisternas = res; |
| 154 | 154 | $scope.$apply(); |
| 155 | - }); | |
| 155 | + }); | |
| 156 | 156 | } |
| 157 | 157 | }); |
| 158 | 158 | |
| 159 | - $scope.next = function(key) { | |
| 159 | + $scope.next = function (key) { | |
| 160 | 160 | if (key === 13) $scope.focused++; |
| 161 | 161 | }; |
| 162 | 162 | |
| 163 | - $scope.salir = function() { | |
| 163 | + $scope.salir = function () { | |
| 164 | 164 | if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { |
| 165 | 165 | focaModalService.confirm( |
| 166 | 166 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 167 | - ).then(function(data) { | |
| 167 | + ).then(function (data) { | |
| 168 | 168 | if (data) { |
| 169 | 169 | $location.path('/vehiculo'); |
| 170 | 170 | } |
| ... | ... | @@ -174,8 +174,8 @@ angular.module('focaAbmVehiculo') |
| 174 | 174 | } |
| 175 | 175 | }; |
| 176 | 176 | |
| 177 | - $scope.editar = function(cisterna) { | |
| 178 | - $scope.cisternas.forEach(function(cisterna) { | |
| 177 | + $scope.editar = function (cisterna) { | |
| 178 | + $scope.cisternas.forEach(function (cisterna) { | |
| 179 | 179 | cisterna.editando = false; |
| 180 | 180 | $scope.crear = true; |
| 181 | 181 | }); |
| ... | ... | @@ -183,7 +183,7 @@ angular.module('focaAbmVehiculo') |
| 183 | 183 | $scope.inicial = angular.copy(cisterna); |
| 184 | 184 | }; |
| 185 | 185 | |
| 186 | - $scope.volver = function(cisterna, key) { | |
| 186 | + $scope.volver = function (cisterna, key) { | |
| 187 | 187 | if (cisterna.id === undefined || !$scope.crear) { |
| 188 | 188 | $scope.cisternas.shift(cisterna); |
| 189 | 189 | $scope.crear = false; |
| ... | ... | @@ -196,7 +196,7 @@ angular.module('focaAbmVehiculo') |
| 196 | 196 | $scope.crear = false; |
| 197 | 197 | }; |
| 198 | 198 | |
| 199 | - $scope.crearCisterna = function() { | |
| 199 | + $scope.crearCisterna = function () { | |
| 200 | 200 | var cisterna = { |
| 201 | 201 | codigo: '', |
| 202 | 202 | capacidad: '', |
| ... | ... | @@ -208,7 +208,7 @@ angular.module('focaAbmVehiculo') |
| 208 | 208 | $scope.crear = true; |
| 209 | 209 | }; |
| 210 | 210 | |
| 211 | - $scope.seleccionarUnidadMedida = function(cisterna) { | |
| 211 | + $scope.seleccionarUnidadMedida = function (cisterna) { | |
| 212 | 212 | var modalInstance = $uibModal.open( |
| 213 | 213 | { |
| 214 | 214 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| ... | ... | @@ -217,14 +217,14 @@ angular.module('focaAbmVehiculo') |
| 217 | 217 | size: 'lg' |
| 218 | 218 | } |
| 219 | 219 | ); |
| 220 | - modalInstance.result.then(function(unidaMedida) { | |
| 220 | + modalInstance.result.then(function (unidaMedida) { | |
| 221 | 221 | cisterna.idUnidadMedida = unidaMedida.ID; |
| 222 | 222 | cisterna.unidadMedida = unidaMedida; |
| 223 | 223 | }); |
| 224 | 224 | }; |
| 225 | 225 | |
| 226 | - $scope.guardar = function(key) { | |
| 227 | - key = (typeof key === 'undefined') ? 13 : key; | |
| 226 | + $scope.guardar = function (key) { | |
| 227 | + key = (typeof key === 'undefined') ? 13 : key; | |
| 228 | 228 | |
| 229 | 229 | if (key === 13) { |
| 230 | 230 | |
| ... | ... | @@ -232,7 +232,7 @@ angular.module('focaAbmVehiculo') |
| 232 | 232 | $scope.salir(); |
| 233 | 233 | return; |
| 234 | 234 | } |
| 235 | - $scope.cisternas.forEach( function(cisterna) { | |
| 235 | + $scope.cisternas.forEach(function (cisterna) { | |
| 236 | 236 | if (cisterna.id === 0) cisterna.id = undefined; |
| 237 | 237 | }); |
| 238 | 238 | |
| ... | ... | @@ -252,33 +252,33 @@ angular.module('focaAbmVehiculo') |
| 252 | 252 | //Valida si existe numero de unidad |
| 253 | 253 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 254 | 254 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 255 | - ' debe ser igual a la capacidad total del vehículo'); | |
| 255 | + ' debe ser igual a la capacidad total del vehículo'); | |
| 256 | 256 | return; |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - validaCodigoUnidad().then(function() { | |
| 259 | + validaCodigoUnidad().then(function () { | |
| 260 | 260 | delete $scope.vehiculo.transportista; |
| 261 | 261 | delete $scope.vehiculo.cisternas; |
| 262 | 262 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
| 263 | - .then(function(res) { | |
| 263 | + .then(function (res) { | |
| 264 | 264 | if ($scope.nuevo) { |
| 265 | 265 | $location.path('/vehiculo/' + res.data.id + |
| 266 | 266 | '/' + res.data.idTransportista); |
| 267 | 267 | } else { |
| 268 | - guardarCisternas($scope.cisternas).then(function() { | |
| 268 | + guardarCisternas($scope.cisternas).then(function () { | |
| 269 | 269 | $location.path('/vehiculo'); |
| 270 | 270 | }); |
| 271 | 271 | } |
| 272 | 272 | }); |
| 273 | - }, function() { | |
| 273 | + }, function () { | |
| 274 | 274 | focaModalService.alert('Código de unidad existente'); |
| 275 | 275 | }); |
| 276 | 276 | } |
| 277 | 277 | }; |
| 278 | 278 | //Agregar propiedades de cisterna |
| 279 | - $scope.$watch('vehiculo', function(newValue) { | |
| 279 | + $scope.$watch('vehiculo', function (newValue) { | |
| 280 | 280 | focaBotoneraLateralService.setPausarData({ |
| 281 | - label:'vehiculo', | |
| 281 | + label: 'vehiculo', | |
| 282 | 282 | val: { |
| 283 | 283 | codigo: newValue.codigo, |
| 284 | 284 | tractor: newValue.tractor, |
| ... | ... | @@ -291,7 +291,7 @@ angular.module('focaAbmVehiculo') |
| 291 | 291 | }, true); |
| 292 | 292 | |
| 293 | 293 | function getLSVehiculo() { |
| 294 | - var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 294 | + var vehiculo = JSON.parse($localStorage.vehiculo || null); | |
| 295 | 295 | if (vehiculo) { |
| 296 | 296 | setearVehiculo(vehiculo); |
| 297 | 297 | delete $localStorage.vehiculo; |
| ... | ... | @@ -308,9 +308,9 @@ angular.module('focaAbmVehiculo') |
| 308 | 308 | }); |
| 309 | 309 | } |
| 310 | 310 | |
| 311 | - $scope.solicitarConfirmacionTabla = function(cisterna) { | |
| 311 | + $scope.solicitarConfirmacionTabla = function (cisterna) { | |
| 312 | 312 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') |
| 313 | - .then( function(data) { | |
| 313 | + .then(function (data) { | |
| 314 | 314 | if (data) { |
| 315 | 315 | cisterna.desactivado = true; |
| 316 | 316 | } |
| ... | ... | @@ -319,12 +319,12 @@ angular.module('focaAbmVehiculo') |
| 319 | 319 | }; |
| 320 | 320 | |
| 321 | 321 | function validaCodigoUnidad() { |
| 322 | - return new Promise(function(resolve, reject) { | |
| 322 | + return new Promise(function (resolve, reject) { | |
| 323 | 323 | focaAbmVehiculoService |
| 324 | 324 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
| 325 | - .then(function(res) { | |
| 325 | + .then(function (res) { | |
| 326 | 326 | //Valida si existe numero de unidad |
| 327 | - var existe = res.data.filter(function(vehiculo) { | |
| 327 | + var existe = res.data.filter(function (vehiculo) { | |
| 328 | 328 | return vehiculo.codigo === $scope.vehiculo.codigo && |
| 329 | 329 | vehiculo.id !== $scope.vehiculo.id; |
| 330 | 330 | }); |
| ... | ... | @@ -340,7 +340,7 @@ angular.module('focaAbmVehiculo') |
| 340 | 340 | |
| 341 | 341 | function validaTotalCargas() { |
| 342 | 342 | var total = 0; |
| 343 | - $scope.cisternas.forEach(function(cisterna) { | |
| 343 | + $scope.cisternas.forEach(function (cisterna) { | |
| 344 | 344 | if (!cisterna.desactivado) { |
| 345 | 345 | total += parseInt(cisterna.capacidad); |
| 346 | 346 | } |
| ... | ... | @@ -348,7 +348,7 @@ angular.module('focaAbmVehiculo') |
| 348 | 348 | return $scope.vehiculo.capacidad >= total; |
| 349 | 349 | } |
| 350 | 350 | function guardarCisternas() { |
| 351 | - var cisternas = $scope.cisternas.map(function(cisterna) { | |
| 351 | + var cisternas = $scope.cisternas.map(function (cisterna) { | |
| 352 | 352 | return { |
| 353 | 353 | id: cisterna.id, |
| 354 | 354 | capacidad: parseFloat(cisterna.capacidad), |
| ... | ... | @@ -362,7 +362,7 @@ angular.module('focaAbmVehiculo') |
| 362 | 362 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | - $scope.agregarCisterna = function(cisterna) { | |
| 365 | + $scope.agregarCisterna = function (cisterna) { | |
| 366 | 366 | if (!cisterna) { |
| 367 | 367 | focaModalService.alert('Ingrese valores'); |
| 368 | 368 | return; |
| ... | ... | @@ -375,47 +375,50 @@ angular.module('focaAbmVehiculo') |
| 375 | 375 | } else if (!cisterna.idUnidadMedida) { |
| 376 | 376 | focaModalService.alert('Ingrese unidad de medida'); |
| 377 | 377 | return; |
| 378 | + } else if (cisterna.id === undefined) { | |
| 379 | + cisterna.id = 0; | |
| 378 | 380 | } |
| 379 | 381 | |
| 380 | 382 | validaCodigo(cisterna); |
| 381 | - cisterna.id = 0; | |
| 382 | 383 | }; |
| 383 | 384 | |
| 384 | 385 | if ($routeParams.idx !== -1) { |
| 385 | 386 | $scope.cisterna = [$routeParams.idx]; |
| 386 | 387 | focaAbmVehiculoService |
| 387 | 388 | .getCisternas($routeParams.idVehiculo) |
| 388 | - .then(function(res) { | |
| 389 | + .then(function (res) { | |
| 389 | 390 | $scope.cisterna = res[$routeParams.idx]; |
| 390 | 391 | }); |
| 391 | 392 | } |
| 392 | 393 | |
| 393 | 394 | function validaCodigo(cisterna) { |
| 394 | 395 | focaAbmVehiculoService |
| 395 | - .getCisternas($routeParams.idVehiculo) | |
| 396 | - .then(function(res) { | |
| 397 | - var cisternas = res; | |
| 398 | - var totalCargado = 0; | |
| 399 | - cisternas.forEach(function(cisternaBase, idx) { | |
| 400 | - //SI EL CODIGO YA EXISTE | |
| 401 | - if (cisternaBase.codigo === cisterna.codigo && | |
| 402 | - idx !== $routeParams.idx && | |
| 403 | - cisternaBase.desactivado === false && | |
| 404 | - cisternaBase.id !== cisterna.id | |
| 405 | - ) | |
| 406 | - { | |
| 396 | + .getCisternas($routeParams.idVehiculo) | |
| 397 | + .then(function (res) { | |
| 398 | + var cisternas = res; | |
| 399 | + var totalCargado = 0; | |
| 400 | + | |
| 401 | + for (var i = 0; i < cisternas.length; i++) { | |
| 402 | + //SI EL CODIGO YA EXISTE | |
| 403 | + if (cisternas[i].codigo === cisterna.codigo && | |
| 404 | + i !== $routeParams.idx && | |
| 405 | + cisternas[i].desactivado === false && | |
| 406 | + cisternas[i].id !== cisterna.id | |
| 407 | + ) { | |
| 407 | 408 | focaModalService.alert('Código de cisterna existente'); |
| 409 | + cisterna.editando = true; | |
| 410 | + return; | |
| 408 | 411 | } |
| 409 | - if (idx !== $routeParams.idx && | |
| 410 | - !cisternaBase.desactivado) { | |
| 411 | - totalCargado += cisternaBase.capacidad; | |
| 412 | - } | |
| 413 | - }); | |
| 414 | - $timeout( function(){ | |
| 415 | - cisterna.editando = false; | |
| 416 | - $scope.crear = false; | |
| 417 | - }); | |
| 412 | + if (i !== $routeParams.idx && | |
| 413 | + !cisternas[i].desactivado) { | |
| 414 | + totalCargado += cisternas[i].capacidad; | |
| 415 | + } | |
| 416 | + } | |
| 417 | + $timeout(function () { | |
| 418 | + cisterna.editando = false; | |
| 419 | + $scope.crear = false; | |
| 418 | 420 | }); |
| 419 | - } | |
| 421 | + }); | |
| 422 | + } | |
| 420 | 423 | } |
| 421 | 424 | ]); |