![]()
<apex:page renderAs="pdf" showheader="false" sidebar="false" applyHtmltag="false" Controller="ExportAccountController">
<head>
<style>
body {
font-family: Arial Unicode MS;
}
.div_main{
font-size:32px;
margin:0px auto;
width:100%;
text-align:center
}
.tableInfo{
border-collapse:collapse;
text-align:center
margin:0px auto;
width:100%;
font-size:12px;
}
.table{
border-collapse:collapse;
text-align:center
margin:0px auto;
width:100%;
font-size:12px;
}
</style>
</head>
<body>
<div class="div_info">
<apex:image url="{!$Resource.Meritor_Loge}" width="270" height="50"/>
</div>
<div class="div_main">
<apex:outputText value="客户信息增加/变更表" />
</div>
<div style="text-align:center" >
{!YEAR(TODAY())}年{!MONTH(TODAY())}月{!DAY(TODAY())}日
</div>
<table class="tableInfo" border="1" color="black">
<tr>
<td colspan="3" style="height:60px;">
客户编码(价格表): <apex:outputField value="{!Account.AccountCode__c}"/>
</td>
<td style="border:none;text-align:right;" colspan="7">
<apex:outputText value=" 合同编号:" />
<apex:repeat value="{!contractList}" var="ct">
<apex:outputField value="{!ct.Name}"/>
</apex:repeat>
</td>
</tr>
<tr>
<th rowspan="5" style="width:6px;text-align:center;r:none">客<br/>户<br/>地<br/>址<br/>信<br/>息</th>
<th colspan="4" style="text-align:center">新建(变更)客户</th>
<th colspan="4" style="text-align:center">原客户</th>
</tr>
<tr>
<th style="width:80px;height:40px;text-align:center"> <apex:outputText value="客户名称" /><br/></th>
<td colspan="3" style="text-align:center"></td>
<th style="width:80px;height:40px;text-align:center"><apex:outputText value="客户名称" /><br/></th>
<td colspan="3" style="text-align:center"><apex:outputField value="{!Account.Name}"/></td>
</tr>
<tr>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="纳税人识别号" /><br/><apex:outputText value="(地址1)" /></th>
<td colspan="3" style="text-align:center"></td>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="纳税人识别号" /><br/><apex:outputText value="(地址1)" /></th>
<td colspan="3" style="text-align:center"><apex:outputField value="{!Account.TaxNo__c }"/></td>
</tr>
<tr>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="地址,电话" /><br/><apex:outputText value="(地址2)" /></th>
<td colspan="3" style="text-align:center"></td>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="地址,电话" /><br/><apex:outputText value="(地址2)" /></th>
<td colspan="3" style="text-align:center"><apex:outputField value="{!Account.Phone}"/><br/><apex:outputField value="{!Account.Phone}"/></td>
</tr>
<tr>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="开户行及账号" /><br/><apex:outputText value="(地址3)" /></th>
<td colspan="3" style="text-align:center"></td>
<th style="width:80px;height:40px;text-align:center">
<apex:outputText value="开户行及账号" /><br/><apex:outputText value="(地址3)" /></th>
<td colspan="3" style="text-align:center"><apex:outputField value="{!Account.Bank__c}"/><br/><apex:outputField value="{!Account.Account__c}"/></td>
</tr>
<tr>
<th rowspan="3" style="width:6px;text-align:center">客<br/>户<br/>数<br/>据</th>
<th style="width:80px;height:50px;text-align:center"> <apex:outputText value="推销员代码" /><br/></th>
<td style="width:80px;height:50px;text-align:center" ></td>
<th style="width:80px;height:50px;text-align:center"><apex:outputText value="地区(财务)" /><br/></th>
<td style="width:80px;height:50px;text-align:center"></td>
<th style="width:80px;height:50px;text-align:center"> <apex:outputText value="推销员代码" /><br/></th>
<td style="width:80px;height:50px;text-align:center"></td>
<th style="width:80px;height:50px;text-align:center"><apex:outputText value="地区(财务)" /><br/></th>
<td></td>
</tr>
<tr>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="销售渠道" /><br/></th>
<td style="width:85px;height:50px;text-align:center"></td>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="付款方式" /><br/></th>
<td style="width:85px;height:50px;text-align:center"></td>
<th style="width:84px;height:50px;text-align:center"> <apex:outputText value="销售渠道" /><br/></th>
<td style="width:85px;height:50px;text-align:center"><apex:outputField value="{!Account.Channel__c}"/></td>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="付款方式" /><br/></th>
<td style="width:85px;height:50px;text-align:center"><apex:outputField value="{!Account.PaymentMethod__c}"/></td>
</tr>
<tr>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="客户类型" /><br/></th>
<td style="width:85px;height:50px;text-align:center"></td>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="信用等级" /><br/></th>
<td style="width:85px;height:50px;text-align:center"></td>
<th style="width:84px;height:50px;text-align:center"> <apex:outputText value="客户类型" /><br/></th>
<td style="width:85px;height:50px;text-align:center"><apex:outputField value="{!Account.Type}"/></td>
<th style="width:84px;height:50px;text-align:center"><apex:outputText value="信用等级" /><br/></th>
<td style="width:85px;height:50px;text-align:center"><apex:outputField value="{!Account.CreditRating__c}"/></td>
</tr>
</table>
<table class="table" border="1">
<tr>
<th rowspan="{!Count}" style="width:6px;text-align:center;border-top:none;text-align:center">合<br/>同<br/>价<br/>格<br/>明<br/>细</th>
<th colspan="4" style="border-top:none;text-align:center"><apex:outputText value="配套产品信息" /></th>
<th colspan="2" style="border-top:none;text-align:center"><apex:outputText value="原配套产品信息" /></th>
</tr>
<tr>
<th style="text-align:center"><apex:outputText value="产品名称" /></th>
<th style="text-align:center"><apex:outputText value="客户产品名称" /></th>
<th style="text-align:center"><apex:outputText value="合同价格/更改价格(含税)" /></th>
<th style="text-align:center"><apex:outputText value="项目号" /></th>
<th style="text-align:center"><apex:outputText value="原产品名称" /></th>
<th style="text-align:center"><apex:outputText value="原价格(含税)" /></th>
</tr>
<apex:repeat value="{!contractItemList }" var="it">
<tr>
<td><apex:outputField value="{!it.Product__c}"/></td>
<td><apex:outputField value="{!it.ProductDescription__c}"/></td>
<td><apex:outputField value="{!it.UnitPrice__c}"/></td>
<td> </td>
<td> </td>
<td> </td>
</tr>
</apex:repeat>
<apex:repeat value="{!contractList}" var="ct">
<tr>
<td colspan="7">备注:<apex:outputField value="{!ct.Description}"/></td>
</tr>
</apex:repeat>
<tr>
<td colspan="3">申请人:<br/>日期</td>
<td colspan="2">市场营销部:<br/>日期</td>
<td colspan="2">财务经理:<br/>日期</td>
</tr>
</table>
<div>
<apex:outputText value="录入人:" />
</div>
</body>
</apex:page>
public class ExportAccountController{
public Account account{get; set;}
public List<ContractItem__c> contractItem{get; set;}
public List<Contract> contractList {get; set;}//这个是合同的List
public Map<Id, List<ContractItem__c>> contractItemMap {get; set;} //这个是合同和合同产品的Map Id是合同的Id
public List<ContractItem__c> contractItemList {get; set;}//这个是合同产品对象的List
public Map<Id, List<Product2>> productMap {get; set;} //这个是合同产品和产品的Map Id是合同产品的Id
public List<Product2> productList {get; set;}//这个是产品对象的List
public Integer Count{get; set;}
public ExportAccountController(){
Map<Id, List<ContractItem__c>> contractItemMap = new Map<Id, List<ContractItem__c>>();
//获取Account的Id
String accountId = ApexPages.currentPage().getParameters().get('id');
account=[select Id, Name,PaymentMethod__c,Account__c, AccountCode__c, Channel__c, CreditRating__c,Annual__c,Type,TaxNo__c ,Bank__c,
BillingCountry,BillingCity, BillingState,Phone
FROM Account
WHERE Id=:accountId];
List<ContractItem__c> contractItem= [SELECT Name,UnitPrice__c,Product__c
FROM ContractItem__c
WHERE Contract__r.AccountId=:accountId
AND Contract__r.EndDate<:date.today()];
//查询所有与该客户有关的合同
contractList = [Select Id, Name,EndDate,Status,Description From Contract Where AccountId =: accountId
AND EndDate>:date.today()
AND Status = 'Activated'];
//创建一个set
Set<Id> contractIdSet = new Set<Id>();
if (contractList != null && contractList.size() > 0){
//循环取出contractList 再添加到set里面
for (Contract cont: contractList){
contractIdSet.add(cont.Id);
}
}
//这个是查询所有合同下边的 合同产品对象
if (contractIdSet.size() > 0){
contractItemList = [Select Id, Name, Product__c,UnitPrice__c,Contract__c,
Comments__c,ProductDescription__c From ContractItem__c Where Contract__c In: contractIdSet
];
Count=2;
for(ContractItem__c ci: contractItemList ){
Count++;
}
}
Set<Id> productIdSet = new Set<Id>();
if (contractItemList != null && contractItemList.size() > 0){
for (ContractItem__c item: contractItemList){
//创建一个list
List<ContractItem__c> itemList = new List<ContractItem__c>();
//如果 合同和合同产品不为空
if(contractItemMap.get(item.Contract__c) != null && contractItemMap.get(item.Contract__c).size() > 0)
{
itemList = contractItemMap.get(item.Contract__c);
}
itemList.add(item);
contractItemMap.put(item.Contract__c, itemList);
productIdSet.add(item.Product__c);
}
}
//查询所有与合同产品相关的产品
if (productIdSet.size() > 0){
productList = [Select Id, Name From Product2 Where Id In: productIdSet];
}
}
}