Commit e7825aeda7d5c250f6b13d7f436efb8767ab996b
Exists in
master
Merge branch 'master' into 'develop'
Master(efernandez) See merge request !37
Showing
3 changed files
 
Show diff stats
.jshintrc
| 1 | { | 1 | { | 
| 2 | /* | 2 | /* | 
| 3 | * ENVIRONMENTS | 3 | * ENVIRONMENTS | 
| 4 | * ================= | 4 | * ================= | 
| 5 | */ | 5 | */ | 
| 6 | 6 | ||
| 7 | // Define globals exposed by modern browsers. | 7 | // Define globals exposed by modern browsers. | 
| 8 | "browser": true, | 8 | "browser": true, | 
| 9 | 9 | ||
| 10 | // Define globals exposed by jQuery. | 10 | // Define globals exposed by jQuery. | 
| 11 | "jquery": true, | 11 | "jquery": true, | 
| 12 | 12 | ||
| 13 | // Define globals exposed by Node.js. | 13 | // Define globals exposed by Node.js. | 
| 14 | "node": true, | 14 | "node": true, | 
| 15 | 15 | ||
| 16 | // Allow ES6. | 16 | // Allow ES6. | 
| 17 | "esversion": 6, | 17 | "esversion": 6, | 
| 18 | 18 | ||
| 19 | /* | 19 | /* | 
| 20 | * ENFORCING OPTIONS | 20 | * ENFORCING OPTIONS | 
| 21 | * ================= | 21 | * ================= | 
| 22 | */ | 22 | */ | 
| 23 | 23 | ||
| 24 | // Force all variable names to use either camelCase style or UPPER_CASE | 24 | // Force all variable names to use either camelCase style or UPPER_CASE | 
| 25 | // with underscores. | 25 | // with underscores. | 
| 26 | "camelcase": true, | 26 | "camelcase": true, | 
| 27 | 27 | ||
| 28 | // Prohibit use of == and != in favor of === and !==. | 28 | // Prohibit use of == and != in favor of === and !==. | 
| 29 | "eqeqeq": true, | 29 | "eqeqeq": true, | 
| 30 | 30 | ||
| 31 | // Enforce tab width of 2 spaces. | 31 | // Enforce tab width of 2 spaces. | 
| 32 | "indent": 4, | 32 | "indent": 4, | 
| 33 | 33 | ||
| 34 | // Prohibit use of a variable before it is defined. | 34 | // Prohibit use of a variable before it is defined. | 
| 35 | "latedef": false, | 35 | "latedef": false, | 
| 36 | 36 | ||
| 37 | // Enforce line length to 100 characters | 37 | // Enforce line length to 100 characters | 
| 38 | "maxlen": 100, | 38 | "maxlen": 100, | 
| 39 | 39 | ||
| 40 | // Require capitalized names for constructor functions. | 40 | // Require capitalized names for constructor functions. | 
| 41 | "newcap": true, | 41 | "newcap": true, | 
| 42 | 42 | ||
| 43 | // Enforce use of single quotation marks for strings. | 43 | // Enforce use of single quotation marks for strings. | 
| 44 | "quotmark": "single", | 44 | "quotmark": "single", | 
| 45 | 45 | ||
| 46 | // Enforce placing 'use strict' at the top function scope | 46 | // Enforce placing 'use strict' at the top function scope | 
| 47 | "strict": false, | 47 | "strict": false, | 
| 48 | 48 | ||
| 49 | // Prohibit use of explicitly undeclared variables. | 49 | // Prohibit use of explicitly undeclared variables. | 
| 50 | "undef": true, | 50 | "undef": false, | 
| 51 | 51 | ||
| 52 | // Warn when variables are defined but never used. | 52 | // Warn when variables are defined but never used. | 
| 53 | "unused": true, | 53 | "unused": false, | 
| 54 | 54 | ||
| 55 | // Para que funcione en angular | 55 | // Para que funcione en angular | 
| 56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | 56 | "predef": ["angular", "alert", "spyOn", "expect", "it", "inject", "beforeEach", "describe"], | 
| 57 | /* | 57 | /* | 
| 58 | * RELAXING OPTIONS | 58 | * RELAXING OPTIONS | 
| 59 | * ================= | 59 | * ================= | 
| 60 | */ | 60 | */ | 
| 61 | 61 | ||
| 62 | // Suppress warnings about == null comparisons. | 62 | // Suppress warnings about == null comparisons. | 
| 63 | "eqnull": true | 63 | "eqnull": true | 
| 64 | } | 64 | } | 
| 65 | 65 | 
src/js/controller.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') | 
| 2 | .controller('focaAbmVehiculosController', [ | 2 | .controller('focaAbmVehiculosController', [ | 
| 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 3 | '$scope', 'focaAbmVehiculoService', '$location', 'focaModalService', | 
| 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | 4 | '$uibModal', 'focaBotoneraLateralService', '$timeout', '$localStorage', | 
| 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 5 | function($scope, focaAbmVehiculoService, $location, focaModalService, | 
| 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 6 | $uibModal, focaBotoneraLateralService, $timeout, $localStorage) { | 
| 7 | 7 | ||
| 8 | $scope.now = new Date(); | 8 | $scope.now = new Date(); | 
| 9 | $scope.botonera = [{ | 9 | $scope.botonera = [{ | 
| 10 | label: 'Transportista', | 10 | label: 'Transportista', | 
| 11 | image: 'cliente.png' | 11 | image: 'cliente.png' | 
| 12 | }]; | 12 | }]; | 
| 13 | 13 | ||
| 14 | focaAbmVehiculoService.cleanCisternas(); | 14 | focaAbmVehiculoService.cleanCisternas(); | 
| 15 | 15 | ||
| 16 | //SETEO BOTONERA LATERAL | 16 | //SETEO BOTONERA LATERAL | 
| 17 | focaBotoneraLateralService.showSalir(false); | 17 | focaBotoneraLateralService.showSalir(false); | 
| 18 | focaBotoneraLateralService.showPausar(false); | 18 | focaBotoneraLateralService.showPausar(false); | 
| 19 | focaBotoneraLateralService.showCancelar(false); | 19 | focaBotoneraLateralService.showCancelar(false); | 
| 20 | focaBotoneraLateralService.showGuardar(false); | 20 | focaBotoneraLateralService.showGuardar(false); | 
| 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 21 | focaBotoneraLateralService.addCustomButton('Salir', salir); | 
| 22 | 22 | ||
| 23 | if ($localStorage.vehiculo) { | ||
| 24 | var vehiculo = JSON.parse($localStorage.vehiculo); | ||
| 25 | if (!vehiculo.idVehiculo) vehiculo.idVehiculo = 0; | ||
| 26 | $location.path('/vehiculo/' + vehiculo.idVehiculo + '/' + vehiculo.idTransportista); | ||
| 27 | } | ||
| 28 | |||
| 29 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 23 | if (focaAbmVehiculoService.transportistaSeleccionado.COD) { | 
| 30 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 24 | elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); | 
| 31 | } | 25 | } | 
| 32 | $scope.editar = function(id) { | 26 | $scope.editar = function(id) { | 
| 33 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 27 | $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); | 
| 34 | }; | 28 | }; | 
| 35 | $scope.solicitarConfirmacion = function(vehiculo) { | 29 | $scope.solicitarConfirmacion = function(vehiculo) { | 
| 36 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 30 | focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + | 
| 37 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 31 | vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( | 
| 38 | function(data) { | 32 | function(data) { | 
| 39 | if (data) { | 33 | if (data) { | 
| 40 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 34 | focaAbmVehiculoService.deleteVehiculo(vehiculo.id); | 
| 41 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 35 | $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); | 
| 42 | } | 36 | } | 
| 43 | } | 37 | } | 
| 44 | ); | 38 | ); | 
| 45 | }; | 39 | }; | 
| 46 | $scope.seleccionarTransportista = function() { | 40 | $scope.seleccionarTransportista = function() { | 
| 47 | var parametrosModal = { | 41 | var parametrosModal = { | 
| 48 | titulo: 'Búsqueda de Transportista', | 42 | titulo: 'Búsqueda de Transportista', | 
| 49 | query: '/transportista', | 43 | query: '/transportista', | 
| 50 | columnas: [ | 44 | columnas: [ | 
| 51 | { | 45 | { | 
| 52 | nombre: 'Código', | 46 | nombre: 'Código', | 
| 53 | propiedad: 'COD' | 47 | propiedad: 'COD' | 
| 54 | }, | 48 | }, | 
| 55 | { | 49 | { | 
| 56 | nombre: 'Nombre', | 50 | nombre: 'Nombre', | 
| 57 | propiedad: 'NOM' | 51 | propiedad: 'NOM' | 
| 58 | }, | 52 | }, | 
| 59 | { | 53 | { | 
| 60 | nombre: 'CUIT', | 54 | nombre: 'CUIT', | 
| 61 | propiedad: 'CUIT' | 55 | propiedad: 'CUIT' | 
| 62 | } | 56 | } | 
| 63 | ] | 57 | ] | 
| 64 | }; | 58 | }; | 
| 65 | focaModalService.modal(parametrosModal).then( | 59 | focaModalService.modal(parametrosModal).then( | 
| 66 | function(transportista) { | 60 | function(transportista) { | 
| 67 | elegirTransportista(transportista); | 61 | elegirTransportista(transportista); | 
| 68 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 62 | focaAbmVehiculoService.transportistaSeleccionado = transportista; | 
| 69 | }, function() { | 63 | }, function() { | 
| 70 | 64 | ||
| 71 | } | 65 | } | 
| 72 | ); | 66 | ); | 
| 73 | }; | 67 | }; | 
| 74 | function elegirTransportista(transportista) { | 68 | function elegirTransportista(transportista) { | 
| 75 | var codigo = ('00000' + transportista.COD).slice(-5); | 69 | var codigo = ('00000' + transportista.COD).slice(-5); | 
| 76 | $scope.idTransportista = transportista.COD; | 70 | $scope.idTransportista = transportista.COD; | 
| 77 | $scope.filtros = transportista.NOM.trim(); | 71 | $scope.filtros = transportista.NOM.trim(); | 
| 78 | $timeout(function() { | 72 | $timeout(function() { | 
| 79 | $scope.$broadcast('addCabecera', { | 73 | $scope.$broadcast('addCabecera', { | 
| 80 | label: 'Transportista:', | 74 | label: 'Transportista:', | 
| 81 | valor: codigo + ' - ' + transportista.NOM | 75 | valor: codigo + ' - ' + transportista.NOM | 
| 82 | }); | 76 | }); | 
| 83 | }); | 77 | }); | 
| 84 | buscar(transportista.COD); | 78 | buscar(transportista.COD); | 
| 85 | } | 79 | } | 
| 86 | 80 | ||
| 87 | function buscar(idTransportista) { | 81 | function buscar(idTransportista) { | 
| 88 | focaAbmVehiculoService | 82 | focaAbmVehiculoService | 
| 89 | .getVehiculosPorTransportista(idTransportista) | 83 | .getVehiculosPorTransportista(idTransportista) | 
| 90 | .then(function(datos) { | 84 | .then(function(datos) { | 
| 91 | $scope.vehiculos = datos.data; | 85 | $scope.vehiculos = datos.data; | 
| 92 | }); | 86 | }); | 
| 93 | } | 87 | } | 
| 94 | function salir() { | 88 | function salir() { | 
| 95 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 89 | focaAbmVehiculoService.transportistaSeleccionado = {}; | 
| 96 | $location.path('/'); | 90 | $location.path('/'); | 
| 97 | } | 91 | } | 
| 98 | } | 92 | } | 
| 99 | ]) | 93 | ]) | 
| 100 | .controller('focaAbmVehiculoController', [ | 94 | .controller('focaAbmVehiculoController', [ | 
| 101 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 95 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 
| 102 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$window', '$localStorage', '$filter', | 96 | 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', | 
| 103 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 97 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 
| 104 | focaModalService, $timeout, focaBotoneraLateralService, $window, $localStorage, $filter) { | 98 | focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { | 
| 105 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 99 | $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; | 
| 106 | $scope.now = new Date(); | 100 | $scope.now = new Date(); | 
| 107 | $scope.focused = 1; | 101 | $scope.focused = 1; | 
| 108 | $scope.transportistaStamp = ''; | 102 | $scope.transportistaStamp = ''; | 
| 109 | $scope.cisternas = []; | 103 | $scope.cisternas = []; | 
| 110 | 104 | ||
| 111 | $timeout(function() { | 105 | $timeout(function() { | 
| 112 | focaBotoneraLateralService.showSalir(false); | 106 | focaBotoneraLateralService.showSalir(false); | 
| 113 | focaBotoneraLateralService.showPausar(true); | 107 | focaBotoneraLateralService.showPausar(true); | 
| 114 | focaBotoneraLateralService.showCancelar(false); | 108 | focaBotoneraLateralService.showCancelar(false); | 
| 115 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 109 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 
| 116 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | 110 | focaBotoneraLateralService.addCustomButton('Cancelar', cancelar); | 
| 117 | }); | 111 | }); | 
| 118 | 112 | ||
| 119 | $timeout(function() {getLSVehiculo();}); | 113 | $timeout(function() {getLSVehiculo();}); | 
| 120 | 114 | ||
| 121 | if ($scope.nuevo) { | 115 | if ($scope.nuevo) { | 
| 122 | focaAbmVehiculoService | 116 | focaAbmVehiculoService | 
| 123 | .getTransportistaPorId($routeParams.idTransportista) | 117 | .getTransportistaPorId($routeParams.idTransportista) | 
| 124 | .then(function(res) { | 118 | .then(function(res) { | 
| 125 | var codigo = ('00000' + res.data.COD).slice(-5); | 119 | var codigo = ('00000' + res.data.COD).slice(-5); | 
| 126 | $scope.vehiculo.idTransportista = res.data.COD; | 120 | $scope.vehiculo.idTransportista = res.data.COD; | 
| 127 | $scope.vehiculo.transportista = res.data; | 121 | $scope.vehiculo.transportista = res.data; | 
| 128 | $scope.$broadcast('addCabecera', { | 122 | $scope.$broadcast('addCabecera', { | 
| 129 | label: 'Transportista:', | 123 | label: 'Transportista:', | 
| 130 | valor: codigo + ' - ' + res.data.NOM | 124 | valor: codigo + ' - ' + res.data.NOM | 
| 131 | }); | 125 | }); | 
| 132 | }); | 126 | }); | 
| 133 | } | 127 | } | 
| 134 | $scope.vehiculo = {}; | 128 | $scope.vehiculo = {}; | 
| 135 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 129 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 
| 136 | if (res.data) { | 130 | if (res.data) { | 
| 137 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 131 | $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); | 
| 138 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 132 | $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; | 
| 139 | 133 | ||
| 140 | $scope.vehiculo = res.data; | 134 | $scope.vehiculo = res.data; | 
| 141 | $scope.$broadcast('addCabecera', { | 135 | $scope.$broadcast('addCabecera', { | 
| 142 | label: 'Transportista:', | 136 | label: 'Transportista:', | 
| 143 | valor: $scope.transportistaStamp | 137 | valor: $scope.transportistaStamp | 
| 144 | }); | 138 | }); | 
| 145 | $scope.$broadcast('addCabecera', { | 139 | $scope.$broadcast('addCabecera', { | 
| 146 | label: 'Unidad:', | 140 | label: 'Unidad:', | 
| 147 | valor: res.data.codigo | 141 | valor: res.data.codigo | 
| 148 | }); | 142 | }); | 
| 149 | focaAbmVehiculoService | 143 | focaAbmVehiculoService | 
| 150 | .getCisternas($routeParams.idVehiculo) | 144 | .getCisternas($routeParams.idVehiculo) | 
| 151 | .then(function(res) { | 145 | .then(function(res) { | 
| 152 | $scope.cisternas = res; | 146 | $scope.cisternas = res; | 
| 153 | $scope.$apply(); | 147 | $scope.$apply(); | 
| 154 | }); | 148 | }); | 
| 155 | } | 149 | } | 
| 156 | }); | 150 | }); | 
| 157 | 151 | ||
| 158 | $scope.next = function(key) { | 152 | $scope.next = function(key) { | 
| 159 | if (key === 13) $scope.focused++; | 153 | if (key === 13) $scope.focused++; | 
| 160 | }; | 154 | }; | 
| 161 | 155 | ||
| 162 | function cancelar() { | 156 | function cancelar() { | 
| 163 | if ($scope.formVehiculo.$pristine == false) { | 157 | if (!$scope.formVehiculo.$pristine) { | 
| 164 | focaModalService.confirm( | 158 | focaModalService.confirm( | 
| 165 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 159 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 
| 166 | ).then(function(data) { | 160 | ).then(function(data) { | 
| 167 | if (data) { | 161 | if (data) { | 
| 168 | $location.path('/vehiculo'); | 162 | $location.path('/vehiculo'); | 
| 169 | } | 163 | } | 
| 170 | }); | 164 | }); | 
| 171 | } else { | 165 | } else { | 
| 172 | $location.path('/vehiculo'); | 166 | $location.path('/vehiculo'); | 
| 173 | } | 167 | } | 
| 174 | } | 168 | } | 
| 175 | 169 | ||
| 176 | $scope.editar = function(key) { | 170 | $scope.editar = function(key) { | 
| 177 | if (key) { | 171 | if (key) { | 
| 178 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 172 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 
| 179 | '/cisterna/' + key); | 173 | '/cisterna/' + key); | 
| 180 | } else { | 174 | } else { | 
| 181 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 175 | $location.path('/vehiculo/' + $routeParams.idVehiculo + '/cisterna/0/'); | 
| 182 | } | 176 | } | 
| 183 | }; | 177 | }; | 
| 184 | $scope.guardar = function(key) { | 178 | $scope.guardar = function(key) { | 
| 185 | 179 | ||
| 186 | key = (typeof key === 'undefined') ? 13 : key; | 180 | key = (typeof key === 'undefined') ? 13 : key; | 
| 187 | 181 | ||
| 188 | if (key === 13) { | 182 | if (key === 13) { | 
| 183 | |||
| 184 | if ($scope.formVehiculo.$pristine) { | ||
| 185 | $scope.cancelar(); | ||
| 186 | return; | ||
| 187 | } | ||
| 188 | |||
| 189 | if (!$scope.vehiculo.codigo) { | 189 | if (!$scope.vehiculo.codigo) { | 
| 190 | focaModalService.alert('Ingrese unidad'); | 190 | focaModalService.alert('Ingrese unidad'); | 
| 191 | return; | 191 | return; | 
| 192 | } else if (!$scope.vehiculo.tractor) { | 192 | } else if (!$scope.vehiculo.tractor) { | 
| 193 | focaModalService.alert('Ingrese dominio tractor'); | 193 | focaModalService.alert('Ingrese dominio tractor'); | 
| 194 | return; | 194 | return; | 
| 195 | } else if (!$scope.vehiculo.semi) { | 195 | } else if (!$scope.vehiculo.semi) { | 
| 196 | focaModalService.alert('Ingrese dominio semi'); | 196 | focaModalService.alert('Ingrese dominio semi'); | 
| 197 | return; | 197 | return; | 
| 198 | } else if (!$scope.vehiculo.capacidad) { | 198 | } else if (!$scope.vehiculo.capacidad) { | 
| 199 | focaModalService.alert('Ingrese capacidad total'); | 199 | focaModalService.alert('Ingrese capacidad total'); | 
| 200 | return; | 200 | return; | 
| 201 | } | 201 | } | 
| 202 | //Valida si existe numero de unidad | 202 | //Valida si existe numero de unidad | 
| 203 | if (!validaTotalCargas() && !$scope.nuevo) { | 203 | if (!validaTotalCargas() && !$scope.nuevo) { | 
| 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 204 | focaModalService.alert('La suma de las capacidades de las cisternas' + | 
| 205 | ' debe ser igual a la capacidad total del vehículo'); | 205 | ' debe ser igual a la capacidad total del vehículo'); | 
| 206 | return; | 206 | return; | 
| 207 | } | 207 | } | 
| 208 | validaCodigoUnidad().then(function() { | 208 | validaCodigoUnidad().then(function() { | 
| 209 | delete $scope.vehiculo.transportista; | 209 | delete $scope.vehiculo.transportista; | 
| 210 | delete $scope.vehiculo.cisternas; | 210 | delete $scope.vehiculo.cisternas; | 
| 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 211 | focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) | 
| 212 | .then(function(res) { | 212 | .then(function(res) { | 
| 213 | if ($scope.nuevo) { | 213 | if ($scope.nuevo) { | 
| 214 | $location.path('/vehiculo/' + res.data.id + | 214 | $location.path('/vehiculo/' + res.data.id + | 
| 215 | '/' + res.data.idTransportista); | 215 | '/' + res.data.idTransportista); | 
| 216 | } else { | 216 | } else { | 
| 217 | guardarCisternas().then(function() { | 217 | guardarCisternas().then(function() { | 
| 218 | $location.path('/vehiculo'); | 218 | $location.path('/vehiculo'); | 
| 219 | }); | 219 | }); | 
| 220 | } | 220 | } | 
| 221 | }); | 221 | }); | 
| 222 | }, function() { | 222 | }, function() { | 
| 223 | focaModalService.alert('Código de unidad existente'); | 223 | focaModalService.alert('Código de unidad existente'); | 
| 224 | }); | 224 | }); | 
| 225 | } | 225 | } | 
| 226 | 226 | ||
| 227 | }; | 227 | }; | 
| 228 | 228 | ||
| 229 | $scope.$watch('vehiculo', function(newValue) { | 229 | $scope.$watch('vehiculo', function(newValue) { | 
| 230 | focaBotoneraLateralService.setPausarData({ | 230 | focaBotoneraLateralService.setPausarData({ | 
| 231 | label:'vehiculo', | 231 | label:'vehiculo', | 
| 232 | val: { | 232 | val: { | 
| 233 | codigo: newValue.codigo, | 233 | codigo: newValue.codigo, | 
| 234 | tractor: newValue.tractor, | 234 | tractor: newValue.tractor, | 
| 235 | semi: newValue.semi, | 235 | semi: newValue.semi, | 
| 236 | capacidad: newValue.capacidad, | 236 | capacidad: newValue.capacidad, | 
| 237 | idVehiculo: newValue.idVehiculo, | 237 | idVehiculo: newValue.idVehiculo, | 
| 238 | idTransportista: newValue.idTransportista | 238 | idTransportista: newValue.idTransportista | 
| 239 | } | 239 | } | 
| 240 | }); | 240 | }); | 
| 241 | }, true); | 241 | }, true); | 
| 242 | 242 | ||
| 243 | function getLSVehiculo() { | 243 | function getLSVehiculo() { | 
| 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | 244 | var vehiculo = JSON.parse($localStorage.vehiculo|| null); | 
| 245 | if (vehiculo) { | 245 | if (vehiculo) { | 
| 246 | setearVehiculo(vehiculo); | 246 | setearVehiculo(vehiculo); | 
| 247 | delete $localStorage.vehiculo; | 247 | delete $localStorage.vehiculo; | 
| 248 | } | 248 | } | 
| 249 | } | 249 | } | 
| 250 | 250 | ||
| 251 | function setearVehiculo(vehiculo) { | 251 | function setearVehiculo(vehiculo) { | 
| 252 | $scope.vehiculo = vehiculo; | 252 | $scope.vehiculo = vehiculo; | 
| 253 | $scope.$broadcast('addCabecera', { | 253 | $scope.$broadcast('addCabecera', { | 
| 254 | label: 'Vehiculo:', | 254 | label: 'Vehiculo:', | 
| 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | 255 | valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' | 
| 256 | }); | 256 | }); | 
| 257 | } | 257 | } | 
| 258 | 258 | ||
| 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 259 | $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { | 
| 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 260 | focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + | 
| 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 261 | cisterna.id + ' ' + cisterna.codigo + ' ?').then( | 
| 262 | function(data) { | 262 | function(data) { | 
| 263 | if (data) { | 263 | if (data) { | 
| 264 | focaAbmVehiculoService.deleteCisterna(idx); | 264 | focaAbmVehiculoService.deleteCisterna(idx); | 
| 265 | focaAbmVehiculoService | 265 | focaAbmVehiculoService | 
| 266 | .getCisternas($routeParams.idVehiculo) | 266 | .getCisternas($routeParams.idVehiculo) | 
| 267 | .then(function(res) { | 267 | .then(function(res) { | 
| 268 | $scope.cisternas = res; | 268 | $scope.cisternas = res; | 
| 269 | }); | 269 | }); | 
| 270 | } | 270 | } | 
| 271 | } | 271 | } | 
| 272 | ); | 272 | ); | 
| 273 | }; | 273 | }; | 
| 274 | 274 | ||
| 275 | function validaCodigoUnidad() { | 275 | function validaCodigoUnidad() { | 
| 276 | return new Promise(function(resolve, reject) { | 276 | return new Promise(function(resolve, reject) { | 
| 277 | focaAbmVehiculoService | 277 | focaAbmVehiculoService | 
| 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 278 | .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) | 
| 279 | .then(function(res) { | 279 | .then(function(res) { | 
| 280 | //Valida si existe numero de unidad | 280 | //Valida si existe numero de unidad | 
| 281 | var existe = res.data.filter(function(vehiculo) { | 281 | var existe = res.data.filter(function(vehiculo) { | 
| 282 | return vehiculo.codigo === $scope.vehiculo.codigo && | 282 | return vehiculo.codigo === $scope.vehiculo.codigo && | 
| 283 | vehiculo.id !== $scope.vehiculo.id; | 283 | vehiculo.id !== $scope.vehiculo.id; | 
| 284 | }); | 284 | }); | 
| 285 | 285 | ||
| 286 | if (existe.length) { | 286 | if (existe.length) { | 
| 287 | reject(existe); | 287 | reject(existe); | 
| 288 | } else { | 288 | } else { | 
| 289 | resolve(); | 289 | resolve(); | 
| 290 | } | 290 | } | 
| 291 | }); | 291 | }); | 
| 292 | }); | 292 | }); | 
| 293 | } | 293 | } | 
| 294 | 294 | ||
| 295 | function validaTotalCargas() { | 295 | function validaTotalCargas() { | 
| 296 | var total = 0; | 296 | var total = 0; | 
| 297 | $scope.cisternas.forEach(function(cisterna) { | 297 | $scope.cisternas.forEach(function(cisterna) { | 
| 298 | if (!cisterna.desactivado) { | 298 | if (!cisterna.desactivado) { | 
| 299 | total += parseInt(cisterna.capacidad); | 299 | total += parseInt(cisterna.capacidad); | 
| 300 | } | 300 | } | 
| 301 | }); | 301 | }); | 
| 302 | return $scope.vehiculo.capacidad == total; | 302 | return $scope.vehiculo.capacidad === total; | 
| 303 | } | 303 | } | 
| 304 | 304 | ||
| 305 | function guardarCisternas() { | 305 | function guardarCisternas() { | 
| 306 | var cisternas = $scope.cisternas.map(function(cisterna) { | 306 | var cisternas = $scope.cisternas.map(function(cisterna) { | 
| 307 | return { | 307 | return { | 
| 308 | id: cisterna.id, | 308 | id: cisterna.id, | 
| 309 | capacidad: parseFloat(cisterna.capacidad), | 309 | capacidad: parseFloat(cisterna.capacidad), | 
| 310 | codigo: cisterna.codigo, | 310 | codigo: cisterna.codigo, | 
| 311 | idUnidadMedida: cisterna.idUnidadMedida, | 311 | idUnidadMedida: cisterna.idUnidadMedida, | 
| 312 | idVehiculo: $routeParams.idVehiculo, | 312 | idVehiculo: $routeParams.idVehiculo, | 
| 313 | desactivado: cisterna.desactivado | 313 | desactivado: cisterna.desactivado | 
| 314 | }; | 314 | }; | 
| 315 | }); | 315 | }); | 
src/js/controllerCisterna.js
| 1 | angular.module('focaAbmVehiculo') | 1 | angular.module('focaAbmVehiculo') | 
| 2 | .controller('focaAbmVehiculoCisternaController', [ | 2 | .controller('focaAbmVehiculoCisternaController', [ | 
| 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 3 | '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', | 
| 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | 4 | 'focaModalService', 'focaBotoneraLateralService', '$timeout','$localStorage', '$filter', | 
| 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 5 | function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, | 
| 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 6 | focaModalService, focaBotoneraLateralService, $timeout, $localStorage, $filter) { | 
| 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 7 | $scope.nuevo = ($routeParams.idx > -1) ? false : true; | 
| 8 | $scope.editar = false; | 8 | $scope.editar = false; | 
| 9 | $scope.now = new Date(); | 9 | $scope.now = new Date(); | 
| 10 | $scope.cisterna = { | 10 | $scope.cisterna = { | 
| 11 | codigo: '', | 11 | codigo: '', | 
| 12 | capacidad: '', | 12 | capacidad: '', | 
| 13 | unidadMedida: {} | 13 | unidadMedida: {} | 
| 14 | }; | 14 | }; | 
| 15 | 15 | ||
| 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 16 | $scope.focused = $scope.nuevo ? 1 : 2; | 
| 17 | $scope.next = function(key) { | 17 | $scope.next = function(key) { | 
| 18 | if (key === 13) $scope.focused++; | 18 | if (key === 13) $scope.focused++; | 
| 19 | }; | 19 | }; | 
| 20 | $scope.capacidadVechiulo = 0; | 20 | $scope.capacidadVechiulo = 0; | 
| 21 | $scope.transportista = ''; | 21 | $scope.transportista = ''; | 
| 22 | 22 | ||
| 23 | //SETEO BOTONERA LATERAL | 23 | //SETEO BOTONERA LATERAL | 
| 24 | $timeout(function() { | 24 | $timeout(function() { | 
| 25 | focaBotoneraLateralService.showSalir(false); | 25 | focaBotoneraLateralService.showSalir(false); | 
| 26 | focaBotoneraLateralService.showPausar(true); | 26 | focaBotoneraLateralService.showPausar(true); | 
| 27 | focaBotoneraLateralService.showCancelar(false); | 27 | focaBotoneraLateralService.showCancelar(false); | 
| 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 28 | focaBotoneraLateralService.showGuardar(true, $scope.guardar); | 
| 29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | 29 | focaBotoneraLateralService.addCustomButton('Cancelar', $scope.cancelar); | 
| 30 | }); | 30 | }); | 
| 31 | 31 | ||
| 32 | if ($routeParams.idx != -1) { | 32 | if ($routeParams.idx !== -1) { | 
| 33 | |||
| 34 | $scope.cisterna = [$routeParams.idx]; | 33 | $scope.cisterna = [$routeParams.idx]; | 
| 35 | focaAbmVehiculoService | 34 | focaAbmVehiculoService | 
| 36 | .getCisternas($routeParams.idVehiculo) | 35 | .getCisternas($routeParams.idVehiculo) | 
| 37 | .then(function(res) { | 36 | .then(function(res) { | 
| 38 | $scope.cisterna = res[$routeParams.idx]; | 37 | $scope.cisterna = res[$routeParams.idx]; | 
| 39 | }); | 38 | }); | 
| 40 | } | 39 | } | 
| 41 | 40 | ||
| 42 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 41 | focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function(res) { | 
| 43 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 42 | var codigo = ('00000' + res.data.transportista.COD).slice(-5); | 
| 44 | $scope.transportista = res.data.transportista.COD; | 43 | $scope.transportista = res.data.transportista.COD; | 
| 45 | $scope.capacidadVechiulo = res.data.capacidad; | 44 | $scope.capacidadVechiulo = res.data.capacidad; | 
| 46 | $scope.$broadcast('addCabecera', { | 45 | $scope.$broadcast('addCabecera', { | 
| 47 | label: 'Transportista:', | 46 | label: 'Transportista:', | 
| 48 | valor: codigo + ' - ' + res.data.transportista.NOM | 47 | valor: codigo + ' - ' + res.data.transportista.NOM | 
| 49 | }); | 48 | }); | 
| 50 | $scope.$broadcast('addCabecera', { | 49 | $scope.$broadcast('addCabecera', { | 
| 51 | label: 'Unidad:', | 50 | label: 'Unidad:', | 
| 52 | valor: res.data.codigo | 51 | valor: res.data.codigo | 
| 53 | }); | 52 | }); | 
| 54 | $scope.$broadcast('addCabecera', { | 53 | $scope.$broadcast('addCabecera', { | 
| 55 | label: 'Capacidad total vehículo:', | 54 | label: 'Capacidad total vehículo:', | 
| 56 | valor: res.data.capacidad | 55 | valor: res.data.capacidad | 
| 57 | }); | 56 | }); | 
| 58 | }); | 57 | }); | 
| 58 | |||
| 59 | $scope.cancelar = function() { | 59 | $scope.cancelar = function() { | 
| 60 | 60 | ||
| 61 | if ($scope.formCisterna.$pristine == false) { | 61 | if (!$scope.formCisterna.$pristine) { | 
| 62 | focaModalService.confirm( | 62 | focaModalService.confirm( | 
| 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 63 | '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' | 
| 64 | ).then(function(data) { | 64 | ).then(function(data) { | 
| 65 | if (data) { | 65 | if (data) { | 
| 66 | $location.path('/vehiculo'); | 66 | $location.path('/vehiculo'); | 
| 67 | } | 67 | } | 
| 68 | }); | 68 | }); | 
| 69 | } | 69 | } | 
| 70 | }; | 70 | }; | 
| 71 | $scope.guardar = function() { | 71 | |
| 72 | $scope.guardar = function() { | ||
| 73 | |||
| 74 | if ($scope.formCisterna.$pristine) { | ||
| 75 | $scope.cancelar(); | ||
| 76 | return; | ||
| 77 | } | ||
| 72 | 78 | ||
| 73 | if (!$scope.cisterna.codigo) { | 79 | if (!$scope.cisterna.codigo) { | 
| 74 | focaModalService.alert('Ingrese codigo de cisterna'); | 80 | focaModalService.alert('Ingrese codigo de cisterna'); | 
| 75 | return; | 81 | return; | 
| 76 | } else if (!$scope.cisterna.capacidad) { | 82 | } else if (!$scope.cisterna.capacidad) { | 
| 77 | focaModalService.alert('Ingrese capacidad'); | 83 | focaModalService.alert('Ingrese capacidad'); | 
| 78 | return; | 84 | return; | 
| 79 | } else if (!$scope.cisterna.idUnidadMedida) { | 85 | } else if (!$scope.cisterna.idUnidadMedida) { | 
| 80 | focaModalService.alert('Ingrese unidad de medida'); | 86 | focaModalService.alert('Ingrese unidad de medida'); | 
| 81 | return; | 87 | return; | 
| 82 | } | 88 | } | 
| 83 | 89 | ||
| 84 | validaCodigo() | 90 | validaCodigo() | 
| 85 | .then(function() { | 91 | .then(function() { | 
| 86 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 92 | $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); | 
| 87 | delete $scope.cisterna.vehiculo; | 93 | delete $scope.cisterna.vehiculo; | 
| 88 | 94 | ||
| 89 | focaAbmVehiculoService | 95 | focaAbmVehiculoService | 
| 90 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 96 | .guardarCisterna($scope.cisterna, $routeParams.idx); | 
| 91 | 97 | ||
| 92 | $timeout(function() { | 98 | $timeout(function() { | 
| 93 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 99 | $location.path('/vehiculo/' + $routeParams.idVehiculo + | 
| 94 | '/' + $scope.transportista); | 100 | '/' + $scope.transportista); | 
| 95 | }, 0); | 101 | }, 0); | 
| 96 | }, function(err) { | 102 | }, function(err) { | 
| 97 | focaModalService.alert(err); | 103 | focaModalService.alert(err); | 
| 98 | }); | 104 | }); | 
| 99 | 105 | ||
| 100 | }; | 106 | }; | 
| 101 | 107 | ||
| 102 | $scope.seleccionarUnidadMedida = function() { | 108 | $scope.seleccionarUnidadMedida = function() { | 
| 103 | var modalInstance = $uibModal.open( | 109 | var modalInstance = $uibModal.open( | 
| 104 | { | 110 | { | 
| 105 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 111 | ariaLabelledBy: 'Busqueda de Unidades de medida', | 
| 106 | templateUrl: 'modal-unidad-medida.html', | 112 | templateUrl: 'modal-unidad-medida.html', | 
| 107 | controller: 'focaModalUnidadMedidaCtrl', | 113 | controller: 'focaModalUnidadMedidaCtrl', | 
| 108 | size: 'lg' | 114 | size: 'lg' | 
| 109 | } | 115 | } | 
| 110 | ); | 116 | ); | 
| 111 | modalInstance.result.then(function(unidaMedida) { | 117 | modalInstance.result.then(function(unidaMedida) { | 
| 112 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 118 | $scope.cisterna.idUnidadMedida = unidaMedida.ID; | 
| 113 | $scope.cisterna.unidadMedida = unidaMedida; | 119 | $scope.cisterna.unidadMedida = unidaMedida; | 
| 114 | }); | 120 | }); | 
| 115 | }; | 121 | }; | 
| 116 | 122 | ||
| 117 | function validaCodigo() { | 123 | function validaCodigo() { | 
| 118 | return new Promise(function(resolve, reject) { | 124 | return new Promise(function(resolve, reject) { | 
| 119 | focaAbmVehiculoService | 125 | focaAbmVehiculoService | 
| 120 | .getCisternas($routeParams.idVehiculo) | 126 | .getCisternas($routeParams.idVehiculo) | 
| 121 | .then(function(res) { | 127 | .then(function(res) { | 
| 122 | var cisternas = res; | 128 | var cisternas = res; | 
| 123 | var totalCargado = 0; | 129 | var totalCargado = 0; | 
| 124 | cisternas.forEach(function(cisterna, idx) { | 130 | cisternas.forEach(function(cisterna, idx) { | 
| 125 | //SI EL CODIGO YA EXISTE | 131 | //SI EL CODIGO YA EXISTE | 
| 126 | if (cisterna.codigo === $scope.cisterna.codigo && | 132 | if (cisterna.codigo === $scope.cisterna.codigo && | 
| 127 | idx != $routeParams.idx && | 133 | idx !== $routeParams.idx && | 
| 128 | !cisterna.desactivado) { | 134 | !cisterna.desactivado) { | 
| 129 | reject('Código de cisterna existente'); | 135 | reject('Código de cisterna existente'); | 
| 130 | } | 136 | } | 
| 131 | if (idx != $routeParams.idx && | 137 | if (idx !== $routeParams.idx && | 
| 132 | !cisterna.desactivado) { | 138 | !cisterna.desactivado) { | 
| 133 | totalCargado += cisterna.capacidad; | 139 | totalCargado += cisterna.capacidad; | 
| 134 | } | 140 | } | 
| 135 | }); | 141 | }); | 
| 136 | resolve(); | 142 | resolve(); | 
| 137 | }); | 143 | }); | 
| 138 | }); | 144 | }); | 
| 139 | } | 145 | } | 
| 140 | } | 146 | } | 
| 141 | ]); | 147 | ]); |