Rounding off Workaround

For example, If the transaction total is 2000.5 Some times business needs to rounding off it as 2001. In NetSuite, this functionality is not available and they have to manually put a separate journal entry for doing this if they want to use it.

Our Solution

We will add the other charge item for the Round Off Amount in Transactions. So that Round off amount will directly go to its corresponding account. In the case of header level discounts, Subtotal Item will be added after all the inventory Items.

Development

Created a User event script that will add another charge item in the record and subtotal item in the case of Header level discounts in the record save by calculating the adjustment value based on the transaction ‘TOTAL’.

Script Reference


 var roundOffitem = 1033;
        var discountitemId = 8;
        var subtotalId = -2;

        function afterSubmit(scriptContext) {
            try {

                var curRec = scriptContext.newRecord;
                var curRecType = scriptContext.newRecord.type;
                var curRecId = scriptContext.newRecord.id;
                var billRec = record.load({
                    type: curRecType,
                    id: curRecId,
                    isDynamic: true
                });
                var currencytype = billRec.getValue({
                    fieldId: 'currency'
                });

                var total = billRec.getValue({
                    fieldId: 'total'
                });

                if (curRecType == 'creditmemo') {
                    total = total * -1;

                }
                var createdFrom = billRec.getValue({
                    fieldId: 'createdfrom'
                });


                //if (curRecType == "salesorder") {
                //
                //Round off functionality

                log.debug("Math.round(total)", Math.round(total));
                log.debug("Math.round(total)", Math.round(total));
                log.debug("Math.rotal)", total);

                var roundOffamount = parseFloat((Math.round(total) - total).toFixed(2));

                log.debug("roundOffamount", roundOffamount);
                var discountitem = billRec.getValue({
                    fieldId: 'discountitem'
                });
                var discounttotal = billRec.getValue({
                    fieldId: 'discounttotal'
                });
                var discountFlag = billRec.getValue({
                    fieldId: 'custbody_jj_drf_153_discount_item_flag'
                });
                if (scriptContext.type == "create" && !createdFrom && discountitem) {
                    var lineNumber = billRec.findSublistLineWithValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: subtotalId
                    });
                    var lineNum = billRec.selectNewLine({
                        sublistId: 'item'
                    });

                    billRec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: subtotalId,
                    });
                    billRec.commitLine({
                        sublistId: 'item'
                    });

                    var lineNumber = billRec.findSublistLineWithValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: discountitemId
                    });
                    var lineNum = billRec.selectNewLine({
                        sublistId: 'item'
                    });
                    billRec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: discountitemId,
                    });

                    billRec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'rate',
                        value: discounttotal,
                    });
                    billRec.commitLine({
                        sublistId: 'item'
                    });

                    billRec.setValue({
                        fieldId: 'discountitem',
                        value: ''
                    });
                    billRec.setValue({
                        fieldId: 'custbody_jj_drf_153_discount_item_flag',
                        value: true
                    });
                }

                if (roundOffamount != 0 && scriptContext.type == "create" && !createdFrom) {
                    var lineNum = billRec.selectNewLine({
                        sublistId: 'item'
                    });
                    billRec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'item',
                        value: roundOffitem,
                    });
                    billRec.setCurrentSublistValue({
                        sublistId: 'item',
                        fieldId: 'rate',
                        value: roundOffamount,
                    });
                    billRec.commitLine({
                        sublistId: 'item'
                    });
                    total = billRec.getValue({
                        fieldId: 'total'
                    });
                }

Leave a comment

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