controller.js 5.19 KB
angular.module('focaLogisticaPedidoRuta') .controller('focaLogisticaPedidoRutaController', [
    '$scope', 'focaLogisticaPedidoRutaService', '$location', '$uibModal', '$filter',
        'focaModalService', 'focaBotoneraLateralService',
    function($scope, focaLogisticaPedidoRutaService, $location, $uibModal, $filter,
        focaModalService, focaBotoneraLateralService
    ) {
        $scope.now = new Date();
        $scope.actividad = 'Logistica';

        //Datos Pantalla
        $scope.titulo = 'Logistica de Pedidos';
        $scope.botonera = ['Vehiculo'];
        var cabecera = '';
        
        $scope.idUsuario = 0;
        $scope.marcadores = [];
        $scope.vehiculos = [];
        getSeguimiento();
        $scope.arrastrando = false;
        $scope.general = function() {
            $scope.idUsuario = 0;
            getSeguimiento();
        };

        //SETEO BOTONERA LATERAL
        focaBotoneraLateralService.showSalir(true);
        focaBotoneraLateralService.showPausar(false);
        focaBotoneraLateralService.showGuardar(false);

        $scope.general = function() {
            $scope.idUsuario = 0;
            getSeguimiento();
            $scope.$broadcast('removeCabecera', cabecera);
            $scope.$broadcast('addCabecera',{
                label: 'General',
                valor: ''
            });
        };

        $scope.cargar = function(id, punto) {
            var idRemito = JSON.parse(punto).notaPedido.remito.id;
            var modalInstance = $uibModal.open(
                {
                    ariaLabelledBy: 'Busqueda de Vehiculo',
                    templateUrl: 'foca-detalle-vehiculo.html',
                    controller: 'focaDetalleVehiculo',
                    size: 'lg',
                    resolve: {
                        idVehiculo: function() {return id;},
                        idRemito: function() {return idRemito;}
                    }
                }
            );
            modalInstance.result.then(function() {
            }, function() {
            });
        };

        $scope.quitarVehiculo = function(vehiculo) {
            focaModalService.confirm('Esta seguro que desea eliminar el vehículo ' +
                vehiculo.codigo + '?').then(function() {
                    $scope.vehiculos.splice($scope.vehiculos.indexOf(vehiculo), 1);
                });
        };

        $scope.informacionVehiculo = function(vehiculo) {
            focaModalService.alert('EN DESARROLLO : \n información del vehículo ' +
                JSON.stringify(vehiculo));
        };

        $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.$broadcast('removeCabecera', 'General');
                $scope.$broadcast('addCabecera', {
                    label: cabecera,
                    valor: $scope.idUsuarioInput
                });
            }
        };

        $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) {
                    var existe = $filter('filter')($scope.vehiculos, {id: vehiculo.id});
                    if(existe.length > 0){
                        focaModalService.alert('El vehiculo que intenta cargar ya ha sido cargado');
                        return;
                    }
                    $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;
            });
        }
    }
]);