Commit 2d4580fb71cbe5e9cb5df528cac2c55b92bbfcdc
Exists in
master
and in
1 other branch
Merge branch 'master' into 'develop'
Master See merge request !38
Showing
1 changed file
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', '$localStorage', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', |
| 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, |
| 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { |
| 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 | focaAbmVehiculoService.cleanCisternas(); | 14 | focaAbmVehiculoService.cleanCisternas(); |
| 15 | 15 | ||
| 16 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL |
| 17 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); |
| 18 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); |
| 19 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); |
| 20 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); |
| 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 22 | 22 | ||
| 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
| 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 25 | } | 25 | } |
| 26 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { |
| 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
| 28 | }; | 28 | }; |
| 29 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { |
| 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
| 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
| 32 | function(data) { | 32 | function(data) { |
| 33 | if (data) { | 33 | if (data) { |
| 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
| 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 36 | } | 36 | } |
| 37 | } | 37 | } |
| 38 | ); | 38 | ); |
| 39 | }; | 39 | }; |
| 40 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { |
| 41 | var parametrosModal = { | 41 | var parametrosModal = { |
| 42 | titulo: 'Búsqueda de Transportista', | 42 | titulo: 'Búsqueda de Transportista', |
| 43 | query: '/transportista', | 43 | query: '/transportista', |
| 44 | columnas: [ | 44 | columnas: [ |
| 45 | { | 45 | { |
| 46 | nombre: 'Código', | 46 | nombre: 'Código', |
| 47 | propiedad: 'COD' | 47 | propiedad: 'COD' |
| 48 | }, | 48 | }, |
| 49 | { | 49 | { |
| 50 | nombre: 'Nombre', | 50 | nombre: 'Nombre', |
| 51 | propiedad: 'NOM' | 51 | propiedad: 'NOM' |
| 52 | }, | 52 | }, |
| 53 | { | 53 | { |
| 54 | nombre: 'CUIT', | 54 | nombre: 'CUIT', |
| 55 | propiedad: 'CUIT' | 55 | propiedad: 'CUIT' |
| 56 | } | 56 | } |
| 57 | ] | 57 | ] |
| 58 | }; | 58 | }; |
| 59 | focaModalService.modal(parametrosModal).then( | 59 | focaModalService.modal(parametrosModal).then( |
| 60 | function(transportista) { | 60 | function(transportista) { |
| 61 | elegirTransportista(transportista); | 61 | elegirTransportista(transportista); |
| 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
| 63 | }, function() { | 63 | }, function() { |
| 64 | 64 | ||
| 65 | } | 65 | } |
| 66 | ); | 66 | ); |
| 67 | }; | 67 | }; |
| 68 | function elegirTransportista(transportista) { | 68 | function elegirTransportista(transportista) { |
| 69 | var codigo = ('00000' + transportista.COD).slice(-5); | 69 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 70 | $scope.idTransportista = transportista.COD; | 70 | $scope.idTransportista = transportista.COD; |
| 71 | $scope.filtros = transportista.NOM.trim(); | 71 | $scope.filtros = transportista.NOM.trim(); |
| 72 | $timeout(function() { | 72 | $timeout(function() { |
| 73 | $scope.$broadcast('addCabecera', { | 73 | $scope.$broadcast('addCabecera', { |
| 74 | label: 'Transportista:', | 74 | label: 'Transportista:', |
| 75 | valor: codigo + ' - ' + transportista.NOM | 75 | valor: codigo + ' - ' + transportista.NOM |
| 76 | }); | 76 | }); |
| 77 | }); | 77 | }); |
| 78 | buscar(transportista.COD); | 78 | buscar(transportista.COD); |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | function buscar(idTransportista) { | 81 | function buscar(idTransportista) { |
| 82 | focaAbmVehiculoService | 82 | focaAbmVehiculoService |
| 83 | .getVehiculosPorTransportista(idTransportista) | 83 | .getVehiculosPorTransportista(idTransportista) |
| 84 | .then(function(datos) { | 84 | .then(function(datos) { |
| 85 | $scope.vehiculos = datos.data; | 85 | $scope.vehiculos = datos.data; |
| 86 | }); | 86 | }); |
| 87 | } | 87 | } |
| 88 | function salir() { | 88 | function salir() { |
| 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
| 90 | $location.path('/'); | 90 | $location.path('/'); |
| 91 | } | 91 | } |
| 92 | } | 92 | } |
| 93 | ]) | 93 | ]) |
| 94 | .controller('focaAbmVehiculoController', [ | 94 | .controller('focaAbmVehiculoController', [ |
| 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', |
| 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { |
| 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 100 | $scope.now = new Date(); | 100 | $scope.now = new Date(); |
| 101 | $scope.focused = 1; | 101 | $scope.focused = 1; |
| 102 | $scope.transportistaStamp = ''; | 102 | $scope.transportistaStamp = ''; |
| 103 | $scope.cisternas = []; | 103 | $scope.cisternas = []; |
| 104 | 104 | ||
| 105 | $timeout(function() { | 105 | $timeout(function() { |
| 106 | focaBotoneraLateralService.showSalir(false); | 106 | focaBotoneraLateralService.showSalir(false); |
| 107 | focaBotoneraLateralService.showPausar(true); | 107 | focaBotoneraLateralService.showPausar(true); |
| 108 | focaBotoneraLateralService.showCancelar(false); | 108 | focaBotoneraLateralService.showCancelar(false); |
| 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 110 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | 110 | focaBotoneraLateralService.addCustomButton('Salir', salir); |
| 111 | }); | 111 | }); |
| 112 | 112 | ||
| 113 | $timeout(function() {getLSVehiculo();}); | 113 | $timeout(function() {getLSVehiculo();}); |
| 114 | 114 | ||
| 115 | if ($scope.nuevo) { | 115 | if ($scope.nuevo) { |
| 116 | focaAbmVehiculoService | 116 | focaAbmVehiculoService |
| 117 | .getTransportistaPorId($routeParams.idTransportista) | 117 | .getTransportistaPorId($routeParams.idTransportista) |
| 118 | .then(function(res) { | 118 | .then(function(res) { |
| 119 | var codigo = ('00000' + res.data.COD).slice(-5); | 119 | var codigo = ('00000' + res.data.COD).slice(-5); |
| 120 | $scope.vehiculo.idTransportista = res.data.COD; | 120 | $scope.vehiculo.idTransportista = res.data.COD; |
| 121 | $scope.vehiculo.transportista = res.data; | 121 | $scope.vehiculo.transportista = res.data; |
| 122 | $scope.$broadcast('addCabecera', { | 122 | $scope.$broadcast('addCabecera', { |
| 123 | label: 'Transportista:', | 123 | label: 'Transportista:', |
| 124 | valor: codigo + ' - ' + res.data.NOM | 124 | valor: codigo + ' - ' + res.data.NOM |
| 125 | }); | 125 | }); |
| 126 | }); | 126 | }); |
| 127 | } | 127 | } |
| 128 | $scope.vehiculo = {}; | 128 | $scope.vehiculo = {}; |
| 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 130 | if (res.data) { | 130 | if (res.data) { |
| 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
| 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
| 133 | 133 | ||
| 134 | $scope.vehiculo = res.data; | 134 | $scope.vehiculo = res.data; |
| 135 | $scope.$broadcast('addCabecera', { | 135 | $scope.$broadcast('addCabecera', { |
| 136 | label: 'Transportista:', | 136 | label: 'Transportista:', |
| 137 | valor: $scope.transportistaStamp | 137 | valor: $scope.transportistaStamp |
| 138 | }); | 138 | }); |
| 139 | $scope.$broadcast('addCabecera', { | 139 | $scope.$broadcast('addCabecera', { |
| 140 | label: 'Unidad:', | 140 | label: 'Unidad:', |
| 141 | valor: res.data.codigo | 141 | valor: res.data.codigo |
| 142 | }); | 142 | }); |
| 143 | focaAbmVehiculoService | 143 | focaAbmVehiculoService |
| 144 | .getCisternas($routeParams.idVehiculo) | 144 | .getCisternas($routeParams.idVehiculo) |
| 145 | .then(function(res) { | 145 | .then(function(res) { |
| 146 | $scope.cisternas = res; | 146 | $scope.cisternas = res; |
| 147 | $scope.$apply(); | 147 | $scope.$apply(); |
| 148 | }); | 148 | }); |
| 149 | } | 149 | } |
| 150 | }); | 150 | }); |
| 151 | 151 | ||
| 152 | $scope.next = function(key) { | 152 | $scope.next = function(key) { |
| 153 | if (key === 13) $scope.focused++; | 153 | if (key === 13) $scope.focused++; |
| 154 | }; | 154 | }; |
| 155 | 155 | ||
| 156 | function cancelar() { | 156 | function salir() { |
| 157 | if (!$scope.formVehiculo.$pristine) { | 157 | if (!$scope.formVehiculo.$pristine) { |
| 158 | focaModalService.confirm( | 158 | focaModalService.confirm( |
| 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 160 | ).then(function(data) { | 160 | ).then(function(data) { |
| 161 | if (data) { | 161 | if (data) { |
| 162 | $location.path('/vehiculo'); | 162 | $location.path('/vehiculo'); |
| 163 | } | 163 | } |
| 164 | }); | 164 | }); |
| 165 | } else { | 165 | } else { |
| 166 | $location.path('/vehiculo'); | 166 | $location.path('/vehiculo'); |
| 167 | } | 167 | } |
| 168 | } | 168 | } |
| 169 | 169 | ||
| 170 | $scope.editar = function(key) { | 170 | $scope.editar = function(key) { |
| 171 | if (key) { | 171 | if (key) { |
| 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 173 | '/cisterna/' + key); | 173 | '/cisterna/' + key); |
| 174 | } else { | 174 | } else { |
| 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
| 176 | } | 176 | } |
| 177 | }; | 177 | }; |
| 178 | $scope.guardar = function(key) { | 178 | $scope.guardar = function(key) { |
| 179 | 179 | ||
| 180 | key = (typeof key === 'undefined') ? 13 : key; | 180 | key = (typeof key === 'undefined') ? 13 : key; |
| 181 | 181 | ||
| 182 | if (key === 13) { | 182 | if (key === 13) { |
| 183 | 183 | ||
| 184 | if ($scope.formVehiculo.$pristine) { | 184 | if ($scope.formVehiculo.$pristine) { |
| 185 | $scope.cancelar(); | 185 | $scope.cancelar(); |
| 186 | return; | 186 | return; |
| 187 | } | 187 | } |
| 188 | 188 | ||
| 189 | if (!$scope.vehiculo.codigo) { | 189 | if (!$scope.vehiculo.codigo) { |
| 190 | focaModalService.alert('Ingrese unidad'); | 190 | focaModalService.alert('Ingrese unidad'); |
| 191 | return; | 191 | return; |
| 192 | } else if (!$scope.vehiculo.tractor) { | 192 | } else if (!$scope.vehiculo.tractor) { |
| 193 | focaModalService.alert('Ingrese dominio tractor'); | 193 | focaModalService.alert('Ingrese dominio tractor'); |
| 194 | return; | 194 | return; |
| 195 | } else if (!$scope.vehiculo.semi) { | 195 | } else if (!$scope.vehiculo.semi) { |
| 196 | focaModalService.alert('Ingrese dominio semi'); | 196 | focaModalService.alert('Ingrese dominio semi'); |
| 197 | return; | 197 | return; |
| 198 | } else if (!$scope.vehiculo.capacidad) { | 198 | } else if (!$scope.vehiculo.capacidad) { |
| 199 | focaModalService.alert('Ingrese capacidad total'); | 199 | focaModalService.alert('Ingrese capacidad total'); |
| 200 | return; | 200 | return; |
| 201 | } | 201 | } |
| 202 | //Valida si existe numero de unidad | 202 | //Valida si existe numero de unidad |
| 203 | if (!validaTotalCargas() && !$scope.nuevo) { | 203 | if (!validaTotalCargas() && !$scope.nuevo) { |
| 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + |
| 205 | ' debe ser igual a la capacidad total del vehículo'); | 205 | ' debe ser igual a la capacidad total del vehículo'); |
| 206 | return; | 206 | return; |
| 207 | } | 207 | } |
| 208 | validaCodigoUnidad().then(function() { | 208 | validaCodigoUnidad().then(function() { |
| 209 | delete $scope.vehiculo.transportista; | 209 | delete $scope.vehiculo.transportista; |
| 210 | delete $scope.vehiculo.cisternas; | 210 | delete $scope.vehiculo.cisternas; |
| 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) |
| 212 | .then(function(res) { | 212 | .then(function(res) { |
| 213 | if ($scope.nuevo) { | 213 | if ($scope.nuevo) { |
| 214 | $location.path('/vehiculo/' + res.data.id + | 214 | $location.path('/vehiculo/' + res.data.id + |
| 215 | '/' + res.data.idTransportista); | 215 | '/' + res.data.idTransportista); |
| 216 | } else { | 216 | } else { |
| 217 | guardarCisternas().then(function() { | 217 | guardarCisternas().then(function() { |
| 218 | $location.path('/vehiculo'); | 218 | $location.path('/vehiculo'); |
| 219 | }); | 219 | }); |
| 220 | } | 220 | } |
| 221 | }); | 221 | }); |
| 222 | }, function() { | 222 | }, function() { |
| 223 | focaModalService.alert('Código de unidad existente'); | 223 | focaModalService.alert('Código de unidad existente'); |
| 224 | }); | 224 | }); |
| 225 | } | 225 | } |
| 226 | 226 | ||
| 227 | }; | 227 | }; |
| 228 | 228 | ||
| 229 | $scope.$watch('vehiculo', function(newValue) { | 229 | $scope.$watch('vehiculo', function(newValue) { |
| 230 | focaBotoneraLateralService.setPausarData({ | 230 | focaBotoneraLateralService.setPausarData({ |
| 231 | label:'vehiculo', | 231 | label:'vehiculo', |
| 232 | val: { | 232 | val: { |
| 233 | codigo: newValue.codigo, | 233 | codigo: newValue.codigo, |
| 234 | tractor: newValue.tractor, | 234 | tractor: newValue.tractor, |
| 235 | semi: newValue.semi, | 235 | semi: newValue.semi, |
| 236 | capacidad: newValue.capacidad, | 236 | capacidad: newValue.capacidad, |
| 237 | idVehiculo: newValue.idVehiculo, | 237 | idVehiculo: newValue.idVehiculo, |
| 238 | idTransportista: newValue.idTransportista | 238 | idTransportista: newValue.idTransportista |
| 239 | } | 239 | } |
| 240 | }); | 240 | }); |
| 241 | }, true); | 241 | }, true); |
| 242 | 242 | ||
| 243 | function getLSVehiculo() { | 243 | function getLSVehiculo() { |
| 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); |
| 245 | if (vehiculo) { | 245 | if (vehiculo) { |
| 246 | setearVehiculo(vehiculo); | 246 | setearVehiculo(vehiculo); |
| 247 | delete $localStorage.vehiculo; | 247 | delete $localStorage.vehiculo; |
| 248 | } | 248 | } |
| 249 | } | 249 | } |
| 250 | 250 | ||
| 251 | function setearVehiculo(vehiculo) { | 251 | function setearVehiculo(vehiculo) { |
| 252 | $scope.vehiculo = vehiculo; | 252 | $scope.vehiculo = vehiculo; |
| 253 | $scope.$broadcast('addCabecera', { | 253 | $scope.$broadcast('addCabecera', { |
| 254 | label: 'Vehiculo:', | 254 | label: 'Vehiculo:', |
| 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' |
| 256 | }); | 256 | }); |
| 257 | } | 257 | } |
| 258 | 258 | ||
| 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { |
| 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + |
| 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( |
| 262 | function(data) { | 262 | function(data) { |
| 263 | if (data) { | 263 | if (data) { |
| 264 | focaAbmVehiculoService.deleteCisterna(idx); | 264 | focaAbmVehiculoService.deleteCisterna(idx); |
| 265 | focaAbmVehiculoService | 265 | focaAbmVehiculoService |
| 266 | .getCisternas($routeParams.idVehiculo) | 266 | .getCisternas($routeParams.idVehiculo) |
| 267 | .then(function(res) { | 267 | .then(function(res) { |
| 268 | $scope.cisternas = res; | 268 | $scope.cisternas = res; |
| 269 | }); | 269 | }); |
| 270 | } | 270 | } |
| 271 | } | 271 | } |
| 272 | ); | 272 | ); |
| 273 | }; | 273 | }; |
| 274 | 274 | ||
| 275 | function validaCodigoUnidad() { | 275 | function validaCodigoUnidad() { |
| 276 | return new Promise(function(resolve, reject) { | 276 | return new Promise(function(resolve, reject) { |
| 277 | focaAbmVehiculoService | 277 | focaAbmVehiculoService |
| 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) |
| 279 | .then(function(res) { | 279 | .then(function(res) { |
| 280 | //Valida si existe numero de unidad | 280 | //Valida si existe numero de unidad |
| 281 | var existe = res.data.filter(function(vehiculo) { | 281 | var existe = res.data.filter(function(vehiculo) { |
| 282 | return vehiculo.codigo === $scope.vehiculo.codigo && | 282 | return vehiculo.codigo === $scope.vehiculo.codigo && |
| 283 | vehiculo.id !== $scope.vehiculo.id; | 283 | vehiculo.id !== $scope.vehiculo.id; |
| 284 | }); | 284 | }); |
| 285 | 285 | ||
| 286 | if (existe.length) { | 286 | if (existe.length) { |
| 287 | reject(existe); | 287 | reject(existe); |
| 288 | } else { | 288 | } else { |
| 289 | resolve(); | 289 | resolve(); |
| 290 | } | 290 | } |
| 291 | }); | 291 | }); |
| 292 | }); | 292 | }); |
| 293 | } | 293 | } |
| 294 | 294 | ||
| 295 | function validaTotalCargas() { | 295 | function validaTotalCargas() { |
| 296 | var total = 0; | 296 | var total = 0; |
| 297 | $scope.cisternas.forEach(function(cisterna) { | 297 | $scope.cisternas.forEach(function(cisterna) { |
| 298 | if (!cisterna.desactivado) { | 298 | if (!cisterna.desactivado) { |
| 299 | total += parseInt(cisterna.capacidad); | 299 | total += parseInt(cisterna.capacidad); |
| 300 | } | 300 | } |
| 301 | }); | 301 | }); |
| 302 | return $scope.vehiculo.capacidad === total; | 302 | return $scope.vehiculo.capacidad === total; |
| 303 | } | 303 | } |
| 304 | 304 | ||
| 305 | function guardarCisternas() { | 305 | function guardarCisternas() { |
| 306 | var cisternas = $scope.cisternas.map(function(cisterna) { | 306 | var cisternas = $scope.cisternas.map(function(cisterna) { |
| 307 | return { | 307 | return { |
| 308 | id: cisterna.id, | 308 | id: cisterna.id, |
| 309 | capacidad: parseFloat(cisterna.capacidad), | 309 | capacidad: parseFloat(cisterna.capacidad), |
| 310 | codigo: cisterna.codigo, | 310 | codigo: cisterna.codigo, |
| 311 | idUnidadMedida: cisterna.idUnidadMedida, | 311 | idUnidadMedida: cisterna.idUnidadMedida, |
| 312 | idVehiculo: $routeParams.idVehiculo, | 312 | idVehiculo: $routeParams.idVehiculo, |
| 313 | desactivado: cisterna.desactivado | 313 | desactivado: cisterna.desactivado |
| 314 | }; | 314 | }; |
| 315 | }); | 315 | }); |
| 316 | 316 | ||
| 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); | 317 | return focaAbmVehiculoService.guardarCisternas(cisternas); |
| 318 | } | 318 | } |
| 319 | } | 319 | } |
| 320 | ]); | 320 | ]); |
| 321 | 321 |