package cn.palmte.work.model;

import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import java.math.BigDecimal;

@MappedSuperclass
public class ProjectBudgetCostDetailBase {
    public static final int TYPE_DEVICE = 1;
    public static final int TYPE_BUILD = 2;
    public static final int TYPE_SERVICE = 3;
    public static final int TYPE_OHTER = 4;

    /**
     * id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @GenericGenerator(name = "persistenceGenerator", strategy = "increment")
    private Integer id;

    @Column(name = "project_id")
    private int projectId;

    private int type;
    private int category;

    private String name;

    private String unit;
    private int amount;
    private BigDecimal price;

    @Column(name = "tax_rate")
    private BigDecimal taxRate;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public int getProjectId() {
        return projectId;
    }

    public void setProjectId(int projectId) {
        this.projectId = projectId;
    }

    public int getType() {
        return type;
    }

    public void setType(int type) {
        this.type = type;
    }

    public int getCategory() {
        return category;
    }

    public void setCategory(int category) {
        this.category = category;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUnit() {
        return unit;
    }

    public void setUnit(String unit) {
        this.unit = unit;
    }

    public int getAmount() {
        return amount;
    }

    public void setAmount(int amount) {
        this.amount = amount;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public BigDecimal getTaxRate() {
        return taxRate;
    }

    public void setTaxRate(BigDecimal taxRate) {
        this.taxRate = taxRate;
    }

    public BigDecimal getTotalTaxInclude(){
        if(null == price){
            return null;
        }
        return price.multiply(new BigDecimal(amount));
    }
    public BigDecimal getTotalTaxExclude(){
        BigDecimal totalTaxInclude = getTotalTaxInclude();
        if(null == totalTaxInclude || taxRate == null){
            return null;
        }

        //不含税总金额=含税总金额/（1+税率）
        return totalTaxInclude.divide(taxRate.divide(new BigDecimal(100), 2, BigDecimal.ROUND_HALF_UP).add(new BigDecimal(1)), 2, BigDecimal.ROUND_HALF_UP);
    }
}