Hi Everyone, My code is in the comments for an inv...
# suitescript
k
Hi Everyone, My code is in the comments for an invoice for the advance HTML/PDF form. currently its showing in the columns Items, Descriptions, and then the sizes from S - XXXL. under that for example would be AM1011-913, and then its description, and then depending on what the size is there will be a number under the size so L would have a 1 as a qty. this is what I want but there's a problem. Under this item is AM1011-913 (same item number but different size) and this is a M so there is a 1 under M. But there's 2 rows of this same item but different size. I just want this item to show once and all of it's sizing should be under the size. so for example there's just 1 row of AM1011-913 and under M is 1 and under L is 1. Not 2 rows of the same item. Can this be done?
Copy code
<?xml version="1.0"?><!DOCTYPE pdf PUBLIC "-//big.faceless.org//report" "report-1.1.dtd">
<pdf>
<head>
	<link name="NotoSans" type="font" subtype="truetype" src="${nsfont.NotoSans_Regular}" src-bold="${nsfont.NotoSans_Bold}" src-italic="${nsfont.NotoSans_Italic}" src-bolditalic="${nsfont.NotoSans_BoldItalic}" bytes="2" />
	<#if .locale == "zh_CN">
		<link name="NotoSansCJKsc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKsc_Regular}" src-bold="${nsfont.NotoSansCJKsc_Bold}" bytes="2" />
	<#elseif .locale == "zh_TW">
		<link name="NotoSansCJKtc" type="font" subtype="opentype" src="${nsfont.NotoSansCJKtc_Regular}" src-bold="${nsfont.NotoSansCJKtc_Bold}" bytes="2" />
	<#elseif .locale == "ja_JP">
		<link name="NotoSansCJKjp" type="font" subtype="opentype" src="${nsfont.NotoSansCJKjp_Regular}" src-bold="${nsfont.NotoSansCJKjp_Bold}" bytes="2" />
	<#elseif .locale == "ko_KR">
		<link name="NotoSansCJKkr" type="font" subtype="opentype" src="${nsfont.NotoSansCJKkr_Regular}" src-bold="${nsfont.NotoSansCJKkr_Bold}" bytes="2" />
	<#elseif .locale == "th_TH">
		<link name="NotoSansThai" type="font" subtype="opentype" src="${nsfont.NotoSansThai_Regular}" src-bold="${nsfont.NotoSansThai_Bold}" bytes="2" />
	</#if>
    <macrolist>
        <macro id="nlheader">
            <table class="header" style="width: 100%; line-height: 110%;"><tr>
<td rowspan="3"><span class="nameandaddress"><strong></strong></span>
<p><br /><br /><br /></p>
</td>
<td align="right"><#if companyInformation.logoUrl?length != 0><@filecabinet nstype="image" style="height: 60px; width: 180px; float: left; margin: 0px;" src="<https://8547352.app.netsuite.com/core/media/media.nl?id=3246&c=8547352&h=DFUwfenygPO4GkDNsQ1bgx_maKbMWM7l-V4-R4Iss8h7uvKH>" /> </#if></td>
</tr>
<tr>
<td align="right">&nbsp;</td>
</tr>
<tr>
<td align="right">&nbsp;</td>
</tr></table>
        </macro>
        <macro id="nlfooter">
            <table class="footer" style="width: 100%;"><tr>
<td align="right"><pagenumber/> of <totalpages/></td>
</tr></table>
        </macro>
    </macrolist>
    <style type="text/css">* {
		<#if .locale == "zh_CN">
			font-family: NotoSans, NotoSansCJKsc, sans-serif;
		<#elseif .locale == "zh_TW">
			font-family: NotoSans, NotoSansCJKtc, sans-serif;
		<#elseif .locale == "ja_JP">
			font-family: NotoSans, NotoSansCJKjp, sans-serif;
		<#elseif .locale == "ko_KR">
			font-family: NotoSans, NotoSansCJKkr, sans-serif;
		<#elseif .locale == "th_TH">
			font-family: NotoSans, NotoSansThai, sans-serif;
		<#else>
			font-family: NotoSans, sans-serif;
		</#if>
		}
		table {
			font-size: 9pt;
			table-layout: fixed;
		}
        th {
            font-size: 8pt;
            vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #dbe8f0;
            color: #4eb1e6;
        }
        td {
            padding: 4px 6px;
        }
		td p { align:left }
        b {
            font-weight: bold;
            color: #333333;
        }
        table.header td {
            padding: 0px;
            font-size: 10pt;
        }
        table.footer td {
            padding: 0px;
            font-size: 8pt;
        }
        table.itemtable th {
            padding-bottom: 10px;
            padding-top: 10px;
        }
        table.body td {
            padding-top: 2px;
        }
        table.total {
            page-break-inside: avoid;
        }
        tr.totalrow {
            background-color: #dbe8f0;
            line-height: 200%;
            color: #abb1c0;
        }
        td.totalboxtop {
            font-size: 12pt;
            background-color: #e3e3e3;
        }
        td.addressheader {
            font-size: 8pt;
            padding-top: 6px;
            padding-bottom: 0px;
            color: Gray;
        }
        td.address {
            padding-top: 0px;
        }
        td.totalboxmid {
            font-size: 28pt;
            padding-top: 20px;
            background-color: #e3e3e3;
        }
        td.totalboxbot {
            background-color: #e3e3e3;
            font-weight: bold;
        }
        span.title {
            font-size: 28pt;
        }
        span.number {
            font-size: 16pt;
        }
        span.itemname {
            font-weight: bold;
            line-height: 150%;
        }
        hr {
            width: 100%;
            color: #d3d3d3;
            background-color: #d3d3d3;
            height: 1px;
        }
</style>
</head>
<body header="nlheader" header-height="10%" footer="nlfooter" footer-height="20pt" padding="0.5in 0.5in 0.5in 0.5in" size="Letter-LANDSCAPE">
    <table style="width: 100%; margin-top: 10px;"><tr>
<td colspan="6">INVOICE</td>
</tr>
<tr>
<td class="addressheader" colspan="3">BILL TO</td>
<td class="addressheader" colspan="3">SHIP TO</td>
<td class="addressheader" colspan="3">PO&nbsp;#</td>
<td colspan="4" rowspan="2">
<table><tr>
<td class="addressheader">INVOICE</td>
<td>${record.tranid}</td>
</tr>
<tr>
<td class="addressheader">DATE</td>
<td>${record.trandate}</td>
</tr>
<tr>
<td class="addressheader">TERMS</td>
<td>${record.terms}</td>
</tr>
<tr>
<td class="addressheader">DUE DATE</td>
<td>${record.duedate}</td>
</tr></table>
</td>
</tr>
<tr><#if record.billaddressee == record.billattention>
<td class="address" colspan="3">${record.billaddress?remove_beginning(record.billattention)?remove_beginning('<br />')}</td>
<#else>
<td class="address" colspan="3">${record.billaddress}</td>
</#if><#if record.shipaddressee == record.shipattention>
<td class="address" colspan="3">${record.shipaddress?remove_beginning(record.shipattention)?remove_beginning('<br />')}</td>
<#else>
<td class="address" colspan="3">${record.shipaddress}</td>
</#if>
<td class="address" colspan="3">${record.otherrefnum}</td>
</tr>
<tr>
<td class="address" colspan="3">MEMO</td>
<td class="address" colspan="3">${record.memo}</td>
</tr>
<tr>
<td class="addressheader" colspan="6">SALES REP</td>
</tr>
<tr>
<td class="address" colspan="6">${record.salesrep}</td>
</tr></table>
<#if record.item?has_content>
<table class="itemtable" style="width: 100%; margin-top: 10px;">
<thead>
<tr>
<th colspan="4">ITEM</th>
<th colspan="9">DESCRIPTION</th>
<th colspan="1" align="right">S</th>
<th colspan="1" align="right">M</th>
<th colspan="1" align="right">L</th>
<th colspan="1" align="right">XL</th>
<th colspan="1" align="right">XXL</th>
<th colspan="1" align="right">XXXL</th>
<th colspan="3" align="right">QTY</th>
<th colspan="4" align="right">RATE</th>
<th colspan="4" align="right">AMOUNT</th>
</tr>
</thead><#assign embroideryTotalQty = 0>
<#assign embroideryTotalAmount = 0>
<#assign embroideryRate = 0>
<#list record.item?sort_by('custcol_sku') as item>
    <#if item.description?contains("Embroidery")>
        <#assign embroideryTotalQty += item.quantity>
        <#assign embroideryTotalAmount += item.amount>
        <#if embroideryRate == 0>
            <#assign embroideryRate = item.rate>
        </#if>
    <#else>
       <tr>
    <!-- Removing the size suffix from custcol_sku -->
    <td colspan="4" align="left">${item.custcol_sku?keep_before_last("-")}</td>
    
    <td colspan="9">${item.description}</td>
    
    <!-- Display quantity for size S -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-S")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display quantity for size M -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-M")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display quantity for size L -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-L")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display quantity for size XL -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-XL")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display quantity for size XXL -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-XXL")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display quantity for size XXXL -->
    <td colspan="1" align="right">
        <#if item.custcol_sku?ends_with("-XXXL")>
            ${item.quantity}
        <#else>
            0
        </#if>
    </td>
    
    <!-- Display the total quantity -->
    <td colspan="3" align="right">${item.quantity}</td>
    
    <!-- Display the rate -->
    <td colspan="4" align="right">${item.rate}</td>
    
    <!-- Display the amount -->
    <td colspan="4" align="right">${item.amount}</td>
</tr>
</#if>

</#list>


<!-- Add the aggregated Embroidery item row at the bottom -->
<tr>
<td colspan="4" align="left">Embroidery</td>
<td colspan="9">All Embroidery Items</td>
<td colspan="3" align="right"></td>
<td colspan="3" align="right">${embroideryTotalQty}</td>
<td colspan="4" align="right">${embroideryRate}</td>
<td colspan="4" align="right">$${embroideryTotalAmount}</td>
</tr></table>
</#if>



<table class="total" style="width: 100%; padding-top: 10px; border-top: 1pt dotted #abb1c0;"><tr>
<td class="addressheader" colspan="2" rowspan="6"><strong><span style="color: #3498db;">Please remit payment to:<br /><br /><br />La Quinta, CA 92253</span></strong><br /><br />If you have questions regarding this invoice,<br />please email: <u><span style="color: #2980b9;"</span></u></td>
<td class="addressheader">SUBTOTAL</td>
<td align="right">${record.subtotal}</td>
</tr>
<tr>
<td class="addressheader">SHIPPING</td>
<td align="right">${record.shippingcost}</td>
</tr>
<tr>
<td class="addressheader">TAX TOTAL</td>
<td align="right">${record.taxtotal}</td>
</tr>
<tr>
<td class="addressheader">TOTAL</td>
<td align="right">${record.total}</td>
</tr>
<tr>
<td class="addressheader">TOTAL QTY</td>
<td align="right">${record.custbody_total_qty_minus_embroidery}</td>
</tr>
<tr>
<td class="addressheader">BALANCE DUE</td>
<td align="right">${record.amountremaining}</td>
</tr></table>
</body>
</pdf>
c
You would need to create a function in your template that summarizes your item data then loop over that data when creating the items table.
k
Thank you for your response. Is it possible to provide an example?
t
You can always prompt Chat GPT with creece's response. It might get you more in the correct arena
c
Similar to the below example except you will get getting the t-shirt sizes instead of total quantity. If you aren't familiar w/ freemarker functions you can look at the doc here: https://freemarker.apache.org/docs/ref_directive_function.html You can add the functions after the <macrolist></macrolist> in the head tags. In your body, you loop over the returned data.
Copy code
<#function getSummarizedItems items>

    <#assign processedItemIds = []>

    <#assign summarizedItems = []>

    <#list items as item>

        <#assign itemId = item.item.internalid>
        <#assign itemType = item.itemtype>

        <#if itemType != "Description" && itemType != "Subtotal">

            <#if processedItemIds?seq_index_of(itemId) == -1>

                <#assign processedItemIds = processedItemIds + [item.item.internalid]>
                <#assign summarizedItems = summarizedItems + [getSummarizedItem(item.item.internalid, items)]>
            </#if>
        </#if>
    </#list>

    <#return summarizedItems>
</#function>

<#function getSummarizedItem itemId items>

    <#assign description   = "">
    <#assign itemName      = "">
    <#assign rate          = 0>

    <#list items as item>

        <#if item.item.internalid == itemId>

            <#assign description = item.description>
            <#assign itemName = item.item>
            <#assign rate = item.rate>

            <#assign totalQuantity = totalQuantity + item.quantity>
        </#if>
    </#list>

    <#assign total = rate * totalQuantity>

    <#assign summarizedItem = {"description": description, "itemName": itemName, "rate": rate, "total": total?string.currency, "totalQuantity": totalQuantity}>

    <#return summarizedItem>
</#function>



<#if record.item?has_content>

    <#assign summarizedItems = getSummarizedItems(record.item)>

    <table style="width: 100%; margin-top: 10px;">

        <#list record.item as item>
            <#if item_index==0>
                <thead>
                    <tr>
                    <th align="center" colspan="3" style="padding: 10px 6px;">${item.quantity@label}</th>
                    <th colspan="12" style="padding: 10px 6px;">${item.item@label}</th>
                    <th align="right" colspan="4" style="padding: 10px 6px;">${item.rate@label}</th>
                    <th align="right" colspan="4" style="padding: 10px 6px;">${item.amount@label}</th>
                    </tr>
                </thead>
            </#if>
        </#list>

        <#if summarizedItems?has_content>
            <#list summarizedItems as summarizedItem>
                <tr>
                    <td align="center" colspan="3" line-height="150%">${summarizedItem.totalQuantity}</td>
                    <td colspan="12"><span style="font-weight: bold; line-height: 150%; color: #333333;">${summarizedItem.itemName}</span><br />${summarizedItem.description}</td>
                    <td align="right" colspan="4">${summarizedItem.rate}</td>
                    <td align="right" colspan="4">${summarizedItem.total}</td>
                </tr>
            </#list>
        </#if>
    </table>
    <hr style="width: 100%; color: #d3d3d3; background-color: #d3d3d3; height: 1px;" />
</#if>
❤️ 1
It's fairly rare I've ever been tasked with summarizing things like this on a PDF but it does happen so once you get it working, I highly recommend saving it off somewhere as a snippet to go back to when you get asked again as its not exactly super intuitive if you aren't familiar with freemarker syntax.
That snippet is worth at least a few hundred dollars of time 😄 💰
😄 1