var Hwidth=90
function addrow(grid)
{
    var generaterow1 = function (i) {
        var row = {};  
        return row;
    }
    var datarow = generaterow1();
    $(grid).jqxGrid('addrow', null, datarow);
}
$(document).on("keyup", 'input[type="textbox"]', function () {
    var length = $(this).val.length;
    if (length != 0) {
        $(this).val($(this).val().replace(/[a-z]/g, function (letter) {
            return letter.toUpperCase();
        }));
       
    }
});

$(document).on("keyup", '.jqx-combobox-input', function () {
    var length = $(this).val.length;
    if (length != 0) {
        $(this).val($(this).val().replace(/[a-z]/g, function (letter) {
            return letter.toUpperCase();
        }));

    }
});
function F5ViewWindow(window) {
    var $this = $(this);
    var offset = $this.offset();
    var width = $this.width();
    var height = $this.height();
    let centerX = (width - 800) / 2;
    let centerY = (height - 650) / 2;

    // var offset = gridcashier.offset();
    $(window).jqxWindow({
        position: { x: centerX, y: centerY },
        showCollapseButton: false, maxHeight: 700, maxWidth: 1000, minHeight: 200, minWidth: 200, height: 550, width: 800, isModal: true, keyboardCloseKey: 0, resizable: false,
        initContent: function () {

        }
    });
    $(window).jqxWindow({ zIndex: 50 });
    $(window).jqxWindow('Open');

}
function parseDate(str) {
    var mdy = str.split('/');
    return new Date(mdy[2], mdy[0] - 1, mdy[1]);
}
function newguid() { // Public Domain/MIT
    var d = new Date().getTime();//Timestamp
    var d2 = (performance && performance.now && (performance.now()*1000)) || 0;//Time in microseconds since page-load or 0 if unsupported
    return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
        var r = Math.random() * 16;//random number between 0 and 16
        if(d > 0){//Use timestamp until depleted
            r = (d + r)%16 | 0;
            d = Math.floor(d/16);
        } else {//Use microseconds since page-load if supported
            r = (d2 + r)%16 | 0;
            d2 = Math.floor(d2/16);
        }
        return (c === 'x' ? r : (r & 0x3 | 0x8)).toString(16);
    });
}
function dateformatIN(date) {
    var dd = date.getDate();
    var mm = date.getMonth() + 1; //January is 0!
    var yyyy = date.getFullYear();
    if (dd < 10) {
        dd = '0' + dd;
    }
    if (mm < 10) {
        mm = '0' + mm;
    }
    var cdate = dd + '/' + mm + '/' + yyyy;
    return cdate;
}
function dateformat(date) {
    var parts = date.split('/');

    var datearray = date.split("/");   
    return (datearray[1] + '/' + datearray[0] + '/' + datearray[2]);
 
}

function AddDays(date, days) {
    var cdate = new Date(date);
    cdate = cdate.setDate(cdate.getDate() + days);
    return new Date(cdate);

}

function roundoff1(num) {
    if (num < 0) {
        num = num * (-1);
        var data = (+(Math.round(num + "e+6") + "e-6")).toFixed(2);
        return (data * (-1));
    }
    else {
        return (+(Math.round(num + "e+6") + "e-6")).toFixed(6);
    }
}
function roundoff3(num) {
    if (num < 0) {
        num = num * (-1);
        var data = (+(Math.round(num + "e+3") + "e-3")).toFixed(3);
        return (data * (-1));
    }
    else {
        return (+(Math.round(num + "e+3") + "e-3")).toFixed(3);
    }
}
function roundoff(num) {
    if (num < 0) {
        num = num * (-1);
        var data = (+(Math.round(num + "e+2") + "e-2")).toFixed(2);
        return (data * (-1));
    }
    else {
        return (+(Math.round(num + "e+2") + "e-2")).toFixed(2);
    }
}
function Keypress09(key) {
    if (key == "0" ||
        key == "1" || key == "2" ||
        key == "3" || key == "4" ||
        key == "5" || key == "6" ||
        key == "7" || key == "8" ||
        key == "9")
    {
        return true;
    }
    else
    {
        return false;
    }
}

function Keypress09N(key, value) {
    if (key == "0" || key == "-" ||
        key == "1" || key == "2" ||
        key == "3" || key == "4" ||
        key == "5" || key == "6" ||
        key == "7" || key == "8" ||
        key == "9") {
        if ((value.toString().startsWith("-")) == true && key == "-") {

            return false;
        }
        else {

            if (value.toString().length == 0 && key == "-") {
                return true;
            }
            else {
                if (key == "-") {
                    return false;
                }
                else {
                    return true;
                }
            }
        }
    }
    else {
        return false;
    }
}

function KeypressAmountN(key, value) {
    if (key == "0" || key == "." ||
        key == "1" || key == "2" ||
        key == "3" || key == "4" ||
        key == "5" || key == "6" ||
        key == "7" || key == "8" || key == "-" ||
        key == "9") {
        if (value.split(".").length >= 2 && key == ".") {

            return false;
        }
        else {

            if ((value.toString().startsWith("-")) == true && key == "-") {

                try {
                    if (value.substring(1, value.length - 4).Equals(".")) {
                        return true;
                    }
                    else {
                        return false;
                    }
                }
                catch (err) {
                    return false;
                }

            }
            else {

                if (value.toString().length == 0 && key == "-") {
                    return true;
                }
                else {
                    if (key == "-") {
                        try {
                            if (value.substring(1, value.length - 4).Equals(".")) {
                                return true;
                            }
                            else {
                                return false;
                            }
                        }
                        catch (err) {
                            return false;
                        }
                    }
                    else {
                        return true;
                    }
                }


            }

        }
    }
    else {
        return false;
    }
}

function KeypressAmount(key,value) {
    if (key == "0" || key == "." ||
        key == "1" || key == "2" ||
        key == "3" || key == "4" ||
        key == "5" || key == "6" ||
        key == "7" || key == "8" ||
        key == "9")
    {
        var temp = value.toString().split(".");
        if (value.toString().split(".").length >= 2 && key == ".") {

            return false;
        }
        else {
            return true;
        }
    }
    else {
        return false;
    }
}

function GridKeyPressValidation(grid, event, length, EntryType, scaleLength,  Negativevalue) {
   var cell = $(grid).jqxGrid('getselectedcell');
    var rowindex = cell.rowindex;
    var columnname = cell.datafield;
    var value = $(grid).jqxGrid('getcelltext', rowindex, columnname);
     try {
        $(grid).jqxGrid('setcellvalue', rowindex, "EditMode", "1");
    }
    catch (err) {

    }
    if (GridEnterMode) {
        $(grid).jqxGrid('setcellvalue', rowindex, columnname, "");   
        value = $(grid).jqxGrid('getcelltext', rowindex, columnname);
        GridEnterMode = false;
    }
    if (NullToString(value) == "-.") {
        $(grid).jqxGrid('setcellvalue', rowindex, columnname, "-0.");
        value = $(grid).jqxGrid('getcelltext', rowindex, columnname);
    }
    if (value == null) {
        value = "";
    }
    value = value.toString();
    var e = event.charCode ? event.charCode : event.keyCode ? event.keyCode : 0;
    if (e == 0) {     
        if (NullToString(value).length >= 1) {
            value = value.substring(0, value.length - 1)
            $(grid).jqxGrid('setcellvalue', rowindex, columnname, value);
        }
        return;
    }
    if (EntryType == "int") {
        if (Keypress09(event.key)) {              
            if (NullToString(value).length < length) {
                if (ValNum(value) == 0) {
                    $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                }
                else {
                    $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value)+event.key);
                }
            }
        }
        return;
    } 
    else if (EntryType == "intN") {
        if (Keypress09N(event.key, NullToString(value))) {
            if (NullToString(value).length < length) {

                if (NullToString(value).toString().startsWith("-")) {
                    $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                }
                else {
                    if (ValNum(value) == 0) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                    }
                    else {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                    }
                }
            }
        }
        return;
    } 
    else if (EntryType == "float") {
     
        if (KeypressAmount(event.key, NullToString(value))) {  

            var ttt = NullToString(value).length;
            if (NullToString(value).length < length) {

                if (event.key == "." && NullToString(value) =="") {
                    $(grid).jqxGrid('setcellvalue', rowindex, columnname, "0.");
                    return;
                }    
                if (NullToString(value).includes(".")) {
                    if (value.split(".")[1].length < scaleLength) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                    }
                    else if (value.split(".")[1].length == scaleLength) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                    }                 
                }
                else {
                    if (event.key == "." && ValNum(value) == 0) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, "0.");
                        return;
                    }
                    else if (ValNum(value) == 0) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                    }
                    else {
                        var temp = NullToString(value) + event.key;
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, temp);
                    }
                }
            }
        }
        return;
    }
    else if (EntryType == "floatN") {

        if (KeypressAmountN(event.key, NullToString(value))) {

            if (NullToString(value).length < length) {
                if (Negativevalue == 0) {
                    if (event.key == "." && NullToString(value) == "") {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, "0.");
                        return;
                    }
                }
                if (NullToString(value).includes(".")) {
                    if (value.split(".")[1].length < scaleLength) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                    }
                    else if (value.split(".")[1].length == scaleLength) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                    }
                }
                else {
                    if (event.key == "." && ValNum(value) == 0 && Negativevalue == 0) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, "0.");
                        return;
                    }
                    else if (NullToString(value).toString().startsWith("-")) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                    }
                    else if (ValNum(value) == 0) {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, event.key);
                    }
                    else {
                        $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key);
                    }
                }
            }
        }
        return;
    }
    else if (EntryType == "string") {
        if (NullToString(value).length < length) {
            $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key.toString().toUpperCase());
        }
    }
    else if (EntryType == "strings") {
        if (NullToString(value).length < length) {
            $(grid).jqxGrid('setcellvalue', rowindex, columnname, NullToString(value) + event.key.toString().toLowerCase());
        }
    }
    else {
        if (e >= 97 && e <= 122) {
            var newKey = e - 32;
            event.keyCode = newKey;
            event.charCode = newKey;
        }
    }

}


function DeleteRow(grid, rowindex, columnindex, cloumnname, rowcount, msgstatus) {
    if (msgstatus == 1) {
        MsgBoxYesNo("Do you Want to Delete Row?").then(function (reply) {
            if (reply == "Yes")
            {
            if (rowcount > 1) {
                var id = $(grid).jqxGrid('getrowid', rowindex);
                var commit = $(grid).jqxGrid('deleterow', id);
                rowcount = rowcount - 1;
            }
            else {
                var id = $(grid).jqxGrid('getrowid', rowindex);
                var commit = $(grid).jqxGrid('deleterow', id);
                addrow(grid);
            }
            rowcount = $(grid).jqxGrid('getdatainformation').rowscount;
            var value = $(grid).jqxGrid('getcellvalue', rowcount - 1, cloumnname);
            if (NullToString($(grid).jqxGrid('getcellvalue', rowcount - 1, cloumnname)) != "") {
                addrow(grid);
                setTimeout(function () {
                    $(grid).jqxGrid('selectcell', rowcount, cloumnname);
                    $(grid).jqxGrid('focus');
                }, 50);
              
            }
            else {
                setTimeout(function () {
                    $(grid).jqxGrid('selectcell', rowcount - 1, cloumnname);
                    $(grid).jqxGrid('focus');
                }, 50);
              
            }
        }
    });     
    
    }
    else
    {
        if (rowcount > 1) {
            var id = $(grid).jqxGrid('getrowid', rowindex);
            var commit = $(grid).jqxGrid('deleterow', id);
            rowcount = rowcount - 1;
        }
        else {
            var id = $(grid).jqxGrid('getrowid', rowindex);
            var commit = $(grid).jqxGrid('deleterow', id);
            addrow(grid);
        }
        rowcount = $(grid).jqxGrid('getdatainformation').rowscount;
        var value = $(grid).jqxGrid('getcellvalue', rowcount - 1, cloumnname);
        if (NullToString($(grid).jqxGrid('getcellvalue', rowcount - 1, cloumnname)) != "") {
            addrow(grid);
        
            setTimeout(function () {
                $(grid).jqxGrid('selectcell', rowcount, cloumnname);
                $(grid).jqxGrid('focus');
            }, 50);
        }
        else {
            setTimeout(function () {
                $(grid).jqxGrid('selectcell', rowcount-1, cloumnname);
                $(grid).jqxGrid('focus');
            }, 50);
        
        }
    }
}
function findindex(array, value) {
    for (var i = 0; i < array.length; i++) {
        if (array[i] == value) {
            return i;
        }
    }
    return null;
}

function findcolumnindex(array, value,columnname) {
    for (var i = 0; i < array.length; i++) {
        var temp = array[i][columnname];
        if (temp == value) {
            return i;
        }
    }
    return null;
}
function VisibleColumn(filename, gridcolumns)
{
    totalwidthgrid = 0; 
    var getData = [];
    $.ajax({
        async: false,
        url: "/Content/Appdata/Visible/" + filename + ".json?v = " + new Date(),
        dataType: 'json',
        contentType: "application/json; charset=utf-8",
        success: function (data) {

            if (data != null) {
                if (data.length != 0) {
                    getData = data;
                    //for (var i = 0; i < data.length; i++) {
                    //    gridItemmaster.jqxGrid('showcolumn', data[i].column);
                    //}
                }
            }

        },
        error: function (error, e1) {

        },
    });
    for (var i = 0; i < getData.length; i++) {
        var column = getData[i].column;
        var Visible = getData[i].Visible;
        if (Visible == false) {
            Visible = true;
        }
        else {
            Visible = false;
        }
        var Width = getData[i].Width;
        var index = findcolumnindex(gridcolumns, column, "datafield")// gridcolumns.indexOf(column);
        if (index != null) {
            try {
                var hiddenvalue = gridcolumns[index].hidden;
                if (hiddenvalue != null) {
                    gridcolumns[index].hidden = Visible;
                }
                if (Visible == false) {
                    totalwidthgrid = totalwidthgrid + Width;
                }
                gridcolumns[index].width = Width;
            
            }
            catch (err) {

            }
        }
    }
}
function AutoScrollPage(grid,rowidnew)
            {
    var pagesize = $(grid).jqxGrid('getdatainformation').paginginformation.pagesize;
                var reminder = rowidnew % pagesize;
                var top = (reminder * 25);               
                var height = $(grid).jqxGrid('height') / 2;
               
                top = top - height;
        
                    setTimeout(function () { $(grid).jqxGrid('scrolloffset', top, 0); }, 10);
        
               
            }
            function AutoScroll(grid,rowidnew)
            {
                var Rowcount = $(grid).jqxGrid('getdatainformation').rowscount;
                var top = (Rowcount * 25);

                setTimeout(function () { $(grid).jqxGrid('scrolloffset', top, 0); }, 10);

        
               
}
function AutoScrollKeydown(grid, rowindex) {
    var top = ((rowindex-1) * 25);
    var position = $(grid).jqxGrid('scrollposition');
    var left = position.left;
    setTimeout(function () { $(grid).jqxGrid('scrolloffset', top, left); }, 5);



}
function ServiceCallByList(url, datavalue) {

        var objlist = [];
        $.ajax({
            async: false,
            url: url,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            // data: '{"Id":' + value + '}',
            data: JSON.stringify(datavalue),
            success: function (data) {
                objlist = data;


            },
            error: function (error) {       
                MsgBox('Technical Fault Contact Software Vendor  !!!.');
            }
        });
        return objlist;
    
}
function GetComputerName() {
    try {
        //var network = new ActiveXObject('WScript.Network');
        //console.log(network.computerName);
        var dnsComp = Components.classes["@mozilla.org/network/dns-service;1"];
        var dnsSvc = dnsComp.getService(Components.interfaces.nsIDNSService);
        var compName = dnsSvc.myHostName;
    }
    catch (e) { }
}
function ServiceCallByIdasync(url, datavalue) {

    if (datavalue != "") {
        loaderopen();
        var objlist = [];
        $.ajax({       
            url: url,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            // data: '{"Id":' + value + '}',
            data: datavalue,
            success: function (data) {
                objlist = data;
                loaderclose();

            },
            error: function (error) {
                loaderclose();
                MsgBox('Technical Fault Contact Software Vendor  !!!.');
            }
        });
        return objlist;
    }
    else {
        loaderopen();
        var objlist = [];
        $.ajax({     
            url: url,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            // data: '{"Id":' + value + '}',
            data: JSON.stringify(objlist),
            success: function (data) {
                loaderclose();
                objlist = data;


            },
            error: function (error) {
                loaderclose();
                MsgBox('Technical Fault Contact Software Vendor  !!!.');
            }
        });
        return objlist;
    }
}
function ServiceCallById(url,datavalue)
{
    if(datavalue !="")
    {
    var objlist=[];
    $.ajax({
        async: false,
        url: url,
        type: "POST",
        dataType: "json",
        contentType: "application/json; charset=utf-8",
        // data: '{"Id":' + value + '}',
        data: datavalue,
        success: function (data) {
            objlist = data;
        

        },
        error: function (error) {       
            MsgBox('Technical Fault Contact Software Vendor  !!!.');
        }
    });
    return objlist;
    }
    else
    {
        var objlist = [];
        $.ajax({
            async: false,
            url: url,
            type: "POST",
            dataType: "json",
            contentType: "application/json; charset=utf-8",
            // data: '{"Id":' + value + '}',
            data: JSON.stringify(objlist),
            success: function (data) {
                objlist = data;


            },
            error: function (error) {
             
                MsgBox('Technical Fault Contact Software Vendor  !!!.');
            }
        });
        return objlist;
    }
}
function jsondatesystem(date) {
    var myDate = new Date(date.match(/\d+/)[0] * 1);
    return $.jqx.dataFormat.formatdate(myDate, 'MM/dd/yyyy');
}
function jsondate(date)

{
 var myDate = new Date(date.match(/\d+/)[0] * 1);             
              return $.jqx.dataFormat.formatdate(myDate, 'dd/MM/yyyy');
}



function F5ViewWindow1(window) {
    var $this = $(this);
    var offset = $this.offset();
    var width = $this.width();
    var height = $this.height();
    let centerX = (width - 800) / 2;
    let centerY = (height - 650) / 2;

    // var offset = gridcashier.offset();
    $(window).jqxWindow({
        position: { x: centerX, y: centerY },
        showCollapseButton: false, maxHeight: 700, maxWidth: 1000, minHeight: 200, minWidth: 200, height: 500, width: 300, isModal: true, keyboardCloseKey: 0, resizable: false,
        initContent: function () {

        }
    });
    $(window).jqxWindow('Open');

}
function F5ViewWindow(window) {  
    var $this = $(this);
    var offset = $this.offset();
    var width = $this.width();
    var height = $this.height();
    let centerX = (width - 800) / 2;
    let centerY = (height - 650) / 2;

    // var offset = gridcashier.offset();
    $(window).jqxWindow({
        position: { x: centerX, y: centerY },
        showCollapseButton: false, maxHeight: 700, maxWidth: 1000, minHeight: 200, minWidth: 200, height: 550, width: 800, isModal: true, keyboardCloseKey: 0, resizable: false,
        initContent: function () {

        }
    });
    $(window).jqxWindow({ zIndex: 50 }); 
    $(window).jqxWindow('Open');
    
}



function MsgBoxViewPrintMail(msg) {
    var defer = $.Deferred();
    $('<div>' + msg + '</div>').dialog({
        autoOpen: true,
        resizable: false,
        height: 'auto',
        width: 500,
        modal: true,
        close: function () {
            $(this).dialog('destroy');
        },
        title: 'WebPOS',
        buttons: {
            "Print": function () {
                defer.resolve("Print"); //on Yes click, end deferred state successfully (done)
                $(this).dialog("close");
            },
            "View": function () {
                defer.resolve("View");
                $(this).dialog("close");
            },
            "Print Mail": function () {
                defer.resolve("Print Mail"); //on Yes click, end deferred state successfully (done)
                $(this).dialog("close");
            },
            "Mail": function () {
                defer.resolve("Mail");
                $(this).dialog("close");
            },
            "Cancel": function () {
                defer.resolve("Cancel");
                $(this).dialog("close");
            }
        }
    });
    return defer.promise(); //important to return the defer promise
}
function MsgBoxViewPrint(msg) {
    var defer = $.Deferred();
    $('<div>' + msg + '</div>').dialog({
        autoOpen: true,
        resizable: false,
        height: 'auto',
        width: 400,
        modal: true,
        close: function () {
            $(this).dialog('destroy');
        },
        title: 'WebPOS',
        buttons: {
            "Print": function () {
                defer.resolve("Print"); //on Yes click, end deferred state successfully (done)
                $(this).dialog("close");
            },
            "View": function () {
                defer.resolve("View");
                $(this).dialog("close");
            },
             "Cancel": function () {
                 defer.resolve("Cancel");
                $(this).dialog("close");
            }
        }
    });
    return defer.promise(); //important to return the defer promise
}
function MsgBoxYesNo(msg) {
    var defer = $.Deferred();
    $('<div>' + msg + '</div>').dialog({
        autoOpen: true,
        resizable: false,
        height: 'auto',
        width: 400,
        modal: true,
        close: function () {
            $(this).dialog('destroy');
        },  
        title: 'WebPOS',
        buttons: {
            "Yes": function () {
                defer.resolve("Yes"); //on Yes click, end deferred state successfully (done)
                $(this).dialog("close");
            },
            "No": function () {
                defer.resolve("No");
                $(this).dialog("close");
            }
        }
    });
 
    return defer.promise(); //important to return the defer promise
}
//function MsgBoxSuccess(msg) {
//    $('<div>' + msg + '</div>').dialog({
//       // autoOpen: true,
//        resizable: false,
//        height: 'auto',
//        width: 400,
//        modal: true,   
//        //hide: {
//        //    effect: "explode",
//        //    duration: 1000
//        //},
//        title: 'WebPOS',
//        open: function (event, ui) {
//            setTimeout(function () {b
//                $(this).dialog("close");
//            }, 1000);
//        }
     
//    });
//    /*  return defer.promise();*/ //important to return the defer promise
//}
function MsgBox(msg) {
    $('<div>' + msg + '</div>').dialog({
        autoOpen: true,
        resizable: false,
        height: 'auto',       
        width: 400,
        modal: true,
        show: {
            effect: "blind",
            duration: 500
        },
        hide: {
            effect: "explode",
            duration: 1000
        },
        close: function () {
            $(this).dialog('destroy');
        },
        title: 'WebPOS',
        buttons: {
            "OK": function () {
                $(this).dialog("close");
            }
        }
    });
  /*  return defer.promise();*/ //important to return the defer promise
}


function loaderopen()
{
    $('#jqxLoader').jqxLoader('open');
}
function loaderclose() {
    $('#jqxLoader').jqxLoader('close');
}
function arraygroupsum(arraylist,groupcolumn,sumcolumn)
{
    var result = [];
    arraylist.reduce(function(res, value) {
        if (!res[value[groupcolumn]]) {
            res[value[groupcolumn]] = { [groupcolumn]: value[groupcolumn], [sumcolumn]: 0 };
            result.push(res[value[groupcolumn]])
        }
        res[value[groupcolumn]][sumcolumn] += ValNum(value[sumcolumn]);
  return res;
    }, {});
    return result;
}

function arraygroupsumNew(arraylist, groupcolumn, sumcolumn, sumcolumn1, sumcolumn2) {
    var result = [];
    arraylist.reduce(function (res, value) {
        if (!res[value[groupcolumn]]) {
            res[value[groupcolumn]] = { [groupcolumn]: value[groupcolumn], [sumcolumn]: 0, [sumcolumn1]: 0, [sumcolumn2]: 0};
            result.push(res[value[groupcolumn]])
        }
        res[value[groupcolumn]][sumcolumn] += value[sumcolumn];
        res[value[groupcolumn]][sumcolumn1] += value[sumcolumn1];
        res[value[groupcolumn]][sumcolumn2] += value[sumcolumn2];
        return res;
    }, {});
    return result;
}

function CheckDuplicate(grid, columnname,Columnmsg) {
    var gridrows = $(grid).jqxGrid('getrows');
    var index = 0;
    var flag = true;
    var column = [];
    for (var i = 0; i < gridrows.length; i++) {
        column.push(gridrows[i][columnname]);
    }
    var item_list = column;
    var unique_list = [];
    var duplicate_list = [];

    function check_insert_unique(item) {
        if (unique_list.includes(item)) {
            MsgBox(Columnmsg + " " + item + " Already Exists !");
            $(grid).jqxGrid('selectcell', index, columnname);
            $(grid).jqxGrid('focus');
            flag = false;
        } else {
            if (unique_list.indexOf(item) == -1) {
                unique_list.push(item)
            }
        }
    }

    for (let i = 0; i < item_list.length; i++) {
        if (flag == true) {
            index = i;
            check_insert_unique(item_list[i]);
        }
        else
        {
            return false;
        }
    }
    if (flag == true) {
        return true;
    }
    else {
        return false;
    }
               
}

function NullToString(str) {
    return !str || 0 === str.length ? '' : str;
}
function GirdColumns(grid)
{
  var objlist = $(grid).jqxGrid('getrows');
    tempgridcolumns = Object.getOwnPropertyNames(objlist[0]);
    var index = tempgridcolumns.indexOf("boundindex");
    if (index > -1) {
        tempgridcolumns.splice(index, 1);
    }
    index = tempgridcolumns.indexOf("uid");
    if (index > -1) {
        tempgridcolumns.splice(index, 1);
    }
    index = tempgridcolumns.indexOf("uniqueid");
    if (index > -1) {
        tempgridcolumns.splice(index, 1);
    }
    index = tempgridcolumns.indexOf("visibleindex");
    if (index > -1) {
        tempgridcolumns.splice(index, 1);
    }
    index = tempgridcolumns.indexOf("EditMode");
    if (index > -1) {
        tempgridcolumns.splice(index, 1);
    }
    return tempgridcolumns;
}
function ValNum(value)
{
    if (value == null)
    {
        value = 0;
    }
    if (value == "") {
        value = 0;
    }
    if (isNaN(value) === true) {
        return 0;
    }
    else {
        return parseFloat(value);
    }
}

function ValNum1(value) {
    if (value == null) {
        return "";
    }
    if (value == 0) {
        return "";
    }
    if (value == "") {
        return "";
    }
    if (isNaN(value) === true) {
        return "";
    }
    else {
        return parseFloat(value).toFixed(2);
    }
}
function GirdFocusNextCell(grid, rowindex, columnindex, cloumnname, rowcount, AmountColumn, tempgirdfocuscolumns, widthcolumns) {

    var index = findcolumnindex(tempgirdfocuscolumns, cloumnname,"column");
                              if (tempgirdfocuscolumns.length - 1 == index)
                              {
                                  if(rowcount-1 == rowindex)
                                  {
                                      if (ValNum($(grid).jqxGrid('getcellvalue', rowindex, AmountColumn)) != 0) {

                                          addrow(grid);
                                          setTimeout(function () {
                                              $(grid).jqxGrid('endrowedit', rowindex, false); 
                                              if (tempgirdfocuscolumns[1].focus == 1) {
                                                  $(grid).jqxGrid('selectcell', rowcount, tempgirdfocuscolumns[1].column);
                                              }
                                              else {
                                                  $(grid).jqxGrid('selectcell', rowcount, tempgirdfocuscolumns[2].column);
                                              }
                                              $(grid).jqxGrid('focus');
                                          }, 50);
                                         

                                          return;
                                      }
                                      else
                                      {                                         
                                          MsgBox("Amount Column is Zero.Please Check It !!!.");
                                          return;
                                      }
                                  }
                                  else
                                  {
                                      setTimeout(function () {
                                          $(grid).jqxGrid('endrowedit', rowindex, false);
                                          $(grid).jqxGrid('selectcell', rowcount - 1, tempgirdfocuscolumns[1].column);
                                          $(grid).jqxGrid('focus');      
                                      },50);
                                                              
                                 
                                      return;
                                  }
                              }
                              else
                              {
                                  var c1 = index + 1;
                                  for (var i = c1; i <= tempgirdfocuscolumns.length; i++) {
                                      var focus = tempgirdfocuscolumns[c1].focus;
                                      var temp  = tempgirdfocuscolumns[c1].column;
                                      var flag = false;
                                      if (temp != null) {
                                          if (temp.endsWith("combo") == true) {
                                              c1 = c1 + 1;
                                              flag = true;
                                          }
                                      }
                                      if (flag == false) {
                                          if (tempgirdfocuscolumns.length - 1 == c1) {

                                              if (focus == 1) {
                                                  AutoScrollH(grid, widthcolumns, tempgirdfocuscolumns[c1].column);
                                                  $(grid).jqxGrid('selectcell', rowindex, tempgirdfocuscolumns[c1].column);
                                                  $(grid).jqxGrid('focus');
                                                  return;
                                              }
                                              else {
                                                  if (rowcount - 1 == rowindex) {
                                                      if (ValNum($(grid).jqxGrid('getcellvalue', rowindex, AmountColumn)) != 0) {
                                                          addrow(grid);
                                                          setTimeout(function () {
                                                              $(grid).jqxGrid('endrowedit', rowindex, false);
                                                              if (tempgirdfocuscolumns[1].focus == 1) {
                                                                  $(grid).jqxGrid('selectcell', rowcount, tempgirdfocuscolumns[1].column);
                                                              }
                                                              else {
                                                                  $(grid).jqxGrid('selectcell', rowcount, tempgirdfocuscolumns[2].column);
                                                              }                                                             
                                                              $(grid).jqxGrid('focus');
                                                          }, 50);
                                                         

                                                          return;
                                                      }
                                                      else {
                                                          MsgBox("Amount Column is Zero.Please Check It !!!.");
                                                          return;
                                                      }
                                                  }
                                                  else {
                                                      setTimeout(function () {
                                                          $(grid).jqxGrid('endrowedit', rowindex, false);
                                                          $(grid).jqxGrid('selectcell', rowcount - 1, tempgirdfocuscolumns[1].column);
                                                          $(grid).jqxGrid('focus');
                                                      }, 50);
                                               
                                                      return;
                                                  }
                                              }
                                          }
                                          else {
                                              if (focus == 0) {
                                                  c1 = c1 + 1;
                                              }
                                              else {
                                                  AutoScrollH(grid, widthcolumns, tempgirdfocuscolumns[c1].column);
                                                  $(grid).jqxGrid('selectcell', rowindex, tempgirdfocuscolumns[c1].column);
                                                  $(grid).jqxGrid('focus');
                                                  return;
                                              }
                                          }
                                      }
                                  }
                                 
                              }

}



function AutoScrollH(grid, widthcolumns, column)
{
    var widthnew = 0;
    if (widthcolumns.length != null) {
        if (widthcolumns.length != 0) {
            var index = findcolumnindex(widthcolumns, column, "datafield");
           
            if (index != null) {
                if (index != 0) {
                    index = index - 1;
                    for (var i = index; i > 0; i--) {
                        widthnew = widthnew + widthcolumns[i].width;
                    }
                    //   widthnew = widthnew;
                    var position = $(grid).jqxGrid('scrollposition');
                    var top = position.top;
                    setTimeout(function () { $(grid).jqxGrid('scrolloffset', top, widthnew); }, 10);
                }
            }

        }
    }
}



function percentage(value, per) {
    return Math.round(value * (per / 100));
}
function ZeroPad(num, places) {
  var zero = places - num.toString().length + 1;
  return Array(+(zero > 0 && zero)).join("0") + num;
}
function GirdNextCell(grid, rowindex, columnindex, cloumnname, widthcolumns, rowcount) {
   var tempgridcolumns = GirdColumns(grid);   
    columnindex = tempgridcolumns.indexOf(columnindex);
    if (columnindex == tempgridcolumns.length - 1) {
        if (rowindex == rowcount - 1) {
            if ($(grid).jqxGrid('getcellvalue', rowindex, cloumnname) != "") {
                addrow(grid);

            }
            else {
                return;
            }
        }

        $(grid).jqxGrid('selectcell', rowindex + 1, cloumnname);
        $(grid).jqxGrid('focus');
        return;
    }
    else {
        var c1 = columnindex + 1;
        for (var i = c1; i <= tempgridcolumns.length; i++) {
            var temp = tempgridcolumns[c1];
            var flag = false;
            if (temp != null)
            {
                if (temp.endsWith("combo") == true) {
                    c1 = c1 + 1;
                    flag = true;
                }
            }
            if (flag == false) {
                if (tempgridcolumns.length == c1) {
                    if (rowcount - 1 == rowindex) {
                        if ($(grid).jqxGrid('getcellvalue', rowindex, cloumnname) != "") {
                            addrow(grid);
                        }
                        else {
                            return;
                        }
                    }
                    $(grid).jqxGrid('selectcell', rowindex + 1, cloumnname);
                    $(grid).jqxGrid('focus');                   
                    return;
                }
                else if ($(grid).jqxGrid('iscolumnvisible', temp) == true) {
                    AutoScrollH(grid, widthcolumns, temp);
                    $(grid).jqxGrid('selectcell', rowindex, temp);
                    $(grid).jqxGrid('focus');               
                    return;
                }
                else {
                    c1 = c1 + 1;
                }
            }
            
        }
    }
}