package com.jianshui.invoice.domain.dto.api.elephant;

import com.jianshui.common.utils.StringUtils;
import com.jianshui.invoice.domain.BillDetail;
import com.jianshui.invoice.domain.BillInfo;
import com.jianshui.invoice.domain.Redinfo;
import com.jianshui.invoice.domain.Redinfodetail;

import java.math.BigDecimal;
import java.util.Objects;

/**
 * Auto-generated: 2022-03-26 11:29:4
 *
 * @author Gong Quanlin
 */
public class DDMXXX {
    public DDMXXX() {

    }

    public DDMXXX(Redinfodetail redinfodetail) {

        this.XH = Integer.toString(redinfodetail.getIndex()); // 项目序号
        if (redinfodetail.getFphxz() != null) {
            this.FPHXZ = Integer.toString(redinfodetail.getFphxz()); // 发票行性质
        }
        this.SPBM = redinfodetail.getSpbm(); // 商品编码
        // this.ZXBM = redinfodetail.get; // 自行编码
        if (redinfodetail.getYhzcbs() != null) {
            this.YHZCBS = Integer.toString(redinfodetail.getYhzcbs()); // 优惠政策标识
        }
        this.LSLBS = redinfodetail.getLslbs(); // 零税率标识
        this.ZZSTSGL = redinfodetail.getZzstsgl(); // 增值税特殊管理
        this.XMMC = redinfodetail.getGoodName(); // 项目名称
        this.GGXH = redinfodetail.getSpec(); // 规格型号
        this.DW = redinfodetail.getUnit(); // 单位
        this.SPSL = redinfodetail.getNum(); // 商品数量
        if (StringUtils.equals(redinfodetail.getWithTaxFlag(), "true")) {
            this.DJ = redinfodetail.getPriceWithTax(); // 单价
            this.JE = redinfodetail.getTaxamt().toString(); // 金额
            this.HSBZ = "1";
        }
        if (StringUtils.equals(redinfodetail.getWithTaxFlag(), "false")) {
            this.DJ = redinfodetail.getPrice().toString(); // 单价
            this.JE = redinfodetail.getTaxfreeamt().toString(); // 金额
            this.HSBZ = "0";
        }

        // this.HSBZ = redinfodetail.getWithTaxFlag(); // 含税标志
        this.SL = redinfodetail.getTaxrate().toString(); // 税率
        this.SE = redinfodetail.getTax().toString(); // 税额
        if (redinfodetail.getKce() != null) {
            this.KCE = redinfodetail.getKce().toString(); // 扣除额
        }
        // this.BYZD1 = redinfodetail.; // 备用字段 1
        // this.BYZD2 = redinfodetail.; // 备用字段 2
        // this.BYZD3 = redinfodetail.; // 备用字段 3

    }

    public DDMXXX(BillInfo billInfo, BillDetail billDetail) {
        this.XH = billDetail.getIndex().toString(); // 项目序号
        this.FPHXZ = billDetail.getFphxz().toString(); // 发票行性质
        // 如果是红字清单
        if (StringUtils.equals(billInfo.getBillType(), "2") && StringUtils.equals(billInfo.getQdbz(), "1")) {
            this.FPHXZ = "6";
        }
        this.SPBM = billDetail.getSpbm(); // 商品编码
        this.ZXBM = billDetail.getZsbm(); // 自行编码
        this.YHZCBS = "0";
        if (billDetail.getYhzcbs() != null) {
            this.YHZCBS = billDetail.getYhzcbs().toString(); // 优惠政策标识
        }
        this.LSLBS = billDetail.getLslbs(); // 零税率标识
        this.ZZSTSGL = billDetail.getZzstsgl(); // 增值税特殊管理
        this.XMMC = billDetail.getGoodName(); // 项目名称
        this.GGXH = billDetail.getSpec(); // 规格型号
        this.DW = billDetail.getUnit(); // 单位
        if (billDetail.getNum() != null) {
            this.SPSL = billDetail.getNum(); // 商品数量
        }
        if (billDetail.getPrice() != null) {
            this.DJ = billDetail.getPrice().toString(); // 单价
        }
        if (billDetail.getHsbz() != null) {
            this.HSBZ = billDetail.getHsbz().toString(); // 含税标志
        }
        if (billDetail.getHsbz() == 0) {
            this.JE = billDetail.getTaxfreeamt().toString(); // 金额
        } else if (billDetail.getHsbz() == 1) {
            this.JE = billDetail.getTaxamt().toString();
        }

        this.SL = billDetail.getTaxrate().toString(); // 税率
        // 清单红字若对应的蓝字发票为多种税率，税率填充为空，单一税率填写此税率
        if (StringUtils.equals(billInfo.getBillType(), "2") && StringUtils.equals(billInfo.getQdbz(), "1")) {
            boolean shouldEmpty = false;
            BigDecimal tempRate = new BigDecimal(-1);
            for (BillDetail i : billInfo.getBillDetailList()) {
                if (Objects.equals(tempRate, new BigDecimal(-1))) {
                    tempRate = i.getTaxrate();
                } else if (!Objects.equals(tempRate, i.getTaxrate())) {
                    shouldEmpty = true;
                    break;
                }
            }
            if (shouldEmpty) {
                this.SL = null;
            }
        }
        this.SE = billDetail.getTax().toString(); // 税额
        if (billDetail.getKce() != null) {
            this.KCE = billDetail.getKce().toString(); // 扣除额
        }
        this.BYZD1 = ""; // 备用字段 1
        this.BYZD2 = ""; // 备用字段 2
        this.BYZD3 = ""; // 备用字段 3

    }

    private String XH; // 项目序号
    private String FPHXZ; // 发票行性质
    private String SPBM; // 商品编码
    private String ZXBM; // 自行编码
    private String YHZCBS; // 优惠政策标识
    private String LSLBS; // 零税率标识
    private String ZZSTSGL; // 增值税特殊管理
    private String XMMC; // 项目名称
    private String GGXH; // 规格型号
    private String DW; // 单位
    private BigDecimal SPSL; // 商品数量
    private String DJ; // 单价
    private String JE; // 金额
    private String HSBZ; // 含税标志
    private String SL; // 税率
    private String SE; // 税额
    private String KCE; // 扣除额
    private String BYZD1; // 备用字段 1
    private String BYZD2; // 备用字段 2
    private String BYZD3; // 备用字段 3

    public void setXH(String XH) {
        this.XH = XH;
    }

    public String getXH() {
        return XH;
    }

    public void setFPHXZ(String FPHXZ) {
        this.FPHXZ = FPHXZ;
    }

    public String getFPHXZ() {
        return FPHXZ;
    }

    public void setSPBM(String SPBM) {
        this.SPBM = SPBM;
    }

    public String getSPBM() {
        return SPBM;
    }

    public void setZXBM(String ZXBM) {
        this.ZXBM = ZXBM;
    }

    public String getZXBM() {
        return ZXBM;
    }

    public void setYHZCBS(String YHZCBS) {
        this.YHZCBS = YHZCBS;
    }

    public String getYHZCBS() {
        return YHZCBS;
    }

    public void setLSLBS(String LSLBS) {
        this.LSLBS = LSLBS;
    }

    public String getLSLBS() {
        return LSLBS;
    }

    public void setZZSTSGL(String ZZSTSGL) {
        this.ZZSTSGL = ZZSTSGL;
    }

    public String getZZSTSGL() {
        return ZZSTSGL;
    }

    public void setXMMC(String XMMC) {
        this.XMMC = XMMC;
    }

    public String getXMMC() {
        return XMMC;
    }

    public void setGGXH(String GGXH) {
        this.GGXH = GGXH;
    }

    public String getGGXH() {
        return GGXH;
    }

    public void setDW(String DW) {
        this.DW = DW;
    }

    public String getDW() {
        return DW;
    }

    public void setSPSL(BigDecimal SPSL) {
        this.SPSL = SPSL;
    }

    public BigDecimal getSPSL() {
        return SPSL;
    }

    public void setDJ(String DJ) {
        this.DJ = DJ;
    }

    public String getDJ() {
        return DJ;
    }

    public void setJE(String JE) {
        this.JE = JE;
    }

    public String getJE() {
        return JE;
    }

    public void setHSBZ(String HSBZ) {
        this.HSBZ = HSBZ;
    }

    public String getHSBZ() {
        return HSBZ;
    }

    public void setSL(String SL) {
        this.SL = SL;
    }

    public String getSL() {
        return SL;
    }

    public void setSE(String SE) {
        this.SE = SE;
    }

    public String getSE() {
        return SE;
    }

    public void setKCE(String KCE) {
        this.KCE = KCE;
    }

    public String getKCE() {
        return KCE;
    }

    public void setBYZD1(String BYZD1) {
        this.BYZD1 = BYZD1;
    }

    public String getBYZD1() {
        return BYZD1;
    }

    public void setBYZD2(String BYZD2) {
        this.BYZD2 = BYZD2;
    }

    public String getBYZD2() {
        return BYZD2;
    }

    public void setBYZD3(String BYZD3) {
        this.BYZD3 = BYZD3;
    }

    public String getBYZD3() {
        return BYZD3;
    }

    public DDMXXX getSelf() {
        return this;
    }

}