package com.dev.swms.server.service.receiving;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.dev.swms.server.model.base.ItemKey;
import com.dev.swms.server.model.base.PackageUnit;
import com.dev.swms.server.model.receiving.ReceivedDoc;
import com.dev.swms.server.model.receiving.ReceivingDoc;
import com.dev.swms.server.model.receiving.ReceivingDocDetail;
import com.dev.swms.server.model.rules.LotRule;
import com.dev.energy.server.service.BaseManager;

@Transactional(readOnly=true)
public interface ReceivingDocManager extends BaseManager {
	/**
	 * 保存收货单－新增收货单时自动设置所属仓库和单据状态
	 * @param receivingDoc 待保存的收货单
	 */
	@Transactional
	void storeReceivingDoc(ReceivingDoc receivingDoc);
	
	/**
	 * 激活收货单－只能激活“打开”状态与收货明细不为空的收货单
	 * @param receivingDocIds 待激活的收货单ID清单
	 */
	@Transactional
	void activeAll(List<Long> receivingDocIds);
	
	/**
	 * 取消激活收货单－只能取消激活“生效”状态的收货单
	 * @param receivingDocIds 待取消激活的收货单ID清单
	 */
	@Transactional
	void inactiveAll(List<Long> receivingDocIds);

	/**
	 * 删除收货单－只能删除“打开”状态的收货单
	 * @param receivingDocIds 待删除收货单的ID清单
	 */
	@Transactional
	void deleteAll(List<Long> receivingDocIds);
	
	/**
	 * 关闭收货单－只能关闭“收货中”状态的收货单
	 * @param receivingDocIds
	 */
	@Transactional
	void closeAll(List<Long> receivingDocIds);

	/**
	 * 取消收货单－只能取消“打开”状态的收货单
	 * @param receivingDocIds
	 */
	@Transactional
	void cancelAll(List<Long> receivingDocIds);
	
    /**
     * 新增收货单明细－当receivingDocDetail对象已存在时，则直接修改收货单明细对象
     * @param receivingDocId　待保存的收货单ＩＤ
     * @param receivingDocDetail　待增加的收货单明细
     */
    @Transactional
    void addReceivingDocDetail(Long receivingDocId, ReceivingDocDetail receivingDocDetail);
    
    /**
     * 删除收货单明细
     * @param receivingDocId 待删除明细的收货单ID
     * @param receivingDocDetailIds 待删除的收货单明细ID集合
     */
    @Transactional
    void removeReceivingDocDetail(Long receivingDocId, List<Long> receivingDocDetailIds);
    
     /**
     * 获取指定收货单明细的未收货数量
     * @param map 前台页面参数map
     */
    String getExpectedQuantityByDetail(Map map);
    /**
     * 根据itemkey找到对应收货单明细
     * @param itemKey
     */
    ReceivingDocDetail getReceivingDocDetailByItemKey(ItemKey itemKey);
    
    ReceivingDoc getReceivingDocByCode(String code);
    
    /**
     * RF方法－根据指定收货单的货品编码查找对应的收货单明细
     * @param docId
     * @param itemCode
     * @param type 0-返回找到的第一条单据明细
     *             1-返回找到的第一条未完成收货确认的单据明细
     * @return
     */
    ReceivingDocDetail getReceivingDocDetailByItem(Long docId, String itemCode,int type);
    
    @Transactional
    PackageUnit getUnit(Long detailId);

	ReceivedDoc getReceivedDocByCode(String code,String receivedDocCode, int type);
}
