Field Calculation
Posted: Fri Apr 04, 2014 9:45 am
I am developing a data base application using a product named PHPRunner. While I realize nobody may know this app there are events that can store PHP code to execute based on various needs. I explain my issue below.
I have an application screen that adds an inventory item to an 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.
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 function above but I am not sure of the syntax for it in this event.
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????
By the way I have also tried simplifying the function for testing to:
function func() {
ctrl3.setValue(ctrl1.getValue());
I have an application screen that adds an inventory item to an 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.
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 function above but I am not sure of the syntax for it in this event.
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????
By the way I have also tried simplifying the function for testing to:
function func() {
ctrl3.setValue(ctrl1.getValue());