Commit c393faa6f8783ca9dbf9f6436a004b1e03b39b9b

Authored by Jose Pinto
Exists in master and in 2 other branches develop, lab

Merge branch 'master' into 'master'

Master

See merge request !27
... ... @@ -11,6 +11,7 @@ const replace = require('gulp-replace');
11 11 const connect = require('gulp-connect');
12 12 const header = require('gulp-header');
13 13 const footer = require('gulp-footer');
  14 +const gulpSequence = require('gulp-sequence');
14 15  
15 16 var paths = {
16 17 srcJS: 'src/js/*.js',
... ... @@ -20,7 +21,9 @@ var paths = {
20 21 dist: 'dist/'
21 22 };
22 23  
23   -gulp.task('templates', ['clean'], function() {
  24 +gulp.task('uglify', gulpSequence('clean', ['templates', 'uglify-spec'], 'uglify-app'));
  25 +
  26 +gulp.task('templates', function() {
24 27 return pump(
25 28 [
26 29 gulp.src(paths.srcViews),
... ... @@ -34,7 +37,7 @@ gulp.task('templates', ['clean'], function() {
34 37 );
35 38 });
36 39  
37   -gulp.task('uglify', ['templates', 'uglify-spec'], function() {
  40 +gulp.task('uglify-app', function() {
38 41 return pump(
39 42 [
40 43 gulp.src([
... ... @@ -83,7 +86,7 @@ gulp.task('pre-commit', function() {
83 86 gulp.task('webserver', function() {
84 87 pump [
85 88 connect.server({port: 3300, host: '0.0.0.0'})
86   - ]
  89 + ];
87 90 });
88 91  
89 92 gulp.task('clean-post-install', function() {
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,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
48 50 transportista: {},
49 51 tarifario: {
50 52 costo: null
51   - }
  53 + },
  54 + remitosTabla: []
52 55 };
53   -
54   - $scope.remitosTabla = [];
55 56 $scope.idLista = undefined;
56 57  
57 58 focaCrearHojaRutaService.getNumeroHojaRuta().then(
... ... @@ -65,15 +66,18 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
65 66 }
66 67 );
67 68  
68   - $scope.inicial = {
69   - hojaRuta: angular.copy($scope.hojaRuta),
70   - remitosTabla: angular.copy($scope.remitosTabla),
71   - idLista: angular.copy($scope.idLista)
72   - };
  69 + $scope.inicial = angular.copy($scope.hojaRuta);
73 70 }
74 71  
  72 + $scope.$watch('hojaRuta', function(newValue, oldValue) {
  73 + focaBotoneraLateralService.setPausarData({
  74 + label: 'hojaRuta',
  75 + val: newValue
  76 + });
  77 + }, true);
  78 +
75 79 $scope.crearHojaRuta = function() {
76   - if(!$scope.remitosTabla.length) {
  80 + if(!$scope.hojaRuta.remitosTabla.length) {
77 81 focaModalService.alert('Ingrese Remitos');
78 82 return;
79 83 }
... ... @@ -107,10 +111,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
107 111 idChofer: $scope.hojaRuta.chofer.id,
108 112 idVehiculo: $scope.hojaRuta.vehiculo.id,
109 113 tarifaFlete: $scope.hojaRuta.tarifario.costo,
110   - fechaReparto: $scope.fechaReparto.toISOString().substring(0, 10),
  114 + fechaReparto: new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10),
111 115 estado: 0
112 116 },
113   - remitos: $scope.remitosTabla
  117 + remitos: $scope.hojaRuta.remitosTabla
114 118 };
115 119 save.hojaRuta = angular.extend({}, save.hojaRuta, $scope.hojaRuta.datosExtra);
116 120 focaCrearHojaRutaService.crearHojaRuta(save).then(
... ... @@ -251,8 +255,8 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
251 255 modalInstance.result.then(
252 256 function(remito) {
253 257 // 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) {
  258 + // for (var i = $scope.hojaRuta.remitosTabla.length - 1; i >= 0; i--) {
  259 + // if ($scope.hojaRuta.remitosTabla[i].id === remito.id) {
256 260 // focaModalService.alert('Remito ya incluido');
257 261 // return;
258 262 // }
... ... @@ -283,7 +287,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
283 287 // remito.litros = litros;
284 288 // $scope.hojaRuta.litros = $scope.hojaRuta.litros + litros;
285 289 $scope.cargarCisterna(remito.id).then(function() {
286   - $scope.remitosTabla.push(remito);
  290 + $scope.hojaRuta.remitosTabla.push(remito);
287 291 $scope.seleccionarRemitos();
288 292 }, function() {
289 293 $scope.seleccionarRemitos();
... ... @@ -310,7 +314,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
310 314 resolve: {
311 315 idVehiculo: function() {return $scope.hojaRuta.vehiculo.id;},
312 316 idRemito: function() {return idRemito;},
313   - fechaReparto: function() {return $scope.fechaReparto;}
  317 + fechaReparto: function() {return $scope.hojaRuta.fechaReparto;}
314 318 }
315 319 }
316 320 );
... ... @@ -318,7 +322,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
318 322 };
319 323  
320 324 $scope.seleccionarFechaEntrega = function() {
321   - if(!$scope.fechaReparto) {
  325 + if (!$scope.hojaRuta.fechaReparto) {
322 326 elegirFecha();
323 327 return;
324 328 }
... ... @@ -359,9 +363,9 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
359 363 focaModalService.confirm('ยฟEstรก seguro que desea desasociar este remito del' +
360 364 ' vehรญculo?').then(function() {
361 365 focaCrearHojaRutaService.desasociarRemitos(idsRemito,
362   - $scope.hojaRuta.vehiculo.id, $scope.remitosTabla.length <= 1).then(
  366 + $scope.hojaRuta.vehiculo.id, $scope.hojaRuta.remitosTabla.length <= 1).then(
363 367 function() {
364   - $scope.remitosTabla.splice(key, 1);
  368 + $scope.hojaRuta.remitosTabla.splice(key, 1);
365 369 focaModalService.alert('Remito desasociado con รฉxito');
366 370 }
367 371 );
... ... @@ -374,7 +378,7 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
374 378 label: 'Fecha de entrega:',
375 379 valor: fecha.toLocaleDateString()
376 380 });
377   - $scope.fechaReparto = fecha;
  381 + $scope.hojaRuta.fechaReparto = fecha;
378 382 });
379 383 }
380 384  
... ... @@ -387,7 +391,7 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
387 391 }
388 392  
389 393 function eligioFecha() {
390   - if(!$scope.fechaReparto) {
  394 + if(!$scope.hojaRuta.fechaReparto) {
391 395 focaModalService.alert('Primero seleccione fecha de reparto');
392 396 return false;
393 397 }
... ... @@ -406,7 +410,7 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
406 410 var parametrosModal = {};
407 411 if(preCargados) {
408 412 parametrosModal.query = '/vehiculo/obtener/pre-confirmados/' +
409   - $scope.fechaReparto.toISOString().substring(0, 10);
  413 + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10);
410 414 parametrosModal.titulo = 'Bรบsqueda de vehiculos pre confirmados';
411 415 }else {
412 416 parametrosModal.query = '/vehiculo';
... ... @@ -439,15 +443,15 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
439 443 ' - ' + vehiculo.transportista.NOM
440 444 });
441 445 focaCrearHojaRutaService
442   - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
  446 + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto)
443 447 .then(function(res) {
444   - $scope.remitosTabla = res.data;
  448 + $scope.hojaRuta.remitosTabla = res.data;
445 449 });
446 450 }else {
447 451 focaCrearHojaRutaService
448   - .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true)
  452 + .getRemitosByIdVehiculo(vehiculo.id, $scope.hojaRuta.fechaReparto, true)
449 453 .then(function(res) {
450   - $scope.remitosTabla = res.data;
  454 + $scope.hojaRuta.remitosTabla = res.data;
451 455 });
452 456 }
453 457 $scope.$broadcast('addCabecera', {
... ... @@ -467,11 +471,12 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
467 471  
468 472 function vehiculoEnUso(vehiculo) {
469 473 var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
470   - for(var i = 0; i < vehiculo.cisternas.length; i++) {
471   - for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  474 + for (var i = 0; i < vehiculo.cisternas.length; i++) {
  475 + for (var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
472 476 var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
473   - if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
474   - .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso &&
  477 + if (cisternaCarga.fechaReparto.substring(0, 10) ===
  478 + new Date($scope.hojaRuta.fechaReparto).toISOString().substring(0, 10) &&
  479 + cisternaCarga.idUsuarioProceso &&
475 480 cisternaCarga.idUsuarioProceso !== idUsuario)
476 481 {
477 482 focaModalService.alert('El vehรญculo estรก siendo usado por otro' +
... ... @@ -486,11 +491,9 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
486 491 function salir() {
487 492 var confirmacion = false;
488 493  
489   - angular.forEach($scope.inicial, function(valor, key) {
490   - if (!angular.equals($scope[key], $scope.inicial[key])) {
491   - confirmacion = true;
492   - }
493   - });
  494 + if (!angular.equals($scope.hojaRuta, $scope.inicial)) {
  495 + confirmacion = true;
  496 + }
494 497  
495 498 if (confirmacion) {
496 499 focaModalService.confirm(
... ... @@ -504,5 +507,70 @@ angular.module(&#39;focaCrearHojaRuta&#39;) .controller(&#39;hojaRutaCtrl&#39;,
504 507 $location.path('/');
505 508 }
506 509 }
  510 +
  511 + function setearHojaRuta(hojaRuta) {
  512 + $scope.$broadcast('cleanCabecera');
  513 +
  514 + var cabeceras = [];
  515 + if (hojaRuta.fechaReparto) {
  516 + cabeceras.push({
  517 + label: 'Fecha de entrega:',
  518 + valor: $filter('date')(hojaRuta.fechaReparto, 'dd/MM/yyyy')
  519 + });
  520 + }
  521 + if (hojaRuta.transportista.COD) {
  522 + cabeceras.push({
  523 + label: 'Transportista:',
  524 + valor: $filter('rellenarDigitos')(hojaRuta.transportista.COD, 5) + ' - ' +
  525 + hojaRuta.transportista.NOM
  526 + });
  527 + }
  528 + if (hojaRuta.chofer.id) {
  529 + cabeceras.push({
  530 + label: 'Chofer:',
  531 + valor: $filter('rellenarDigitos')(hojaRuta.chofer.id, 3) +
  532 + ' - ' + hojaRuta.chofer.nombre
  533 + });
  534 + }
  535 + if (hojaRuta.vehiculo.id) {
  536 + cabeceras.push({
  537 + label: 'Tractor:',
  538 + valor: hojaRuta.vehiculo.tractor
  539 + });
  540 + cabeceras.push({
  541 + label: 'Semi:',
  542 + valor: hojaRuta.vehiculo.semi
  543 + });
  544 + cabeceras.push({
  545 + label: 'Capacidad:',
  546 + valor: hojaRuta.vehiculo.capacidad
  547 + });
  548 + }
  549 + if (hojaRuta.tarifario.costo) {
  550 + cabeceras.push({
  551 + label: 'Tarifario:',
  552 + valor: hojaRuta.tarifario.costo
  553 + });
  554 + }
  555 +
  556 + addArrayCabecera(cabeceras);
  557 + $scope.hojaRuta = hojaRuta;
  558 + }
  559 +
  560 + function getLSHojaRuta() {
  561 + var hojaRuta = JSON.parse($localStorage.hojaRuta || null);
  562 + if (hojaRuta) {
  563 + setearHojaRuta(hojaRuta);
  564 + delete $localStorage.hojaRuta;
  565 + }
  566 + }
  567 + function addArrayCabecera(array) {
  568 + for(var i = 0; i < array.length; i++) {
  569 + $scope.$broadcast('addCabecera', {
  570 + label: array[i].label,
  571 + valor: array[i].valor
  572 + });
  573 + }
  574 + }
507 575 }
508 576 ]);
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">