+ Start a Discussion
rajesh k 10rajesh k 10 

URGENT:How to Multiply Datatable two columns ?

hi,
        
<apex:dataTable value="{!listOfOptionalAdOnWrapper}" var="pitem" rowClasses="odd,even" width="100%" rendered="{!listOfOptionalAdOnWrapper.size > 0}">
                        <apex:column headerValue="Action">

                            <apex:inputCheckbox value="{!pitem.isSelected}" id="InputId" />
                        </apex:column>
                        <apex:column headerValue="Name">

                            <apex:outputField value="{!pitem.optionaladon.Name}" />
                        </apex:column>
                       <apex:column headerValue="Quantity">

                            <apex:outputField value="{!pitem.optionaladon.Quantity__c}">
                                   <apex:inlineEditSupport event="ondblclick" showOnEdit="update" />
                            </apex:outputField>
                        </apex:column> 
                        <apex:column headerValue="list Price">

                         <apex:outputtext value="{!ProductidToPricebookEntryOfOptionalAdOnProduct[pitem.optionaladon.Product__c]}"/> 

                        </apex:column>
                         <apex:column headerValue="Total">

                          <apex:facet name="footer">
                                <strong> Total: </strong>
                            </apex:facet>
                        </apex:column>
                    </apex:dataTable>

Controller:
public List < Optional_Ons__c > OptionalAdOnProductList {get;set;}
public  Map<Id,Decimal>  ProductidToPricebookEntryOfOptionalAdOnProduct{get;set;}


 Set<Id> productisOfOptionalAdon=new set<Id>();
            OptionalAdOnProductList = [select id, name,BObject__c,Quantity__c,Product__c from Optional_Ons__c  where BObject__c = : bId];
            if (OptionalOnProductList.size() > 0) {
                for (Optional_Ons__c iterateadOn: OptionalAdOnProductList) {
                    listOfOptionalAdOnWrapper.add(new OptionalAdOnWrapper(iterateadOn));
                    productisOfOptionalAdon.add(iterateadOn.Product__c);
                    System.debug('&&&&listOfWrapper&&&&&' + listOfOptionalAdOnWrapper);
                }
            }
            //Ger all the products related Pricebook as well as bundle object selected Pricebook match
            for(PricebookEntry pricBkEntry : [SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry WHERE Product2Id IN :productisOfOptionalAdon AND Pricebook2Id = :pricebookid AND CurrencyIsoCode='USD']){
			       Decimal Listprice=pricBkEntry.UnitPrice;
			        ProductidToPricebookEntryOfOptionalAdOnProduct.put(pricBkEntry.Product2Id,Listprice);
			}

//Wrapper class

public class OptionalAdOnWrapper {
        public Boolean isselected {get;set;}
        public Optional_Ons__c optionaladon {get;set;}
        public OptionalAdOnWrapper(Optional_Ons__c optional) {
            this.optionaladon = optional;
            this.isselected   =False;
        }
    }

Action            Productname Quantity   Listprice   Total
checkbox        xxxx               123         500          ?
checkbox        yyyy                321        400           ?
                                                        
                                                           Grand Total:?

Please help me How to calculate Total and Grand Total?
shiva pendemshiva pendem
Hi,

Try below code.
Controller :

public List < Optional_Ons__c > OptionalAdOnProductList {get;set;}
public  Map<Id,Decimal>  ProductidToPricebookEntryOfOptionalAdOnProduct{get;set;}
public decimal GrandTotal{get;set;}

 Set<Id> productisOfOptionalAdon=new set<Id>();
            OptionalAdOnProductList = [select id, name,BObject__c,Quantity__c,Product__c from Optional_Ons__c  where BObject__c = : bId];
            public decimal Mtotal;

            if (OptionalOnProductList.size() > 0) {
                GrandTotal=0;
                for (Optional_Ons__c iterateadOn: OptionalAdOnProductList) {
                     Mtotal =  iterateadOn.Quantity__c*iterateadOn.Product__c;
                     GrandTotal = Mtotal+GrandTotal;
                    listOfOptionalAdOnWrapper.add(new OptionalAdOnWrapper(iterateadOn,Mtotal));
                    productisOfOptionalAdon.add(iterateadOn.Product__c);
                    
                    System.debug('&&&&listOfWrapper&&&&&' + listOfOptionalAdOnWrapper);
                }
            }
            //Ger all the products related Pricebook as well as bundle object selected Pricebook match
            for(PricebookEntry pricBkEntry : [SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry WHERE Product2Id IN :productisOfOptionalAdon AND Pricebook2Id = :pricebookid AND CurrencyIsoCode='USD']){
                   Decimal Listprice=pricBkEntry.UnitPrice;
                    ProductidToPricebookEntryOfOptionalAdOnProduct.put(pricBkEntry.Product2Id,Listprice);
            }

//Wrapper class

public class OptionalAdOnWrapper {
        public Boolean isselected {get;set;}
        public Optional_Ons__c optionaladon {get;set;}
        public decimal MultiTotal{get;set;}
        public OptionalAdOnWrapper(Optional_Ons__c optional,decimal mt) {
            this.optionaladon = optional;
            this.isselected   = False;
            this.MultiTotal   = mt;
        }
    }

Vf page:

<apex:dataTable value="{!listOfOptionalAdOnWrapper}" var="pitem" rowClasses="odd,even" width="100%" rendered="{!listOfOptionalAdOnWrapper.size > 0}">
                        <apex:column headerValue="Action">

                            <apex:inputCheckbox value="{!pitem.isSelected}" id="InputId" />
                        </apex:column>
                        <apex:column headerValue="Name">

                            <apex:outputField value="{!pitem.optionaladon.Name}" />
                        </apex:column>
                       <apex:column headerValue="Quantity">

                            <apex:outputField value="{!pitem.optionaladon.Quantity__c}">
                                   <apex:inlineEditSupport event="ondblclick" showOnEdit="update" />
                            </apex:outputField>
                        </apex:column>
                        <apex:column headerValue="list Price">

                         <apex:outputtext value="{!ProductidToPricebookEntryOfOptionalAdOnProduct[pitem.optionaladon.Product__c]}"/>

                        </apex:column>
                         <apex:column headerValue="Total">
                               <apex:outputLabel Value="{!pitem.MultiTotal}"/>
                        </apex:column>
                        <apex:facet name="footer">
                         <strong> Total: </strong>
                              <apex:outputLabel value="{!GrandTotal}"/>
                     </apex:facet>
                    </apex:dataTable>


Thanks,
 Shiva

 
rajesh k 10rajesh k 10
  Hi , 
         Thank you for reply .I got below error:

   "arithematic expressions must be numaric arguments error" Here
 
Mtotal =  iterateadOn.Quantity__c*iterateadOn.Product__c;

help me..

 
shiva pendemshiva pendem
Hi,
Try to check the fied data types of these two fields and check whether the type is Number or any other .

thanks
shiva
rajesh k 10rajesh k 10
ok Thanks.Here How can i check map condition.I want to check  below for loop currect put Listprice into pricBkEntry.Product2Id.Otherwise how can i throw an error" value(unit price) is not match to related Product(pricBkEntry.Product2Id)"


for(PricebookEntry pricBkEntry : [SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry WHERE Product2Id IN :productisOfOptionalAdon AND Pricebook2Id = :pricebookid AND CurrencyIsoCode='USD']){ Decimal Listprice=pricBkEntry.UnitPrice; ProductidToPricebookEntryOfOptionalAdOnProduct.put(pricBkEntry.Product2Id,Listprice); }

 
public List < Optional_Ons__c > OptionalAdOnProductList {get;set;}
public  Map<Id,Decimal>  ProductidToPricebookEntryOfOptionalAdOnProduct{get;set;}


 Set<Id> productisOfOptionalAdon=new set<Id>();
            OptionalAdOnProductList = [select id, name,BObject__c,Quantity__c,Product__c from Optional_Ons__c  where BObject__c = : bId];
            if (OptionalOnProductList.size() > 0) {
                for (Optional_Ons__c iterateadOn: OptionalAdOnProductList) {
                    listOfOptionalAdOnWrapper.add(new OptionalAdOnWrapper(iterateadOn));
                    productisOfOptionalAdon.add(iterateadOn.Product__c);
                    System.debug('&&&&listOfWrapper&&&&&' + listOfOptionalAdOnWrapper);
                }
            }
            //Ger all the products related Pricebook as well as bundle object selected Pricebook match
            for(PricebookEntry pricBkEntry : [SELECT Product2Id,Pricebook2Id,UnitPrice FROM PriceBookEntry WHERE Product2Id IN :productisOfOptionalAdon AND Pricebook2Id = :pricebookid AND CurrencyIsoCode='USD']){
			       Decimal Listprice=pricBkEntry.UnitPrice;
			        ProductidToPricebookEntryOfOptionalAdOnProduct.put(pricBkEntry.Product2Id,Listprice);
			}

//Wrapper class

public class OptionalAdOnWrapper {
        public Boolean isselected {get;set;}
        public Optional_Ons__c optionaladon {get;set;}
        public OptionalAdOnWrapper(Optional_Ons__c optional) {
            this.optionaladon = optional;
            this.isselected   =False;
        }
    }
help me...