<?php
include('../../../php/sessionStart.php');
include('../../../php/db/dbExec.php');
include('../../../php/functions.php');

echo buscar();

function buscar() {
	$dtFecIni=utf8_decode(TRIM($_POST['dtFecIni']));
	$dtFecFin=utf8_decode(TRIM($_POST['dtFecFin']));
	$txtNom=utf8_decode(TRIM($_POST['txtNom']));
	$txtNomPed=utf8_decode(TRIM($_POST['txtNomPed']));
	$empCod=$_SESSION['empCod'];
	$pCaja = utf8_decode($_SESSION['pCaja']);

	# QUERYS
	$sFacturas = "SELECT *, 
			TRIM(fact_nom) AS fact_nom,
			TRIM(fact_nomped)  AS fact_nomped
			FROM facturas 
			WHERE fact_emp='$empCod' AND fact_caja='$pCaja' AND fact_fnum=0 AND fact_documentguid='' AND fact_fec>='$dtFecIni' AND fact_fec<='$dtFecFin' AND fact_nom LIKE '%$txtNom%' AND fact_nomped LIKE '%$txtNomPed%'";

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$resp["facturas"] = $db->sFetchAll($sFacturas);
	$db->close();

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