Version: eXtendPS-SE 1.3.0 and above
Audience: Administrator, Developer

Use Case

To include shipping and tax charges as expense lines on the generated vendor bill record from the PromoStandards invoice response.

Prerequisites

  1. An expense account to record for shipping charges.
  2. An expense account to record for tax charges.

Configuration

To set the expense lines for shipping and tax charges, add the following function to the suite_promo_transformers.js file. Replace ACCOUNT_FOR_SHIPPING_EXPENSE_LINES and ACCOUNT_FOR_SALES_TAX_EXPENSE_LINES with the internal ID of the associated expense account in the snippet below.
/**
 * @param    {Object} args
 * @property {Object} args.vendorBillRecord
 * @property {Object} args.invoice
 * @returns  {Object} vendorBillRecord
 */
function setTaxAndShippingAsExpense(args) {
  var vendorBillRecord = args.vendorBillRecord;
  var invoice = args.invoice || {};

  // Adding expense line for version 1.0.0
  // This section is applicable only for invoice 1.0.0
  var taxArray = _.get(invoice'taxarray.tax') || [];
  if (taxArray && taxArray.length > 0) {
    var totalTaxAmount = invoice.taxamount || '';
    totalTaxAmount = totalTaxAmount ? parseFloat(totalTaxAmount) : 0;

    if (totalTaxAmount) {
      taxArray.forEach(function (taxObject) {
        var taxAmount = taxObject.taxamount || '';
        taxAmount = taxAmount ? parseFloat(taxAmount) : 0;

        if (!taxAmount) {
          return;
        }

        vendorBillRecord.selectNewLine({ sublistId: 'expense' });
        vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'account'value: ACCOUNT_FOR_SALES_TAX_EXPENSE_LINES });
        vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'amount'value: taxAmount });
        memo = '';
        memo += 'Tax Type: ' + (taxObject.taxtype || '');
        memo += (memo ? '\n' : '') + 'Tax Jurisdiction: ' + (taxObject.taxjurisdiction || '');
        memo = (memo.length > MEMO_TEXT_LIMIT) ? (memo.substring(0, (MEMO_TEXT_LIMIT - 3)) + '...') : memo;
        vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'memo'value: memo });
        vendorBillRecord.commitLine({ sublistId: 'expense' });
      });
    }
  }

  // Adding expense line for the shipping amount here for both 0.0.1 and 1.0.0 version.
  // For 0.0.1 version need to pick shipping amount from shippingandhandlingamount
  // For 1.0.0 version need to pick shipping amount from shippingamount
  var shippingAmount = invoice.shippingandhandlingamount || invoice.shippingamount;
  shippingAmount = shippingAmount ? parseFloat(shippingAmount) : 0;
  if (shippingAmount) {
    vendorBillRecord.selectNewLine({ sublistId: 'expense' });
    vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'account'value: ACCOUNT_FOR_SHIPPING_EXPENSE_LINES });
    vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'amount'value: shippingAmount });
    memo = '';
    memo += 'Line Type: Ship Line';
    memo = (memo.length > MEMO_TEXT_LIMIT) ? (memo.substring(0, (MEMO_TEXT_LIMIT - 3)) + '...') : memo;
    vendorBillRecord.setCurrentSublistValue({ sublistId: 'expense'fieldId: 'memo'value: memo });
    vendorBillRecord.commitLine({ sublistId: 'expense' });
  }

  return vendorBillRecord;
}


As an example, if your expense account for shipping charges has an internal ID of 1234 and your expense account for tax charges has an internal ID of 5125, then you would replace ACCOUNT_FOR_SHIPPING_EXPENSE_LINES and ACCOUNT_FOR_SALES_TAX_EXPENSE_LINES with 1234 and 5125 respectively.