<?php

require_once("../include/config.php");	
require_once("../include/startup.php");

$obj  = new Client();
$obj1  = new Company();

	if($G_memberid > 0)
{
	$memberid = $G_memberid;
	 $memberuserscompanyid = $G_memberuserscompanyid;
	$membercompanyid= $G_membercompanyid;
	if($memberuserscompanyid > 0)
	{	
		$sql2 = "select * from mstmember x
				  inner join trninvoicetomember a on x.memberid = a.memberid 
				  inner join trninvoicetomemberdetails b on a.memberinvoicesid = b.memberinvoicesid
				  inner join mstclients c on a.billed_membercompanyid = c.clientcompanyid
				  inner join user_company_payment_header d on a.memberinvoicesid = d.memberinvoicesid
				  inner join user_company_payment_detail e on d.memberpaymentheaderid = e.memberpaymentheaderid
				   inner join trnuser_company f on x.memberid = f.memberid
				  where x.memberid = $memberid  and f.memberuserscompanyid = $memberuserscompanyid and a.billing_membercompanyid=$membercompanyid and quotes_proforma_invoice = 2  GROUP by memberpaymentdetailID order by a.invoicedate,CAST(a.invoiceno AS unsigned) ";
	}
	else
	{
		$sql2 = "select * from mstmember x
				  inner join trninvoicetomember a on x.memberid = a.memberid 
				  inner join trninvoicetomemberdetails b on a.memberinvoicesid = b.memberinvoicesid
				  inner join mstclients c on a.billed_membercompanyid = c.clientcompanyid
				  inner join user_company_payment_header d on a.memberinvoicesid = d.memberinvoicesid
				  inner join user_company_payment_detail e on d.memberpaymentheaderid = e.memberpaymentheaderid
				  where x.memberid = $memberid  and quotes_proforma_invoice = 2  GROUP by memberpaymentdetailID order by a.invoicedate,CAST(a.invoiceno AS unsigned) ";
	}			  
		/*$sql2 ="select * from mstmember x
				  inner join trninvoicetomember a on x.memberid = a.memberid 
				  inner join trninvoicetomemberdetails b on a.memberinvoicesid = b.memberinvoicesid
				  inner join mstclients c on a.billed_membercompanyid = c.clientcompanyid
                  INNER join user_company f on x.memberid = f.memberid
				  inner join user_company_payment_header d on a.memberinvoicesid = d.memberinvoicesid
				  inner join user_company_payment_detail e on d.memberpaymentheaderid = e.memberpaymentheaderid
				  where x.memberid = $memberid  and quotes_proforma_invoice = 2  GROUP by memberpaymentdetailID";	*/	  
		$sqllist2 = $obj1->getCompany('','',$sql2);
		//print_r($sqllist2);
		if(is_array($sqllist2))
		{
			$rowcount2 = count($sqllist2);
		}
	require_once("header1.html");
	require_once("leftnav.html");
	require_once("view-payments1.html");
	require_once("footer1.html");


}
else if (!headers_sent($filename, $linenum)) 
{
				$redirect_url = DOC_ROOT."login.php";
				header("Location: $redirect_url");
    			exit;
					// You would most likely trigger an error here.
}
else 
{
				echo "Headers already sent in $filename on line $linenum\n" .
          			"Cannot redirect, for now please click this <a ";
    			exit;
}   
?>
