package cn.palmte.work.bean;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * @author Yuanping Zhang
 * @date 2021/11/15
 */
public class FormerBean extends IncomeCostBean {

    /**
     * 所得税
     */
    private BigDecimal costIncomeTax;
    /**
     * 管理总计
     */
    private BigDecimal costManageTotal;
    /**
     * 毛利润
     */
    private BigDecimal grossProfit;
    /**
     * 毛利润
     */
    private BigDecimal grossProfitMargin;
    /**
     * 贡献利润
     */
    private BigDecimal contributionProfit;
    /**
     * 贡献利润
     */
    private BigDecimal contributionProfitMargin;
    /**
     * 净利润
     */
    private BigDecimal netProfit;
    /**
     * 净利润
     */
    private BigDecimal netProfitMargin;
    /**
     * a销售商品、提供劳务收到的现金
     */
    private BigDecimal saleIncomeCash;
    /**
     * b收到的税费返还
     */
    private BigDecimal taxReturn;
    /**
     * c其他与经营活动有关的现金【保证金收入】
     */
    private BigDecimal earnestMoneyIncome;
    /**
     * d购买商品、接受劳务支付的现金【设备支出+工程支出】
     */
    private BigDecimal purchaseCost;
    /**
     * e支付的各项税费
     */
    private BigDecimal taxCost;
    /**
     * f支付其他与经营活动有关的现金
     */
    private BigDecimal earnestMoneyCost;
    /**
     * g经营活动产生的现金流量净额
     */
    private BigDecimal netCashFlow;
    /**
     * h投资活动现金流入
     */
    private BigDecimal cashInflowFromInvestingActivities;
    /**
     * i投资活动现金流出
     */
    private BigDecimal cashOutflowFromInvestingActivities;
    /**
     * j投资活动产生的现金流量净额
     */
    private BigDecimal netCashFromInvestingActivities;
    /**
     * k融资资金流入【垫资计划】
     */
    private BigDecimal financingCapitalInflow;
    /**
     * l融资资金流出【还款计划】
     */
    private BigDecimal financingCapitalOutflow;
    /**
     * m筹资活动产生的现金流量净额
     */
    private BigDecimal financingCapitalCashflow;
    /**
     * n货币资金净增加额
     */
    private BigDecimal netIncreaseMonetaryFunds;
    /**
     * 现金流量总计
     */
    private BigDecimal cashFlowTotal;

    /**
     * 项目毛利利润率
     */
    private BigDecimal grossProfitProfitMargin;

    public BigDecimal getGrossProfitProfitMargin() {
        // 100 * grossProfit() / getIncomeTotalTaxExclude()
        BigDecimal grossProfit = getGrossProfit();
        BigDecimal incomeTotalTaxExclude = getIncomeTotalTaxExclude();

        if (null == grossProfit || null == incomeTotalTaxExclude) {
            return handleSpecial(null);
        }
        if (incomeTotalTaxExclude.compareTo(BigDecimal.ZERO) == 0) {
            return BigDecimal.ZERO;
        }
        return grossProfit.divide(incomeTotalTaxExclude,4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
    }

    public void setGrossProfitProfitMargin(BigDecimal grossProfitProfitMargin) {
        this.grossProfitProfitMargin = grossProfitProfitMargin;
    }

    /**
     * 项目贡献利润利润率
     */
    private BigDecimal contributionProfitProfitMargin;

    public BigDecimal getContributionProfitProfitMargin() {
        //100 * contributionProfit() / getIncomeTotalTaxExclude()
        BigDecimal contributionProfit = getContributionProfit();
        BigDecimal incomeTotalTaxExclude = getIncomeTotalTaxExclude();

        if (null == contributionProfit || null == incomeTotalTaxExclude) {
            return handleSpecial(null);
        }
        if (incomeTotalTaxExclude.compareTo(BigDecimal.ZERO) == 0) {
            return BigDecimal.ZERO;
        }
        return contributionProfit.divide(incomeTotalTaxExclude,4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
    }

    public void setContributionProfitProfitMargin(BigDecimal contributionProfitProfitMargin) {
        this.contributionProfitProfitMargin = contributionProfitProfitMargin;
    }

    /**
     * 项目净利润利润率
     */
    private BigDecimal netProfitProfitMargin;

    public BigDecimal getNetProfitProfitMargin() {
        //100 * netProfit() / getIncomeTotalTaxExclude()
        BigDecimal netProfit = getNetProfit();
        BigDecimal incomeTotalTaxExclude = getIncomeTotalTaxExclude();

        if (null == netProfit || null == incomeTotalTaxExclude) {
            return handleSpecial(null);
        }
        if (incomeTotalTaxExclude.compareTo(BigDecimal.ZERO) == 0) {
            return BigDecimal.ZERO;
        }
        return netProfit.divide(incomeTotalTaxExclude,4, RoundingMode.HALF_UP).multiply(new BigDecimal(100));
    }

    public void setNetProfitProfitMargin(BigDecimal netProfitProfitMargin) {
        this.netProfitProfitMargin = netProfitProfitMargin;
    }

    public BigDecimal getCostIncomeTax() {
        return costIncomeTax;
    }

    public void setCostIncomeTax(BigDecimal costIncomeTax) {
        this.costIncomeTax = costIncomeTax;
    }

    public BigDecimal getCostManageTotal() {
        BigDecimal costExpropriation = getCostExpropriationTaxExclude();
        BigDecimal costCompanyManage = getCostCompanyManageTaxExclude();
        BigDecimal costIncomeTax = getCostIncomeTax();

        if (null == costExpropriation || null == costCompanyManage || null == costIncomeTax) {
            return new BigDecimal(0);
        }

        return costExpropriation.add(costCompanyManage).add(costIncomeTax);
    }

    public void setCostManageTotal(BigDecimal costManageTotal) {
        this.costManageTotal = costManageTotal;
    }

    public BigDecimal getGrossProfit() {
        return grossProfit;
    }

    public void setGrossProfit(BigDecimal grossProfit) {
        this.grossProfit = grossProfit;
    }

    public BigDecimal getGrossProfitMargin() {
        return grossProfitMargin;
    }

    public void setGrossProfitMargin(BigDecimal grossProfitMargin) {
        this.grossProfitMargin = grossProfitMargin;
    }

    public BigDecimal getContributionProfit() {
        return contributionProfit;
    }

    public void setContributionProfit(BigDecimal contributionProfit) {
        this.contributionProfit = contributionProfit;
    }

    public BigDecimal getContributionProfitMargin() {
        return contributionProfitMargin;
    }

    public void setContributionProfitMargin(BigDecimal contributionProfitMargin) {
        this.contributionProfitMargin = contributionProfitMargin;
    }

    public BigDecimal getNetProfit() {
        return netProfit;
    }

    public void setNetProfit(BigDecimal netProfit) {
        this.netProfit = netProfit;
    }

    public BigDecimal getNetProfitMargin() {
        return netProfitMargin;
    }

    public void setNetProfitMargin(BigDecimal netProfitMargin) {
        this.netProfitMargin = netProfitMargin;
    }

    public BigDecimal getSaleIncomeCash() {
        return saleIncomeCash;
    }

    public void setSaleIncomeCash(BigDecimal saleIncomeCash) {
        this.saleIncomeCash = saleIncomeCash;
    }

    public BigDecimal getTaxReturn() {
        return taxReturn;
    }

    public void setTaxReturn(BigDecimal taxReturn) {
        this.taxReturn = taxReturn;
    }

    public BigDecimal getEarnestMoneyIncome() {
        return earnestMoneyIncome;
    }

    public void setEarnestMoneyIncome(BigDecimal earnestMoneyIncome) {
        this.earnestMoneyIncome = earnestMoneyIncome;
    }

    public BigDecimal getPurchaseCost() {
        return purchaseCost;
    }

    public void setPurchaseCost(BigDecimal purchaseCost) {
        this.purchaseCost = purchaseCost;
    }

    public BigDecimal getTaxCost() {
        return taxCost;
    }

    public void setTaxCost(BigDecimal taxCost) {
        this.taxCost = taxCost;
    }

    public BigDecimal getEarnestMoneyCost() {
        return earnestMoneyCost;
    }

    public void setEarnestMoneyCost(BigDecimal earnestMoneyCost) {
        this.earnestMoneyCost = earnestMoneyCost;
    }

    public BigDecimal getNetCashFlow() {
        return netCashFlow;
    }

    public void setNetCashFlow(BigDecimal netCashFlow) {
        this.netCashFlow = netCashFlow;
    }

    public BigDecimal getCashInflowFromInvestingActivities() {
        return cashInflowFromInvestingActivities;
    }

    public void setCashInflowFromInvestingActivities(BigDecimal cashInflowFromInvestingActivities) {
        this.cashInflowFromInvestingActivities = cashInflowFromInvestingActivities;
    }

    public BigDecimal getCashOutflowFromInvestingActivities() {
        return cashOutflowFromInvestingActivities;
    }

    public void setCashOutflowFromInvestingActivities(BigDecimal cashOutflowFromInvestingActivities) {
        this.cashOutflowFromInvestingActivities = cashOutflowFromInvestingActivities;
    }

    public BigDecimal getNetCashFromInvestingActivities() {
        return netCashFromInvestingActivities;
    }

    public void setNetCashFromInvestingActivities(BigDecimal netCashFromInvestingActivities) {
        this.netCashFromInvestingActivities = netCashFromInvestingActivities;
    }

    public BigDecimal getFinancingCapitalInflow() {
        return financingCapitalInflow;
    }

    public void setFinancingCapitalInflow(BigDecimal financingCapitalInflow) {
        this.financingCapitalInflow = financingCapitalInflow;
    }

    public BigDecimal getFinancingCapitalOutflow() {
        return financingCapitalOutflow;
    }

    public void setFinancingCapitalOutflow(BigDecimal financingCapitalOutflow) {
        this.financingCapitalOutflow = financingCapitalOutflow;
    }

    public BigDecimal getFinancingCapitalCashflow() {
        return financingCapitalCashflow;
    }

    public void setFinancingCapitalCashflow(BigDecimal financingCapitalCashflow) {
        this.financingCapitalCashflow = financingCapitalCashflow;
    }

    public BigDecimal getNetIncreaseMonetaryFunds() {
        return netIncreaseMonetaryFunds;
    }

    public void setNetIncreaseMonetaryFunds(BigDecimal netIncreaseMonetaryFunds) {
        this.netIncreaseMonetaryFunds = netIncreaseMonetaryFunds;
    }

    public BigDecimal getCashFlowTotal() {
        BigDecimal saleIncomeCash = getSaleIncomeCash();
        BigDecimal taxReturn = getTaxReturn();
        BigDecimal earnestMoneyIncome = getEarnestMoneyIncome();
        BigDecimal purchaseCost = getPurchaseCost();
        BigDecimal taxCost = getTaxCost();
        BigDecimal earnestMoneyCost = getEarnestMoneyCost();
        BigDecimal netCashFlow = getNetCashFlow();
        BigDecimal cashInflowFromInvestingActivities = getCashInflowFromInvestingActivities();
        BigDecimal cashOutflowFromInvestingActivities = getCashOutflowFromInvestingActivities();
        BigDecimal netCashFromInvestingActivities = getNetCashFromInvestingActivities();
        BigDecimal financingCapitalInflow = getFinancingCapitalInflow();
        BigDecimal financingCapitalOutflow = getFinancingCapitalOutflow();
        BigDecimal financingCapitalCashflow = getFinancingCapitalCashflow();
        BigDecimal netIncreaseMonetaryFunds = getNetIncreaseMonetaryFunds();

        if (null == saleIncomeCash || null == taxReturn || null == earnestMoneyIncome || null == purchaseCost || null == taxCost
                || null == earnestMoneyCost || null == netCashFlow || null == cashInflowFromInvestingActivities ||
                null == cashOutflowFromInvestingActivities || null == netCashFromInvestingActivities ||
                null == financingCapitalInflow || null == financingCapitalOutflow || null == financingCapitalCashflow || null == netIncreaseMonetaryFunds) {
            return new BigDecimal(0);
        }

        return saleIncomeCash.add(taxReturn).add(earnestMoneyIncome).add(purchaseCost).add(taxCost).add(earnestMoneyCost)
                .add(netCashFlow).add(cashInflowFromInvestingActivities).add(cashOutflowFromInvestingActivities).add(netCashFromInvestingActivities)
                .add(financingCapitalInflow).add(financingCapitalOutflow).add(financingCapitalCashflow).add(netIncreaseMonetaryFunds);
    }

    public void setCashFlowTotal(BigDecimal cashFlowTotal) {
        this.cashFlowTotal = cashFlowTotal;
    }

    /**
     * 原样返回
     */
    @Override
    protected BigDecimal handleSpecial(BigDecimal src) {
        return src;
    }
}
