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