package com.kingdee.eas.custom.ats.util;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.IObjectPK;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.ats.AtsLeaveBillDetailSameFactory;
import com.kingdee.eas.hr.ats.AtsLeaveBillEntryCollection;
import com.kingdee.eas.hr.ats.AtsLeaveBillEntryFactory;
import com.kingdee.eas.hr.ats.AtsLeaveBillInfo;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 操作工具类工具类
 * @author zkwuh
 *
 */
public class AtsLeaveBillEasOperationUtil {
	
	private static final Logger logger = LoggerFactory.getLogger(AtsLeaveBillEasOperationUtil.class);
	
	
	/**
	 * 将数据存入新的拆分表
	 * @param ctx
	 * @param atsLeaveBillInfo
	 * @throws BOSException
	 * @throws EASBizException
	 */
	public static void saveInfo(Context ctx,AtsLeaveBillInfo atsLeaveBillInfo) {
		
		try {
			logger.info("AtsLeaveBillOperationUtil....saveInfo....start");
			int size = atsLeaveBillInfo.getEntries().size();
			AtsLeaveBillEntryCollection billEntryColl = AtsLeaveBillEntryFactory.getLocalInstance(ctx)
					.getAtsLeaveBillEntryCollection(" where bill='" + atsLeaveBillInfo.getId().toString() + "'");

			for (int i = 0; i < size; ++i) {
				AtsLeaveEasBillSameSplitHelper atsLeaveBillSplitHelper = new AtsLeaveEasBillSameSplitHelper(ctx, atsLeaveBillInfo,
						billEntryColl.get(i));
				atsLeaveBillSplitHelper.splitLeaveBill();
			}
			
		}catch(Exception e) {
			logger.info("AtsLeaveBillOperationUtil....saveInfo...",e);
		}
		
	}
	
	
	/**
	 * 删除拆分表数据
	 * @param ctx
	 * @param atsLeaveBillInfo
	 * @throws EASBizException
	 * @throws BOSException
	 */
	public static void deleteInfo(Context ctx,String Id) {
		try {
			String sql=" where leavebill in "+Id +" ";
			IObjectPK[] delete = AtsLeaveBillDetailSameFactory.getLocalInstance(ctx).delete(sql);
		}catch(Exception e) {
			logger.info("AtsLeaveBillOperationUtil....deleteInfo...",e);
		}
	}
	
	
	
	
}
