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

if (isset($send))
	{
	invoice_resend($send, $http_web, $email_admin, $uid, 1);

	$invoice_sent=true;
	}

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'>

			<table width='725' cellpadding='2' cellspacing='0' border='0'>
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/menu_arrow.gif'><b>Non Hosting Billable Service Invoice History Per Client</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[<a href='".$http_admin."/invoice_non_hosting_clients.php?sid=".$sid."'><font color='#990000'>Back</font></a>]</td>
				</tr>
				<tr>
					<td align='left' valign='top'><hr color='#F0EFED'></td>
				</tr>
	");
if (isset($invoice_sent))
	{
	echo("
				<tr>
					<td align='left' valign='top'><img src='".$http_images."/error_arrow.gif'><font color='#990000'><b>The invoice was sent successfully!</b></font></td>
				</tr>
				<tr>
					<td align='left' valign='top'><hr color='#F0EFED'></td>
				</tr>
		");
	}
echo("
			</table>
			<table width='725' border='0' cellspacing='1' cellpadding='2'>
				<tr>
					<td width='10%' align='center' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>View</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice</b></td>
					<td width='38%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Client Name</b></td>
					<td width='15%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Created</b></td>
					<td width='18%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Invoice Terms</b></td>
					<td width='10%' align='left' valign='middle' bgcolor='#E5E7E9'>&nbsp;<b>Status</b></td>
				</tr>
				");

			$query0="select ";
			$query0.="uid, ";
			$query0.="first_name, ";
			$query0.="last_name, ";
			$query0.="email ";
			$query0.="from ";
			$query0.="user ";
			$query0.="where ";
			$query0.="uid='".addslashes(trim($uid))."'";

			$rs0=mysql_fetch_row(mysql_query($query0));

			$uid=stripslashes(trim($rs0[0]));
			$first_name=stripslashes(trim($rs0[1]));
			$last_name=stripslashes(trim($rs0[2]));
			$email=stripslashes(trim($rs0[3]));

			$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.="uid, ";			// 6
			$query.="invoice_terms ";	// 7
			$query.="from invoice ";
			$query.="where ";
			$query.="invoice_type='1' ";
			$query.="and ";
			$query.="uid='".addslashes(trim($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]));
				$invoice_status=stripslashes(trim($rs[4]));
				$date_paid=stripslashes(trim($rs[5]));
				$uid=stripslashes(trim($rs[6]));
				$invoice_terms=stripslashes(trim($rs[7]));
				$invoice_terms_displayed=translate_invoice_terms($invoice_terms);

				$client_name="<a href='mailto:".$email."'>";
				$client_name.=$first_name." ".$last_name."</a>";
				
				if ($y==1) { $bgcolor="#F2F4F6"; $y=0; } else { $bgcolor="#ECEEF0"; $y=1; }

				echo("
					<tr>
						<td align='center' valign='top' bgcolor='".$bgcolor."'>&nbsp;<a href='".$http_admin."/invoice_create.php?sid=".$sid."&iid=".$iid."&p=70'><img alt='Click to manage this invoice.' src='".$http_images."/manage_invoice.gif' border='0'></a>&nbsp;&nbsp;<a href='".$http_web."/invoice_service.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;<a href='".$http_admin."/invoice_non_hosting_client_summary.php?sid=".$sid."&uid=".$uid."&send=".$iid."'><img alt='Click to resend a payable invoice.' src='".$http_images."/resend_invoice.gif' border='0'></a>":"&nbsp;<img alt='This invoice has been paid.' src='".$http_images."/resend_invoice_.gif' border='0'>")."&nbsp;</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;#".$invoice_number."</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".$client_name."</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".date("m/d/Y", $created)."</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".$invoice_terms_displayed."</td>
						<td align='left' valign='top' bgcolor='".$bgcolor."'>&nbsp;".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 billable service invoices found in the database.</font></td>
					</tr>
			");
			}

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

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