package cn.palmte.work.bean;

import java.math.BigDecimal;

/**
 * 现金流量
 * @author xiongshiyan at 2021/11/6 , contact me with email yanshixiong@126.com or phone 15208384257
 */
public class CashFlowBean {
    /**
     * 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经营活动产生的现金流量净额
     * g=a+c+b-d-f-e
     */
    //private BigDecimal netCashFlow;
    /**
     * h投资活动现金流入
     */
    private BigDecimal cashInflowFromInvestingActivities;
    /**
     * i投资活动现金流出
     */
    private BigDecimal cashOutflowFromInvestingActivities;
    /**
     * j投资活动产生的现金流量净额
     */
    private BigDecimal netCashFromInvestingActivities;
    /**
     * k融资资金流入【垫资计划】
     */
    private BigDecimal financingCapitalInflow;
    /**
     * l融资资金流出【还款计划】
     */
    private BigDecimal financingCapitalOutflow;
    /**
     *m筹资活动产生的现金流量净额
     * m=k-l
     */
    //private BigDecimal financingCapitalCashflow;
    /**
     * n货币资金净增加额
     * n=g+j+m
     */
    //private BigDecimal netIncreaseMonetaryFunds;

    public BigDecimal getSaleIncomeCash() {
        return handleSpecial(saleIncomeCash);
    }

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

    public BigDecimal getTaxReturn() {
        return handleSpecial(taxReturn);
    }

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

    public BigDecimal getEarnestMoneyIncome() {
        return handleSpecial(earnestMoneyIncome);
    }

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

    public BigDecimal getPurchaseCost() {
        return handleSpecial(purchaseCost);
    }

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

    public BigDecimal getTaxCost() {
        return handleSpecial(taxCost);
    }

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

    public BigDecimal getEarnestMoneyCost() {
        return handleSpecial(earnestMoneyCost);
    }

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

    public BigDecimal getNetCashFlow() {

        BigDecimal saleIncomeCash = getSaleIncomeCash();
        BigDecimal taxReturn = getTaxReturn();
        BigDecimal earnestMoneyIncome = getEarnestMoneyIncome();
        BigDecimal purchaseCost = getPurchaseCost();
        BigDecimal taxCost = getTaxCost();
        BigDecimal earnestMoneyCost = getEarnestMoneyCost();

        return saleIncomeCash
                .add(taxReturn)
                .add(earnestMoneyIncome)
                .subtract(purchaseCost)
                .subtract(taxCost)
                .subtract(earnestMoneyCost);
    }

    public BigDecimal getCashInflowFromInvestingActivities() {
        return handleSpecial(cashInflowFromInvestingActivities);
    }

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

    public BigDecimal getCashOutflowFromInvestingActivities() {
        return handleSpecial(cashOutflowFromInvestingActivities);
    }

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

    public BigDecimal getNetCashFromInvestingActivities() {
        return handleSpecial(netCashFromInvestingActivities);
    }

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

    public BigDecimal getFinancingCapitalInflow() {
        return handleSpecial(financingCapitalInflow);
    }

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

    public BigDecimal getFinancingCapitalOutflow() {
        return handleSpecial(financingCapitalOutflow);
    }

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

    public BigDecimal getFinancingCapitalCashflow() {
        BigDecimal financingCapitalInflow = getFinancingCapitalInflow();
        BigDecimal financingCapitalOutflow = getFinancingCapitalOutflow();
        return financingCapitalInflow.subtract(financingCapitalOutflow);
    }

    public BigDecimal getNetIncreaseMonetaryFunds() {
        BigDecimal netCashFlow = getNetCashFlow();
        BigDecimal netCashFromInvestingActivities = getNetCashFromInvestingActivities();
        BigDecimal financingCapitalCashflow = getFinancingCapitalCashflow();
        return netCashFlow
                .add(netCashFromInvestingActivities)
                .add(financingCapitalCashflow);
    }

    /**
     * 获取所有现金流量决算总额
     * @return
     */
    public BigDecimal getCashFluxTotal() {
        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);
    }

    /**
     * 处理特殊值
     * null就返回0
     */
    protected BigDecimal handleSpecial(BigDecimal src) {
        return null == src ? new BigDecimal(0) : src;
    }
}
