Search code examples
pdfif-statementfreemarkernetsuite

Netsuite Customer Statement (PDF/HTML)


I had a need to display the amount.paid on invoices (line items) on the customer statement.

Below is the solution I came up with, after i was suggested to include the toNumber function


Solution

  • Looking at that information, I was able to come up with a statement table that gives me what I wanted.

    • 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
    • (see below for 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}&nbsp;-&nbsp;${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>