<?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');


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

function consultar() {
	global $empCod;

	$txtUsuCod=$_POST['txtUsuCod'];

	# QUERYS
	$sUsuario = "SELECT * FROM usuarios usu
				 LEFT JOIN vendedor vend ON usu.usu_vend=vend.vend_cod
				 WHERE usu_cod='$txtUsuCod'";

	$sCajat = "SELECT caj_emp, caj_cod, TRIM(caj_nom) AS caj_nom
				FROM caja ";

	function sCaja($caja){
		global $empCod;
		return "SELECT caj_emp, caj_cod, TRIM(caj_nom) AS caj_nom
				FROM caja 
				WHERE caj_cod='$caja'";
	}

	# EJECUCION DE QUERYS
	$db = new dbExec();
	$select["usuarios"] = $db->query($sUsuario);
	$fetchAssoc["usuarios"] = $db->fetchAssoc($select["usuarios"]);
	$ncaja=$fetchAssoc["usuarios"]["vend_caja"];

	if ($ncaja=='999') {
		$resp["caja"] = $db->sFetchAll($sCajat);
	} else {
		$resp["caja"] = $db->sFetchAll(sCaja($ncaja));
	}	
	$db->close();

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

?>