diff --git a/src/js/controller.js b/src/js/controller.js index a723f79..fe076aa 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -8,8 +8,10 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', 'focaCrearHojaRutaService', 'focaModalService', 'focaBotoneraLateralService', + 'focaLoginService', function($scope, $uibModal, $location, $filter, $timeout, - focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService) { + focaCrearHojaRutaService, focaModalService, focaBotoneraLateralService, + focaLoginSrv) { $scope.botonera = focaCrearHojaRutaService.getBotonera(); $scope.datepickerAbierto = false; @@ -173,7 +175,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }; $scope.seleccionarVehiculo = function() { - if(eligioPreConfirmado()) return; + if(!eligioFecha() || eligioPreConfirmado()) return; modalVehiculos(); }; @@ -395,6 +397,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', propiedad: ['codigo', 'tractor', 'semi'] }; focaModalService.modal(columnas, query, titulo).then(function(vehiculo) { + if(vehiculoEnUso(vehiculo)) return; $scope.hojaRuta.vehiculo = vehiculo; $scope.hojaRuta.transportista = vehiculo.transportista; if(preCargados) { @@ -406,9 +409,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); focaCrearHojaRutaService .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto) - .then(function(res) { - $scope.remitosTabla = res.data; - }); + .then(function(res) { + $scope.remitosTabla = res.data; + }); + }else { + focaCrearHojaRutaService + .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true) + .then(function(res) { + $scope.remitosTabla = res.data; + }); } $scope.$broadcast('addCabecera', { label: 'Tractor:', @@ -424,5 +433,23 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl', }); }); } + + function vehiculoEnUso(vehiculo) { + var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador; + for(var i = 0; i < vehiculo.cisternas.length; i++) { + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) { + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j]; + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso && + cisternaCarga.idUsuarioProceso !== idUsuario) + { + focaModalService.alert('El vehículo está siendo usado por otro' + + ' usuario'); + return true; + } + } + } + return false; + } } ]); diff --git a/src/js/service.js b/src/js/service.js index 13ebc65..92e5720 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -55,9 +55,10 @@ angular.module('focaCrearHojaRuta') getNumeroHojaRuta: function() { return $http.get(route + '/hoja-ruta/numero-siguiente'); }, - getRemitosByIdVehiculo: function(idVehiculo, fechaReparto) { + getRemitosByIdVehiculo: function(idVehiculo, fechaReparto, sinConfirmar) { + var noCofirmados = sinConfirmar ? '/sinConfirmar' : ''; return $http.get(route + '/vehiculo/obtener/remitos/' + - idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10)); + idVehiculo + '/' + fechaReparto.toISOString().substring(0, 10) + noCofirmados); }, desasociarRemitos: function(idsRemitos, idVehiculo, sinRemitos) { return $http.post(route + '/vehiculo/desasociar-remitos',