Commit c5233189925b35a8db127fbfe6bfd8b3e58d6c0f

Authored by Luigi
1 parent 471ce2b86a
Exists in master

Calculo capacidad total vehiculo

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.tipo = ''; 9 $scope.tipo = '';
10 $scope.botonera = [{ 10 $scope.botonera = [{
11 label: 'Transportista', 11 label: 'Transportista',
12 image: 'cliente.png' 12 image: 'cliente.png'
13 }]; 13 }];
14 14
15 focaAbmVehiculoService.cleanCisternas(); 15 focaAbmVehiculoService.cleanCisternas();
16 16
17 //SETEO BOTONERA LATERAL 17 //SETEO BOTONERA LATERAL
18 focaBotoneraLateralService.showSalir(false); 18 focaBotoneraLateralService.showSalir(false);
19 focaBotoneraLateralService.showPausar(false); 19 focaBotoneraLateralService.showPausar(false);
20 focaBotoneraLateralService.showCancelar(false); 20 focaBotoneraLateralService.showCancelar(false);
21 focaBotoneraLateralService.showGuardar(false); 21 focaBotoneraLateralService.showGuardar(false);
22 focaBotoneraLateralService.addCustomButton('Salir', salir); 22 focaBotoneraLateralService.addCustomButton('Salir', salir);
23 23
24 if (focaAbmVehiculoService.transportistaSeleccionado.COD) { 24 if (focaAbmVehiculoService.transportistaSeleccionado.COD) {
25 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado); 25 elegirTransportista(focaAbmVehiculoService.transportistaSeleccionado);
26 } 26 }
27 $scope.editar = function (id) { 27 $scope.editar = function (id) {
28 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista); 28 $location.path('/vehiculo/' + id + '/' + $scope.idTransportista);
29 }; 29 };
30 30
31 $scope.solicitarConfirmacion = function (vehiculo) { 31 $scope.solicitarConfirmacion = function (vehiculo) {
32 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' + 32 focaModalService.confirm('¿Está seguro que desea borrar el vehiculo ' +
33 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then( 33 vehiculo.id + ' ' + vehiculo.tractor + ' ?').then(
34 function (data) { 34 function (data) {
35 if (data) { 35 if (data) {
36 focaAbmVehiculoService.deleteVehiculo(vehiculo.id); 36 focaAbmVehiculoService.deleteVehiculo(vehiculo.id);
37 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1); 37 $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
38 } 38 }
39 } 39 }
40 ); 40 );
41 }; 41 };
42 $scope.seleccionarTransportista = function () { 42 $scope.seleccionarTransportista = function () {
43 var parametrosModal = { 43 var parametrosModal = {
44 titulo: 'Búsqueda de Transportista', 44 titulo: 'Búsqueda de Transportista',
45 query: '/transportista', 45 query: '/transportista',
46 columnas: [ 46 columnas: [
47 { 47 {
48 nombre: 'Código', 48 nombre: 'Código',
49 propiedad: 'COD' 49 propiedad: 'COD'
50 }, 50 },
51 { 51 {
52 nombre: 'Nombre', 52 nombre: 'Nombre',
53 propiedad: 'NOM' 53 propiedad: 'NOM'
54 }, 54 },
55 { 55 {
56 nombre: 'CUIT', 56 nombre: 'CUIT',
57 propiedad: 'CUIT' 57 propiedad: 'CUIT'
58 } 58 }
59 ] 59 ]
60 }; 60 };
61 focaModalService.modal(parametrosModal).then( 61 focaModalService.modal(parametrosModal).then(
62 function (transportista) { 62 function (transportista) {
63 elegirTransportista(transportista); 63 elegirTransportista(transportista);
64 focaAbmVehiculoService.transportistaSeleccionado = transportista; 64 focaAbmVehiculoService.transportistaSeleccionado = transportista;
65 }, function () { 65 }, function () {
66 66
67 } 67 }
68 ); 68 );
69 }; 69 };
70 function elegirTransportista(transportista) { 70 function elegirTransportista(transportista) {
71 var codigo = ('00000' + transportista.COD).slice(-5); 71 var codigo = ('00000' + transportista.COD).slice(-5);
72 $scope.idTransportista = transportista.COD; 72 $scope.idTransportista = transportista.COD;
73 $scope.filtros = transportista.NOM.trim(); 73 $scope.filtros = transportista.NOM.trim();
74 $timeout(function () { 74 $timeout(function () {
75 $scope.$broadcast('addCabecera', { 75 $scope.$broadcast('addCabecera', {
76 label: 'Transportista:', 76 label: 'Transportista:',
77 valor: codigo + ' - ' + transportista.NOM 77 valor: codigo + ' - ' + transportista.NOM
78 }); 78 });
79 }); 79 });
80 buscar(transportista.COD); 80 buscar(transportista.COD);
81 } 81 }
82 82
83 function buscar(idTransportista) { 83 function buscar(idTransportista) {
84 focaAbmVehiculoService 84 focaAbmVehiculoService
85 .getVehiculosPorTransportista(idTransportista) 85 .getVehiculosPorTransportista(idTransportista)
86 .then(function (datos) { 86 .then(function (datos) {
87 $scope.vehiculos = datos.data; 87 $scope.vehiculos = datos.data;
88 }); 88 });
89 } 89 }
90 function salir() { 90 function salir() {
91 focaAbmVehiculoService.transportistaSeleccionado = {}; 91 focaAbmVehiculoService.transportistaSeleccionado = {};
92 $location.path('/'); 92 $location.path('/');
93 } 93 }
94 } 94 }
95 ]) 95 ])
96 .controller('focaAbmVehiculoController', [ 96 .controller('focaAbmVehiculoController', [
97 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal', 97 '$scope', 'focaAbmVehiculoService', '$routeParams', '$location', '$uibModal',
98 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter', 98 'focaModalService', '$timeout', 'focaBotoneraLateralService', '$localStorage', '$filter',
99 function ($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal, 99 function ($scope, focaAbmVehiculoService, $routeParams, $location, $uibModal,
100 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) { 100 focaModalService, $timeout, focaBotoneraLateralService, $localStorage, $filter) {
101 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false; 101 $scope.nuevo = $routeParams.idVehiculo === '0' ? true : false;
102 $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true; 102 $scope.nuevoCisterna = ($routeParams.idx > -1) ? false : true;
103 $scope.now = new Date(); 103 $scope.now = new Date();
104 $scope.focused = 1; 104 $scope.focused = 1;
105 $scope.tipo = ''; 105 $scope.tipo = '';
106 $scope.creando = false; 106 $scope.creando = false;
107 $scope.crear = false; 107 $scope.crear = false;
108 $scope.transportistaStamp = ''; 108 $scope.transportistaStamp = '';
109 $scope.cisternas = []; 109 $scope.cisternas = [];
110 110
111 $timeout(function () { 111 $timeout(function () {
112 focaBotoneraLateralService.showSalir(false); 112 focaBotoneraLateralService.showSalir(false);
113 focaBotoneraLateralService.showPausar(true); 113 focaBotoneraLateralService.showPausar(true);
114 focaBotoneraLateralService.showCancelar(false); 114 focaBotoneraLateralService.showCancelar(false);
115 focaBotoneraLateralService.showGuardar(true, $scope.guardar); 115 focaBotoneraLateralService.showGuardar(true, $scope.guardar);
116 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir); 116 focaBotoneraLateralService.addCustomButton('Salir', $scope.salir);
117 }); 117 });
118 118
119 if ($scope.nuevo) { 119 if ($scope.nuevo) {
120 $scope.tipo = 'Crear Vehiculo'; 120 $scope.tipo = 'Crear Vehiculo';
121 focaAbmVehiculoService 121 focaAbmVehiculoService
122 .getTransportistaPorId($routeParams.idTransportista) 122 .getTransportistaPorId($routeParams.idTransportista)
123 .then(function (res) { 123 .then(function (res) {
124 var codigo = ('00000' + res.data[0].COD).slice(-5); 124 var codigo = ('00000' + res.data[0].COD).slice(-5);
125 $scope.vehiculo.idTransportista = res.data[0].COD; 125 $scope.vehiculo.idTransportista = res.data[0].COD;
126 $scope.vehiculo.transportista = res.data; 126 $scope.vehiculo.transportista = res.data;
127 $scope.vehiculo.capacidad = 0;
127 $scope.$broadcast('addCabecera', { 128 $scope.$broadcast('addCabecera', {
128 label: 'Transportista:', 129 label: 'Transportista:',
129 valor: codigo + ' - ' + res.data[0].ALI 130 valor: codigo + ' - ' + res.data[0].ALI
130 }); 131 });
131 $scope.$broadcast('addCabecera', { 132 $scope.$broadcast('addCabecera', {
132 label: 'Unidad:', 133 label: 'Unidad:',
133 valor: 'NUEVO' 134 valor: 'NUEVO'
134 }); 135 });
135 }); 136 });
136 } else { 137 } else {
137 $scope.tipo = 'Editar Vehiculo'; 138 $scope.tipo = 'Editar Vehiculo';
138 } 139 }
139 $scope.vehiculo = {}; 140 $scope.vehiculo = {};
140 141
141 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function (res) { 142 focaAbmVehiculoService.getVehiculo($routeParams.idVehiculo).then(function (res) {
142 if (res.data) { 143 if (res.data) {
143 var vehiculoSeteado = getLSVehiculo(); 144 var vehiculoSeteado = getLSVehiculo();
144 if (vehiculoSeteado === false) { 145 if (vehiculoSeteado === false) {
145 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5); 146 $scope.transportistaStamp = ('00000' + res.data.transportista.COD).slice(-5);
146 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM; 147 $scope.transportistaStamp += ' - ' + res.data.transportista.NOM;
147 148
148 $scope.vehiculo = res.data; 149 $scope.vehiculo = res.data;
149 $scope.$broadcast('addCabecera', { 150 $scope.$broadcast('addCabecera', {
150 label: 'Transportista:', 151 label: 'Transportista:',
151 valor: $scope.transportistaStamp 152 valor: $scope.transportistaStamp
152 }); 153 });
153 $scope.$broadcast('addCabecera', { 154 $scope.$broadcast('addCabecera', {
154 label: 'Unidad:', 155 label: 'Unidad:',
155 valor: res.data.codigo 156 valor: res.data.codigo
156 }); 157 });
157 } 158 }
158 159
159 focaAbmVehiculoService 160 focaAbmVehiculoService
160 .getCisternas($routeParams.idVehiculo) 161 .getCisternas($routeParams.idVehiculo)
161 .then(function (res) { 162 .then(function (res) {
162 $scope.cisternas = res; 163 $scope.cisternas = res;
163 $scope.$apply(); 164 $scope.$apply();
164 }); 165 });
165 } 166 }
166 }); 167 });
167 168
168 $scope.next = function (key) { 169 $scope.next = function (key) {
169 if (key === 13) $scope.focused++; 170 if (key === 13) $scope.focused++;
170 }; 171 };
171 172
172 $scope.salir = function () { 173 $scope.salir = function () {
173 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 174 if (!$scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
174 focaModalService.confirm( 175 focaModalService.confirm(
175 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.' 176 '¿Está seguro de que desea salir? Se perderán todos los datos cargados.'
176 ).then(function (data) { 177 ).then(function (data) {
177 if (data) { 178 if (data) {
178 $location.path('/vehiculo'); 179 $location.path('/vehiculo');
179 } 180 }
180 }); 181 });
181 } else { 182 } else {
182 $location.path('/vehiculo'); 183 $location.path('/vehiculo');
183 } 184 }
184 }; 185 };
185 186
186 $scope.editar = function (cisterna) { 187 $scope.editar = function (cisterna) {
187 $scope.cisternas.forEach(function (cisterna) { 188 $scope.cisternas.forEach(function (cisterna) {
188 cisterna.editando = false; 189 cisterna.editando = false;
189 $scope.crear = true; 190 $scope.crear = true;
190 }); 191 });
191 cisterna.editando = true; 192 cisterna.editando = true;
192 $scope.inicial = angular.copy(cisterna); 193 $scope.inicial = angular.copy(cisterna);
193 }; 194 };
194 195
195 $scope.volver = function (cisterna, key) { 196 $scope.volver = function (cisterna, key) {
196 if (cisterna.id === undefined || !$scope.crear) { 197 if (cisterna.id === undefined || !$scope.crear) {
197 $scope.cisternas.shift(cisterna); 198 $scope.cisternas.shift(cisterna);
198 $scope.crear = false; 199 $scope.crear = false;
199 return; 200 return;
200 } 201 }
201 if (cisterna.id !== undefined) { 202 if (cisterna.id !== undefined) {
202 $scope.cisternas[key] = $scope.inicial; 203 $scope.cisternas[key] = $scope.inicial;
203 $scope.cisternas[key].editando = false; 204 $scope.cisternas[key].editando = false;
204 } 205 }
205 $scope.crear = false; 206 $scope.crear = false;
206 }; 207 };
207 208
208 $scope.crearCisterna = function () { 209 $scope.crearCisterna = function () {
209 var cisterna = { 210 var cisterna = {
210 codigo: '', 211 codigo: '',
211 capacidad: '', 212 capacidad: '',
212 idUnidadMedida: 0, 213 idUnidadMedida: 0,
213 unidadMedida: {}, 214 unidadMedida: {},
214 editando: true, 215 editando: true,
215 }; 216 };
216 $scope.cisternas.unshift(cisterna); 217 $scope.cisternas.unshift(cisterna);
217 $scope.crear = true; 218 $scope.crear = true;
218 }; 219 };
219 220
220 $scope.seleccionarUnidadMedida = function (cisterna) { 221 $scope.seleccionarUnidadMedida = function (key,cisterna) {
221 var modalInstance = $uibModal.open( 222
222 { 223 if (key === 13) {
223 ariaLabelledBy: 'Busqueda de Unidades de medida', 224 var modalInstance = $uibModal.open(
224 templateUrl: 'modal-unidad-medida.html', 225 {
225 controller: 'focaModalUnidadMedidaCtrl', 226 ariaLabelledBy: 'Busqueda de Unidades de medida',
226 size: 'lg' 227 templateUrl: 'modal-unidad-medida.html',
227 } 228 controller: 'focaModalUnidadMedidaCtrl',
228 ); 229 size: 'lg'
229 modalInstance.result.then(function (unidaMedida) { 230 }
230 cisterna.idUnidadMedida = unidaMedida.ID; 231 );
231 cisterna.unidadMedida = unidaMedida; 232 modalInstance.result.then(function (unidaMedida) {
232 }); 233 cisterna.idUnidadMedida = unidaMedida.ID;
234 cisterna.unidadMedida = unidaMedida;
235 });
236 }
233 }; 237 };
234 238
235 $scope.guardar = function (key) { 239 $scope.guardar = function (key) {
236 key = (typeof key === 'undefined') ? 13 : key; 240 key = (typeof key === 'undefined') ? 13 : key;
237 241
238 if (key === 13) { 242 if (key === 13) {
239 243
240 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) { 244 if ($scope.formVehiculo.$pristine && focaAbmVehiculoService.cisternasPristine) {
241 $scope.salir(); 245 $scope.salir();
242 return; 246 return;
243 } 247 }
244 $scope.cisternas.forEach(function (cisterna) { 248 $scope.cisternas.forEach(function (cisterna) {
245 if (cisterna.id === 0) cisterna.id = undefined; 249 if (cisterna.id === 0) cisterna.id = undefined;
246 }); 250 });
247 251
248 if (!$scope.vehiculo.codigo) { 252 if (!$scope.vehiculo.codigo) {
249 focaModalService.alert('Ingrese unidad'); 253 focaModalService.alert('Ingrese unidad');
250 return; 254 return;
251 } else if (!$scope.vehiculo.tractor) { 255 } else if (!$scope.vehiculo.tractor) {
252 focaModalService.alert('Ingrese dominio tractor'); 256 focaModalService.alert('Ingrese dominio tractor');
253 return; 257 return;
254 } else if (!$scope.vehiculo.semi) { 258 } else if (!$scope.vehiculo.semi) {
255 focaModalService.alert('Ingrese dominio semi'); 259 focaModalService.alert('Ingrese dominio semi');
256 return; 260 return;
257 } else if (!$scope.vehiculo.capacidad) {
258 focaModalService.alert('Ingrese capacidad total');
259 return;
260 }
261 //Valida si existe numero de unidad
262 if (!validaTotalCargas() && !$scope.nuevo) {
263 focaModalService.alert('La suma de las capacidades de las cisternas' +
264 ' debe ser igual a la capacidad total del vehículo');
265 return;
266 } 261 }
267 262
268 if ($scope.nuevo) { 263 if ($scope.nuevo) {
269 validaCodigoUnidad().then(function () { 264 validaCodigoUnidad().then(function () {
270 delete $scope.vehiculo.transportista; 265 delete $scope.vehiculo.transportista;
271 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo) 266 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo)
272 .then(function (res) { 267 .then(function (res) {
273 $routeParams.idVehiculo = res.data.id; 268 $routeParams.idVehiculo = res.data.id;
274 guardarCisternas($scope.cisternas).then(function () { 269 guardarCisternas($scope.cisternas).then(function () {
275 angular.element('#guardar').addClass('guardado'); 270 angular.element('#guardar').addClass('guardado');
276 $timeout(function () {$location.path('/vehiculo');},300); 271 $timeout(function () {$location.path('/vehiculo');},300);
277 }); 272 });
278 }); 273 });
279 }, function () { 274 }, function () {
280 focaModalService.alert('Código de unidad existente'); 275 focaModalService.alert('Código de unidad existente');
281 }); 276 });
282 } else { 277 } else {
278 delete $scope.vehiculo.cisternas;
279 delete $scope.vehiculo.transportista;
280 focaAbmVehiculoService.guardarVehiculo($scope.vehiculo);
283 guardarCisternas($scope.cisternas).then(function () { 281 guardarCisternas($scope.cisternas).then(function () {
284 angular.element('#guardar').addClass('guardado'); 282 angular.element('#guardar').addClass('guardado');
285 $timeout(function () {$location.path('/vehiculo');},500); 283 $timeout(function () {$location.path('/vehiculo');},500);
286 }); 284 });
287 } 285 }
288 } 286 }
289 }; 287 };
290 //Agregar propiedades de cisterna 288 //Agregar propiedades de cisterna
291 $scope.$watch('vehiculo', function (newValue) { 289 $scope.$watch('vehiculo', function (newValue) {
292 focaBotoneraLateralService.setPausarData({ 290 focaBotoneraLateralService.setPausarData({
293 label: 'vehiculo', 291 label: 'vehiculo',
294 val: { 292 val: {
295 codigo: newValue.codigo, 293 codigo: newValue.codigo,
296 tractor: newValue.tractor, 294 tractor: newValue.tractor,
297 semi: newValue.semi, 295 semi: newValue.semi,
298 capacidad: newValue.capacidad, 296 capacidad: newValue.capacidad,
299 idVehiculo: newValue.idVehiculo, 297 idVehiculo: newValue.idVehiculo,
300 idTransportista: newValue.idTransportista 298 idTransportista: newValue.idTransportista
301 } 299 }
302 }); 300 });
303 }, true); 301 }, true);
304 302
305 function getLSVehiculo() { 303 function getLSVehiculo() {
306 var vehiculo = JSON.parse($localStorage.vehiculo || null); 304 var vehiculo = JSON.parse($localStorage.vehiculo || null);
307 if (vehiculo) { 305 if (vehiculo) {
308 setearVehiculo(vehiculo); 306 setearVehiculo(vehiculo);
309 delete $localStorage.vehiculo; 307 delete $localStorage.vehiculo;
310 return true; 308 return true;
311 } 309 }
312 return false; 310 return false;
313 } 311 }
314 312
315 function setearVehiculo(vehiculo) { 313 function setearVehiculo(vehiculo) {
316 $scope.vehiculo = vehiculo; 314 $scope.vehiculo = vehiculo;
317 $scope.$broadcast('addCabecera', { 315 $scope.$broadcast('addCabecera', {
318 label: 'Vehiculo:', 316 label: 'Vehiculo:',
319 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - ' 317 valor: $filter('rellenarDigitos')(vehiculo.codigo) + ' - '
320 }); 318 });
321 } 319 }
322 320
323 $scope.solicitarConfirmacionTabla = function (cisterna) { 321 $scope.solicitarConfirmacionTabla = function (cisterna) {
324 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?') 322 focaModalService.confirm('¿Está seguro que desea borrar la cisterna ' + cisterna.id + ' ' + cisterna.codigo + ' ?')
325 .then(function (data) { 323 .then(function (data) {
326 if (data) { 324 if (data) {
327 cisterna.desactivado = true; 325 cisterna.desactivado = true;
326 validaTotalCargas();
328 } 327 }
329 }); 328 });
330 return; 329 return;
331 }; 330 };
332 331
333 function validaCodigoUnidad() { 332 function validaCodigoUnidad() {
334 return new Promise(function (resolve, reject) { 333 return new Promise(function (resolve, reject) {
335 focaAbmVehiculoService 334 focaAbmVehiculoService
336 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista)) 335 .getVehiculosPorTransportista(parseInt($routeParams.idTransportista))
337 .then(function (res) { 336 .then(function (res) {
338 //Valida si existe numero de unidad 337 //Valida si existe numero de unidad
339 var existe = res.data.filter(function (vehiculo) { 338 var existe = res.data.filter(function (vehiculo) {
340 return vehiculo.codigo === $scope.vehiculo.codigo && 339 return vehiculo.codigo === $scope.vehiculo.codigo &&
341 vehiculo.id !== $scope.vehiculo.id; 340 vehiculo.id !== $scope.vehiculo.id;
342 }); 341 });
343 342
344 if (existe.length) { 343 if (existe.length) {
345 reject(existe); 344 reject(existe);
346 } else { 345 } else {
347 resolve(); 346 resolve();
348 } 347 }
349 }); 348 });
350 }); 349 });
351 } 350 }
352 351
353 function validaTotalCargas() { 352 function validaTotalCargas() {
354 var total = 0; 353 var total = 0;
355 $scope.cisternas.forEach(function (cisterna) { 354 $scope.cisternas.forEach(function (cisterna) {
356 if (!cisterna.desactivado) { 355 if (!cisterna.desactivado) {
357 total += parseInt(cisterna.capacidad); 356 total += parseInt(cisterna.capacidad);
357 } else {
358 $scope.vehiculo.capacidad -= parseInt(cisterna.capacidad);
358 } 359 }
359 }); 360 });
360 return $scope.vehiculo.capacidad >= total; 361 return $scope.vehiculo.capacidad = total;
361 } 362 }
362 function guardarCisternas() { 363 function guardarCisternas() {
363 364
364 var cisternas = $scope.cisternas.map(function (cisterna) { 365 var cisternas = $scope.cisternas.map(function (cisterna) {
365 return { 366 return {
366 id: cisterna.id, 367 id: cisterna.id,
367 capacidad: parseFloat(cisterna.capacidad), 368 capacidad: parseFloat(cisterna.capacidad),
368 codigo: cisterna.codigo, 369 codigo: cisterna.codigo,
369 idUnidadMedida: cisterna.idUnidadMedida, 370 idUnidadMedida: cisterna.idUnidadMedida,
370 idVehiculo: $routeParams.idVehiculo, 371 idVehiculo: $routeParams.idVehiculo,
371 desactivado: cisterna.desactivado 372 desactivado: cisterna.desactivado
372 }; 373 };
373 }); 374 });
374 375
375 return focaAbmVehiculoService.guardarCisternas(cisternas); 376 return focaAbmVehiculoService.guardarCisternas(cisternas);
376 } 377 }
377 378
378 $scope.agregarCisterna = function (cisterna) { 379 $scope.agregarCisterna = function (cisterna) {
379 if (!cisterna) { 380 if (!cisterna) {
380 focaModalService.alert('Ingrese valores'); 381 focaModalService.alert('Ingrese valores');
381 return; 382 return;
382 } else if (!cisterna.codigo) { 383 } else if (!cisterna.codigo) {
383 focaModalService.alert('Ingrese codigo de cisterna'); 384 focaModalService.alert('Ingrese codigo de cisterna');
384 return; 385 return;
385 } else if (!cisterna.capacidad) { 386 } else if (!cisterna.capacidad) {
386 focaModalService.alert('Ingrese capacidad'); 387 focaModalService.alert('Ingrese capacidad');
387 return; 388 return;
388 } else if (!cisterna.idUnidadMedida) { 389 } else if (!cisterna.idUnidadMedida) {
389 focaModalService.alert('Ingrese unidad de medida'); 390 focaModalService.alert('Ingrese unidad de medida');
390 return; 391 return;
391 } else if (cisterna.id === undefined) { 392 } else if (cisterna.id === undefined) {
392 cisterna.id = 0; 393 cisterna.id = 0;
393 } 394 }
394 395
396 validaTotalCargas();
395 validaCodigo(cisterna); 397 validaCodigo(cisterna);
396 }; 398 };
397 399
398 if ($routeParams.idx !== -1) { 400 if ($routeParams.idx !== -1) {
399 $scope.cisterna = [$routeParams.idx]; 401 $scope.cisterna = [$routeParams.idx];
400 focaAbmVehiculoService 402 focaAbmVehiculoService
401 .getCisternas($routeParams.idVehiculo) 403 .getCisternas($routeParams.idVehiculo)
402 .then(function (res) { 404 .then(function (res) {
403 $scope.cisterna = res[$routeParams.idx]; 405 $scope.cisterna = res[$routeParams.idx];
404 }); 406 });
405 } 407 }
406 408
407 function validaCodigo(cisterna) { 409 function validaCodigo(cisterna) {
408 focaAbmVehiculoService 410 focaAbmVehiculoService
409 .getCisternas($routeParams.idVehiculo) 411 .getCisternas($routeParams.idVehiculo)
410 .then(function (res) { 412 .then(function (res) {
411 var cisternas = res; 413 var cisternas = res;
412 var totalCargado = 0; 414 var totalCargado = 0;
413 415
414 for (var i = 0; i < cisternas.length; i++) { 416 for (var i = 0; i < cisternas.length; i++) {
415 //SI EL CODIGO YA EXISTE 417 //SI EL CODIGO YA EXISTE
416 if (cisternas[i].codigo === cisterna.codigo && 418 if (cisternas[i].codigo === cisterna.codigo &&
417 i !== $routeParams.idx && 419 i !== $routeParams.idx &&
418 cisternas[i].desactivado === false && 420 cisternas[i].desactivado === false &&
419 cisternas[i].id !== cisterna.id 421 cisternas[i].id !== cisterna.id
420 ) { 422 ) {
421 focaModalService.alert('Código de cisterna existente'); 423 focaModalService.alert('Código de cisterna existente');
422 cisterna.editando = true; 424 cisterna.editando = true;
423 return; 425 return;
424 } 426 }
425 if (i !== $routeParams.idx && 427 if (i !== $routeParams.idx &&
426 !cisternas[i].desactivado) { 428 !cisternas[i].desactivado) {
427 totalCargado += cisternas[i].capacidad; 429 totalCargado += cisternas[i].capacidad;
428 } 430 }
429 } 431 }
src/views/foca-abm-vehiculos-item.html
1 <div class="row"> 1 <div class="row">
2 <foca-cabecera-facturador 2 <foca-cabecera-facturador
3 titulo="'Vehiculo / ' + tipo" 3 titulo="'Vehiculo / ' + tipo"
4 fecha="now" 4 fecha="now"
5 class="mb-0 col-lg-12" 5 class="mb-0 col-lg-12"
6 ></foca-cabecera-facturador> 6 ></foca-cabecera-facturador>
7 </div> 7 </div>
8 <div class="row"> 8 <div class="row">
9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded"> 9 <div class="col-12 col-md-10 p-0 mt-4 border border-white rounded">
10 <form name="formVehiculo" class="px-3"> 10 <form name="formVehiculo" class="px-3">
11 <input type="hidden" name="id" ng-model="sector.id" /> 11 <input type="hidden" name="id" ng-model="sector.id" />
12 <div class="row mt-3"> 12 <div class="row mt-3">
13 <div class="form-group d-flex mb-2 col-md-6"> 13 <div class="form-group d-flex mb-2 col-md-6">
14 <label class="col-form-label col-md-4">Unidad</label> 14 <label class="col-form-label col-md-4">Unidad</label>
15 <div class="input-group col-md-8 pl-0"> 15 <div class="input-group col-md-8 pl-0">
16 <input 16 <input
17 class="form-control" 17 class="form-control"
18 type="text" 18 type="text"
19 teclado-virtual 19 teclado-virtual
20 ng-model="vehiculo.codigo" 20 ng-model="vehiculo.codigo"
21 foca-focus="focused == 1" 21 foca-focus="focused == 1"
22 ng-focus="focused = 1" 22 ng-focus="focused = 1"
23 ng-keypress="next($event.keyCode)" 23 ng-keypress="next($event.keyCode)"
24 ng-disabled="!nuevo" 24 ng-disabled="!nuevo"
25 /> 25 />
26 </div> 26 </div>
27 </div> 27 </div>
28 <div class="form-group d-flex mb-2 col-md-6"> 28 <div class="form-group d-flex mb-2 col-md-6">
29 <label class="col-form-label col-md-4">Dominio tractor</label> 29 <label class="col-form-label col-md-4">Dominio tractor</label>
30 <div class="input-group col-md-8 pl-0"> 30 <div class="input-group col-md-8 pl-0">
31 <input 31 <input
32 class="form-control" 32 class="form-control"
33 type="text" 33 type="text"
34 teclado-virtual 34 teclado-virtual
35 ng-model="vehiculo.tractor" 35 ng-model="vehiculo.tractor"
36 ng-required="true" 36 ng-required="true"
37 foca-focus="focused == 2" 37 foca-focus="focused == 2"
38 ng-focus="focused = 2" 38 ng-focus="focused = 2"
39 ng-keypress="next($event.keyCode)" 39 ng-keypress="next($event.keyCode)"
40 /> 40 />
41 </div> 41 </div>
42 </div> 42 </div>
43 <div class="form-group d-flex mb-2 col-md-6"> 43 <div class="form-group d-flex mb-2 col-md-6">
44 <label class="col-form-label col-md-4">Dominio semi</label> 44 <label class="col-form-label col-md-4">Dominio semi</label>
45 <div class="input-group col-md-8 pl-0"> 45 <div class="input-group col-md-8 pl-0">
46 <input 46 <input
47 class="form-control" 47 class="form-control"
48 type="text" 48 type="text"
49 teclado-virtual 49 teclado-virtual
50 ng-model="vehiculo.semi" 50 ng-model="vehiculo.semi"
51 ng-required="true" 51 ng-required="true"
52 foca-focus="focused == 3" 52 foca-focus="focused == 3"
53 ng-focus="focused = 3" 53 ng-focus="focused = 3"
54 ng-keypress="next($event.keyCode)" 54 ng-keypress="next($event.keyCode)"
55 /> 55 />
56 </div> 56 </div>
57 </div> 57 </div>
58 <div class="form-group d-flex mb-2 col-md-6"> 58 <div class="form-group d-flex mb-2 col-md-6">
59 <label class="col-form-label col-md-4">Capacidad total</label> 59 <label class="col-form-label col-md-4">Capacidad total</label>
60 <div class="input-group col-md-8 pl-0"> 60 <div class="input-group col-md-8 pl-0">
61 <input 61 <input
62 class="form-control" 62 class="form-control"
63 foca-tipo-input 63 foca-tipo-input
64 solo-positivos 64 solo-positivos
65 teclado-virtual 65 teclado-virtual
66 ng-model="vehiculo.capacidad" 66 ng-model="vehiculo.capacidad"
67 ng-required="true" 67 ng-required="true"
68 foca-focus="focused == 4" 68 foca-focus="focused == 4"
69 ng-focus="focused = 4" 69 ng-focus="focused = 4"
70 ng-disabled="!nuevo" 70 ng-disabled="nuevo || !nuevo"
71 /> 71 />
72 </div> 72 </div>
73 </div> 73 </div>
74 </div> 74 </div>
75 </form> 75 </form>
76 <div> 76 <div>
77 <h5 class="pl-4 table-title">Cisternas</h5> 77 <h5 class="pl-4 table-title">Cisternas</h5>
78 <table class="table table-default table-hover table-sm table-abm table-striped mb-0" > 78 <table class="table table-default table-hover table-sm table-abm table-striped mb-0" >
79 <thead> 79 <thead>
80 <tr> 80 <tr>
81 <th class="text-center px-4">Código</th> 81 <th class="text-center px-4">Código</th>
82 <th class="text-center">Capacidad</th> 82 <th class="text-center">Capacidad</th>
83 <th class="text-center">Unidad de Medida</th> 83 <th class="text-center">Unidad de Medida</th>
84 <th class="text-center"> 84 <th class="text-center">
85 <button 85 <button
86 class="btn btn-outline-debo boton-accion" 86 class="btn btn-outline-debo boton-accion"
87 title="Agregar Cisterna" 87 title="Agregar Cisterna"
88 ng-click="crearCisterna(); focused = 1" 88 ng-click="crearCisterna(); focused = 1"
89 ng-disabled="crear" 89 ng-disabled="crear"
90 foca-focus="focused == 5" 90 foca-focus="focused == 5"
91 ng-focus="focused = 5" 91 ng-focus="focused = 5"
92 > 92 >
93 <i class="fa fa-plus"></i> 93 <i class="fa fa-plus"></i>
94 </button> 94 </button>
95 </th> 95 </th>
96 </tr> 96 </tr>
97 </thead> 97 </thead>
98 <tbody> 98 <tbody>
99 <tr ng-show="creando"> 99 <tr ng-show="creando">
100 <td align="center"> 100 <td align="center">
101 <input 101 <input
102 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 102 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
103 ng-model="cisterna.codigo" 103 ng-model="cisterna.codigo"
104 ng-keypress="next($event.keyCode)" 104 ng-keypress="next($event.keyCode)"
105 foca-focus="focused == 1" 105 foca-focus="focused == 1"
106 ng-focus="focused = 1" 106 ng-focus="focused = 1"
107 ng-disabled="!nuevoCisterna" 107 ng-disabled="!nuevoCisterna"
108 teclado-virtual 108 teclado-virtual
109 > 109 >
110 </td> 110 </td>
111 <td align="center"> 111 <td align="center">
112 <input 112 <input
113 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 113 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
114 teclado-virtual 114 teclado-virtual
115 foca-tipo-input 115 foca-tipo-input
116 solo-positivos 116 solo-positivos
117 ng-model="cisterna.capacidad" 117 ng-model="cisterna.capacidad"
118 ng-required="true" 118 ng-required="true"
119 ng-keypress="next($event.keyCode)" 119 ng-keypress="next($event.keyCode)"
120 foca-focus="focused == 2" 120 foca-focus="focused == 2"
121 ng-focus="focused = 2" 121 ng-focus="focused = 2"
122 > 122 >
123 </td> 123 </td>
124 <td align="center"> 124 <td align="center">
125 <div class="input-group"> 125 <div class="input-group">
126 <input 126 <input
127 ng-model="cisterna.unidadMedida.NOM" 127 ng-model="cisterna.unidadMedida.NOM"
128 class="form-control" 128 class="form-control"
129 readonly 129 readonly
130 /> 130 />
131 <div class="input-group-append"> 131 <div class="input-group-append">
132 <button 132 <button
133 ladda="searchLoading" 133 ladda="searchLoading"
134 class="btn btn-outline-secondary form-control" 134 class="btn btn-outline-secondary form-control"
135 type="button" 135 type="button"
136 ng-click="seleccionarUnidadMedida()" 136 ng-click="seleccionarUnidadMedida()"
137 foca-focus="focused == 3" 137 foca-focus="focused == 3"
138 > 138 >
139 <i class="fa fa-search" aria-hidden="true"></i> 139 <i class="fa fa-search" aria-hidden="true"></i>
140 </button> 140 </button>
141 </div> 141 </div>
142 </div> 142 </div>
143 </td> 143 </td>
144 <td align="center"> 144 <td align="center">
145 <button 145 <button
146 class="btn btn-outline-dark boton-accion" 146 class="btn btn-outline-dark boton-accion"
147 ng-click="agregarCisterna()" 147 ng-click="agregarCisterna()"
148 > 148 >
149 <i class="fa fa-save"></i> 149 <i class="fa fa-save"></i>
150 </button> 150 </button>
151 </td> 151 </td>
152 </tr> 152 </tr>
153 153
154 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado"> 154 <tr ng-repeat="(key, cisterna) in cisternas | filter:filtros" ng-hide="cisterna.desactivado">
155 <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td> 155 <td ng-bind="cisterna.codigo" class="text-center" ng-hide="cisterna.editando"></td>
156 <td align="center" ng-show="cisterna.editando"> 156 <td align="center" ng-show="cisterna.editando">
157 <input 157 <input
158 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 158 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
159 ng-model="cisterna.codigo" 159 ng-model="cisterna.codigo"
160 ng-keypress="next($event.keyCode)" 160 ng-keypress="next($event.keyCode)"
161 foca-focus="focused == 1" 161 foca-focus="focused == 1"
162 ng-focus="focused = 1" 162 ng-focus="focused = 1"
163 teclado-virtual 163 teclado-virtual
164 esc-key="volver(cisterna, key)" 164 esc-key="volver(cisterna, key)"
165 > 165 >
166 </td> 166 </td>
167 <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td> 167 <td ng-bind="cisterna.capacidad" class="text-center" ng-hide="cisterna.editando"></td>
168 <td align="center" ng-show="cisterna.editando" > 168 <td align="center" ng-show="cisterna.editando" >
169 <input 169 <input
170 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched" 170 class="form-control text-uppercase foca-input ng-not-empty ng-valid ng-valid-required ng-touched"
171 teclado-virtual 171 teclado-virtual
172 foca-tipo-input 172 foca-tipo-input
173 solo-positivos 173 solo-positivos
174 ng-model="cisterna.capacidad" 174 ng-model="cisterna.capacidad"
175 ng-required="true" 175 ng-required="true"
176 ng-keypress="next($event.keyCode)" 176 ng-keypress="next($event.keyCode)"
177 foca-focus="focused == 2" 177 foca-focus="focused == 2"
178 ng-focus="focused = 2" 178 ng-focus="focused = 2"
179 esc-key="volver(cisterna, key)" 179 esc-key="volver(cisterna, key)"
180 > 180 >
181 </td> 181 </td>
182 <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td> 182 <td ng-bind="cisterna.unidadMedida.NOM" class="text-center" ng-hide="cisterna.editando"></td>
183 <td align="center" ng-show="cisterna.editando"> 183 <td align="center" ng-show="cisterna.editando">
184 <div class="input-group"> 184 <div class="input-group">
185 <input 185 <input
186 ng-model="cisterna.unidadMedida.NOM" 186 ng-model="cisterna.unidadMedida.NOM"
187 class="form-control" 187 class="form-control"
188 ng-keypress="seleccionarUnidadMedida($event.keyCode,cisterna)"
188 readonly 189 readonly
189 esc-key="volver(cisterna, key)" 190 esc-key="volver(cisterna, key)"
190 /> 191 />
191 <div class="input-group-append"> 192 <div class="input-group-append">
192 <button 193 <button
193 ladda="searchLoading" 194 ladda="searchLoading"
194 class="btn btn-outline-secondary form-control" 195 class="btn btn-outline-secondary form-control"
195 type="button" 196 type="button"
196 ng-click="seleccionarUnidadMedida(cisterna)" 197 ng-click="seleccionarUnidadMedida(13,cisterna)"
197 foca-focus="focused == 3" 198 foca-focus="focused == 3"
198 > 199 >
199 <i class="fa fa-search" aria-hidden="true"></i> 200 <i class="fa fa-search" aria-hidden="true"></i>
200 </button> 201 </button>
201 </div> 202 </div>
202 </div> 203 </div>
203 </td> 204 </td>
204 <td class="text-center" ng-hide="cisterna.editando"> 205 <td class="text-center" ng-hide="cisterna.editando">
205 <button 206 <button
206 class="btn btn-outline-dark boton-accion" 207 class="btn btn-outline-dark boton-accion"
207 title="Editar" 208 title="Editar"
208 ng-click="editar(cisterna)" 209 ng-click="editar(cisterna)"
209 > 210 >
210 <i class="fa fa-pencil"></i> 211 <i class="fa fa-pencil"></i>
211 </button> 212 </button>
212 <button 213 <button
213 class="btn btn-outline-dark boton-accion" 214 class="btn btn-outline-dark boton-accion"
214 title="Eliminar" 215 title="Eliminar"
215 ng-click="solicitarConfirmacionTabla(cisterna, $index)" 216 ng-click="solicitarConfirmacionTabla(cisterna, $index)"
216 > 217 >
217 <i class="fa fa-trash"></i> 218 <i class="fa fa-trash"></i>
218 </button> 219 </button>
219 </td> 220 </td>
220 <td align="center" ng-show="cisterna.editando" > 221 <td align="center" ng-show="cisterna.editando" >
221 <button 222 <button
222 class="btn btn-outline-dark boton-accion" 223 class="btn btn-outline-dark boton-accion"
223 ng-click="agregarCisterna(cisterna)" 224 ng-click="agregarCisterna(cisterna)"
224 > 225 >
225 <i class="fa fa-save"></i> 226 <i class="fa fa-save"></i>
226 </button> 227 </button>
227 <button 228 <button
228 class="btn btn-outline-dark boton-accion" 229 class="btn btn-outline-dark boton-accion"
229 ng-click="volver(cisterna, key)" 230 ng-click="volver(cisterna, key)"
230 > 231 >
231 <i class="fa fa-undo" aria-hidden="true"></i> 232 <i class="fa fa-undo" aria-hidden="true"></i>
232 </button> 233 </button>
233 </td> 234 </td>
234 </tr> 235 </tr>
235 <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false"> 236 <tr ng-repeat="(key, cisterna) in cisternas" ng-show="false">
236 </tr> 237 </tr>
237 </body> 238 </body>
238 </table> 239 </table>
239 </div> 240 </div>
240 </div> 241 </div>
241 </div> 242 </div>
242 243