Commit fb6365463c3b4cf4e4ecfb679d8995141f8ba327

Authored by Eric Fernandez
1 parent ebea7927c6
Exists in master

obtengo remitos del vehiculo elegido

valido que el vehiculo no esté en uso
Showing 2 changed files with 35 additions and 7 deletions   Show diff stats
src/js/controller.js
... ... @@ -8,8 +8,10 @@ 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) {
13 15  
14 16 $scope.botonera = focaCrearHojaRutaService.getBotonera();
15 17 $scope.datepickerAbierto = false;
... ... @@ -173,7 +175,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
173 175 };
174 176  
175 177 $scope.seleccionarVehiculo = function() {
176   - if(eligioPreConfirmado()) return;
  178 + if(!eligioFecha() || eligioPreConfirmado()) return;
177 179 modalVehiculos();
178 180 };
179 181  
... ... @@ -395,6 +397,7 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
395 397 propiedad: ['codigo', 'tractor', 'semi']
396 398 };
397 399 focaModalService.modal(columnas, query, titulo).then(function(vehiculo) {
  400 + if(vehiculoEnUso(vehiculo)) return;
398 401 $scope.hojaRuta.vehiculo = vehiculo;
399 402 $scope.hojaRuta.transportista = vehiculo.transportista;
400 403 if(preCargados) {
... ... @@ -406,9 +409,15 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
406 409 });
407 410 focaCrearHojaRutaService
408 411 .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto)
409   - .then(function(res) {
410   - $scope.remitosTabla = res.data;
411   - });
  412 + .then(function(res) {
  413 + $scope.remitosTabla = res.data;
  414 + });
  415 + }else {
  416 + focaCrearHojaRutaService
  417 + .getRemitosByIdVehiculo(vehiculo.id, $scope.fechaReparto, true)
  418 + .then(function(res) {
  419 + $scope.remitosTabla = res.data;
  420 + });
412 421 }
413 422 $scope.$broadcast('addCabecera', {
414 423 label: 'Tractor:',
... ... @@ -424,5 +433,23 @@ angular.module('focaCrearHojaRuta') .controller('hojaRutaCtrl',
424 433 });
425 434 });
426 435 }
  436 +
  437 + function vehiculoEnUso(vehiculo) {
  438 + var idUsuario = focaLoginSrv.getLoginData().vendedorCobrador;
  439 + for(var i = 0; i < vehiculo.cisternas.length; i++) {
  440 + for(var j = 0; j < vehiculo.cisternas[i].cisternasCarga.length; j++) {
  441 + var cisternaCarga = vehiculo.cisternas[i].cisternasCarga[j];
  442 + if(cisternaCarga.fechaReparto.substring(0, 10) === $scope.fechaReparto
  443 + .toISOString().substring(0, 10) && cisternaCarga.idUsuarioProceso &&
  444 + cisternaCarga.idUsuarioProceso !== idUsuario)
  445 + {
  446 + focaModalService.alert('El vehículo está siendo usado por otro' +
  447 + ' usuario');
  448 + return true;
  449 + }
  450 + }
  451 + }
  452 + return false;
  453 + }
427 454 }
428 455 ]);
... ... @@ -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',