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') | |
| 2 | - .controller('focaAbmVehiculosController', [ | |
| 3 | - '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | |
| 4 | - '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | |
| 5 | - function($scope, focaAbmVehiculoService, $location, focaModalService, | |
| 6 | - $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | |
| 1 | +angular.module('focaAbmVehiculo') | |
| 2 | + .controller('focaAbmVehiculosController', [ | |
| 3 | + '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | |
| 4 | + '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | |
| 5 | + function($scope, focaAbmVehiculoService, $location, focaModalService, | |
| 6 | + $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | |
| 7 | 7 | |
| 8 | - $scope.now = new Date(); | |
| 9 | - $scope.botonera = [{ | |
| 10 | - label: 'Transportista', | |
| 11 | - image: 'cliente.png' | |
| 12 | - }]; | |
| 8 | + $scope.now = new Date(); | |
| 9 | + $scope.botonera = [{ | |
| 10 | + label: 'Transportista', | |
| 11 | + image: 'cliente.png' | |
| 12 | + }]; | |
| 13 | 13 | |
| 14 | - focaAbmVehiculoService.cleanCisternas(); | |
| 14 | + focaAbmVehiculoService.cleanCisternas(); | |
| 15 | 15 | |
| 16 | - //SETEO BOTONERA LATERAL | |
| 17 | - focaBotoneraLateralService.showSalir(false); | |
| 18 | - focaBotoneraLateralService.showPausar(false); | |
| 19 | - focaBotoneraLateralService.showCancelar(false); | |
| 20 | - focaBotoneraLateralService.showGuardar(false); | |
| 21 | - focaBotoneraLateralService.addCustomButton('Salir', salir); | |
| 16 | + //SETEO BOTONERA LATERAL | |
| 17 | + focaBotoneraLateralService.showSalir(false); | |
| 18 | + focaBotoneraLateralService.showPausar(false); | |
| 19 | + focaBotoneraLateralService.showCancelar(false); | |
| 20 | + focaBotoneraLateralService.showGuardar(false); | |
| 21 | + focaBotoneraLateralService.addCustomButton('Salir', salir); | |
| 22 | 22 | |
| 23 | - if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | |
| 24 | - elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | |
| 25 | - } | |
| 26 | - $scope.editar = function(id) { | |
| 27 | - $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | |
| 28 | - }; | |
| 29 | - $scope.solicitarConfirmacion = function(vehiculo) { | |
| 30 | - focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | |
| 31 | - vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | |
| 32 | - function(data) { | |
| 33 | - if (data) { | |
| 34 | - focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | |
| 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' | |
| 23 | + if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | |
| 24 | + elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | |
| 25 | + } | |
| 26 | + $scope.editar = function(id) { | |
| 27 | + $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | |
| 28 | + }; | |
| 29 | + $scope.solicitarConfirmacion = function(vehiculo) { | |
| 30 | + focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | |
| 31 | + vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | |
| 32 | + function(data) { | |
| 33 | + if (data) { | |
| 34 | + focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | |
| 35 | + $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | |
| 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) { | |
| 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 | |
| 76 | - }); | |
| 59 | + focaModalService.modal(parametrosModal).then( | |
| 60 | + function(transportista) { | |
| 61 | + elegirTransportista(transportista); | |
| 62 | + focaAbmVehiculoService.transportistaSeleccionado = transportista; | |
| 63 | + }, function() { | |
| 64 | + | |
| 65 | + } | |
| 66 | + ); | |
| 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); | |
| 79 | - } | |
| 77 | + }); | |
| 78 | + buscar(transportista.COD); | |
| 79 | + } | |
| 80 | 80 | |
| 81 | - function buscar(idTransportista) { | |
| 82 | - focaAbmVehiculoService | |
| 83 | - .getVehiculosPorTransportista(idTransportista) | |
| 84 | - .then(function(datos) { | |
| 85 | - $scope.vehiculos = datos.data; | |
| 86 | - }); | |
| 87 | - } | |
| 88 | - function salir() { | |
| 89 | - focaAbmVehiculoService.transportistaSeleccionado = {}; | |
| 90 | - $location.path('/'); | |
| 91 | - } | |
| 81 | + function buscar(idTransportista) { | |
| 82 | + focaAbmVehiculoService | |
| 83 | + .getVehiculosPorTransportista(idTransportista) | |
| 84 | + .then(function(datos) { | |
| 85 | + $scope.vehiculos = datos.data; | |
| 86 | + }); | |
| 92 | 87 | } |
| 93 | - ]) | |
| 94 | - .controller('focaAbmVehiculoController', [ | |
| 95 | - '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | |
| 96 | - 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | |
| 97 | - function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 98 | - focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
| 99 | - $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | |
| 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 = []; | |
| 88 | + function salir() { | |
| 89 | + focaAbmVehiculoService.transportistaSeleccionado = {}; | |
| 90 | + $location.path('/'); | |
| 91 | + } | |
| 92 | + } | |
| 93 | + ]) | |
| 94 | + .controller('focaAbmVehiculoController', [ | |
| 95 | + '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | |
| 96 | + 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | |
| 97 | + function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | |
| 98 | + focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | |
| 99 | + $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | |
| 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 = { | |
| 108 | - codigo: '', | |
| 109 | - capacidad: '', | |
| 110 | - unidadMedida: {} | |
| 111 | - }; | |
| 107 | + $scope.cisterna = { | |
| 108 | + codigo: '', | |
| 109 | + capacidad: '', | |
| 110 | + unidadMedida: {} | |
| 111 | + }; | |
| 112 | 112 | |
| 113 | - $timeout(function() { | |
| 114 | - focaBotoneraLateralService.showSalir(false); | |
| 115 | - focaBotoneraLateralService.showPausar(true); | |
| 116 | - focaBotoneraLateralService.showCancelar(false); | |
| 117 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
| 118 | - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 119 | - }); | |
| 113 | + $timeout(function() { | |
| 114 | + focaBotoneraLateralService.showSalir(false); | |
| 115 | + focaBotoneraLateralService.showPausar(true); | |
| 116 | + focaBotoneraLateralService.showCancelar(false); | |
| 117 | + focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
| 118 | + focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 119 | + }); | |
| 120 | 120 | |
| 121 | - if ($scope.nuevo) { | |
| 122 | - focaAbmVehiculoService | |
| 123 | - .getTransportistaPorId($routeParams.idTransportista) | |
| 124 | - .then(function(res) { | |
| 125 | - var codigo = ('00000' + res.data.COD).slice(-5); | |
| 126 | - $scope.vehiculo.idTransportista = res.data.COD; | |
| 127 | - $scope.vehiculo.transportista = res.data; | |
| 128 | - $scope.$broadcast('addCabecera', { | |
| 129 | - label: 'Transportista:', | |
| 130 | - valor: codigo + ' - ' + res.data.NOM | |
| 131 | - }); | |
| 121 | + if ($scope.nuevo) { | |
| 122 | + focaAbmVehiculoService | |
| 123 | + .getTransportistaPorId($routeParams.idTransportista) | |
| 124 | + .then(function(res) { | |
| 125 | + var codigo = ('00000' + res.data.COD).slice(-5); | |
| 126 | + $scope.vehiculo.idTransportista = res.data.COD; | |
| 127 | + $scope.vehiculo.transportista = res.data; | |
| 128 | + $scope.$broadcast('addCabecera', { | |
| 129 | + label: 'Transportista:', | |
| 130 | + valor: codigo + ' - ' + res.data.NOM | |
| 132 | 131 | }); |
| 133 | - } | |
| 134 | - $scope.vehiculo = {}; | |
| 132 | + }); | |
| 133 | + } | |
| 134 | + $scope.vehiculo = {}; | |
| 135 | 135 | |
| 136 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 137 | - | |
| 138 | - if (res.data) { | |
| 139 | - var vehiculoSeteado = getLSVehiculo(); | |
| 140 | - if (vehiculoSeteado === false) { | |
| 141 | - $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
| 142 | - $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
| 136 | + focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 137 | + | |
| 138 | + if (res.data) { | |
| 139 | + var vehiculoSeteado = getLSVehiculo(); | |
| 140 | + if (vehiculoSeteado === false) { | |
| 141 | + $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
| 142 | + $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
| 143 | 143 | |
| 144 | - $scope.vehiculo = res.data; | |
| 145 | - $scope.$broadcast('addCabecera', { | |
| 146 | - label: 'Transportista:', | |
| 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(); | |
| 144 | + $scope.vehiculo = res.data; | |
| 145 | + $scope.$broadcast('addCabecera', { | |
| 146 | + label: 'Transportista:', | |
| 147 | + valor: $scope.transportistaStamp | |
| 160 | 148 | }); |
| 161 | - } | |
| 162 | - }); | |
| 163 | - | |
| 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 | - } | |
| 149 | + $scope.$broadcast('addCabecera', { | |
| 150 | + label: 'Unidad:', | |
| 151 | + valor: res.data.codigo | |
| 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) { | |
| 183 | - if (key === 'nuevo') { | |
| 184 | - $scope.editando = true; | |
| 185 | - } else { | |
| 186 | - console.log('Editar: '); | |
| 187 | - $scope.cisterna = cisterna; | |
| 188 | - $scope.editando = true; | |
| 189 | - } | |
| 190 | - }; | |
| 164 | + $scope.next = function(key) { | |
| 165 | + if (key === 13) $scope.focused++; | |
| 166 | + }; | |
| 191 | 167 | |
| 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' | |
| 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'); | |
| 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) { | |
| 208 | - | |
| 209 | - key = (typeof key === 'undefined') ? 13 : key; | |
| 182 | + $scope.editar = function(key, cisterna) { | |
| 183 | + if (key === 'nuevo') { | |
| 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) { | |
| 214 | - $scope.salir(); | |
| 215 | - return; | |
| 216 | - } | |
| 207 | + $scope.guardar = function(key) { | |
| 208 | + | |
| 209 | + key = (typeof key === 'undefined') ? 13 : key; | |
| 217 | 210 | |
| 218 | - if (!$scope.vehiculo.codigo) { | |
| 219 | - focaModalService.alert('Ingrese unidad'); | |
| 220 | - return; | |
| 221 | - } else if (!$scope.vehiculo.tractor) { | |
| 222 | - focaModalService.alert('Ingrese dominio tractor'); | |
| 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 | - }); | |
| 211 | + if (key === 13) { | |
| 212 | + | |
| 213 | + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 214 | + $scope.salir(); | |
| 215 | + return; | |
| 254 | 216 | } |
| 255 | - }; | |
| 256 | 217 | |
| 257 | - //Agregar propiedades de cisterna | |
| 258 | - $scope.$watch('vehiculo', function(newValue) { | |
| 259 | - focaBotoneraLateralService.setPausarData({ | |
| 260 | - label:'vehiculo', | |
| 261 | - val: { | |
| 262 | - codigo: newValue.codigo, | |
| 263 | - tractor: newValue.tractor, | |
| 264 | - semi: newValue.semi, | |
| 265 | - capacidad: newValue.capacidad, | |
| 266 | - idVehiculo: newValue.idVehiculo, | |
| 267 | - idTransportista: newValue.idTransportista | |
| 268 | - } | |
| 218 | + if (!$scope.vehiculo.codigo) { | |
| 219 | + focaModalService.alert('Ingrese unidad'); | |
| 220 | + return; | |
| 221 | + } else if (!$scope.vehiculo.tractor) { | |
| 222 | + focaModalService.alert('Ingrese dominio tractor'); | |
| 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'); | |
| 269 | 253 | }); |
| 270 | - }, true); | |
| 254 | + } | |
| 255 | + }; | |
| 271 | 256 | |
| 272 | - function getLSVehiculo() { | |
| 273 | - var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 274 | - if (vehiculo) { | |
| 275 | - setearVehiculo(vehiculo); | |
| 276 | - delete $localStorage.vehiculo; | |
| 277 | - return true; | |
| 257 | + //Agregar propiedades de cisterna | |
| 258 | + $scope.$watch('vehiculo', function(newValue) { | |
| 259 | + focaBotoneraLateralService.setPausarData({ | |
| 260 | + label:'vehiculo', | |
| 261 | + val: { | |
| 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; | |
| 280 | - } | |
| 269 | + }); | |
| 270 | + }, true); | |
| 281 | 271 | |
| 282 | - function setearVehiculo(vehiculo) { | |
| 283 | - $scope.vehiculo = vehiculo; | |
| 284 | - $scope.$broadcast('addCabecera', { | |
| 285 | - label: 'Vehiculo:', | |
| 286 | - valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | |
| 287 | - }); | |
| 272 | + function getLSVehiculo() { | |
| 273 | + var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 274 | + if (vehiculo) { | |
| 275 | + setearVehiculo(vehiculo); | |
| 276 | + delete $localStorage.vehiculo; | |
| 277 | + return true; | |
| 288 | 278 | } |
| 279 | + return false; | |
| 280 | + } | |
| 289 | 281 | |
| 290 | - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
| 291 | - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
| 292 | - cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
| 293 | - function(data) { | |
| 294 | - if (data) { | |
| 295 | - focaAbmVehiculoService.deleteCisterna(idx); | |
| 296 | - focaAbmVehiculoService | |
| 297 | - .getCisternas($routeParams.idVehiculo) | |
| 298 | - .then(function(res) { | |
| 299 | - $scope.cisternas = res; | |
| 300 | - }); | |
| 301 | - } | |
| 302 | - } | |
| 303 | - ); | |
| 304 | - }; | |
| 282 | + function setearVehiculo(vehiculo) { | |
| 283 | + $scope.vehiculo = vehiculo; | |
| 284 | + $scope.$broadcast('addCabecera', { | |
| 285 | + label: 'Vehiculo:', | |
| 286 | + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | |
| 287 | + }); | |
| 288 | + } | |
| 305 | 289 | |
| 306 | - function validaCodigoUnidad() { | |
| 307 | - return new Promise(function(resolve, reject) { | |
| 308 | - focaAbmVehiculoService | |
| 309 | - .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | |
| 310 | - .then(function(res) { | |
| 311 | - //Valida si existe numero de unidad | |
| 312 | - var existe = res.data.filter(function(vehiculo) { | |
| 313 | - return vehiculo.codigo === $scope.vehiculo.codigo && | |
| 314 | - vehiculo.id !== $scope.vehiculo.id; | |
| 315 | - }); | |
| 290 | + $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
| 291 | + focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
| 292 | + cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
| 293 | + function(data) { | |
| 294 | + if (data) { | |
| 295 | + focaAbmVehiculoService.deleteCisterna(idx); | |
| 296 | + focaAbmVehiculoService | |
| 297 | + .getCisternas($routeParams.idVehiculo) | |
| 298 | + .then(function(res) { | |
| 299 | + $scope.cisternas = res; | |
| 300 | + }); | |
| 301 | + } | |
| 302 | + } | |
| 303 | + ); | |
| 304 | + }; | |
| 316 | 305 | |
| 317 | - if (existe.length) { | |
| 318 | - reject(existe); | |
| 319 | - } else { | |
| 320 | - resolve(); | |
| 321 | - } | |
| 306 | + function validaCodigoUnidad() { | |
| 307 | + return new Promise(function(resolve, reject) { | |
| 308 | + focaAbmVehiculoService | |
| 309 | + .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | |
| 310 | + .then(function(res) { | |
| 311 | + //Valida si existe numero de unidad | |
| 312 | + var existe = res.data.filter(function(vehiculo) { | |
| 313 | + return vehiculo.codigo === $scope.vehiculo.codigo && | |
| 314 | + vehiculo.id !== $scope.vehiculo.id; | |
| 322 | 315 | }); |
| 323 | - }); | |
| 324 | - } | |
| 325 | 316 | |
| 326 | - function validaTotalCargas() { | |
| 327 | - var total = 0; | |
| 328 | - $scope.cisternas.forEach(function(cisterna) { | |
| 329 | - if (!cisterna.desactivado) { | |
| 330 | - total += parseInt(cisterna.capacidad); | |
| 331 | - } | |
| 332 | - }); | |
| 333 | - return $scope.vehiculo.capacidad == total; | |
| 317 | + if (existe.length) { | |
| 318 | + reject(existe); | |
| 319 | + } else { | |
| 320 | + resolve(); | |
| 321 | + } | |
| 322 | + }); | |
| 323 | + }); | |
| 324 | + } | |
| 325 | + | |
| 326 | + function validaTotalCargas() { | |
| 327 | + var total = 0; | |
| 328 | + $scope.cisternas.forEach(function(cisterna) { | |
| 329 | + if (!cisterna.desactivado) { | |
| 330 | + total += parseInt(cisterna.capacidad); | |
| 331 | + } | |
| 332 | + }); | |
| 333 | + return $scope.vehiculo.capacidad == total; | |
| 334 | + } | |
| 335 | + function guardarCisternas() { | |
| 336 | + var cisternas = $scope.cisternas.map(function(cisterna) { | |
| 337 | + return { | |
| 338 | + id: cisterna.id, | |
| 339 | + capacidad: parseFloat(cisterna.capacidad), | |
| 340 | + codigo: cisterna.codigo, | |
| 341 | + idUnidadMedida: cisterna.idUnidadMedida, | |
| 342 | + idVehiculo: $routeParams.idVehiculo, | |
| 343 | + desactivado: cisterna.desactivado | |
| 344 | + }; | |
| 345 | + }); | |
| 346 | + | |
| 347 | + return focaAbmVehiculoService.guardarCisternas(cisternas); | |
| 348 | + } | |
| 349 | + | |
| 350 | + $scope.guardarCisterna = function() { | |
| 351 | + if (!$scope.cisterna.codigo) { | |
| 352 | + focaModalService.alert('Ingrese codigo de cisterna'); | |
| 353 | + return; | |
| 354 | + } else if (!$scope.cisterna.capacidad) { | |
| 355 | + focaModalService.alert('Ingrese capacidad'); | |
| 356 | + return; | |
| 357 | + } else if (!$scope.cisterna.idUnidadMedida) { | |
| 358 | + focaModalService.alert('Ingrese unidad de medida'); | |
| 359 | + return; | |
| 334 | 360 | } |
| 335 | - function guardarCisternas() { | |
| 336 | - var cisternas = $scope.cisternas.map(function(cisterna) { | |
| 337 | - return { | |
| 338 | - id: cisterna.id, | |
| 339 | - capacidad: parseFloat(cisterna.capacidad), | |
| 340 | - codigo: cisterna.codigo, | |
| 341 | - idUnidadMedida: cisterna.idUnidadMedida, | |
| 342 | - idVehiculo: $routeParams.idVehiculo, | |
| 343 | - desactivado: cisterna.desactivado | |
| 344 | - }; | |
| 361 | + $scope.editando = false; | |
| 362 | + validaCodigo() | |
| 363 | + .then(function() { | |
| 364 | + saveCisterna(); | |
| 365 | + }, function(err) { | |
| 366 | + focaModalService.alert(err); | |
| 345 | 367 | }); |
| 346 | - | |
| 347 | - return focaAbmVehiculoService.guardarCisternas(cisternas); | |
| 348 | - } | |
| 368 | + }; | |
| 349 | 369 | |
| 350 | - $scope.guardarCisterna = function() { | |
| 351 | - if (!$scope.cisterna.codigo) { | |
| 352 | - focaModalService.alert('Ingrese codigo de cisterna'); | |
| 353 | - return; | |
| 354 | - } else if (!$scope.cisterna.capacidad) { | |
| 355 | - focaModalService.alert('Ingrese capacidad'); | |
| 356 | - return; | |
| 357 | - } else if (!$scope.cisterna.idUnidadMedida) { | |
| 358 | - focaModalService.alert('Ingrese unidad de medida'); | |
| 359 | - return; | |
| 360 | - } | |
| 361 | - $scope.editando = false; | |
| 362 | - validaCodigo() | |
| 363 | - .then(function() { | |
| 364 | - saveCisterna(); | |
| 365 | - }, function(err) { | |
| 366 | - focaModalService.alert(err); | |
| 367 | - }); | |
| 368 | - }; | |
| 370 | + function saveCisterna () { | |
| 371 | + $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | |
| 372 | + delete $scope.cisterna.vehiculo; | |
| 373 | + var auxCisternas = $scope.cisternas; | |
| 374 | + auxCisternas.push($scope.cisterna); | |
| 375 | + guardarCisternas(auxCisternas) | |
| 376 | + .then(function(result) { | |
| 377 | + $scope.cisternas = result.data; | |
| 378 | + $scope.cisterna = {}; | |
| 379 | + }) | |
| 380 | + .catch(function (err) { | |
| 381 | + console.log('Err: ', err); | |
| 382 | + }); | |
| 383 | + } | |
| 369 | 384 | |
| 370 | - function saveCisterna () { | |
| 371 | - $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | |
| 372 | - delete $scope.cisterna.vehiculo; | |
| 373 | - var auxCisternas = $scope.cisternas; | |
| 374 | - auxCisternas.push($scope.cisterna); | |
| 375 | - guardarCisternas(auxCisternas) | |
| 376 | - .then(function(result) { | |
| 377 | - $scope.cisternas = result.data; | |
| 378 | - $scope.cisterna = {}; | |
| 379 | - }) | |
| 380 | - .catch(function (err) { | |
| 381 | - console.log('Err: ', err); | |
| 385 | + if ($routeParams.idx !== -1) { | |
| 386 | + $scope.cisterna = [$routeParams.idx]; | |
| 387 | + focaAbmVehiculoService | |
| 388 | + .getCisternas($routeParams.idVehiculo) | |
| 389 | + .then(function(res) { | |
| 390 | + $scope.cisterna = res[$routeParams.idx]; | |
| 382 | 391 | }); |
| 383 | - } | |
| 392 | + } | |
| 384 | 393 | |
| 385 | - if ($routeParams.idx !== -1) { | |
| 386 | - $scope.cisterna = [$routeParams.idx]; | |
| 394 | + function validaCodigo() { | |
| 395 | + return new Promise(function(resolve, reject) { | |
| 387 | 396 | focaAbmVehiculoService |
| 388 | 397 | .getCisternas($routeParams.idVehiculo) |
| 389 | 398 | .then(function(res) { |
| 390 | - $scope.cisterna = res[$routeParams.idx]; | |
| 391 | - }); | |
| 392 | - } | |
| 393 | - | |
| 394 | - function validaCodigo() { | |
| 395 | - return new Promise(function(resolve, reject) { | |
| 396 | - focaAbmVehiculoService | |
| 397 | - .getCisternas($routeParams.idVehiculo) | |
| 398 | - .then(function(res) { | |
| 399 | - var cisternas = res; | |
| 400 | - var totalCargado = 0; | |
| 401 | - cisternas.forEach(function(cisterna, idx) { | |
| 402 | - //SI EL CODIGO YA EXISTE | |
| 403 | - if (cisterna.codigo === $scope.cisterna.codigo && | |
| 404 | - idx != $routeParams.idx && | |
| 405 | - !cisterna.desactivado) { | |
| 406 | - reject('Código de cisterna existente'); | |
| 407 | - } | |
| 408 | - if (idx !== $routeParams.idx && | |
| 409 | - !cisterna.desactivado) { | |
| 410 | - totalCargado += cisterna.capacidad; | |
| 411 | - } | |
| 412 | - }); | |
| 413 | - resolve(); | |
| 399 | + var cisternas = res; | |
| 400 | + var totalCargado = 0; | |
| 401 | + cisternas.forEach(function(cisterna, idx) { | |
| 402 | + //SI EL CODIGO YA EXISTE | |
| 403 | + if (cisterna.codigo === $scope.cisterna.codigo && | |
| 404 | + idx != $routeParams.idx && | |
| 405 | + !cisterna.desactivado) { | |
| 406 | + reject('Código de cisterna existente'); | |
| 407 | + } | |
| 408 | + if (idx !== $routeParams.idx && | |
| 409 | + !cisterna.desactivado) { | |
| 410 | + totalCargado += cisterna.capacidad; | |
| 411 | + } | |
| 414 | 412 | }); |
| 415 | - }); | |
| 416 | - } | |
| 413 | + resolve(); | |
| 414 | + }); | |
| 415 | + }); | |
| 417 | 416 | } |
| 418 | - ]); | |
| 417 | + } | |
| 418 | + ]); |