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