The following function can be used to add the summary box to the suitelet using HTML.
/**
* Generates HTML for the summary box displaying category discounts.
*
* @param {Object} categoryDiscounts - An object containing category discounts.
* @returns {string} HTML string representing the summary box.
*/
function generateSummaryBoxData(categoryDiscounts, totalBillable) {
try {
let html = '<style>' +
'table.newtotallingtable caption {n' +
' display: table-caption !important;n' +
' margin-bottom: 10px;n' +
' font-weight: bold;n' +
' color: white;n' +
' font-size: 12px !important;n' +
' padding: 4px 0px 4px 8px;n' +
' background-color: #607799;n' +
'}' +
'caption, th {n' +
' text-align: left;n' +
'}' +
'table.newtotallingtable td {n' +
' padding: 5px 0;n' +
'}' +
'table.newtotallingtable .total-line {n' +
' border-top: 1px solid #000;n' +
' padding-top: 5px;n' +
'}' +
'</style>';
html += '<span class="bgmd totallingbg" style="display:inline-block; position:relative;left: 0px; padding: 10px 25px; margin-bottom:5px;">';
html += '<table class="newtotallingtable" cellspacing="2" cellpadding="0px" border="0px" style="padding: 5px;n' +
' width: 217px;"><caption>Free Items</caption><tbody>';
let totalDiscount = 0;
for (let key in categoryDiscounts) {
html += addCategoryRow(key, categoryDiscounts[key]);
totalDiscount += Number(categoryDiscounts[key]);
}
let discountPerc = totalDiscount? (totalBillable? ((totalDiscount / totalBillable) * 100) : 100) : 0;
html += '<tr class="total-line"><td colspan="2" style="border-top: 1px solid #000;"></td></tr>';
html += '<tr><td style="color: #262626 !important; font-size: 12px;" align="left">TOTAL</td><td align="right" style="font-size: 12px; color: #262626 !important;"><b>$ ';
html += Math.abs(totalDiscount).toFixed(2) + '</b></td></tr>';
html += '<tr><td style="color: #262626 !important; font-size: 12px;" align="left">Discount % </td><td align="right" style="font-size: 12px; color: #262626 !important;"><b>';
html += Math.abs(discountPerc).toFixed(2) + '%</b></td></tr>';
html += '</table></div>';
return html;
} catch (e) {
log.error('generateSummaryBoxData', e);
return '';
}
}