Salesforce PDF報價單制作


本篇介紹通過使用VF自帶標簽,css標簽和Apex實現簡單的 PDF報價單制作:

 

 

1.根據截圖,用自己的方式畫出於圖中類似的界面

        我的界面采用了一些Apex內部的標簽和css標簽樣式

  • ApexPages.Controller:當為一個標准Controller定義擴展的時候使用此類。Controller對象為Salesforce提供的預構建VF的控制器對象引用;

     

  1 <apex:page renderAs="pdf" showheader="false" sidebar="false" applyHtmltag="false" Controller="QuoteController"  >
  2    <head>
  3    <style>
  4      body {
  5         font-family: Arial Unicode MS;
  6      }
  7      .head_div{
  8      width:100%;
  9      height:100px;
 10      border:1px solid blue;
 11      margin-bottom:20px;
 12      text-align:right;
 13      line-height:100px
 14      }
 15        .table_one{
 16      margin:0px auto;
 17      width:100%;
 18      }
 19      
 20      
 21      .table_two{
 22      margin:0px auto;
 23      width:100%;
 24      border-collapse:collapse;
 25      text-align:center
 26      }
 27      
 28       .table_three{
 29       
 30      margin:0px auto;
 31      width:100%;
 32       border:none
 33      }
 34      
 35        .table_three th{
 36        margin-top:20px;
 37        text-align:center;
 38        border-top:none;
 39        border:none
 40       
 41      }
 42     
 43    
 44      .div_mian{
 45       text-align:center;
 46       margin-top:50px;
 47      }
 48      
 49      
 50      </style>
 51    </head>
 52    <body>
 53    <div class="head_div"  >
 54    <apex:outputText value="Proiect Quotation"   style="font-size:20px;color:blue;font-weight:bold"/>
 55    </div>
 56        <!--導入靜態資源  
--> 57 <apex:image url="{!$Resource.salfLogo}" width="130" height="90" style="position:fixed; top:35px; left:15px;" /> 58 59 <table class="table_one" > 60 <tr style="margin:-80px auto;"> 61 <td> 62 <apex:outputText value="www.self-electronics.com" style="text-decoration:underline"/><br/> 63 <apex:outputText value="3264 Saturn count,Peachtree Corners,GA 30092" /><br/> 64 <apex:outputText value="P 770.248.9023 F 770.248.9028"></apex:outputText> 65 </td> 66 <td style="background:#f6f5ec"> 67 <apex:outputText value="Date:" style="padding-right:270px;"/> 68 <apex:outputField value="{!Quote.QuoteDate__c}"/> 69 <br/> 70 <apex:outputText value="Project Name: " style="font-weight:700" />{!Quote.Name} 71 </td> 72 </tr> 73 <tr style="height:100px"> 74 <td> <apex:outputText value="BILL TO" style="background:#f6f5ec;padding-right:25px;"/> 75 <apex:outputField value="{!Quote.BillingCity}"/> 76 <apex:outputField value="{!Quote.BillingCountry}"/> 77 <apex:outputField value="{!Quote.BillingState}"/> 78 79 80 </td> 81 <td> <apex:outputText value="SHIP TO" style="background:#f6f5ec;padding-right:25px"/> 82 <apex:outputField value="{!Quote.ShippingCountry}"/> 83 <apex:outputField value="{!Quote.ShippingCity}"/> 84 <apex:outputField value="{!Quote.ShippingState}"/> 85 86 </td> 87 </tr> 88 </table> 89 90 <table class="table_two"> 91 <thead > 92 <tr style='background:#d3d7d4;'> 93 <th>SALES PERSON</th> 94 <th>SHIP DATE</th> 95 <th>SHIP VIA</th> 96 <th>TERMS</th> 97 </tr> 98 </thead> 99 <tbody> 100 <tr style='background:#f6f5ec;'> 101 <td>{!Quote.Account.Name}</td> 102 <td>TBD</td> 103 <td>{!Quote.Contact}</td> 104 <td>TBD</td> 105 </tr> 106 </tbody> 107 </table> 108 <!--<div style="width:100%;height:20px;border:1px solid blue;background:blue;margin-top:20px"></div>--> 109 110 <br/> 111 <table class="table_three" cellspacing="0"> 112 113 <thead > 114 <tr style="background:blue; border-collapse:collapse;"> 115 <td colspan="7" style=" border-bottom:none;">&nbsp;</td> 116 </tr > 117 <tr > 118 <th>Line</th> 119 <th>Model Number</th> 120 <th>Catalog Number</th> 121 <th>Description</th> 122 <th>Quantity</th> 123 <th>Price</th> 124 <th>Amount</th> 125 </tr> 126 </thead> 127 <tbody> 128 <apex:repeat value="{!pis}" var="it"> 129 <tr > 130 <td style="text-align:center;border:0.5pt solid #080808" >{!it.serial}</td> 131 <td style="border:0.5pt solid #080808">{!it.qli.Product2.Name}</td> 132 <td style="border:0.5pt solid #080808">{!it.qli.Product2.Description}</td> 133 <td style="text-align:right;border:0.5pt solid #080808">{!it.qli.Quantity}</td> 134 <td style="text-align:right;border:0.5pt solid #080808">{!it.qli.Subtotal}</td> 135 <td style="text-align:right;border:0.5pt solid #080808">{!it.qli.UnitPrice}</td> 136 <td style="text-align:right;border:0.5pt solid #080808">{!it.qli.TotalPrice}</td> 137 138 139 </tr> 140 </apex:repeat> 141 142 <tr style="background:blue;border-bottom:none;border-collapse:collapse;"> 143 <td colspan="5" style=" border:none">&nbsp;</td> 144 <td style="text-align:left;color:white;font-size:11px; border:none">TOTAL:</td> 145 <td style="text-align:right;color:white;font-size:11px; border:none">{!Quote.TotalPrice}</td> 146 </tr > 147 </tbody> 148 </table> 149 150 151 <div class="div_mian"> 152 <apex:outputText value="Shipping not includ,actual freight costs will be billed on invoice." /><br/> 153 <apex:outputText value="QUOTE VALID FOR 30 DAYS." style="font-size:18px"/> 154 </div> 155 </body> 156 </apex:page>

 

 創建一個QuoteController      

一個報價的對象里面  可能有多張報價單  所以一開始  得取到打印的那張報價單的id    同時在報價單里面創建一個打印報價的按鈕  自定義按鈕

按鈕綁定id  當點擊按扭時  則出現你將打印的報價單

 

 

 1 public class QuoteController{
 2     public Quote quote {get; set;}
 3     public List<ProductItem> pis {get; set;}//相當於自己創建的一個虛擬對象,要吧序號放到這個對象,然后后面接對象
 4     
 5     public QuoteController() {
 6          //獲取頁面quoteId 
 7          String qtId = ApexPages.currentPage().getParameters().get('quoteId');
 8           //根據取到的quoteId去查詢數據
 9          quote = [SELECT Id,Name, QuoteNumber, QuoteDate__c, Account.Name, BillingCountry, Contact.Name, DateofDelivery__c, 
10                 ShippingCity, ShippingCountry, ShippingPostalCode, ShippingState, BillingCity, BillingState,    
11                 Opportunity.Owner.Name, Opportunity.Owner.Email, Opportunity.Owner.Phone, 
12                 Tax, Subtotal, TotalPrice, GrandTotal
13             FROM Quote 
14             WHERE Id = :qtId];
15            //系統里面有的數據對象
16            List<QuoteLineItem> quoteItems = [SELECT Id, HSCode__c, Product2Id, Product2.Name, Product2.Description, 
17                 Quantity, Subtotal, TotalPrice, UnitPrice 
18             FROM QuoteLineItem 
19             WHERE QuoteId = :qtId];
20         
//pis是一個集合 21 pis = new List<ProductItem>(); 22 Integer i = 1;
     //循環取到系統的數據
23 for(QuoteLineItem li: quoteItems) {
         添加到pis集合里面,i是序號,li是循環取出來的一條條數據,放到pis里面
24 pis.add(new ProductItem(i, quote.DateofDelivery__c.format().replace('.','/'), li)); 25 i++; 26 } 27 28 29 30 } 31 // 構造函數 命名屬性 虛擬對象里面需要的東西 前端取值 32 Class ProductItem { 33 public Integer serial {get; set;} 34 public String dlDate {get; set;} 35 public QuoteLineItem qli {get; set;} 36
      //實例化 37 public ProductItem(Integer serial, String dlDate, QuoteLineItem qli) { 38 this.serial = serial; 39 this.dlDate = dlDate; 40 this.qli = qli; 41 } 42 } 43 44 }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM