<?php
include(getabspath("include/SPC_Pending_settings.php"));

function DisplayMasterTableInfo_SPC_Pending($params)
{
	$detailtable=$params["detailtable"];
	$keys=$params["keys"];
	global $conn,$strTableName;
	$xt = new Xtempl();
	
	$oldTableName=$strTableName;
	$strTableName="SPC-Pending";

//$strSQL = "SELECT  lead_table.Leadid,  lead_table.Region,  lead_table.`Customer Name`,  lead_table.`Contact Person`,  lead_table.`Lead Details`,  lead_table.`Employee Name`,  lead_table.`Approx Closure Date`,  lead_table.`Lead Status`,  lead_table.`Manager Name`,  lead_table.`Manager Remarks`,  lead_table.`Sales Call Status`,  lead_table.`Lead Level`,  lead_table.`Requirement Details`,  lead_table.`Approx Value`,  lead_table.`First Quote Remarks`,  lead_table.`Proposed Closure Date`,  lead_table.`Projected Closure QTR`,  lead_table.`Proposed Solution Details`,  lead_table.`Quoted Price`,  lead_table.`Final Quote Remarks`,  lead_table.`Discussion Highlights`,  lead_table.`WIN / Lost Analysis`,  lead_table.`Alligned Vendor`,  COUNT(lead_bom.SPC_Status) AS SPC_Item_Count  FROM lead_table  INNER JOIN lead_bom ON lead_table.Leadid = lead_bom.Lead_ID  WHERE (lead_bom.SPC_Status =\"Pending\")  GROUP BY lead_table.Leadid, lead_table.Region, lead_table.`Customer Name`, lead_table.`Contact Person`, lead_table.`Lead Details`, lead_table.`Employee Name`, lead_table.`Approx Closure Date`, lead_table.`Lead Status`, lead_table.`Manager Name`, lead_table.`Manager Remarks`, lead_table.`Sales Call Status`, lead_table.`Lead Level`, lead_table.`Requirement Details`, lead_table.`Approx Value`, lead_table.`First Quote Remarks`, lead_table.`Proposed Closure Date`, lead_table.`Projected Closure QTR`, lead_table.`Proposed Solution Details`, lead_table.`Quoted Price`, lead_table.`Final Quote Remarks`, lead_table.`Discussion Highlights`, lead_table.`WIN / Lost Analysis`, lead_table.`Alligned Vendor`  ";

$sqlHead="SELECT lead_table.Leadid,  lead_table.Region,  lead_table.`Customer Name`,  lead_table.`Contact Person`,  lead_table.`Lead Details`,  lead_table.`Employee Name`,  lead_table.`Approx Closure Date`,  lead_table.`Lead Status`,  lead_table.`Manager Name`,  lead_table.`Manager Remarks`,  lead_table.`Sales Call Status`,  lead_table.`Lead Level`,  lead_table.`Requirement Details`,  lead_table.`Approx Value`,  lead_table.`First Quote Remarks`,  lead_table.`Proposed Closure Date`,  lead_table.`Projected Closure QTR`,  lead_table.`Proposed Solution Details`,  lead_table.`Quoted Price`,  lead_table.`Final Quote Remarks`,  lead_table.`Discussion Highlights`,  lead_table.`WIN / Lost Analysis`,  lead_table.`Alligned Vendor`,  COUNT(lead_bom.SPC_Status) AS SPC_Item_Count";
$sqlFrom="FROM lead_table  INNER JOIN lead_bom ON lead_table.Leadid = lead_bom.Lead_ID";
$sqlWhere="(lead_bom.SPC_Status =\"Pending\")";
$sqlTail="GROUP BY lead_table.Leadid, lead_table.Region, lead_table.`Customer Name`, lead_table.`Contact Person`, lead_table.`Lead Details`, lead_table.`Employee Name`, lead_table.`Approx Closure Date`, lead_table.`Lead Status`, lead_table.`Manager Name`, lead_table.`Manager Remarks`, lead_table.`Sales Call Status`, lead_table.`Lead Level`, lead_table.`Requirement Details`, lead_table.`Approx Value`, lead_table.`First Quote Remarks`, lead_table.`Proposed Closure Date`, lead_table.`Projected Closure QTR`, lead_table.`Proposed Solution Details`, lead_table.`Quoted Price`, lead_table.`Final Quote Remarks`, lead_table.`Discussion Highlights`, lead_table.`WIN / Lost Analysis`, lead_table.`Alligned Vendor`";

$where="";

if($detailtable=="SPC_Approval")
{
		$where.= GetFullFieldName("Leadid")."=".make_db_value("Leadid",$keys[1-1]);
}
if(!$where)
{
	$strTableName=$oldTableName;
	return;
}
	$str = SecuritySQL("Export");
	if(strlen($str))
		$where.=" and ".$str;
	
	$strWhere=whereAdd($sqlWhere,$where);
	if(strlen($strWhere))
		$strWhere=" where ".$strWhere." ";
	$strSQL= $sqlHead.' '.$sqlFrom.$strWhere.$sqlTail;

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

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


//	Leadid - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Leadid", ""),"field=Leadid".$keylink,"",MODE_PRINT);
			$xt->assign("Leadid_mastervalue",$value);

//	Region - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Region", ""),"field=Region".$keylink,"",MODE_PRINT);
			$xt->assign("Region_mastervalue",$value);

//	Customer Name - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Customer Name", ""),"field=Customer+Name".$keylink,"",MODE_PRINT);
			$xt->assign("Customer_Name_mastervalue",$value);

//	Contact Person - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Contact Person", ""),"field=Contact+Person".$keylink,"",MODE_PRINT);
			$xt->assign("Contact_Person_mastervalue",$value);

//	Lead Details - HTML
			$value="";
				$value = GetData($data,"Lead Details", "HTML");
			$xt->assign("Lead_Details_mastervalue",$value);

//	Employee Name - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Employee Name", ""),"field=Employee+Name".$keylink,"",MODE_PRINT);
			$xt->assign("Employee_Name_mastervalue",$value);

//	Approx Closure Date - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Approx Closure Date", ""),"field=Approx+Closure+Date".$keylink,"",MODE_PRINT);
			$xt->assign("Approx_Closure_Date_mastervalue",$value);

//	Lead Status - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Lead Status", ""),"field=Lead+Status".$keylink,"",MODE_PRINT);
			$xt->assign("Lead_Status_mastervalue",$value);

//	Requirement Details - HTML
			$value="";
				$value = GetData($data,"Requirement Details", "HTML");
			$xt->assign("Requirement_Details_mastervalue",$value);

//	Approx Value - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Approx Value", ""),"field=Approx+Value".$keylink,"",MODE_PRINT);
			$xt->assign("Approx_Value_mastervalue",$value);

//	First Quote Remarks - HTML
			$value="";
				$value = GetData($data,"First Quote Remarks", "HTML");
			$xt->assign("First_Quote_Remarks_mastervalue",$value);

//	Proposed Closure Date - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Proposed Closure Date", ""),"field=Proposed+Closure+Date".$keylink,"",MODE_PRINT);
			$xt->assign("Proposed_Closure_Date_mastervalue",$value);

//	Projected Closure QTR - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Projected Closure QTR", ""),"field=Projected+Closure+QTR".$keylink,"",MODE_PRINT);
			$xt->assign("Projected_Closure_QTR_mastervalue",$value);

//	Proposed Solution Details - HTML
			$value="";
				$value = GetData($data,"Proposed Solution Details", "HTML");
			$xt->assign("Proposed_Solution_Details_mastervalue",$value);

//	Quoted Price - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Quoted Price", ""),"field=Quoted+Price".$keylink,"",MODE_PRINT);
			$xt->assign("Quoted_Price_mastervalue",$value);

//	Final Quote Remarks - HTML
			$value="";
				$value = GetData($data,"Final Quote Remarks", "HTML");
			$xt->assign("Final_Quote_Remarks_mastervalue",$value);

//	Discussion Highlights - HTML
			$value="";
				$value = GetData($data,"Discussion Highlights", "HTML");
			$xt->assign("Discussion_Highlights_mastervalue",$value);

//	WIN / Lost Analysis - HTML
			$value="";
				$value = GetData($data,"WIN / Lost Analysis", "HTML");
			$xt->assign("WIN___Lost_Analysis_mastervalue",$value);

//	Alligned Vendor - 
			$value="";
				$value = ProcessLargeText(GetData($data,"Alligned Vendor", ""),"field=Alligned+Vendor".$keylink,"",MODE_PRINT);
			$xt->assign("Alligned_Vendor_mastervalue",$value);

//	SPC_Item_Count - 
			$value="";
				$value = ProcessLargeText(GetData($data,"SPC_Item_Count", ""),"field=SPC%5FItem%5FCount".$keylink,"",MODE_PRINT);
			$xt->assign("SPC_Item_Count_mastervalue",$value);
	$xt->display("SPC_Pending_masterprint.htm");
	$strTableName=$oldTableName;

}

?>