<?PHP
include "../inc/var.php";
include "../inc/connect.php";
include $server_inc."/whm_functions.php";
include $server_inc."/client_functions.php";
include $server_inc."/login_functions.php";
include $server_inc."/invoice_functions.php";
include $server_admin_inc."/header.php";

echo("
	<table width='725' cellpadding='0' cellspacing='0' border='0'>
		<tr>
			<td width='1%' align='left' valign='top'><img src='".$http_images."/space.gif' width='15' height='375'></td>
			<td width='99%' align='left' valign='top'>

			<form action='".$PHP_SELF."' method='POST'>
			".((isset($pid))?"<input type='hidden' name='pid' value='".trim($pid)."'>":"")."
			<input type='hidden' name='sid' value='".trim($sid)."'>
			<table width='725' cellpadding='2' cellspacing='1' border='0'>
				<tr>
					<td colspan='5' align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Domain / Billable Service Invoice History</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/client_view_edit.php?sid=".$sid."'><font color='#990000'>Back</font></a>]</td>
				</tr>
				<tr>
					<td colspan='5' align='left' valign='top'><hr color='#F0EFED'></td>
				</tr>
	");

# hosting objects invoiced
echo("
				<tr>
					<td colspan='5' align='left' valign='middle'><img src='".$http_images."/error_arrow.gif'><b>Domain Invoice History</b></td>
				</tr>
				<tr>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Actions</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice</b></td>
					<td width='40%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Domain Name</b></td>
					<td width='15%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice Created</b></td>
					<td width='15%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice Due</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Status</b></td>
				</tr>
				");

			$x=1;
			$y=1;
			$query="select ";
			$query.="iid, ";			// 0
			$query.="invoice_number, ";	// 1
			$query.="created, ";		// 2
			$query.="due_date, ";		// 3
			$query.="status, ";			// 4
			$query.="date_paid ";		// 5
			$query.="from invoice ";
			$query.="where oid='".addslashes(trim(base64_decode($oid)))."' ";
			$query.="order by created desc";

			$row=mysql_query($query);
			while ($rs=mysql_fetch_row($row))
				{
				$iid=stripslashes(trim($rs[0]));
				$invoice_number=stripslashes(trim($rs[1]));
				$created=stripslashes(trim($rs[2]));
				$due_date=stripslashes(trim($rs[3]));
				$invoice_status=stripslashes(trim($rs[4]));
				$date_paid=stripslashes(trim($rs[5]));

				$rs1=mysql_fetch_row(mysql_query("select domain_name from hosting_order where oid='".addslashes(trim(base64_decode($oid)))."' limit 0, 1"));

				$domain_name=stripslashes(trim($rs1[0]));
		
				if ($y==1) { $bgcolor="#F2F4F6"; $y=0; } else { $bgcolor="#ECEEF0"; $y=1; }

				echo("
					<tr>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;<a href='".$http_admin."/client_view.php?sid=".$sid."&oid=".base64_decode($oid)."&in=5'><img alt='Click to view this domains hosting account information.' src='".$http_images."/icon_view.gif' border='0'></a>&nbsp;&nbsp;<a href='".$http_admin."/invoice_hosting.php?sid=".$sid."&iid=".$iid."&oid=".$oid."&uid=".$uid."'><img alt='Click to manage this invoice.' src='".$http_images."/manage_invoice.gif' border='0'></a>&nbsp;&nbsp;<a href='".$http_web."/invoice_hosting.php?c=".urlencode(e("576cb7f68040520768bf51c75f7f4c84", $iid))."' target='_blank'><img alt='Click to view a printable invoice.' src='".$http_images."/view_formatted.gif' border='0'></a>&nbsp;".(($invoice_status!=1)?"&nbsp;<img alt='Click to resend a payable invoice.' src='".$http_images."/resend_invoice.gif' border='0'>":"&nbsp;<img alt='This invoice has been paid.' src='".$http_images."/resend_invoice_.gif' border='0'>")."&nbsp;</td>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;#".$invoice_number."</td>
						<td width='40%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;<a href='http://".$domain_name."' target='_blank'>http://".$domain_name."</a></td>
						<td width='15%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".date("m/d/Y", $created)."</td>
						<td width='15%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;
					");
				if ($invoice_status==2)
					{
					echo "<A HREF='javascript:void(0)' class='cleanlink3' onmouseover=\"return overlib('This invoice is past due', CAPTION, 'Past Due');\" onmouseout='nd();'><font color='#990000'>".date("m/d/Y", $due_date)."</font>";
					}
				else if ($rs[3]<=time()&&$invoice_status!=1)
					{
					echo "<A HREF='".$http_admin."/invoice_hosting.php?sid=".$sid."&iid=".$iid."&oid=".$oid."&uid=".$uid."' class='cleanlink3' onmouseover=\"return overlib('This invoice is now past due, you should consider changing the status by clicking here.', CAPTION, 'Past Due - Status Change?');\" onmouseout='nd();'><font color='#990000'>".date("m/d/Y", $due_date)."</font>";
					}
				else
					{
					echo "<A HREF='javascript:void(0)' class='cleanlink3' onmouseover=\"return overlib('This invoice was paid on:<br>".date("m/d/Y", $date_paid).".', CAPTION, 'Paid Invoice');\" onmouseout='nd();'>".date("m/d/Y", $due_date)."</a>";
					}


				echo("
						</td>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>".invoice_status($invoice_status)."</td>
					</tr>
					");
				$x++;
				}

	if ($x==1)
		{
		echo("
					<tr>
						<td colspan='6'><img src='".$http_images."/space.gif' width='1' height='4'></td>
					</tr>
					<tr>
						<td colspan='6'><font color='#990000'>No hosting invoices found in the database for this client.</font></td>
					</tr>
			");
		}

	echo("
					<tr>
						<td colspan='6'><img src='".$http_images."/space.gif' width='1' height='16'></td>
					</tr>
				</table>
		");
/*
echo("
			<table width='100%' border='0' cellspacing='1' cellpadding='2'>
				<tr>
					<td colspan='5' align='left' valign='middle'><img src='".$http_images."/error_arrow.gif'><b>Billable Service Invoice History</b></td>
				</tr>
				<tr>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice #</b></td>
					<td width='25%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Billed To</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Created</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Due Date</b></td>
					<td width='45%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Actions</b></td>
				</tr>
				");

			$x=1;
			$y=1;
			$query="select ";
			$query.="iid, ";			// 0
			$query.="invoice_number, ";	// 1
			$query.="created, ";		// 2
			$query.="due_date ";		// 3
			$query.="from invoice ";
			$query.="where uid='".addslashes(trim(base64_decode($uid)))."' ";
			$query.="order by created desc";

			$row=mysql_query($query);
			while ($rs=mysql_fetch_row($row))
				{
				$iid=stripslashes(trim($rs[0]));
				$invoice_number=stripslashes(trim($rs[1]));
				$created=stripslashes(trim($rs[2]));
				$due_date=stripslashes(trim($rs[3]));
				$uid=stripslashes(trim($rs[4]));

				$rs1=mysql_fetch_row(mysql_query("select first_name, last_name from user where uid='".addslashes(trim($uid))."' limit 0, 1"));

				$first_name=stripslashes(trim($rs1[0]));
				$last_name=stripslashes(trim($rs1[1]));


				if ($y==1) {$bgcolor="#F2F4F6"; $y=0;} else {$bgcolor="#ECEEF0"; $y=1;}
				echo("
					<tr>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>
						<table width='100%' cellpadding='0' cellspacing='0'>
							<tr>
								<td width='1%' align='left' valign='middle'>&nbsp;<a href='".$http_admin."/invoice_create.php?sid=".$sid."&iid=".$iid."&p=5'><img alt='Click to view this invoice.' src='".$http_images."/icon_view.gif' border='0'></a>&nbsp;</td>
								<td width='99%' align='left' valign='middle'>&nbsp;<a href='".$http_admin."/invoice_create.php?sid=".$sid."&iid=".$iid."&p=5'>".$invoice_number."</a></td>
							</tr>
						</table>
						</td>
						<td width='25%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".$first_name." ".$last_name."</td>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".date("m/d/Y", $created)."</td>
						<td width='10%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".date("m/d/Y", $due_date)."</td>
						<td width='45%' align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;[ <a href='".$http_admin."/invoice_pending.php?iid=".$iid."&sid=".$sid."&send=".$uid."&n=".$invoice_number."'>Send Invoice</a> ]&nbsp;[ <a href='".$http_admin."/invoice_view_formatted.php?iid=".$iid."&sid=".$sid."' target='_blank'>View Formatted Invoice</a> ]&nbsp;[ <a href='".$PHP_SELF."?sid=".$sid."&delete=".$iid."'><font color='#990000'>Delete</font></a> ]</td>
					</tr>
					");
				$x++;
				}

	if ($x==1)
		{
		echo("
					<tr>
						<td colspan='6'><img src='".$http_images."/error_arrow.gif'>No non-hosting invoices found in the database for this client.</td>
					</tr>
			");
		}

	echo("
					<tr>
						<td colspan='6'><img src='".$http_images."/space.gif' width='1' height='8'></td>
					</tr>
				</table>
		");
*/
	echo("

				</form>
				</td>
			</tr>
		</table>
		");

include $server_admin_inc."/footer.php";
mysql_close($dblink);
?>