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

import com.uas.platform.b2b.model.*;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * 采购方角度ERP委外验收单
 * 
 * @author aof
 * @date 2015年8月17日
 */
public class MakeProdInOut {

	/**
	 * erp出入库单据的id
	 */
	private Long pi_id;

	/**
	 * erp出入库单据单号
	 */
	private String pi_inoutno;

	/**
	 * 供应商UU
	 */
	private Long pi_vendoruu;

	/**
	 * 币别
	 */
	private String pi_currency;

	/**
	 * 汇率
	 */
	private Float pi_rate;

	/**
	 * 付款方式
	 */
	private String pi_payment;

	/**
	 * 运输方式
	 */
	private String pi_transport;

	/**
	 * 备注
	 */
	private String pi_remark;

	/**
	 * 过账人
	 */
	private String pi_inoutman;

	/**
	 * 过账日期
	 */
	private Date pi_date;

	/**
	 * 送货单号
	 */
	private String pi_sendcode;

	/**
	 * 应付供应商名
	 */
	private String pi_receivename;

	/**
	 * 应付供应商编号
	 */
	private String pi_receivecode;

	/**
	 * 明细
	 */
	private List<MakeProdInOutDetail> details;

	/**
	 * b2bId
	 */
	private Long pi_b2b_id;

	public Long getPi_id() {
		return pi_id;
	}

	public void setPi_id(Long pi_id) {
		this.pi_id = pi_id;
	}

	public String getPi_inoutno() {
		return pi_inoutno;
	}

	public void setPi_inoutno(String pi_inoutno) {
		this.pi_inoutno = pi_inoutno;
	}

	public Long getPi_vendoruu() {
		return pi_vendoruu;
	}

	public void setPi_vendoruu(Long pi_vendoruu) {
		this.pi_vendoruu = pi_vendoruu;
	}

	public String getPi_currency() {
		return pi_currency;
	}

	public void setPi_currency(String pi_currency) {
		this.pi_currency = pi_currency;
	}

	public Float getPi_rate() {
		return pi_rate;
	}

	public void setPi_rate(Float pi_rate) {
		this.pi_rate = pi_rate;
	}

	public String getPi_payment() {
		return pi_payment;
	}

	public void setPi_payment(String pi_payment) {
		this.pi_payment = pi_payment;
	}

	public String getPi_transport() {
		return pi_transport;
	}

	public void setPi_transport(String pi_transport) {
		this.pi_transport = pi_transport;
	}

	public String getPi_remark() {
		return pi_remark;
	}

	public void setPi_remark(String pi_remark) {
		this.pi_remark = pi_remark;
	}

	public String getPi_inoutman() {
		return pi_inoutman;
	}

	public void setPi_inoutman(String pi_inoutman) {
		this.pi_inoutman = pi_inoutman;
	}

	public Date getPi_date() {
		return pi_date;
	}

	public void setPi_date(Date pi_date) {
		this.pi_date = pi_date;
	}

	public String getPi_sendcode() {
		return pi_sendcode;
	}

	public void setPi_sendcode(String pi_sendcode) {
		this.pi_sendcode = pi_sendcode;
	}

	public String getPi_receivecode() {
		return pi_receivecode;
	}

	public void setPi_receivecode(String pi_receivecode) {
		this.pi_receivecode = pi_receivecode;
	}

	public String getPi_receivename() {
		return pi_receivename;
	}

	public void setPi_receivename(String pi_receivename) {
		this.pi_receivename = pi_receivename;
	}

	public List<MakeProdInOutDetail> getDetails() {
		return details;
	}

	public void setDetails(List<MakeProdInOutDetail> details) {
		this.details = details;
	}

	public Long getPi_b2b_id() {
		return pi_b2b_id;
	}

	public void setPi_b2b_id(Long pi_b2b_id) {
		this.pi_b2b_id = pi_b2b_id;
	}

	public MakeAccept convent() {
		MakeAccept accept = new MakeAccept();
		accept.setErpId(this.pi_id);
		accept.setCode(this.pi_inoutno);
		accept.setVendUU(this.pi_vendoruu);
		accept.setCurrency(this.pi_currency);
		accept.setRate(this.pi_rate);
		accept.setPayments(this.pi_payment);
		accept.setRemark(this.pi_remark);
		accept.setRecorder(this.pi_inoutman);
		accept.setDate(this.pi_date);
		accept.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		accept.setEnterprise(new EnterpriseInfo(SystemSession.getUser().getEnterprise()));
		accept.setSendCode(this.pi_sendcode);
		accept.setReceiveName(this.pi_receivename);
		accept.setReceiveCode(this.pi_receivecode);
		accept.setSendStatus((short) Status.NOT_UPLOAD.value());
		if (!CollectionUtils.isEmpty(this.details)) {
			Set<MakeAcceptItem> acceptItems = new HashSet<MakeAcceptItem>();
			for (MakeProdInOutDetail detail : this.details) {
				acceptItems.add(detail.convent());
			}
			accept.setAcceptItems(acceptItems);
		}
		return accept;
	}

	public MakeReturn conventToReturn() {
		MakeReturn makeReturn = new MakeReturn();
		makeReturn.setErpId(this.pi_id);
		makeReturn.setCode(this.pi_inoutno);
		makeReturn.setVendUU(this.pi_vendoruu);
		makeReturn.setCurrency(this.pi_currency);
		makeReturn.setRate(this.pi_rate);
		makeReturn.setPayments(this.pi_payment);
		makeReturn.setRemark(this.pi_remark);
		makeReturn.setRecorder(this.pi_inoutman);
		makeReturn.setDate(this.pi_date);
		makeReturn.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		makeReturn.setSendCode(this.pi_sendcode);
		makeReturn.setReceiveName(this.pi_receivename);
		makeReturn.setReceiveCode(this.pi_receivecode);
		makeReturn.setSendStatus((short) Status.NOT_UPLOAD.value());
		if (!CollectionUtils.isEmpty(this.details)) {
			Set<MakeReturnItem> returnItems = new HashSet<MakeReturnItem>();
			for (MakeProdInOutDetail detail : this.details) {
				returnItems.add(detail.conventToReturn());
			}
			makeReturn.setReturnItems(returnItems);
		}
		return makeReturn;
	}
}
