<HTML><HEAD>
<!-- What's in the Till?
Version 1.0
till1.php
By Mike Calabrese
http://www.mikecalabrese.com
8-15-2003
-->
<TITLE>What's in the Till?</TITLE>
</HEAD>
<BODY BGCOLOR="#ffffff" LINK="#008000" TEXT=#"000000" VLINK="#804000">
<CENTER>
<?
// Variable Declarations
$login = "yourlogin";
$password = "yourpassword";
$database = "yourdatabase";
?>
<?
// Error Conditions
if (($date == "" && $type == "deposit") ||
($date == "" && $type == "withdrawl")) {
echo "<BR><BR><BR><TABLE WIDTH='350' BORDER='1' CELLPADDING='3'><TR><TD>";
echo "<CENTER><B>Sorry, but Today's Date is a required field when depositing ";
echo "or withdrawing money.</B><P><FORM METHOD='POST' ";
echo "ACTION='till1.php'><INPUT TYPE='submit' ";
echo "VALUE=' OK '></CENTER></FORM><P></TD></TR></TABLE>";
exit();
}
if (($amount == "" && $type == "deposit") ||
($amount == "" && $type == "withdrawl")) {
echo "<BR><BR><BR><TABLE WIDTH='350' BORDER='1' CELLPADDING='3'><TR><TD>";
echo "<CENTER><B>Sorry, but Amount of Transaction is a required field ";
echo "when depositing ";
echo "or withdrawing money.</B><P><FORM METHOD='POST' ";
echo "ACTION='till1.php'><INPUT TYPE='submit' ";
echo "VALUE=' OK '></CENTER></FORM><P></TD></TR></TABLE>";
exit();
}
if (ereg("[a-zA-Z]", $amount)){
echo "<BR><BR><BR><TABLE WIDTH='350' BORDER='1' CELLPADDING='3'><TR><TD>";
echo "<CENTER><B>Sorry, but the Amount of Transaction must be either ";
echo "numbers or numbers and a decimal when depositing or withdrawing ";
echo "money.</B><P><FORM METHOD='POST' ";
echo "ACTION='till1.php'><INPUT TYPE='submit' ";
echo "VALUE=' OK '></CENTER></FORM><P></TD></TR></TABLE>";
exit();
}
if (($initials == "" && $type == "deposit") ||
($amount == "" && $type == "withdrawl")) {
echo "<BR><BR><BR><TABLE WIDTH='350' BORDER='1' CELLPADDING='3'><TR><TD>";
echo "<CENTER><B>Sorry, but Your Initials is a required field ";
echo "when depositing ";
echo "or withdrawing money.</B><P><FORM METHOD='POST' ";
echo "ACTION='till1.php'><INPUT TYPE='submit' ";
echo "VALUE=' OK '></CENTER></FORM><P></TD></TR></TABLE>";
exit();
}
$initials = strtoupper($initials);
$ip_address = getenv("REMOTE_ADDR");
?>
<TABLE CELLPADDING="0" CELLSPACING="0" WIDTH=400 BORDER="0">
<TR>
<TD>
<P>
<H3 align=center>
What's in the Till?
</H3>
<P align=center>
<A href="till1.php">
<SMALL><B><<Back</B></SMALL></A>
<P>
<?
if ($type == "view") {
echo ("<TT><B>Here's what's in the Till:</B><BR><BR>
</TT>");
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "select transaction_date,
transaction_type,
transaction_amount,
transaction_balance, transaction_initials, transaction_ip,
transaction_comments from the_till order by transaction_date desc
limit 0, 5";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$row = mysql_result($result, $i, "transaction_date");
$themonth = substr($row, 4, 2);
$theday = substr($row, 6, 2);
$theyear = substr($row, 0, 4);
$thehour = substr($row, 8, 2) + 1;
$theminute = substr($row, 10, 2);
$theseconds = substr($row, 12, 2);
echo "<TT>Transaction Date: </TT>";
echo "<TT>$themonth</TT>";
echo "<TT>-$theday</TT>";
echo "<TT>-$theyear</TT>";
if ($thehour < 10)
{
echo "<TT> 0$thehour</TT>";
} else
{
echo "<TT> $thehour</TT>";
}
echo "<TT>:$theminute</TT>";
echo "<TT>:$theseconds</TT>";
echo "<BR>";
$row = mysql_result($result, $i, "transaction_type");
if ($row == "D") {
echo "<TT>Transaction Type: Deposit<BR></TT>";
}
if ($row == "W") {
echo "<TT>Transaction Type: Withdrawl<BR></TT>";
}
$row = mysql_result($result, $i, "transaction_amount");
echo "<TT>Amount: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_balance");
echo "<TT>Balance: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_initials");
echo "<TT>Initials: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_ip");
echo "<TT>IP Address: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_comments");
echo "<TT>Comments: $row<BR><BR></TT>";
}
if ($num_results) {
echo "<BR><TT><I>$num_results Record(s) Returned</I></TT>";
} else {
echo "<BR><TT><I>0 Records Returned</I></TT>";
}
mysql_close ($link);
echo "<P></TD></TR></TABLE>";
echo "</TT></CENTER><P align=center>";
echo "<A href='till1.php'>"; echo "<B><SMALL><<Back</SMALL></B>";
echo "</A></BODY></HTML>";
exit();
}
if ($type =="deposit") {
// query the database to get the current balance.
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "select transaction_date, transaction_type,
transaction_amount,
transaction_balance, transaction_initials, transaction_ip,
transaction_comments from the_till order by transaction_date desc
limit 0, 1";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$transaction_date = mysql_result($result, $i, "transaction_date");
$current_balance = mysql_result($result, $i, "transaction_balance");
}
mysql_close ($link);
// Add todays deposit to the balance we just got
$new_balance = $current_balance + $amount;
// Insert today's information into the database.
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "insert into the_till values(NULL,'".D."','".$amount."','".$new_balance."','".$initials."','".$ip_address."','".$comments."')";
$result = mysql_query($query);
mysql_close ($link);
// Show the new information.
echo "<I>Do not refresh this page or you will cause duplicate entries.</I>";
echo ("<P><TT><B>Here's what's in the Till:</B><BR><BR></TT>");
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "select transaction_date, transaction_type,
transaction_amount,
transaction_balance, transaction_initials, transaction_ip,
transaction_comments from the_till order by transaction_date desc
limit 0, 5";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$row = mysql_result($result, $i, "transaction_date");
$themonth = substr($row, 4, 2);
$theday = substr($row, 6, 2);
$theyear = substr($row, 0, 4);
$thehour = substr($row, 8, 2) + 1;
$theminute = substr($row, 10, 2);
$theseconds = substr($row, 12, 2);
echo "<TT>Transaction Date: </TT>";
echo "<TT>$themonth</TT>";
echo "<TT>-$theday</TT>";
echo "<TT>-$theyear</TT>";
if ($thehour < 10)
{
echo "<TT> 0$thehour</TT>";
} else
{
echo "<TT> $thehour</TT>";
}
echo "<TT>:$theminute</TT>";
echo "<TT>:$theseconds</TT>";
echo "<BR>";
$row = mysql_result($result, $i, "transaction_type");
if ($row == "D") {
echo "<TT>Transaction Type: Deposit<BR></TT>";
}
if ($row == "W") {
echo "<TT>Transaction Type: Withdrawl<BR></TT>";
}
$row = mysql_result($result, $i, "transaction_amount");
echo "<TT>Amount: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_balance");
echo "<TT>Balance: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_initials");
echo "<TT>Initials: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_ip");
echo "<TT>IP Address: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_comments");
echo "<TT>Comments: $row<BR><BR></TT>";
}
if ($num_results) {
echo "<BR><TT><I>$num_results Record(s) Returned</I></TT>";
} else {
echo "<BR><TT><I>0 Records Returned</I></TT>";
}
mysql_close ($link);
echo "<P></TD></TR></TABLE>";
echo "</TT></CENTER><P align=center>";
echo "<A href='till1.php'>";
echo "<B><SMALL><<Back</SMALL></B></A> ";
echo "</BODY></HTML>";
exit();
}
if ($type =="withdrawl") {
// query the database to get the current balance.
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "select transaction_date, transaction_type,
transaction_amount,
transaction_balance, transaction_initials, transaction_ip,
transaction_comments from the_till order by transaction_date desc
limit 0, 1";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$current_balance = mysql_result($result, $i, "transaction_balance");
}
mysql_close ($link);
// Subtract today's withdrawl from the balance we just got.
$new_balance = $current_balance - $amount;
// Insert today's information into the database.
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "insert into the_till values(NULL,'".W."','".$amount."','".$new_balance."','".$initials."','".$ip_address."','".$comments."')";
$result = mysql_query($query);
mysql_close ($link);
// Show the new information.
echo "<I>Do not refresh this page or you will cause duplicate entries.</I>";
echo ("<P><TT><B>Here's what's in the till:</B><BR><BR>
</TT>");
$link = mysql_connect ("localhost", "$login", "$password")
or exit ();
mysql_select_db ("$database")
or exit ();
$query = "select transaction_date, transaction_type,
transaction_amount,
transaction_balance, transaction_initials, transaction_ip,
transaction_comments from the_till order by transaction_date desc
limit 0, 5";
$result = mysql_query ($query);
$num_results = mysql_num_rows($result);
for ($i=0; $i <$num_results; $i++) {
$row = mysql_result($result, $i, "transaction_date");
$themonth = substr($row, 4, 2);
$theday = substr($row, 6, 2);
$theyear = substr($row, 0, 4);
$thehour = substr($row, 8, 2) + 1;
$theminute = substr($row, 10, 2);
$theseconds = substr($row, 12, 2);
echo "<TT>Transaction Date: </TT>";
echo "<TT>$themonth</TT>";
echo "<TT>-$theday</TT>";
echo "<TT>-$theyear</TT>";
if ($thehour < 10)
{
echo "<TT> 0$thehour</TT>";
} else
{
echo "<TT> $thehour</TT>";
}
echo "<TT>:$theminute</TT>";
echo "<TT>:$theseconds</TT>";
echo "<BR>";
$row = mysql_result($result, $i, "transaction_type");
if ($row == "D") {
echo "<TT>Transaction Type: Deposit<BR></TT>";
}
if ($row == "W") {
echo "<TT>Transaction Type: Withdrawl<BR></TT>";
}
$row = mysql_result($result, $i, "transaction_amount");
echo "<TT>Amount: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_balance");
echo "<TT>Balance: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_initials");
echo "<TT>Initials: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_ip");
echo "<TT>IP Address: $row<BR></TT>";
$row = mysql_result($result, $i, "transaction_comments");
echo "<TT>Comments: $row<BR><BR></TT>";
}
}
?>
<P>
</TD></TR>
</TABLE>
</TT>
</CENTER>
<P align=center>
<A href="till1.php">
<B><SMALL><<Back</SMALL></B></A>
</SMALL></B>
</BODY></HTML>