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.MakeOrderChangeItem;
import com.uas.platform.b2b.model.PurchaseOrderChange;
import com.uas.platform.b2b.model.PurchaseOrderChangeItem;

/**
 * ERP系统的客户采购订单变更单
 * 
 * @author yingp
 * 
 */
public class SaleDownChange {

	private long b2b_pc_id;
	private String sc_code;
	private String sc_sacode;
	private long sc_custuu;
	private Date sc_indate;
	private String sc_recorder;
	private String sc_newpayments;
	private String sc_newcurrency;
	private Float sc_newrate;
	private String sc_description;
	private String sc_remark;
	private Short sc_agreed;
	private Short sc_unNeedReply;
	private List<SaleDownChangeDetail> changeDetails;

	public long getB2b_pc_id() {
		return b2b_pc_id;
	}

	public void setB2b_pc_id(long b2b_pc_id) {
		this.b2b_pc_id = b2b_pc_id;
	}

	public String getSc_code() {
		return sc_code;
	}

	public void setSc_code(String sc_code) {
		this.sc_code = sc_code;
	}

	public Date getSc_indate() {
		return sc_indate;
	}

	public void setSc_indate(Date sc_indate) {
		this.sc_indate = sc_indate;
	}

	public String getSc_remark() {
		return sc_remark;
	}

	public void setSc_remark(String sc_remark) {
		this.sc_remark = sc_remark;
	}

	public String getSc_recorder() {
		return sc_recorder;
	}

	public void setSc_recorder(String sc_recorder) {
		this.sc_recorder = sc_recorder;
	}

	public String getSc_newpayments() {
		return sc_newpayments;
	}

	public void setSc_newpayments(String sc_newpayments) {
		this.sc_newpayments = sc_newpayments;
	}

	public String getSc_newcurrency() {
		return sc_newcurrency;
	}

	public void setSc_newcurrency(String sc_newcurrency) {
		this.sc_newcurrency = sc_newcurrency;
	}

	public Float getSc_newrate() {
		return sc_newrate;
	}

	public void setSc_newrate(Float sc_newrate) {
		this.sc_newrate = sc_newrate;
	}

	public String getSc_description() {
		return sc_description;
	}

	public void setSc_description(String sc_description) {
		this.sc_description = sc_description;
	}

	public String getSc_sacode() {
		return sc_sacode;
	}

	public void setSc_sacode(String sc_sacode) {
		this.sc_sacode = sc_sacode;
	}

	public long getSc_custuu() {
		return sc_custuu;
	}

	public void setSc_custuu(long sc_custuu) {
		this.sc_custuu = sc_custuu;
	}

	public List<SaleDownChangeDetail> getChangeDetails() {
		return changeDetails;
	}

	public void setChangeDetails(List<SaleDownChangeDetail> changeDetails) {
		this.changeDetails = changeDetails;
	}

	public Short getSc_agreed() {
		return sc_agreed;
	}

	public void setSc_agreed(Short sc_agreed) {
		this.sc_agreed = sc_agreed;
	}

	public Short getSc_unNeedReply() {
		return sc_unNeedReply;
	}

	public void setSc_unNeedReply(Short sc_unNeedReply) {
		this.sc_unNeedReply = sc_unNeedReply;
	}

	public SaleDownChange() {
	}

	/**
	 * 从平台的采购变更单，转到卖家ERP的客户采购变更单
	 * 
	 * @param orderChange
	 *            平台的采购变更单
	 */
	public SaleDownChange(PurchaseOrderChange orderChange) {
		this.b2b_pc_id = orderChange.getId();
		this.sc_code = orderChange.getCode();
		this.sc_sacode = orderChange.getOrderCode();
		this.sc_custuu = orderChange.getEnUU();
		this.sc_indate = orderChange.getDate();
		this.sc_remark = orderChange.getRemark();
		this.sc_description = orderChange.getDescription();
		this.sc_newcurrency = orderChange.getNewCurrency();
		this.sc_newrate = orderChange.getNewRate();
		this.sc_newpayments = orderChange.getNewPayments();
		this.sc_recorder = orderChange.getRecorder();
		this.sc_unNeedReply = orderChange.getUnNeedReply();
		this.sc_agreed = orderChange.getAgreed();
		if (!CollectionUtils.isEmpty(orderChange.getOrderChangeItems())) {
			List<SaleDownChangeDetail> details = new ArrayList<SaleDownChangeDetail>();
			for (PurchaseOrderChangeItem changeItem : orderChange.getOrderChangeItems()) {
				details.add(new SaleDownChangeDetail(changeItem));
			}
			this.changeDetails = details;
		}
	}
	
	/**
	 * 委外变更单 -> 卖方ERP的采购变更单
	 * @param item
	 */
	public SaleDownChange(MakeOrderChangeItem item) {
		this.b2b_pc_id = item.getId();
		this.sc_agreed = 1;
		this.sc_code = item.getOrderChange().getCode();
		this.sc_sacode = item.getOrderCode();
		this.sc_custuu = item.getOrderChange().getEnUU();
		this.sc_indate = item.getOrderChange().getDate();
		this.sc_remark = item.getOrderChange().getRemark();
		this.sc_recorder = item.getOrderChange().getRecorder();
		List<SaleDownChangeDetail> details = new ArrayList<SaleDownChangeDetail>();
		details.add(new SaleDownChangeDetail(item));
		this.changeDetails = details;
	}

}