package com.kingdee.shr.ats.web.handler;

import java.math.BigDecimal;
import java.sql.SQLException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.ui.ModelMap;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.util.app.DbUtil;
import com.kingdee.jdbc.rowset.IRowSet;
import com.kingdee.shr.base.syssetting.context.SHRContext;
import com.kingdee.shr.base.syssetting.exception.SHRWebException;
import com.kingdee.shr.base.syssetting.web.json.JSONUtils;

/**
 * 假期额度表单handler
 * @author xiaoxin
 *
 */
public class HolidayLimitEditHandlerEx extends HolidayLimitEditHandler{

	/**
	 * 获取年假上年转入额度-今年结转额度
	 * @param request
	 * @param response
	 * @param modelMap
	 * @throws EASBizException
	 * @throws BOSException
	 * @throws SHRWebException
	 */
	public void getCarryLimitAction(HttpServletRequest request, HttpServletResponse response, ModelMap modelMap) throws EASBizException, BOSException, SHRWebException {
		Context ctx = SHRContext.getInstance().getContext();
		String billId = request.getParameter("billId");
		String sql = "/*dialect*/SELECT COALESCE(a.CFLASTCARRYFORWARD,0) - COALESCE(a.CFCARRYFORWARD,0) as auualLimit  FROM T_HR_ATS_HolidayLimit a "
				+ "left join T_HR_ATS_HolidayPolicy b on a.FHOLIDAYPOLICYID = b.fid "
				+ "left join T_HR_ATS_HolidayType c on b.FHOLIDAYTYPEID = c.fid  "
				+ "where a.fid = '"+billId+"' and c.FNUMBER = 'JQLX000001Y'";
		IRowSet rowSet = DbUtil.executeQuery(ctx, sql);
		BigDecimal carryLimit = BigDecimal.ZERO;
		try {
			if(rowSet.next()) {
				carryLimit = rowSet.getBigDecimal("auualLimit")==null?BigDecimal.ZERO:rowSet.getBigDecimal("auualLimit");
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		modelMap.put("carryLimit", carryLimit);
		JSONUtils.writeJson(response, modelMap);
	}
}
