GL Plugin

Creating the GL plugin script for assembly build, vendor bill, and item receipt.

The GL plugin script is used to credit or debit some amounts to the specific accounts respective to the transactions which shows impact to the GL.

/**
 * Module Description
 * 
 * Version Date Author Remarks 1.00 16 Sep 2019 Jobin and Jismi IT services LLP
 * 
 */
function customizeGlImpact(transactionRecord, standardLines, customLines, book) {
    try {
        nlapiLogExecution('DEBUG', 'in inv', transactionRecord.getRecordType());
        if (transactionRecord.getRecordType() == "assemblybuild") {
            var recid = transactionRecord.getId();
            nlapiLogExecution('DEBUG', 'recid', recid);
            var recordid = transactionRecord.id;
            nlapiLogExecution('DEBUG', 'recordid', recordid);
            var assemblybuildSearch = nlapiSearchRecord("assemblybuild", null,
                [
                    ["datecreated", "onorafter", "7/1/2019 12:00 am"],
                    "AND",
                    ["type", "anyof", "Build"],
                    "AND",
                    ["location", "anyof", "6", "115", "12", "13", "109", "18", "14", "112", "15", "16", "11", "9", "17", "10"],
                    "AND",
                    ["internalid", "anyof", recordid]
                ],
                [
                    new nlobjSearchColumn("tranid"),
                    new nlobjSearchColumn("internalid"),
                    new nlobjSearchColumn("amount"),
                    new nlobjSearchColumn("creditamount"),
                    new nlobjSearchColumn("debitamount"),
                    new nlobjSearchColumn("account"),
                    new nlobjSearchColumn("location")
                ]
            );
            if (assemblybuildSearch) {
                if (assemblybuildSearch.length) {
                    var totalValue = 0;
                    for (var i = 0; i < standardLines.getCount(); i++) {
                        nlapiLogExecution('DEBUG', 'getCreditAmount', standardLines.getLine(i).getCreditAmount());
                        if (standardLines.getLine(i).getCreditAmount() > 0) {
                            var newLine1 = customLines.addNewLine();
                            newLine1.setDebitAmount(standardLines.getLine(i).getCreditAmount());
                            newLine1.setAccountId(standardLines.getLine(i).getAccountId());
                            newLine1.setMemo(' ');
                            totalValue += parseFloat(standardLines.getLine(i).getCreditAmount());
                        }
                    }

                    nlapiLogExecution('DEBUG', 'totalValue', totalValue);
                    var newLine = customLines.addNewLine();
                    newLine.setCreditAmount(totalValue);
                    newLine.setAccountId(250);
                    newLine.setMemo(' ');
                }
            }
        } else if (transactionRecord.getRecordType() == "vendorbill") {
            var recordid = transactionRecord.id;
            nlapiLogExecution('DEBUG', 'recordid', recordid);
            var vendorbillSearch = nlapiSearchRecord("vendorbill", null,
                [
                    ["type", "anyof", "VendBill"],
                    "AND",
                    ["datecreated", "onorafter", "7/1/2019 12:00 am"],
                    "AND",
                    ["location", "anyof", "6", "115", "12", "13", "109", "18", "14", "112", "15", "16", "11", "9", "17", "10"],
                    "AND",
                    ["internalid", "anyof", recordid]
                ],
                [
                    new nlobjSearchColumn("internalid"),
                    new nlobjSearchColumn("location"),
                    new nlobjSearchColumn("tranid"),
                    new nlobjSearchColumn("account")
                ]
            );
            if (vendorbillSearch) {
                if (vendorbillSearch.length) {
                    var totalValue = 0;
                    for (var i = 0; i < standardLines.getCount(); i++) {
                        nlapiLogExecution('DEBUG', 'getCreditAmount', standardLines.getLine(i).getDebitAmount());
                        if (standardLines.getLine(i).getDebitAmount() > 0) {
                            var newLine1 = customLines.addNewLine();
                            newLine1.setCreditAmount(standardLines.getLine(i).getDebitAmount());
                            newLine1.setAccountId(standardLines.getLine(i).getAccountId());
                            newLine1.setMemo(' ');
                            totalValue += parseFloat(standardLines.getLine(i).getDebitAmount());
                        }
                    }

                    nlapiLogExecution('DEBUG', 'totalValue', totalValue);
                    var newLine = customLines.addNewLine();
                    newLine.setDebitAmount(totalValue);
                    newLine.setAccountId(250);
                    newLine.setMemo(' ');
                }
            }
        } else if (transactionRecord.getRecordType() == "itemreceipt") {
            var recordid = transactionRecord.id;
            nlapiLogExecution('DEBUG', 'recordid', recordid);
            var itemreceiptSearch = nlapiSearchRecord("itemreceipt", null,
                [
                    ["datecreated", "onorafter", "7/1/2019 12:00 am"],
                    "AND",
                    ["type", "anyof", "ItemRcpt"],
                    "AND",
                    ["location", "anyof", "6", "115", "12", "13", "109", "18", "14", "112", "15", "16", "11", "9", "17", "10"],
                    "AND",
                    ["internalid", "anyof", recordid]
                ],
                [
                    new nlobjSearchColumn("tranid"),
                    new nlobjSearchColumn("internalid"),
                    new nlobjSearchColumn("amount"),
                    new nlobjSearchColumn("creditamount"),
                    new nlobjSearchColumn("debitamount"),
                    new nlobjSearchColumn("account"),
                    new nlobjSearchColumn("location")
                ]
            );
            if (itemreceiptSearch) {
                if (itemreceiptSearch.length) {
                    var totalValue = 0;
                    for (var i = 0; i < standardLines.getCount(); i++) {
                        nlapiLogExecution('DEBUG', 'getCreditAmount', standardLines.getLine(i).getDebitAmount());
                        if (standardLines.getLine(i).getDebitAmount() > 0) {
                            var newLine1 = customLines.addNewLine();
                            newLine1.setCreditAmount(standardLines.getLine(i).getDebitAmount());
                            newLine1.setAccountId(standardLines.getLine(i).getAccountId());
                            newLine1.setMemo(' ');
                            totalValue += parseFloat(standardLines.getLine(i).getDebitAmount());
                        }
                    }
                    nlapiLogExecution('DEBUG', 'totalValue', totalValue);
                    var newLine = customLines.addNewLine();
                    newLine.setDebitAmount(totalValue);
                    newLine.setAccountId(250);
                    newLine.setMemo(' ');
                }
            }
        }
    } catch (e) {
        nlapiLogExecution('DEBUG', 'custom GL', e.message);
    }

}

Leave a comment

Your email address will not be published. Required fields are marked *