[56k WARN] Forms and arrays when re-calculating form data
Posted: Tue Aug 09, 2005 9:26 pm
Hi all,
I have a site/application that I'm making for my wife's hair salon. I didn't want to purchase an app as I thought it'd be a fun project (and it is!)
This part of the app currently takes info from forms on a previous screen and presents it on the screen shown in this image:

I wil post the code below. Currently it works fine, it shows all that needs to be shown, and in particular works out the GST (VAT/Tax/Etc). What happens though, if in this example, the receptionist decided to give the product to the client for $10 off, they would change the 'adjusted price' input, and the colour may have been $120, not $90 as shown, so they would adjust that also. After doing so they would press the 'Re-Calculate' button.
This is all good exept, how the heck do I do that?! I need to re-load the page I know, and I am guessing I need to stick the form data into an array (you think?). Then I need to process the array like I did in the last form and re-present it.
Perhaps looking at my code you might get some clues.
I'd really appreciate some help on what to do here. I'm having a true mental block.
Thanks so much.
Rob
I have a site/application that I'm making for my wife's hair salon. I didn't want to purchase an app as I thought it'd be a fun project (and it is!)
This part of the app currently takes info from forms on a previous screen and presents it on the screen shown in this image:

I wil post the code below. Currently it works fine, it shows all that needs to be shown, and in particular works out the GST (VAT/Tax/Etc). What happens though, if in this example, the receptionist decided to give the product to the client for $10 off, they would change the 'adjusted price' input, and the colour may have been $120, not $90 as shown, so they would adjust that also. After doing so they would press the 'Re-Calculate' button.
This is all good exept, how the heck do I do that?! I need to re-load the page I know, and I am guessing I need to stick the form data into an array (you think?). Then I need to process the array like I did in the last form and re-present it.
Perhaps looking at my code you might get some clues.
I'd really appreciate some help on what to do here. I'm having a true mental block.
Thanks so much.
Rob
Code: Select all
<?
include "header.php";
include "menu.php";
include "config.php";
//Get the passed variables
$Submit = $_GET['Submit'];
$client = $_GET['client'];
$date = $_GET['date'];
$employee = $_GET['employee'];
$notes = $_GET['notes'];
$avail = $_GET['Avail'];
$select = $_GET['Sel'];
$avail2 = $_GET['Avail2'];
$select2 = $_GET['Sel2'];
$total_price = "0"; //for working out the total price
$total_gst = "0"; //for working out the total tax
//Remove the commas and stick the numbers into an array
$services = (explode(',', $select, -1));
$products = (explode(',', $select2, -1));
//Connect to server
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);
mysql_select_db($dbname);
//Get Client Details
$sql = "SELECT * FROM clients WHERE id = $client";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$client_id = $Xcontent["id"];
$client_name_first = $Xcontent["name_first"];
$client_name_last = $Xcontent["name_last"];
//Get Employee Details
$sql = "SELECT * FROM operators WHERE id = $employee";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$employee_id = $Xcontent["id"];
$employee_name = $Xcontent["name"];
?>
<!-- ##### Main Copy ##### -->
<link href="prosimii-screen.css" rel="stylesheet" type="text/css">
<form action="retail_finalise.php" method="get" name="refill_stock_Add" target="_self">
<!-- CUSTOMER DETAILS -->
<table width="500" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td align="center" class="headerSubTitle">Purchase info for customer <b><? echo "$client_name_first $client_name_last"; ?></b>.</td>
</tr>
<tr>
<td align="center" class="headerSubTitle">Service supplied by <b><? echo "$employee_name"; ?></b>.</td>
</tr>
<?
if ($notes != "")
{
echo "<tr> <td align=\"center\" class=\"clientview\"><b>Notes:</b><? echo \"$notes\"; ?>.</td></tr>";
}
?>
<tr>
<td align="center" class="clientview"><b>Date:</b><? echo "$date"; ?></td>
</tr>
<?
/* Playing with showing the passed values after editing the $ value */
if ($Submit == "Re-Calculate")
{
echo "<tr><td class=\"clientviewTitle\"><div align=\"center\">Total Price has been recalculated below</td></tr>";
}
?>
</table>
<br>
<br>
<table width="500" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td colspan="3" align="center" class="clientviewHeader">Please verify SERVICE details before finalising</td>
</tr>
<tr>
<td class="clientviewTitle"><div align="center">Service</div></td>
<td class="clientviewTitle"><div align="center">RRP</div></td>
<td class="clientviewTitle"><div align="center">Adjusted Price</div></td>
</tr>
<?
// Define the services array
$services_array = array(array(0,0));
foreach($services as $val)
{
$sql = "SELECT * FROM services WHERE id = $val";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$service_id = $Xcontent["id"];
$service_name = $Xcontent["name"];
$service_description = $Xcontent["description"];
$service_price = $Xcontent["price"];
if ($val == $service_id)
{
echo "
<tr>
<td class=\"clientview\"><div align=\"center\">$service_name</div></td>
<td class=\"clientview\"><div align=\"center\">$$service_price</div></td>
<td class=\"clientview\"><div align=\"center\"><input name=\"service_price".$service_id."\" type=\"text\" value=\"$service_price\" size=\"6\" maxlength=\"7\"></div></td>
";
//Add up the Totals
if ($service_price != "")
{
$total_price = ($total_price + $service_price);
}
}
}
?>
</table>
<br><br>
<table width="500" border="0" cellspacing="1" cellpadding="1" align="center">
<tr>
<td colspan="3" align="center" class="clientviewHeader">Please verify PRODUCT details before finalising</td>
</tr>
<tr>
<td class="clientviewTitle"><div align="center">Product</div></td>
<td class="clientviewTitle"><div align="center">RRP</div></td>
<td class="clientviewTitle"><div align="center">Adjusted Price</div></td>
</tr>
<?
foreach($products as $val)
{
$sql = "SELECT * FROM stock_retail WHERE id = $val";
$content = mysql_query($sql);
$Xcontent = mysql_fetch_array($content);
$stock_id = $Xcontent["id"];
$stock_name = $Xcontent["product_name"];
$stock_size = $Xcontent["size"];
$stock_price = $Xcontent["rrp_firstbuy"];
if ($val == $stock_id)
{
echo "
<tr>
<td class=\"clientview\"><div align=\"center\">$stock_name - $stock_size</div></td>
<td class=\"clientview\"><div align=\"center\">$$stock_price</div></td>
<td class=\"clientview\"><div align=\"center\"><input name=\"stock_price".$stock_id."\" type=\"text\" value=\"$stock_price\" size=\"6\" maxlength=\"7\"></div></td></tr>
";
//Add up the Totals
if ($stock_price != "")
{
$total_price = ($total_price + $stock_price);
}
}
}
//Show the total price / final price
$total_gst = ($total_price * $cfg_gst_rate);
echo "
<tr>
<td class=\"clientview\"><div align=\"center\"></div></td>
<td class=\"clientview\"><div align=\"center\">GST</div></td>
<td class=\"clientviewHeader\"><div align=\"center\">$$total_gst</div></td></tr>
<tr>
<td class=\"clientview\"><div align=\"center\"></div></td>
<td class=\"clientview\"><div align=\"center\">TOTAL</div></td>
<td class=\"clientviewHeader\"><div align=\"center\"><strong>$$total_price</strong></div></td></tr>";
?>
<tr>
<td class="clientviewTitle"><div align="right"></div></td>
<td align="center">
<input type="hidden" name="client_name" value="<? echo "$client"; ?>">
<input type="hidden" name="date" value="<? echo "$date"; ?>">
<input type="hidden" name="employee_name" value="<? echo "$employee"; ?>">
<input type="hidden" name="notes" value="<? echo "$notes"; ?>">
<input type="submit" name="Submit" value="FINALISE">
</form>
<?
/* ************************************************************************************************************** */
/* This form is for the re-calculate, it's really just me mucking around, and I think it's not on the right track */
/* ************************************************************************************************************** */
?>
<form action="" method="get" name="refill_stock_total" target="_self">
<input type="hidden" name="client" value="<? echo "$client"; ?>">
<input type="hidden" name="date" value="<? echo "$date"; ?>">
<input type="hidden" name="employee" value="<? echo "$employee"; ?>">
<input type="hidden" name="notes" value="<? echo "$notes"; ?>">
<input type="hidden" name="Avail" value="<? echo "$avail"; ?>">
<input type="hidden" name="Sel" value="<? echo "$select"; ?>">
<input type="hidden" name="Avail2" value="<? echo "$avail2"; ?>">
<input type="hidden" name="Sel2" value="<? echo "$select2"; ?>">
<input type="submit" name="Submit" value="Re-Calculate">
</form>
</td>
</tr>
</table>
<?
include "footer.php";
?>