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

import java.io.File;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.transaction.annotation.Transactional;

import com.dev.swms.server.model.abstractEntity.BomAccount;
import com.dev.swms.server.model.abstractEntity.PlanPickDetail;
import com.dev.swms.server.model.abstractEntity.PlanPickTicket;
import com.dev.swms.server.model.abstractEntity.ProductionPlan;
import com.dev.swms.server.model.abstractEntity.SpareParts;
import com.dev.swms.server.model.base.ItemKey;
import com.dev.swms.server.model.base.Location;
import com.dev.swms.server.model.base.WarehouseArea;
import com.dev.swms.server.model.inventory.Inventory;
import com.dev.swms.server.model.inventory.InventoryLog;
import com.dev.swms.server.model.receiving.ASN;
import com.dev.swms.server.model.shipping.BOL;
import com.dev.swms.server.model.shipping.MasterBOL;
import com.dev.swms.server.model.shipping.PickTicket;
import com.dev.swms.server.model.shipping.PickTicketDetail;
import com.dev.swms.server.model.shipping.Prewave;

import net.sf.json.JSONObject;

import com.dev.energy.server.service.BaseManager;

/**
 * @author  dev
 * 
 */
@Transactional(readOnly = true)
public interface PickKamsManager extends BaseManager {

	/**
	 * 保存拣货单－新增拣货单时自动设置所属仓库和单据状态
	 * 
	 * @param pickTicket
	 *            待保存的拣货单
	 */
	@Transactional
	void storePickTicket(PickTicket pickTicket);

	/**
	 * 激活发货单－只能激活“打开”状态的发货单
	 * 
	 * @param pickTicketIds
	 *            待激活的发货单ID清单
	 */
	@Transactional
	void activeAll(List<Long> pickTicketIds);
	@Transactional
	void appPlamAssemblys(PickTicket pt,BomAccount bomAccount,String bonded,String meg);
	@Transactional
	void activeAll(Long pickTicketId);
	

	@Transactional
	void inactiveAllTask(List<Long> pickTicketIds);
	
	/**
	 * 删除拣货单－只能删除“打开”状态的拣货单
	 * 
	 * @param pickTicketIds
	 *            待删除拣货单的ID清单
	 */
	@Transactional
	void deleteAll(List<Long> pickTicketIds);
	
	/**取消备货计划*/
	@Transactional
    void cancelPlanPick(List<Long> ids);

	/**
	 * 取消拣货单－只能取消“打开”状态的拣货单
	 * 
	 * @param pickTicketIds
	 *            待取消拣货单的ID清单
	 */
	@Transactional
	void cancelAll(List<Long> pickTicketIds);

	/**
	 * 新增拣货单明细－当PickTicketDetail对象已存在时，则直接修改拣货单明细对象
	 * 
	 * @param pickTicketId
	 *            待保存的拣货单ＩＤ
	 * @param pickTicketDetail
	 *            待增加的拣货单明细
	 */
	@Transactional
	void addPickTicketDetail(Long pickTicketId,
			PickTicketDetail pickTicketDetail);
	
	@Transactional
	void addPickTicketDetails(Long pickTicketId,List<Long> ids);

	/**
	 * 删除拣货单明细
	 * 
	 * @param pickTicket
	 *            待删除明细的拣货单ID
	 * @param pickTicketDetailIds
	 *            待删除的拣货单明细ID集合
	 */
	@Transactional
	void removePickTicketDetail(Long pickTicketId,
			List<Long> pickTicketDetailIds);
	
	
	@Transactional
	void removePlanPickTicketDetail(Long pickTicketId,
			List<Long> planPickTicketDetailIds);

	/**
	 * 对已分配的发货单取消分配
	 * @param pickTicketIds
	 */
	@Transactional
	void unallocate(List<Long> pickTicketIds);


	/**
	 * 生成BOL
	 * 
	 * @param BOL
	 * @param pickTicketIds 相关pickTicket
	 */
//	@Transactional
//	void createBOL(BOL BOL,List<Long> pickTicketIds);
	/**
	 * 保存BOL
	 * 
	 * @param BOL
	 * @param pickTicketIds
	 */
	@Transactional
	void storeBOL(BOL BOL);

	MasterBOL getMasterBOLbyCode(String code);

	/**
	 * 拣货确认－对指定的发货单拣货记录中未拣货的记录进行拣货
	 * 
	 * @param taskId 
	 * @param srcLocId
	 * @param srcLp
	 * @param lot
	 * @param packageUnitId
	 * @param pickedQuantity
	 * @param workerId
	 */
	@Transactional
	void pickConfirm(Long taskId, Long srcLocId, String srcLp, String lot, Long packageUnitId, double pickedQuantity,double weight, Long workerId);
	@Transactional
	void pickKamsForSys(Long taskId, double pickedQuantity, Long workerId);
	@Transactional
	JSONObject pickKamsForApp(Long ptId, String xpp,String operator,String tph,String bhr);
	/**
	 * 发动机扫描确认
	 * */
	@Transactional
	JSONObject pickKamsForFdj(Long ptId, String ewm,String operator,String bhr) ;
	@Transactional
	void shipConfirmKAMS(List<Long> pickIds);
	@Transactional
	void shipConfirmTphKAMS(Long pt_id,List<Long> ids,String cph,String oper);
	/**
	 * 拣货确认－对指定的发货单拣货记录中未拣货的记录进行拣货
	 * @param taskId
	 * @param pickedQuantity
	 * @param workerId
	 */
	@Transactional
	void pickConfirm(Long taskId, double pickedQuantity, Long workerId);
	
	/**
	 * 拣货确认－对指定的发货单进行拣货
	 * 
	 * @param pickedId
	 * @param workerId
	 */
	@Transactional
	void pickConfirm(Long pickTicketId, Long workerId);
	
	@Transactional
	void willShip(List<Long> ids, Long dockId, Date shipDateStart, Date shipDateEnd);
	
	/**
	 * 发货单整单退拣
	 * @param pickTicketId
	 */
	@Transactional
	void pickedBack(Long pickTicketId);
	
	/**
	 * 发货单批量退拣
	 */
	@Transactional
	void pickedBack(Long pickTicketId, List<Long> taskLogIds);
	
	/**
	 * 发货单批量退拣
	 */
	@Transactional
	void pickedBackXpp(Long pickTicketId, List<Long> taskLogIds);
	
	/**
	 *发货单部分退拣
	*/
	@Transactional
	void pickedBackForSys(Long pickTicketId, Long taskLogId,Double movedQuantity);
	/**
	 *发货单部分退拣
	*/
	@Transactional
	void pickedBack(Long pickTicketId, Long taskLogId, Double pickQty,String operName,Long xpp_id);
	
	/**批量拣货确认*/
	@Transactional
	void multiPickConfirm(List<Long> ids);
	/**装车单-批量拣货确认*/
	@Transactional
	void multiPickConfirmForBOL(List<Long> ids);
	
	@Transactional
	void shipconfirm(List<Long> ids,double fytps,String shipmentType,String cphorkddh,Date shipDate);//发运确认

	/**取消分配*/
	@Transactional
	void cancellAllocate(List<Long> ids);
	
	/**退货*/
	@Transactional
	void returnGoods(Long pickTicketId,Map map);
	
	/** 导入 **/
	@Transactional
	void importPickTicket(File file);
	/** 导入 **/
	@Transactional
	void importPickTicketKAMS(Long pickId,File file);
	@Transactional
	void appAllocate(List<Long> pickTicketIds);
	/** 备货登记 **/
	@Transactional
	void confirmShip(Long pickId, Map qtys) ;
	/** 备货登记 **/
	@Transactional
	void confirmKAMSShip(Long pickId, Map qtys) ;
	/** 备货登记 **/
	@Transactional
	void confirmKAMSShipQT(Long pickId) ;
	/** 发运登记**/
	@Transactional
	void confirmShip(Long pickId) ;
	/** 发运登记**/
	@Transactional
	void confirmKAMSShip(Long pickId) ;
	/** 其他出库取消**/
	@Transactional
	void cancelShipKamsQt(Long pickId);
	
	/** 取消备货 **/
	@Transactional
	void cancelPick(Long pickId) ;
	/** 取消发货 **/
	@Transactional
	void cancelShip(Long pickId) ;
	@Transactional
	void appPlanPickTicket(List<Long> pickTicketIds);
	
	@Transactional
	void storePlanPickTicket(PlanPickTicket p);
	
	//成套生成出库单
	@Transactional
	void addpick(Map clientParams,List<Long>  id);
	
	//成套生成预备货
		@Transactional
		void addPlanPick(Map clientParams,List<Long>  id);
	
	//生成出库任务
	@Transactional
	void appPlanAssembly(List<Long> pickTicketIds,int fs1,int fs2,int fs3);
//	@Transactional
	void addpickTicketSCRJHPageer(Long id,double qty1);
	//生成拖拉机出库计划
	@Transactional
	void appPlanTLJ(List<Long> pickTicketIds);
	//获取起始机号
	@Transactional
	String getByJhMap(Map map);
	//耗用
	@Transactional
	void deleteProductionPlan(Long id,String tsr,double qty,String procedure);
	//完成品备货
	@Transactional
	void addpickTicketPlan_zs(Long planid,String rd,Long id,Double sum);
	@Transactional
	void addpickTicketPlan_bh(Long planid,String rd,Long id,Double sum);
	@Transactional
	void copypickTicketPlan_bh(Long planid,String rd,List<Long> ids);
	@Transactional
	void appPlanPickzd(List<Long> pickTicketIds);
	
	@Transactional
	void addProductionp(String tsr,String str1,double qty,String procedure,String description);
	
	//生成履带机出库计划
	@Transactional
	void appPlanLDJ(List<Long> pickTicketIds);
	//线边接收
	@Transactional
	void xbjs(List<Long> pickTicketIds);
	//线边接收
	@Transactional
	void xbjsSys(List<Long> pickTicketIds);
	//线边接收
	@Transactional
	void xbjs(Long pt_id,String tph,List<Long> logIds,String oper);
	//发货确认
	@Transactional
	void confirmShipKAMS(List<Long> pickIds) ;
	
	@Transactional
	void manualAllocate(List<Long> pickIds) ;
	//KAMS审核
	@Transactional
	void activeKAMSAll(List<Long> pickTicketIds);
	//耗用
	@Transactional
	void saveProductionPlan(List<Long> pickTicketIds ,String p,Long spId);
	@Transactional
	void deleteProduction(List<Long> pickTicketIds);
	
	@Transactional
	void addInstructions(String pickTicketId,Long billTypeid,
			PlanPickDetail planPickTicketDetail);
	@Transactional
	void deletePlanAll(List<Long> pickIds);
	@Transactional
	/**手工指示生成备货操作*/
	void createPickTicket1(List<Long> pickIds) ;
	@Transactional
	/**手工指示生成备货操作*/
	void createPickTicket2(List<Long> pickIds) ;
	@Transactional
	void addSpareParts(SpareParts spareParts);
	
	@Transactional
	void copySpareParts(List<Long> ids);
	
	@Transactional
	void deletSpareParts(List<Long> ids);
	/***
	 * 零件耗用
	 * @param ids
	 */
	@Transactional
	void hyInv(List<Long> ids);
	/***
	 * 备货登记
	 * @param ids
	 */
	@Transactional
	void confirmPickKAMS(Long pickId, Map qtys);
	/***
	 * 删除月度计划
	 * @param ids
	 */
	@Transactional
	void deletePlanAssembly(List<Long> ids);
	
	/**
	 * 
	 * @param pickTicketDetailId 明细ID
	 * @param quantity 设变数量
	 */
	@Transactional
	void designList(long pickTicketDetailId,double quantity);
	
	boolean sheChangeColor(long pickTicketId);
	/**制造库位调整*/
	@Transactional
	void manualMoveZzkw(Long srcInventoryId, Long destLocationId,double quantity, Long workerId);
	
	/**制造库位投料*/
	@Transactional
	void invZzkwTlSys(Long srcInventoryId, Long destLocationId,double quantity);
	
	/**制造库位投料*/
	@Transactional
	void invZzkwTl(Long srcInventoryId, Long destLocationId,double quantity,String oper);
	/**批量更新库存库位*/
	@Transactional
	void importMoveLocation(File file);
	//手工生成拖拉机
	@Transactional
	void addProductionPlan(Long id,String tsr,String str1,double qty,String procedure,String description,String modelName);
	@Transactional 
	void checkAutoProduction(List<Long> ids);

	
	public Inventory findInventory(ItemKey itemkey,WarehouseArea zone,Location location,String billCode,String type,Location zzkw);
	
	public InventoryLog addInventoryLog(String logType, int incOrDec, WarehouseArea zone,Location location,String relatedBill, 
			 ItemKey itemKey,  double occurQuantity, String LP,String operator,Long referenceLog, String description,String bhr,String cph,Location zzkw);
	
	

}
