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());
Field Calculation
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Field Calculation
Seems lit the problem is with your code that sets the value. Try:
Code: Select all
function setDiscountPrice() {
ctrlSellPrice.setValue(ctrlListPrice.getValue() * (ctrlItemDiscount.getValue() / 100));
};
ctrlItemId.on('click', setDiscountPrice);(#10850)
-
cjsaputo2716
- Forum Newbie
- Posts: 3
- Joined: Fri Apr 04, 2014 9:32 am
Re: Field Calculation
Still did not work. The discount price is still blank. I modified you code to use the variables I had and added the subtraction as below:
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 setDiscountPrice() {
ctrlctrl3.setValue(ctrlctrl1.getvalue() - (ctrlctrl1.getValue() * (ctrlctrl2.getValue() / 100)));
};
ctrlctrl.on('click', setDiscountPrice);
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 setDiscountPrice() {
ctrlctrl3.setValue(ctrlctrl1.getvalue() - (ctrlctrl1.getValue() * (ctrlctrl2.getValue() / 100)));
};
ctrlctrl.on('click', setDiscountPrice);
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Field Calculation
So what does ctrlctrl3.setValue() do? Does it just set a value in a object? Or is it supposed to display the value too? You may need to change the value manually.
(#10850)
-
cjsaputo2716
- Forum Newbie
- Posts: 3
- Joined: Fri Apr 04, 2014 9:32 am
Re: Field Calculation
I am no coder so from what I understand this line, and the other similar lines, set the values to the variables on the screen:
var ctrl = Runner.getControl(pageid, 'Item_id');
Maybe I am misunderstanding the coding. And maybe I should just use the variables on the screen. Should I remove the first four lines as unnecessary and use the function with the field names? In other words, would this work by itself:
function setDiscountPrice() {
ctrldiscount_price.setValue(ctrlList_price.getvalue() - (ctrlList_price.getvalue() * (ctrlitem_discount.getvalue() / 100)));
};
ctrlitem_id.on('click', setDiscountPrice);
var ctrl = Runner.getControl(pageid, 'Item_id');
Maybe I am misunderstanding the coding. And maybe I should just use the variables on the screen. Should I remove the first four lines as unnecessary and use the function with the field names? In other words, would this work by itself:
function setDiscountPrice() {
ctrldiscount_price.setValue(ctrlList_price.getvalue() - (ctrlList_price.getvalue() * (ctrlitem_discount.getvalue() / 100)));
};
ctrlitem_id.on('click', setDiscountPrice);
Re: Field Calculation
Do you have any prior experience with PHPRunner? I've never used it but a quick Google suggests it builds PHP applications for you through some sort of pseudocode that you've been posting above. If you've got experience with it and are somewhat comfortable with it, great. Otherwise, I can't help but wonder if it isn't making things unnecessarily difficult to accomplish and making getting help when you're stuck more difficult than it otherwise would be. Just a thought.