我正在尝试在付款收据的高级 pdf 模板上显示发票行级别项目。是否可以?预先感谢!
是的,这是可以做到的。
beforeLoad 类型的用户事件脚本可以使用脚本上下文的类型字段来运行“打印”事件。
然后,您可以查找自定义数据并将其作为自定义字段和列表添加到您的记录中。
您的 PDF 模板可以检查这些字段和列表是否存在并适当地显示它们。
一些 Typescript 可帮助您入门。请注意,这与您要求的相反 - 它在打印的发票上列出了付款。
export function beforeLoad(ctx: EntryPoints.UserEvent.beforeLoadContext){
if(ctx.type == ctx.UserEventType.PRINT && ctx.newRecord && ctx.newRecord.id){
const payments = search.create(...).run().getRange({start:0, end:1000}).map...);
var paymentsList = form.addSublist({
id:'custpage_links',
type: ui.SublistType.STATICLIST,
label:'Applied'
});
paymentsList.addField({
id:'doc',
type:ui.FieldType.TEXT,
label:'Document'
})
paymentsList.addField({
id:'type',
type:ui.FieldType.TEXT,
label:'Type'
});
paymentsList.addField({
id:'total',
type:ui.FieldType.CURRENCY,
label:'total'
});
payments.forEach((pmnt, idx)=>{
paymentsList.setSublistValue({
id:'doc',
line:idx,
value:pmnt.doc
})
paymentsList.setSublistValue({
id:'type',
line:idx,
value:mapAppliedType(pmnt.type, pmnt.method)
});
paymentsList.setSublistValue({
id:'total',
line:idx,
value:''+ pmnt.total
});
});
然后在交易 pdf 模板方面:
<#assign appliedLines = []>
<#assign hasPayment = false>
<#if record.custpage_links?has_content>
<#list record.custpage_links as link>
<#if link.type?has_content && link.type != 'Total'>
<#if appliedLines?seq_contains(link.type)>
<#else>
<#assign hasPayment = true>
<#assign appliedLines = appliedLines + [link.type]>
<#assign typeApplied = 0>
<#list record.custpage_links as pymnt>
<#if pymnt.type == link.type>
<#assign typeApplied = typeApplied + pymnt.total>
</#if>
</#list>
<tr>
<td colspan="5" align="right"><b>${link.type}</b></td>
<td align="right"><i>(${typeApplied?string.currency})</i></td>
</tr>
</#if>
</#if>
</#list>
</#if>
<#if hasPayment == false>
<tr>
<td colspan="5" align="right"><b>${record.amountpaid@label}</b></td>
<td align="right">${record.amountpaid}</td>
</tr>
</#if>