<?php
include_once('../../../php/sessionStart.php');
include_once('../../../php/db/dbExec.php');
include_once('../../../php/functions.php');
include_once('../../../php/timezone.php');
include_once('../../../php/privileges.php');
include_once('../../../php/maxExecTime.php');

$bitForm = "fel1035";
$bitMod = "fel";
$empCod = $_SESSION['empCod'];

switch ($_POST['action']) {
	case 'consultarNotas':
		echo consultarNotas();
		break;

	case 'imprimir':
		echo imprimir();
		break;
}

function consultarNotas() {
	global $empCod;

	$priv = new privileges();
	if (!$priv->consult($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorConsult());
	}

	$dtFecIni = $_POST["dtFecIni"];
	$dtFecFin = $_POST["dtFecFin"];

	# QUERYS
	$sNotas = "SELECT *, TRIM(cli.cli_email) AS cli_email
				FROM notas nc LEFT JOIN cliencc cli ON nc.fact_codp=cli.cli_cod 
				WHERE fact_emp='$empCod' AND fact_fec>='$dtFecIni' AND fact_fec<='$dtFecFin'  ORDER BY fact_idinterno DESC";
	
	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["notas"] = $db->sFetchAll($sNotas);
	$db->close();

	$func = new functions();
	return $func->jsonEncodeArray($resp, "notas");
}

function imprimir() {
	global $empCod;

	$priv = new privileges();
	if (!$priv->consult($_SESSION['usuPriv'])) {
		return json_encode($priv->rErrorConsult());
	}

	$_SESSION["tblFac"] = $_POST["tblFac"];
	return "";
}
?>