javascript NSOA:计算项目预算法案费率

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript NSOA:计算项目预算法案费率相关的知识,希望对你有一定的参考价值。

/**
 * Main entrance function (afterSave)
 */
function main(type) {
    var DECIMALS = 2;
    var FLD_RATE = 'budget_rate__c';

    var needsUpdate = false;
    var newRec = NSOA.form.getNewRecord();
    
    if (type == "create") {
        needsUpdate = true;
    } else if (type == "edit") {
        var oldRec = NSOA.form.getOldRecord();
        if (oldRec.budget_time !== newRec.budget_time || oldRec.budget !== newRec.budget) {
            needsUpdate = true;
        }
    }
    
    if (!needsUpdate || needsUpdate === false) {
        return;
    }

    var budget = parseFloat(newRec.budget) || 0.00;
    var time = parseFloat(newRec.budget_time) || 0.00;
    
    if (!budget || budget === 0 || budget === 0.00) {
        return;
    }

    if (!time || time === 0 || time === 0.00) {
        return;
    }

    var rate = round(budget / time, DECIMALS);
    var prjRec = new NSOA.record.oaProject();
    prjRec.id = newRec.id;
    prjRec[FLD_RATE] = rate;

    NSOA.wsapi.disableFilterSet(true);
    var attr = {name: "update_custom", value: "1"};
    var results = NSOA.wsapi.modify([attr], [prjRec]);
}

/**
 * Round a number based on decimal points
 */
function round(number, decimals) {
    number = parseFloat(number);
    decimals = parseInt(decimals) || DECIMALS;

    if (isNaN(number) || isNaN(decimals)) {
        return number;
    }
    return (Math.round(number * Math.pow(10, 2)) / Math.pow(10, 2)).toFixed(decimals);
}

以上是关于javascript NSOA:计算项目预算法案费率的主要内容,如果未能解决你的问题,请参考以下文章

xml NSOA:默认高级映射06232014

json NSOA:蜂窝服务领先

全面预算管理

爱因斯坦计划最新进展(201705)

企业IT成本预算

2019年一级建造师《工程项目管理》高频考点:索赔费用和工期索赔计算