Commit 4c26d0978431f758f6a700a16965eb153f843fb5

Authored by Jose Pinto
Exists in master

Merge branch 'master' into 'master'

Master(efernandez)

See merge request !15
src/js/controller.js
... ... @@ -8,8 +8,11 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
8 8 'focaCrearHojaRutaService',
9 9 'focaModalService',
10 10 'focaBotoneraLateralService',
  11 + 'focaLoginService',
11 12 function($scope, $uibModal, $location, $filter, $timeout,
12   - focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) {
  13 + focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService,
  14 + focaLoginSrv)
  15 + {
13 16  
14 17 $scope.botonera = focaCrearHojaRutaService.getBotonera();
15 18 $scope.datepickerAbierto = false;
... ... @@ -173,7 +176,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
173 176 };
174 177  
175 178 $scope.seleccionarVehiculo = function() {
176   - if(eligioPreConfirmado()) return;
  179 + if(!eligioFecha() || eligioPreConfirmado()) return;
177 180 modalVehiculos();
178 181 };
179 182  
... ... @@ -395,6 +398,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
395 398 propiedad: ['codigo', 'tractor', 'semi']
396 399 };
397 400 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) {
  401 + if(vehiculoEnUso(vehiculo)) return;
398 402 $scope.hojaRuta.vehiculo = vehiculo;
399 403 $scope.hojaRuta.transportista = vehiculo.transportista;
400 404 if(preCargados) {
... ... @@ -406,9 +410,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
406 410 });
407 411 focaCrearHojaRutaService
408 412 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
409   - .then(function(res) {
410   - $scope.remitosTabla = res.data;
411   - });
  413 + .then(function(res) {
  414 + $scope.remitosTabla = res.data;
  415 + });
  416 + }else {
  417 + focaCrearHojaRutaService
  418 + .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true)
  419 + .then(function(res) {
  420 + $scope.remitosTabla = res.data;
  421 + });
412 422 }
413 423 $scope.$broadcast('addCabecera', {
414 424 label: 'Tractor:',
... ... @@ -424,5 +434,23 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
424 434 });
425 435 });
426 436 }
  437 +
  438 + function vehiculoEnUso(vehiculo) {
  439 + var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
  440 + for(var i = 0; i < vehiculo.cisternas.length; i++) {
  441 + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  442 + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
  443 + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
  444 + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso &&
  445 + cisternaCarga.idUsuarioProceso !== idUsuario)
  446 + {
  447 + focaModalService.alert('El vehículo está siendo usado por otro' +
  448 + ' usuario');
  449 + return true;
  450 + }
  451 + }
  452 + }
  453 + return false;
  454 + }
427 455 }
428 456 ]);
... ... @@ -55,9 +55,10 @@ angular.module(&#39;focaCrearHojaRuta&#39;)
55 55 getNumeroHojaRuta: function() {
56 56 return $http.get(route + '/hoja-ruta/numero-siguiente');
57 57 },
58   - getRemitosByIdVehiculo: function(idVehiculo, fechaReparto) {
  58 + getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) {
  59 + var noCofirmados = sinConfirmar ? '/sinConfirmar' : '';
59 60 return $http.get(route + '/vehiculo/obtener/remitos/' +
60   - idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10));
  61 + idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados);
61 62 },
62 63 desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) {
63 64 return $http.post(route + '/vehiculo/desasociar-remitos',