package com.dev.swms.server.model.inventory;

import java.util.Date;
import java.util.Set;

import org.apache.commons.lang.builder.EqualsBuilder;
import org.apache.commons.lang.builder.HashCodeBuilder;

import com.dev.swms.server.model.base.Location;
import com.dev.swms.server.model.base.Warehouse;
import com.dev.energy.server.model.Entity;

/**
 * 托盘管理采用先收货，后码托，再上架的方式
 * @author  dev
 *
 */
public class Stock extends Entity {
	private static final long serialVersionUID = 5102527806241244092L;
	/** 所属仓库 */
	private Warehouse warehouse;
	/** 托盘号 */
	private String LP;
	/** 托盘类型（StockType） */
	private String type;
	/** 货品数(基本单位数量) */
	private double itemQty;
	/** 重量 */
	private double weight;
	/** 体积 */
	private double volume;
	/** 放置库位 */
	private Location location;
	/** 库位托盘排序号 */
	private int locationIndex;
	/** 托盘上库存数量 */
	private double inventoryQty;
	/** 附注 */
	private String remark;
	/** 单层码放数 */
	private double tierQty;
	/** 堆高层数 */
	private double stackHighQty;
	/** 是否失效 */
	private boolean enabled = true;
	/** 包含库存 */
	private Set<Inventory> inventories;
	
	private int validity;//货品效期
	private String describe;//描述
	private String creatPeople;//创建人
	private Date creatDate;//创建时间
	
	
	
	
	
	public String getDescribe() {
		return describe;
	}

	public void setDescribe(String describe) {
		this.describe = describe;
	}

	public String getCreatPeople() {
		return creatPeople;
	}

	public void setCreatPeople(String creatPeople) {
		this.creatPeople = creatPeople;
	}

	public Date getCreatDate() {
		return creatDate;
	}

	public void setCreatDate(Date creatDate) {
		this.creatDate = creatDate;
	}

	public int getValidity() {
		return validity;
	}

	public void setValidity(int validity) {
		this.validity = validity;
	}

	@Override
	public boolean equals(final Object other) {
		if (!(other instanceof Stock))
			return false;
		Stock castOther = (Stock) other;
		return new EqualsBuilder().append(warehouse, castOther.warehouse)
				.append(LP, castOther.LP).isEquals();
	}

	@Override
	public int hashCode() {
		return new HashCodeBuilder().append(warehouse).append(LP).toHashCode();
	}

	public Stock() {
		super();
	}
	
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	public Set<Inventory> getInventories() {
		return inventories;
	}
	public void setInventories(Set<Inventory> inventories) {
		this.inventories = inventories;
	}
	public double getInventoryQty() {
		return inventoryQty;
	}
	public void setInventoryQty(double inventoryQty) {
		this.inventoryQty = inventoryQty;
	}
	public double getWeight() {
		return weight;
	}
	public void setWeight(double weight) {
		this.weight = weight;
	}
	public double getVolume() {
		return volume;
	}
	public void setVolume(double volume) {
		this.volume = volume;
	}
	public Warehouse getWarehouse() {
		return warehouse;
	}
	public void setWarehouse(Warehouse warehouse) {
		this.warehouse = warehouse;
	}
	public int getLocationIndex() {
		return locationIndex;
	}
	public void setLocationIndex(int locationIndex) {
		this.locationIndex = locationIndex;
	}
	public String getRemark() {
		return remark;
	}
	public void setRemark(String remark) {
		this.remark = remark;
	}
	public double getItemQty() {
		return itemQty;
	}
	public void setItemQty(double itemQty) {
		this.itemQty = itemQty;
	}
	public String getLP() {
		return LP;
	}
	public void setLP(String lp) {
		LP = lp;
	}
	public Location getLocation() {
		return location;
	}
	public void setLocation(Location location) {
		this.location = location;
	}
	public boolean isEnabled() {
		return enabled;
	}
	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}
	
	//增加托盘中的库存数量
	public void addInventoryQty(double quantity) {
		this.inventoryQty += quantity;
	}
	
	//扣减托盘中的库存数量
	public void removeInventoryQty(double quantity) {
		this.inventoryQty -= quantity;
/*		if (this.getInventoryQty() <= 0 
				&& StockType.PALLET.equals(this.type)) {
			this.setEnabled(false);
			//对不可回收托盘，要去掉moveDocDetail\Task\TaskLog中的外键关联
			ListableBeanFactory lbf = (ListableBeanFactory) SecurityContextHolder.getCurrentSession().getServletContext().getAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE);
			InventoryManager inventoryManager = (InventoryManager)lbf.getBean("inventoryManager");
			inventoryManager.removeLPRelations(this);
		}
*/	}

	public double getTierQty() {
		return tierQty;
	}

	public void setTierQty(double tierQty) {
		this.tierQty = tierQty;
	}

	public double getStackHighQty() {
		return stackHighQty;
	}

	public void setStackHighQty(double stackHighQty) {
		this.stackHighQty = stackHighQty;
	}
}
