/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) MIND Co., Ltd.       http://www.e-mind.co.jp/
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */
package jp.mosp.kintai.kintai.vo;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.MospException;
import jp.mosp.common.utils.DateUtil;
import jp.mosp.common.utils.StringUtil;
import jp.mosp.kintai.kintai.dto.MSyukkinboDto;

/**
 * 
 */
public class AttendanceHolidayCardVo extends AttendanceMenuVo {
	
	private static final long	serialVersionUID			= -4666690261405185923L;
	
	// パラメータ名
	/**
	 * 
	 */
	public static final String	PRM_PLT_HOLIDAY_REASON		= "pltHolidayReason";
	/**
	 * 
	 */
	public static final String	PRM_PLT_HOLIDAY_CERTIFICATE	= "pltHolidayCertificate";
	/**
	 * 
	 */
	public static final String	PRM_TXT_HOLIDAY_COMMENT		= "txtHolidayComment";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SUBSTITUTE_YEAR		= "pltSubstituteYear";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SUBSTITUTE_MONTH	= "pltSubstituteMonth";
	/**
	 * 
	 */
	public static final String	PRM_PLT_SUBSTITUTE_DAY		= "pltSubstituteDay";
	
	// フィールド名及び制限
	/**
	 * 
	 */
	public String				NAM_HOLIDAY_REASON;
	/**
	 * 
	 */
	public String				NAM_HOLIDAY_CERTIFICATE;
	/**
	 * 
	 */
	public String				NAM_HOLIDAY_COMMENT;
	/**
	 * 
	 */
	public String				NAM_SUBSTITUTE_HOLIDAY;
	/**
	 * 
	 */
	public int					LEN_COMMENT;
	
	// フィールド
	private String				pltHolidayReason;
	private String				pltHolidayCertificate;
	private String				txtHolidayComment;
	private String				pltSubstituteYear;
	private String				pltSubstituteMonth;
	private String				pltSubstituteDay;
	
	private int					holidayTimes;
	
	// プルダウンリスト
	/**
	 * 
	 */
	public String[][]			aryPltHolidayReason;
	/**
	 * 
	 */
	public String[][]			aryPltHolidayCertificate;
	/**
	 * 
	 */
	public String[][]			aryPltSubstituteYear;
	/**
	 * 
	 */
	public String[][]			aryPltSubstituteMonth;
	/**
	 * 
	 */
	public String[][]			aryPltSubstituteDay;
	

	/**
	 * コンストラクタ
	 */
	public AttendanceHolidayCardVo() {
		super();
		setViewPath(getClassName());
		setMode(MODE_EDIT);
		addAttendanceMenuCss();
		addAttendanceMenuJs();
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = CommonConst.NAM_INPUT_HOLIDAY;
	}
	
	@Override
	protected void setFieldsName() {
		super.setFieldsName();
		NAM_HOLIDAY_REASON = CommonConst.NAM_VACATION_LEAVE + CommonConst.NAM_REASON;
		NAM_HOLIDAY_CERTIFICATE = CommonConst.NAM_CERTIFICATE;
		NAM_HOLIDAY_COMMENT = CommonConst.NAM_COMMENT;
		NAM_SUBSTITUTE_HOLIDAY = CommonConst.NAM_APPLY_DATE;
		LEN_COMMENT = 50;
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		super.setParams(request);
		pltHolidayReason = request.getParameter(PRM_PLT_HOLIDAY_REASON);
		pltHolidayCertificate = request.getParameter(PRM_PLT_HOLIDAY_CERTIFICATE);
		txtHolidayComment = request.getParameter(PRM_TXT_HOLIDAY_COMMENT);
		pltSubstituteYear = request.getParameter(PRM_PLT_SUBSTITUTE_YEAR);
		pltSubstituteMonth = request.getParameter(PRM_PLT_SUBSTITUTE_MONTH);
		pltSubstituteDay = request.getParameter(PRM_PLT_SUBSTITUTE_DAY);
	}
	
	/**
	 * フィールド設定
	 * @param dto	対象DTO
	 */
	public void setFields(MSyukkinboDto dto) {
		pltHolidayReason = dto.getKKRiyuu();
		pltHolidayCertificate = dto.getKKSyoumei();
		txtHolidayComment = dto.getKKComent();
		pltSubstituteYear = DateUtil.convStringDateToArray(dto.getDaiKyuJyu())[0];
		pltSubstituteMonth = DateUtil.convStringDateToArray(dto.getDaiKyuJyu())[1];
		pltSubstituteDay = DateUtil.convStringDateToArray(dto.getDaiKyuJyu())[2];
	}
	
	@Override
	public void setDtoFields(MSyukkinboDto dto) {
		super.setDtoFields(dto);
		dto.setKinmu(CommonConst.ATTENDANCE_TYPE_HOLIDAY);
		dto.setKKRiyuu(pltHolidayReason);
		// 充当日
		if (StringUtil.isNotNull(pltSubstituteYear) && StringUtil.isNotNull(pltSubstituteMonth)
				&& StringUtil.isNotNull(pltSubstituteDay)) {
			dto.setDaiKyuJyu(DateUtil.convStringDateFormatted(pltSubstituteYear, pltSubstituteMonth, pltSubstituteDay));
		}
		dto.setKKComent(txtHolidayComment);
		dto.setKKSyoumei(pltHolidayCertificate);
		dto.setKKJikan(holidayTimes);
		dto.setKKTimes(DateUtil.getDateTime(DateUtil.getNowDate()));
		dto.setSnRiyuu(CommonConst.NUM_ATTENDANCE_REQUEST);
		dto.setUpdtTimes(DateUtil.getDateTime(DateUtil.getNowDate()));
	}
	
	/**
	 * フィールド初期化
	 */
	public void initFields() {
		pltHolidayReason = "";
		pltHolidayCertificate = "";
		txtHolidayComment = "";
		pltSubstituteYear = "";
		pltSubstituteMonth = "";
		pltSubstituteDay = "";
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 充当日チェック
		if (StringUtil.isNotNull(pltSubstituteYear) || StringUtil.isNotNull(pltSubstituteMonth)
				|| StringUtil.isNotNull(pltSubstituteDay)) {
			checkDate(getIntParam(pltSubstituteYear), getIntParam(pltSubstituteMonth), getIntParam(pltSubstituteDay),
					NAM_SUBSTITUTE_HOLIDAY, PRM_PLT_SUBSTITUTE_YEAR);
		}
		// 妥当性確認終了時処理
		endValidation();
	}
	
	/**
	 * @return pltHolidayReason
	 */
	public String getPltHolidayReason() {
		return pltHolidayReason;
	}
	
	/**
	 * @return pltHolidayCertificate
	 */
	public String getPltHolidayCertificate() {
		return pltHolidayCertificate;
	}
	
	/**
	 * @return txtHolidayComment
	 */
	public String getTxtHolidayComment() {
		return txtHolidayComment;
	}
	
	/**
	 * @return pltSubstituteYear
	 */
	public String getPltSubstituteYear() {
		return pltSubstituteYear;
	}
	
	/**
	 * @return pltSubstituteMonth
	 */
	public String getPltSubstituteMonth() {
		return pltSubstituteMonth;
	}
	
	/**
	 * @return pltSubstituteDay
	 */
	public String getPltSubstituteDay() {
		return pltSubstituteDay;
	}
	
	/**
	 * @return holidayTimes
	 */
	public int getHolidayTimes() {
		return holidayTimes;
	}
	
	/**
	 * @param pltHolidayReason セットする pltHolidayReason
	 */
	public void setPltHolidayReason(String pltHolidayReason) {
		this.pltHolidayReason = pltHolidayReason;
	}
	
	/**
	 * @param pltHolidayCertificate セットする pltHolidayCertificate
	 */
	public void setPltHolidayCertificate(String pltHolidayCertificate) {
		this.pltHolidayCertificate = pltHolidayCertificate;
	}
	
	/**
	 * @param txtHolidayComment セットする txtHolidayComment
	 */
	public void setTxtHolidayComment(String txtHolidayComment) {
		this.txtHolidayComment = txtHolidayComment;
	}
	
	/**
	 * @param pltSubstituteYear セットする pltSubstituteYear
	 */
	public void setPltSubstituteYear(String pltSubstituteYear) {
		this.pltSubstituteYear = pltSubstituteYear;
	}
	
	/**
	 * @param pltSubstituteMonth セットする pltSubstituteMonth
	 */
	public void setPltSubstituteMonth(String pltSubstituteMonth) {
		this.pltSubstituteMonth = pltSubstituteMonth;
	}
	
	/**
	 * @param pltSubstituteDay セットする pltSubstituteDay
	 */
	public void setPltSubstituteDay(String pltSubstituteDay) {
		this.pltSubstituteDay = pltSubstituteDay;
	}
	
	/**
	 * @param holidayTimes セットする holidayTimes
	 */
	public void setHolidayTimes(int holidayTimes) {
		this.holidayTimes = holidayTimes;
	}
	
}
