package com.uas.platform.b2b.model;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.OrderBy;
import javax.persistence.SequenceGenerator;
import javax.persistence.Table;

import org.codehaus.jackson.annotate.JsonIgnore;

import com.alibaba.fastjson.annotation.JSONField;
import com.uas.platform.core.model.Constant;

/**
 * 平台里面，以供应商的角度来查看采购订单变更单 <br>
 * 级联变更明细
 * 
 * @author yingp
 * 
 */
@Table(name = "purc$changes")
@Entity
public class PurchaseOrderChange implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	@Column(name = "pc_id")
	private Long id;

	/**
	 * 采购变更单所属企业UU
	 */
	@Column(name = "pc_enuu")
	private Long enUU;

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

	/**
	 * 采购变更单买方用户UU（订单中的数据）
	 */
	@Column(name = "pc_useruu")
	private Long userUU;

	/**
	 * 采购变更单供应商UU
	 */
	@Column(name = "pc_venduu")
	private Long vendUU;

	/**
	 * 采购变更单原应付供应商
	 */
	@Column(name = "pc_apvendname")
	private String apVendorName;

	/**
	 * 采购变更单新应付供应商
	 */
	@Column(name = "pc_newapvendname")
	private String newApVendorName;

	/**
	 * 采购变更单卖方用户UU（订单中的数据）
	 */
	@Column(name = "pc_venduseruu")
	private Long vendUserUU;

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

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

	/**
	 * 单据录入日期
	 */
	@Column(name = "pc_indate")
	private Date date;

	/**
	 * 变更内容描述
	 */
	@Column(name = "pc_description", length = 3000)
	private String description;

	/**
	 * 备注
	 */
	@Column(name = "pc_remark", length = 500)
	private String remark;

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

	/**
	 * 从平台传回复内容到供应商ERP的状态
	 */
	@Column(name = "pc_replysendstatus")
	private Short replySendStatus;

	/**
	 * 状态（未回复、已回复）
	 */
	@Column(name = "pc_status")
	private Short status;

	/**
	 * 卖家是否同意了买家的变更请求(1,0)
	 */
	@Column(name = "pc_agreed")
	private Short agreed;

	/**
	 * 不需要供应商确认(1表示不需要确认,0表示需要确认)
	 */
	@Column(name = "pc_unneedreply")
	private Short unNeedReply;

	/**
	 * 回复备注
	 */
	@Column(name = "pc_replyremark", length = 500)
	private String replyRemark;

	/**
	 * 从平台传回复信息到买方ERP的状态
	 */
	@Column(name = "pc_backstatus")
	private Short backStatus;

	/**
	 * 新付款方式
	 */
	@Column(name = "pc_newpayments")
	private String newPayments;

	/**
	 * 原单据单据付款方式
	 */
	@Column(name = "pc_oldpayments")
	private String oldPayments;

	/**
	 * 新付款币种
	 */
	@Column(name = "pc_newcurrency")
	private String newCurrency;

	/**
	 * 原单据付款币种
	 */
	@Column(name = "pc_oldcurrency")
	private String oldCurrency;

	/**
	 * 新汇率
	 */
	@Column(name = "pc_newrate")
	private Float newRate;

	/**
	 * 原单据汇率
	 */
	@Column(name = "pc_oldrate")
	private Float oldRate;

	@Column(name = "pc_puid")
	private Long orderId;

	/**
	 * 采购订单编号
	 */
	@Column(name = "pc_pucode")
	private String orderCode;

	/**
	 * 采购变更单明细
	 */
	@OneToMany(mappedBy = "orderChange", cascade = { CascadeType.REFRESH, CascadeType.PERSIST, CascadeType.REMOVE,
			CascadeType.MERGE }, fetch = FetchType.EAGER)
	@OrderBy("number")
	private Set<PurchaseOrderChangeItem> orderChangeItems;

	/**
	 * 对应的erpId
	 * 
	 * @return
	 */
	@Column(name = "pc_erpid")
	private Long erpId;

	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 String getCode() {
		return code;
	}

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

	public String getRecorder() {
		return recorder;
	}

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

	public Date getDate() {
		return date;
	}

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

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}

	public String getRemark() {
		return remark;
	}

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

	public Short getSendStatus() {
		return sendStatus;
	}

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

	public String getNewPayments() {
		return newPayments;
	}

	public void setNewPayments(String newPayments) {
		this.newPayments = newPayments;
	}

	public String getNewCurrency() {
		return newCurrency;
	}

	public void setNewCurrency(String newCurrency) {
		this.newCurrency = newCurrency;
	}

	public Float getNewRate() {
		return newRate;
	}

	public void setNewRate(Float newRate) {
		this.newRate = newRate;
	}

	public Set<PurchaseOrderChangeItem> getOrderChangeItems() {
		return orderChangeItems;
	}

	public void setOrderChangeItems(Set<PurchaseOrderChangeItem> orderChangeItems) {
		this.orderChangeItems = orderChangeItems;
	}

	public Short getStatus() {
		return status;
	}

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

	public Short getAgreed() {
		return agreed;
	}

	public void setAgreed(Short agreed) {
		this.agreed = agreed;
	}

	public String getReplyRemark() {
		return replyRemark;
	}

	public void setReplyRemark(String replyRemark) {
		this.replyRemark = replyRemark;
	}

	public Short getBackStatus() {
		return backStatus;
	}

	public void setBackStatus(Short backStatus) {
		this.backStatus = backStatus;
	}

	public Short getReplySendStatus() {
		return replySendStatus;
	}

	public void setReplySendStatus(Short replySendStatus) {
		this.replySendStatus = replySendStatus;
	}

	public Long getOrderId() {
		return orderId;
	}

	public void setOrderId(Long orderId) {
		this.orderId = orderId;
	}

	public String getOldPayments() {
		return oldPayments;
	}

	public void setOldPayments(String oldPayments) {
		this.oldPayments = oldPayments;
	}

	public String getOldCurrency() {
		return oldCurrency;
	}

	public void setOldCurrency(String oldCurrency) {
		this.oldCurrency = oldCurrency;
	}

	public Float getOldRate() {
		return oldRate;
	}

	public void setOldRate(Float oldRate) {
		this.oldRate = oldRate;
	}

	public String getOrderCode() {
		return orderCode;
	}

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

	public EnterpriseInfo getEnterprise() {
		return enterprise;
	}

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

	public Long getVendUU() {
		return vendUU;
	}

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

	public Long getUserUU() {
		return userUU;
	}

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

	public Long getVendUserUU() {
		return vendUserUU;
	}

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

	public String getApVendorName() {
		return apVendorName;
	}

	public void setApVendorName(String apVendorName) {
		this.apVendorName = apVendorName;
	}

	public String getNewApVendorName() {
		return newApVendorName;
	}

	public void setNewApVendorName(String newApVendorName) {
		this.newApVendorName = newApVendorName;
	}

	@JsonIgnore
	@JSONField(serialize = false)
	public boolean isAgreed() {
		return this.agreed != null && Constant.YES == this.agreed;
	}

	/**
	 * 处理详情
	 * 
	 * @return
	 */
	public String replyDescription() {
		return isAgreed() ? "同意变更" : "不同意变更";
	}

	public Short getUnNeedReply() {
		return unNeedReply == null ? 0 : unNeedReply;
	}

	public void setUnNeedReply(Short unNeedReply) {
		this.unNeedReply = unNeedReply;
	}

	public Long getErpId() {
		return erpId;
	}

	public void setErpId(Long erpId) {
		this.erpId = erpId;
	}

}
