This topic is locked

Qty Calculations

1/3/2007 4:06:59 PM
PHPRunner General questions
J
JZint author

I have three tables that I am working with. I have a inventory detail table and a receive parts table that updates the equipment in stock table. When I receive inventory it tags the item as Customer Owned and the receive parts table tags the entry as Surplus Parts. When I deliver parts or equipment, In my movements form, I have a drop down that looks at the available tag_id numbers in the equipment list. If I pick a tag that is Customer Owned, it deletes the line item and when I pick a item that is taged Surplus it should just delete the qty entered for delivery for that tag id. The Customer Owned part works, but when I select a tag that is surplus and enter a qty, it enters a neg #(ie 10 in stock, 2 to deliver, current qty -2) The math looks right but it is surely not working right. Once I get this part right, I will put in some checks to make sure that I am not delivering more than I have in stock and on the receive parts I will check to see if a part number exists and if so just update qty and if not add new part number and qty. Here is the code that I am currently using in the movenent detail table. Any help would greatly be appreciated.
function BeforeAdd(&$values)

{
// Parameters:

// $values - Array object.

// Each field on the Add form represented as 'Field name'-'Field value' pair
//** Update equipment in stock table ****

global $conn;

$strSQL = "SELECT * from _equipment_in_stock as ES,_movement_detail as MD where ES.Tag_ID = MD.Tag_ID && ES.Tag_ID = '".$values['Tag_ID']."' ";

db_exec($strSQL,$conn);

$result = mysql_query($strSQL);

$row = mysql_fetch_array($result);

if ($row['Type'] == 'Customer Owned')
{

// Delete from Equipment In Stock Table

global $conn;

$strSQLdelete = "delete from _equipment_in_stock where Tag_ID = '".$values['Tag_ID']."' ";

db_exec($strSQLdelete,$conn);

}
else

{

$curqty = $row['Qty'];

$newqty = $curqty - $values['Qty'] ;
// Update QTY

global $conn;

$strSQLupdate = "UPDATE _equipment_in_stock SET Qty = '".$newqty."' where Tag_ID = '".$values['Tag_ID']."'";

db_exec($strSQLupdate,$conn);

} //end else statement
return true;
// return true if you like to proceed with adding new record

// return false in other case
}

L
larsonsc 1/3/2007

I would suggest adding a couple of echos to the end of your event to see if what you want to be in the variable is actually what's making it into the variable. Just looking over the code and your explanation of what is happening, it seems like $curqty is getting a zero value in it instead of the $row element.
Try doing this and see what values they are returning...

/*** Update QTY ***

global $conn;

$strSQLupdate = "UPDATE _equipment_in_stock SET Qty = '".$newqty."' where Tag_ID = '".$values['Tag_ID']."'";

db_exec($strSQLupdate,$conn);
echo $curqty."\n";

echo $newqty;

} //end else statement


Once you know the values that are getting into the variables, post them back here and maybe I can figure out what's giving you the trouble.
--Shawn

J
JZint author 1/4/2007

The current quantity is being picked up as 0 and the new quantity is what ever I put in the quantity field for the delivery and the new updated quantity in the equipment table becomes a negitive number.
Quantity in equipment table: 50

Quantity to be delivered: 5

New updated quantity: -5 (Should be 45)

L
larsonsc 1/4/2007

JZint,
Sorry to ask you to run another block of code for me, but could you replace the two echo's with the line below and post the results here?

print_r ($row);


This should show everything that is actually making it into the array $row in a readable format. Thanks.
--Shawn