package jp.mosp.payroll.dao;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.Properties;

import jp.mosp.common.dto.CmAspUserDto;
import jp.mosp.common.dto.CmUserDto;
import jp.mosp.payroll.dto.DetailMoneyDto;

public class PdPaySumDao  extends DetailMoneyDao {
	/**
	 *  テーブル名。<br>
	 */
	public static final String TABLE = "PD_PAY_SUM";
	
	/**
	 * {@link DetailMoneyDao#DetailMoneyDao(Properties, String, CmAspUserDto, CmUserDto, Connection)}
	 * を行う。<br>
	 * @param cfg     設定ファイル
	 * @param cmd     コマンド
	 * @param aspUser ASPユーザー
	 * @param user    ユーザー
	 * @param conn    DBコネクション
	 */
	public PdPaySumDao(
			Properties   cfg    ,
			String       cmd    ,
			CmAspUserDto aspUser,
			CmUserDto    user   ,
			Connection   conn
	) {
		super(cfg, cmd, aspUser, user, conn);
	}

	/**
	 * 条件によりデータを取得する。(社員コード、計算年月、明細コード)<br>
	 * @param kCode     社員コード
	 * @param calcDate 計算年月
	 * @return 検索結果(DTOのList)
	 * @throws SQLException 
	 * @throws IllegalAccessException 
	 * @throws NoSuchFieldException 
	 */
	public DetailMoneyDto find_detailCode(
			String kCode, Date calcDate, String detailCode 
	) throws SQLException, NoSuchFieldException, IllegalAccessException {
		index = 1;
		StringBuffer sb = new StringBuffer();
		sb.append("WHERE ");
		sb.append(COL_KCODE + " = ? ");
		sb.append("AND ");
		sb.append(COL_CALC_DATE + " = ? ");
		sb.append("AND ");
		sb.append(COL_DETAIL_CODE + " = ? ");
		try {
			prepareStatement(getSelectQuery(getClass()) + sb.toString());
			setParam    (index++, kCode    );
			setDateParam(index++, calcDate);
			setParam    (index++, detailCode);
			executeQuery();
			DetailMoneyDto dto = null;
			if (rs.next()) {
				dto = mapping();
			}
			return dto;
		} catch (SQLException e) {
			throw e;
		} finally {
			releaseResultSet();
			releasePreparedStatement();
		}
	}
	
}
