This topic is locked
[SOLVED]

 Programming event

8/13/2010 4:41:50 PM
PHPRunner General questions
T
tazzo73 author

Hallo Everyone!
I am new to PHPRunner. Can someone maybe help me to program a event. I have a application where I want to check stock against "qty in stock" when you add a new transaction. The qty in stock column is in a mysql view.
How can you program the event that it must lookup qty in stock in the view to see that there is enough stock to bookout.
Appreciate your assistance.
Tazzo73

A
ann 8/16/2010

Hi,
use Before record added event on the Events tab to check 'qty in stock' value.

Here is a sample code:

$sql="select `qty in stock` from ViewName where ViewKeyFieldName=".$values["KeyFieldName"];

$rs=CustomQuery($sql);

$data=db_fetch_array($rs);

if ($data["`qty in stock`"]==$values["stock"]){

return true;

}

else{

return false;

}
T
tazzo73 author 8/18/2010

Hallo Ann!
Thanks for helping me out.
I have change your code to my scenario, but still is getting php errors. "unknown columns"
I am getting frustrated with the programming of events and really need some assistance to complete my project.
Will appreciate if you can maybe help.
Regards

Tazz073

A
ann 8/18/2010

Hi,
please makes sure you've replaced ViewKeyFieldName, KeyFieldName, qty in stock, stock field names with your actual field names.

T
tazzo73 author 8/18/2010

Hi Ann!
This is my code;
$sql="select qty_instock from qty_instock where equipmentCode=".$values["equipment"];
$rs=CustomQuery($sql);
$data=db_fetch_array($rs);
if ($values["issue_qty"]>$data["qty_instock"])
{

$message = "insufficient stock";

return false;

}

else{

return true;

}
Regards

Tazzo73

A
ann 8/18/2010

Tazzo73,
please publish your database creation script or a screenshot of the 'qty_instock' table.

T
tazzo73 author 8/18/2010

Hi Ann!
This is the qty_instock view script,
CREATE ALGORITHM=UNDEFINED DEFINER=root@localhost SQL SECURITY DEFINER VIEW jetvac.qty_instock AS select jetvac.equipment.equipmentCode AS equipmentCode,jetvac.equipment.equipment_description AS equipment_description,jetvac.equipment.qty_onhand AS qty_onhand,((jetvac.equipment.qty_onhand - sum(jetvac.equiptransactiondetail.issue_qty)) + sum(jetvac.equiptransactiondetail.return_qty)) AS qty_instock from (jetvac.equiptransactiondetail join jetvac.equipment) where (jetvac.equiptransactiondetail.equipment = jetvac.equipment.equipmentCode) group by jetvac.equipment.equipmentCode,jetvac.equipment.equipment_description,jetvac.equipment.qty_onhand
Regards

Tazzo73

A
ann 8/19/2010

Tazzo73,
It's difficult to tell you what's happening without seeing actual files.

Please publish your project on Demo Account and open a ticket at http://support.xlinesoft.com sending a URL to your pages along with instructions on reproducing this error. 'Demo Account' button can be found on the last screen in the program.