diff --git a/src/js/controller.js b/src/js/controller.js index f2a3343..3c8c1a5 100644 --- a/src/js/controller.js +++ b/src/js/controller.js @@ -14,7 +14,7 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo }; var fecha = { label: 'Fecha Reparto', - image: 'abmChofer.png' + image: 'fechaDeReparto.png' }; $scope.botonera = [fecha, transportista]; var cabecera = ''; @@ -76,6 +76,21 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo }; $scope.quitarVehiculo = function(vehiculo) { + //TODO: Pasar validación a función + $scope.fechaReparto.setHours(0, 0, 0, 0); + var idUsuario = focaLogisticaPedidoRutaService.idUsuario; + 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 !== + idUsuario) + { + focaModalService.alert('El vehículo está siendo usado por otro usuario'); + return; + } + } + } focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' + vehiculo.codigo + '?').then(function() { eliminarVehiculo(vehiculo); @@ -87,6 +102,21 @@ angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaCo focaModalService.alert('Primero seleccione fecha de reparto'); return; } + //TODO: Pasar validación a función + $scope.fechaReparto.setHours(0, 0, 0, 0); + var idUsuario = focaLogisticaPedidoRutaService.idUsuario; + 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 !== + idUsuario) + { + focaModalService.alert('El vehículo está siendo usado por otro usuario'); + return; + } + } + } var modalInstance = $uibModal.open( { ariaLabelledBy: 'Creación hoja ruta', diff --git a/src/js/controllerCerrarVehiculo.js b/src/js/controllerCerrarVehiculo.js index dd36ef7..f4fc821 100644 --- a/src/js/controllerCerrarVehiculo.js +++ b/src/js/controllerCerrarVehiculo.js @@ -13,13 +13,11 @@ angular.module('focaLogisticaPedidoRuta') $scope.remitos = []; $scope.now = new Date(); focaLogisticaPedidoRutaService.obtenerVehiculoById(idVehiculo).then(function(res) { - $scope.vehiculo = res.data; + $scope.vehiculo = res.data; }); - //TODO: refactor código esta rre feo focaLogisticaPedidoRutaService.getRemitos(idVehiculo).then(function(res) { $scope.remitos = focaLogisticaPedidoRutaService.obtenerRemitosDeCarga(res.data); }); - focaLogisticaPedidoRutaService.numeroHojaRuta().then(function(res) { $scope.sucursal = res.data.sucursal; $scope.numero = res.data.numeroHojaRuta; @@ -28,22 +26,19 @@ angular.module('focaLogisticaPedidoRuta') $uibModalInstance.close(); }; $scope.aceptar = function() { - var save = { - hojaRuta: { - id: 0, - fechaCreacion: $scope.now.toISOString().slice(0, 19).replace('T', ' '), - idTransportista: $scope.vehiculo.idTransportista, - idChofer: $scope.chofer.id, - idVehiculo: $scope.vehiculo.id, - tarifaFlete: $scope.tarifaFlete - }, - remitos: $scope.remitos, - idVehiculo: $scope.vehiculo.id - }; - focaLogisticaPedidoRutaService.crearHojaRuta(save).then(function() { - $uibModalInstance.close(); - focaModalService.alert('Hoja de ruta guardada con éxito'); + var idsRemito = []; + $scope.remitos.forEach(function(remito) { + idsRemito.push(remito.id); }); + var cierreDistribuicion = { + idsRemito: idsRemito, + fechaReparto: focaLogisticaPedidoRutaService.fecha + }; + focaLogisticaPedidoRutaService.cerrarDistribuicion(cierreDistribuicion) + .then(function() { + focaModalService.alert('Vehículo cerrado con éxito'); + } + ); }; $scope.seleccionarChofer = function() { var modalInstance = $uibModal.open( diff --git a/src/js/controllerDetalleVehiculo.js b/src/js/controllerDetalleVehiculo.js index 1270522..eecbe2b 100644 --- a/src/js/controllerDetalleVehiculo.js +++ b/src/js/controllerDetalleVehiculo.js @@ -39,16 +39,30 @@ angular.module('focaLogisticaPedidoRuta') } $scope.articulos = $scope.remito.articulosRemito; $scope.seleccionarArticulo($scope.articulos[0]); + var tieneUsuario = $scope.cisternas.filter(function(cisterna) { + if(cisterna.cisternaCarga) { + return cisterna.cisternaCarga.idUsuarioProceso !== + focaLogisticaPedidoRutaService.idUsuario; + } + }); + if(tieneUsuario.length) { + focaModalService.alert('Otro usario esta usando este vehículo'); + $uibModalInstance.close(); + return; + } }); $scope.aceptar = function() { $scope.cargando = true; for(var i = 0; i < $scope.cisternasCarga.length; i++) { + $scope.cisternasCarga[i].idUsuarioProceso = + focaLogisticaPedidoRutaService.idUsuario; delete $scope.cisternasCarga[i].articulo; } var cisterna = { cisternaMovimientos: cisternaMovimientos, cisternaCargas: $scope.cisternasCarga, - idVehiculo: $scope.vehiculo.id + idVehiculo: $scope.vehiculo.id, + fechaReparto: focaLogisticaPedidoRutaService.fecha }; focaLogisticaPedidoRutaService.guardarCisternas(cisterna, $scope.remito.id) .then(function() { @@ -59,11 +73,8 @@ angular.module('focaLogisticaPedidoRuta') }).catch(function(error) { $scope.cargando = false; $uibModalInstance.close(); - if (error.status === 403.1) { - focaModalService.alert('ERROR: El vehículo esta en uso'); - } - if(error.status === 403.2) { - focaModalService.alert('ERROR: Otro usario ya cargó este remito'); + if (error.status === 403) { + focaModalService.alert('ERROR: ' + error.data); return; } focaModalService.alert('Hubo un error al cargar las cisternas'); diff --git a/src/js/service.js b/src/js/service.js index 5c0e4dc..8433f99 100644 --- a/src/js/service.js +++ b/src/js/service.js @@ -6,36 +6,37 @@ angular.module('focaLogisticaPedidoRuta') 'API_ENDPOINT', '$filter', function($http, $cookies, API_ENDPOINT, $filter) { + var url = API_ENDPOINT.URL; return { idUsuario: $cookies.get('idUsuario'), obtenerActividad: function(parametros) { - return $http.post(API_ENDPOINT.URL + '/seguimiento/filtros', parametros); + return $http.post(url + '/seguimiento/filtros', parametros); }, obtenerVehiculoById: function(idVehiculo) { - return $http.get(API_ENDPOINT.URL + '/vehiculo/' + idVehiculo); + return $http.get(url + '/vehiculo/' + idVehiculo); }, obtenerRemitoById: function(idRemito) { - return $http.get(API_ENDPOINT.URL + '/remito/obtener/' + idRemito); + return $http.get(url + '/remito/obtener/' + idRemito); }, guardarCisternas: function(cisterna, idRemito) { - return $http.post(API_ENDPOINT.URL + '/cisterna/guardar/cargar/' + + return $http.post(url + '/cisterna/guardar/cargar/' + this.idUsuario + '/' + idRemito,cisterna); }, numeroHojaRuta: function() { - return $http.get(API_ENDPOINT.URL + '/hoja-ruta/numero-siguiente'); + return $http.get(url + '/hoja-ruta/numero-siguiente'); }, getRemitos: function(idVehiculo) { - return $http.get(API_ENDPOINT.URL + '/remito/sin-hoja-ruta/' +idVehiculo); + return $http.get(url + '/remito/sin-hoja-ruta/' +idVehiculo); }, - crearHojaRuta: function(hojaRuta) { - return $http.post(API_ENDPOINT.URL + '/hoja-ruta', hojaRuta); + cerrarDistribuicion: function(remitos) { + return $http.post(url + '/vehiculo/cierre-distribuicion', remitos); }, desasociarRemitos: function(remitos, idVehiculo, sinRemitos) { var idsRemitos = []; for (var i = 0; i < remitos.length; i++) { idsRemitos.push(remitos[i].id); } - return $http.post(API_ENDPOINT.URL + '/vehiculo/desasociar-remitos', + return $http.post(url + '/vehiculo/desasociar-remitos', { idsRemitos: idsRemitos, idVehiculo: idVehiculo, @@ -53,7 +54,8 @@ angular.module('focaLogisticaPedidoRuta') .length; k++) { if(cisterna.cisternasCarga[j].fechaReparto.substring(0, 10) === - fecha.substring(0, 10)) + fecha.substring(0, 10) && !cisterna.cisternasCarga[j] + .confirmado) { procesoMovimiento(cisterna.cisternasCarga[j] .cisternaMovimientos[k]); @@ -74,18 +76,18 @@ angular.module('focaLogisticaPedidoRuta') return remitosRes; }, getVehiculosByIdUsuario: function() { - return $http.get(API_ENDPOINT.URL + '/vehiculo/usuario/' + this.idUsuario); + return $http.get(url + '/vehiculo/usuario/' + this.idUsuario); }, obtenerCisternasPorFecha: function(idVehiculo) { - return $http.post(API_ENDPOINT.URL + '/cisterna/listar/fecha', + return $http.post(url + '/cisterna/listar/fecha', {idVehiculo: idVehiculo, fechaReparto: this.fecha}); }, getUnidadesByFecha: function() { - return $http.post(API_ENDPOINT.URL + '/vehiculo/listar/fecha', + return $http.post(url + '/vehiculo/listar/fecha', {fecha: this.fecha}); }, setFechaReparto: function(fechaReparto) { this.fecha = fechaReparto; - } + }, }; }]); diff --git a/src/views/foca-logistica-pedido-ruta.html b/src/views/foca-logistica-pedido-ruta.html index fe947d6..30b1860 100644 --- a/src/views/foca-logistica-pedido-ruta.html +++ b/src/views/foca-logistica-pedido-ruta.html @@ -50,29 +50,6 @@ ng-focus="fechaHastaOpen = true" ng-change="search()" /> - -