Location: PHPKode > projects > Pet Grooming Management System > pet/sale2.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
<title>PGMS Sale 2</title>
</head>
<?php
$method = $_POST['method'];
$today = date('Y-m-d');
if ($method == 'Cash'){
echo'<body>';
echo'<form action = "sale3.php" method = "post">';
/** Cash only **/
require ('header.inc');
echo'<center>';
require ('tax.inc.');
require ('invDesc.inc');
$iid = $_POST['iid'];
$numItems = count($iid);
$discount = $_POST['discount'];
$coupType = $_POST['coupType'];
$percent = $_POST['percent'];
$perOff = 1-$percent;
require ('info.inc');
echo'<table>';
mysql_connect('localhost',$r,$p) or die("Could not connect to Host.");
mysql_select_db($d) or die("Could not select database.");
echo'<tr><th>SKU</th><th align = "left">Item</th><th>Price</th></tr>';
for ($i=0;$i<$numItems;$i++)
{
$query = "select * from items where iid = '$iid[$i]'";
$result = mysql_query($query) or die("Could not run query2.");
$num = mysql_num_rows($result);
 $row = mysql_fetch_array($result);
 $sku = $row['sku'];
 $item = $row['item'];
 $price = $row['price'];
 $itemTax = ($price * tax($tax));
/** decrease inventory **/
inventoryDecrease($iid[$i]);
/** enter info into sales table **/
$query1 = "insert into sales
           (iid,price,tax,date_sold,how)
					 values ('$iid[$i]','$price','$itemTax','$today','$method')";
$result1 = mysql_query($query1) or die("Could not run query1.");
if (mysql_affected_rows()==1){
	     echo '<P>Sales have been saved';
			 }else{
			 echo '<P>Something went wrong with saving your sales.</P>';
			 } 
$sid = MYSQL_INSERT_ID();
/** enter info in coupon table **/
if ($discount > 0){
$query = "insert into coupons
          (sid,type,camount,pamount)
					values ('$sid','$coupType','$discount','$percent')";
$result1 = mysql_query($query) or die("Could not run query1.");
if (mysql_affected_rows()==1){
	     echo '<P>Coupon is entered';
			 }else{
			 echo '<P>Something went wrong with saving your sales.</P>';
			 } 
 }
 echo'<tr><td>'.$sku.'</td><td>'.$item.'</td><td style="text-align: right">'.number_format($price,2).'</td></tr>';
 $subTotal = $subTotal + $price;
 echo'<input type="hidden" name="iid[]" value="'.$iid[$i].'" />';
 echo'<input type="hidden" name="discount" value="'.$discount.'" />';
}
$subTotal = $subTotal - $discount;
$subTax = $subTotal * tax($tax);
$salesTotal = $subTotal + $subTax;
if ($discount > 0){echo'<tr><td colspan = "2" >Discount</td><td style=" text-align: right">$'.number_format($discount,2).'</td></tr>';}
echo'<tr><td colspan = "2" style="color: blue;">Subtotal</td><td style="color: blue; text-align: right">$'.number_format($subTotal,2).'</td></tr>';
echo'<tr><td colspan = "2" style="color: green">Tax</td><td style="color: green; text-align: right">'.number_format($subTax,2).'</td></tr>';
echo'<tr><td colspan = "2" style="color: red">Total</td><td style="color: red; text-align: right">$'.number_format($salesTotal,2).'</td></tr>';
echo'<tr><td colspan = "2">Amount tendered: </td><td><input type="text" name="amount" size = "5"/></td></tr>';
echo'<tr><td colspan = "2"><button type="submit">Change Due</button></td></tr>';
echo'</table>';
echo'</center>';
echo'</form>';
require ('footer.inc');
}
else{
echo'<body onLoad = "window.print()">';
require ('header.inc');
echo'<center>';
require ('tax.inc.');
require ('invDesc.inc');
$discount = $_POST['discount'];
$method = $_POST['method'];
$iid = $_POST['iid'];
$coupType = $_POST['coupType'];
$percent = $_POST['percent'];
$perOff = 1 - $percent;
$numItems = count($iid);
require ('info.inc');
echo'<table>';
mysql_connect('localhost',$r,$p) or die("Could not connect to Host.");
mysql_select_db($d) or die("Could not select database.");
echo'<tr><th>SKU</th><th align = "left">Item</th><th>Price</th></tr>';
for ($i=0;$i<$numItems;$i++)
{
$query = "select * from items where iid = '$iid[$i]'";
$result = mysql_query($query) or die("Could not run query.");
$num = mysql_num_rows($result);
 $row = mysql_fetch_array($result);
 $sku = $row['sku'];
 $item = $row['item'];
 $price = $row['price'];
 $itemTax = ($price * tax($tax));
/** decrease inventory **/
inventoryDecrease($iid[$i]);
/** enter info into sales table **/
$query1 = "insert into sales
           (iid,price,tax,date_sold,how)
					 values ('$iid[$i]','$price','$itemTax','$today','$method')";
$result1 = mysql_query($query1) or die("Could not run query1.");
if (mysql_affected_rows()==1){
	     echo '<P>Sales have been saved';
			 }else{
			 echo '<P>Something went wrong with saving your sales.</P>';
			 } 
$sid = MYSQL_INSERT_ID();
/** enter info in coupon table **/
if ($discount>0){
$query = "insert into coupons
          (sid,type,camount,pamount)
					values ('$sid','$coupType','$discount','$percent')";
$result1 = mysql_query($query) or die("Could not run query 2.");
if (mysql_affected_rows()==1){
	     echo '<P>Coupon is entered';
			 }else{
			 echo '<P>Something went wrong with saving your sales.</P>';
			 } 
 }
 echo'<tr><td>'.$sku.'</td><td>'.$item.'</td><td style="text-align: right">'.number_format($price,2).'</td></tr>';
 $subTotal = $subTotal + $price;
}
$subTotal = $subTotal - $discount;
$subTax = $subTotal * tax($tax);
$salesTotal = $subTotal + $subTax;
if ($discount > 0){echo'<tr><td colspan = "2" >Discount</td><td style=" text-align: right">$'.number_format($discount,2).'</td></tr>';}
echo'<tr><td colspan = "2" style="color: blue;">Subtotal</td><td style="color: blue; text-align: right">$'.number_format($subTotal,2).'</td></tr>';
echo'<tr><td colspan = "2" style="color: green">Tax</td><td style="color: green; text-align: right">'.number_format($subTax,2).'</td></tr>';
echo'<tr><td colspan = "2" style="color: red">Total</td><td style="color: red; text-align: right">$'.number_format($salesTotal,2).'</td></tr>';
echo'<tr><td colspan = "2" style="color: purple">Payment Method:</td><td style="color: purple">'.$method.'</td></tr>';
echo'</table>';
echo'</center>';
require ('footer.inc');
}
?>

</body>
</html>
Return current item: Pet Grooming Management System