/**
 * @NApiVersion 2.0
 * @NScriptType UserEventScript
 * @NModuleScope SameAccount
 */
define(['N/record','N/format', 'N/log'], function(record, format) {

    function beforeSubmit(context) {
        // Get the invoice record
        var invoiceRecord = context.currentRecord;
        var tranDate = invoiceRecord.getValue('trandate');
        var termstrxDate = invoiceRecord.getValue('custbody31'); //terms

        var formattedTranDate = format.parse({
            value: tranDate, 
            type: format.Type.DATE
        });
        EOMONTH(trandate+60,0);
        var endOfMonthDate = new Date(formattedTranDate.getFullYear(), formattedTranDate.getMonth() + 2, 0);
        invoiceRecord.setValue({
            fieldId: 'duedate',
            value: endOfMonthDate
        });
    }

    return {
        beforeSubmit: beforeSubmit
      };
})