<?php
include_once(getabspath("include/venta_settings.php"));

function DisplayMasterTableInfo_venta($params)
{
	$detailtable=$params["detailtable"];
	$keys=$params["keys"];
	global $conn,$strTableName;
	$xt = new Xtempl();
	
	$oldTableName=$strTableName;
	$strTableName="venta";

//$strSQL = "SELECT  idventa,  fecha,  cliente,  total_venta,  total_cobro,  observacion,  cobrada,  anulada  FROM venta  WHERE (anulada =\"NO\")  ORDER BY idventa DESC  ";

	$cipherer = new RunnerCipherer($strTableName);
	$settings = new ProjectSettings($strTableName, PAGE_PRINT);
	
	$masterQuery = $settings->getSQLQuery();
	$viewControls = new ViewControlsContainer($settings, PAGE_PRINT);

$where="";

global $pageObject, $page_styles, $page_layouts, $page_layout_names, $container_styles;
$layout = new TLayout("masterprint","BoldAqua","MobileAqua");
$layout->blocks["bare"] = array();
$layout->containers["0"] = array();

$layout->containers["0"][] = array("name"=>"masterprintheader","block"=>"","substyle"=>1);


$layout->skins["0"] = "empty";
$layout->blocks["bare"][] = "0";
$layout->containers["mastergrid"] = array();

$layout->containers["mastergrid"][] = array("name"=>"masterprintfields","block"=>"","substyle"=>1);


$layout->skins["mastergrid"] = "grid";
$layout->blocks["bare"][] = "mastergrid";$page_layouts["venta_masterprint"] = $layout;


$showKeys = "";
if($detailtable=="det_venta")
{
		$where.= GetFullFieldName("idventa", "", false)."=".$cipherer->MakeDBValue("idventa",$keys[1-1], "", "", true);
	$showKeys .= " "."Nº venta".": ".$keys[1-1];
	$xt->assign('showKeys',$showKeys);
	
}
if($detailtable=="cobro")
{
		$where.= GetFullFieldName("idventa", "", false)."=".$cipherer->MakeDBValue("idventa",$keys[1-1], "", "", true);
	$showKeys .= " "."Nº venta".": ".$keys[1-1];
	$xt->assign('showKeys',$showKeys);
	
}
if(!$where)
{
	$strTableName=$oldTableName;
	return;
}
	$str = SecuritySQL("Export");
	if(strlen($str))
		$where.=" and ".$str;
	
	$strWhere = whereAdd($masterQuery->m_where->toSql($masterQuery),$where);
	if(strlen($strWhere))
		$strWhere=" where ".$strWhere." ";
	$strSQL = $masterQuery->HeadToSql().' '.$masterQuery->FromToSql().$strWhere.$masterQuery->TailToSql();

//	$strSQL=AddWhere($strSQL,$where);

	LogInfo($strSQL);
	$rs=db_query($strSQL,$conn);
	$data = $cipherer->DecryptFetchedArray($rs);
	if(!$data)
	{
		$strTableName=$oldTableName;
		return;
	}
	$keylink="";
	$keylink.="&key1=".htmlspecialchars(rawurlencode(@$data["idventa"]));
	

//	idventa - 
			$xt->assign("idventa_mastervalue", $viewControls->showDBValue("idventa", $data, $keylink));

//	fecha - Short Date
			$xt->assign("fecha_mastervalue", $viewControls->showDBValue("fecha", $data, $keylink));

//	cliente - 
			$xt->assign("cliente_mastervalue", $viewControls->showDBValue("cliente", $data, $keylink));

//	total_venta - Number
			$xt->assign("total_venta_mastervalue", $viewControls->showDBValue("total_venta", $data, $keylink));

//	total_cobro - Number
			$xt->assign("total_cobro_mastervalue", $viewControls->showDBValue("total_cobro", $data, $keylink));
	$xt->display("venta_masterprint.htm");
	$strTableName=$oldTableName;

}

?>