<html> <head></head> <body> <h2>Account Statement</h2> <table border="1" cellspacing="0" cellpadding="10"> <tr> <td colspan="3"><b>PURCHASES</b></td> </tr> <tr> <td>Date</td> <td>Description</td> <td>Amount</td> </tr> <?php // database parameters // get these via user input $host = "localhost"; $user = "guest"; $pass = "a85jsl2"; $db = "billing"; // query database for purchases $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); mysql_select_db($db) or die ("Unable to select database!"); $query = "SELECT description, transactionDate, amount FROM purchases WHERE customerCode = 8737"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if(mysql_num_rows($result) > 0) { // counter to record purchase totals $purchaseTotal = 0; // get the raw data (records) // iterate through result set // print transactions details while($row = mysql_fetch_object($result)) { echo "<tr>"; echo "<td>" . $row->transactionDate . "</td>"; echo "<td>" . $row->description . "</td>"; echo "<td align=right>" . sprintf("%01.2f", $row->amount) . "</td>"; echo "</tr>"; // increment purchase counter $purchaseTotal += $row->amount; } } ?> <tr> <td colspan="2" align="right">Sub-Total of Purchases</td> <td align="right"><? echo sprintf("%01.2f", $purchaseTotal); ?></td> </tr> <tr> <td colspan="3"><b>PAYMENTS</b></td> </tr> <tr> <td>Date</td> <td>Description</td> <td>Amount</td> </tr> <?php // query database for receipts for this customer $query = "SELECT transactionDate, receiptAmount FROM receipts WHERE customerCode = 8737"; $result = mysql_query($query) or die ("Error in query: $query. " . mysql_error()); if(mysql_num_rows($result) > 0) { $receiptTotal = 0; // get the raw data (records) // iterate through result set // print receipts while($row = mysql_fetch_object($result)) { echo "<tr>"; echo "<td>" . $row->transactionDate . "</td>"; echo "<td>RECEIPT - THANK YOU</td>"; echo "<td align=right>" . sprintf("%01.2f", $row->receiptAmount) . "</td>"; echo "</tr>"; // get total receipts $receiptTotal += $row->receiptAmount; } } // close connection mysql_close($connection); ?> <tr> <td colspan="2" align="right">Sub-Total of Payments</td> <td align=right><? echo sprintf("%01.2f", $receiptTotal); ?></td> </tr> <tr> <td colspan="2" align="right"><b>TOTAL</b></td> <td align=right><? echo sprintf("%01.2f", $purchaseTotal - $receiptTotal); ?></td> </tr> </table> <p> <hr> <?php // include class and create object include ("Numbers/Words.php"); $nw = new Numbers_Words(); // obtain outstanding amount // purchases less payments // print the amount in words echo "<b>Your total outstanding amount is " . $nw->toCurrency(sprintf("%01.2f", $purchaseTotal - $receiptTotal)) . "</b>"; ?> <hr> </body> </html> |