Commit e3a979164abb49920dd72701cc9fc4a16b2833ae

Authored by Jose Pinto
1 parent 627cd1963f
Exists in master and in 1 other branch develop

redirects con location.path

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', '$window',
97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 97 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
98 focaModalService, $timeout, focaBotoneraLateralService, $window) { 98 focaModalService, $timeout, focaBotoneraLateralService, $window) {
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 key = (typeof key === 'undefined') ? 13 : key; 165 key = (typeof key === 'undefined') ? 13 : key;
166 if(key === 13) { 166 if(key === 13) {
167 //Valida si existe numero de unidad 167 //Valida si existe numero de unidad
168 if(!validaTotalCargas() && !$scope.nuevo) { 168 if(!validaTotalCargas() && !$scope.nuevo) {
169 focaModalService.alert('La suma de las capacidades de las cisternas' + 169 focaModalService.alert('La suma de las capacidades de las cisternas' +
170 ' debe ser igual a la capacidad total del vehículo'); 170 ' debe ser igual a la capacidad total del vehículo');
171 return; 171 return;
172 } 172 }
173 validaCodigoUnidad().then(function() { 173 validaCodigoUnidad().then(function() {
174 delete $scope.vehiculo.transportista; 174 delete $scope.vehiculo.transportista;
175 delete $scope.vehiculo.cisternas; 175 delete $scope.vehiculo.cisternas;
176 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 176 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
177 .then(function(res) { 177 .then(function(res) {
178 if($scope.nuevo) { 178 if ($scope.nuevo) {
179 $location.path('/vehiculo/' + res.data.id + 179 $location.path('/vehiculo/' + res.data.id +
180 '/' + res.data.idTransportista); 180 '/' + res.data.idTransportista);
181 }else { 181 } else {
182 guardarCisternas().then(function() { 182 guardarCisternas().then(function() {
183 $window.location.assign('/#!/vehiculo'); 183 $location.path('/vehiculo');
184 }); 184 });
185 } 185 }
186 }); 186 });
187 }, function() { 187 }, function() {
188 focaModalService.alert('Código de unidad existente'); 188 focaModalService.alert('Código de unidad existente');
189 }); 189 });
190 } 190 }
191 191
192 }; 192 };
193 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) { 193 $scope.solicitarConfirmacionCisterna = function(cisterna, idx) {
194 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + 194 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' +
195 cisterna.id + ' ' + cisterna.codigo + ' ?').then( 195 cisterna.id + ' ' + cisterna.codigo + ' ?').then(
196 function(data) { 196 function(data) {
197 if(data) { 197 if(data) {
198 focaAbmVehiculoService.deleteCisterna(idx); 198 focaAbmVehiculoService.deleteCisterna(idx);
199 focaAbmVehiculoService 199 focaAbmVehiculoService
200 .getCisternas($routeParams.idVehiculo) 200 .getCisternas($routeParams.idVehiculo)
201 .then(function(res) { 201 .then(function(res) {
202 $scope.cisternas = res; 202 $scope.cisternas = res;
203 }); 203 });
204 } 204 }
205 } 205 }
206 ); 206 );
207 }; 207 };
208 208
209 function validaCodigoUnidad() { 209 function validaCodigoUnidad() {
210 return new Promise(function(resolve, reject) { 210 return new Promise(function(resolve, reject) {
211 focaAbmVehiculoService 211 focaAbmVehiculoService
212 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 212 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
213 .then(function(res) { 213 .then(function(res) {
214 //Valida si existe numero de unidad 214 //Valida si existe numero de unidad
215 var existe = res.data.filter(function(vehiculo) { 215 var existe = res.data.filter(function(vehiculo) {
216 return vehiculo.codigo === $scope.vehiculo.codigo && 216 return vehiculo.codigo === $scope.vehiculo.codigo &&
217 vehiculo.id !== $scope.vehiculo.id; 217 vehiculo.id !== $scope.vehiculo.id;
218 }); 218 });
219 219
220 if(existe.length) { 220 if(existe.length) {
221 reject(existe); 221 reject(existe);
222 }else { 222 }else {
223 resolve(); 223 resolve();
224 } 224 }
225 }); 225 });
226 }); 226 });
227 } 227 }
228 228
229 function validaTotalCargas() { 229 function validaTotalCargas() {
230 var total = 0; 230 var total = 0;
231 $scope.cisternas.forEach(function(cisterna) { 231 $scope.cisternas.forEach(function(cisterna) {
232 if(!cisterna.desactivado) { 232 if(!cisterna.desactivado) {
233 total += parseInt(cisterna.capacidad); 233 total += parseInt(cisterna.capacidad);
234 } 234 }
235 }); 235 });
236 return $scope.vehiculo.capacidad == total; 236 return $scope.vehiculo.capacidad == total;
237 } 237 }
238 238
239 function guardarCisternas() { 239 function guardarCisternas() {
240 var cisternas = $scope.cisternas.map(function(cisterna) { 240 var cisternas = $scope.cisternas.map(function(cisterna) {
241 return { 241 return {
242 id: cisterna.id, 242 id: cisterna.id,
243 capacidad: parseFloat(cisterna.capacidad), 243 capacidad: parseFloat(cisterna.capacidad),
244 codigo: cisterna.codigo, 244 codigo: cisterna.codigo,
245 idUnidadMedida: cisterna.idUnidadMedida, 245 idUnidadMedida: cisterna.idUnidadMedida,
246 idVehiculo: $routeParams.idVehiculo, 246 idVehiculo: $routeParams.idVehiculo,
247 desactivado: cisterna.desactivado 247 desactivado: cisterna.desactivado
248 }; 248 };
249 }); 249 });
250 250
251 return focaAbmVehiculoService.guardarCisternas(cisternas); 251 return focaAbmVehiculoService.guardarCisternas(cisternas);
252 } 252 }
253 } 253 }
254 ]); 254 ]);
255 255
src/js/controllerCisterna.js
1 angular.module('focaAbmVehiculo') 1 angular.module('focaAbmVehiculo')
2 .controller('focaAbmVehiculoCisternaController', [ 2 .controller('focaAbmVehiculoCisternaController', [
3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 3 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window', 4 'focaModalService', 'focaBotoneraLateralService', '$timeout', '$window',
5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 5 function($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
6 focaModalService, focaBotoneraLateralService, $timeout, $window) { 6 focaModalService, focaBotoneraLateralService, $timeout, $window) {
7 $scope.nuevo = ($routeParams.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 if(!$scope.cisterna.unidadMedida) { 57 if(!$scope.cisterna.unidadMedida) {
58 focaModalService.alert('Ingrese unidad de medida'); 58 focaModalService.alert('Ingrese unidad de medida');
59 return; 59 return;
60 } 60 }
61 validaCodigo() 61 validaCodigo()
62 .then(function() { 62 .then(function() {
63 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo); 63 $scope.cisterna.idVehiculo = parseInt($routeParams.idVehiculo);
64 delete $scope.cisterna.vehiculo; 64 delete $scope.cisterna.vehiculo;
65 65
66 focaAbmVehiculoService 66 focaAbmVehiculoService
67 .guardarCisterna($scope.cisterna, $routeParams.idx); 67 .guardarCisterna($scope.cisterna, $routeParams.idx);
68 68
69 $window.location.assign('/#!/vehiculo/' + $routeParams.idVehiculo + 69 $timeout(function() {
70 '/' + $scope.transportista); 70 $location.path('/vehiculo/' + $routeParams.idVehiculo +
71 '/' + $scope.transportista);
72 }, 0);
71 }, function(err) { 73 }, function(err) {
72 focaModalService.alert(err); 74 focaModalService.alert(err);
73 }); 75 });
74 76
75 }; 77 };
76 78
77 $scope.seleccionarUnidadMedida = function() { 79 $scope.seleccionarUnidadMedida = function() {
78 var modalInstance = $uibModal.open( 80 var modalInstance = $uibModal.open(
79 { 81 {
80 ariaLabelledBy: 'Busqueda de Unidades de medida', 82 ariaLabelledBy: 'Busqueda de Unidades de medida',
81 templateUrl: 'modal-unidad-medida.html', 83 templateUrl: 'modal-unidad-medida.html',
82 controller: 'focaModalUnidadMedidaCtrl', 84 controller: 'focaModalUnidadMedidaCtrl',
83 size: 'lg' 85 size: 'lg'
84 } 86 }
85 ); 87 );
86 modalInstance.result.then(function(unidaMedida) { 88 modalInstance.result.then(function(unidaMedida) {
87 $scope.cisterna.idUnidadMedida = unidaMedida.ID; 89 $scope.cisterna.idUnidadMedida = unidaMedida.ID;
88 $scope.cisterna.unidadMedida = unidaMedida; 90 $scope.cisterna.unidadMedida = unidaMedida;
89 }); 91 });
90 }; 92 };
91 93
92 function validaCodigo() { 94 function validaCodigo() {
93 return new Promise(function(resolve, reject) { 95 return new Promise(function(resolve, reject) {
94 focaAbmVehiculoService 96 focaAbmVehiculoService
95 .getCisternas($routeParams.idVehiculo) 97 .getCisternas($routeParams.idVehiculo)
96 .then(function(res) { 98 .then(function(res) {
97 var cisternas = res; 99 var cisternas = res;
98 var totalCargado = 0; 100 var totalCargado = 0;
99 cisternas.forEach(function(cisterna, idx) { 101 cisternas.forEach(function(cisterna, idx) {
100 //SI EL CODIGO YA EXISTE 102 //SI EL CODIGO YA EXISTE
101 if(cisterna.codigo === $scope.cisterna.codigo && 103 if(cisterna.codigo === $scope.cisterna.codigo &&
102 idx != $routeParams.idx && 104 idx != $routeParams.idx &&
103 !cisterna.desactivado) { 105 !cisterna.desactivado) {
104 reject('Código de cisterna existente'); 106 reject('Código de cisterna existente');
105 } 107 }
106 if(idx != $routeParams.idx && 108 if(idx != $routeParams.idx &&
107 !cisterna.desactivado) { 109 !cisterna.desactivado) {
108 totalCargado += cisterna.capacidad; 110 totalCargado += cisterna.capacidad;
109 } 111 }
110 }); 112 });
111 resolve(); 113 resolve();
112 }); 114 });
113 }); 115 });
114 } 116 }
115 } 117 }
116 ]); 118 ]);
117 119