1

Can any one help me on this. I have a visual force page created in PDF format. I have few of the products with different names in different product family. If the product line for the product selected in opportunity items is ‘DIE’ make following changes .

1) unit price should change to $.01.

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

Visual force Code :

<apex:page standardController="Opportunity" renderAs="pdf" applyhtmltag="false" showHeader="false" applyBodyTag="false" extensions="InvoiceController">
<head>
    <style>
        @page {
            margin: 1px 50px 225px 50px; 
            size:A4;
            Padding-top:30px;

            @top-center { 
                    content : element(header);
                 }

            @bottom-center {
                    content : element(footer);
                    height:200px;
                    padding-top:10px;
                 }
        } 
        body { font-family: 'Arial Unicode MS'; }
        .companyName { font: bold 30px; color: red; }  
        table {width:100%; border-spacing:0; border-collapse:collapse; border-width: 1px; border-color:#C0C0C0;border-style:solid;} 
        .header-table-data { border-width: 1px; border-color:Black;border-style:solid;background-color:#FFFFFF;
                             color:Black; font-size:14px; font-family:Verdana;
                             text-align:center;}
        .header-table-heading {border-width: 1px; border-color:Black;border-style:solid;background-color:#C0C0C0; 
                               font-weight:bold;color:Black; font-size:14px; font-family:Verdana;
                               text-align:center;}
        .header-data { border-width: 0px; border-color:Black;border-style:solid;background-color:#FFFFFF;
                       color:Black; font-size:14px; font-family:Verdana;text-align:left; padding-right: 10px;}

        .header-heading {border-width: 0px; border-color:Black;border-style:solid; 
                         font-weight:bold;color:Black; font-size:14px; font-family:Verdana;
                         text-align:left;}
    </style>

</head>
<body> 

    <table>
        <tr>
            <td><img style="WIDTH:25%; HEIGHT: 25%" src='{!URLFOR($Resource.Bridgelux_New_Logo)}' />
            </td>
        </tr>
        <br/>
        <tr>
            <td><b>Commercial Invoice</b>
            </td>
        </tr>
    </table><br/>

    <table cellspacing="0" cellpadding="0" width="100%" border="0" >
        <tr>
           <!--- <td border="0" bgcolor="Silver">Sold To</td> ---->
            <td bgcolor="Silver">Ship To:</td>
            <td bgcolor="Silver">Ship From</td>
        </tr>
        <tr>
            <!--<td style="border-width: 0px; border-color:Black;border-style:solid;background-color:#FFFFFF;" align="left" width="10%">
                <f style="color:Black; font-size:12px; font-family:Verdana;">
                    <!-- Code starts here ********************************************************* -->
                    <!-- {!showaddressonVf} -->
                   <!-- <apex:outputText value="{!opportunity.account.Name}"></apex:outputText><br/>-->
                    <!-- Added by Sumit -->
                   <!-- <apex:outputText value=" {!all}" escape="false"></apex:outputText>-->
                    <!--     -----------   -->
                    <!--<br />-->
                <!--</f>-->
            <!--</td> -->     
            <td style="border-width: 0px; border-color:Black;border-style:solid;background-color:#FFFFFF;" align="left" width="10%">
            <f style="color:Black; font-size:12px; font-family:Verdana;">
                <!-- Code starts here ********************************************************* -->
                <!-- Added below line by KiranmaiKosaraju. To show Ship To Account Name If diff from Account Name or else show Account Name -->
                <apex:outputText value="{!IF ((opportunity.Ship_To_Account_Name__c = NULL),  opportunity.account.Name,opportunity.Ship_To_Account_Name__c)}"></apex:outputText><br /> 
                <!--<apex:outputText value="{!opportunity.account.Name}"></apex:outputText><br /> -->
                <!-- Added by Sumit -->
                <apex:outputText value=" {!all}" escape="false"></apex:outputText>
                <!--     -----------   -->
                <br />  
            </f>
            </td>
            <td style="border-width: 0px; border-color:Black;border-style:solid;background-color:#FFFFFF;" align="left" width="10%">
            <f style="color:Black; font-size:12px; font-family:Verdana;">
                Bridgelux Inc. C/O JSI Logistics (HK) Ltd.<br/>
                16/F Tsuen Wan International Center,<br/>
                68 Wang Lung Street, Tsuen Wan,<br/>
                Hong Kong<br/>
                Tel: (852) 3761 7080<br/>
                Fax: (852) 2750 0721<br/>
            </f>
            <f style="color:Blue; font-size:12px; font-family:Tahoma;"> Email:Info@bridgelux.com</f>
            <f style="color:Blue; font-size:10px; font-family:Trebuchet MS;"><br/> </f>
            </td>
        </tr>
    </table> 

     <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>
    </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<b/></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">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==true, 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.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"><apex:outputText value="{!opportunity.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.Pick_Total__c + opportunity.Shipping_Charges__c}"></apex:outputText></td>
        </tr>
    </table>
</body>
</apex:page>

APEX CLASS

public with sharing class InvoiceController {
           List<wrapperClass> appointmentList {get;set;}
           List<wrapperClass> appointmentList1 {get;set;} 
           public list<string> addaress{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;}
   //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
                          FROM OpportunityLineItem where OpportunityId=:oppId]; 
                          system.debug('HHHHHHHHHH'+OPplineitem.size());

                   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.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 productname{get;set;}
           public String BinItemCode{get;set;}
           public Decimal Quantity{get;set;}
           public Decimal totalamount{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 wholeaddress{get;set;}
           public boolean Pick{get;set;}
           public date ScheduledShipDate{get;set;}
           public wrapperClass(){}                
       }
}

I shall appreciate your help.

  • Without seeing the code for your PDF page, it's difficult for anyone to tell you what to do. Its possible, this change may need to be made in your controller, or I suppose I should say that it might be easiest to make it in the controller. It all depends on how the data for page is being generated. – crmprogdev Jan 14 '15 at 16:23
  • @crmprogdev:I have updated with code.can u plz help me on this.I shall appreciate your help. – nikkey Jan 14 '15 at 16:43
1

Not sure I totally understand what you are trying to do but by what it sounds like I would probably make the change in the Controller as crmprogdev suggested. It looks like your PDF is using a hard coded value of:

<td class="header-table-data">$1</td>

You would want to update this to:

<td class="header-table-data"><apex:outputtext value="{!line.unitprice}"></apex:outputtext></td>

If I understand your question

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;
                 //Add a conditional statement here
                // If 'DIE' is supposed to be a NULL check, then I would probably use this if statement
                // Assuming that you are not trying to say productname == "DIE"
                 if(isEmpty(tempObject.productname)) 
                     {
                      tempObj.unitprice=0.01;
                      tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice;
                     }
                 else
                     {
                     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);
                 }

It looks like you had a hardcoded value of $1 in the unitprice before on the output display and were not using the ListPrice stored on the Opporunity object, this code should resolve those problems.

  • :Thanks for your reply.But as per requirement is Only when the product_line is ‘DIE’,unit price should change to $.01. – nikkey Jan 14 '15 at 18:09
  • I didn't see where you were pulling product_line, so if you bring in the productline to your tempObj, you could thenreplace the IF statement with if(tempObject.productline == 'DIE') – TC Sutton Jan 14 '15 at 18:27
  • :The visual force page and the controller are related to opportunity and opportunitylineitem .The product_line is a custom field in Product object.So i need to add them in vf page and in controller as per the requirement when the product_line is ‘DIE’,unit price should change to $.01.So can we achieve this. – nikkey Jan 14 '15 at 18:36
  • you should be able to pull the product_line in on your SOQL query. – TC Sutton Jan 14 '15 at 18:50
  • :I have queryed the product line and added the IF condition if(tempObject.Product_Line__c==DIE) { tempObj.unitprice=0.01; tempobj.extension=OPplineitem[i].Quantity * tempObj.unitprice; } else { tempObj.unitprice=OPplineitem[i].ListPrice; tempobj.extension=OPplineitem[i].Extension__c;} but still i get an Error as :expecting a semi-colon, found '(' at line 84 column 53 .Any help is very much appreciated. – nikkey Jan 14 '15 at 19:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.