Jira Code: FHI-13
Added proforma Invoice button for the Fully Europe subsidiary. The button will render the corresponding advanced PDF template and get the value from Quote record.
User Event
/**
* Copyright (c) 1998-2018 NetSuite, Inc.
* 2955 Campus Drive, Suite 100, San Mateo, CA, USA 94403-2511
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* NetSuite, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with NetSuite.
*/
/**
* @NApiVersion 2.x
* @NScriptType userEventScript
*
* Version Date Author Remarks
* 1.00 11/20/2018 Samiha Chowdhury Initial Commit
* Version Date Author Remarks
* 1.00 04/18/2019 Jobin and Jismi IT services proforma invoice for Fully europe
*/
define(['N/runtime'],
function(runtime) {
function beforeLoad(context) {
var logTitle = 'beforeLoad';
var form = context.form;
var quoteRec = context.newRecord;
var subsidiary = quoteRec.getValue({fieldId: 'subsidiary'});
log.debug('Checking', 'Subsidiary = '+ subsidiary);
if (subsidiary != null && subsidiary != 1 && subsidiary != 3) //1= North America 3=Fully Europe
return;
if (context.type === context.UserEventType.VIEW) { // Only show button on view
try {
var script = runtime.getCurrentScript();
var clientFile = script.getParameter('custscript_acs_client_file_id');
var buttonLabel = script.getParameter('custscript_acs_button_label');
var customerName = quoteRec.getValue({
fieldId: 'entity'
});
if (customerName !== null) { // Only show button for programmatic invoice
form.clientScriptFileId = clientFile;
form.addButton({
label: buttonLabel,
id: 'custpage_print_pdf_button',
functionName: 'generatePDF();'
});
}
} catch (error) {
log.error(logTitle, error.message);
}
}
}
function isEmpty(value) {
var logTitle = 'isEmpty';
try {
if (value == null || value == '' || (!value) || value == 'undefined') {
return true;
}
return false;
} catch (error) {
log.error(logTitle, error);
}
}
return {
beforeLoad: beforeLoad
}
});
Suitelet
/**
* Copyright (c) 1998-2018 NetSuite, Inc.
* 2955 Campus Drive, Suite 100, San Mateo, CA, USA 94403-2511
* All Rights Reserved.
*
* This software is the confidential and proprietary information of
* NetSuite, Inc. ("Confidential Information"). You shall not
* disclose such Confidential Information and shall use it only in
* accordance with the terms of the license agreement you entered into
* with NetSuite.
*/
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
* @NModuleScope Public
*
* Version Date Author Remarks
* 1.00 11/20/2018 Samiha Chowdhury Initial Commit
* Version Date Author Remarks
* 1.00 04/18/2019 Jobin and Jismi IT services proforma invoice for Fully europe
*
*/
define(['N/record', 'N/render', 'N/runtime'],
function(record, render, runtime) {
function onRequest(context) {
var logTitle = 'onRequest';
//just display pdf
var request = context.request;
var response = context.response;
//if (context.request.method === 'GET') {
// var form = serverWidget.createForm({
// title: 'Proforma Invoice',
try {
var scriptObj = runtime.getCurrentScript();
var quoteId = request.parameters.quoteId;
var rec = record.load({
type: record.Type.ESTIMATE,
id: quoteId
});
var subsidiaryId = rec.getValue('subsidiary');
if(subsidiaryId == 1){
var pdfTemplate = scriptObj.getParameter({ //set this on script parameter
name: 'custscript_pdf_template'
});
}
else if(subsidiaryId == 3){
var pdfTemplate = scriptObj.getParameter({ //set this on script parameter
name: 'custscript_jj_pdf_template_fully_europe'
});
}
log.debug('pdfTemplate',pdfTemplate)
var renderer = render.create();
renderer.setTemplateById(pdfTemplate); //pass 'template id' to use as base to display data
renderer.addRecord({ //pass a record ex: trans,entity,
templateName: 'record',
record: rec
})
log.debug('renderer',renderer)
if (subsidiaryId != null && subsidiaryId != '')
{
var subsidiary = record.load({
type: record.Type.SUBSIDIARY,
id: subsidiaryId
});
renderer.addRecord({ //pass a record ex: trans,entity,
templateName: 'subsidiary',
record: subsidiary
})
}
//***Change added by Ric
var rendererContent = renderer.renderAsString();
renderer.templateContent = rendererContent;
//***End change
var quotePdf = renderer.renderAsPdf(); //this parameter converts it
quotePdf.name = 'Quote #' + quoteId + '.pdf';
context.response.writeFile({
file: quotePdf, //whatever parameter you use obj etc
isInline: true
});
} catch (error) {
log.error(logTitle, error.message);
}
//}
}
return {
onRequest: onRequest
};
});
Advanced PDF Template
<?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%;">
<tr>
<td rowspan="3" class="addressheader"><#if companyInformation.logoUrl?length != 0><img src="https://system.netsuite.com/core/media/media.nl?id=12&c=4141760_SB1&h=dbf6d3d539f8ff6fb1c7" style="margin: 0px;" />
</#if>
<#if record.custbody_jj_taxcode_vatnumber?has_content>${subsidiary.mainaddress_text?keep_before("BTW")}<br />
${record.custbody_jj_taxcode_vatnumber?keep_before("|")}: ${record.custbody_jj_taxcode_vatnumber?keep_after("|")}
<#else>
${subsidiary.mainaddress_text}<br />
Frans BTW nummer/French VAT number: FR 56 842791725<br />
BTW nummer voor Groot Brittanië /VAT number for Great Britain: GB 305 8329 09<br />
</#if>
</td>
<td align="right">
<table style="width: 90%;">
<tbody>
<tr>
<td width="80%" align="left"><span class="title">Proforma Invoice</span></td>
<td width="30%"><span class="subheader"></span></td>
</tr>
<tr>
<td width="80%"><br/><span class="subheader">Page <pagenumber/> of <totalpages/></span></td>
<td width="30%"><span class="subheader"></span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Datum / Date</span></td>
<td width="30%"><span class="subheader">${record.trandate}</span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Factuur / Invoice</span></td>
<td width="30%"><span class="subheader">${record.tranid}</span></td>
</tr>
</tbody>
</table>
<table style="width: 90%;">
<tbody>
<tr>
<td width="80%"><br/><span class="subheaderlabel">Betalingstermijn / Due Date</span></td>
<td width="30%"><br/><span class="subheader">${record.duedate}</span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Contactpersoon / Sales Rep</span></td>
<td width="30%"><span class="subheader">${record.salesrep}</span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Verzindingmethode / Shipping Method</span></td>
<td width="30%"><span class="subheader">${record.shipmethod}</span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Verzenddatum / Ship Date</span></td>
<td width="30%"><span class="subheader">${record.shipdate}</span></td>
</tr>
<tr>
<td width="80%"><span class="subheaderlabel">Beschrijving / Description</span></td>
<td width="30%"><span class="subheader">${record.otherrefnum}</span></td>
</tr>
</tbody>
</table>
</td>
</tr>
</table>
</macro>
<macro id="nlfooter">
<table style="width: 100%">
<tr>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Signature</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Name</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Title</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Date</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>
}
title{
font-family: sans-serif;
}
table {
font-size: 9pt;
table-layout: fixed;
}
th {
font-weight: bold;
font-size: 8pt;
vertical-align: middle;
padding: 5px 6px 3px;
background-color: #e3e3e3;
color: #333333;
text-align: left;
}
td {
padding: 4px 6px;
}
td p { align:left }
b {
font-weight: bold;
color: #333333;
}
table.header td {
padding: 2px;
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: #e3e3e3;
line-height: 200%;
}
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: 20pt;
font-weight: bold;
}
span.number {
font-size: 16pt;
}
span.itemname {
font-weight: bold;
line-height: 150%;
}
span.subheader {
font-size: 8pt;
padding: 4px 4px;
}
span.subheaderlabel {
font-size: 8pt;
font-weight: bold;
padding: 4px 4px;
}
hr {
width: 100%;
color: #d3d3d3;
background-color: #d3d3d3;
height: 1px;
}
</style>
</head>
<body header="nlheader" header-height="20%" footer="nlfooter" footer-height="5%" size="Letter">
<table style="width: 100%; margin-top: 10px;"><tr>
<td class="addressheader" colspan="3"><b>Facturatie adres / Billing Address</b></td>
<td class="addressheader" colspan="3"><b>Verzendingsadres / Shipping address</b></td>
<td colspan="6"></td>
</tr>
<tr>
<td class="addressheader" colspan="3" rowspan="2">${record.billaddress}</td>
<td class="addressheader" colspan="3" rowspan="2">${record.shipaddress}</td>
<td align="right" colspan="5"></td>
</tr>
</table>
<table style="margin-top: 10px;">
<tr>
<td class="addressheader" colspan="3"><b>BE BTW nr / BE VAT Number:</b></td>
<td class="addressheader" colspan="3"> BE 0635.808.769</td>
</tr>
<tr>
<td class="addressheader" colspan="3"><b>GB BTW nr / GB VAT Number:</b></td>
<td class="addressheader" colspan="3"> GB 305.8329.09</td>
</tr>
<tr>
<td class="addressheader" colspan="3"><b>FR BTW nr / FR VAT Number:</b></td>
<td class="addressheader" colspan="3"> FR 5684.2791.725</td>
</tr>
</table>
<br/>
<#if record.item?has_content>
<table class="itemtable" style="width: 100%; margin-top: 10px;"><!-- start items --><#list record.item as item><#if item_index==0>
<thead>
<tr>
<th colspan="4" class="addressheader" >Item</th>
<th align="left" colspan="3" class="addressheader" >Hoeveelheid <p style="font-size:8pt;">Quantity</p></th>
<th colspan="2" class="addressheader" ></th>
<th align="left" colspan="4" class="addressheader">Beschrijving <p style="font-size:8pt;">Description</p></th>
<th colspan="2" class="addressheader" ></th>
<th align="right" colspan="4" class="addressheader" >Eenheidsprijs<p style="font-size:8pt;">Unit Price</p></th>
<th colspan="1" class="addressheader" ></th>
<th align="right" colspan="3" class="addressheader" style="text-align=right;" >Prijs <p style="font-size:8pt;">Amount</p></th>
</tr>
</thead>
</#if><tr>
<td colspan="4" class="addressheader"><span>${item.item}</span></td>
<td align="center" colspan="3" line-height="150%" class="addressheader">${item.quantity}</td>
<td colspan="2" class="addressheader"></td>
<td align="left" colspan="4" class="addressheader">${item.description}</td>
<td colspan="2" class="addressheader"></td>
<td align="center" colspan="4" class="addressheader">${item.rate}</td>
<td colspan="1" class="addressheader"></td>
<td align="left" colspan="3" class="addressheader">${item.amount}</td>
</tr>
</#list><!-- end items -->
</table>
<hr /></#if>
<table class="addressheader" style="width: 100%; margin-top: 10px;"><tr>
<td background-color="#ffffff" colspan="2"></td>
<td align="right" class="addressheader" colspan="4"><b>Totaal Excl. btw / Total without VAT</b></td>
<td align="right" class="addressheader">${record.subtotal}</td>
</tr>
<tr>
<td background-color="#ffffff" colspan="2"></td>
<td align="right" class="addressheader" colspan="4"><b> Verzendkosten / Shipping Cost</b></td>
<td align="right" class="addressheader">${record.shippingcost}</td>
</tr>
<tr>
<td background-color="#ffffff" colspan="2"></td>
<td align="right" class="addressheader" colspan="4"><b>Totaal btw / VAT <#list record.item as item><#if item.line=='1'> (${item.taxrate1}) </#if></#list></b></td>
<td align="right" class="addressheader">${record.taxtotal}</td>
</tr>
<tr>
<td background-color="#ffffff" colspan="2"></td>
<td align="right" class="addressheader" colspan="4"><b>Totaal / Total</b></td>
<td align="right" class="addressheader">${record.total}</td>
</tr>
</table>
<hr/>
<table class="subheaderlabel" >
<tr>
<td class="addressheader"></td>
<td class="addressheader">
<table>
<tr>
<td class="addressheader">${record.subsidiary.custrecord_css_bank_info}</td>
<td class="addressheader">${record.subsidiary.custrecord_css_bank_info_2}</td>
</tr>
</table>
</td>
</tr>
<tr>
<td class="addressheader"><b>Betalingstermijn / Payment Terms</b></td>
<td class="addressheader">${record.subsidiary.custrecord_css_payment_terms_invoice}</td>
</tr>
</table>
<p align="left" style="font-size: 8pt;" ><b>Voorwaarden / Terms :</b><span style="font-size: 8pt;">Please review, sign, date, and return to Fully</span></p>
<p align="left" style="font-size: 8pt;" >Once a completed Proforma Invoice is submitted, any changes made to this order must be approved by Fully Europe BVBA.</p>
<table class="subheaderlabel" width = "100%">
<tr>
<td class="addressheader" align="center">${record.subsidiary.custrecord_css_contact_info}</td>
</tr>
</table>
<!--<table style="width: 100%">
<tr>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Signature</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Name</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Title</td>
<td style="width: 30%; border-top: 1px solid #a3a3a3; padding-top: 5px">Date</td>
</tr>
</table>-->
</body>
</pdf>