<?php namespace App\Http\Controllers;

use App\Custom\SQLConnection;
use App\Custom\Misc;

use Illuminate\Support\Facades\Response;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Request;

use DateTime;


class EstadisticasController extends Controller  {
  
  public function obtenerEstadisticas() {
  	$menu = Misc::obtenerPermisosNavigatorNoCuit();
    //valido si el usuario tiene el permiso correspondiente para acceder a la sección solicitada.
    $valido =  Misc::restriccionPermiso('FUENTES');
    if(!$valido){ return redirect('/menu'); }
    return view('/estadisticas/index')->with(compact('menu'));
  }

  public function buscarEntreFechas() {
  	$fecha_desde = Request::input('fecha_desde_con');
  	$fecha_hasta = Request::input('fecha_hasta_con');
		$respuesta_fechas		= SQLConnection::backendStoreProcedure('obtener_estadisticas_entre_fechas',array($fecha_desde,$fecha_hasta),"select");
		$respuesta_clientes	= SQLConnection::backendStoreProcedure('obtener_estadisticas_por_cliente_y_fechas',array($fecha_desde,$fecha_hasta),"select");
    return view('/estadisticas/consultas')->with(compact('respuesta_fechas','respuesta_clientes'))->render();
  }
  
  public function detallePorCliente() {
  	$anio 				= Request::input('anio');
  	$mes 					= Request::input('mes');
  	$cliente 	= Request::input('cliente');
		$productos		= SQLConnection::backendStoreProcedure('obtener_estadisticas_cliente_productos',array($anio,$mes,$cliente),"select");
    return view('/modals/modal_detalle_estadistica_producto')->with(compact('productos'))->render();
  	
  }

}