Commit b38b6e0b937491af15e43a394b5f4bf522c6ac5e
1 parent
627479f5e2
Exists in
master
and in
1 other branch
Arreglo espacios IF
Showing
2 changed files
with
7 additions
and
43 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 ($localStorage.vehiculo) { | 23 | if ($localStorage.vehiculo) { |
| 24 | var vehiculo = JSON.parse($localStorage.vehiculo); | 24 | var vehiculo = JSON.parse($localStorage.vehiculo); |
| 25 | if (!vehiculo.idVehiculo) { vehiculo.idVehiculo = 0; } | 25 | if (!vehiculo.idVehiculo) vehiculo.idVehiculo = 0; |
| 26 | $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); | 26 | $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); |
| 27 | } | 27 | } |
| 28 | 28 | ||
| 29 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 29 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { |
| 30 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 30 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); |
| 31 | } | 31 | } |
| 32 | $scope.editar = function(id) { | 32 | $scope.editar = function(id) { |
| 33 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 33 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); |
| 34 | }; | 34 | }; |
| 35 | $scope.solicitarConfirmacion = function(vehiculo) { | 35 | $scope.solicitarConfirmacion = function(vehiculo) { |
| 36 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 36 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + |
| 37 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 37 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( |
| 38 | function(data) { | 38 | function(data) { |
| 39 | if(data) { | 39 | if (data) { |
| 40 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 40 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); |
| 41 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 41 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); |
| 42 | } | 42 | } |
| 43 | } | 43 | } |
| 44 | ); | 44 | ); |
| 45 | }; | 45 | }; |
| 46 | $scope.seleccionarTransportista = function() { | 46 | $scope.seleccionarTransportista = function() { |
| 47 | var parametrosModal = { | 47 | var parametrosModal = { |
| 48 | titulo: 'Búsqueda de Transportista', | 48 | titulo: 'Búsqueda de Transportista', |
| 49 | query: '/transportista', | 49 | query: '/transportista', |
| 50 | columnas: [ | 50 | columnas: [ |
| 51 | { | 51 | { |
| 52 | nombre: 'Código', | 52 | nombre: 'Código', |
| 53 | propiedad: 'COD' | 53 | propiedad: 'COD' |
| 54 | }, | 54 | }, |
| 55 | { | 55 | { |
| 56 | nombre: 'Nombre', | 56 | nombre: 'Nombre', |
| 57 | propiedad: 'NOM' | 57 | propiedad: 'NOM' |
| 58 | }, | 58 | }, |
| 59 | { | 59 | { |
| 60 | nombre: 'CUIT', | 60 | nombre: 'CUIT', |
| 61 | propiedad: 'CUIT' | 61 | propiedad: 'CUIT' |
| 62 | } | 62 | } |
| 63 | ] | 63 | ] |
| 64 | }; | 64 | }; |
| 65 | focaModalService.modal(parametrosModal).then( | 65 | focaModalService.modal(parametrosModal).then( |
| 66 | function(transportista) { | 66 | function(transportista) { |
| 67 | elegirTransportista(transportista); | 67 | elegirTransportista(transportista); |
| 68 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 68 | focaAbmVehiculoService.transportistaSeleccionado = transportista; |
| 69 | }, function() { | 69 | }, function() { |
| 70 | 70 | ||
| 71 | } | 71 | } |
| 72 | ); | 72 | ); |
| 73 | }; | 73 | }; |
| 74 | function elegirTransportista(transportista) { | 74 | function elegirTransportista(transportista) { |
| 75 | var codigo = ('00000' + transportista.COD).slice(-5); | 75 | var codigo = ('00000' + transportista.COD).slice(-5); |
| 76 | $scope.idTransportista = transportista.COD; | 76 | $scope.idTransportista = transportista.COD; |
| 77 | $scope.filtros = transportista.NOM.trim(); | 77 | $scope.filtros = transportista.NOM.trim(); |
| 78 | $timeout(function() { | 78 | $timeout(function() { |
| 79 | $scope.$broadcast('addCabecera', { | 79 | $scope.$broadcast('addCabecera', { |
| 80 | label: 'Transportista:', | 80 | label: 'Transportista:', |
| 81 | valor: codigo + ' - ' + transportista.NOM | 81 | valor: codigo + ' - ' + transportista.NOM |
| 82 | }); | 82 | }); |
| 83 | }); | 83 | }); |
| 84 | buscar(transportista.COD); | 84 | buscar(transportista.COD); |
| 85 | } | 85 | } |
| 86 | 86 | ||
| 87 | function buscar(idTransportista) { | 87 | function buscar(idTransportista) { |
| 88 | focaAbmVehiculoService | 88 | focaAbmVehiculoService |
| 89 | .getVehiculosPorTransportista(idTransportista) | 89 | .getVehiculosPorTransportista(idTransportista) |
| 90 | .then(function(datos) { | 90 | .then(function(datos) { |
| 91 | $scope.vehiculos = datos.data; | 91 | $scope.vehiculos = datos.data; |
| 92 | }); | 92 | }); |
| 93 | } | 93 | } |
| 94 | function salir() { | 94 | function salir() { |
| 95 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 95 | focaAbmVehiculoService.transportistaSeleccionado = {}; |
| 96 | $location.path('/'); | 96 | $location.path('/'); |
| 97 | } | 97 | } |
| 98 | } | 98 | } |
| 99 | ]) | 99 | ]) |
| 100 | .controller('focaAbmVehiculoController', [ | 100 | .controller('focaAbmVehiculoController', [ |
| 101 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 101 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 102 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', | 102 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', |
| 103 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 103 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 104 | focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { | 104 | focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { |
| 105 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 105 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; |
| 106 | $scope.now = new Date(); | 106 | $scope.now = new Date(); |
| 107 | $scope.focused = 1; | 107 | $scope.focused = 1; |
| 108 | $scope.transportistaStamp = ''; | 108 | $scope.transportistaStamp = ''; |
| 109 | $scope.cisternas = []; | 109 | $scope.cisternas = []; |
| 110 | 110 | ||
| 111 | $timeout(function() { | 111 | $timeout(function() { |
| 112 | focaBotoneraLateralService.showSalir(false); | 112 | focaBotoneraLateralService.showSalir(false); |
| 113 | focaBotoneraLateralService.showPausar(true); | 113 | focaBotoneraLateralService.showPausar(true); |
| 114 | focaBotoneraLateralService.showCancelar(false); | 114 | focaBotoneraLateralService.showCancelar(false); |
| 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 116 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | 116 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); |
| 117 | }); | 117 | }); |
| 118 | 118 | ||
| 119 | $timeout(function() {getLSVehiculo();}); | 119 | $timeout(function() {getLSVehiculo();}); |
| 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 | }); | 131 | }); |
| 132 | }); | 132 | }); |
| 133 | } | 133 | } |
| 134 | $scope.vehiculo = {}; | 134 | $scope.vehiculo = {}; |
| 135 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 135 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 136 | if (res.data) { | 136 | if (res.data) { |
| 137 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 137 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); |
| 138 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 138 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; |
| 139 | 139 | ||
| 140 | $scope.vehiculo = res.data; | 140 | $scope.vehiculo = res.data; |
| 141 | $scope.$broadcast('addCabecera', { | 141 | $scope.$broadcast('addCabecera', { |
| 142 | label: 'Transportista:', | 142 | label: 'Transportista:', |
| 143 | valor: $scope.transportistaStamp | 143 | valor: $scope.transportistaStamp |
| 144 | }); | 144 | }); |
| 145 | $scope.$broadcast('addCabecera', { | 145 | $scope.$broadcast('addCabecera', { |
| 146 | label: 'Unidad:', | 146 | label: 'Unidad:', |
| 147 | valor: res.data.codigo | 147 | valor: res.data.codigo |
| 148 | }); | 148 | }); |
| 149 | focaAbmVehiculoService | 149 | focaAbmVehiculoService |
| 150 | .getCisternas($routeParams.idVehiculo) | 150 | .getCisternas($routeParams.idVehiculo) |
| 151 | .then(function(res) { | 151 | .then(function(res) { |
| 152 | $scope.cisternas = res; | 152 | $scope.cisternas = res; |
| 153 | $scope.$apply(); | 153 | $scope.$apply(); |
| 154 | }); | 154 | }); |
| 155 | } | 155 | } |
| 156 | }); | 156 | }); |
| 157 | 157 | ||
| 158 | $scope.next = function(key) { | 158 | $scope.next = function(key) { |
| 159 | if (key === 13) $scope.focused++; | 159 | if (key === 13) $scope.focused++; |
| 160 | }; | 160 | }; |
| 161 | 161 | ||
| 162 | function cancelar() { | 162 | function cancelar() { |
| 163 | if ($scope.formVehiculo.$pristine == false) { | 163 | if ($scope.formVehiculo.$pristine == false) { |
| 164 | focaModalService.confirm( | 164 | focaModalService.confirm( |
| 165 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 165 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 166 | ).then(function(data) { | 166 | ).then(function(data) { |
| 167 | if (data) { | 167 | if (data) { |
| 168 | $location.path('/vehiculo'); | 168 | $location.path('/vehiculo'); |
| 169 | } | 169 | } |
| 170 | }); | 170 | }); |
| 171 | } else { | 171 | } else { |
| 172 | $location.path('/vehiculo'); | 172 | $location.path('/vehiculo'); |
| 173 | } | 173 | } |
| 174 | } | 174 | } |
| 175 | 175 | ||
| 176 | $scope.editar = function(key) { | 176 | $scope.editar = function(key) { |
| 177 | if (key) { | 177 | if (key) { |
| 178 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 178 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 179 | '/cisterna/' + key); | 179 | '/cisterna/' + key); |
| 180 | } else { | 180 | } else { |
| 181 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 181 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); |
| 182 | } | 182 | } |
| 183 | }; | 183 | }; |
| 184 | $scope.guardar = function(key) { | 184 | $scope.guardar = function(key) { |
| 185 | 185 | ||
| 186 | key = (typeof key === 'undefined') ? 13 : key; | 186 | key = (typeof key === 'undefined') ? 13 : key; |
| 187 | 187 | ||
| 188 | if (key === 13) { | 188 | if (key === 13) { |
| 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 |
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','$localStorage', '$filter', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', |
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { |
| 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? 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 | codigo: '', | 11 | codigo: '', |
| 12 | capacidad: '', | 12 | capacidad: '', |
| 13 | unidadMedida: {} | 13 | unidadMedida: {} |
| 14 | }; | 14 | }; |
| 15 | 15 | ||
| 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; |
| 17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { |
| 18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; |
| 19 | }; | 19 | }; |
| 20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; |
| 21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; |
| 22 | 22 | ||
| 23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL |
| 24 | $timeout(function() { | 24 | $timeout(function() { |
| 25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); |
| 26 | focaBotoneraLateralService.showPausar(true); | 26 | focaBotoneraLateralService.showPausar(true); |
| 27 | focaBotoneraLateralService.showCancelar(false); | 27 | focaBotoneraLateralService.showCancelar(false); |
| 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); |
| 29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | 29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); |
| 30 | }); | 30 | }); |
| 31 | 31 | ||
| 32 | // $timeout(function() {getLSCisterna();}); | ||
| 33 | |||
| 34 | // if ($localStorage.cisterna) { | ||
| 35 | // var cisterna = JSON.parse($localStorage.cisterna); | ||
| 36 | // console.log('Cisterna datos: ' ,cisterna); | ||
| 37 | // if (!cisterna.codigo) { cisterna.idcisterna = 0; } | ||
| 38 | // $location.path('/vehiculo/' + vehiculo.idVehiculo + '/cisterna/'); | ||
| 39 | // } | ||
| 40 | |||
| 41 | if ($routeParams.idx != -1) { | 32 | if ($routeParams.idx != -1) { |
| 42 | 33 | ||
| 43 | $scope.cisterna = [$routeParams.idx]; | 34 | $scope.cisterna = [$routeParams.idx]; |
| 44 | focaAbmVehiculoService | 35 | focaAbmVehiculoService |
| 45 | .getCisternas($routeParams.idVehiculo) | 36 | .getCisternas($routeParams.idVehiculo) |
| 46 | .then(function(res) { | 37 | .then(function(res) { |
| 47 | $scope.cisterna = res[$routeParams.idx]; | 38 | $scope.cisterna = res[$routeParams.idx]; |
| 48 | }); | 39 | }); |
| 49 | } | 40 | } |
| 50 | 41 | ||
| 51 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 42 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { |
| 52 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 43 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); |
| 53 | $scope.transportista = res.data.transportista.COD; | 44 | $scope.transportista = res.data.transportista.COD; |
| 54 | $scope.capacidadVechiulo = res.data.capacidad; | 45 | $scope.capacidadVechiulo = res.data.capacidad; |
| 55 | $scope.$broadcast('addCabecera', { | 46 | $scope.$broadcast('addCabecera', { |
| 56 | label: 'Transportista:', | 47 | label: 'Transportista:', |
| 57 | valor: codigo + ' - ' + res.data.transportista.NOM | 48 | valor: codigo + ' - ' + res.data.transportista.NOM |
| 58 | }); | 49 | }); |
| 59 | $scope.$broadcast('addCabecera', { | 50 | $scope.$broadcast('addCabecera', { |
| 60 | label: 'Unidad:', | 51 | label: 'Unidad:', |
| 61 | valor: res.data.codigo | 52 | valor: res.data.codigo |
| 62 | }); | 53 | }); |
| 63 | $scope.$broadcast('addCabecera', { | 54 | $scope.$broadcast('addCabecera', { |
| 64 | label: 'Capacidad total vehículo:', | 55 | label: 'Capacidad total vehículo:', |
| 65 | valor: res.data.capacidad | 56 | valor: res.data.capacidad |
| 66 | }); | 57 | }); |
| 67 | }); | 58 | }); |
| 68 | $scope.cancelar = function() { | 59 | $scope.cancelar = function() { |
| 69 | 60 | ||
| 70 | if ($scope.formCisterna.$pristine == false) { | 61 | if ($scope.formCisterna.$pristine == false) { |
| 71 | focaModalService.confirm( | 62 | focaModalService.confirm( |
| 72 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' |
| 73 | ).then(function(data) { | 64 | ).then(function(data) { |
| 74 | if (data) { | 65 | if (data) { |
| 75 | $location.path('/vehiculo'); | 66 | $location.path('/vehiculo'); |
| 76 | } | 67 | } |
| 77 | }); | 68 | }); |
| 78 | } | 69 | } |
| 79 | }; | 70 | }; |
| 80 | $scope.guardar = function() { | 71 | $scope.guardar = function() { |
| 81 | 72 | ||
| 82 | if (!$scope.cisterna.codigo) { | 73 | if (!$scope.cisterna.codigo) { |
| 83 | focaModalService.alert('Ingrese codigo de cisterna'); | 74 | focaModalService.alert('Ingrese codigo de cisterna'); |
| 84 | return; | 75 | return; |
| 85 | } else if (!$scope.cisterna.capacidad) { | 76 | } else if (!$scope.cisterna.capacidad) { |
| 86 | focaModalService.alert('Ingrese capacidad'); | 77 | focaModalService.alert('Ingrese capacidad'); |
| 87 | return; | 78 | return; |
| 88 | } else if (!$scope.cisterna.idUnidadMedida) { | 79 | } else if (!$scope.cisterna.idUnidadMedida) { |
| 89 | focaModalService.alert('Ingrese unidad de medida'); | 80 | focaModalService.alert('Ingrese unidad de medida'); |
| 90 | return; | 81 | return; |
| 91 | } | 82 | } |
| 92 | 83 | ||
| 93 | validaCodigo() | 84 | validaCodigo() |
| 94 | .then(function() { | 85 | .then(function() { |
| 95 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 86 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); |
| 96 | delete $scope.cisterna.vehiculo; | 87 | delete $scope.cisterna.vehiculo; |
| 97 | 88 | ||
| 98 | focaAbmVehiculoService | 89 | focaAbmVehiculoService |
| 99 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 90 | .guardarCisterna($scope.cisterna, $routeParams.idx); |
| 100 | 91 | ||
| 101 | $timeout(function() { | 92 | $timeout(function() { |
| 102 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 93 | $location.path('/vehiculo/' + $routeParams.idVehiculo + |
| 103 | '/' + $scope.transportista); | 94 | '/' + $scope.transportista); |
| 104 | }, 0); | 95 | }, 0); |
| 105 | }, function(err) { | 96 | }, function(err) { |
| 106 | focaModalService.alert(err); | 97 | focaModalService.alert(err); |
| 107 | }); | 98 | }); |
| 108 | 99 | ||
| 109 | }; | 100 | }; |
| 110 | 101 | ||
| 111 | $scope.seleccionarUnidadMedida = function() { | 102 | $scope.seleccionarUnidadMedida = function() { |
| 112 | var modalInstance = $uibModal.open( | 103 | var modalInstance = $uibModal.open( |
| 113 | { | 104 | { |
| 114 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 105 | ariaLabelledBy: 'Busqueda de Unidades de medida', |
| 115 | templateUrl: 'modal-unidad-medida.html', | 106 | templateUrl: 'modal-unidad-medida.html', |
| 116 | controller: 'focaModalUnidadMedidaCtrl', | 107 | controller: 'focaModalUnidadMedidaCtrl', |
| 117 | size: 'lg' | 108 | size: 'lg' |
| 118 | } | 109 | } |
| 119 | ); | 110 | ); |
| 120 | modalInstance.result.then(function(unidaMedida) { | 111 | modalInstance.result.then(function(unidaMedida) { |
| 121 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 112 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; |
| 122 | $scope.cisterna.unidadMedida = unidaMedida; | 113 | $scope.cisterna.unidadMedida = unidaMedida; |
| 123 | }); | 114 | }); |
| 124 | }; | 115 | }; |
| 125 | 116 | ||
| 126 | /*$scope.$watch('cisterna', function(newValue) { | ||
| 127 | focaBotoneraLateralService.setPausarData({ | ||
| 128 | label:'cisterna', | ||
| 129 | val: { | ||
| 130 | codigo: newValue.codigo, | ||
| 131 | capacidad: newValue.capacidad, | ||
| 132 | unidadMedida: newValue.NOM | ||
| 133 | } | ||
| 134 | }); | ||
| 135 | }, true);*/ | ||
| 136 | |||
| 137 | /*function getLSCisterna() { | ||
| 138 | var cisterna = JSON.parse($localStorage.cisterna|| null); | ||
| 139 | if (cisterna) { | ||
| 140 | setearcisterna(cisterna); | ||
| 141 | delete $localStorage.cisterna; | ||
| 142 | } | ||
| 143 | } | ||
| 144 | |||
| 145 | function setearcisterna(cisterna) { | ||
| 146 | $scope.cisterna = cisterna; | ||
| 147 | $scope.$broadcast('addCabecera', { | ||
| 148 | label: 'cisterna:', | ||
| 149 | valor: $filter('rellenarDigitos')(cisterna.codigo) + ' - ' | ||
| 150 | }); | ||
| 151 | }*/ | ||
| 152 | |||
| 153 | function validaCodigo() { | 117 | function validaCodigo() { |
| 154 | return new Promise(function(resolve, reject) { | 118 | return new Promise(function(resolve, reject) { |
| 155 | focaAbmVehiculoService | 119 | focaAbmVehiculoService |
| 156 | .getCisternas($routeParams.idVehiculo) | 120 | .getCisternas($routeParams.idVehiculo) |
| 157 | .then(function(res) { | 121 | .then(function(res) { |
| 158 | var cisternas = res; | 122 | var cisternas = res; |
| 159 | var totalCargado = 0; | 123 | var totalCargado = 0; |
| 160 | cisternas.forEach(function(cisterna, idx) { | 124 | cisternas.forEach(function(cisterna, idx) { |
| 161 | //SI EL CODIGO YA EXISTE | 125 | //SI EL CODIGO YA EXISTE |
| 162 | if(cisterna.codigo === $scope.cisterna.codigo && | 126 | if (cisterna.codigo === $scope.cisterna.codigo && |
| 163 | idx != $routeParams.idx && | 127 | idx != $routeParams.idx && |
| 164 | !cisterna.desactivado) { | 128 | !cisterna.desactivado) { |
| 165 | reject('Código de cisterna existente'); | 129 | reject('Código de cisterna existente'); |
| 166 | } | 130 | } |
| 167 | if(idx != $routeParams.idx && | 131 | if (idx != $routeParams.idx && |
| 168 | !cisterna.desactivado) { | 132 | !cisterna.desactivado) { |
| 169 | totalCargado += cisterna.capacidad; | 133 | totalCargado += cisterna.capacidad; |
| 170 | } | 134 | } |
| 171 | }); | 135 | }); |
| 172 | resolve(); | 136 | resolve(); |
| 173 | }); | 137 | }); |
| 174 | }); | 138 | }); |
| 175 | } | 139 | } |
| 176 | } | 140 | } |
| 177 | ]); | 141 | ]); |
| 178 | 142 |