Advanced PDF Statement – How to show Amount Remaining on each invoice Invoice line ?
I’m working on a pdf statement and came across some code on stack overflow that fits exactly what I’m trying to accomplish. When I try to print a statement with this code inserted, it errors out. Any ideas on what can be done to get rid of the error?
==== From Stack
- Each line will display a charge, if it is an invoice
- Will show the amount paid, if it is an invoice with payments applied
- If it is a payment/deposit/credit, the payment column will show the total paid on that payment.
- The balance column will display an amount if, it as unpaid or partially paid invoice and the running column, will display the running total of the statement
===== Code
<table>
<#list statement.lines as line>
<#if line_index==0>
<thead>
<tr>
<th>Date</th>
<th>Description</th>
<th>References #</th>
<th>Charge</th>
<th>Payment</th>
<th>Balance Due</th>
<th>Running</th>
</tr>
</thead>
</#if>
<tr>
<#function toNumber val><#if val?has_content && val?length gt 0 ><#return val?html?replace('[^0-9.]','','r')?number ><#else><#return 0 ></#if></#function>
<#assign amountpaid=(line.charge?int-line.amountremaining?int)>
<td>${line.datecol}</td>
<td>${line.description}</td>
<td>${line.otherrefnum} - ${line.custbodyjobnum}</td>
<td>${line.charge}</td>
<td><#if amountpaid gt 0>${amountpaid?string.currency}<#else>${line.payment}</#if></td>
<td>${line.amountremaining}</td>
<td>${line.balance}</td>
</tr>
</#list>
</table>




OlivierGagnon
What is the errror?
Do you have Charge Based Billing enabled?
Does your PDF have the rest of the necessary code to render? This is just an in-body snippet, you still have the rest of the needed tags right?
dYubet
dYubet
Sidenote: one change I did make to the code snippet above, before trying to print a statement, was change:
<#list statement.lines as line> to <#list record.lines as line>