Commit 7fbb72e845f4d4ccfb43e9856646d3f9006e42df

Authored by Eric
1 parent dada99d278
Exists in master and in 1 other branch develop

pre commit

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