Invoice Group in Netsuite – Features and Scripting
Category : Uncategorized
Netsuite’s Invoice Groups feature enables grouping of invoices for customers. This feature allows for the creation of several Invoice Groups per customer. Applying payments to an Invoice Group is made easier by this functionality. All of the invoices in an Invoice Group are affected when a payment is applied to that group of invoices. Netsuite enables partial and full payment for Invoice Group just like it does for regular invoices.
For accessing the invoice groups, each user is subject to a set of restrictions and permissions. For example, if there are twenty invoices in a group and you can only view five invoices then you can view only that five invoices.
Enabling the Feature
The Netsuite account needs to have a few settings changed in order to use the Invoice Group feature. To begin with, go to Setup -> Company -> Enable Feature and see if the Invoice Group is enabled for the account.
Now click the Transaction sub tab and move down to the Billing section.
Check if the Invoice Groups is checked, if not, check the box and hit the Save button.
It is to be noted that, once this feature is enabled, it is difficult to disable this feature.
Once the Invoice Group feature is enabled, we need to check the Group Invoice check box in the Financial subtab of the Customer record.
Now, you must mark the For Invoice Grouping checkbox for its associated Sales Order in order to group the invoice for the customer for whom the Group Invoice check box is selected. Uncheck it if you do not want to group the invoice.
If the For Invoice Grouping checkbox is not displayed in the Sales Order, go to Customize -> Customize Form, locate the For Invoice Grouping label in the Screen Fields subtab, check the Show checkbox, and Save.
Now create a new invoice for the Sales Order, since only newly created Invoice or generated invoice is eligible for grouping.
Creating a Group Invoice
Now to create a new Group Invoice, go to Transactions -> Sales -> Group Invoices
By default, it will show All in the Customer list. Invoices for all customers can be grouped by selecting All, or you can choose the customer from the list you want to group the invoice for. The customer list will show only those customers whose Group Invoice is enabled. Check the Group by PO # box to group by purchase order number. Now mark the Group checkbox next to the invoices that you want to group. You can mark all the invoice by clicking the Mark All button and unmark all the marked invoice by clicking Unmark All button.
Here we are taking only one customer.
Now click Submit.
The Group Invoice is created when the Submission Status is Complete. You can view the created Group Invoice by going to Transactions -> Sales -> Group Invoices -> List
Scenario :
Create a Map Reduce Script to create an Invoice Group for the Invoices with same Customer, PO# and terms.
Solution :
/**
*@NApiVersion 2.x
*@NScriptType MapReduceScript
*/
define([‘N/record’, ‘N/search’, ‘N/action’], function (record, search, action) {
function getInputData() {
try {
var creatSrchObj = search.create({ // search to find the Un-Grouped Invoice
type: search.Type.INVOICE,
filters: [
{ name: “groupedto”, operator: “anyof”, values: [“@NONE@”] },
{ name: “mainline”, operator: “is”, values: [“T”] },
{ name: “forinvoicegrouping”, operator: “is”, values: [“T”] },
],
columns: [
{ name: “entity”, summary: “GROUP”, label: “Name”, type: “select”, sortdir: “ASC” },
{ name: “otherrefnum”, summary: “GROUP”, label: “PO/Check Number”, type: “text”, sortdir: “NONE” },
{ name: “terms”, summary: “GROUP”, label: “Terms”, type: “select”, sortdir: “NONE” }
],
title: ‘Search to find Invoice with same customer,PO# and terms’,
id: ‘customsearch_inv_samecustmr’,
isPublic: true
});
return creatSrchObj;
} catch (error) {
log.debug({ title: ‘Error Caught’, details: error });
}
}
function map(context) {
try {
var JSONParseObj = JSON.parse(context.value);
var customerId = JSONParseObj.values[‘GROUP(entity)’].value //Customer
var po_CheckNo = JSONParseObj.values[‘GROUP(otherrefnum)’] //PO#
var terms = JSONParseObj.values[‘GROUP(terms)’].value||”@NONE@” //Terms
var srchInvObj = search.create({ // search to find the Invoices with the received customer,PO#,Terms
type: search.Type.INVOICE,
filters: [
{ name: “groupedto”, operator: “anyof”, values: [“@NONE@”] },
{ name: “forinvoicegrouping”, operator: “is”, values: [“T”] },
{ name: “name”, operator: “is”, values: customerId },
{ name: “otherrefnum”, operator: “equalto”, values: po_CheckNo },
{ name: “terms”, operator: “anyof”, values: terms },
{ name: “mainline”, operator: “is”, values: [“T”] }
],
title: ‘Search invoice with given criteria’,
id: ‘customsearch_inv_givncritria’,
isPublic: true
})
var runSrchInvObj = srchInvObj.run().getRange({ start: 0, end: 1000 });
var invoiceList = “” // stores the invoice with same customer,PO#,Terms
for (var i = 0; i < runSrchInvObj.length; i++) {
invoiceList = invoiceList + runSrchInvObj[i].id + ‘,’;
}
invoiceList = invoiceList.slice(0, -1) //Removes extra “,” at the end
var createGrpInvObj = record.create({type: ‘invoicegroup’});
createGrpInvObj.setValue({fieldId: ‘customer’,value: customerId,ignoreFieldChange: true});
createGrpInvObj.setValue({fieldId: ‘terms’,value: JSONParseObj.values[‘GROUP(terms)’].value,ignoreFieldChange: true});
var grpInvoicId = createGrpInvObj.save({enableSourcing: true,ignoreMandatoryFields: true});
action.execute({recordType: ‘invoicegroup’,id: ‘groupinvoices’,params: {recordId: grpInvoicId,invoicelist: invoiceList}});
} catch (error) {
log.debug({ title: ‘Error Caught’, details: error });
}
}
function reduce(context) {
}
function summarize(summary) {
}
return {
getInputData: getInputData,
map: map,
//reduce: reduce,
//summarize: summarize
}
});