package com.uas.platform.b2b.model;

import org.hibernate.annotations.Where;

import javax.persistence.*;
import java.util.Date;
import java.util.Set;

/** 
  * @author yujia 
  * @version 创建时间：2015年12月29日 上午11:25:19 
  * 待交货的采购订单
  */

@Table(name = "purc$orders", indexes = { @Index(name = "purc$orders_date", columnList = "pu_date") })
@Entity
@Where(clause = "(pu_end=0 or pu_end is null) and pu_id in (select i.pd_puid from purc$orderitems i where ifnull(i.pd_acceptqty,0)<ifnull(i.pd_qty,0)+ifnull(i.pd_returnqty,0)) and pu_status <> 311")
public class PurchaseOrderWaiting {
	
	@Id
	@Column(name = "pu_id")
	private Long id;
	
	/**
	 * 采购企业UU
	 */
	@Column(name = "pu_enuu")
	private Long enUU;

	/**
	 * 采购企业
	 */
	@OneToOne(cascade = { CascadeType.MERGE, CascadeType.REFRESH })
	@JoinColumn(name = "pu_enuu", insertable = false, updatable = false)
	private EnterpriseInfo enterprise;

	/**
	 * 采购单所属采购员
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = "pu_useruu", insertable = false, updatable = false)
	private UserBaseInfo user;

	/**
	 * 采购单所属采购员UU
	 */
	@Column(name = "pu_useruu")
	private Long userUU;

	/**
	 * 采购单号
	 */
	@Column(name = "pu_code")
	private String code;

	/**
	 * 采购类型
	 */
	@Column(name = "pu_type")
	private String type;

	/**
	 * 单据归属日期
	 */
	@Column(name = "pu_date")
	private Date date;

	/**
	 * 录单人
	 */
	@Column(name = "pu_recorder")
	private String recorder;

	/**
	 * 审核人
	 */
	@Column(name = "pu_auditor")
	private String auditor;

	/**
	 * 供应商UU
	 */
	@Column(name = "pu_venduu")
	private Long vendUU;
	
	/**
	 * 供应商名称
	 */
	@Transient
	private String enName;

	/**
	 * 供应商联系人UU
	 */
	@Column(name = "pu_venduseruu")
	private Long vendUserUU;

	/**
	 * 收货地址
	 */
	@Column(name = "pu_shipaddress")
	private String shipAddress;

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

	/**
	 * 付款币种
	 */
	@Column(name = "pu_currency")
	private String currency;

	/**
	 * 汇率
	 */
	@Column(name = "pu_rate")
	private Float rate;

	/**
	 * 付款方式
	 */
	@Column(name = "pu_payments")
	private String payments;

	/**
	 * 处理状态（已回复、未回复），全部回复后改为已回复
	 */
	@Column(name = "pu_status")
	private Short status;

	/**
	 * 从平台传到供应商ERP的状态
	 */
	@Column(name = "pu_sendstatus")
	private Short sendStatus;

	/**
	 * 采购单明细
	 */
	@OneToMany(mappedBy = "order", cascade = { CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE, CascadeType.MERGE }, fetch = FetchType.EAGER)
	@OrderBy("number")
	@Where(clause = "(ifnull(pd_acceptqty,0)<ifnull(pd_qty,0)+ifnull(pd_returnqty,0)) and (pd_end = 0 or pd_end is null)")
	private Set<PurchaseOrderWaitingItem> orderItems;
	
	/**
	 * 显示状态(0 已查看 ， 1 未查看， 2 置顶)
	 */
	@Column(name = "pu_display")
	private Short display;
	
	/**
	 * 打印次数
	 */
	@Column(name = "pu_print")
	private Short print;

	/**
	 * 打印次数(采购方)
	 */
	@Column(name = "pu_custprint")
	private Short custPrint;

	public Short getCustPrint() {
		return custPrint;
	}

	public void setCustPrint(Short custPrint) {
		this.custPrint = custPrint;
	}

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

	/**
	 * 客户公司名称
	 */
	@Column(name = "pu_cop")
	private String cop;

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

	@Column(name = "pu_purpose")
	private String purpose; // 用途，

	@Column(name = "pu_arcustcode")
	private String arCustCode; // 买家应收客户，

	@Column(name = "pu_shcustcode")
	private String shCustCode; // 收货客户，

	@Column(name = "pu_refcode")
	private String refCode; // 销售单号

	@Column(name = "pu_custcode")
	private String custCode; // 客户编号，

	@Column(name = "pu_custname")
	private String custName; // 客户名称。

	public String getPurpose() {
		return purpose;
	}

	public void setPurpose(String purpose) {
		this.purpose = purpose;
	}

	public String getArCustCode() {
		return arCustCode;
	}

	public void setArCustCode(String arCustCode) {
		this.arCustCode = arCustCode;
	}

	public String getShCustCode() {
		return shCustCode;
	}

	public void setShCustCode(String shCustCode) {
		this.shCustCode = shCustCode;
	}

	public String getRefCode() {
		return refCode;
	}

	public void setRefCode(String refCode) {
		this.refCode = refCode;
	}

	public String getCustCode() {
		return custCode;
	}

	public void setCustCode(String custCode) {
		this.custCode = custCode;
	}

	public String getCustName() {
		return custName;
	}

	public void setCustName(String custName) {
		this.custName = custName;
	}
	

	public Long getId() {
		return id;
	}

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

	public Long getEnUU() {
		return enUU;
	}

	public void setEnUU(Long enUU) {
		this.enUU = enUU;
	}

	public EnterpriseInfo getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(EnterpriseInfo enterprise) {
		this.enterprise = enterprise;
	}

	public UserBaseInfo getUser() {
		return user;
	}

	public void setUser(UserBaseInfo user) {
		this.user = user;
	}

	public Long getUserUU() {
		return userUU;
	}

	public void setUserUU(Long userUU) {
		this.userUU = userUU;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getType() {
		return type;
	}

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

	public Date getDate() {
		return date;
	}

	public void setDate(Date date) {
		this.date = date;
	}

	public String getRecorder() {
		return recorder;
	}

	public void setRecorder(String recorder) {
		this.recorder = recorder;
	}

	public String getAuditor() {
		return auditor;
	}

	public void setAuditor(String auditor) {
		this.auditor = auditor;
	}

	public Long getVendUU() {
		return vendUU;
	}

	public void setVendUU(Long vendUU) {
		this.vendUU = vendUU;
	}

	public Long getVendUserUU() {
		return vendUserUU;
	}

	public void setVendUserUU(Long vendUserUU) {
		this.vendUserUU = vendUserUU;
	}

	public String getShipAddress() {
		return shipAddress;
	}

	public void setShipAddress(String shipAddress) {
		this.shipAddress = shipAddress;
	}

	public String getRemark() {
		return remark;
	}

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

	public String getCurrency() {
		return currency;
	}

	public void setCurrency(String currency) {
		this.currency = currency;
	}

	public Float getRate() {
		return rate;
	}

	public void setRate(Float rate) {
		this.rate = rate;
	}

	public String getPayments() {
		return payments;
	}

	public void setPayments(String payments) {
		this.payments = payments;
	}

	public Short getStatus() {
		return status;
	}

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

	public Short getSendStatus() {
		return sendStatus;
	}

	public void setSendStatus(Short sendStatus) {
		this.sendStatus = sendStatus;
	}

	public Set<PurchaseOrderWaitingItem> getOrderItems() {
		return orderItems;
	}

	public void setOrderItems(Set<PurchaseOrderWaitingItem> orderItems) {
		this.orderItems = orderItems;
	}

	public Short getDisplay() {
		if(this.display == null) {
            this.display = 0;
        }
		return display;
	}

	public void setDisplay(Short display) {
		this.display = display;
	}

	public Short getPrint() {
		return print;
	}

	public void setPrint(Short print) {
		this.print = print;
	}

	public String getReceiveName() {
		return receiveName;
	}

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

	public String getReceiveCode() {
		return receiveCode;
	}

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

	public String getEnName() {
		return enName;
	}

	public void setEnName(String enName) {
		this.enName = enName;
	}

	public String getCop() {
		return cop;
	}

	public void setCop(String cop) {
		this.cop = cop;
	}

	@Column(name = "pu_end")
	private Short end;

	public Short getEnd() {
		if (orderItems.size() == 0) {
			return 1;
		} else {
			return end;
		}
	}

	public void setEnd(Short end) {
		this.end = end;
	}
}
