<?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_pt = "SELECT *  FROM `agwa` inner join billing on billing.tcode= agwa.tcode WHERE billing.tcode = 'QRICWCV7HpabGrQFm4h42F630f53423a5da'";
$pt = mysqli_query( $lancrox, $query_pt) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_pt = mysqli_fetch_assoc($pt);
$totalRows_pt = mysqli_num_rows($pt);
$query_gt = "SELECT *  FROM `agwa` inner join billing on billing.tcode= agwa.tcode WHERE billing.tcode = 'QRICWCV7HpabGrQFm4h42F630f53423a5da'";
$gt = mysqli_query( $lancrox, $query_gt) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_gt = mysqli_fetch_assoc($gt);
$totalRows_gt = mysqli_num_rows($gt);
$query_agt = "SELECT sum(paid+bank)amount from billing WHERE billing.tcode = 'QRICWCV7HpabGrQFm4h42F630f53423a5da'";
$agt = mysqli_query( $lancrox, $query_agt) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_agt = mysqli_fetch_assoc($agt);
$totalRows_agt = mysqli_num_rows($agt);
$query_bgr = "SELECT sum(amount)amount from agwa WHERE tcode = 'QRICWCV7HpabGrQFm4h42F630f53423a5da' group by tcode";
$bgr = mysqli_query( $lancrox, $query_bgr) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_bgr = mysqli_fetch_assoc($bgr);
$totalRows_bgr = mysqli_num_rows($bgr);

$query_agt1 = "SELECT sum(paid+bank)amount from billing WHERE userid = '47pamCQrW4bRICVFFhG2HQ'";
$agt1 = mysqli_query( $lancrox, $query_agt1) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_agt1 = mysqli_fetch_assoc($agt1);
$totalRows_agt1 = mysqli_num_rows($agt1);
$query_bgr1 = "SELECT sum(amount)amount from agwa WHERE userid = '47pamCQrW4bRICVFFhG2HQ' group by userid";
$bgr1 = mysqli_query( $lancrox, $query_bgr1) or die(mysqli_error($GLOBALS["___mysqli_ston"]));
$row_bgr1 = mysqli_fetch_assoc($bgr1);
$totalRows_bgr1 = mysqli_num_rows($bgr1);
$n=1;
$a=1;
?>
<!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>Untitled Document</title>
<style type="text/css">
body {
	margin-left: 0px;
	margin-top: 0px;
	margin-right: 0px;
	margin-bottom: 0px;
}
</style>
</head>

<body>
<p>&nbsp;</p>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td><img src="../images/logo1.png" width="600" height="150" /></td>
    <td><img src="../images/logo1.png" width="600" height="150" /></td>
  </tr>
  <tr>
    <td><table width="60%" border="1" cellspacing="4" cellpadding="4">
      <tr>
        <td width="4%"><strong>SN</strong></td>
        <td width="11%"><strong>QTY</strong></td>
        <td width="43%"><strong>DESCRIPTION OF GOODS</strong></td>
        <td width="14%"><strong>RATE</strong></td>
        <td width="28%"><strong>AMOUNT</strong></td>
      </tr>
      <?php do { ?>
      <tr>
        <td><? echo $n++; ?></td>
        <td><?php echo $row_pt['outputs']; ?></td>
        <td><?php echo $row_pt['item']; ?></td>
        <td><?php echo number_format($row_pt['unitcost']); ?></td>
        <td><?php echo number_format($row_pt['amount']); ?></td>
        <?php } while ($row_pt = mysqli_fetch_assoc($pt)); ?>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td bgcolor="#FFDF7C"><strong>Total Cost</strong></td>
        <td bgcolor="#FFDF7C"><? echo number_format($row_bgr[amount])?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><strong>Amount Paid</strong></td>
        <td><? echo number_format($row_agt[amount])?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><strong>Final Balance</strong></td>
        <td><? echo number_format($row_agt[amount]-$row_bgr[amount])?></td>
        <td><strong>Balance</strong></td>
        <td><? echo number_format($row_agt[amount]-$row_bgr[amount])?></td>
      </tr>
    </table></td>
    <td><table width="60%" border="1" cellspacing="4" cellpadding="4">
      <tr>
        <td width="4%"><strong>SN</strong></td>
        <td width="11%"><strong>QTY</strong></td>
        <td width="43%"><strong>DESCRIPTION OF GOODS</strong></td>
        <td width="14%"><strong>RATE</strong></td>
        <td width="28%"><strong>AMOUNT</strong></td>
      </tr>
      <?php do { ?>
      <tr>
        <td><? echo $a++; ?></td>
        <td><?php echo $row_gt['outputs']; ?></td>
        <td><?php echo $row_gt['item']; ?></td>
        <td><?php echo number_format($row_gt['unitcost']); ?></td>
        <td><?php echo number_format($row_gt['amount']); ?></td>
        <?php } while ($row_gt = mysqli_fetch_assoc($gt)); ?>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td bgcolor="#FFDF7C"><strong>Total Cost</strong></td>
        <td bgcolor="#FFDF7C"><? echo number_format($row_bgr[amount])?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><strong>Amount Paid</strong></td>
        <td><? echo number_format($row_agt[amount])?></td>
      </tr>
      <tr>
        <td>&nbsp;</td>
        <td><strong>Final Balance</strong></td>
        <td><? echo number_format($row_agt[amount]-$row_bgr[amount])?></td>
        <td><strong>Balance</strong></td>
        <td><? echo number_format($row_agt[amount]-$row_bgr[amount])?></td>
      </tr>
    </table></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>Name:<br />
Address: </p>
<p>&nbsp;</p>
</body>
</html>
<?php
((mysqli_free_result($pt) || (is_object($pt) && (get_class($pt) == "mysqli_result"))) ? true : false);
?>
