0

Can any one help me on this ?RollUp Summary field can be multiplied in a visual force page.Based on the condition ,I need the value of the RollUp summary to get multipled (0.01) in wrapper class .

"Subtotal__c" and "Non_Pick_Total__c" are Roll up summary fields on Opportunity Object.They give the "Sum" of Opportunity Product aggregates on Extension Field.Extension(Extension=qty*1) is a Formula field data type as Currency on Opportunity Product.

The issue I'm having is that the "Extension" field value is getting calculated based on the formula field but it should get calculated as per the changes made in the visual force page and display (Extension = Qty*0.01) on the subtotal.

Condition :

If the product line for the product selected in opportunity items is ‘DIE’ make following changes .

1) unit price should change to $.01.

2)Unit price just change on the PDF display only and with extended amount which will be quantity times .01.

3)Subtotal__c=Non_Pick_Total__c

How do I achieve this?I shall appreciate your help. VF CODE :

<apex:page standardController="Opportunity"  renderAs="PDF" applyhtmltag="false" showHeader="false" applyBodyTag="false" extensions="InvoiceController">

     <table border="0" cellspacing="0" cellpadding="1" width="100%" >
        <tr>
            <td class="header-heading">
                Ship Date:
            </td>
            <td class="header-data">
                <apex:outputText value="{!opportunity.Sys_today_s_date__c}"></apex:outputText><br/>
            </td>
            <td class="header-heading">
                Special Instructions:
            </td>
            <td class="header-data">                
                <apex:outputText value="{!opportunity.Special_Instructions__c}"></apex:outputText>
            </td>
        </tr>
        <tr>
            <td><b><f style="color:Black; font-size:14px; font-family:Verdana;"></f></b> &nbsp;&nbsp;<apex:outputText value="{!Opportunity.Customer_VAT_number__c}"></apex:outputText><br/>
            </td>
        </tr>
    </table> 

    <table>
        <tr border="0">
            <td class="header-table-heading">CI Invoice Id</td>
            <td class="header-table-heading">Ship Date<b/></td>
            <!--<td class="header-table-heading">Sales Order#</td>-->
            <td class="header-table-heading">Opportunity Name</td>
            <td class="header-table-heading">Order Date</td>
            <!--<td class="header-table-heading">Customer#</td>-->
            <td class="header-table-heading">Customer Name</td>
        </tr>
        <tr>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Salesorder_number__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.Sys_today_s_date__c}"></apex:outputText></td>
            <!--<td class="header-table-data"><apex:outputText value="{!Opportunity.Salesorder_number__c}"></apex:outputText></td>-->
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Name}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Sys_createddate__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.account.Name}"></apex:outputText></td>
            <!--<td class="header-table-data">{!Opportunity.account.Ebs_Customer_number__c}</td>-->
        </tr>
    </table>
    <br/>
    <table >
        <tr>
            <td class="header-table-heading">LN</td>
            <td class="header-table-heading">Item</td>
            <!--<td class="header-table-heading">BinItemCode</td>-->
            <td class="header-table-heading">Customer Item #<b/></td>
            <td class="header-table-heading">COO</td>
            <td class="header-table-heading">ECCN #</td>
            <td class="header-table-heading">UOM</td>
            <td class="header-table-heading">Unit Price</td>
            <td class="header-table-heading">Quantity</td>
            <td class="header-table-heading">Extension</td>
        </tr>
        <tr>
            <td class="header-table-heading"></td>
            <td colspan="8" style="text-align:left"  class="header-table-heading">Description</td>
        </tr>
        <apex:repeat value="{!appointmentList}" var="line">
        <apex:outputPanel layout="none" rendered="{!if(line.pick==false, true, false)}">

        <tr>         
            <td class="header-table-data"><apex:outputText value="{!line.LineNumber}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!line.productname}"></apex:outputText></td>
            <!--<td class="header-table-data"><apex:outputText value="{!line.BinItemCode}"></apex:outputText></td>-->
            <td class="header-table-data"></td>
            <td class="header-table-data"></td>
            <td class="header-table-data">8541.40.2000</td>
            <td class="header-table-data">EA</td>
            <!--<td class="header-table-data">$1</td>-->
            <td class="header-table-data">$<apex:outputtext value="{!line.unitprice}"></apex:outputtext></td>
            <td class="header-table-data"><apex:outputtext value="{!line.quantity}"></apex:outputtext></td>
            <td class="header-table-data"><apex:outputtext value="{!line.extension}"></apex:outputtext></td>
        </tr>
        <tr>
            <td class="header-table-data"></td>
            <td colspan="8" style="text-align:left" class="header-table-data"><b>Scheduled Ship Date:</b>
                        <apex:outputText value="{0,date,MM'/'dd'/'yyyy}">
                                <apex:param value="{!line.Scheduledshipdate}"/>
                        </apex:outputText> </td>
        </tr>
        </apex:outputPanel>    
        </apex:repeat>
    </table>
    <br/>
    <table>
        <tr>
            <td class="header-table-heading">Gross Weight</td>
            <td class="header-table-heading">Net Weight</td>
            <td class="header-table-heading">Shipped Via</td>
            <td class="header-table-heading">Tracking #</td>
            <td class="header-table-heading">Payment Terms</td>
            <td class="header-table-heading">Incoterms </td>
            <td class="header-table-heading">Currency </td>
            <td rowspan="0" class="header-table-heading">Sub Total <br/>Shipping Charges</td>
            <td rowspan="0" class="header-table-data" id="sub"><apex:outputText value="{!opportunity.Non_Pick_Total__c}"></apex:outputText>
                                                   <br/><apex:outputText value="{!Opportunity.Shipping_Charges__c}"></apex:outputText><br/></td>

        </tr>
        <apex:repeat value="{!appointmentList1}" var="line1">
        </apex:repeat>
        <tr>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Gross_Weight__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Net_weight__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Shipped_Via__c}"></apex:outputText></td>
            <td class="header-table-data"><apex:outputText value="{!Opportunity.Bill_of_Lading__c}"> </apex:outputText></td>
            <td class="header-table-data">Net 30</td>
            <td class="header-table-data">EXW</td>
            <td class="header-table-data">USD</td>
            <td rowspan="0" class="header-table-heading"> Total Amount Due</td>
            <td class="header-table-data"><apex:outputText value="{!opportunity.Non_Pick_Total__c + opportunity.Shipping_Charges__c}"></apex:outputText></td>
        </tr>
    </table>
</body>
</apex:page>

Code :

    public with sharing class InvoiceController {
           List<wrapperClass> appointmentList {get;set;}
           List<wrapperClass> appointmentList1 {get;set;} 
           public list<string> address{get;set;}
           public string address1{get;set;}
           public string address2{get;set;}
           public string address3{get;set;}
           public string address4{get;set;}
           public string address5{get;set;}
           public string address6{get;set;}
           public string address7{get;set;}
           public String showaddressonVf{get;set;}
           public string wholeaddress{get;set;}
            public static wrapperClass tempObj2 ;

   //Added by sumit
               List<String> stringList ;
               public String all{get;set;}
           //------------
   public InvoiceController(){
   list<opportunity> op=[select id,Shipment_Info__c
   from opportunity where id=:apexpages.currentpage().getparameters().get('id')];
    //opportunity op=[select id,Shipment_Info__c from opportunity where id=:apexpages.currentpage().getparameters().get('id')];
       //---------------------Added by sumit----------------------
       stringList= new List<String>(); 
       if(op.size()>0)
       if(op[0].Shipment_Info__c!=NULL && op[0].Shipment_Info__c!=''){
           List<String> stringList=(op[0].Shipment_Info__c).split(',');
               for(integer i=0;i<stringList.size();i++){
                   all=all+stringList[i]+'<br/>';
               }

           all=all.remove('null');      
        }
      //------------------------------------------------------------
   }
       public Id OppId{get;set;}



       public InvoiceController(ApexPages.StandardController sc) {
       oppId=Apexpages.currentPage().getparameters().get('Id');
   }
               public List<wrapperClass> getappointmentList (){
               wrapperClass tempObj;
               tempObj = new wrapperClass();

               List<wrapperClass> aReList = new List<wrapperClass>(); 
           List<Opportunity> opp=[select id,Name,AccountId from Opportunity where id=:oppid limit 1];
           List<opportunity> Opp1=[select id,name,CreatedDate from opportunity where id=:oppid];
           //Opportunity opp1=[select id,Name,AccountId from Opportunity where id=:oppid limit 1];
           //Opportunity Opp=[select id,name,CreatedDate from opportunity where id=:oppid ];
                          List<OpportunityLineItem> OPplineitem= [SELECT OpportunityId,Quantity,PricebookEntry.Product2.Name,Sys_total_Amount__c,LN__c,Extension__c,ListPrice
                          ,Pick__c,Schedule_Ship_date__c,Bin_Item_Code__c ,PricebookEntry.Product2.Product_Line__c,OpportunityLineItem.Opportunity.Subtotal__c,OpportunityLineItem.Opportunity.Non_Pick_Total__c
                           FROM OpportunityLineItem where OpportunityId=:oppId]; 
                          system.debug('HHHHHHHHHH'+OPplineitem.size());
                          tempObj2 =new wrapperClass();
                         // tempObj1.Subtotal=
                       for(integer i=0; i < OPplineitem.size(); i++)
                       {
                     tempObj = new wrapperClass();
                     tempObj.productname= OPplineitem[i].PricebookEntry.Product2.Name;
                     tempObj.BinItemCode=OPplineitem[i].Bin_Item_Code__c;
                     tempObj.quantity=OPplineitem[i].Quantity;
                     tempObj.totalamount=OPplineitem[i].Sys_total_Amount__c;
                    // tempObj.Subtotal =OPplineitem[i].Opportunity.Subtotal__c;
                 //   tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c;

                     //j=j+OPplineitem[i].Quantity * tempObj.unitprice;

                    // tempObj.productline=OPplineitem[i].PricebookEntry.Product2.Product_Line__c;
                     //Add a conditional statement here


                 if(OPplineitem[i].PricebookEntry.Product2.Product_Line__c=='DIE') 
                     {
                      tempObj.unitprice=0.01;
                      tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice;
                      tempObj.productname=OPplineitem[i].Bin_Item_Code__c;
                      //tempObj.Subtotal =j;
                      if(i==0){
                      tempObj2.Subtotal=tempobj.extension;
                     }
                     else{
                      tempObj2.Subtotal=tempObj2.Subtotal+tempObj.extension;
                       }

                    // tempObj1.Subtotal =tempObj1.Subtotal+tempObj.extension;
                     system.debug('@@@@@@@@'+tempObj2.Subtotal);

                    //tempObj.NonPickTotal=OPplineitem[i].Opportunity.Non_Pick_Total__c*tempObj.unitprice;

                     }
                 else
                     {
                     tempObj.unitprice=1;
                     //tempObj.unitprice=OPplineitem[i].ListPrice;
                     tempobj.extension=OPplineitem[i].Extension__c ;
                    }
                     tempobj.LineNumber=OPplineitem[i].LN__c;
                     tempobj.Pick= OPplineitem[i].Pick__c;
                     tempobj.ScheduledShipDate = Opplineitem[i].schedule_ship_date__c;

                     if(tempobj!=null){
                        aReList.add(tempObj);
                     }
                    }

           return aReList;


   }



       public List<wrapperClass> getappointmentList1 (){
           wrapperClass tempObj1 ; 
           List<wrapperClass> aReList1 = new List<wrapperClass>();
                   List<Opportunity> opp=[select id,Name,AccountId,Shipment_Info__c,
                    Shipping_Address_Line1__c,
                        Shipping_Address_Line2__c,
                        Shipping_Address_Line3__c,
                        Shipping_City__c,
                        Shipping_State_Province__c,
                        Shipping_Zipcode__c,
                        Shipping_Country__c  
                        from Opportunity where id=:oppid];
           for(integer i=0; i < opp.size(); i++)
           {
             tempObj1 = new wrapperClass();
             tempObj1.billingAddress= opp[i].Shipment_Info__c;
                               }
             aReList1.add(tempObj1);        

             /* Below code commented by Kiranmai as Shipment Info field is split into multiple fields

             //------- Added by Sumit-----------  
             stringList= new List<String>(); 

             if(aReList1[0].billingAddress!=NULL && aReList1[0].billingAddress!=''){
                List<String> stringList=(aReList1[0].billingAddress).split(',');
                for(integer i=0;i<stringList.size();i++){
                   all=all+stringList[i]+'<br/>';
                }
             } */

             all = all + opp[0].Shipping_Address_Line1__c + '<br/>';
             if(opp[0].Shipping_Address_Line2__c!=NULL && opp[0].Shipping_Address_Line2__c!=''){
                 all = all + opp[0].Shipping_Address_Line2__c + '<br/>';
             }

             if(opp[0].Shipping_Address_Line3__c!=NULL && opp[0].Shipping_Address_Line3__c!=''){
                 all = all + opp[0].Shipping_Address_Line3__c + '<br/>';
             } 

             if(opp[0].Shipping_City__c!=NULL && opp[0].Shipping_City__c!=''){
                 all = all + opp[0].Shipping_City__c + '<br/>';
             }

             if(opp[0].Shipping_State_Province__c!=NULL && opp[0].Shipping_State_Province__c!=''){
                 all = all + opp[0].Shipping_State_Province__c + '<br/>';
             }  

             if(opp[0].Shipping_Zipcode__c!=NULL && opp[0].Shipping_Zipcode__c!=''){
                 all = all + opp[0].Shipping_Zipcode__c + '<br/>';
             }

             if(opp[0].Shipping_Country__c!=NULL && opp[0].Shipping_Country__c!=''){
                 all = all + opp[0].Shipping_Country__c + '<br/>';
             }
            /* all = all + opp[0].Shipping_City__c + ', '+opp[0].Shipping_State_Province__c + ' - ' + opp[0].Shipping_Zipcode__c + '<br/>';
             all = all + opp[0].Shipping_Country__c + '<br/>';*/

             all=all.remove('null');

                /*-----------------------------------*/ 
      return aReList1;  
   }
           public class wrapperClass{
          // public String Item{get;private set;}
           public String productname{get; set;}
           public String BinItemCode{get;set;}
           public Decimal Quantity{get;set;}
           public Decimal totalamount{get;set;}
           public Decimal Subtotal{get;set;}
           public Decimal NonPickTotal{get;set;}                            
           public Decimal unitprice{get;set;}
           public date todaysdate{get;set;}
           public decimal extension{get;set;}
           public string LineNumber{get;set;}
           public string billingAddress{get;set;}
           public string splittedaddress{get;set;}
           public string productline{get;set;}
           public string wholeaddress{get;set;}
           public boolean Pick{get;set;}
           public date ScheduledShipDate{get;set;}
           public wrapperClass(){}                
       }


}

When i check in the Debug logs the value gets calculated but it does not get changed in the visual force page. PFA SCreen Shot : enter image description here Any help very much appreciated.

11
  • What do you mean "does not get changed in the visual force page"? How are you displaying these values on the page? Is the code you posted part of the initialization of the page or a result of some action?
    – CyberJus
    Mar 27, 2015 at 2:35
  • @ CyberJus:Based on condition i have written a logic in the code.The logic works in condition for step 1 and 2 and fails at step 3.The code posted is a part of the logic written .
    – nikkey
    Mar 27, 2015 at 9:40
  • As you using a wrapper class for tempObj2, and are are you doing anything to that tempObj2.subtotal other than what you posted? Can you add a debug into your else condition to check how it is incrementing?
    – CyberJus
    Mar 27, 2015 at 13:08
  • @CyberJus:i have updated the complete code ,the tempObj2 is used for the logic
    – nikkey
    Mar 27, 2015 at 16:25
  • can you post your VF code so I can see those fields being used? As far as I can tell, since you using that wrapper class, any roll-up fields on the object should not matter - you are doing your own roll up.
    – CyberJus
    Mar 27, 2015 at 16:46

2 Answers 2

0

If you are doing the a custom calculation using an object in your controller, you need to make sure that object is the one being used on the page.

In this case the controller is doing a custom calculation using tempObj2 into the Subtotal property. The fix is to use {!tempObj2.Subtotal} on the Visualforce page.

2
  • :I have a visual force page created for 4 reports and has wizard controller .The logic is working fine at one report and gets failed for other report.For PickReport & PickReportUS :The condition is Subtotal__c=Non_Pick_Total__c(Rollup summary :Aggregrates the Extension,has a Criterias as "Pick is False" ) and for InvoiceReport&InvoiceReportUS:Subtotal__c=Pick_Total__c(Rollup summary :Aggregrates the Extension,has a Criterias as "Pick is True" ).
    – nikkey
    Mar 31, 2015 at 10:43
  • When i use the {!tempObj2.Subtotal} on the Visualforce page in place of "{!opportunity.Non_Pick_Total__c}",It is displaying the total value of extension instead of one value which is not picked .Similarly in case of Invoice report.Any help very much appreciated.
    – nikkey
    Mar 31, 2015 at 10:46
0

I think your issue is most likely caused by the use of a formula field. Can't you create a new field just for this? (since its not possible to overwrite a formula field)

1
  • :This formula field is linked with other roll up summary field for the aggregration with their criterias.I tried changing the formula ,it works for one condition and the next condition gets failed.when i unchange the formula one conditions get failed and the other works .Any help very much appreciated.
    – nikkey
    Mar 27, 2015 at 10:09

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .