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

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

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPVo;
import jp.mosp.common.common.FileUploadUtility;
import jp.mosp.kintai.kintai.dto.MSyukkinboDto;

import org.apache.commons.fileupload.FileItem;

public class TimeRecordImportCardVo extends MosPVo {
	
	private static final long	serialVersionUID	= 1L;
	
	// URL、CSS
	private static final String	RETURN_URL			= "/jsp/payroll/common/timeRecordImportCard.jsp";
	private static final String	EXTRA_JS			= "/pub/payroll/common/js/timeRecordImportCard.js";
	private static final String	EXTRA_CSS			= "/pub/payroll/common/css/timeRecordImportCard.css";
	
	// パラメーター名
	public static final String	PRM_FIL_IMPORT_FILE	= "filImportFile";
	
	// フィールド
	private FileItem			filImportFile;
	private String[][]			aryImportData;
	
	private String				selectICode;
	private String				lblHeader;
	
	// リスト
	public String[][]			aryWorkType;
	public String[][]			aryHolidayReason;
	public String[][]			aryLateReason;
	public String[][]			aryLeaveEarlyReason;
	public String[][]			arySHankyuKb;
	public String[][]			aryTHankyuKb;
	

	/**
	 * コンストラクタ
	 */
	public TimeRecordImportCardVo() {
		super();
		setRetUrl(RETURN_URL);
		addExtraJs(EXTRA_JS);
		setExtraCss(EXTRA_CSS);
		aryWorkType = new String[0][0];
		aryHolidayReason = new String[0][0];
		aryLateReason = new String[0][0];
		aryLeaveEarlyReason = new String[0][0];
		aryImportData = new String[0][0];
		arySHankyuKb = new String[0][0];
		aryTHankyuKb = new String[0][0];
	}
	
	/**
	 * サブタイトルを設定する。
	 */
	@Override
	protected void setSubTitle() {
		super.setSubTitle();
		subTitle = getName("P_TIMECARD") + getName("P_IMPORT");
		aryMenu = new String[2][2];
		aryMenu[0][0] = "P1910";
		aryMenu[0][1] = getName("C_MENU") + getName("C_TO");
		aryMenu[1][0] = "P9022";
		aryMenu[1][1] = getName("C_LIST") + getName("C_TO");
	}
	
	/**
	 * パラメータ設定
	 * @param list リクエストリスト
	 */
	public void setImportFile(List list) throws Exception {
		filImportFile = FileUploadUtility.getMultipartFile(list, PRM_FIL_IMPORT_FILE);
	}
	
	/**
	 * フィールド設定
	 * @param importCsvList インポートリスト
	 */
	@Override
	public void setFields(List<?> importCsvList) {
		//リストの設定
		list = importCsvList;
		//データ総数の取得
		count = importCsvList.size();
		//配列の初期化
		aryImportData = new String[count][9];
//		aryImportData = new String[count][11];
		
		//データの設定
		int i = 0;
		Iterator it = importCsvList.iterator();
		while (it.hasNext()) {
			MSyukkinboDto dto = (MSyukkinboDto)it.next();
			aryImportData[i][0] = escapeHTML(dto.getKCode());
			aryImportData[i][1] = escapeHTML(dto.getHizuke());
			aryImportData[i][2] = escapeHTML(dto.getSyJikoku());
			aryImportData[i][3] = escapeHTML(dto.getTaJikoku());
			if (dto.getKinmu().equals(CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY)) {
				aryImportData[i][4] = escapeHTML(CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY);
			} else if (dto.getKinmu().equals(CommonConst.ATTENDANCE_TYPE_HOLIDAY)) {
				aryImportData[i][4] = escapeHTML(getCodeName(dto.getKKRiyuu(), aryHolidayReason));
			} else {
				aryImportData[i][4] = escapeHTML(getCodeName(dto.getKinmu(), aryWorkType));
			}
			aryImportData[i][5] = escapeHTML(getCodeName(dto.getKKRiyuu(), aryHolidayReason));
			
			if (dto.getSHankyuKb().equals("1")) {
				aryImportData[i][6] = escapeHTML(CommonConst.NAM_VACATION_LEAVE_HALF);
			} else {
				aryImportData[i][6] = "";
			}
			
			if (dto.getTHankyuKb().equals("1")) {
				aryImportData[i][7] = escapeHTML(CommonConst.NAM_VACATION_LEAVE_HALF);
			} else {
				aryImportData[i][7] = "";
			}
			
			if (dto.getKyusyuKb().equals("1")) {
				aryImportData[i][8] = escapeHTML(CommonConst.NAM_WORK_ON_HOLIDAY);
			} else {
				aryImportData[i][8] = "";
			}
			// aryImportData[i][9]		= escapeHTML(util.getHourString(util.convIntegerTimeToDoubleTime(dto.getNijiKyu())));
			// aryImportData[i][10]		= escapeHTML(util.getHourString(util.convIntegerTimeToDoubleTime(dto.getWarimasi1())));
			
//			StringBuffer sb = new StringBuffer();
//			sb.append(dto.getSyokuji());
//			sb.append(CommonConst.SEPARATOR_DATE);
//			sb.append(dto.getCyoku1());
//			sb.append(dto.getCyoku2());
//			sb.append(dto.getCyoku3());
//			sb.append(CommonConst.SEPARATOR_DATE);
//			sb.append(dto.getHoka1());
//			sb.append(dto.getHoka2());
//			sb.append(dto.getHoka3());
//			sb.append(dto.getHoka4());
//			sb.append(dto.getHoka5());
//			aryImportData[i][8] = escapeHTML(sb.toString());
//			aryImportData[i][10] = escapeHTML(sb.toString());
			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 FileItem getFilImportFile() {
		return filImportFile;
	}
	
	public String[][] getEscAryImportData() {
		return aryImportData.clone();
	}
	
	public String getSelectICode() {
		return selectICode;
	}
	
	public String getLblHeader() {
		return lblHeader;
	}
	
	public String getEscLblHeader() {
		return escapeHTML(lblHeader);
	}
	
	public void setSelectICode(String selectICode) {
		this.selectICode = selectICode;
	}
	
	public void setLblHeader(String lblHeader) {
		this.lblHeader = lblHeader;
	}
	
}
