Location: PHPKode > projects > QUICKLYWEB > quicklyweb/admin/viewbill.php
<?
session_start();
require("quicklyweb.php");
require("security/hybrid.php");

if(isset($_POST['CustomerID'])) {
	if(isset($_POST['InvoiceID'])) {
	$conf_result = DBquery("select * from Configuration", $db);
	checkDBError($db);
	$config = DBfetch_array($conf_result);
	$configuration = DBfetch_array($conf_result);
	$cust_result = DBquery("SELECT * FROM Customers WHERE CustomerID='$_POST[CustomerID]'", $db);
	checkDBError($db);
	$customer = DBfetch_array($cust_result);
	$act_result = DBquery("SELECT * FROM Accounts WHERE CustomerID='$_POST[CustomerID]'", $db);
	checkDBError($db);
	$accounts = DBfetch_array($act_result);
	$pay_result = DBquery("SELECT * FROM Payments WHERE CustomerID='$_POST[CustomerID]' ORDER BY PaymentID DESC", $db);
	checkDBError($db);
	$payments = DBfetch_array($pay_result);
        $dat_result = DBquery("SELECT * FROM Invoices WHERE InvoiceID='$_POST[InvoiceID]'", $db); 
	$inv_result = DBquery("SELECT * FROM InvoiceItems WHERE InvoiceID='$_POST[InvoiceID]'", $db);
	checkDBError($db);
        $dat_items = DBfetch_array($dat_result);
		while ($inv_items = DBfetch_array($inv_result)) {
				$inv_total += $inv_items["Amount"];
				$taxes_total += $inv_items["Taxes"];
				$itemsDesc = $inv_items["Description"];
				$Amount +=  $inv_items["Amount"];
				$Taxes +=  $inv_items["Taxes"];

			$invset .= "<TR><TD VALIGN=TOP ALIGN='LEFT' bgcolor=\"#ffffff\">".$itemsDesc. " <br></TD>";
			$invset .= "<TD VALIGN=TOP NOWRAP ALIGN='RIGHT' bgcolor=\"#ffffff\">" .sprintf("$lCurrency%.2f",$inv_items["Amount"])."\n</TD>";
			$invset .= "<TD VALIGN=TOP NOWRAP ALIGN='RIGHT' bgcolor=\"#ffffff\">".sprintf("$lCurrency%.2f",$inv_items["Taxes"])."\n</TD>";
			$invset .= "<TD VALIGN=TOP NOWRAP ALIGN='RIGHT' bgcolor=\"#ffffff\">".sprintf("$lCurrency%.2f",$inv_items["Amount"] + $inv_items["Taxes"])."\n<br>$Exchange</TD>";
			$invset .= "</TR>";
		}
                $invset .= "<tr><td colspan=4 width=100% bgcolor=#ffffff><table width=100% ><tr><td ></td><td align=right ><table bgcolor=\"#cccccc\" cellspacing=1 cellpadding=5>";
		$invset .= "<TR><TD><B>Sub Totals</B></TD><TD ALIGN='RIGHT' bgcolor=\"#ffffff\"><B>".sprintf("$lCurrency%.2f",$Amount)."</B></TD></TR>";
               $invset .= "<TR><TD><B>$lTaxTag</B></TD><TD ALIGN='RIGHT' bgcolor=\"#ffffff\"><B>".sprintf("$lCurrency%.2f",$Taxes)."</B></TD></tr>";
 
		$invset .= "<TR><TD><B>Grand Total</B></TD><TD ALIGN='RIGHT' bgcolor=\"#ffffff\"><B>".sprintf("$lCurrency%.2f",$Amount + $Taxes)."</B></TD></TR>";
		$invset .="</table></td></tr></table></td></tr>";
//	if($customer["Email"]) {
		$grandtotal = $pay_total  - ($inv_total + $taxes_total);
		if($grandtotal < 0) {
			$grandtotal = abs($grandtotal);
		} else {
			$grandtotal =	"-".$grandtotal;
		} 

		show_bill_html('Header',$_POST['BillTypeID'],'Invoice');
		
		$message .= "<table width=\"100%\"><tr><td width=50% valign=top style=\"font-size:14px;\"><strong>Invoice to:</strong>\n<blockquote>\n";
		$fullname = stripslashes($customer["First"]) ." ".stripslashes($customer["Mid"])." ".stripslashes($customer["Last"]);
		$message .= $fullname . "\n<br>";
		if($customer["Company"] != "") { 
			$message .= stripslashes($customer["Company"]) . "\n<br>";
		}
		$message .= stripslashes($customer["Address"]) . "\n<br>";
		$message .= stripslashes($customer["City"])." ".$customer["State"]." ".$customer["Zip"] . "\n";
		$message .= "</blockquote><br>\n</td>";
                $message .= "<td width=50% valign=top style=\"font-size:14px;\"><strong>Invoice from:</strong>\n<blockquote>\n";
                $message .= "QUICKLYWEB ENTERPRISES<br>51 Brigstock Road<br>Thornton Heath<br>Surrey, CR7 7JH<br>United Kingdom<br>TEL: 08707740286<br>EMAIL:hide@address.com</td></tr>";
                $message .= "<tr><td colspan=2> <br><br></td></tr><tr><td colspan=2><table border=0 cellspacing=1 cellpadding=3 width=100% bgcolor=#cccccc><tr>";
                $message .="<td><b>$lInvoiceNumber: </b></td>";
                $message .="<td><b>$lDateBilled: </b></td>";
                $message .="<td><b>Pay in</b></td></tr>";
                $message .="<tr><td bgcolor=#ffffff><b>".$_POST['InvoiceID']."</b></td>";
                $message .="<td bgcolor=#ffffff><b>".$dat_items['DateBilled']."</b></td>";
                $message .="<td bgcolor=#ffffff><b>14 Days</b></td></tr>";
                $message .="</tr></table></td></tr>";

		$message .= "<tr><td colspan=2><br><br></td></tr>";
		
		$message .= "<tr><td colspan=2 style=\"font-size:14px;\"><TABLE BORDER=0 CELLSPACING=1 CELLPADDING=3   WIDTH=\"100%\" BGCOLOR=\"#cccccc\">\n\t";
		$message .= "<tr bgcolor=\"#cccccc\"><th ALIGN='LEFT' >Description</th><th ALIGN='RIGHT'>Item Total</th><th ALIGN='RIGHT'>$lTaxTag</th><th ALIGN='RIGHT'>Line Total</th></tr>\n";
		$message .= $invset . "</TABLE></td></tr>\n<br><br></table>";

		echo $message;

		show_bill_html('Footer',$customer["BillTypeID"],'');

		
	} // END if(isset($_POST[InvoiceID]))
} else {
	echo "Viewing bills requires a CustomerID";
} // END if(isset($_POST[CustomerID])) 

die();

// Dump Bill Header and Footer HTML
function show_bill_html($btype,$BillID,$title) {
	global $db;

	$res = $db->query("SELECT Header,Footer FROM BillingInfo WHERE BillTypeID='$BillID'");
	$html = DBfetch_array($res);
	//$html = str_replace("@title", $title, $html);
	echo $html[$btype];
}
?>
Return current item: QUICKLYWEB