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