/*
 * MosP - Mind Open Source Project         http://www.mosp.jp/
 * Copyright (C) 1987-2009 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.vo;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.MospException;
import jp.mosp.common.common.MospUtility;

import jp.mosp.kintai.dto.MSyukkinboDto;

public class AttendanceStartCardVo extends AttendanceMenuVo {

	private static final long serialVersionUID = 5615485616797787215L;

	// URL、CSS
	private static final String RETURN_URL = "/jsp/kintai/attendanceStartCard.jsp";
	private static final String EXTRA_JS   = "/pub/kintai/js/attendanceStartCard.js";
	private static final String EXTRA_CSS  = "/pub/kintai/css/attendanceStartCard.css";

	// 画面サブタイトル
	public final String SUB_TITLE = CommonConst.NAM_INPUT_START;

	// パラメータ名
	public static final String PRM_TXT_START_HOUR 		= "txtStartHour"		;
	public static final String PRM_TXT_START_MIN 			= "txtStartMin"			;
	public static final String PRM_PLT_WORK_TYPE 			= "pltWorkType"			;
	public static final String PRM_PLT_HALF_HOLIDAY 		= "pltHalfHoliday"		;
	public static final String PRM_PLT_WORK_ON_HOLIDAY 	= "pltWorkOnHoliday"	;

	public static final String PRM_TXT_LATE_HOUR 			= "txtLateHour"			;
	public static final String PRM_TXT_LATE_MIN 			= "txtLateMin"			;
	public static final String PRM_PLT_LATE_REASON 		= "pltLateReason"		;
	public static final String PRM_PLT_LATE_CERTIFICATE 	= "pltLateCertificate"	;
	public static final String PRM_TXT_LATE_COMMENT 		= "txtLateComment"		;

	// フィールド名及び制限
	public static final String NAM_START_TIME			= CommonConst.NAM_START_TIME + CommonConst.NAM_TIME;
	public static final String NAM_START_TIME_HOUR		= CommonConst.NAM_START_TIME + CommonConst.MSG_HOUR;
	public static final String NAM_START_TIME_MIN		= CommonConst.NAM_START_TIME + CommonConst.MSG_MINUTES;
	public static final String NAM_WORKING_TYPE		= CommonConst.NAM_WORKING_TYPE;
	public static final String NAM_HALF_HOLIDAY		= CommonConst.NAM_VACATION_LEAVE_HALF + CommonConst.NAM_COMMON_TYPE;
	public static final String NAM_WORK_ON_HOLIDAY		= CommonConst.NAM_WORK_ON_HOLIDAY + CommonConst.NAM_COMMON_TYPE;

	public static final String NAM_LATE_TIME			= CommonConst.NAM_ARRIVE_LATE + CommonConst.NAM_COMMON_TIME;
	public static final String NAM_LATE_TIME_HOUR		= CommonConst.NAM_ARRIVE_LATE + CommonConst.NAM_COMMON_TIME + CommonConst.MSG_HOUR;
	public static final String NAM_LATE_TIME_MIN		= CommonConst.NAM_ARRIVE_LATE + CommonConst.NAM_COMMON_TIME + CommonConst.MSG_MINUTES;
	public static final String NAM_LATE_REASON			= CommonConst.NAM_ARRIVE_LATE + CommonConst.NAM_REASON;
	public static final String NAM_LATE_CERTIFICATE	= CommonConst.NAM_CERTIFICATE;
	public static final String NAM_LATE_COMMENT 		= CommonConst.NAM_COMMENT;

	public static final int	LEN_HOUR  		= CommonConst.LEN_TIME_HOUR;
	public static final int	LEN_MIN  		= CommonConst.LEN_TIME_MIN;
	public static final int	LEN_COMMENT		= 50;

	// フィールド	
	private String txtStartHour;
	private String txtStartMin;
	private String pltWorkType;
	private String pltHalfHoliday;
	private String pltWorkOnHoliday;

	private String txtLateHour;
	private String txtLateMin;
	private String pltLateReason;
	private String pltLateCertificate;
	private String txtLateComment;

	// プルダウンリスト
	public String[][] aryPltWorkType;
	public String[][] aryPltHalfHoliday;
	public String[][] aryPltWorkOnHoliday;
	public String[][] aryPltLateReason;
	public String[][] aryPltLateCertificate;

	/**
	 * コンストラクタ
	 */
	public AttendanceStartCardVo() {
		super();
		setRetUrl(RETURN_URL);
		addExtraJs(EXTRA_JS);
		setExtraCss(EXTRA_CSS);
		mode = MODE_EDIT;
	}

	/**
	 * パラメータ設定
	 * @param request リクエスト
	 */
	@Override
	public void setParams(HttpServletRequest request) {
		super.setParams(request);
		txtStartHour 		= request.getParameter(PRM_TXT_START_HOUR);
		txtStartMin 		= request.getParameter(PRM_TXT_START_MIN);
		pltWorkType 		= request.getParameter(PRM_PLT_WORK_TYPE);
		pltHalfHoliday 		= request.getParameter(PRM_PLT_HALF_HOLIDAY);
		pltWorkOnHoliday 	= request.getParameter(PRM_PLT_WORK_ON_HOLIDAY);
		txtLateHour			= request.getParameter(PRM_TXT_LATE_HOUR);
		txtLateMin			= request.getParameter(PRM_TXT_LATE_MIN);
		pltLateReason		= request.getParameter(PRM_PLT_LATE_REASON);
		pltLateCertificate	= request.getParameter(PRM_PLT_LATE_CERTIFICATE);
		txtLateComment		= request.getParameter(PRM_TXT_LATE_COMMENT);
	}

	/**
	 * フィールド設定
	 * @param dto	対象DTO
	 */
	public void setFields(MSyukkinboDto dto) {
		txtStartHour 		= util.convStringTimeToStringHour(dto.getSyJikoku());
		txtStartMin			= util.convStringTimeToStringMinutes(dto.getSyJikoku());
		pltWorkType  		= dto.getKinmu();
		pltHalfHoliday 		= dto.getSHankyuKb();
		pltWorkOnHoliday  	= dto.getKyusyuKb();

		txtLateHour 		= String.valueOf(util.convIntegerTimeToStringHour(dto.getTiJikan()));
		txtLateMin 			= String.valueOf(util.convIntegerTimeToStringMinutes(dto.getTiJikan()));
		pltLateReason 		= dto.getTiRiyuu();
		pltLateCertificate 	= dto.getTiSyoumei();
		txtLateComment 		= dto.getTiComent();
	}

	/**
	 * フィールド設定(DTOに対するVO情報のセット)
	 * @param dto	対象DTO
	 */
	@Override
	public void setDtoFields(MSyukkinboDto dto) {
		super.setDtoFields(dto);
		dto.setSyJikoku(util.convStringTimeFormatted(txtStartHour, txtStartMin));
		dto.setKinmu(pltWorkType);
		dto.setSHankyuKb(pltHalfHoliday);
		dto.setKyusyuKb(pltWorkOnHoliday);
		dto.setTiJikan(util.convStringTimeToIntegerTime(txtLateHour, txtLateMin));
		dto.setTiRiyuu(pltLateReason);
		dto.setTiSyoumei(pltLateCertificate);
		dto.setTiComent(txtLateComment);
		dto.setSyTimes(util.getDateTime(util.getNowDate()));
	}

	/**
	 * フィールド初期化
	 */
	public void initFields() {
		txtStartHour 		= String.valueOf(MospUtility.getHour(util.getNowDate()));
		txtStartMin 		= String.valueOf(MospUtility.getMinute(util.getNowDate()));
		pltWorkType 		= "";
		pltHalfHoliday 		= "";
		pltWorkOnHoliday 	= "";

		txtLateHour 		= "0";
		txtLateMin 			= "0";
		pltLateReason 		= "";
		pltLateCertificate 	= "";
		txtLateComment 		= "";
	}

	/**
	 * フィールドの妥当性確認
	 * @throws MospException
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 必須確認
		checkRequired(txtStartHour	, NAM_START_TIME	, PRM_TXT_START_HOUR);
		checkRequired(txtStartMin	, NAM_START_TIME	, PRM_TXT_START_MIN);
		checkRequired(txtLateHour	, NAM_LATE_TIME		, PRM_TXT_LATE_HOUR);
		checkRequired(txtLateMin	, NAM_LATE_TIME 	, PRM_TXT_LATE_MIN);
		// 数字確認
		checkNumber(txtStartHour	, NAM_START_TIME	, PRM_TXT_START_HOUR);
		checkNumber(txtStartMin		, NAM_START_TIME	, PRM_TXT_START_MIN);
		checkNumber(txtLateHour		, NAM_LATE_TIME		, PRM_TXT_LATE_HOUR);
		checkNumber(txtLateMin		, NAM_LATE_TIME		, PRM_TXT_LATE_MIN);
		// 長さ確認	
		checkLength(txtStartHour	, LEN_HOUR		, NAM_START_TIME	, PRM_TXT_START_HOUR);
		checkLength(txtStartMin		, LEN_MIN		, NAM_START_TIME	, PRM_TXT_START_MIN);
		checkLength(txtLateHour		, LEN_HOUR		, NAM_LATE_TIME		, PRM_TXT_LATE_HOUR);
		checkLength(txtLateMin		, LEN_MIN		, NAM_LATE_TIME		, PRM_TXT_LATE_MIN);
		checkLength(txtLateComment	, LEN_COMMENT	, NAM_LATE_COMMENT	, PRM_TXT_LATE_COMMENT);
		// 妥当性確認終了時処理
		endValidation();
	}

	/**
	 * JavaScript設定
	 * @param cls 情報取得クラス
	 * @throws IllegalAccessException
	 */
	@Override
	public String getDirectJs(Class cls) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls));
		sb.append("var MODE = ");
		sb.append(mode);
		sb.append(";");
		return sb.toString();
	}

	// アクセサメソッド
	public String getTxtStartHour		() { return txtStartHour		; }
	public String getTxtStartMin		() { return txtStartMin			; }
	public String getPltWorkType		() { return pltWorkType			; }
	public String getPltHalfHoliday		() { return pltHalfHoliday		; }
	public String getPltWorkOnHoliday	() { return pltWorkOnHoliday	; }
	public String getTxtLateHour		() { return txtLateHour			; }
	public String getTxtLateMin			() { return txtLateMin			; }
	public String getPltLateReason		() { return pltLateReason		; }
	public String getPltLateCertificate	() { return pltLateCertificate	; }
	public String getTxtLateComment		() { return txtLateComment		; }

	public String getEscTxtStartHour		() { return escapeHTML(txtStartHour			); }
	public String getEscTxtStartMin			() { return escapeHTML(txtStartMin			); }
	public String getEscPltWorkType			() { return escapeHTML(pltWorkType			); }
	public String getEscPltHalfHoliday		() { return escapeHTML(pltHalfHoliday		); }
	public String getEscPltWorkOnHoliday	() { return escapeHTML(pltWorkOnHoliday		); }
	public String getEscTxtLateHour			() { return escapeHTML(txtLateHour			); }
	public String getEscTxtLateMin			() { return escapeHTML(txtLateMin			); }
	public String getEscPltLateReason		() { return escapeHTML(pltLateReason		); }
	public String getEscPltLateCertificate	() { return escapeHTML(pltLateCertificate	); }
	public String getEscTxtLateComment		() { return escapeHTML(txtLateComment		); }

}
