function calculateFinal() {

    $("input[name='incomeDeviceFinalTotal']").change(function () {
        calIncomeFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("incomeDeviceFinalTotal", "input[name='incomeDeviceFinalTotal']");
    });
    $("input[name='incomeEngineerFinalTotal']").change(function () {
        calIncomeFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("incomeEngineerFinalTotal", "input[name='incomeEngineerFinalTotal']");
    });
    $("input[name='incomeServiceFinalTotal']").change(function () {
        calIncomeFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("incomeServiceFinalTotal", "input[name='incomeServiceFinalTotal']");
    });


    $("input[name='costPurchaseDeviceFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costPurchaseDeviceFinalTotal", "input[name='costPurchaseDeviceFinalTotal']");
    });
    $("input[name='costPurchaseBuildFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costPurchaseBuildFinalTotal", "input[name='costPurchaseBuildFinalTotal']");
    });
    $("input[name='costPurchaseServiceFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costPurchaseServiceFinalTotal", "input[name='costPurchaseServiceFinalTotal']");
    });
    $("input[name='costPurchaseOtherFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costPurchaseOtherFinalTotal", "input[name='costPurchaseOtherFinalTotal']");
    });
    $("input[name='costProjectManageFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costProjectManageFinalTotal", "input[name='costProjectManageFinalTotal']");
    });
    $("input[name='costOtherFinalTotal']").change(function () {
        calCostFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costOtherFinalTotal", "input[name='costOtherFinalTotal']");
    });


    $("input[name='costExpropriationFinalTotal']").change(function () {
        calManageFinalTotal();
        calGrossProfitFinalTotal();
        calGrossProfitProfitMargin();
        digitalSelf("costExpropriationFinalTotal", "input[name='costExpropriationFinalTotal']");
    });
    $("input[name='costCompanyManageFinalTotal']").change(function () {
        calManageFinalTotal();
        calContributionMarginFinalTotal();
        calContributionMarginProfitMargin();
        digitalSelf("costCompanyManageFinalTotal", "input[name='costCompanyManageFinalTotal']");
    });
    $("input[name='costIncomeTaxFinalTotal']").change(function () {
        calManageFinalTotal();
        calNetMarginFinalTotal();
        calNetMarginProfitMargin();
        digitalSelf("costIncomeTaxFinalTotal", "input[name='costIncomeTaxFinalTotal']");
    });

    //现金流量表
    $("input[name='saleIncomeCash']").change(function () {
        //calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("saleIncomeCash", "input[name='saleIncomeCash']");
    });
    $("input[name='taxReturn']").change(function () {
        //calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("taxReturn", "input[name='taxReturn']");
    });
    $("input[name='earnestMoneyIncome']").change(function () {
        //calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("earnestMoneyIncome", "input[name='earnestMoneyIncome']");
    });
    $("input[name='purchaseCost']").change(function () {
        calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("purchaseCost", "input[name='purchaseCost']");
    });
    $("input[name='taxCost']").change(function () {
        // calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("taxCost", "input[name='taxCost']");
    });
    $("input[name='earnestMoneyCost']").change(function () {
        //calCashFluxFinalTotal();
        calNetCashFlow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("earnestMoneyCost", "input[name='earnestMoneyCost']");
    });
    $("input[name='netCashFlow']").change(function () {
        // calCashFluxFinalTotal();
    });
    $("input[name='cashInflowFromInvestingActivities']").change(function () {
        // calCashFluxFinalTotal();
        calNetCashFromInvestingActivities();
        calNetIncreaseMonetaryFunds();
        digitalSelf("cashInflowFromInvestingActivities", "input[name='cashInflowFromInvestingActivities']");
    });
    $("input[name='cashOutflowFromInvestingActivities']").change(function () {
        //calCashFluxFinalTotal();
        calNetCashFromInvestingActivities();
        calNetIncreaseMonetaryFunds();
        digitalSelf("cashOutflowFromInvestingActivities", "input[name='cashOutflowFromInvestingActivities']");
    });
    $("input[name='netCashFromInvestingActivities']").change(function () {
        // calCashFluxFinalTotal();
    });
    $("input[name='financingCapitalInflow']").change(function () {
        //calCashFluxFinalTotal();
        calFinancingCapitalCashflow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("financingCapitalInflow", "input[name='financingCapitalInflow']");
    });
    $("input[name='financingCapitalOutflow']").change(function () {
        //calCashFluxFinalTotal();
        calFinancingCapitalCashflow();
        calNetIncreaseMonetaryFunds();
        digitalSelf("financingCapitalOutflow", "input[name='financingCapitalOutflow']");
    });
    $("input[name='financingCapitalCashflow']").change(function () {
        //calCashFluxFinalTotal();
    });
    $("input[name='netIncreaseMonetaryFunds']").change(function () {
        //calCashFluxFinalTotal();
    });


}

/**
 * 经营活动产生的现金流量净额
 */
function calNetCashFlow() {

    var saleIncomeCash = $("input[name='saleIncomeCash']").val();
    var taxReturn = $("input[name='taxReturn']").val();
    var earnestMoneyIncome = $("input[name='earnestMoneyIncome']").val();
    var purchaseCost = $("input[name='purchaseCost']").val();
    var taxCost = $("input[name='taxCost']").val();
    var earnestMoneyCost = $("input[name='earnestMoneyCost']").val();

    var netCashFlow = $("input[name='netCashFlow']");

    if (saleIncomeCash && taxReturn && earnestMoneyIncome
        && purchaseCost && taxCost && earnestMoneyCost) {
        netCashFlow.val(f2Fixed(f2(saleIncomeCash) + f2(taxReturn) + f2(earnestMoneyIncome)
            - f2(purchaseCost) - f2(taxCost) - f2(earnestMoneyCost)));
    } else {
        netCashFlow.val("");
    }
}

/**
 * 投资活动产生的现金流量净额
 */
function calNetCashFromInvestingActivities() {
    var cashInflowFromInvestingActivities = $("input[name='cashInflowFromInvestingActivities']").val();
    var cashOutflowFromInvestingActivities = $("input[name='cashOutflowFromInvestingActivities']").val();

    var netCashFromInvestingActivities = $("input[name='netCashFromInvestingActivities']");

    if (cashInflowFromInvestingActivities && cashOutflowFromInvestingActivities) {
        netCashFromInvestingActivities.val(f2Fixed(f2(cashInflowFromInvestingActivities) - f2(cashOutflowFromInvestingActivities)));
    } else {
        netCashFromInvestingActivities.val("");
    }
}

/**
 * 筹资活动产生的现金流量净额
 */
function calFinancingCapitalCashflow() {
    var financingCapitalInflow = $("input[name='financingCapitalInflow']").val();
    var financingCapitalOutflow = $("input[name='financingCapitalOutflow']").val();

    var financingCapitalCashflow = $("input[name='financingCapitalCashflow']");

    if (financingCapitalInflow && financingCapitalOutflow) {
        financingCapitalCashflow.val(f2Fixed(f2(financingCapitalInflow) - f2(financingCapitalOutflow)));
    } else {
        financingCapitalCashflow.val("");
    }
}

function calNetIncreaseMonetaryFunds() {
    var netCashFlow = $("input[name='netCashFlow']").val();
    var netCashFromInvestingActivities = $("input[name='netCashFromInvestingActivities']").val();
    var financingCapitalCashflow = $("input[name='financingCapitalCashflow']").val();

    var netIncreaseMonetaryFunds = $("input[name='netIncreaseMonetaryFunds']");

    if (netCashFlow && netCashFromInvestingActivities && financingCapitalCashflow) {
        netIncreaseMonetaryFunds.val(f2Fixed(f2(netCashFlow) + f2(netCashFromInvestingActivities) + f2(financingCapitalCashflow)));
    } else {
        netIncreaseMonetaryFunds.val("");
    }
}

/**
 * 收入决算总额(不含税)，有一项没填就置空
 */
function calIncomeFinalTotal() {
    var incomeDeviceFinalTotal = $("input[name='incomeDeviceFinalTotal']").val();
    var incomeEngineerFinalTotal = $("input[name='incomeEngineerFinalTotal']").val();
    var incomeServiceFinalTotal = $("input[name='incomeServiceFinalTotal']").val();

    var incomeFinalTotal = $("input[name='incomeFinalTotal']");

    if (incomeDeviceFinalTotal && incomeEngineerFinalTotal && incomeServiceFinalTotal) {
        incomeFinalTotal.val(f2Fixed(f2(incomeDeviceFinalTotal) + f2(incomeEngineerFinalTotal) + f2(incomeServiceFinalTotal)));
    } else {
        incomeFinalTotal.val("");
    }
}

/**
 * 成本决算总额(不含税)，有一项没填就置空
 */
function calCostFinalTotal() {
    var costPurchaseDeviceFinalTotal = $("input[name='costPurchaseDeviceFinalTotal']").val();
    var costPurchaseBuildFinalTotal = $("input[name='costPurchaseBuildFinalTotal']").val();
    var costPurchaseServiceFinalTotal = $("input[name='costPurchaseServiceFinalTotal']").val();
    var costPurchaseOtherFinalTotal = $("input[name='costPurchaseOtherFinalTotal']").val();
    var costProjectManageFinalTotal = $("input[name='costProjectManageFinalTotal']").val();
    var costOtherFinalTotal = $("input[name='costOtherFinalTotal']").val();

    var costFinalTotal = $("input[name='costFinalTotal']");

    if (costPurchaseDeviceFinalTotal && costPurchaseBuildFinalTotal && costPurchaseServiceFinalTotal &&
        costPurchaseOtherFinalTotal && costProjectManageFinalTotal) {
        costFinalTotal.val(f2Fixed(f2(costPurchaseDeviceFinalTotal) + f2(costPurchaseBuildFinalTotal) + f2(costPurchaseServiceFinalTotal) +
            f2(costPurchaseOtherFinalTotal) + f2(costProjectManageFinalTotal) + f2(costOtherFinalTotal)));
    } else {
        costFinalTotal.val("");
    }
}


/**
 * 管理成本总额(不含税)，有一项没填就置空
 */
function calManageFinalTotal() {
    var costExpropriationFinalTotal = $("input[name='costExpropriationFinalTotal']").val();
    var costCompanyManageFinalTotal = $("input[name='costCompanyManageFinalTotal']").val();
    var costIncomeTaxFinalTotal = $("input[name='costIncomeTaxFinalTotal']").val();

    var manageFinalTotal = $("input[name='manageFinalTotal']");

    if (costExpropriationFinalTotal && costCompanyManageFinalTotal && costIncomeTaxFinalTotal) {
        manageFinalTotal.val(f2Fixed(f2(costExpropriationFinalTotal) + f2(costCompanyManageFinalTotal) + f2(costIncomeTaxFinalTotal)));
    } else {
        manageFinalTotal.val("");
    }
}

/**
 * 现金流量表总额(不含税)，有一项没填就置空
 */
function calCashFluxFinalTotal() {
    var saleIncomeCash = $("input[name='saleIncomeCash']").val();
    var taxReturn = $("input[name='taxReturn']").val();
    var earnestMoneyIncome = $("input[name='earnestMoneyIncome']").val();
    var purchaseCost = $("input[name='purchaseCost']").val();
    var taxCost = $("input[name='taxCost']").val();
    var earnestMoneyCost = $("input[name='earnestMoneyCost']").val();
    var netCashFlow = $("input[name='netCashFlow']").val();
    var cashInflowFromInvestingActivities = $("input[name='cashInflowFromInvestingActivities']").val();
    var cashOutflowFromInvestingActivities = $("input[name='cashOutflowFromInvestingActivities']").val();
    var netCashFromInvestingActivities = $("input[name='netCashFromInvestingActivities']").val();
    var financingCapitalInflow = $("input[name='financingCapitalInflow']").val();
    var financingCapitalOutflow = $("input[name='financingCapitalOutflow']").val();
    var financingCapitalCashflow = $("input[name='financingCapitalCashflow']").val();
    var netIncreaseMonetaryFunds = $("input[name='netIncreaseMonetaryFunds']").val();

    var cashFluxFinalTotal = $("input[name='cashFluxFinalTotal']");

    if (saleIncomeCash && taxReturn && earnestMoneyIncome &&
        purchaseCost && taxCost && earnestMoneyCost &&
        netCashFlow && cashInflowFromInvestingActivities && cashOutflowFromInvestingActivities &&
        netCashFromInvestingActivities && financingCapitalInflow && financingCapitalOutflow
        && financingCapitalCashflow && netIncreaseMonetaryFunds) {
        cashFluxFinalTotal.val(f2Fixed(f2(saleIncomeCash) + f2(taxReturn) + f2(earnestMoneyIncome) +
            f2(purchaseCost) + f2(taxCost) + f2(earnestMoneyCost) +
            f2(netCashFlow) + f2(cashInflowFromInvestingActivities) + f2(cashOutflowFromInvestingActivities) +
            f2(netCashFromInvestingActivities) + f2(financingCapitalInflow) + f2(financingCapitalOutflow) +
            f2(financingCapitalCashflow) + f2(netIncreaseMonetaryFunds)));
    } else {
        cashFluxFinalTotal.val("");
    }
}

/**
 * 项目毛利决算总额
 */
function calGrossProfitFinalTotal() {
    var incomeFinalTotal = $("input[name='incomeFinalTotal']").val();
    var costFinalTotal = $("input[name='costFinalTotal']").val();
    var costExpropriationFinalTotal = $("input[name='costExpropriationFinalTotal']").val();

    var grossProfitFinalTotal = $("input[name='grossProfitFinalTotal']");

    if (incomeFinalTotal && costFinalTotal && costExpropriationFinalTotal) {
        grossProfitFinalTotal.val(f2Fixed(f2(incomeFinalTotal) - f2(costFinalTotal) - f2(costExpropriationFinalTotal)));
    } else {
        grossProfitFinalTotal.val("");
    }
}

/**
 * 项目毛利利润率
 */
function calGrossProfitProfitMargin() {
    var grossProfitFinalTotal = $("input[name='grossProfitFinalTotal']").val();
    var incomeFinalTotal = $("input[name='incomeFinalTotal']").val();

    var grossProfitProfitMargin = $("input[name='grossProfitProfitMargin']");
    if (grossProfitFinalTotal && incomeFinalTotal) {
        grossProfitProfitMargin.val(f2Fixed(100 * f2(grossProfitFinalTotal) / f2min(incomeFinalTotal)));
    } else {
        grossProfitProfitMargin.val("");
    }
}


/**
 * 项目贡献利润决算总额
 */
function calContributionMarginFinalTotal() {
    var grossProfitFinalTotal = $("input[name='grossProfitFinalTotal']").val();
    var costCompanyManageFinalTotal = $("input[name='costCompanyManageFinalTotal']").val();

    var contributionMarginFinalTotal = $("input[name='contributionMarginFinalTotal']");

    if (grossProfitFinalTotal && costCompanyManageFinalTotal) {
        contributionMarginFinalTotal.val(f2Fixed(f2(grossProfitFinalTotal) - f2(costCompanyManageFinalTotal)));
    } else {
        contributionMarginFinalTotal.val("");
    }
}

/**
 * 项目贡献利润利润率
 */
function calContributionMarginProfitMargin() {
    var contributionMarginFinalTotal = $("input[name='contributionMarginFinalTotal']").val();
    var incomeFinalTotal = $("input[name='incomeFinalTotal']").val();

    var contributionMarginProfitMargin = $("input[name='contributionMarginProfitMargin']");
    if (contributionMarginFinalTotal && incomeFinalTotal) {
        contributionMarginProfitMargin.val(f2Fixed(100 * f2(contributionMarginFinalTotal) / f2min(incomeFinalTotal)));
    } else {
        contributionMarginProfitMargin.val("");
    }
}

/**
 * 项目净利润决算总额
 */
function calNetMarginFinalTotal() {
    var contributionMarginFinalTotal = $("input[name='contributionMarginFinalTotal']").val();
    var costIncomeTaxFinalTotal = $("input[name='costIncomeTaxFinalTotal']").val();


    var netMarginFinalTotal = $("input[name='netMarginFinalTotal']");

    if (contributionMarginFinalTotal && costIncomeTaxFinalTotal) {
        netMarginFinalTotal.val(f2Fixed(f2(contributionMarginFinalTotal) - f2(costIncomeTaxFinalTotal)));
    } else {
        netMarginFinalTotal.val("");
    }
}

/**
 * 项目净利润利润率
 */
function calNetMarginProfitMargin() {
    var netMarginFinalTotal = $("input[name='netMarginFinalTotal']").val();
    var incomeFinalTotal = $("input[name='incomeFinalTotal']").val();

    var netMarginProfitMargin = $("input[name='netMarginProfitMargin']");
    if (netMarginFinalTotal && incomeFinalTotal) {
        netMarginProfitMargin.val(f2Fixed(100 * f2(netMarginFinalTotal) / f2min(incomeFinalTotal)));
    } else {
        netMarginProfitMargin.val("");
    }
}









