| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632 | /** * 进度台账相关js * * @author Ellisran * @date 2020/11/6 * @version */function getTenderId() {    return window.location.pathname.split('/')[2];}$(function () {    autoFlashHeight();    if(schedule && !schedule.mode && !revising && !schedule.revising) {        $('#mode').modal('show');    }    // 初始化台账    const ledgerSpread = SpreadJsObj.createNewSpread($('#ledger-spread')[0]);    const treeSetting = {        id: 'ledger_id',        pid: 'ledger_pid',        order: 'order',        level: 'level',        rootId: -1,        fullPath: 'full_path',        calcFun: function (node) {            node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);            if (node.children && node.children.length > 0) {                for (const sm of scheduleMonth) {                    node[sm.yearmonth+'_gcl'] = ZhCalc.round(ZhCalc.div(node[sm.yearmonth+'_tp'], node.dgn_price), 3);                }            }        }        //treeCacheKey: 'ledger_bills_fold' + '_' + getTenderId(),        // markFoldKey: 'bills-fold',        // markFoldSubKey: window.location.pathname.split('/')[2],    };    const static_cols = [        {title: '编号', colSpan: '1', rowSpan: '2', field: 'code', hAlign: 0, width: 145, formatter: '@', readOnly: true, cellType: 'tree'},        {title: '名称', colSpan: '1', rowSpan: '2', field: 'name', hAlign: 0, width: 185, formatter: '@', readOnly: true},        {title: '单位', colSpan: '1', rowSpan: '2', field: 'unit', hAlign: 1, width: 50, formatter: '@', readOnly: true},        {title: '经济指标', colSpan: '1', rowSpan: '2', field: 'dgn_price', hAlign: 2, width: 60, type: 'Number', readOnly: true},        {title: '总设计|工程量', colSpan: '2|1', rowSpan: '1|1', field: 'dgn_qty1', hAlign: 2, width: 70, type: 'Number', readOnly: true},        {title: '|金额(元)', colSpan: '|1', rowSpan: '|1', field: 'total_price', hAlign: 2, width: 70, type: 'Number', readOnly: true},    ];    const ledgerSpreadSetting = {        emptyRows: 0,        headRows: 2,        headRowHeight: [25, 25],        defaultRowHeight: 21,        headerFont: '12px 微软雅黑',        font: '12px 微软雅黑',        // readOnly: true,        localCache: {            key: 'ledger-plan',            colWidth: true,        }    };    const monthsCols = [];    const calcCols = ['total_price'];    if(scheduleMonth.length > 0) {        for (const sm of scheduleMonth) {            const readOnly = sm.stage_gcl_used !== 0 || sm.stage_tp_used !== 0;            const yearmonth = sm.yearmonth.split('-')[0] + '年' + parseInt(sm.yearmonth.split('-')[1]) + '月';            const cols = {title: yearmonth + '|计划工程量', colSpan: '2|1', rowSpan: '1|1', field: sm.yearmonth+'_gcl', hAlign: 2, width: 90, type: 'Number', readOnly: readOnly ? readOnly : 'readOnly.gcl'};            const cols2 = {title: '|计划金额(元)', colSpan: '|1', rowSpan: '|1', field: sm.yearmonth+'_tp', hAlign: 2, width: 90, type: 'Number', readOnly: readOnly ? readOnly : 'readOnly.tp'};            monthsCols.push(cols);            monthsCols.push(cols2);            // calcCols.push(sm.yearmonth+'_gcl');            calcCols.push(sm.yearmonth+'_tp');        }    }    treeSetting.calcFields = calcCols;    const ledgerTree = createNewPathTree('filter', treeSetting);    const spreadHeaderCols = static_cols.concat(monthsCols);    ledgerSpreadSetting.cols = spreadHeaderCols;    const ledgerCol = {        readOnly: {            tp: function (data) {                let flag = data.is_leaf;                if (data.is_leaf) {                    flag = schedule && schedule.mode === mode.tp;                }                return !(flag && !revising);            },            gcl: function (data) {                let flag = data.is_leaf;                if (data.is_leaf) {                    flag = schedule && schedule.mode === mode.gcl;                }                return !(flag && !revising);            },        },    };    sjsSettingObj.setFxTreeStyle(ledgerSpreadSetting, sjsSettingObj.FxTreeStyle.jz);    if (thousandth) sjsSettingObj.setTpThousandthFormat(ledgerSpreadSetting);    SpreadJsObj.initSpreadSettingEvents(ledgerSpreadSetting, ledgerCol);    SpreadJsObj.initSheet(ledgerSpread.getActiveSheet(), ledgerSpreadSetting);    SpreadJsObj.selChangedRefreshBackColor(ledgerSpread.getActiveSheet());    ledgerSpread.getActiveSheet().frozenColumnCount(6);    ledgerSpread.getActiveSheet().options.frozenlineColor = '#93b5e4';    postData('/tender/' + getTenderId() + '/schedule/ledger/load', {}, function (data) {        // let treeData = [];        // for(const sl of selectedLedgerList) {        //     const one = _.find(data, { 'ledger_id' : sl });        //     treeData.push(one);        // }        // treeData = setLeafData(treeData);        // console.log(treeData);        // let treeData = data;        const calcList = ['total_price'];        const showList = ['ledger_id', 'ledger_pid', 'order', 'level', 'tender_id', 'full_path',            'code', 'name', 'unit', 'dgn_qty1', 'dgn_qty2', 'dgn_price', 'quantity', 'total_price'];        for (const m of monthList) {            showList.push(m + '_tp');            showList.push(m + '_gcl');            // calcList.push(m + '_tp');            // calcList.push(m + '_gcl');        }        const baseLedgerTree = createNewPathTree('base', {            id: 'ledger_id',            pid: 'ledger_pid',            order: 'order',            level: 'level',            rootId: -1,            fullPath: 'full_path',            calcFields: calcList,            calcFun: function (node) {                node.dgn_price = ZhCalc.round(ZhCalc.div(node.total_price, node.dgn_qty1), 2);            }        });        const newLedgerList = setMonthToLedger(data.bills, data.slm);        baseLedgerTree.loadDatas(newLedgerList);        treeCalc.calculateAll(baseLedgerTree);        for (const d of baseLedgerTree.nodes) {            if (!d.b_code) {                const one = _.find(selectedLedgerList, function (item) {                    return item === d.ledger_id;                });                if(one) {                    ledgerTree.addData(d, showList);                }            }        }        ledgerTree.sortTreeNode(true);        treeCalc.calculateAll(ledgerTree);        console.log(ledgerTree);        SpreadJsObj.loadSheetData(ledgerSpread.getActiveSheet(), SpreadJsObj.DataType.Tree, ledgerTree);    }, null, true);    const ledgerSpreadObj = {        refreshTree: function (sheet, data) {            SpreadJsObj.massOperationSheet(sheet, function () {                const tree = sheet.zh_tree;                // 处理删除                if (data.delete) {                    data.delete.sort(function (x, y) {                        return y.deleteIndex - x.deleteIndex;                    });                    for (const d of data.delete) {                        sheet.deleteRows(d.deleteIndex, 1);                    }                }                // 处理新增                if (data.create) {                    const newNodes = data.create;                    if (newNodes) {                        newNodes.sort(function (a, b) {                            return a.index - b.index;                        });                        for (const node of newNodes) {                            sheet.addRows(node.index, 1);                            SpreadJsObj.reLoadRowData(sheet, tree.nodes.indexOf(node), 1);                        }                    }                }                // 处理更新                if (data.update) {                    const rows = [];                    for (const u of data.update) {                        rows.push(tree.nodes.indexOf(u));                    }                    SpreadJsObj.reLoadRowsData(sheet, rows);                }                // 处理展开                if (data.expand) {                    const expanded = [];                    for (const e of data.expand) {                        if (expanded.indexOf(e) === -1) {                            const posterity = tree.getPosterity(e);                            for (const p of posterity) {                                sheet.setRowVisible(tree.nodes.indexOf(p), p.visible);                                expanded.push(p);                            }                        }                    }                }            });        },        editEnded: function (e, info) {            if (info.sheet.zh_setting) {                const select = SpreadJsObj.getSelectObject(info.sheet);                const col = info.sheet.zh_setting.cols[info.col];                let validText = is_numeric(info.editingText) ? parseFloat(info.editingText) : (info.editingText ? trimInvalidChar(info.editingText) : null);                const orgValue = select[col.field];                if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {                    SpreadJsObj.reLoadRowData(info.sheet, info.row);                    return;                }                if (isNaN(validText)) {                    toastr.error('不能输入其它非数字类型字符');                    SpreadJsObj.reLoadRowData(info.sheet, info.row);                    return;                }                const yearmonth = col.field.split('_')[0];                const mode = col.field.split('_')[1];                let plan_gcl = 0;                let plan_tp = 0;                // 判断输入位数,提示                if (mode === 'tp') {                    const reg = new RegExp('^([-]?)\\d+$');                    if (validText !== null && (!reg.test(validText))) {                        // toastr.error('输入金额请为整数');                        // SpreadJsObj.reLoadRowData(info.sheet, info.row);                        // return;                        validText = ZhCalc.round(validText, 0);                    }                    plan_gcl = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, select.dgn_price), 3) : 0;                    plan_tp = validText;                } else {                    const reg = new RegExp('^([-]?)\\d+$');                    if (validText !== null && (!reg.test(validText))) {                        // toastr.error('输入工程量小数位数不能大于3位');                        // SpreadJsObj.reLoadRowData(info.sheet, info.row);                        // return;                        validText = ZhCalc.round(validText, 3);                    }                    plan_gcl = validText;                    plan_tp = select.dgn_price && select.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, select.dgn_price), 0) : 0;                }                select[col.field] = validText;                const updateData = {                    lid: select.ledger_id,                    yearmonth,                    plan_gcl,                    plan_tp,                };                postData(window.location.pathname + '/save', {type: 'ledger_edit', postData: updateData}, function (result) {                    if (mode === 'tp') {                        select[yearmonth + '_gcl'] = plan_gcl;                    } else {                        select[yearmonth + '_tp'] = plan_tp;                    }                    const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select, 1);                    console.log(nodes, select);                    const refreshNode = ledgerTree.loadPostData({update: nodes});                    console.log(refreshNode);                    ledgerSpreadObj.refreshTree(info.sheet, refreshNode);                },function () {                    select[col.field] = orgValue;                    const nodes = treeCalc.calculateParent(info.sheet.zh_tree, select, 1);                    const refreshNode = ledgerTree.loadPostData({update: nodes});                    ledgerSpreadObj.refreshTree(info.sheet, refreshNode);                })            }        },        deletePress: function (sheet) {            if (!sheet.zh_setting) return;            if (sheet.zh_setting && sheet.zh_tree) {                const sel = sheet.getSelections()[0], datas = [], filterNodes = [];                if (!sel) return;                for (let iRow = sel.row; iRow < sel.row + sel.rowCount; iRow++) {                    let bDel = false;                    const node = sheet.zh_tree.nodes[iRow];                    for (let iCol = sel.col; iCol < sel.col + sel.colCount; iCol++) {                        const col = sheet.zh_setting.cols[iCol];                        const orgValue = node[col.field];                        if (!orgValue) {                            continue;                        }                        const yearmonth = col.field.split('_')[0];                        const modes = col.field.split('_')[1];                        if(col.readOnly === true || !node.is_leaf || mode[modes] !== schedule.mode) {                            continue;                        }                        const updateData = {                            lid: node.ledger_id,                            yearmonth,                            plan_gcl: null,                            plan_tp: null,                        };                        datas.push(updateData);                        node[yearmonth+'_gcl'] = null;                        node[yearmonth+'_tp'] = null;                        bDel = true;                    }                    if (bDel) filterNodes.push(node);                }                if (datas.length > 0) {                    postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {                        for (const uul of filterNodes) {                            const nodes = treeCalc.calculateParent(sheet.zh_tree, uul, 1);                            const refreshNode = ledgerTree.loadPostData({update: nodes});                            ledgerSpreadObj.refreshTree(sheet, refreshNode);                        }                        SpreadJsObj.reLoadSheetData(sheet);                    }, function () {                        SpreadJsObj.reLoadSheetData(sheet);                    });                }            }        },        clipboardPasted(e, info) {            const hint = {                cellError: {type: 'error', msg: '粘贴内容超出了表格范围'},                numberExpr: {type: 'error', msg: '不能粘贴其它非数字类型字符'},            };            const tree = info.sheet.zh_tree;            if (!tree) { return; }            const sortData = info.sheet.zh_tree.nodes;            const datas = [], filterNodes = [];            for (let iRow = 0; iRow < info.cellRange.rowCount; iRow ++) {                let bPaste = false;                const curRow = info.cellRange.row + iRow;                const node = sortData[curRow];                if (node) {                    for (let iCol = 0; iCol < info.cellRange.colCount; iCol++) {                        const curCol = info.cellRange.col + iCol;                        const colSetting = info.sheet.zh_setting.cols[curCol];                        let validText = is_numeric(info.sheet.getText(curRow, curCol)) ? parseFloat(info.sheet.getText(curRow, curCol)) : (info.sheet.getText(curRow, curCol) ? trimInvalidChar(info.sheet.getText(curRow, curCol)) : null);                        const orgValue = node[colSetting.field];                        if (orgValue == validText || ((!orgValue || orgValue === '') && (validText === ''))) {                            continue;                        }                        if (isNaN(validText)) {                            toastMessageUniq(hint.numberExpr);                            continue;                        }                        const yearmonth = colSetting.field.split('_')[0];                        const mode = colSetting.field.split('_')[1];                        let plan_gcl = 0;                        let plan_tp = 0;                        // 判断输入位数,提示                        if (mode === 'tp') {                            const reg = new RegExp('^([-]?)\\d+$');                            if (validText !== null && (!reg.test(validText))) {                                validText = ZhCalc.round(validText, 0);                            }                            plan_gcl = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(validText, node.dgn_price), 3) : 0;                            plan_tp = validText;                        } else {                            const reg = new RegExp('^([-]?)\\d+$');                            if (validText !== null && (!reg.test(validText))) {                                validText = ZhCalc.round(validText, 3);                            }                            plan_gcl = validText;                            plan_tp = node.dgn_price && node.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(validText, node.dgn_price), 0) : 0;                        }                        const updateData = {                            lid: node.ledger_id,                            yearmonth,                            plan_gcl,                            plan_tp,                        };                        datas.push(updateData);                        node[yearmonth+'_gcl'] = plan_gcl;                        node[yearmonth+'_tp'] = plan_tp;                        bPaste = true;                    }                    if (bPaste) {                        filterNodes.push(node);                    }                }            }            if (datas.length > 0) {                postData(window.location.pathname + '/save', {type: 'ledger_paste', postData: datas}, function (result) {                    for (const uul of filterNodes) {                        const nodes = treeCalc.calculateParent(info.sheet.zh_tree, uul, 1);                        const refreshNode = ledgerTree.loadPostData({update: nodes});                        ledgerSpreadObj.refreshTree(info.sheet, refreshNode);                    }                    SpreadJsObj.reLoadSheetData(info.sheet);                }, function () {                    SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);                });            } else {                SpreadJsObj.reLoadRowData(info.sheet, info.cellRange.row, info.cellRange.rowCount);            }        },    };    ledgerSpread.bind(spreadNS.Events.EditEnded, ledgerSpreadObj.editEnded);    SpreadJsObj.addDeleteBind(ledgerSpread, ledgerSpreadObj.deletePress);    ledgerSpread.bind(spreadNS.Events.ClipboardPasted, ledgerSpreadObj.clipboardPasted);    // 进度计算方式选择    $('.mode-select').on('click', function () {        const _self = $(this);        const this_mode = _self.data('mode');        // 重新计算所有未使用的月份数据        const under_ledger = _.filter(ledgerTree.nodes, { is_leaf: true});        const update_nodes = [];        const newMonthList = _.map(_.filter(scheduleMonth, function (item) {            return item.stage_gcl_used === 0 && item.stage_tp_used === 0;        }), 'yearmonth');        for (const ul of under_ledger) {            for (const m of newMonthList) {                if (ul[m+'_tp'] || ul[m+'_gcl']) {                    update_nodes.push(ul);                    break;                }            }        }        const update_under_ledger = [];        if(update_nodes.length > 0) {            for (const un of update_nodes) {                if (this_mode === mode.gcl) {                    for (const m of newMonthList) {                        if(un[m+'_tp']) {                            un[m+'_tp'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.mul(un[m+'_gcl'], un.dgn_price), 0) : 0;                            update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});                        }                    }                } else {                    for (const m of newMonthList) {                        if(un[m+'_gcl']) {                            un[m+'_gcl'] = un.dgn_price && un.dgn_price !== 0 ? ZhCalc.round(ZhCalc.div(un[m+'_tp'], un.dgn_price), 3) : 0;                            update_under_ledger.push({lid: un.ledger_id, yearmonth: m, plan_tp: un[m+'_tp'], plan_gcl: un[m+'_gcl']});                        }                    }                }            }        }        postData(window.location.pathname + '/save', {type: 'mode', postData: {mode: this_mode, update_under_ledger}}, function (result) {            _self.addClass('disabled').attr('disabled', true);            _self.text('当前');            _self.parents('.col-6').siblings('.col-6').find('button').removeClass('disabled').removeAttr('disabled');            _self.parents('.col-6').siblings('.col-6').find('button').text('选择');            $('#mode-tips').show();            $('#mode-cancel').show();            $('#mode').modal('hide');            schedule.mode = this_mode;            if (update_nodes.length > 0) {                for (const uul of update_nodes) {                    const nodes = treeCalc.calculateParent(ledgerSpread.getActiveSheet().zh_tree, uul, 1);                    const refreshNode = ledgerTree.loadPostData({update: nodes});                    ledgerSpreadObj.refreshTree(ledgerSpread.getActiveSheet(), refreshNode);                }            }            SpreadJsObj.reLoadSheetData(ledgerSpread.getActiveSheet());        })    });    // 月份添加    $('#add-month').click(function () {        const range = $('#month-range').val();        if(range === '') {            toastr.error('请选择计划周期时间');            return;        }        const addMonthList = [];        const cycle = range.split(' ~ ');        if(cycle.length === 1) {            addMonthList.push(cycle[0]);        } else {            // 多个月份            const back_year = parseInt(cycle[1].split('-')[0]);            const back_month = parseInt(cycle[1].split('-')[1]);            const front_year = parseInt(cycle[0].split('-')[0]);            const front_month = parseInt(cycle[0].split('-')[1]);            if(back_year > front_year) {                const num = getDistanceMonth(cycle[0], cycle[1]);                let j = 1;                for (let i = 0; i <= num; i++) {                    if(front_month + i > 12*j) {                        j = j + 1;                    }                    const m = (front_month + i)%12 === 0 ? 12 : (front_month + i)%12;                    addMonthList.push((front_year + (j-1)) + '-' + (m < 10 ? '0' + m : m));                }            } else if (back_year === front_year) {                // 小于1年并没有跨年                for (let i = front_month; i <= back_month; i++) {                    addMonthList.push(back_year + '-' + (i < 10 ? '0' + i : i));                }            }        }        // 判断是否已添加本月份        if (addMonthList.length > 0) {            const hadmonth = [];            for (const m of addMonthList) {                const one = _.find(scheduleMonth, { yearmonth: m });                if (one) {                    hadmonth.push(m);                }            }            if (hadmonth.length > 0) {                let html = '';                for (const hm of hadmonth) {                    html += `<div class="alert alert-danger">${hm} 已创建</div>`;                }                $('#add-month-error-list').html(html);                $('#add-month-error-list').show();                return;            }        } else {            toastr.error('请选择计划周期时间');            return;        }        $('#add-month-error-list').html('');        $('#add-month-error-list').hide();        const _self = $(this);        postData(window.location.pathname + '/save', {type: 'addmonth', postData: addMonthList}, function (result) {            _self.addClass('disabled').attr('disabled', true);            toastr.success('新增成功');            setTimeout(function () {                window.location.reload();            }, 500)        })    });    $('#month-table input[type="checkbox"]').click(function () {        const selectedMonth = [];        $('#month-table input:checkbox:checked').each(function () {            selectedMonth.push('「' + $(this).parents('td').siblings('td').text() + '」');        });        if(selectedMonth.length > 0) {            $('#del-month-list').text(selectedMonth.join(''));            $('#del-month-list').parent().show();            $('#del-month').removeAttr('disabled');        } else {            $('#del-month-list').parent().hide();            $('#del-month').attr('disabled', true);        }    });    $('#del-month').click(function () {        const selectedMonth = [];        $('#month-table input:checkbox:checked').each(function () {            selectedMonth.push($(this).parents('td').siblings().text());        });        if (selectedMonth.length === 0) {            toastr.error('请选择删除的计划周期');            return;        }        const _self = $(this);        postData(window.location.pathname + '/save', {type: 'delmonth', postData: selectedMonth}, function (result) {            _self.addClass('disabled').attr('disabled', true);            toastr.success('删除成功');            setTimeout(function () {                window.location.reload();            }, 500)        })    });    $.subMenu({        menu: '#sub-menu', miniMenu: '#sub-mini-menu', miniMenuList: '#mini-menu-list',        toMenu: '#to-menu', toMiniMenu: '#to-mini-menu',        key: 'menu.1.0.0',        miniHint: '#sub-mini-hint', hintKey: 'menu.hint.1.0.1',        callback: function (info) {            if (info.mini) {                $('.panel-title').addClass('fluid');                $('#sub-menu').removeClass('panel-sidebar');            } else {                $('.panel-title').removeClass('fluid');                $('#sub-menu').addClass('panel-sidebar');            }            ledgerSpread.refresh();            autoFlashHeight();        }    });});// 月份间隔function getDistanceMonth(startTime,endTime){    startTime = new Date(startTime);    endTime = new Date(endTime);    var dateToMonth = 0;    var startDate=startTime.getDate() + startTime.getHours()/24 + startTime.getMinutes()/24/60;    var endDate=endTime.getDate()  +endTime.getHours()/24 + endTime.getMinutes()/24/60;    if(endDate >= startDate){        dateToMonth = 0;    }else{        dateToMonth = -1;    }    let yearToMonth = (endTime.getYear() - startTime.getYear()) * 12;    let monthToMonth = endTime.getMonth() - startTime.getMonth();    return yearToMonth + monthToMonth + dateToMonth;}function setLeafData(tree) {    const newtree = [];    for (const t of tree) {        const child = _.find(tree, { 'ledger_pid': t.ledger_id });        if (!child && !t.is_leaf) {            t.is_leaf = true;        }        newtree.push(t);    }    return newtree;}function setMonthToLedger(ledgerList, slm) {    if (slm.length > 0) {        for(const s of slm) {            const index = _.findIndex(ledgerList, { 'ledger_id': s.lid });            if (index && index !== -1) {                ledgerList[index][s.yearmonth + '_tp'] = s.plan_tp;                ledgerList[index][s.yearmonth + '_gcl'] = s.plan_gcl;            }        }    }    return ledgerList;}const is_numeric = (value) => {    if (typeof(value) === 'object') {        return false;    } else {        return !Number.isNaN(Number(value)) && value.toString().trim() !== '';    }};
 |