<?php require_once('../Connections/lancrox.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  }

  $theValue = function_exists("mysqli_real_escape_string") ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((isset($GLOBALS["___mysqli_ston"]) && is_object($GLOBALS["___mysqli_ston"])) ? mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $theValue) : ((trigger_error("[MySQLConverterToo] Fix the mysql_escape_string() call! This code does not work.", E_USER_ERROR)) ? "" : ""));

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

mysqli_select_db( $lancrox, $database_lancrox);
 $query_gf = "SELECT *,agwa.datein as mydate FROM agwa inner join clients on agwa.userid = clients.userid where tcode='$_REQUEST[me]'";
$gf = mysqli_query( $lancrox, $query_gf) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_gf = mysqli_fetch_assoc($gf);
$totalRows_gf = mysqli_num_rows($gf);

$down6= "SELECT SUM(paid)bal,SUM(bank)bb,cost,billing.userid FROM billing inner JOIN (SELECT SUM(outputs*unitcost)cost, userid from agwa where userid='$row_gf[userid]') agwa on agwa.userid = billing.userid where billing.userid='$row_gf[userid]'";
$rst_chk6=mysqli_query($lancrox, $down6);
$num_chk6=mysqli_num_rows($rst_chk6); 
$row_down6 = mysqli_fetch_assoc($rst_chk6);

$down6a= "SELECT SUM(amount)total from agwa where tcode='$_REQUEST[code]'";
$rst_chk6a=mysqli_query($lancrox, $down6a);
$num_chk6a=mysqli_num_rows($rst_chk6a); 
$row_down6a = mysqli_fetch_assoc($rst_chk6a);
$down6b= "SELECT SUM(paid+bank)paid from billing where tcode='$_REQUEST[code]'";
$rst_chk6b=mysqli_query($lancrox, $down6b);
$num_chk6b=mysqli_num_rows($rst_chk6b); 
$row_down6b = mysqli_fetch_assoc($rst_chk6b);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Receipt</title>
<style type="text/css">
body {
	background-image: url();
	background-repeat: no-repeat;
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
#main {
	float: left;
	height: 630px;
	width: 282px;
	padding-right: 5px;
	padding-left: 10px;
	margin: 0px;
}
.center {
	text-align: center;
	font-size: 14px;
}
#main .center.12 {
	font-size: 12px;
}
</style>
<script>
window.print();
myWindow.resizeTo(282,683);
</script>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div id="main">
  <p><img src="../images/logo.jpg" width="232" height="193" /></p>
  <p><strong><?php echo $row_gf['fullname']; ?></strong><br />
  <? echo date('d-M-Y  h:i:s A', $row_gf[mydate]);?>
  </p>
  <table width="282" border="0" cellspacing="3" cellpadding="2">
    <tr>
      <td width="152"><strong>Description x Unit</strong></td>
      <td width="113"><strong>Cost</strong></td>
    </tr>      <?php do { ?>
    <tr>

        <td align="left" valign="top"><?php echo $row_gf['item']; ?> x <?php echo $row_gf['outputs']; ?></td>
        <td align="left" valign="top">₦<?php echo number_format($row_gf['amount'],2); ?>
        <p>&nbsp;</p></td>
        <?php } while ($row_gf = mysqli_fetch_assoc($gf)); ?>
    </tr>
    <tr>
      <td><strong>Total Cost</strong></td>
      <td>₦ <? echo number_format($row_down6a[total]);?></td>
    </tr>
    <tr>
      <td><strong>Amount Paid</strong></td>
      <td>₦ <? echo number_format($row_down6b[paid]);?></td>
    </tr>
    <tr>
      <td><strong>Current Balance</strong></td>
      <td>₦<? echo number_format($row_down6['bal']+$row_down6[bb]-$row_down6['cost'],2);?></td>
    </tr>
  </table>
  <p>Cashier:<?php echo $row_gf['sender']; ?></p>
  <p class="center">Thank You for your patronage.</p>
</div></body>
</html>
<?php
((mysqli_free_result($gf) || (is_object($gf) && (get_class($gf) == "mysqli_result"))) ? true : false);
?>
