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

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.util.CollectionUtils;

import com.uas.platform.b2b.model.PurchaseOrderAll;
import com.uas.platform.b2b.model.PurchaseOrderAllItem;

public class SaleDown {

	/**
	 * 平台订单ID，传入供应商的ERP。可供写入时检测，防止重复传的问题
	 */
	private long b2b_pu_id;
	private String sa_code;
	private String sa_pocode;
	private Long sa_customeruu;// 客户UU
	private String sa_custcontact;// 客户联系人
	private Long sa_custcontactuu;// 客户联系人UU
	private String sa_custmobile;// 客户联系人手机号
	private Long sa_useruu;// 企业业务员UU
	private Date sa_date;
	private Date sa_recorddate;
	private String sa_payments;
	private String sa_currency;
	private Float sa_rate;
	private String sa_shipby;
	private List<SaleDownDetail> saleDownDetails;

	public long getB2b_pu_id() {
		return b2b_pu_id;
	}

	public void setB2b_pu_id(long b2b_pu_id) {
		this.b2b_pu_id = b2b_pu_id;
	}

	public String getSa_code() {
		return sa_code;
	}

	public void setSa_code(String sa_code) {
		this.sa_code = sa_code;
	}

	public String getSa_pocode() {
		return sa_pocode;
	}

	public void setSa_pocode(String sa_pocode) {
		this.sa_pocode = sa_pocode;
	}

	public Long getSa_customeruu() {
		return sa_customeruu;
	}

	public void setSa_customeruu(Long sa_customeruu) {
		this.sa_customeruu = sa_customeruu;
	}

	public Date getSa_date() {
		return sa_date;
	}

	public void setSa_date(Date sa_date) {
		this.sa_date = sa_date;
	}

	public Date getSa_recorddate() {
		return sa_recorddate;
	}

	public void setSa_recorddate(Date sa_recorddate) {
		this.sa_recorddate = sa_recorddate;
	}

	public String getSa_payments() {
		return sa_payments;
	}

	public void setSa_payments(String sa_payments) {
		this.sa_payments = sa_payments;
	}

	public String getSa_currency() {
		return sa_currency;
	}

	public void setSa_currency(String sa_currency) {
		this.sa_currency = sa_currency;
	}

	public Float getSa_rate() {
		return sa_rate;
	}

	public void setSa_rate(Float sa_rate) {
		this.sa_rate = sa_rate;
	}

	public String getSa_shipby() {
		return sa_shipby;
	}

	public void setSa_shipby(String sa_shipby) {
		this.sa_shipby = sa_shipby;
	}

	public List<SaleDownDetail> getSaleDownDetails() {
		return saleDownDetails;
	}

	public void setSaleDownDetails(List<SaleDownDetail> saleDownDetails) {
		this.saleDownDetails = saleDownDetails;
	}

	public Long getSa_useruu() {
		return sa_useruu;
	}

	public void setSa_useruu(Long sa_useruu) {
		this.sa_useruu = sa_useruu;
	}

	public String getSa_custcontact() {
		return sa_custcontact;
	}

	public void setSa_custcontact(String sa_custcontact) {
		this.sa_custcontact = sa_custcontact;
	}

	public Long getSa_custcontactuu() {
		return sa_custcontactuu;
	}

	public void setSa_custcontactuu(Long sa_custcontactuu) {
		this.sa_custcontactuu = sa_custcontactuu;
	}

	public String getSa_custmobile() {
		return sa_custmobile;
	}

	public void setSa_custmobile(String sa_custmobile) {
		this.sa_custmobile = sa_custmobile;
	}

	public SaleDown() {
	}

	/**
	 * 从平台的采购订单，转到卖家ERP的订单下达
	 * 
	 * @param order
	 *            平台的采购订单
	 */
	public SaleDown(PurchaseOrderAll order) {
		this.b2b_pu_id = order.getId();
		this.sa_code = order.getCode();
		this.sa_customeruu = order.getEnUU();
		this.sa_custcontactuu = order.getUserUU();//存在单据采购员UU为单据采购员UU，否则为系统在平台新增的客户企业的一个用户
		this.sa_custcontact = order.getUser().getUserName();
		this.sa_custmobile = order.getUser().getUserTel();
		this.sa_useruu = order.getVendUserUU();//单据上的供应商联系人 || 平台上供应商资料信息中的联系人
		this.sa_currency = order.getCurrency();
		this.sa_rate = order.getRate();
		this.sa_date = order.getDate();
		this.sa_pocode = order.getCode();
		this.sa_shipby = order.getShipAddress();
		this.sa_recorddate = new Date();
		this.sa_payments = order.getPayments();
		if (!CollectionUtils.isEmpty(order.getOrderItems())) {
			List<SaleDownDetail> details = new ArrayList<SaleDownDetail>();
			for (PurchaseOrderAllItem item : order.getOrderItems()) {
				details.add(new SaleDownDetail(item));
			}
			this.saleDownDetails = details;
		}
	}

}
