This task involves customizing the standard customer statement template in NetSuite to calculate the difference in days between two dates for an advanced PDF template. The goal is to map a field description that categorizes the difference between the date and the due date into ranges like 1 to 30 days, 31 to 60 days, 61 to 90 days, etc. I’ve tried the following code in the advanced PDF template:
<#– Define the date format –>
<#assign date_format = “yyyy-MM-dd”/>
<#assign daysDifference = 0 />
${line.datecol}gg${line.duedate}
<#if (line.datecol?has_content && line.duedate?has_content)>
<#-- Convert the date strings to date objects -->
<#assign datecol = line.datecol?string(date_format)?date />
<#assign duedate = line.duedate?string(date_format)?date />
Converted Dates: ${datecol} and ${duedate}
<#-- Calculate the difference in milliseconds -->
<#assign diffInMilliseconds = duedate?long - datecol?long />
<#-- Calculate the difference in days -->
<#assign diffInDays = (diffInMilliseconds / (1000 * 60 * 60 * 24))?int />
<#-- Assign the difference to a variable -->
<#assign daysDifference = diffInDays?int />
<#else>
<#– Assign a default value if dates are not present –>
<#assign daysDifference = “N/A” />
</#if>
Difference in days: ${daysDifference}
However, the <#if (line.datecol?has_content && line.duedate?has_content)> condition doesn’t seem to work.
Deliverables
- Provide help in fixing the code and calculating the days.