package com.uas.platform.b2b.model;


import javax.persistence.*;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 买家应付（卖家应收）对账单明细
 */
@Table(name = "purc$apcheckitem")
@Entity
public class PurchaseApCheckItemInfo implements Serializable {

	/**
	 * 序列号
	 */
	private static final long serialVersionUID = 1L;

	/**
	 * ID
	 */
	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "pai_id")
	private Long id;

	/**
	 * 行号
	 */
	@Column(name = "pai_number")
	private Short number;

	/**
	 * 客户物料ID
	 */
	@Column(name = "pai_prid")
	private Long prid;

	/**
	 * 客户订单单号
	 */
	@Column(name = "pai_ordercode")
	private String orderCode;

	/**
	 * 客户出入库类型
	 */
	@Column(name = "pai_orderclass")
	private String orderClass;

	/**
	 * 客户订单序号
	 */
	@Column(name = "pai_orderdetno")
	private Long orderDetno;

	/**
	 * 客户出入库单号
	 */
	@Column(name = "pai_inoutno")
	private String inoutno;

	/**
	 * 出入库单序号
	 */
	@Column(name = "pai_inoutnodetno")
	private Long inoutnodetno;

	/**
	 * 客户料号
	 */
	@Column(name = "pai_prodcode")
	private String prodCode;

	/**
	 * 物料名称
	 */
	@Column(name = "pai_prodtitle")
	private String prodTitle;

	/**
	 * 物料规格
	 */
	@Column(name = "pai_prodspec")
	private String prodSpec;

	/**
	 * 单价
	 */
	@Column(name = "pai_price")
	private Double price;

	/**
	 * 税率
	 */
	@Column(name = "pai_taxrate")
	private Double taxrate;

	/**
	 * 对账数量
	 */
	@Column(name = "pai_checkqty")
	private Double checkQty;

	/**
	 * 对账金额
	 */
	@Column(name = "pai_amount")
	private Double amount;

	/**
	 * 客户确认数量
	 */
	@Column(name = "pai_custcheckqty")
	private Double custCheckQty;

	/**
	 * 备注
	 */
	@Column(name = "pai_remark")
	private String remark;

	/**
	 * 对账状态
	 */
	@Column(name = "pai_status")
	private Integer status;

	/**
	 * 明细行数据来源表
	 */
	@Column(name = "pai_sourcetable")
	private String sourceTable;

	/**
	 * 明细行数据来源对应ID
	 */
	@Column(name = "pai_sourceid")
	private Long sourceId;

	/**
	 * 此次转账之前的已对账数（用于删除应收对账单时）
	 */
	@Column(name = "pai_oldycheckqty")
	private Double oldYCheckQty;

	/**
	 * 应付供应商编号
	 */
	@Column(name = "pai_receivecode")
	private String receiveCode;

	/**
	 * 应付供应商名称
	 */
	@Column(name = "pai_receivename")
	private String receiveName;

	/**
	 * 送货单号
	 */
	@Column(name = "pai_sendcode")
	private String sendcode;

	/**
	 * 仓库
	 */
	@Column(name = "pai_whname")
	private String whname;

	/**
	 * 已开票数量
	 */
	@Column(name = "pai_billed")
	private Double billed;

	@Column(name = "pai_paid")
	private Long paid;

	/**
	 * 应收对账单主记录
	 */
	@ManyToOne(cascade = { CascadeType.REFRESH, CascadeType.MERGE })
	@JoinColumn(name = "pai_paid", insertable = false, updatable = false)
	private PurchaseApCheckInfo apCheck;

	public Long getId() {
		return id;
	}

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

	public Short getNumber() {
		return number;
	}

	public void setNumber(Short number) {
		this.number = number;
	}

	public Long getPrid() {
		return prid;
	}

	public void setPrid(Long prid) {
		this.prid = prid;
	}

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public String getOrderClass() {
		return orderClass;
	}

	public void setOrderClass(String orderClass) {
		this.orderClass = orderClass;
	}

	public Long getOrderDetno() {
		return orderDetno;
	}

	public void setOrderDetno(Long orderDetno) {
		this.orderDetno = orderDetno;
	}

	public String getProdCode() {
		return prodCode;
	}

	public void setProdCode(String prodCode) {
		this.prodCode = prodCode;
	}

	public Double getPrice() {
		return price;
	}

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

	public Double getTaxrate() {
		return taxrate;
	}

	public void setTaxrate(Double taxrate) {
		this.taxrate = taxrate;
	}

	public Double getCheckQty() {
		return checkQty;
	}

	public void setCheckQty(Double checkQty) {
		this.checkQty = checkQty;
	}

	public Double getAmount() {
		return amount;
	}

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

	public Double getCustCheckQty() {
		return custCheckQty;
	}

	public void setCustCheckQty(Double custCheckQty) {
		this.custCheckQty = custCheckQty;
	}

	public String getRemark() {
		return remark;
	}

	public void setRemark(String remark) {
		this.remark = remark;
	}

	public Integer getStatus() {
		return status;
	}

	public void setStatus(Integer status) {
		this.status = status;
	}

	public String getSourceTable() {
		return sourceTable;
	}

	public void setSourceTable(String sourceTable) {
		this.sourceTable = sourceTable;
	}

	public Long getSourceId() {
		return sourceId;
	}

	public void setSourceId(Long sourceId) {
		this.sourceId = sourceId;
	}

	public Double getOldYCheckQty() {
		return oldYCheckQty;
	}

	public void setOldYCheckQty(Double oldYCheckQty) {
		this.oldYCheckQty = oldYCheckQty;
	}

	public String getInoutno() {
		return inoutno;
	}

	public void setInoutno(String inoutno) {
		this.inoutno = inoutno;
	}

	public Long getInoutnodetno() {
		return inoutnodetno;
	}

	public void setInoutnodetno(Long inoutnodetno) {
		this.inoutnodetno = inoutnodetno;
	}

	public String getReceiveCode() {
		return receiveCode;
	}

	public void setReceiveCode(String receiveCode) {
		this.receiveCode = receiveCode;
	}

	public String getReceiveName() {
		return receiveName;
	}

	public void setReceiveName(String receiveName) {
		this.receiveName = receiveName;
	}

	public Long getPaid() {
		return paid;
	}

	public void setPaid(Long paid) {
		this.paid = paid;
	}

	public PurchaseApCheckInfo getApCheck() {
		return apCheck;
	}

	public void setApCheck(PurchaseApCheckInfo apCheck) {
		this.apCheck = apCheck;
	}

	public String getProdTitle() {
		return prodTitle;
	}

	public void setProdTitle(String prodTitle) {
		this.prodTitle = prodTitle;
	}

	public String getProdSpec() {
		return prodSpec;
	}

	public void setProdSpec(String prodSpec) {
		this.prodSpec = prodSpec;
	}

	public String getSendcode() {
		return sendcode;
	}

	public void setSendcode(String sendcode) {
		this.sendcode = sendcode;
	}

	public String getWhname() {
		return whname;
	}

	public void setWhname(String whname) {
		this.whname = whname;
	}

	public Double getBilled() {
		return billed;
	}

	public void setBilled(Double billed) {
		this.billed = billed;
	}

	public static List<PurchaseApCheckInfo> distinct(List<PurchaseApCheckItemInfo> items) {
		List<PurchaseApCheckInfo> purchaseApChecks = new ArrayList<PurchaseApCheckInfo>();
		Set<Long> keys = new HashSet<Long>();
		for (PurchaseApCheckItemInfo item : items) {
			if (!keys.contains(item.apCheck.getId())) {
				purchaseApChecks.add(item.apCheck);
				keys.add(item.apCheck.getId());
			}
		}
		return purchaseApChecks;
	}

}
