Commit 565239b5f6fbec586494fd317eee1298b52f26e1
1 parent
8fa463e44a
Exists in
master
Agregar cisterna
Showing
3 changed files
with
463 additions
and
285 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); | |
| 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' | |
| 36 | 56 | } |
| 57 | + ] | |
| 58 | + }; | |
| 59 | + focaModalService.modal(parametrosModal).then( | |
| 60 | + function(transportista) { | |
| 61 | + elegirTransportista(transportista); | |
| 62 | + focaAbmVehiculoService.transportistaSeleccionado = transportista; | |
| 63 | + }, function() { | |
| 64 | + | |
| 37 | 65 | } |
| 38 | 66 | ); |
| 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 | - ] | |
| 58 | 67 | }; |
| 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 | |
| 76 | - }); | |
| 77 | - }); | |
| 78 | - buscar(transportista.COD); | |
| 79 | - } | |
| 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 | - } | |
| 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.now = new Date(); | |
| 101 | - $scope.focused = 1; | |
| 102 | - $scope.transportistaStamp = ''; | |
| 103 | - $scope.cisternas = []; | |
| 104 | - | |
| 105 | - $timeout(function() { | |
| 106 | - focaBotoneraLateralService.showSalir(false); | |
| 107 | - focaBotoneraLateralService.showPausar(true); | |
| 108 | - focaBotoneraLateralService.showCancelar(false); | |
| 109 | - focaBotoneraLateralService.showGuardar(true, $scope.guardar); | |
| 110 | - focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); | |
| 111 | - }); | |
| 112 | - | |
| 113 | - $timeout(function() {getLSVehiculo();}); | |
| 114 | - | |
| 115 | - if ($scope.nuevo) { | |
| 116 | - focaAbmVehiculoService | |
| 117 | - .getTransportistaPorId($routeParams.idTransportista) | |
| 118 | - .then(function(res) { | |
| 119 | - var codigo = ('00000' + res.data.COD).slice(-5); | |
| 120 | - $scope.vehiculo.idTransportista = res.data.COD; | |
| 121 | - $scope.vehiculo.transportista = res.data; | |
| 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() { | |
| 122 | 73 | $scope.$broadcast('addCabecera', { |
| 123 | 74 | label: 'Transportista:', |
| 124 | - valor: codigo + ' - ' + res.data.NOM | |
| 75 | + valor: codigo + ' - ' + transportista.NOM | |
| 125 | 76 | }); |
| 126 | 77 | }); |
| 78 | + buscar(transportista.COD); | |
| 79 | + } | |
| 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 | + } | |
| 127 | 92 | } |
| 128 | - $scope.vehiculo = {}; | |
| 129 | - focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | |
| 130 | - if (res.data) { | |
| 131 | - $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | |
| 132 | - $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | |
| 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 = []; | |
| 133 | 106 | |
| 134 | - $scope.vehiculo = res.data; | |
| 135 | - $scope.$broadcast('addCabecera', { | |
| 136 | - label: 'Transportista:', | |
| 137 | - valor: $scope.transportistaStamp | |
| 138 | - }); | |
| 139 | - $scope.$broadcast('addCabecera', { | |
| 140 | - label: 'Unidad:', | |
| 141 | - valor: res.data.codigo | |
| 142 | - }); | |
| 107 | + $scope.cisterna = { | |
| 108 | + codigo: '', | |
| 109 | + capacidad: '', | |
| 110 | + unidadMedida: {} | |
| 111 | + }; | |
| 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 | + }); | |
| 120 | + | |
| 121 | + if ($scope.nuevo) { | |
| 143 | 122 | focaAbmVehiculoService |
| 144 | - .getCisternas($routeParams.idVehiculo) | |
| 123 | + .getTransportistaPorId($routeParams.idTransportista) | |
| 145 | 124 | .then(function(res) { |
| 146 | - $scope.cisternas = res; | |
| 147 | - $scope.$apply(); | |
| 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 | + }); | |
| 148 | 132 | }); |
| 149 | 133 | } |
| 150 | - }); | |
| 134 | + $scope.vehiculo = {}; | |
| 151 | 135 | |
| 152 | - $scope.next = function(key) { | |
| 153 | - if (key === 13) $scope.focused++; | |
| 154 | - }; | |
| 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; | |
| 155 | 143 | |
| 156 | - $scope.salir = function() { | |
| 157 | - if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 158 | - focaModalService.confirm( | |
| 159 | - '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | |
| 160 | - ).then(function(data) { | |
| 161 | - if (data) { | |
| 162 | - $location.path('/vehiculo'); | |
| 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 | + }); | |
| 163 | 153 | } |
| 154 | + | |
| 155 | + focaAbmVehiculoService | |
| 156 | + .getCisternas($routeParams.idVehiculo) | |
| 157 | + .then(function(res) { | |
| 158 | + $scope.cisternas = res; | |
| 159 | + $scope.$apply(); | |
| 160 | + }); | |
| 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 | + } | |
| 176 | + }); | |
| 177 | + } else { | |
| 178 | + $location.path('/vehiculo'); | |
| 179 | + } | |
| 180 | + }; | |
| 181 | + | |
| 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 | + }; | |
| 191 | + | |
| 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; | |
| 164 | 204 | }); |
| 165 | - } else { | |
| 166 | - $location.path('/vehiculo'); | |
| 167 | - } | |
| 168 | - } | |
| 205 | + }; | |
| 169 | 206 | |
| 170 | - $scope.editar = function(key) { | |
| 171 | - if (key) { | |
| 172 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + | |
| 173 | - '/cisterna/' + key); | |
| 174 | - } else { | |
| 175 | - $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | |
| 176 | - } | |
| 177 | - }; | |
| 178 | - $scope.guardar = function(key) { | |
| 207 | + $scope.guardar = function(key) { | |
| 208 | + | |
| 209 | + key = (typeof key === 'undefined') ? 13 : key; | |
| 179 | 210 | |
| 180 | - key = (typeof key === 'undefined') ? 13 : key; | |
| 211 | + if (key === 13) { | |
| 181 | 212 | |
| 182 | - if (key === 13) { | |
| 213 | + if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 214 | + $scope.salir(); | |
| 215 | + return; | |
| 216 | + } | |
| 183 | 217 | |
| 184 | - if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { | |
| 185 | - $scope.salir(); | |
| 186 | - return; | |
| 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 | + }); | |
| 187 | 254 | } |
| 255 | + }; | |
| 188 | 256 | |
| 189 | - if (!$scope.vehiculo.codigo) { | |
| 190 | - focaModalService.alert('Ingrese unidad'); | |
| 191 | - return; | |
| 192 | - } else if (!$scope.vehiculo.tractor) { | |
| 193 | - focaModalService.alert('Ingrese dominio tractor'); | |
| 194 | - return; | |
| 195 | - } else if (!$scope.vehiculo.semi) { | |
| 196 | - focaModalService.alert('Ingrese dominio semi'); | |
| 197 | - return; | |
| 198 | - } else if (!$scope.vehiculo.capacidad) { | |
| 199 | - focaModalService.alert('Ingrese capacidad total'); | |
| 200 | - return; | |
| 201 | - } | |
| 202 | - //Valida si existe numero de unidad | |
| 203 | - if (!validaTotalCargas() && !$scope.nuevo) { | |
| 204 | - focaModalService.alert('La suma de las capacidades de las cisternas' + | |
| 205 | - ' debe ser igual a la capacidad total del vehículo'); | |
| 206 | - return; | |
| 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 | + } | |
| 269 | + }); | |
| 270 | + }, true); | |
| 271 | + | |
| 272 | + function getLSVehiculo() { | |
| 273 | + var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 274 | + if (vehiculo) { | |
| 275 | + setearVehiculo(vehiculo); | |
| 276 | + delete $localStorage.vehiculo; | |
| 277 | + return true; | |
| 207 | 278 | } |
| 208 | - validaCodigoUnidad().then(function() { | |
| 209 | - delete $scope.vehiculo.transportista; | |
| 210 | - delete $scope.vehiculo.cisternas; | |
| 211 | - focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | |
| 279 | + return false; | |
| 280 | + } | |
| 281 | + | |
| 282 | + function setearVehiculo(vehiculo) { | |
| 283 | + $scope.vehiculo = vehiculo; | |
| 284 | + $scope.$broadcast('addCabecera', { | |
| 285 | + label: 'Vehiculo:', | |
| 286 | + valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | |
| 287 | + }); | |
| 288 | + } | |
| 289 | + | |
| 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 | + }; | |
| 305 | + | |
| 306 | + function validaCodigoUnidad() { | |
| 307 | + return new Promise(function(resolve, reject) { | |
| 308 | + focaAbmVehiculoService | |
| 309 | + .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | |
| 212 | 310 | .then(function(res) { |
| 213 | - if ($scope.nuevo) { | |
| 214 | - $location.path('/vehiculo/' + res.data.id + | |
| 215 | - '/' + res.data.idTransportista); | |
| 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 | + }); | |
| 316 | + | |
| 317 | + if (existe.length) { | |
| 318 | + reject(existe); | |
| 216 | 319 | } else { |
| 217 | - guardarCisternas().then(function() { | |
| 218 | - $location.path('/vehiculo'); | |
| 219 | - }); | |
| 320 | + resolve(); | |
| 220 | 321 | } |
| 221 | 322 | }); |
| 222 | - }, function() { | |
| 223 | - focaModalService.alert('Código de unidad existente'); | |
| 224 | 323 | }); |
| 225 | 324 | } |
| 226 | 325 | |
| 227 | - }; | |
| 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 | + } | |
| 228 | 349 | |
| 229 | - $scope.$watch('vehiculo', function(newValue) { | |
| 230 | - focaBotoneraLateralService.setPausarData({ | |
| 231 | - label:'vehiculo', | |
| 232 | - val: { | |
| 233 | - codigo: newValue.codigo, | |
| 234 | - tractor: newValue.tractor, | |
| 235 | - semi: newValue.semi, | |
| 236 | - capacidad: newValue.capacidad, | |
| 237 | - idVehiculo: newValue.idVehiculo, | |
| 238 | - idTransportista: newValue.idTransportista | |
| 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; | |
| 239 | 360 | } |
| 240 | - }); | |
| 241 | - }, true); | |
| 361 | + $scope.editando = false; | |
| 362 | + validaCodigo() | |
| 363 | + .then(function() { | |
| 364 | + saveCisterna(); | |
| 365 | + }, function(err) { | |
| 366 | + focaModalService.alert(err); | |
| 367 | + }); | |
| 368 | + }; | |
| 242 | 369 | |
| 243 | - function getLSVehiculo() { | |
| 244 | - var vehiculo = JSON.parse($localStorage.vehiculo|| null); | |
| 245 | - if (vehiculo) { | |
| 246 | - setearVehiculo(vehiculo); | |
| 247 | - delete $localStorage.vehiculo; | |
| 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 | + }); | |
| 248 | 383 | } |
| 249 | - } | |
| 250 | - | |
| 251 | - function setearVehiculo(vehiculo) { | |
| 252 | - $scope.vehiculo = vehiculo; | |
| 253 | - $scope.$broadcast('addCabecera', { | |
| 254 | - label: 'Vehiculo:', | |
| 255 | - valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | |
| 256 | - }); | |
| 257 | - } | |
| 258 | 384 | |
| 259 | - $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | |
| 260 | - focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | |
| 261 | - cisterna.id + ' ' + cisterna.codigo + ' ?').then( | |
| 262 | - function(data) { | |
| 263 | - if (data) { | |
| 264 | - focaAbmVehiculoService.deleteCisterna(idx); | |
| 265 | - focaAbmVehiculoService | |
| 266 | - .getCisternas($routeParams.idVehiculo) | |
| 267 | - .then(function(res) { | |
| 268 | - $scope.cisternas = res; | |
| 269 | - }); | |
| 270 | - } | |
| 271 | - } | |
| 272 | - ); | |
| 273 | - }; | |
| 274 | - | |
| 275 | - function validaCodigoUnidad() { | |
| 276 | - return new Promise(function(resolve, reject) { | |
| 385 | + if ($routeParams.idx !== -1) { | |
| 386 | + $scope.cisterna = [$routeParams.idx]; | |
| 277 | 387 | focaAbmVehiculoService |
| 278 | - .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | |
| 388 | + .getCisternas($routeParams.idVehiculo) | |
| 279 | 389 | .then(function(res) { |
| 280 | - //Valida si existe numero de unidad | |
| 281 | - var existe = res.data.filter(function(vehiculo) { | |
| 282 | - return vehiculo.codigo === $scope.vehiculo.codigo && | |
| 283 | - vehiculo.id !== $scope.vehiculo.id; | |
| 284 | - }); | |
| 285 | - | |
| 286 | - if (existe.length) { | |
| 287 | - reject(existe); | |
| 288 | - } else { | |
| 289 | - resolve(); | |
| 290 | - } | |
| 390 | + $scope.cisterna = res[$routeParams.idx]; | |
| 291 | 391 | }); |
| 292 | - }); | |
| 293 | - } | |
| 294 | - | |
| 295 | - function validaTotalCargas() { | |
| 296 | - var total = 0; | |
| 297 | - $scope.cisternas.forEach(function(cisterna) { | |
| 298 | - if (!cisterna.desactivado) { | |
| 299 | - total += parseInt(cisterna.capacidad); | |
| 300 | - } | |
| 301 | - }); | |
| 302 | - return $scope.vehiculo.capacidad == total; | |
| 303 | - } | |
| 304 | - | |
| 305 | - function guardarCisternas() { | |
| 306 | - var cisternas = $scope.cisternas.map(function(cisterna) { | |
| 307 | - return { | |
| 308 | - id: cisterna.id, | |
| 309 | - capacidad: parseFloat(cisterna.capacidad), | |
| 310 | - codigo: cisterna.codigo, | |
| 311 | - idUnidadMedida: cisterna.idUnidadMedida, | |
| 312 | - idVehiculo: $routeParams.idVehiculo, | |
| 313 | - desactivado: cisterna.desactivado | |
| 314 | - }; | |
| 315 | - }); | |
| 392 | + } | |
| 316 | 393 | |
| 317 | - return focaAbmVehiculoService.guardarCisternas(cisternas); | |
| 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(); | |
| 414 | + }); | |
| 415 | + }); | |
| 416 | + } | |
| 318 | 417 | } |
| 319 | - | |
| 320 | - } | |
| 321 | - ]); | |
| 418 | + ]); |
src/js/controllerCisterna.js
| 1 | 1 | angular.module('focaAbmVehiculo') |
| 2 | 2 | .controller('focaAbmVehiculoCisternaController', [ |
| 3 | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', |
| 4 | - 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', | |
| 4 | + 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window','$localStorage', | |
| 5 | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, |
| 6 | - focaModalService, focaBotoneraLateralService, $timeout, $window) { | |
| 6 | + focaModalService, focaBotoneraLateralService, $timeout, $window, $localStorage) { | |
| 7 | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; |
| 8 | 8 | $scope.editar = false; |
| 9 | 9 | $scope.now = new Date(); |
| ... | ... | @@ -29,6 +29,8 @@ angular.module('focaAbmVehiculo') |
| 29 | 29 | focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); |
| 30 | 30 | }); |
| 31 | 31 | |
| 32 | + $timeout(function (){getLSCisterna();}); | |
| 33 | + | |
| 32 | 34 | if ($routeParams.idx !== -1) { |
| 33 | 35 | $scope.cisterna = [$routeParams.idx]; |
| 34 | 36 | focaAbmVehiculoService |
| ... | ... | @@ -122,6 +124,29 @@ angular.module('focaAbmVehiculo') |
| 122 | 124 | }); |
| 123 | 125 | }; |
| 124 | 126 | |
| 127 | + $scope.$watch('cisterna', function(newValue) { | |
| 128 | + focaBotoneraLateralService.setPausarData({ | |
| 129 | + label:'cisterna', | |
| 130 | + val: newValue | |
| 131 | + }); | |
| 132 | + }, true); | |
| 133 | + | |
| 134 | + function getLSCisterna() { | |
| 135 | + var cisterna = JSON.parse($localStorage.cisterna|| null); | |
| 136 | + if (cisterna) { | |
| 137 | + setearVehiculo(cisterna); | |
| 138 | + delete $localStorage.cisterna; | |
| 139 | + } | |
| 140 | + } | |
| 141 | + | |
| 142 | + function setearVehiculo(cisterna) { | |
| 143 | + $scope.cisterna = cisterna; | |
| 144 | + $scope.$broadcast('addCabecera', { | |
| 145 | + label: 'Codigo de Cisterna:', | |
| 146 | + valor: cisterna.codigo | |
| 147 | + }); | |
| 148 | + } | |
| 149 | + | |
| 125 | 150 | function validaCodigo() { |
| 126 | 151 | return new Promise(function(resolve, reject) { |
| 127 | 152 | focaAbmVehiculoService |
src/views/foca-abm-vehiculos-item.html
| ... | ... | @@ -77,28 +77,84 @@ |
| 77 | 77 | <table class="table table-default table-hover table-sm table-abm table-striped mb-0"> |
| 78 | 78 | <thead> |
| 79 | 79 | <tr> |
| 80 | - <th class="px-5">Código</th> | |
| 81 | - <th class="text-right px-5">Capacidad</th> | |
| 82 | - <th class="text-center px-4"> | |
| 80 | + <th class="text-center px-4">Código</th> | |
| 81 | + <th class="text-center">Capacidad</th> | |
| 82 | + <th class="text-center">Unidad de Medida</th> | |
| 83 | + <th class="text-center"> | |
| 83 | 84 | <button |
| 84 | 85 | class="btn btn-outline-debo boton-accion" |
| 85 | 86 | title="Agregar" |
| 86 | - ng-click="editar(-1)"> | |
| 87 | + ng-click="editar('nuevo')"> | |
| 87 | 88 | <i class="fa fa-plus"></i> |
| 88 | 89 | </button> |
| 89 | 90 | </th> |
| 90 | 91 | </tr> |
| 91 | 92 | </thead> |
| 92 | 93 | <tbody> |
| 94 | + <tr ng-show="editando"> | |
| 95 | + <td align="center"> | |
| 96 | + <input | |
| 97 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 98 | + ng-model="cisterna.codigo" | |
| 99 | + ng-keypress="next($event.keyCode)" | |
| 100 | + foca-focus="focused == 1" | |
| 101 | + ng-focus="focused = 1" | |
| 102 | + ng-disabled="!nuevoCisterna" | |
| 103 | + teclado-virtual | |
| 104 | + > | |
| 105 | + </td> | |
| 106 | + <td align="center"> | |
| 107 | + <input | |
| 108 | + class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" | |
| 109 | + teclado-virtual | |
| 110 | + foca-tipo-input | |
| 111 | + ng-model="cisterna.capacidad" | |
| 112 | + ng-required="true" | |
| 113 | + ng-keypress="next($event.keyCode)" | |
| 114 | + foca-focus="focused == 2" | |
| 115 | + ng-focus="focused = 2" | |
| 116 | + > | |
| 117 | + </td> | |
| 118 | + <td align="center"> | |
| 119 | + <div class="input-group"> | |
| 120 | + <input | |
| 121 | + ng-model="cisterna.unidadMedida.NOM" | |
| 122 | + class="form-control" | |
| 123 | + readonly | |
| 124 | + /> | |
| 125 | + <div class="input-group-append"> | |
| 126 | + <button | |
| 127 | + ladda="searchLoading" | |
| 128 | + class="btn btn-outline-secondary form-control" | |
| 129 | + type="button" | |
| 130 | + ng-click="seleccionarUnidadMedida()" | |
| 131 | + foca-focus="focused == 3" | |
| 132 | + > | |
| 133 | + <i class="fa fa-search" aria-hidden="true"></i> | |
| 134 | + </button> | |
| 135 | + </div> | |
| 136 | + </div> | |
| 137 | + </td> | |
| 138 | + <td align="center"> | |
| 139 | + <button | |
| 140 | + class="btn btn-outline-dark boton-accion" | |
| 141 | + ng-click="guardarCisterna()" | |
| 142 | + > | |
| 143 | + <i class="fa fa-save"></i> | |
| 144 | + </button> | |
| 145 | + </td> | |
| 146 | + </tr> | |
| 147 | + | |
| 93 | 148 | <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" |
| 94 | 149 | ng-show="!cisterna.desactivado"> |
| 95 | - <td ng-bind="cisterna.codigo" class="px-5"></td> | |
| 96 | - <td ng-bind="cisterna.capacidad + ' ' + cisterna.unidadMedida.NOM" class="text-right px-5"></td> | |
| 97 | - <td class="text-center px-4"> | |
| 150 | + <td ng-bind="cisterna.codigo" class="text-center"></td> | |
| 151 | + <td ng-bind="cisterna.capacidad" class="text-center"></td> | |
| 152 | + <td ng-bind="cisterna.unidadMedida.NOM" class="text-center"></td> | |
| 153 | + <td class="text-center"> | |
| 98 | 154 | <button |
| 99 | 155 | class="btn btn-outline-dark boton-accion" |
| 100 | 156 | title="Editar" |
| 101 | - ng-click="editar(key)" | |
| 157 | + ng-click="editar('',cisterna)" | |
| 102 | 158 | > |
| 103 | 159 | <i class="fa fa-pencil"></i> |
| 104 | 160 | </button> |