You need to sign in to do that
Don't have an account?
Urvik
Help with Calculator Controller
I have a vf page. Below is the code for it. I have been trying to calculate total amount. In my vf page, users are required to enter
1) Effective Date
2) Expiration Date
3) Number of Boxes
Based on the above input - I want to calculate the total amount. Below is the formula.
100/930*(Expiration Date - TODAY)*Number of Boxes
How do I create controller and accomodate this formula?
Here is my vf page
<apex:page standardcontroller="Application__c" > <apex:form > <apex:pageblock > <apex:pageblockSection > <apex:inputField value="{!Application__c.Effective_Date__c}"/> <apex:inputField value="{!Application__c.Expiration_Date__c}"/> <apex:inputField value="{!Application__c.of_Boxes__c}"/> </apex:pageblockSection> </apex:pageblock> </apex:form> </apex:page>
1) Are you planning to insert any records here : If yes you need a SAVE method.
2) Are you planning to display the amount while entering the data or after saving the record?
3) If you want to display the amount after saving then add a formula field total amount.and sfdc will calculate this for you upon SAVE.
If you want to display the amount before saving the record you can add a button or onchange JAVAscript to call a extension class method to perform the calculation and then rerender the section to display the amount.
Hi Rahul,
1) I am not planning to insert any new records.
2) Yes, I am planning to display the amount while entering the data or after clicking the Show Result button.
3) I am struggling with the extension controller to rerender the section to display the amount. Any help would be appreciated.
Hi Urvik.,
Use Extentions to accomplish your need
<apex:page standardcontroller="Application__c" extentions="your_controller" >
In your_controller extention
Step 1:
private final Application__c app;
public decimal results{get;set;}
Step2 :
public Your_Controller(ApexPages.StandardController stdController) {
this.app= (Application__c)stdController.getRecord();
}
public PageReference resultCalculate(){
//Your Calculation like results=100/930*(this.app.Effective_Date__c - TODAY)*this.app.of_Boxes__c
}
In Visualforce Page
<apex:page standardcontroller="Application__c" >
<apex:form >
<apex:pageblock >
<apex:pageblockSection >
<apex:commandButton action="{!resultCalculate}" value="calculate" rerender="Result"/>
<apex:inputField value="{!Application__c.Effective_Date__c}"/>
<apex:inputField value="{!Application__c.Expiration_Date__c}"/>
<apex:inputField value="{!Application__c.of_Boxes__c}"/>
</apex:pageblockSection>
<apex:pageblockSection id="Result">
<apex:outputLable value="{!results}"/>
</apex:pageblockSection>
</apex:pageblock>
</apex:form>
</apex:page>
After Enter the values then click on the CommandButton., it will call your calculate funtion and show the result by rerendering the page block section.