html NS:PDF生成器模板

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了html NS:PDF生成器模板相关的知识,希望对你有一定的参考价值。

/**
 * Copyright NetSuite, Inc. 2016 All rights reserved.
 * The following code is a demo prototype. Due to time constraints of a demo,
 * the code may contain bugs, may not accurately reflect user requirements
 * and may not be the best approach. Actual implementation should not reuse
 * this code without due verification.
 *
 * Populates charges in an invoice header custom field.
 *
 * Version    Date             Author           Remarks
 * 1.00       09 Mar 2016      Ryan Morrissey   Initial commit.
 * 1.01       06 Apr 2017      Ryan Morrissey   Added script parameter logic for
 *                                              invoice custom field name.
 *
 */

function populateChargesAfterSubmit(type) {
    try {
        var ctx     = nlapiGetContext(),
            invID   = nlapiGetRecordId(),
            invRec  = nlapiLoadRecord('invoice', invID),
            invFldD = 'custbody_ns_cc_charge_details',  // default custom field value in bundle
            invFld  = ctx.getSetting('SCRIPT', 'custscript_ns_cc_charge_details') || invFldD;

            chgArr  = [],
            cols    = [],
            flts    = [],
            results = null;

        cols.push(new nlobjSearchColumn('internalid'));
        flts.push(new nlobjSearchFilter('internalid', 'invoice', 'is', invID));
        results = nlapiSearchRecord('charge', null, flts, cols);

        if (!results || results.length < 1) {
            nlapiLogExecution('DEBUG', 'Invoice update', 'No charges found for invoice id ' + invID);
            return;
        }

        for (var _i = results.length - 1; _i >= 0; _i--) {
            chgArr.push(results[_i].getId());
        }

        nlapiLogExecution('DEBUG', 'Invoice update', 'Charges found: ' + JSON.stringify(chgArr));
        invRec.setFieldValues(invFld, chgArr);
        nlapiSubmitRecord(invRec);
    } catch(e) {
        nlapiLogExecution('DEBUG', 'Try/catch error', e.message);
    }
}
<#if .locale == "ru_RU"><link name="verdana" type="font" subtype="opentype" src="${nsfont.verdana}" src-bold="${nsfont.verdana_bold}" bytes="2" /></#if><macrolist><!-- Start header --><macro id="nlheader">
<table>
    <tbody>
        <tr>
            <td align="left"><#if companyInformation.logoUrl?length != 0><img height="30px" src="${companyInformation.logoUrl}" style="max-width:100%;" vertical-align="top" /> </#if></td>
        </tr>
        <tr height="8px">
            <td align="left"></td>
        </tr>
    </tbody>
</table>
</macro><!-- End header --><!-- Start footer --><macro id="nlfooter">

<table class="footer" style="width: 100%;">
    <tbody>
        <tr>
            <td align="right">Page <pagenumber/> of <totalpages/></td>
        </tr>
    </tbody>
</table>
</macro><!-- End footer --></macrolist>
<style type="text/css">body, table {
    <#if .locale == "zh_CN">
        font-family: stsong, sans-serif;
    <#elseif .locale == "zh_TW">
        font-family: msung, sans-serif;
    <#elseif .locale == "ja_JP">
        font-family: heiseimin, sans-serif;
    <#elseif .locale == "ko_KR">
        font-family: hygothic, sans-serif;
    <#elseif .locale == "ru_RU">
        font-family: verdana;
    <#else>
        font-family: sans-serif;
    </#if>
        font-size: 9pt;
        table-layout: fixed;
    }
    body {
        background-color: #ffffff;
    }
    th {
        font-weight: bold;
        font-size: 10pt;
        vertical-align: middle;
        padding: 5px 8px 3px;
        background-color: #00467F;
        color: #ffffff;
    }
    td {
        padding: 4px 6px;
    }
    b {
        font-weight: bold;
        color: #333333;
    }
    table.header td {
        padding: 0px;
        font-size: 10pt;
        /*border-bottom: 4px solid #666666;*/
    }
    table.footer td {
        padding: 0px;
        font-size: 8pt;
    }
    table.itemtable th {
        padding-bottom: 5px;
        padding-top: 5px;
    }
    table.itemtable-green th {
        background-color: #467f00;  /*green*/
    }
    table.itemtable-orange th {
        background-color: #7f3900;  /*orange*/
    }
    table.itemtable tr.oddRow td {
        background-color: #ececec;  /*light-gray*/
    }
    table.body td {
        padding-top: 2px;
    }
    table.total {
        page-break-inside: avoid;
    }
    tr.borderBottom td {
        border-bottom:1pt solid #ececec;
    }
    tr.totalrow {
        background-color: #ffffff;
        line-height: 200%;
        color: #2B547E;
    }
    td.totalboxtop {
        font-size: 12pt;
        background-color: #e3e3e3;
    }
    td.addressheader {
        font-size: 8pt;
        padding-top: 6px;
        padding-bottom: 2px;
    }
    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;
        color:#00467f;
    }
    span.itemname {
        font-weight: bold;
        line-height: 150%;
    }
    hr {
        width: 100%;
        color: #d3d3d3;
        background-color: #d3d3d3;
        height: 1px;
    }
</style>
<!-- Start invoice addresses -->
<table style="width: 100%; margin-top: 10px;">
    <tbody>
        <!-- Total columns per row is 12, so make sure colspan adds to 12 in each tr -->
        <!-- Only caveat is with rowspan, which carries the column count down a row -->
        <tr>
            <td class="addressheader" colspan="3"><b>${record.billaddress@label}</b></td>
            <td class="addressheader" colspan="3"><b>${record.shipaddress@label}</b></td>
            <td class="totalboxtop" colspan="3"><b>${record.total@label?upper_case}</b></td>
            <td align="right" class="totalboxtop" colspan="3"><b>${record.tranid@label}:</b> ${record.tranid}</td>
        </tr>
        <tr>
            <td class="address" colspan="3" rowspan="2">${record.billaddress}</td>
            <td class="address" colspan="3" rowspan="2">${record.shipaddress}</td>
            <td align="right" class="totalboxmid" colspan="6">${record.total}</td>
        </tr>
        <tr>
            <td align="right" class="totalboxbot" colspan="6"><b>${record.duedate@label}:</b> ${record.duedate}</td>
        </tr>
    </tbody>
</table>
<!-- End invoice addresses -->

<!-- Start invoice header fields -->
<table class="body" style="width: 100%; margin-top: 10px;">
    <tbody>
        <tr>
            <th>${record.job@label}</th>
            <th>${record.terms@label}</th>
            <th>${record.otherrefnum@label}</th>
            <th>${record.salesrep@label}</th>
        </tr>
        <tr>
            <td>${record.job}</td>
            <td>${record.terms}</td>
            <td>${record.otherrefnum}</td>
            <td>${record.salesrep}</td>
        </tr>
    </tbody>
</table>
<!-- End invoice header fields -->

<!-- Start invoice line items -->
<#if record.item?has_content>
<table class="itemtable" style="width: 100%; margin-top: 10px;">
    <tbody>
        <tr>
            <th colspan="5">Item</th>
            <th colspan="7">Description</th>
            <th align="right" colspan="4">Amount</th>
        </tr>

        <!-- Iterate through all invoice lines -->
        <!-- Group first by item display name -->
        <#list record.item?sort_by('item') as item>
        <tr>
            <td colspan="5">${item.item}</td>
            <td colspan="7">${item.description}</td>
            <td align="right" colspan="4">${item.amount}</td>
        </tr>
        </#list>
        <!-- End invoice lines -->
    </tbody>
</table>
<hr />
</#if>
<!-- End invoice line items -->

<!-- Start invoice total -->
<table align="left" border="0" class="itemtable" width="100%">
    <tbody>
        <!-- Total columns per row is 16, so make sure colspan adds to 16 in each tr -->
        <!-- Only caveat is with rowspan, which carries the column count down a row -->
        <tr>
            <td colspan="8"></td>
            <td colspan="4" style="align: right;"><b>${record.subtotal@label}</b></td>
            <td colspan="4" style="align: right;"><b>${record.subtotal}</b></td>
        </tr>
        <tr>
            <td colspan="8"></td>
            <td colspan="4" style="align: right;"><b>Discount</b></td>
            <td colspan="4" style="align: right;"><b>${record.discounttotal}</b></td>
        </tr>
        <tr>
            <td colspan="8"></td>
            <td colspan="4" style="align: right;"><b>Tax Amount (${record.taxrate}%)</b></td>
            <td colspan="4" style="align: right;"><b>${record.taxtotal}</b></td>
        </tr>
    </tbody>
</table>

<table align="left" border="0" class="itemtable" width="100%">
    <tbody>
        <!-- Total columns per row is 16, so make sure colspan adds to 16 in each tr -->
        <!-- Only caveat is with rowspan, which carries the column count down a row -->
        <tr class="totalrow">
            <th colspan="8"></th>
            <th colspan="4" style="align: right;">${record.total@label}</th>
            <th colspan="4" style="align: right;">${record.total}</th>
        </tr>
    </tbody>
</table>
<!-- End invoice total -->

<!-- Start charge detail section -->
<#if record.custbody_charge_details?has_content>
    <!-- Force page break for charge details -->
    <pbr />

    <!-- Start charge header -->
    <table align="left" border="0" width="100%" style="margin-top: 10px; margin-bottom: 10px;">
        <tbody>
            <tr class="borderBottom">
                <td style="align: center; font-size: 18pt;">Billable Charges - Detailed Backup</td>
            </tr>
        </tbody>
    </table>
    <!-- End charge header -->

    <!-- Variables for charge types -->
    <%var hasTime=false%>
    <%var hasExpense=false%>
    <%var hasOther=false%>

    <!-- Create array of charge types -->
    <%var uniqLine=_.uniqBy(line, 'customsort')%>
    <!-- customsort 1=time-based, 2=expense-based, 3=other -->
    <%_.each(uniqLine,function(un){%>

        <!-- Determine if time charges -->
        <%if(un.customsort == 1){%>
            <%hasTime=true%>
        <%}%>

        <!-- Determine if expense charges -->
        <%if(un.customsort == 2){%>
            <%hasExpense=true%>
        <%}%>

        <!-- Determine if other charges -->
        <%if(un.customsort == 3){%>
            <%hasOther=true%>
        <%}%>

    <%})%>
    <!-- End check for time charges -->

    <!-- LABOR ITEMS -->
    <%if(hasTime){%>

        <!-- Charge subtotal variables -->
        <#assign timeSubtotal=0>
        <#assign hoursSubtotal=0>

        <!-- End charge subtotal variables -->
        <table class="itemtable" style="width: 100%; margin-top: 10px; margin-bottom: 20px;">
            <tbody>
                <!-- Total columns per row is 28, so make sure colspan adds to 28 in each tr -->
                <tr>
                    <th align="center" colspan="28">Billable Time</th>
                </tr>
                <tr>
                    <th colspan="2">Date</th>
                    <th colspan="4">Employee</th>
                    <th colspan="8">Service Item</th>
                    <th align="center" colspan="2">Units</th>
                    <th align="center" colspan="2">Qty</th>
                    <th align="center" colspan="3">Currency</th>
                    <th align="right" colspan="3">Rate</th>
                    <th align="right" colspan="4">Amount</th>
                </tr>

                <!-- Start charge details -->
                <!-- These match the saved search custom labels -->
                <%_.each(line,function(ln){%>
                    <%if(ln.customsort == 1){%>
                        <tr class="<%-ln.specialchargetypetext%> borderBottom">
                            <td class="brdL" colspan="2"><%-ln.chargedate%></td>
                            <td class="brdL" colspan="4"><%-ln.chargeemployee%></td>
                            <td class="brdL" colspan="8"><span class="itemname"><%-ln.chargeitem%></span><br /><%-ln.chargedescription%></td>
                            <td align="center" class="brdL" colspan="2"><%-ln.chargeunits%></td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeQty = <%-ln.chargequantity%>>
                            <td align="center" class="brdL" colspan="2">${custChargeQty?string[",##0.00"]}</td>

                            <td align="center" class="brdL" colspan="3"><%-ln.chargecurrency%></td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeRate = <%-ln.chargerate%>>
                            <td align="right" class="brdL" colspan="3">${custChargeRate?string[",##0.00"]}</td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeAmt = <%-ln.chargeamount%>>
                            <td align="right" class="brdL" colspan="4">${custChargeAmt?string[",##0.00"]}</td>
                        </tr>

                        <!-- Start time subtotal -->
                        <#assign timeSubtotal = timeSubtotal + <%-ln.chargeamount%>>
                        <#assign hoursSubtotal = hoursSubtotal + <%-ln.chargequantity%>>
                        <!-- End time subtotal -->
                    <%}%>
                <%})%>
                <!-- End charge details -->
                <tr>
                    <th colspan="16">Subtotal</th>
                    <th colspan="2" align="center">${hoursSubtotal?string[",##0.00"]}</th>
                    <th colspan="10" align="right">${timeSubtotal?string[",##0.00"]}</th>
                </tr>
            </tbody>
        </table>
    <%}%>
    <!-- END LABOR ITEMS -->

    <!-- EXPENSE ITEMS -->
    <%if(hasExpense){%>
        <#assign expenseSubtotal=0>
        <table class="itemtable itemtable-green" style="width: 100%; margin-top: 10px; margin-bottom: 20px;">
            <tbody>
                <!-- Total columns per row is 28, so make sure colspan adds to 28 in each tr -->
                <tr>
                    <th align="center" colspan="28">Billable Expenses</th>
                </tr>
                <tr>
                    <th colspan="2">Date</th>
                    <th colspan="4">Employee</th>
                    <th colspan="10">Expense Item</th>
                    <th align="center" colspan="2">Qty</th>
                    <th align="center" colspan="3">Currency</th>
                    <th align="right" colspan="3">Rate</th>
                    <th align="right" colspan="4">Amount</th>
                </tr>

                <!-- Start charge details -->
                <!-- These match the saved search custom labels -->
                <%_.each(line,function(ln){%>
                    <%if(ln.customsort == 2){%>
                        <tr class="<%-ln.specialchargetypetext%> borderBottom">
                            <td class="brdL" colspan="2"><%-ln.chargedate%></td>
                            <td class="brdL" colspan="4"><%-ln.chargeemployee%></td>
                            <td class="brdL" colspan="10"><span class="itemname"><%-ln.chargeitem%></span><br /><%-ln.chargedescription%></td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeQty = <%-ln.chargequantity%>>
                            <td align="center" class="brdL" colspan="2">${custChargeQty?string[",##0.00"]}</td>

                            <td align="center" class="brdL" colspan="3"><%-ln.chargecurrency%></td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeRate = <%-ln.chargerate%>>
                            <td align="right" class="brdL" colspan="3">${custChargeRate?string[",##0.00"]}</td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeAmt = <%-ln.chargeamount%>>
                            <td align="right" class="brdL" colspan="4">${custChargeAmt?string[",##0.00"]}</td>
                        </tr>

                        <!-- Start expense subtotal -->
                        <#assign expenseSubtotal = expenseSubtotal + <%-ln.chargeamount%>>
                        <!-- End expense subtotal -->
                    <%}%>
                <%})%>
                <!-- End charge details -->
                <tr>
                    <th colspan="24">Subtotal</th>
                    <th colspan="4" align="right">${expenseSubtotal?string[",##0.00"]}</th>
                </tr>
            </tbody>
        </table>
    <%}%>
    <!-- END EXPENSE ITEMS -->

    <!-- OTHER ITEMS -->
    <%if(hasOther){%>
        <#assign otherSubtotal=0>
        <table class="itemtable itemtable-orange" style="width: 100%; margin-top: 10px; margin-bottom: 20px;">
            <tbody>
                <!-- Total columns per row is 28, so make sure colspan adds to 28 in each tr -->
                <tr>
                    <th align="center" colspan="28">Billable Fixed Fee</th>
                </tr>
                <tr>
                    <th colspan="2">Date</th>
                    <th colspan="4">Type</th>
                    <th colspan="15">Service Item</th>
                    <th align="center" colspan="3">Currency</th>
                    <th align="right" colspan="4">Amount</th>
                </tr>

                <!-- Start charge details -->
                <!-- These match the saved search custom labels -->
                <%_.each(line,function(ln){%>
                    <%if(ln.customsort == 3){%>
                        <tr class="<%-ln.specialchargetypetext%> borderBottom">
                            <td class="brdL" colspan="2"><%-ln.chargedate%></td>
                            <td class="brdL" colspan="4"><%-ln.chargetype%></td>
                            <td class="brdL" colspan="15"><span class="itemname"><%-ln.chargeitem%></span><br /><%-ln.chargedescription%></td>
                            <td align="center" class="brdL" colspan="3"><%-ln.chargecurrency%></td>

                            <!-- Apply 2 decimal number format -->
                            <#assign custChargeAmt = <%-ln.chargeamount%>>
                            <td align="right" class="brdL" colspan="4">${custChargeAmt?string[",##0.00"]}</td>
                        </tr>

                        <!-- Start other subtotal -->
                        <#assign otherSubtotal = otherSubtotal + <%-ln.chargeamount%>>
                        <!-- End other subtotal -->
                    <%}%>
                <%})%>
                <!-- End charge details -->
                <tr>
                    <th colspan="24">Subtotal</th>
                    <th colspan="4" align="right">${otherSubtotal?string[",##0.00"]}</th>
                </tr>
            </tbody>
        </table>
    <%}%>
    <!-- END OTHER ITEMS -->
</#if>
<!-- End charge detail section -->

以上是关于html NS:PDF生成器模板的主要内容,如果未能解决你的问题,请参考以下文章

使用 PDFSharp 从 HTML 模板生成 PDF 并发送到浏览器

有没有办法从 iOs 中的 XML/HTML 模板生成 PDF 文件

django 生成动态的PDF文件

iTextSharp生成pdf含模板---制作pdf模板

html模板到带有图像的pdf

使用wkhtmltopdf工具生成pdf