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

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jp.mosp.common.CommonConst;
import jp.mosp.system.dao.MWorkTypeDao;
import jp.mosp.system.dto.MWorkTypeDto;

/**
 * 勤務形態に関するPartクラス
 * @author yoshida
 *	@version	0.0.1
 */
public class WorkTypePart extends BasePart {

	/**
	 * コンストラクタ
	 */
	public WorkTypePart() {
		super();
	}

	/**
	 * コンストラクタ
	 * @param partInfo
	 */
	public WorkTypePart(PartInfo partInfo) {
		super(partInfo);
	}

	/**
	 * CM_WORKTYPEテーブル用DAOの取得
	 * @return	初期化済みMWorkTypeDaoインスタンス
	 * @throws Exception
	 */
	public MWorkTypeDao getMWorkTypeDao() throws Exception {
		return (MWorkTypeDao)getPreparedDao(MWorkTypeDao.class.getCanonicalName());
	}

	/**
	 * 勤務形態コード取得(CM_WORKTYPE)
	 * @return 勤務形態コードリスト
	 * @throws Exception 
	 */
	public String[][] getWorkTypeArrayNotDeleted() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAvailable();
		// 配列の作成
		String[][] aryWorkType = new String[listWorkType.size()][2];
		for (int i = 0; i < listWorkType.size(); i++) {
			aryWorkType[i][0] = listWorkType.get(i).getShiftCode();
			aryWorkType[i][1] = listWorkType.get(i).getShiftName();
		}
		return aryWorkType;
	}

	/**
	 * 勤務形態コード取得(CM_WORKTYPE)（週休付）
	 * @return 勤務形態コードリスト
	 * @throws Exception 
	 */
	public String[][] getWorkTypeArrayWithWeekHoliday() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAvailable();
		// 配列の作成
		String[][] aryWorkType = new String[listWorkType.size()][2];
		for (int i = 0; i < listWorkType.size(); i++) {
			aryWorkType[i][0] = listWorkType.get(i).getShiftCode();
			aryWorkType[i][1] = listWorkType.get(i).getShiftName();
		}
		aryWorkType = StringPart.addArrayLastRowValue(aryWorkType,
				CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY,
				CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY);
		return aryWorkType;
	}

	/**
	 * 勤務形態コード取得(CM_WORKTYPE)
	 * @return 勤務形態コードリスト
	 * @throws Exception 
	 */
	public String[][] getWorkTypeArrayAll() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAll();
		// 配列の作成
		String[][] aryWorkType = new String[listWorkType.size()][2];
		for (int i = 0; i < listWorkType.size(); i++) {
			aryWorkType[i][0] = listWorkType.get(i).getShiftCode();
			aryWorkType[i][1] = listWorkType.get(i).getShiftName();
		}
		return aryWorkType;
	}

	/**
	 * 勤務形態コード取得(CM_WORKTYPE)
	 * @return 勤務形態コードリスト
	 * @throws Exception 
	 */
	public String[][] getWorkTypeArrayAllWithWeekHoliday() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAll();
		// 配列の作成
		String[][] aryWorkType = new String[listWorkType.size()][2];
		for (int i = 0; i < listWorkType.size(); i++) {
			aryWorkType[i][0] = listWorkType.get(i).getShiftCode();
			aryWorkType[i][1] = listWorkType.get(i).getShiftName();
		}
		aryWorkType = StringPart.addArrayLastRowValue(aryWorkType,
				CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY,
				CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY);
		return aryWorkType;
	}

	/**
	 * 勤務形態情報取得(CM_WORKTYPE)
	 * @return 勤務形態コードリスト
	 * @throws Exception 
	 */
	public String[][] getWorkTypeDataArray() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAll();
		// 配列の作成
		String[][] aryWorkType = new String[listWorkType.size()][8];
		for (int i = 0; i < listWorkType.size(); i++) {
			aryWorkType[i][0] = listWorkType.get(i).getShiftCode();
			aryWorkType[i][1] = listWorkType.get(i).getShiftName();
			aryWorkType[i][2] = String.valueOf(listWorkType.get(i).getStartTime());
			aryWorkType[i][3] = String.valueOf(listWorkType.get(i).getQuitTime());
			aryWorkType[i][4] = String.valueOf(listWorkType.get(i).getWorkTime());
			aryWorkType[i][5] = String.valueOf(listWorkType.get(i).getBreakTime());
			aryWorkType[i][6] = String.valueOf(listWorkType.get(i).getOverStart());
			aryWorkType[i][7] = String.valueOf(listWorkType.get(i).getOverBreak());
		}
		return aryWorkType;
	}

	/**
	 * 勤務形態リスト取得(CM_WORKTYPE)
	 * @return 勤務形態リスト
	 * @throws Exception 
	 */
	public Map<String, MWorkTypeDto> getWorkTypeMap() throws Exception {
		// 情報の取得
		List<MWorkTypeDto> listWorkType = getMWorkTypeDao().findAll();
		// Mapの作成
		HashMap<String, MWorkTypeDto> map = new HashMap<String, MWorkTypeDto>();
		for (int i = 0; i < listWorkType.size(); i++) {
			map.put(listWorkType.get(i).getShiftCode(), listWorkType.get(i));
		}
		return map;
	}

}
