This topic is locked

Field Calculation

4/3/2014 8:14:13 AM
PHPRunner General questions
C
cjsaputo author

I have an application screen that adds an inventory item to am order. The first field on the screen is a drop down to select an item code. Based on the item selection there are a number of fields that auto fill. However, one of the fields is calculated based on two other fields. These two fields do appear on the screen when the item is selected so I know they are available.
I need to calculate the sell_price based on the item_discount subtracted from the list_price.

The formula I would use is list_price-(list_price(item_discount/100)). The item_discount is an integer and I am dividing by 100 to create a percent.
Here is the issue. I need this calculation to be done and load sell_price based on the item selection. I am using the JavaScript onload event for the add screen and have inserted the code below based on an example in the PHPRunner manual. The calculation is not working and since I am not a coder I suspect I have done something wrong in the code. Can anyone provide some insight.
I have placed the code below into the on load event. It does not work and I suspect there is a problem in my code:
var ctrlItemId = Runner.getControl(pageid, 'item_id');

var ctrlListPrice = Runner.getControl(pageid, 'List_price');

var ctrlItemDiscount = Runner.getControl(pageid, 'item_discount');

var ctrlSellPrice = Runner.getControl(pageid, 'Sell_price');

function func() {

ctrlSellPrice.setValue(+ctrlListPrice.getValue()) +

-((+ctrlListPrice.getValue())
(+ctrlItemDiscount.getValue())/100);

};

ctrlItemId.on('keyup', func);
The point is that the item discount is on the screen when the page loads from the order main. List price loads when an item is selected. I want to calculate the sell price by the following formula but I am not sure of the syntax for it in this event:
Thanks for any help that can be provided.

C
cjsaputo author 4/3/2014

In order to simplify I have changed the code to:
var ctrl = Runner.getControl(pageid, 'item_id');

var ctrl1 = Runner.getControl(pageid, 'List_price');

var ctrl2 = Runner.getControl(pageid, 'item_discount');

var ctrl3 = Runner.getControl(pageid, 'discount_price');
function func() {

ctrl3.setValue(ctrl1.getValue());
};
ctrl.on('change', func);
I am just trying to load List_price into discount_price when the item_id changes from a drop down.
I have copied this structure from other posts and the help, and I cannot get discount_price to load with List_price.

C
cjsaputo author 4/4/2014

With additional testing I have discovered that the discount_price will load but only after I select a different item_id.
In other words, when I enter the add item screen the item_id field is blank. When I select an item from the drop down all the other fields load except the discount_price. If I select a different item from the drop down, without saving the first item, the discount_price will load, but it is the List_price(as coded) from the previous item.
I have tried changing the function call to 'keyup' and 'keydown', but neither make a difference. Any ideas????



In order to simplify I have changed the code to:
var ctrl = Runner.getControl(pageid, 'item_id');

var ctrl1 = Runner.getControl(pageid, 'List_price');

var ctrl2 = Runner.getControl(pageid, 'item_discount');

var ctrl3 = Runner.getControl(pageid, 'discount_price');
function func() {

ctrl3.setValue(ctrl1.getValue());
};
ctrl.on('change', func);
I am just trying to load List_price into discount_price when the item_id changes from a drop down.
I have copied this structure from other posts and the help, and I cannot get discount_price to load with List_price.