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

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

import org.apache.commons.collections.CollectionUtils;

import com.uas.platform.b2b.model.PurchaseInquiry;
import com.uas.platform.b2b.model.PurchaseInquiryItem;
import com.uas.platform.b2b.support.SystemSession;

/**
 * 买家ERP系统的采购询价单
 * 
 * @author yingp
 * 
 */
public class Inquiry {

	private String in_code;
	private Date in_date;
	private String in_recorder;
	private String in_auditor;
	private Date in_recorddate;
	private Date in_enddate;
	private String in_remark;
	private List<InquiryDetail> details;

	public String getIn_code() {
		return in_code;
	}

	public void setIn_code(String in_code) {
		this.in_code = in_code;
	}

	public Date getIn_date() {
		return in_date;
	}

	public void setIn_date(Date in_date) {
		this.in_date = in_date;
	}

	public String getIn_recorder() {
		return in_recorder;
	}

	public void setIn_recorder(String in_recorder) {
		this.in_recorder = in_recorder;
	}

	public String getIn_auditor() {
		return in_auditor;
	}

	public void setIn_auditor(String in_auditor) {
		this.in_auditor = in_auditor;
	}

	public Date getIn_recorddate() {
		return in_recorddate;
	}

	public void setIn_recorddate(Date in_recorddate) {
		this.in_recorddate = in_recorddate;
	}

	public Date getIn_enddate() {
		return in_enddate;
	}

	public void setIn_enddate(Date in_enddate) {
		this.in_enddate = in_enddate;
	}

	public String getIn_remark() {
		return in_remark;
	}

	public void setIn_remark(String in_remark) {
		this.in_remark = in_remark;
	}

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

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

	/**
	 * 转为平台的采购询价
	 * 
	 * @return
	 */
	public PurchaseInquiry convert() {
		PurchaseInquiry inquiry = new PurchaseInquiry();
		inquiry.setCode(this.in_code);
		inquiry.setDate(this.in_date);
		inquiry.setEndDate(this.in_enddate);
		inquiry.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		inquiry.setEnterprise(SystemSession.getUser().getEnterprise());
		inquiry.setRecorder(this.in_recorder);
		inquiry.setRemark(this.in_remark);
		if (!CollectionUtils.isEmpty(this.details)) {
			Set<PurchaseInquiryItem> inquiryItems = new HashSet<PurchaseInquiryItem>();
			for (InquiryDetail detail : details) {
				inquiryItems.add(detail.convert());
			}
			inquiry.setInquiryItems(inquiryItems);
		}
		return inquiry;
	}

}
