This topic is locked

Get a value from master table field

12/5/2008 12:05:51 AM
PHPRunner General questions
vin7102 author

Hi,
I need help with a master - detail app.

I would like to add an "Available Qty" code snippet field event to an ADD NEW RECORD page that will get its value from it's master table

The Master table is called "New Inventory" and the field containing the value I need is called "Current Balance".

I basically want to grab the "Current Balance" from the master table and put it on the ADD NEW RECORD page.
I'm putting this snippet on the "add new record" form to let the user know how much material is available to take,

Is there a way to stop the user from taking more material than what is in the "Current Balance" field on the master table?

The field in the ADD NEW RECORD page where the user enters the amount is called "Amount Pull" and its in the child table called "Pull Inventory"
Thanks In Advance
Vince

J
Jane 12/5/2008

Vince,
use custom event (Insert PHP code snippet option in the Visual Editor tab) for this purpose.

Here is just a sample:

global $conn,$strTableName;

$str = "select `Current Balance` from `New Inventory` where RecordID=".$_SESSION[$strTableNamer."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

echo "Current Balance: ".$data["Current Balance"];

vin7102 author 12/5/2008

Thanks Jane- 1st part Works perfect!
For the second question,

now that I have the current balance on the "add records" page, Can I make phprunner deny a record update if the user tries to pull out more material than what is available?

I think I'm starting to get the hang of this now and I believe the code would have to be put in the "before record added" event in the "Pull Inventory" add page!
The statement would be like this:

If master table "New Inventory" "Current Balance" field is less than the amount being pulled in "Pull Inventory" "Amount Pull" field then deny the action and echo"Not Enough Material in Stock"
Hope you understand all this,

Thanks,
Vince

J
Jane 12/8/2008

Hi,
use Before record added event on the Eventstab for this purpose.

Here is a sample:

global $conn,$strTableName;

$str = "select `Current Balance` from `New Inventory` where RecordID=".$_SESSION[$strTableNamer."_masterkey1"];

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

if ($data["Current Balance"]<$values["Amount Pull"])

{

echo"Not Enough Material in Stock";

return false;

}

else

return true;

vin7102 author 12/8/2008

Jane
Took your code and added
$message="<div class=message><<<"."Insufficient Material Qty".">>></div>";
to have message appear at the top of the actual "add record" form
Works perfect
Thank you very much Jane!
Vince