package com.uas.platform.b2b.erp.model;

import com.uas.platform.b2b.model.PurchaseNotice;
import com.uas.platform.b2b.model.PurchaseOrder;
import com.uas.platform.b2b.model.PurchaseOrderItem;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;

import java.util.Date;

/**
 * 买家ERP系统的送货提醒单（提醒卖家发货）
 * 
 * @author yingp
 * 
 */
public class PurchaseNotify {

	/**
	 * 原id，erp id
	 */
	private long pn_id;
	/**
	 * 供应商UU号
	 */
	private long ve_uu;
	/**
	 * 录入日期
	 */
	private Date pn_indate;
	/**
	 * 需求数量
	 */
	private Double pn_qty;
	/**
	 * 要求发货日期
	 */
	private Date pn_delivery;
	/**
	 * 订单编号
	 */
	private String pn_ordercode;
	/**
	 * 订单明细序号
	 */
	private Short pn_orderdetno;
	/**
	 * 备注
	 */
	private String pn_remark;
	/**
	 * 已发货数量
	 */
	private Double pn_endqty;
	private Double pr_zxbzs; // 物料最小包装数
	private Long pn_b2bid; // b2bid

	public long getPn_id() {
		return pn_id;
	}

	public void setPn_id(long pn_id) {
		this.pn_id = pn_id;
	}

	public Date getPn_indate() {
		return pn_indate;
	}

	public void setPn_indate(Date pn_indate) {
		this.pn_indate = pn_indate;
	}

	public Double getPn_qty() {
		return pn_qty;
	}

	public void setPn_qty(Double pn_qty) {
		this.pn_qty = pn_qty;
	}

	public Date getPn_delivery() {
		return pn_delivery;
	}

	public void setPn_delivery(Date pn_delivery) {
		this.pn_delivery = pn_delivery;
	}

	public String getPn_ordercode() {
		return pn_ordercode;
	}

	public void setPn_ordercode(String pn_ordercode) {
		this.pn_ordercode = pn_ordercode;
	}

	public Short getPn_orderdetno() {
		return pn_orderdetno;
	}

	public void setPn_orderdetno(Short pn_orderdetno) {
		this.pn_orderdetno = pn_orderdetno;
	}

	public String getPn_remark() {
		return pn_remark;
	}

	public void setPn_remark(String pn_remark) {
		this.pn_remark = pn_remark;
	}

	public Double getPn_endqty() {
		return pn_endqty;
	}

	public void setPn_endqty(Double pn_endqty) {
		this.pn_endqty = pn_endqty;
	}

	public long getVe_uu() {
		return ve_uu;
	}

	public void setVe_uu(long ve_uu) {
		this.ve_uu = ve_uu;
	}

	public Double getPr_zxbzs() {
		return pr_zxbzs;
	}

	public void setPr_zxbzs(Double pr_zxbzs) {
		this.pr_zxbzs = pr_zxbzs;
	}

	public Long getPn_b2bid() {
		return pn_b2bid;
	}

	public void setPn_b2bid(Long pn_b2bid) {
		this.pn_b2bid = pn_b2bid;
	}

	/**
	 * 转为平台的客户送货提醒
	 * 
	 * @return
	 */
	public PurchaseNotice convert() {
		PurchaseNotice notice = new PurchaseNotice();
		notice.setSourceId(pn_id);
		notice.setDate(pn_indate);
		notice.setDelivery(pn_delivery);
		notice.setEndQty(pn_endqty);
		notice.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		notice.setQty(pn_qty);
		notice.setRemark(pn_remark);
		notice.setVendUU(ve_uu);
		PurchaseOrder order = new PurchaseOrder();
		order.setCode(pn_ordercode);
		PurchaseOrderItem orderItem = new PurchaseOrderItem();
		orderItem.setNumber(pn_orderdetno);
		orderItem.setOrder(order);
		notice.setOrderItem(orderItem);
		notice.setStatus((short) Status.NOT_REPLY.value());
		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
		notice.setMinPackQty(pr_zxbzs);// 物料最小包装数
		notice.setErpDate(new Date());
		return notice;
	}

	/**
	 * 转为平台的客户送货提醒（EDI）
	 *
	 * @return
	 */
	public PurchaseNotice convertEDI(Long enUU) {
		PurchaseNotice notice = new PurchaseNotice();
		notice.setSourceId(pn_id);
		notice.setDate(pn_indate);
		notice.setDelivery(pn_delivery);
		notice.setEndQty(pn_endqty);
		notice.setEnUU(enUU);
		notice.setQty(pn_qty);
		notice.setRemark(pn_remark);
		notice.setVendUU(ve_uu);
		PurchaseOrder order = new PurchaseOrder();
		order.setCode(pn_ordercode);
		PurchaseOrderItem orderItem = new PurchaseOrderItem();
		orderItem.setNumber(pn_orderdetno);
		orderItem.setOrder(order);
		notice.setOrderItem(orderItem);
		notice.setStatus((short) Status.NOT_REPLY.value());
		notice.setSendStatus((short) Status.NOT_UPLOAD.value());
		notice.setMinPackQty(pr_zxbzs);// 物料最小包装数
		notice.setErpDate(new Date());
		return notice;
	}

    /**
     * 将平台的发货提醒封装成ERP系统的发货提醒
     *
     * @param notice 平台发货提醒
     */
	public PurchaseNotify(PurchaseNotice notice) {
        this.pn_b2bid = notice.getId();
        this.pn_id = notice.getSourceId();
	}

	public PurchaseNotify() {}
}
