Commit 14154ecf70826acff58da0b6948d36d9dff3876a
1 parent
7d68d24ce9
Exists in
master
boton pausar funcionando
Showing
3 changed files
with
106 additions
and
36 deletions
Show diff stats
src/js/controller.js
... | ... | @@ -9,9 +9,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
9 | 9 | 'focaModalService', |
10 | 10 | 'focaBotoneraLateralService', |
11 | 11 | 'focaLoginService', |
12 | + '$localStorage', | |
12 | 13 | function($scope, $uibModal, $location, $filter, $timeout, |
13 | 14 | focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, |
14 | - focaLoginSrv) | |
15 | + focaLoginSrv, $localStorage) | |
15 | 16 | { |
16 | 17 | config(); |
17 | 18 | |
... | ... | @@ -33,6 +34,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
33 | 34 | }); |
34 | 35 | |
35 | 36 | init(); |
37 | + $timeout(function() {getLSHojaRuta();}); | |
36 | 38 | } |
37 | 39 | |
38 | 40 | function init() { |
... | ... | @@ -48,10 +50,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
48 | 50 | transportista: {}, |
49 | 51 | tarifario: { |
50 | 52 | costo: null |
51 | - } | |
53 | + }, | |
54 | + remitosTabla: [] | |
52 | 55 | }; |
53 | 56 | |
54 | - $scope.remitosTabla = []; | |
55 | 57 | $scope.idLista = undefined; |
56 | 58 | |
57 | 59 | focaCrearHojaRutaService.getNumeroHojaRuta().then( |
... | ... | @@ -65,15 +67,18 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
65 | 67 | } |
66 | 68 | ); |
67 | 69 | |
68 | - $scope.inicial = { | |
69 | - hojaRuta: angular.copy($scope.hojaRuta), | |
70 | - remitosTabla: angular.copy($scope.remitosTabla), | |
71 | - idLista: angular.copy($scope.idLista) | |
72 | - }; | |
70 | + $scope.inicial = angular.copy($scope.hojaRuta); | |
73 | 71 | } |
74 | 72 | |
73 | + $scope.$watch('hojaRuta', function(newValue, oldValue) { | |
74 | + focaBotoneraLateralService.setPausarData({ | |
75 | + label: 'hojaRuta', | |
76 | + val: newValue | |
77 | + }); | |
78 | + }, true); | |
79 | + | |
75 | 80 | $scope.crearHojaRuta = function() { |
76 | - if(!$scope.remitosTabla.length) { | |
81 | + if(!$scope.hojaRuta.remitosTabla.length) { | |
77 | 82 | focaModalService.alert('Ingrese Remitos'); |
78 | 83 | return; |
79 | 84 | } |
... | ... | @@ -107,10 +112,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
107 | 112 | idChofer: $scope.hojaRuta.chofer.id, |
108 | 113 | idVehiculo: $scope.hojaRuta.vehiculo.id, |
109 | 114 | tarifaFlete: $scope.hojaRuta.tarifario.costo, |
110 | - fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10), | |
115 | + fechaReparto: new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10), | |
111 | 116 | estado: 0 |
112 | 117 | }, |
113 | - remitos: $scope.remitosTabla | |
118 | + remitos: $scope.hojaRuta.remitosTabla | |
114 | 119 | }; |
115 | 120 | save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra); |
116 | 121 | focaCrearHojaRutaService.crearHojaRuta(save).then( |
... | ... | @@ -251,8 +256,8 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
251 | 256 | modalInstance.result.then( |
252 | 257 | function(remito) { |
253 | 258 | // TODO: borrar cuando no se use definitivamente |
254 | - // for (var i = $scope.remitosTabla.length - 1; i >= 0; i--) { | |
255 | - // if ($scope.remitosTabla[i].id === remito.id) { | |
259 | + // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) { | |
260 | + // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) { | |
256 | 261 | // focaModalService.alert('Remito ya incluido'); |
257 | 262 | // return; |
258 | 263 | // } |
... | ... | @@ -283,7 +288,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
283 | 288 | // remito.litros = litros; |
284 | 289 | // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros; |
285 | 290 | $scope.cargarCisterna(remito.id).then(function() { |
286 | - $scope.remitosTabla.push(remito); | |
291 | + $scope.hojaRuta.remitosTabla.push(remito); | |
287 | 292 | $scope.seleccionarRemitos(); |
288 | 293 | }, function() { |
289 | 294 | $scope.seleccionarRemitos(); |
... | ... | @@ -310,7 +315,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
310 | 315 | resolve: { |
311 | 316 | idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;}, |
312 | 317 | idRemito: function() {return idRemito;}, |
313 | - fechaReparto: function() {return $scope.fechaReparto;} | |
318 | + fechaReparto: function() {return $scope.hojaRuta.fechaReparto;} | |
314 | 319 | } |
315 | 320 | } |
316 | 321 | ); |
... | ... | @@ -318,7 +323,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
318 | 323 | }; |
319 | 324 | |
320 | 325 | $scope.seleccionarFechaEntrega = function() { |
321 | - if(!$scope.fechaReparto) { | |
326 | + if(!$scope.hojaRuta.fechaReparto) { | |
322 | 327 | elegirFecha(); |
323 | 328 | return; |
324 | 329 | } |
... | ... | @@ -359,9 +364,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
359 | 364 | focaModalService.confirm('ยฟEstรก seguro que desea desasociar este remito del' + |
360 | 365 | ' vehรญculo?').then(function() { |
361 | 366 | focaCrearHojaRutaService.desasociarRemitos(idsRemito, |
362 | - $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then( | |
367 | + $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1).then( | |
363 | 368 | function() { |
364 | - $scope.remitosTabla.splice(key, 1); | |
369 | + $scope.hojaRuta.remitosTabla.splice(key, 1); | |
365 | 370 | focaModalService.alert('Remito desasociado con รฉxito'); |
366 | 371 | } |
367 | 372 | ); |
... | ... | @@ -374,7 +379,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
374 | 379 | label: 'Fecha de entrega:', |
375 | 380 | valor: fecha.toLocaleDateString() |
376 | 381 | }); |
377 | - $scope.fechaReparto = fecha; | |
382 | + $scope.hojaRuta.fechaReparto = fecha; | |
378 | 383 | }); |
379 | 384 | } |
380 | 385 | |
... | ... | @@ -387,7 +392,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
387 | 392 | } |
388 | 393 | |
389 | 394 | function eligioFecha() { |
390 | - if(!$scope.fechaReparto) { | |
395 | + if(!$scope.hojaRuta.fechaReparto) { | |
391 | 396 | focaModalService.alert('Primero seleccione fecha de reparto'); |
392 | 397 | return false; |
393 | 398 | } |
... | ... | @@ -406,7 +411,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
406 | 411 | var parametrosModal = {}; |
407 | 412 | if(preCargados) { |
408 | 413 | parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' + |
409 | - $scope.fechaReparto.toISOString().substring(0, 10); | |
414 | + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10); | |
410 | 415 | parametrosModal.titulo = 'Bรบsqueda de vehiculos pre confirmados'; |
411 | 416 | }else { |
412 | 417 | parametrosModal.query = '/vehiculo'; |
... | ... | @@ -439,15 +444,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
439 | 444 | ' - ' + vehiculo.transportista.NOM |
440 | 445 | }); |
441 | 446 | focaCrearHojaRutaService |
442 | - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) | |
447 | + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto) | |
443 | 448 | .then(function(res) { |
444 | - $scope.remitosTabla = res.data; | |
449 | + $scope.hojaRuta.remitosTabla = res.data; | |
445 | 450 | }); |
446 | 451 | }else { |
447 | 452 | focaCrearHojaRutaService |
448 | - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) | |
453 | + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true) | |
449 | 454 | .then(function(res) { |
450 | - $scope.remitosTabla = res.data; | |
455 | + $scope.hojaRuta.remitosTabla = res.data; | |
451 | 456 | }); |
452 | 457 | } |
453 | 458 | $scope.$broadcast('addCabecera', { |
... | ... | @@ -470,8 +475,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
470 | 475 | for(var i = 0; i < vehiculo.cisternas.length; i++) { |
471 | 476 | for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { |
472 | 477 | var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; |
473 | - if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto | |
474 | - .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && | |
478 | + if(cisternaCarga.fechaReparto.substring(0, 10) === | |
479 | + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) && | |
480 | + cisternaCarga.idUsuarioProceso && | |
475 | 481 | cisternaCarga.idUsuarioProceso !== idUsuario) |
476 | 482 | { |
477 | 483 | focaModalService.alert('El vehรญculo estรก siendo usado por otro' + |
... | ... | @@ -486,11 +492,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
486 | 492 | function salir() { |
487 | 493 | var confirmacion = false; |
488 | 494 | |
489 | - angular.forEach($scope.inicial, function(valor, key) { | |
490 | - if (!angular.equals($scope[key], $scope.inicial[key])) { | |
491 | - confirmacion = true; | |
492 | - } | |
493 | - }); | |
495 | + if (!angular.equals($scope.hojaRuta, $scope.inicial)) { | |
496 | + confirmacion = true; | |
497 | + } | |
494 | 498 | |
495 | 499 | if (confirmacion) { |
496 | 500 | focaModalService.confirm( |
... | ... | @@ -504,5 +508,70 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', |
504 | 508 | $location.path('/'); |
505 | 509 | } |
506 | 510 | } |
511 | + | |
512 | + function setearHojaRuta(hojaRuta) { | |
513 | + $scope.$broadcast('cleanCabecera'); | |
514 | + | |
515 | + var cabeceras = []; | |
516 | + if (hojaRuta.fechaReparto) { | |
517 | + cabeceras.push({ | |
518 | + label: 'Fecha de entrega:', | |
519 | + valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy') | |
520 | + }); | |
521 | + } | |
522 | + if (hojaRuta.transportista.COD) { | |
523 | + cabeceras.push({ | |
524 | + label: 'Transportista:', | |
525 | + valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' + | |
526 | + hojaRuta.transportista.NOM | |
527 | + }); | |
528 | + } | |
529 | + if (hojaRuta.chofer.id) { | |
530 | + cabeceras.push({ | |
531 | + label: 'Chofer:', | |
532 | + valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) + | |
533 | + ' - ' + hojaRuta.chofer.nombre | |
534 | + }); | |
535 | + } | |
536 | + if (hojaRuta.vehiculo.id) { | |
537 | + cabeceras.push({ | |
538 | + label: 'Tractor:', | |
539 | + valor: hojaRuta.vehiculo.tractor | |
540 | + }); | |
541 | + cabeceras.push({ | |
542 | + label: 'Semi:', | |
543 | + valor: hojaRuta.vehiculo.semi | |
544 | + }); | |
545 | + cabeceras.push({ | |
546 | + label: 'Capacidad:', | |
547 | + valor: hojaRuta.vehiculo.capacidad | |
548 | + }); | |
549 | + } | |
550 | + if (hojaRuta.tarifario.costo) { | |
551 | + cabeceras.push({ | |
552 | + label: 'Tarifario:', | |
553 | + valor: hojaRuta.tarifario.costo | |
554 | + }); | |
555 | + } | |
556 | + | |
557 | + addArrayCabecera(cabeceras); | |
558 | + $scope.hojaRuta = hojaRuta; | |
559 | + } | |
560 | + | |
561 | + function getLSHojaRuta() { | |
562 | + var hojaRuta = JSON.parse($localStorage.hojaRuta || null); | |
563 | + if (hojaRuta) { | |
564 | + setearHojaRuta(hojaRuta); | |
565 | + delete $localStorage.hojaRuta; | |
566 | + } | |
567 | + } | |
568 | + function addArrayCabecera(array) { | |
569 | + for(var i = 0; i < array.length; i++) { | |
570 | + $scope.$broadcast('addCabecera', { | |
571 | + label: array[i].label, | |
572 | + valor: array[i].valor | |
573 | + }); | |
574 | + } | |
575 | + } | |
507 | 576 | } |
508 | 577 | ]); |
src/js/service.js
1 | 1 | angular.module('focaCrearHojaRuta') |
2 | - .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', function($http, API_ENDPOINT) { | |
2 | + .service('focaCrearHojaRutaService', ['$http', 'API_ENDPOINT', | |
3 | + function($http, API_ENDPOINT) { | |
3 | 4 | var route = API_ENDPOINT.URL; |
4 | 5 | return { |
5 | 6 | crearHojaRuta: function(hojaRuta) { |
src/views/hoja-ruta.html
... | ... | @@ -45,9 +45,9 @@ |
45 | 45 | </thead> |
46 | 46 | <tbody class="tabla-articulo-body"> |
47 | 47 | <tr |
48 | - ng-repeat="(key, remito) in remitosTabla" | |
48 | + ng-repeat="(key, remito) in hojaRuta.remitosTabla" | |
49 | 49 | class="d-flex" |
50 | - ng-show="show || key == remitosTabla.length - 1" | |
50 | + ng-show="show || key == hojaRuta.remitosTabla.length - 1" | |
51 | 51 | > |
52 | 52 | <td ng-bind="key + 1" class="col-auto"></td> |
53 | 53 | <td |
... | ... | @@ -70,7 +70,7 @@ |
70 | 70 | <tr class="d-flex"> |
71 | 71 | <td class="col-auto px-1"> |
72 | 72 | <strong>Remitos:</strong> |
73 | - <a ng-bind="remitosTabla.length"></a> | |
73 | + <a ng-bind="hojaRuta.remitosTabla.length"></a> | |
74 | 74 | </td> |
75 | 75 | <td class="col"></td> |
76 | 76 | <td class="col-auto px-1"> |