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

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPMenuConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.part.DatePart;
import jp.mosp.common.part.TimePart;
import jp.mosp.workflow.dto.OverTimeRequestDto;

public class OverTimeRequestListVo extends MosPVo {

	private static final long serialVersionUID = -1598511432661195806L;

	// パラメータ名
	public static final String PRM_PLT_YEAR 		= "pltYear";
	public static final String PRM_PLT_MONTH 		= "pltMonth";

	// フィールド	
	private String[][]	aryOverTime;
	private String 		pltYear;
	private String 		pltMonth;
	private String 		lblSection;

	// フィールド名及び制限
	public static final String NAM_SECTION 	= CommonConst.NAM_STATION;
	public static final String NAM_K_NAME 		= CommonConst.NAM_K_NAME;
	public static final String NAM_WORK_MONTH 	= CommonConst.NAM_WORKING + CommonConst.NAM_MONTH;

	public static final String NAM_WORK_DATE 		= CommonConst.NAM_WORKING + CommonConst.NAM_DAY;
	public static final String NAM_REASON 			= CommonConst.NAM_REASON;
	public static final String NAM_REQUEST_TIME 	= CommonConst.NAM_APPLICATION + CommonConst.NAM_COMMON_TIME;
	public static final String NAM_REQUEST_DATE 	= CommonConst.NAM_APPLICATION + CommonConst.NAM_DAY;
	public static final String NAM_STATUS 			= CommonConst.NAM_APPROVAL_STATE;
	public static final String NAM_APPROVER 		= CommonConst.NAM_APPROVER;

	// プルダウンリスト
	public String[][] aryPltYear;
	public String[][] aryPltMonth;

	// ソートキー
	public final String KEY_WORK_DATE		= "keyWorkDate";
	public final String KEY_REQUEST_DATE	= "keyRequestDate";
	public final String KEY_STATUS			= "keyStatus";
	public final String KEY_APPROVER		= "keyApprover";

	/**
	 * コンストラクタ
	 */
	public OverTimeRequestListVo() {
		super();
		setViewPath(getClassName());
		aryOverTime = new String[0][0];
		pltYear = "";
		pltMonth = "";
		setFormerKey(KEY_WORK_DATE);
	}

	public void setSubTitle() {
		subTitle = CommonConst.NAM_OVER_TIME_REQUEST;
		aryMenu = new String[][] {
				{ CMD_MENU_INPUT, CommonConst.NAM_TO_MENU },
				MosPMenuConst.getEmployeeCmdArray()[3],
		};
	}

	/**
	 * パラメータ設定
	 * @param request リクエスト
	 */
	public void setParams(HttpServletRequest request) {
		pltYear = request.getParameter(PRM_PLT_YEAR);
		pltMonth = request.getParameter(PRM_PLT_MONTH);
	}

	/**
	 * フィールド設定
	 * @param listRequest		リスト
	 */
	public void setFields(List listRequest) {
		// リストの設定
		list = listRequest;
		// データ総数の取得
		count = listRequest.size();
		// 配列の初期化
		aryOverTime = new String[count][7];
		// データの設定
		int i = 0;
		Iterator it = listRequest.iterator();
		while (it.hasNext()) {
			OverTimeRequestDto dto = (OverTimeRequestDto)it.next();
			// 伝票番号
			aryOverTime[i][0] = escapeHTML(String.valueOf(dto.getVoucher()));
			// 勤務日
			aryOverTime[i][1] = escapeHTML(DatePart.convDateToFormatDateJP(dto.getWorkDate()));
			// 事由
			aryOverTime[i][2] = escapeHTML(dto.getReason());
			// 申請時間
			aryOverTime[i][3] = escapeHTML(TimePart.convIntegerTimeToJPHours(dto.getOverTime()));
			// 申請日
			aryOverTime[i][4] = escapeHTML(DatePart.convDateToFormatDateJP(dto.getRequestDate()));
			// 承認状況
			aryOverTime[i][5] = escapeHTML(dto.getApprovalStatus());
			// 承認者
			aryOverTime[i][6] = escapeHTML(dto.getApproverName());
			i++;
		}
	}

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

	// アクセサメソッド	
	public String[][] getEscAryOverTime() { return aryOverTime.clone(); }

	public String getPltYear() { return pltYear; }
	public String getPltMonth() { return pltMonth; }

	public String getEscPltYear() { return escapeHTML(pltYear); }
	public String getEscPltMonth() { return escapeHTML(pltMonth); }

	public void setPltYear(String pltYear) { this.pltYear = pltYear; }
	public void setPltMonth(String pltMonth) { this.pltMonth = pltMonth; }

	public String getEscLblSection() { return escapeHTML(lblSection); }
	public void setLblSection(String lblSection) { this.lblSection = lblSection; }

}
