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

import java.util.Date;
import java.util.Objects;

import org.apache.commons.collections.CollectionUtils;

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

/**
 * 数据传送到移动端的轻量级实体类 <br>
 * 收到的客户采购订单
 * 
 * @author yingp
 *
 */
public class Purchase {

	/**
	 * ID
	 */
	private long pu_id;
	/**
	 * 订单号
	 */
	private String pu_code;
	/**
	 * 日期
	 */
	private Date pu_date;
	/**
	 * 备注
	 */
	private String pu_remark;
	/**
	 * 币种
	 */
	private String pu_currency;
	/**
	 * 汇率
	 */
	private Float pu_rate;
	/**
	 * 付款方式
	 */
	private String pu_payments;
	/**
	 * 交货地址
	 */
	private String pu_address;
	/**
	 * 采购方企业
	 */
	private String en_name;
	/**
	 * 供应商企业名称
	 */
	private String vendName;
	/**
	 * 金额
	 */
	private Double pu_total;

	public long getPu_id() {
		return pu_id;
	}

	public void setPu_id(long pu_id) {
		this.pu_id = pu_id;
	}

	public String getPu_code() {
		return pu_code;
	}

	public void setPu_code(String pu_code) {
		this.pu_code = pu_code;
	}

	public Date getPu_date() {
		return pu_date;
	}

	public void setPu_date(Date pu_date) {
		this.pu_date = pu_date;
	}

	public String getPu_remark() {
		return pu_remark;
	}

	public void setPu_remark(String pu_remark) {
		this.pu_remark = pu_remark;
	}

	public String getPu_currency() {
		return pu_currency;
	}

	public void setPu_currency(String pu_currency) {
		this.pu_currency = pu_currency;
	}

	public Float getPu_rate() {
		return pu_rate;
	}

	public void setPu_rate(Float pu_rate) {
		this.pu_rate = pu_rate;
	}

	public String getPu_payments() {
		return pu_payments;
	}

	public void setPu_payments(String pu_payments) {
		this.pu_payments = pu_payments;
	}

	public String getPu_address() {
		return pu_address;
	}

	public void setPu_address(String pu_address) {
		this.pu_address = pu_address;
	}

	public String getEn_name() {
		return en_name;
	}

	public void setEn_name(String en_name) {
		this.en_name = en_name;
	}

	public Double getPu_total() {
		return pu_total;
	}

	public void setPu_total(Double pu_total) {
		this.pu_total = pu_total;
	}

	public String getVendName() {
		return vendName;
	}

	public void setVendName(String vendName) {
		this.vendName = vendName;
	}

	public Purchase() {
	}

	/**
	 * 转为移动端客户采购单
	 * 
	 * @param order
	 */
	public Purchase(PurchaseOrderAll order) {
		this.pu_address = order.getShipAddress();
		this.pu_code = order.getCode();
		this.pu_currency = order.getCurrency();
		this.pu_rate = order.getRate();
		this.pu_payments = order.getPayments();
		this.pu_remark = order.getRemark();
		this.en_name = order.getEnterprise().getEnName();
		this.pu_id = order.getId();
		this.pu_date = order.getDate();
		this.pu_total = 0.0;
		if (!CollectionUtils.isEmpty(order.getOrderItems())) {
			for (PurchaseOrderAllItem item : order.getOrderItems()) {
				this.pu_total += item.getAmount();
			}
		}
		// 取到多个企业的单据，需要切换供应商名字
		if(!Objects.equals(order.getVendUU(), SystemSession.getUser().getEnterprise().getUu())) {
			SystemSession.getUser().setCurrentEnterprise(order.getVendUU());
		}
		this.vendName = SystemSession.getUser().getEnterprise().getEnName();
	}
}
