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.payroll.dto.DetailTimeDto;

import org.apache.commons.fileupload.FileItem;

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

	/**
	 * コンストラクタ
	 */
	public PayrollImportCardVo() {
		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];
		aryImportHeaderItem = new String[0];
	}
	
	/**
	 * サブタイトルを設定する。
	 */
	@Override
	protected void setSubTitle() {
		super.setSubTitle();
		subTitle = getName("P_PAYMENT") + 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][14];
		//データの設定
		int i = 0;
		Iterator it = importCsvList.iterator();
		while (it.hasNext()) {
			DetailTimeDto dto = (DetailTimeDto)it.next();
			
			aryImportData[i][0] = escapeHTML(dto.getKCode());
			
			StringBuffer sb = new StringBuffer();
			sb.append(CommonConst.SEPARATOR_DATE);
			sb.append(CommonConst.SEPARATOR_DATE);
			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[] getaryImportHeader() {
		return aryImportHeaderItem;
	}
	
	public int getImportHeaderCount() {
		return aryImportHeaderItem.length;
	}
	
	public int getImporDataCount() {
		return aryImportData.length;
	}
	
	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;
	}
	
}
