使用“高级PDF /模板”编辑器从保存的搜索中生成自定义报告

时间:2019-06-11 21:57:30

标签: netsuite freemarker suitescript

我正在基于保存的搜索来构建可打印的报告,以对多个批次和库存明细进行分组和小计,并将其列出在每个项目下,并在每个项目组的下方显示小计。

我可以使用此代码正确设置代码的格式,使其一次显示1个项目

    <#if results?has_content>
<table class="itemtable" dir="ltr" style="width:100%;"><!-- start items --><#list results as result><tr>
    <td style="width: 43px;"><span style="font-size:10px;">**</span></td>
    <td colspan="2" rowspan="1" style="width: 70px;"><span style="font-size:10px;">${result.itemid}</span></td>
    <td colspan="2" rowspan="1" style="width: 94px; white-space: nowrap;"><span style="font-size:10px;">${result.displayname}</span></td>
    <td style="width: 133px;">&nbsp;</td>
    <td style="width: 72px;">&nbsp;</td>
    <td style="width: 47px;">&nbsp;</td>
    <td style="width: 120px;">&nbsp;</td>
    <td style="width: 79px;">&nbsp;</td>
    <td style="width: 68px;">&nbsp;</td>
    </tr>
    <tr>
    <td style="width: 43px;"><span style="font-size:10px;">${result.custitempacksize}</span></td>
    <td style="width: 70px;"><span style="font-size:10px;">${result.custcol_lottextitemlinelevel}</span></td>
    <td style="width: 48px;"><span style="font-size:10px;">${result.custitem_brand}</span></td>
    <td style="width: 94px;">${result.expirationdate}</td>
    <td style="width: 97px;"><span style="font-size:10px;">${result.serialnumbers}</span></td>
    <td style="width: 133px;"><span style="font-size:10px;">${result.location}</span></td>
    <td style="width: 72px;"><span style="font-size:10px;">${result.custbodyestimatedarrivaldate}</span></td>
    <td style="width: 47px;"><span style="font-size:10px;">${result.rate}</span></td>
    <td style="width: 120px;"><span style="font-size:10px;">${result.formulacurrency}</span></td>
    <td style="width: 79px;"><span style="font-size:10px;">${result.quantityavailable}</span></td>
    <td style="width: 68px;"><span style="font-size:10px;">${result.formulanumeric}</span></td>
    </tr>
    <tr>
    <td style="width: 43px;">**</td>
    <td colspan="3" rowspan="1" style="width: 70px;">Subtotal for :&nbsp;${result.itemid}</td>
    <td style="width: 97px;">&nbsp;</td>
    <td style="width: 133px;">&nbsp;</td>
    <td style="width: 72px;">&nbsp;</td>
    <td style="width: 47px;">&nbsp;</td>
    <td style="width: 120px;">&nbsp;
    <hr />{subtotalEC}</td>
    <td style="width: 79px;">&nbsp;
    <hr />{subtotalLB}</td>
    <td style="width: 68px;">&nbsp;
    <hr />{subtotalCS}</td>
    </tr>
    </#list><!-- end items --></table>
</#if>
</body>
</pdf>

我在获取想要的PDF结果中正处于正确的轨道,但是当我尝试添加<#if>和<#else>标签来对项目进行分组时,它将保存,但是当我出现时会产生意外错误尝试打印它。

<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">
            ${preferences.formlandscape}
<table class="header" style="width:100%;"><tr>
    <td colspan="3" style="text-align: left; vertical-align: top; white-space: nowrap; height: 40px; width: 178px;"><span style="font-size:12px;"><strong>Date:</strong></span></td>
    <td colspan="5" style="text-align: center; vertical-align: middle; white-space: nowrap; height: 40px; width: 400px;"><span style="font-size:12px;"><strong>Hofseth North America<br />In Stock Inventory Report sorted by Item<br />For All Items Available All Locations</strong></span></td>
    <td colspan="3" style="text-align: right; vertical-align: top; white-space: nowrap; height: 40px;"><span style="font-size:12px;"><strong>Page:<pagenumber/> of <totalpages/></strong></span></td>
    </tr></table>

<table boarder="1" class="header" style="width:100%;">
<thead>
    <tr>
    <th style="width: 40px;"><span style="font-size:12px;">Pack Size</span></th>
    <th style="width: 55px;"><span style="font-size:12px;">Load #</span></th>
    <th style="width: 75px;"><span style="font-size:12px;">Brand</span></th>
    <th style="width: 50px;"><span style="font-size:12px;">Exp. Date</span></th>
    <th style="width: 90px;"><span style="font-size:12px;">Lot #</span></th>
    <th style="width: 100px;"><span style="font-size:12px;">Location</span></th>
    <th style="width: 65px;"><span style="font-size:12px;">Arrival<br />Date</span></th>
    <th style="width: 69px;"><span style="font-size:12px;">Unit<br />Cost</span></th>
    <th style="width: 110px;"><span style="font-size:12px;">Extended<br />Cost</span></th>
    <th style="width: 70px;"><span style="font-size:12px;">Qty<br />Available</span></th>
    <th style="width: 64px;"><span style="font-size:12px;">Units<br />Available</span></th>
    </tr>
</thead>
</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;
        }
        th {
            font-weight: bold;
            font-size: 8pt;
            vertical-align: middle;
            padding: 5px 6px 3px;
            background-color: #e3e3e3;
            color: #333333;
        }
        td {
            padding: 4px 6px;
        }
        td p { align:left }
</style>
</head> 
    <body header="nlheader" header-height="15%" padding="0.2in 0.2in 0.2in 0.2in" size="Letter-LANDSCAPE">
    <#if results?has_content><#assign subtotalEC = 0 subtotalLB = 0 subtotalCS = 0>
<table class="itemtable" style="width:100%;"><!-- start items --><#list results as result><#list result.itemid as items>
    <tr>
    <td style="width: 43px;"><span style="font-size:10px;">**</span></td>
    <td colspan="2" rowspan="1" style="width: 70px;"><span style="font-size:10px;">${result.itemid}</span></td>
    <td colspan="2" rowspan="1" style="width: 94px; white-space: nowrap;"><span style="font-size:10px;">${result.displayname}</span></td>
    <td style="width: 133px;">&nbsp;</td>
    <td style="width: 72px;">&nbsp;</td>
    <td style="width: 47px;">&nbsp;</td>
    <td style="width: 120px;">&nbsp;</td>
    <td style="width: 79px;">&nbsp;</td>
    <td style="width: 68px;">&nbsp;</td>
    </tr>
<#elseif><tr>
    <td style="width: 43px;"><span style="font-size:10px;">${result.custitempacksize}</span></td>
    <td style="width: 70px;"><span style="font-size:10px;">${result.custcol_lottextitemlinelevel}</span></td>
    <td style="width: 48px;"><span style="font-size:10px;">${result.custitem_brand}</span></td>
    <td style="width: 94px;">${result.expirationdate}</td>
    <td style="width: 97px;"><span style="font-size:10px;">${result.serialnumbers}</span></td>
    <td style="width: 133px;"><span style="font-size:10px;">${result.location}</span></td>
    <td style="width: 72px;"><span style="font-size:10px;">${result.custbodyestimatedarrivaldate}</span></td>
    <td style="width: 47px;"><span style="font-size:10px;">${result.rate}</span></td>
    <td style="width: 120px;"><span style="font-size:10px;">${result.formulacurrency}</span></td>
    <td style="width: 79px;"><span style="font-size:10px;">${result.quantityavailable}</span></td>
    <td style="width: 68px;"><span style="font-size:10px;">${result.formulanumeric}</span></td>
    </tr>
    </#elseif></#list>
    <#else><tr>
    <td style="width: 43px;">**</td>
    <td colspan="3" rowspan="1" style="width: 70px;">Subtotal for :&nbsp;${result.itemid}</td>
    <td style="width: 97px;">&nbsp;</td>
    <td style="width: 133px;">&nbsp;</td>
    <td style="width: 72px;">&nbsp;</td>
    <td style="width: 47px;">&nbsp;</td>
    <td style="width: 120px;">&nbsp;
    <hr />{subtotalEC}</td>
    <td style="width: 79px;">&nbsp;
    <hr />{subtotalLB}</td>
    <td style="width: 68px;">&nbsp;
    <hr />{subtotalCS}</td>
    </tr>
    </#else></#list><!-- end items --></table>
</#if>
</body>
</pdf>

我无法使用freemarker标记来创建所需的列表。 我提供的代码保存没有错误 但是在尝试打印时会产生未知错误 或通过用户界面将其显示为PDF。

我希望发生以下情况。

拥有报告组并列出所有项目。 在每个项目下面,列出该项目搜索中包含的行级别详细信息。 将“分组信息”中每个项目下的3个字段小计,并将其显示在“分组信息”的最后一行下。 然后重复搜索中包含的所有项目

1 个答案:

答案 0 :(得分:0)

关于if-else结构,可能有些挑剔。 您正在关闭else-if和else的标签,在这种情况下可能不会那样。
这是来自freemarker网站的示例:

  

<#if x == 1>
    x是1
  <#elseif x == 2>
    x是2
  <#elseif x == 3>
    x是3
  <#elseif x == 4>
    x是4
  <#else>
    x既不是1也不是2也不是3也不是4
   

值得一试!