• Tanvi
  • NEWBIE
  • 0 Points
  • Member since 2011

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies

Hi,

 

   The scenario i have is as below.

 

   I have three Custom Obj named Project related Custom Object Budget. Third Custom Object is Period which consist Date Field and 

  few formula fields which comes up with CFY and CFYQ1,2,3/4.

 

 

   So here i design a VF Page which accept two fields (1) Period (Lookup to Period Custom Obj) (2) Value (Currency)

 

    I would like to calculate Total Budget for the Project. But i don't know how to write achieve this,

 

 

<apex:page standardController="Budget__c" showheader="true" extensions="BudgetDetailController">
<apex:form >
        <apex:pageBlock title="{!Budget__c.pmo_project__r.name}" mode="edit">
            <apex:pageBlockButtons >
                <apex:commandButton action="{!addMore}" value="Add More" reRender="in , out"/>
            </apex:pageBlockButtons>
            <apex:pageBlockSection title="Budget Entry Page" columns="2">
                <apex:inputField value="{!Budget__c.Period__c}"/>
                <apex:inputField value="{!Budget__c.Value__c}"/>
                
                          
            </apex:pageBlockSection>
        </apex:pageBlock>
       
    </apex:form>
    
  <!-- Ajax call for Budget Entry Page -->   
    
   <apex:pageBlock id="out" title="Monthly Read View">              
       
    <apex:dataTable value="{!myBudgets}" var="aBudget" width="100%" >
     <apex:column >
      <apex:facet name="header"><b>Name</b></apex:facet>
 
      {!aBudget.Name}
     </apex:column>
     <apex:column >
      <apex:facet name="header"><b>Period</b></apex:facet>
      {!aBudget.Period__r.Month_Info__c}
     </apex:column>
   <apex:column >
      <apex:facet name="header"><b>Value</b></apex:facet>
      {!aBudget.Value__c}
     </apex:column>
     
      <apex:column >
      <apex:facet name="header"><b>Quater Information</b></apex:facet>
      {!aBudget.period__r.Quarter_Info__c}
     </apex:column>
     
   </apex:dataTable>               
    </apex:pageBlock>
   <apex:pageBlock id="in" title="Quaterly Read View">              
       
    <apex:dataTable value="{!myBudgetsquaters}" var="aBudget" width="100%" >
     <apex:column >
      <apex:facet name="header"><b>Year</b></apex:facet>
                  {!total}           
      
     </apex:column>
   
   </apex:dataTable>               
    </apex:pageBlock>
              
</apex:page>
// BudgetController
public with sharing class BudgetDetailController {
 public static double total;
    
     Id id = System.currentPageReference().getParameters().get('id');
      public budget__C budget {get;set;}
    
      private final Budget__c budget1; 
    
      public BudgetDetailController(ApexPages.StandardController controller) {
    
      this.budget1= (Budget__C)Controller.getRecord();
      
    }
    
    //Ajax Monthly Readview
    
    public List<Budget__c> getMyBudgets() {
    return [SELECT Id, Name, Period__r.Month_Info__c, Value__c, Period__r.Quarter_Info__c FROM budget__c 
    ORDER BY LastModifiedDate DESC LIMIT 10];
       }
     //Ajax Quarterly View
    public void getMyBudgetsQuaters()
    {
   
    }
     public PageReference addMore()
     {
        
         
       total = total + budget1.value__c;
          budget1.test1__C=total;
          database.Insert(budget1);
        //  ApexPages.StandardController budgetController = new ApexPages.StandardController(budget1);
       //   budgetController.save();
          return page.budgetDetail;
     }
     
     public double getTotal()
     {
        
     }
}

 

<apex:page standardController="Budget__c" showheader="true" extensions="BudgetDetailController"><apex:form >        <apex:pageBlock title="{!Budget__c.pmo_project__r.name}" mode="edit">            <apex:pageBlockButtons >                <apex:commandButton action="{!addMore}" value="Add More" reRender="in , out"/>            </apex:pageBlockButtons>            <apex:pageBlockSection title="Budget Entry Page" columns="2">                <apex:inputField value="{!Budget__c.Period__c}"/>                <apex:inputField value="{!Budget__c.Value__c}"/>                                                      </apex:pageBlockSection>        </apex:pageBlock>           </apex:form>      <!-- Ajax call for Budget Entry Page -->          <apex:pageBlock id="out" title="Monthly Read View">                         <apex:dataTable value="{!myBudgets}" var="aBudget" width="100%" >     <apex:column >      <apex:facet name="header"><b>Name</b></apex:facet>       {!aBudget.Name}     </apex:column>     <apex:column >      <apex:facet name="header"><b>Period</b></apex:facet>      {!aBudget.Period__r.Month_Info__c}     </apex:column>   <apex:column >      <apex:facet name="header"><b>Value</b></apex:facet>      {!aBudget.Value__c}     </apex:column>           <apex:column >      <apex:facet name="header"><b>Quater Information</b></apex:facet>      {!aBudget.period__r.Quarter_Info__c}     </apex:column>        </apex:dataTable>                   </apex:pageBlock>   <apex:pageBlock id="in" title="Quaterly Read View">                         <apex:dataTable value="{!myBudgetsquaters}" var="aBudget" width="100%" >     <apex:column >      <apex:facet name="header"><b>Year</b></apex:facet>                  {!total}                      </apex:column>      </apex:dataTable>                   </apex:pageBlock>              </apex:page>