zoukankan      html  css  js  c++  java
  • 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="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 }
  • 相关阅读:
    C++总结
    KMP算法
    理解I/O Completion Port(完成端口)
    [转载]Windows网络编程系列教程之四:Select模型
    [转载]理解 I/O Completion Port (IOCP完成端口)
    [转载]IOCP模型的总结
    发个IOCP的C++例子
    说说网络通信模型
    几个网络模型的示例代码(BlockingModel、OverlappedModel、WSAEventSelect、CompletionRoutine)..c++
    关于Socket 多线程 的一篇好文章
  • 原文地址:https://www.cnblogs.com/pipidan/p/6904895.html
Copyright © 2011-2022 走看看