/*
 * 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.payroll.vo;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPMenuConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.MospException;
import jp.mosp.common.common.MospUtility;
import jp.mosp.common.utils.DateUtil;

/**
 * @author nakamura
 *
 */
public class WorkCompileExportCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= 8449447211917228425L;
	
	// パラメータ名
	/**
	 * 所属
	 */
	public static final String	PRM_PLT_SECTION		= "pltSection";
	/**
	 * 社員コード
	 */
	public static final String	PRM_TXT_K_CODE		= "txtKCode";
	/**
	 * 開始年
	 */
	public static final String	PRM_PLT_START_YEAR	= "pltStartYear";
	/**
	 * 開始月
	 */
	public static final String	PRM_PLT_START_MONTH	= "pltStartMonth";
	/**
	 * 終了年
	 */
	public static final String	PRM_PLT_END_YEAR	= "pltEndYear";
	/**
	 * 終了月
	 */
	public static final String	PRM_PLT_END_MONTH	= "pltEndMonth";
	/**
	 * 勤怠テーブル
	 */
	public static final String	PRM_PLT_WORK_TABLE	= "pltWorkTable";
	
	// フィールド
	private String				pltSection;
	private String				txtKCode;
	private String				pltStartYear;
	private String				pltStartMonth;
	private String				pltEndYear;
	private String				pltEndMonth;
	private String				pltWorkTable;
	
	// プルダウンリスト
	/**
	 * 所属(配列)
	 */
	public String[][]			aryPltSection;
	/**
	 * 開始年(配列)
	 */
	public String[][]			aryPltYear;
	/**
	 * 開始月(配列)
	 */
	public String[][]			aryPltMonth;
	/**
	 * 勤怠テーブル(配列)
	 */
	public String[][]			aryPltWorkTable;
	/**
	 * 開始年(配列)旧有給休暇テーブル選択時
	 */
	public String[][]			aryOldYear;
	/**
	 * 開始年(配列)新有給休暇テーブル選択時
	 */
	public String[][]			aryNewYear;
	/**
	 * 開始月(配列)旧有給休暇テーブル選択時
	 */
	public String[][]			aryOldMonth;
	/**
	 * 開始月(配列)新有給休暇テーブル選択時
	 */
	public String[][]			aryNewMonth;
	
	// フィールド名及び制限	
	/**
	 * 社員コード
	 */
	public String				NAM_K_CODE;
	/**
	 * 所属
	 */
	public String				NAM_SECTION;
	/**
	 * 開始年月
	 */
	public String				NAM_START_DATE;
	/**
	 * 終了年月
	 */
	public String				NAM_END_DATE;
	/**
	 * 勤怠テーブル
	 */
	public String				NAM_WORK_TABLE;
	/**
	 * 社員コード(項目長)
	 */
	public int					LEN_K_CODE;
	

	/**
	 * コンストラクター
	 */
	public WorkCompileExportCardVo() {
		super();
		setViewPath(getClassName());
		aryPltYear = new String[0][0];
		aryPltMonth = new String[0][0];
	}
	
	@Override
	protected void setSubTitle() {
		subTitle = "勤怠集計情報エクスポート";
		createAryMenu(CMD_MENU_PAYROLL, MosPMenuConst.getMenuAttendanceCalculate());
	}
	
	@Override
	protected void setFieldsName() {
		NAM_K_CODE = CommonConst.NAM_K_CODE;
		NAM_SECTION = CommonConst.NAM_STATION;
		NAM_START_DATE = CommonConst.NAM_START + CommonConst.NAM_YEAR + CommonConst.NAM_MONTH;
		NAM_END_DATE = CommonConst.NAM_END + CommonConst.NAM_YEAR + CommonConst.NAM_MONTH;
		NAM_WORK_TABLE = CommonConst.NAM_COMMON_OUTPUT + CommonConst.NAM_COMMON_TARGET;
		LEN_K_CODE = CommonConst.LEN_K_CODE;
	}
	
	/**
	 * 初期値設定
	 */
	public void setDefaultValues() {
		pltSection = "";
		txtKCode = "";
		pltStartYear = String.valueOf(MospUtility.getYear(DateUtil.getNowDate()));
		pltStartMonth = String.valueOf(MospUtility.getMonth(DateUtil.getNowDate()));
		pltEndYear = String.valueOf(MospUtility.getYear(DateUtil.getNowDate()));
		pltEndMonth = String.valueOf(MospUtility.getMonth(DateUtil.getNowDate()));
		if (DateUtil.getNowDate().compareTo(DateUtil.getDate(2010, 3, 31)) > 0) {
			pltWorkTable = "1";
		} else {
			pltWorkTable = "0";
		}
	}
	
	@Override
	public void setParams(HttpServletRequest request) {
		pltSection = request.getParameter(PRM_PLT_SECTION);
		txtKCode = request.getParameter(PRM_TXT_K_CODE);
		pltStartYear = request.getParameter(PRM_PLT_START_YEAR);
		pltStartMonth = request.getParameter(PRM_PLT_START_MONTH);
		pltEndYear = request.getParameter(PRM_PLT_END_YEAR);
		pltEndMonth = request.getParameter(PRM_PLT_END_MONTH);
		pltWorkTable = request.getParameter(PRM_PLT_WORK_TABLE);
	}
	
	/**
	 * フィールドの妥当性確認
	 * @throws MospException	MosP例外処理が発生した場合
	 */
	public void validate() throws MospException {
		// 妥当性確認開始時処理
		startValidation();
		// 文字列長確認
		checkLength(txtKCode, LEN_K_CODE, NAM_K_CODE, PRM_TXT_K_CODE);
		// 妥当性確認終了時処理
		endValidation();
	}
	
	/**
	 * JavaScript(設定配列)取得
	 * @param name       変数名
	 * @param arySetting 設定配列
	 * @return JavaScript(設定配列)文字列
	 */
	public static String getArrayJs(String name, String[][] arySetting) {
		StringBuffer sb = new StringBuffer();
		sb.append("var ");
		sb.append(escapeHTML(name));
		sb.append(" = new Array(");
		sb.append(arySetting.length);
		sb.append(");");
		for (int i = 0; i < arySetting.length; i++) {
			sb.append(name);
			sb.append("[");
			sb.append(i);
			sb.append("] = new Array(");
			sb.append(2);
			sb.append(");");
			
			sb.append(name);
			sb.append("[");
			sb.append(i);
			sb.append("][");
			sb.append(0);
			sb.append("] = \"");
			sb.append(escapeHTML(arySetting[i][0]));
			sb.append("\";");
			
			sb.append(name);
			sb.append("[");
			sb.append(i);
			sb.append("][");
			sb.append(1);
			sb.append("] = \"");
			sb.append(escapeHTML(arySetting[i][1]));
			sb.append("\";");
		}
		return sb.toString();
	}
	
	@Override
	public String getDirectJs(Class<?> cls, Object obj) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls, obj));
		sb.append(getArrayJs("ARY_OLD_YEAR", aryOldYear));
		sb.append(getArrayJs("ARY_NEW_YEAR", aryNewYear));
		sb.append(getArrayJs("ARY_OLD_MONTH", aryOldMonth));
		sb.append(getArrayJs("ARY_NEW_MONTH", aryNewMonth));
		sb.append(getArrayJs("ARY_PLT_MONTH", aryPltMonth));
		return sb.toString();
	}
	
	// アクセサメソッド	
	/**
	 * @return		社員コード(HTMLエスケープ)
	 */
	public String getEscTxtKCode() {
		return escapeHTML(txtKCode);
	}
	
	/**
	 * @return		所属
	 */
	public String getPltSection() {
		return pltSection;
	}
	
	/**
	 * @return		社員コード
	 */
	public String getTxtKCode() {
		return txtKCode;
	}
	
	/**
	 * @return		開始年
	 */
	public String getPltStartYear() {
		return pltStartYear;
	}
	
	/**
	 * @return		開始月
	 */
	public String getPltStartMonth() {
		return pltStartMonth;
	}
	
	/**
	 * @return		終了年
	 */
	public String getPltEndYear() {
		return pltEndYear;
	}
	
	/**
	 * @return		終了月
	 */
	public String getPltEndMonth() {
		return pltEndMonth;
	}
	
	/**
	 * @return		有給休暇テーブル
	 */
	public String getPltWorkTable() {
		return pltWorkTable;
	}
	
	/**
	 * @param pltSection		所属
	 */
	public void setPltSection(String pltSection) {
		this.pltSection = pltSection;
	}
	
	/**
	 * @param txtKCode			社員コード
	 */
	public void setTxtKCode(String txtKCode) {
		this.txtKCode = txtKCode;
	}
	
	/**
	 * @param pltStartYear		開始年
	 */
	public void setPltStartYear(String pltStartYear) {
		this.pltStartYear = pltStartYear;
	}
	
	/**
	 * @param pltStartMonth		開始月
	 */
	public void setPltStartMonth(String pltStartMonth) {
		this.pltStartMonth = pltStartMonth;
	}
	
	/**
	 * @param pltEndYear		終了年
	 */
	public void setPltEndYear(String pltEndYear) {
		this.pltEndYear = pltEndYear;
	}
	
	/**
	 * @param pltEndMonth		終了月
	 */
	public void setPltEndMonth(String pltEndMonth) {
		this.pltEndMonth = pltEndMonth;
	}
	
	/**
	 * @param pltWorkTable	有給休暇テーブル
	 */
	public void setPltWorkTable(String pltWorkTable) {
		this.pltWorkTable = pltWorkTable;
	}
}
