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.SaleQuotation;
import com.uas.platform.b2b.model.SaleQuotationItem;
import com.uas.platform.b2b.support.SystemSession;
import com.uas.platform.core.model.Status;

/**
 * 供应商主动报价
 * 
 * @author yingp
 *
 */
public class Quotation {

	private long cu_uu;
	private Long qu_custcontactuu;
	private String qu_custcontact;
	private Long qu_useruu;
	private String qu_code;
	private Date qu_recorddate;
	private Date qu_enddate;
	private String qu_currency;
	private Float qu_rate;
	private Float qu_taxrate;
	private String qu_remark;
	private List<QuotationDetail> details;

	public long getCu_uu() {
		return cu_uu;
	}

	public void setCu_uu(long cu_uu) {
		this.cu_uu = cu_uu;
	}
	
	public Long getQu_useruu() {
		return qu_useruu;
	}

	public void setQu_useruu(Long qu_useruu) {
		this.qu_useruu = qu_useruu;
	}

	public String getQu_code() {
		return qu_code;
	}

	public void setQu_code(String qu_code) {
		this.qu_code = qu_code;
	}

	public Date getQu_recorddate() {
		return qu_recorddate;
	}

	public void setQu_recorddate(Date qu_recorddate) {
		this.qu_recorddate = qu_recorddate;
	}

	public Date getQu_enddate() {
		return qu_enddate;
	}

	public void setQu_enddate(Date qu_enddate) {
		this.qu_enddate = qu_enddate;
	}

	public String getQu_currency() {
		return qu_currency;
	}

	public void setQu_currency(String qu_currency) {
		this.qu_currency = qu_currency;
	}

	public Float getQu_rate() {
		return qu_rate;
	}

	public void setQu_rate(Float qu_rate) {
		this.qu_rate = qu_rate;
	}

	public Float getQu_taxrate() {
		return qu_taxrate;
	}

	public void setQu_taxrate(Float qu_taxrate) {
		this.qu_taxrate = qu_taxrate;
	}

	public String getQu_remark() {
		return qu_remark;
	}

	public void setQu_remark(String qu_remark) {
		this.qu_remark = qu_remark;
	}

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

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

	public Long getQu_custcontactuu() {
		return qu_custcontactuu;
	}

	public void setQu_custcontactuu(Long qu_custcontactuu) {
		this.qu_custcontactuu = qu_custcontactuu;
	}

	public String getQu_custcontact() {
		return qu_custcontact;
	}

	public void setQu_custcontact(String qu_custcontact) {
		this.qu_custcontact = qu_custcontact;
	}

	/**
	 * 供应商ERP的主动报价单，转为平台的报价单
	 * 
	 * @return
	 */
	public SaleQuotation convert() {
		SaleQuotation quotation = new SaleQuotation();
		quotation.setCode(this.qu_code);
		quotation.setCurrency(this.qu_currency);
		quotation.setCustUserUU(this.qu_custcontactuu);
		quotation.setCustUU(this.cu_uu);
		quotation.setDate(this.qu_recorddate);
		quotation.setEndDate(this.qu_enddate);
		quotation.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		quotation.setUserUU(this.getQu_useruu());
		quotation.setRate(this.qu_rate);
		quotation.setRemark(this.qu_remark);
		quotation.setSendStatus((short) Status.NOT_UPLOAD.value());
		quotation.setTaxrate(this.qu_taxrate);
		Set<SaleQuotationItem> quotationItems = new HashSet<SaleQuotationItem>();
		if (!CollectionUtils.isEmpty(this.details)) {
			for (QuotationDetail detail : this.details)
				quotationItems.add(detail.convert());
		}
		quotation.setQuotationItems(quotationItems);
		return quotation;
	}

	

}
