controller.js 3.67 KB
angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [
    '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter',
    function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter) {
        $scope.actividad = '';

        $scope.now = new Date();
        $scope.actividad = 'Nota de pedido';
        $scope.idUsuario = 0;
        $scope.marcadores = [];
        $scope.vehiculos = [];
        getSeguimiento();
        $scope.arrastrando = false;
        $scope.general = function() {
            $scope.idUsuario = 0;
            getSeguimiento();
        };

        $scope.cargar = function(id, punto) {
            var marcador = JSON.parse(punto);
            var vehiculo = $filter('filter')($scope.vehiculos, {id: parseInt(id)})[0];            
            var modalInstance = $uibModal.open(
                {
                    ariaLabelledBy: 'Busqueda de Vehiculo',
                    templateUrl: 'foca-detalle-vehiculo.html',
                    controller: 'focaDetalleVehiculo',
                    size: 'lg',
                    resolve: {
                        vehiculo: function() {return vehiculo;},
                        marcador: function() {return marcador;}
                    }
                }
            );
            modalInstance.result.then(function() {                
            }, function() {
                //run when cancel modal
            });
        };

        $scope.arrastra = function() {            
            $scope.arrastrando = true;
            $scope.$digest();
        };

        $scope.noArrastra = function() {
            $scope.arrastrando = false;
            $scope.$digest();
        };

        $scope.individual = function() {
            $scope.idUsuario = -1;
        };

        $scope.mostrarDetalle = function() {
            $scope.detalle = true;
        };

        $scope.salir = function() {
            $location.path('/');
        };

        $scope.search = function(key) {
            if (key === 13) {
                $scope.idUsuario = $scope.idUsuarioInput;
                getSeguimiento();
            }
        };

        $scope.fecha = function() {
            getSeguimiento();
        };

        $scope.seleccionarVehiculo = function() {
            var modalInstance = $uibModal.open(
                {
                    ariaLabelledBy: 'Busqueda de Vehiculo',
                    templateUrl: 'modal-vehiculo.html',
                    controller: 'focaModalVehiculoController',
                    size: 'lg'
                }
            );

            modalInstance.result.then(
                function(vehiculo) {
                    $scope.vehiculos.push(vehiculo);
                }, function() {
                    // funcion ejecutada cuando se cancela el modal
                }
            );
        };
        


        function getSeguimiento() {
            var now = $scope.now;
            var desde = new Date(new Date(now.setHours(0)).setMinutes(0));
            desde = desde.setDate(desde.getDate() - 1);
            desde = new Date(desde);
            var datos = {
                actividad: $scope.actividad,
                idUsuario: $scope.idUsuario,
                fechaDesde: desde,
                fechaHasta: new Date(new Date(now.setHours(23)).setMinutes(59))
            };

            $scope.datosBuscados = {
                actividad: $scope.actividad,
                individual: $scope.idUsuario !== 0 ? true : false
            };

            focaLogisticaPedidoRutaService.obtenerActividad(datos).then(function(datos) {
                
                $scope.marcadores = datos.data;
            });
        }
    }
]);