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

import java.util.Date;
import java.util.Iterator;

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

import jp.mosp.common.CommonConst;

import jp.mosp.common.MosPAction;

import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospUtility;
import jp.mosp.common.common.VoInterface;
import jp.mosp.common.dto.HumanBasisDtoInterface;
import jp.mosp.common.dto.KintaiCommonDtoInterface;

import jp.mosp.common.part.DatePart;
import jp.mosp.common.part.KintaiApprovalPart;
import jp.mosp.common.part.KintaiCalcPart;
import jp.mosp.common.part.KintaiCommonPart;
import jp.mosp.common.part.TimePart;
import jp.mosp.common.part.VariousPart;

import jp.mosp.common.part.PartManager;

import jp.mosp.kintai.action.AttendanceCheckCardAction;
import jp.mosp.kintai.action.AttendanceHolidayCardAction;
import jp.mosp.kintai.action.AttendanceListAction;
import jp.mosp.kintai.action.AttendanceQuitCardAction;
import jp.mosp.kintai.action.AttendanceStartCardAction;

import jp.mosp.kintai.dao.MScheduleDao;
import jp.mosp.kintai.dao.MSyukkinboDao;

import jp.mosp.kintai.dto.MScheduleDto;
import jp.mosp.kintai.dto.MSyukkinboDto;

import jp.mosp.kintai.vo.AttendanceMenuVo;
import jp.mosp.kintai.vo.ScheduleMenuVo;

import jp.mosp.payroll.dto.KintaiCompileDto;

import jp.mosp.system.dto.MWorkTypeDto;
import jp.mosp.workflow.dto.CtOvertimeRequestDto;

public abstract class AttendanceTotalAction extends MosPAction {

	// 僼傿乕儖僪
	protected String	startDate;
	protected String	endDate;

	protected int		lateNightStart 	= 0;
	protected int		lateNightEnd 	= 0;

	protected int		allHoliday	 	= 0;
	protected int		halfHoliday	 	= 0;

	protected int		inputUnit 		= 1;

	protected boolean isAutoCalc;

	protected List<MSyukkinboDto>	attendanceList;
	protected List<MScheduleDto> 	scheduleList;

	// 嬑柋宍懺儅僢僾
	private Map<String, MWorkTypeDto> workTypeMap;

	protected String[][] aryHolidayReason;

	// 擔廤寁僨乕僞
	protected String[][] aryAttendance;
	// 寧廤寁僨乕僞
	protected String[][] aryAttendanceCompile;

	/*						
	 *  	2009/04/21	m.yoshida	捛壛
	 */
	private MScheduleDao 	scheduleDao;
	private MSyukkinboDao 	syukkinboDao;

	/**
	 * 梊掕曤梡DAO弨旛
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @throws Exception
	 */
	private void prepareMScheduleDao() throws Exception {
		// DAO弨旛
		if (scheduleDao !=null) {
			return;
		}
		scheduleDao = PartManager.kintai(partInfo()).getMScheduleDao();
	}

	/**
	 * 弌嬑曤梡DAO弨旛
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @throws Exception
	 */
	private void prepareMSyukkinboDao() throws Exception {
		// DAO弨旛
		if (syukkinboDao !=null) {
			return;
		}
		syukkinboDao = PartManager.kintai(partInfo()).getMSyukkinboDao();
	}

	/**
	 * 梊掕曤梡DAO庢摼
	 * @return	弶婜壔嵪傒MScheduleDao僀儞僗僞儞僗
	 * @throws Exception
	 */
	protected MScheduleDao scheduleDao() throws Exception {
		// 梊掕曤梡DAO弨旛
		prepareMScheduleDao();
		return scheduleDao;
	}

	/**
	 * 弌嬑曤梡DAO庢摼
	 * @return	弶婜壔嵪傒MSyukkinboDao僀儞僗僞儞僗
	 * @throws Exception
	 */
	protected MSyukkinboDao syukkinboDao() throws Exception {
		// 梊掕曤梡DAO弨旛
		prepareMSyukkinboDao();
		return syukkinboDao;
	}

	/**
	 * 梊掕曤懳徾擔庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kcode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @return dto 懳徾DTO
	 * @throws Exception
	 */
	protected MScheduleDto getScheduleInfo(String kcode, String targetDate) throws Exception {
		return scheduleDao().findForKey(kcode, targetDate);
	}

	/**
	 * 梊掕曤懳徾擔庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kcode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @return dto 懳徾DTO
	 * @throws Exception
	 */
	protected MScheduleDto getScheduleInfo(String kcode, Date targetDate) throws Exception {
		return getScheduleInfo(kcode, util.convDateFormatted(targetDate));
	}

	/**
	 * 梊掕曤懳徾擔峴儘僢僋
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔(yyyy/MM/dd)
	 * @return				懳徾DTO
	 * @throws Exception
	 */
	protected MScheduleDto lockScheduleInfo(String kCode, String targetDate) throws Exception {
		return scheduleDao().findForUpdate(kCode, targetDate);
	}

	/**
	 * 弌嬑曤懳徾擔庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kcode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔(yyyy/MM/dd)
	 * @return dto 懳徾DTO
	 * @throws Exception
	 */
	protected MSyukkinboDto getSyukkinboInfo(String kcode, String targetDate) throws Exception {
		return syukkinboDao().findForKey(kcode, targetDate);
	}

	/**
	 * 弌嬑曤懳徾擔庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kcode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @return dto 懳徾DTO
	 * @throws Exception
	 */
	protected MSyukkinboDto getSyukkinboInfo(String kcode, Date targetDate) throws Exception {
		return getSyukkinboInfo(kcode, util.convDateFormatted(targetDate));
	}

	/**
	 * 弌嬑曤懳徾擔峴儘僢僋
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔(yyyy/MM/dd)
	 * @return 				懳徾DTO(峴儘僢僋嵪傒)
	 * @throws Exception
	 */
	protected MSyukkinboDto lockSyukkinboInfo(String kCode, String targetDate) throws Exception {
		return syukkinboDao().findForUpdate(kCode, targetDate);
	}

	/**
	 * 弌嬑曤懳徾擔峴儘僢僋
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @return 				懳徾DTO(峴儘僢僋嵪傒)
	 * @throws Exception
	 */
	protected MSyukkinboDto lockSyukkinboInfo(String kCode, Date targetDate) throws Exception {
		return lockSyukkinboInfo(kCode, util.convDateFormatted(targetDate));
	}

	/**
	 * 弌嬑曤懳徾擔乮峴儘僢僋乯庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔(yyyy/MM/dd)
	 * @return dto 懳徾DTO(峴儘僢僋嵪傒)
	 * @throws Exception
	 */
	protected MSyukkinboDto getSyukkinboInfo(String kCode, String targetDate, boolean isUpdate) throws Exception {
		if (isUpdate) {
			return lockSyukkinboInfo(kCode, targetDate);
		}
		return getSyukkinboInfo(kCode, targetDate);
	}

	/**
	 * 弌嬑曤懳徾擔乮峴儘僢僋乯庢摼
	 * <p>	2009/04/21	m.yoshida	捛壛	</p>
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @return dto 懳徾DTO(峴儘僢僋嵪傒)
	 * @throws Exception
	 */
	protected MSyukkinboDto getSyukkinboInfo(String kCode, Date targetDate, boolean isUpdate) throws Exception {
		if (isUpdate) {
			return lockSyukkinboInfo(kCode, targetDate);
		}
		return getSyukkinboInfo(kCode, targetDate);
	}

	/**
	 * 嬑懹堦棗僨乕僞
	 * @param kCode		懳徾幮堳僐乕僪
	 * @throws Exception
	 */
	protected List<MSyukkinboDto> getAttendanceList(String kCode) throws Exception {
		// 寧堦棗偺庢摼
		attendanceList	= syukkinboDao().findForAttendanceList(kCode, startDate, endDate);
		return attendanceList;
	}

	/**
	 * 嬑懹寧堦棗僨乕僞庢摼
	 * @param kCode       懳徾幮堳僐乕僪
	 * @param targetMonth 懳徾寧
	 * @throws Exception
	 */
	protected List<MSyukkinboDto> getAttendanceList(String kCode, Date targetMonth) throws Exception {
		// 専嶕斖埻庢摼
		startDate = DatePart.convDateFormatted(getStartDate(targetMonth));
		endDate   = DatePart.convDateFormatted(getEndDate(targetMonth));
		// 専嶕
		getAttendanceList(kCode);
		return attendanceList;
	}

	/**
	 * 嬑懹寧堦棗僨乕僞庢摼乮昞帵梡乯
	 * <p>2009/01/20	m.yoshida	捛壛</p>
	 * @param kCode
	 * @param targetDate
	 * @throws Exception
	 */
	protected List<MSyukkinboDto> getAttendanceListForView(String kCode, Date targetDate) throws Exception {
		// 専嶕斖埻庢摼
		startDate = DatePart.convDateFormatted(getStartDateForList(targetDate));
		endDate   = DatePart.convDateFormatted(getEndDateForList(targetDate));
		// 専嶕
		getAttendanceList(kCode);
		return attendanceList;
	}

	/**
	 * 寧廤寁
	 * @param kCode				懳徾幮堳僐乕僪
	 * @param attendanceList	懳徾弌嬑曤儕僗僩
	 * @throws Exception
	 */
	protected void totalAttendanceDaily(
			String kCode,
			List<MSyukkinboDto> attendanceList
	) throws Exception {
		KintaiCompileDto dto = PartManager.kintaicompile(partInfo()).getCompiledInfo(
				kCode,
				attendanceList
		);
		// 攝楍偺弶婜壔
		aryAttendanceCompile = new String[18][2];
		// 攝楍
		// 嬑柋帪娫崌寁
		aryAttendanceCompile[0][0] = CommonConst.NAM_WORKING;
		aryAttendanceCompile[0][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalWork()));
		// 媥宔帪娫崌寁
		aryAttendanceCompile[1][0] = CommonConst.NAM_INTERVAL_TIME;
		aryAttendanceCompile[1][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalInterbal()));
		// 抶崗帪娫崌寁
		aryAttendanceCompile[2][0] = CommonConst.NAM_ARRIVE_LATE;
		aryAttendanceCompile[2][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalLate()));
		// 憗戅帪娫崌寁
		aryAttendanceCompile[3][0] = CommonConst.NAM_LEAVE_EARLY;
		aryAttendanceCompile[3][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalLeave()));
		// 巆嬈帪娫崌寁
		aryAttendanceCompile[4][0] = CommonConst.NAM_OVERTIME;
		aryAttendanceCompile[4][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalOver()));
		// 媥弌帪娫崌寁
		aryAttendanceCompile[5][0] = CommonConst.NAM_WORK_ON_HOLIDAY;
		aryAttendanceCompile[5][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalHolidayWork()));
		// 怺栭帪娫崌寁
		aryAttendanceCompile[6][0] = CommonConst.NAM_LATE_NIGHT;
		aryAttendanceCompile[6][1] = getHourString(util.convIntegerTimeToDoubleTime(dto.getTotalLateNight()));
		// 弌嬑擔悢
		aryAttendanceCompile[7][0] = CommonConst.NAM_PRESENCE;
		aryAttendanceCompile[7][1] = String.valueOf(dto.getTotalWorkDays());
		// 桳媼媥壣擔悢
		aryAttendanceCompile[8][0] = aryHolidayReason[0][1];
		aryAttendanceCompile[8][1] = String.valueOf(dto.getTotalPaidHoliday());
		// 摿暿媥壣擔悢
		aryAttendanceCompile[9][0] = aryHolidayReason[1][1];
		aryAttendanceCompile[9][1] = String.valueOf(dto.getTotalParticularHoliday());
		// 寚嬑媥壣擔悢
		aryAttendanceCompile[10][0] = aryHolidayReason[2][1];
		aryAttendanceCompile[10][1] = String.valueOf(dto.getTotalAbsence());
		// 彎昦媥壣擔悢
		aryAttendanceCompile[11][0] = aryHolidayReason[3][1];
		aryAttendanceCompile[11][1] = String.valueOf(dto.getTotalMedicalLeave());
		// 戙媥擔悢
		aryAttendanceCompile[12][0] = aryHolidayReason[4][1];
		aryAttendanceCompile[12][1] = String.valueOf(dto.getTotalCompensationDay());
		// 怳懼媥壣擔悢
		aryAttendanceCompile[13][0] = aryHolidayReason[5][1];
		aryAttendanceCompile[13][1] = String.valueOf(dto.getTotalTransfer());
		// 懘懠媥壣擔悢
		aryAttendanceCompile[14][0] = CommonConst.NAM_OTHER_SHORT;
		aryAttendanceCompile[14][1] = String.valueOf(dto.getTotalOther());
		// 抶崗憗戅悢
		aryAttendanceCompile[15][0] = CommonConst.NAM_LATE_AND_LEAVE_EARLY;
		aryAttendanceCompile[15][1] = String.valueOf(dto.getLeaveAndLate());
		// 庤摉
		StringBuffer allowance = new StringBuffer();
		allowance.append(dto.getSyokuji());
		allowance.append(CommonConst.STR_SLASH_SEPARATOR);
		allowance.append(dto.getCyoku1());
		allowance.append(dto.getCyoku2());
		allowance.append(dto.getCyoku3());
		allowance.append(CommonConst.STR_SLASH_SEPARATOR);
		allowance.append(dto.getHoka1());
		allowance.append(dto.getHoka2());
		allowance.append(dto.getHoka3());
		allowance.append(dto.getHoka4());
		allowance.append(dto.getHoka5());
		aryAttendanceCompile[16][0] = CommonConst.NAM_ALLOWANCE;
		aryAttendanceCompile[16][1] = allowance.toString();
		// 奆嬑乮寚嬑丄摿暿媥壣丄彎昦丄抶崗憗戅悢偺崌寁乯
		aryAttendanceCompile[17][0] = CommonConst.NAM_PERFECT_ATTENDANCE;
		if (dto.isApplyAttendanceAllowance()) {
			aryAttendanceCompile[17][1] = CommonConst.NAM_PERFECT_ATTENDANCE;
		} else {
			aryAttendanceCompile[17][1] = "";			
		}
	}

	/**
	 * 嬑柋宍懺儅僗僞愝掕
	 * @throws Exception 
	 */
	protected void setWorkTypeMap() throws Exception {
		// 庢摼嵪妋擣
		if (workTypeMap != null) {
			return;
		}
		// Map偺嶌惉
		workTypeMap = getWorkTypeMap();
	}

	/**
	 * 嬑柋宍懺暿忣曬庢摼
	 * @param shiftcode		懳徾嬑柋宍懺僐乕僪
	 * @return
	 * @throws Exception
	 */
	protected MWorkTypeDto getWorkTypeInfo(String shiftcode) throws Exception {
		// 嬑柋宍懺儅僗僞愝掕
		setWorkTypeMap();
		return workTypeMap.get(shiftcode);
	}

	/**
	 * 怺栭帪娫庢摼
	 * @throws Exception 
	 */
	private void setLateNightTime() throws Exception {
		// 抣偺愝掕
		lateNightStart = PartManager.kintai(partInfo()).getLateNightStart();
		lateNightEnd   = lateNightStart + PartManager.kintai(partInfo()).getLateNightEnd();
	}

	/**
	 * 帺摦寁嶼僼儔僌庢摼
	 * @throws Exception
	 */
	private void setAutoCalc() throws Exception {
		// 帺摦寁嶼僼儔僌庢摼
		isAutoCalc = PartManager.kintai(partInfo()).isAutoCalc();
	}

	/**
	 * 媥壣帪娫庢摼
	 * @throws Exception
	 */
	private void setHolidayTimes() throws Exception {
		allHoliday = PartManager.kintai(partInfo()).getAllHolidayTimes();
		halfHoliday = PartManager.kintai(partInfo()).getHalfHolidayTimes();
	}

	/**
	 * 廤寁婎杮愝掕
	 * @throws Exception
	 */
	protected void setCalcParam() throws Exception {
		// 帺摦寁嶼愝掕
		setAutoCalc();
		// 擖椡扨埵帪娫
		setInputUnit();
		// 怺栭帪娫愝掕
		setLateNightTime();
		// 媥壣帪娫愝掕
		setHolidayTimes();
		// 媥壣棟桼
		aryHolidayReason = PartManager.mospcode(partInfo()).getHolidayReasonArray();
	}

	/**
	 * 擖椡扨埵帪娫愝掕
	 * @throws Exception
	 */
	protected void setInputUnit() throws Exception {
		// 擖椡扨埵帪娫
		inputUnit = PartManager.kintai(partInfo()).getInputUnitTimes();
	}

	/**
	 * 彸擣棟桼昞帵
	 * @param riyuu 彸擣棟桼
	 * @return	result
	 * @throws Exception
	 */
	protected String[] getApproval(String riyuu) throws Exception {
		return PartManager.kintaiapproval(partInfo()).getApproval(riyuu);
	}

	/**
	 * 嬑懹専嶕
	 * @throws Exception
	 */
	protected void searchAttendance() throws Exception {
		// 嬑懹専嶕
		MSyukkinboDto dto = getSyukkinboInfo(key1, key2);
		if (VariousPart.chkExistDto(dto)) {
			if (!KintaiCommonPart.isHoliday(dto)) {
				// 弌嬑桳傝丄戅嬑柍偟
				if (dto.getTaJikoku().equals("") 
						&& !KintaiCommonPart.isWeekHoliday(dto)
				) {
					// 戅嬑昞帵傊
					setNextCmd(AttendanceQuitCardAction.CMD_QUIT_CARD_SHOW);
				} else {
					// 弌嬑桳傝丄戅嬑桳傝乮廡媥偺応崌傕乯
					// 妋擣昞帵傊
					setNextCmd(AttendanceCheckCardAction.CMD_CHECK_CARD_SELECT);
				}				
			} else {
				// 媥壣
				// 媥壣昞帵傊
				setNextCmd(AttendanceHolidayCardAction.CMD_HOLIDAY_CARD_SELECT);		
			}
		} else {
			// 弌嬑昞帵傊
			setNextCmd(AttendanceStartCardAction.CMD_START_CARD_SHOW);
		}
		// 僒乕僽儗僢僩傊揮憲
		setUrl(MospConst.URL_SRV);
	}

	/**
	 * 嬑懹搊榐僷儔儊乕僞愝掕
	 * @param vo
	 * @throws Exception
	 */
	protected void setAttendanceInfo(AttendanceMenuVo vo) throws Exception {
		// 恖帠婎杮忣曬庢摼
		HumanBasisDtoInterface mKihonDto = getBasisInfo(key1);
		// AttendanceMenuVo偵抣傪僙僢僩
		vo.setHidKCode(mKihonDto.getKCode());
		vo.setHidKName(mKihonDto.getSimei());
		vo.setHidYear(String.valueOf(MospUtility.getYear(MospUtility.getDate(key2))));
		vo.setHidMonth(String.valueOf(MospUtility.getMonth(MospUtility.getDate(key2))));
		vo.setHidDay(String.valueOf(MospUtility.getDay(MospUtility.getDate(key2))));
		vo.setHidDate(util.convStringDateFormatted(vo.getHidYear(), vo.getHidMonth(), vo.getHidDay()));
		vo.setHidSelectCmd(cmd);
		vo.setLblKCode(vo.getHidKCode());
		vo.setLblKName(vo.getHidKName());
		vo.setLblYear(vo.getHidYear());
		vo.setLblMonth(vo.getHidMonth());
		vo.setLblDay(vo.getHidDay());
		// 巆嬈怽惪忣曬愝掕
		setOverTimeRequestInfo(vo);
	}

	/**
	 * 昞帵儌乕僪僙僢僩
	 * <p>[怴婯]丄[峏怴]丄[彸擣嵪傒]</p>
	 * @param vo
	 * @param dto
	 */
	protected void setMode(AttendanceMenuVo vo, MSyukkinboDto dto) throws Exception {
		if (!chkExistDto(dto)) {
			vo.setMode(AttendanceMenuVo.MODE_INSERT);
		} else if (KintaiApprovalPart.isApproved(dto)) {
			vo.setMode(AttendanceMenuVo.MODE_APPROVED);
		} else {
			vo.setMode(AttendanceMenuVo.MODE_EDIT);
		}
	}

	/**
	 * 嵞専嶕梡MenuVo偺曐懚
	 * @param vo
	 */
	protected void setStoreAttendanceMenuVo(AttendanceMenuVo vo) {
		// 曐懚VO偺攋婞
		removeStoredVo(CommonConst.VO_ATTENDANCE_MENU);
		// VO偺曐懚
		storeVo(CommonConst.VO_ATTENDANCE_MENU, vo);
	}

	/**
	 * 廽擔柤徧庢摼
	 * <p>	2009/02/25	m.yoshida	廽擔儊僜僢僪廋惓 </p>
	 * @param targetDate		懳徾擭寧擔
	 * @return	懳徾擭寧擔廽擔柤徧
	 * @throws Exception
	 */
	protected String getPublicHolidayName(Date targetDate) throws Exception {
		return PartManager.holiday(partInfo()).getPublicHolidayName(targetDate);
	}

	/**
	 * 嬑懹堦棗梡僒僽僞僀僩儖僐儅儞僪偺愝掕
	 * @param vo	懳徾VO
	 */
	protected void setSubTitleMenu(AttendanceMenuVo vo) {
		// 嬑懹娗棟僐儅儞僪
		if (getStoredVo(CommonConst.VO_EMPLOYEE_ATTENDANCE_LIST) != null) {
			// 忬懺慗堏妋擣
			vo.setCmdMenuButton(vo.CMD_MENU_MAMAGE);
			vo.setCmdListButton(AttendanceListAction.CMD_ATTENDANCE_LIST_RE_SEARCH);
			vo.setNamListButton(CommonConst.TTL_ATTENDANCE_LIST);
		} else {
			vo.setCmdMenuButton(vo.CMD_MENU_INPUT);
			vo.setCmdListButton(vo.CMD_MENU_INPUT);
			vo.setNamListButton(CommonConst.NAM_MENU);			
		}
	}

	/*僗働僕儏乕儖娭楢*/

	/**
	 * 梊掕寧堦棗僨乕僞
	 * @param kCode		懳徾幮堳僐乕僪
	 * @throws Exception
	 */
	protected List<MScheduleDto> getScheduleList(String kCode) throws Exception {
		// 寧堦棗偺庢摼
		scheduleList = scheduleDao().findForScheduleList(kCode, startDate, endDate);
		return scheduleList;
	}

	/**
	 * 梊掕寧堦棗僨乕僞庢摼
	 * @param kCode       懳徾幮堳僐乕僪
	 * @param targetMonth 懳徾寧
	 * @throws Exception
	 */
	protected List<MScheduleDto> getScheduleList(String kCode, Date targetMonth) throws Exception {
		// 専嶕斖埻庢摼
		startDate = DatePart.convDateFormatted(getStartDate(targetMonth));
		endDate   = DatePart.convDateFormatted(getEndDate(targetMonth));
		// 専嶕
		getScheduleList(kCode);
		return scheduleList;
	}

	/**
	 * 梊掕寧堦棗僨乕僞庢摼乮昞帵梡乯
	 * <p>2009/01/20	m.yoshida	捛壛</p>
	 * @param kCode 		懳徾幮堳僐乕僪
	 * @param targetDate	懳徾擭寧擔
	 * @throws Exception
	 */
	protected List<MScheduleDto> getScheduleListForView(String kCode, Date targetDate) throws Exception {
		// 専嶕斖埻庢摼
		startDate = DatePart.convDateFormatted(getStartDateForList(targetDate));
		endDate   = DatePart.convDateFormatted(getEndDateForList(targetDate));
		// 専嶕
		getScheduleList(kCode);
		return scheduleList;
	}

	/**
	 * 擔廤寁僨乕僞帪娫愝掕
	 * @param scheduleList		懳徾梊掕曤儕僗僩
	 * @throws Exception
	 */
	protected void setScheduleHours(List<MScheduleDto> scheduleList) throws Exception {
		// 嬑懹忣曬愝掕
		setCalcParam();
		// 擔廤寁僨乕僞庢摼
		Iterator<MScheduleDto> it = scheduleList.iterator();
		while (it.hasNext()) {
			MScheduleDto dto = it.next();
			if (KintaiCommonPart.isHoliday(dto)) {
				// 媥壣偺応崌
				dto.setKKJikan(allHoliday);
			} else if (KintaiCommonPart.isWeekHoliday(dto)) {
				// 廡媥偺応崌
			} else {
				// 弌嬑偺応崌
				// 嬑懹崁栚偺寁嶼
				dto = (MScheduleDto)getCalculatedInfo(dto);
			}
		}
	}

	/*梊掕曤娭楢*/

	/**
	 * 慖戰幮堳恖帠婎杮忣曬庢摼
	 * @param vo
	 * @throws Exception
	 */
	protected void setSelectBasicInfo(ScheduleMenuVo vo) throws Exception {
		// 恖帠婎杮忣曬偺庢摼
		HumanBasisDtoInterface mKihonDto = getBasisInfo(vo.getSelectKCode());
		// 慖戰忣曬偺愝掕
		vo.setSelectKName(mKihonDto.getSimei());
		vo.setSelectSectionName(getSectionName(mKihonDto.getSCode()));
	}

	/**
	 * 梊掕曤忣曬偺僙僢僩
	 * @param mKihonDto 	懳徾幮堳婎杮忣曬
	 * @param arySchedule 	懳徾擖椡梊掕曤忣曬
	 * @return dto 懳徾DTO
	 * @throws Exception
	 */
	protected MScheduleDto setScheduleInfo(
			HumanBasisDtoInterface mKihonDto,
			String[] arySchedule
	) throws Exception {
		MScheduleDto dto = new MScheduleDto();
		dto.setKCode(mKihonDto.getKCode());
		dto.setHizuke(arySchedule[0]);
		dto.setNen(MospUtility.getYear(util.convStringDateToDate(dto.getHizuke())));
		dto.setTuki(MospUtility.getMonth(util.convStringDateToDate(dto.getHizuke())));
		dto.setHi(MospUtility.getDay(util.convStringDateToDate(dto.getHizuke())));
		dto.setSyozoku(mKihonDto.getSCode());
		dto.setUpdtTimes(util.getDateTime(DatePart.getNowDate()));
		dto.setSnRiyuu(CommonConst.NUM_ATTENDANCE_REQUEST);
		if (KintaiCommonPart.isWeekHoliday(arySchedule[1])) {
			// 廡媥偺応崌
			dto.setKinmu(CommonConst.ATTENDANCE_TYPE_WEEK_HOLIDAY);
		} else {
			MWorkTypeDto workTypeDto = getWorkTypeInfo(arySchedule[1]);
			dto.setKinmu(workTypeDto.getShiftCode());
			dto.setSyJikoku(util.convIntegerTimeToStringTime(workTypeDto.getStartTime()));
			dto.setSyTimes(util.getDateTime(DatePart.getNowDate()));
			dto.setTaJikoku(util.convIntegerTimeToStringTime(workTypeDto.getQuitTime()));
			dto.setKinmuJi(workTypeDto.getWorkTime());
			dto.setKyukeiJi(workTypeDto.getBreakTime());
			dto.setTaTimes(util.getDateTime(DatePart.getNowDate()));
		}
		return dto;
	}

	/**
	 * 弌嬑曤偺搊榐
	 * @param dto			懳徾DTO
	 * @param vo			懳徾VO
	 * @throws Exception
	 */
	protected void insert(MSyukkinboDto dto, VoInterface vo) throws Exception {
		// 懚嵼僠僃僢僋
		chkDuplicate(getSyukkinboInfo(dto.getKCode(), dto.getHizuke()), vo);
		// 僨乕僞偺憓擖
		syukkinboDao().insert(dto);
		// DTO偺嵞庢摼
		chkInsert(getSyukkinboInfo(dto.getKCode(), dto.getHizuke()));
	}

	/**
	 * 梊掕曤偺搊榐
	 * @param dto
	 * @throws Exception
	 */
	protected void registSchedule(MScheduleDto dto, VoInterface vo) throws Exception {
		MScheduleDto currentDto = getScheduleInfo(dto.getKCode(), dto.getHizuke());
		if (chkExistDto(currentDto)) {
			// 攔懠妋擣
			chkExclusive(currentDto, lockScheduleInfo(dto.getKCode(), dto.getHizuke()), vo);
			// 峏怴
			scheduleDao().update(dto);
		} else {
			// 搊榐
			scheduleDao().insert(dto);
		}
		// DTO偺嵞庢摼	
		chkUpdate(getScheduleInfo(dto.getKCode(), dto.getHizuke()));
	}

	/**
	 * 弌嬑曤梡忣曬愝掕
	 * @param dto MScheduleDto
	 * @return mSyukkinboDto MSyukkinboDto
	 * @throws Exception
	 */
	protected MSyukkinboDto copyScheduleInfo(MScheduleDto dto) throws Exception {
		return KintaiCommonPart.copyScheduleToSyukkinbo(dto);
	}

	/**
	 * 僇儞儅嬫愗傝偺擔晅傪庢摼
	 * @param year		
	 * @param month
	 * @param day
	 * @return
	 */
	protected String getMessageDate(String year, String month, String day) {
		return util.convStringDateFormatted(year, month, day);
	}

	/**
	 * 嬑懹寁嶼婡屇傃弌偟
	 * @param shiftCode		懳徾嬑柋宍懺k僐乕僪
	 * @return	嬑懹寁嶼婡僀儞僗僞儞僗
	 * @throws Exception 
	 */
	protected KintaiCalcPart getCalculator(String shiftCode) throws Exception {
		MWorkTypeDto dto = getWorkTypeInfo(shiftCode);
		if (dto == null) {
			throw new NullPointerException();
		}
		return new KintaiCalcPart(
				dto.getStartTime(),
				dto.getQuitTime(),
				dto.getWorkTime(),
				dto.getBreakTime(),
				dto.getOverStart(),
				dto.getOverBreak(),
				lateNightStart,
				lateNightEnd,
				halfHoliday,
				inputUnit
		);
	}

	/**
	 * 弌嬑崁栚寁嶼
	 * @param dto			懳徾弌嬑曤DTO
	 * @return	弌嬑崁栚寁嶼嵪傒弌嬑曤DTO
	 * @throws Exception
	 */
	protected MSyukkinboDto getStartCalculated(MSyukkinboDto dto) throws Exception {
		// 嬑柋宍懺暿忣曬愝掕
		KintaiCalcPart calc = getCalculator(dto.getKinmu());
		// 弌嬑崁栚偺寁嶼
		calc.runCalcStartTime(
				// 弌嬑帪娫僙僢僩
				util.convStringTimeToIntegerTime(dto.getSyJikoku()),
				KintaiCommonPart.isStartHalfHoliday(dto),
				KintaiCommonPart.isWorkOnHoliday(dto)
		);
		// 抶崗帪娫僙僢僩
		dto.setTiJikan(calc.getLateTime());
		return dto;
	}

	/**
	 * 嬑懹崁栚寁嶼
	 * @param dto		懳徾DTO
	 * @return	嬑懹崁栚寁嶼嵪傒DTO
	 * @throws Exception
	 */
	protected KintaiCommonDtoInterface getCalculatedInfo(KintaiCommonDtoInterface dto) throws Exception {
		// 嬑懹寁嶼婡庢摼
		KintaiCalcPart calc = getCalculator(dto.getKinmu());
		// 奺崁栚偺寁嶼
		calc.runCalculate(
				// 弌嬑帪崗嶼弌
				util.convStringTimeToIntegerTime(dto.getSyJikoku()),
				// 戅嬑帪崗嶼弌
				util.convStringTimeToIntegerTime(dto.getTaJikoku()),
				KintaiCommonPart.isStartHalfHoliday(dto),
				KintaiCommonPart.isQuitHalfHoliday(dto),
				KintaiCommonPart.isWorkOnHoliday(dto)
		);
		// 抶崗帪娫僙僢僩
		dto.setTiJikan(calc.getLateTime());
		// 嬑柋帪娫僙僢僩
		dto.setKinmuJi(calc.getWorkTime());
		// 憗戅帪娫僙僢僩
		dto.setSoJikan(calc.getLeaveTime());
		// 巆嬈帪娫僙僢僩
		dto.setZaJikan(calc.getOverTime());
		// 媥宔帪娫僙僢僩
		dto.setKyukeiJi(calc.getIntervalTime());
		// 怺栭帪娫僙僢僩
		dto.setSnJikan(calc.getLateNightTime());
		// 媥弌帪娫僙僢僩
		dto.setKsJikan(calc.getHolidayWorkTime());
		return dto;
	}

	/**
	 * 巆嬈怽惪忣曬愝掕
	 * @param vo			懳徾VO
	 * @throws Exception
	 */
	protected void setOverTimeRequestInfo(AttendanceMenuVo vo) throws Exception {
		// 巆嬈怽惪忣曬庢摼
		CtOvertimeRequestDto dto = PartManager.overtime(partInfo()).getTargetOverTimeRequest(
				vo.getHidKCode(),
				DatePart.convStringDateToDate(vo.getHidDate())
		);
		// 弶婜壔
		vo.setApplicationTime("");
		vo.setRequestStatus("");
		if (VariousPart.chkExistDto(dto)) {
			// 怽惪帪娫
			vo.setApplicationTime(TimePart.convIntegerTimeToJPHours(dto.getOverTime()));
			// 彸擣忬嫷
			vo.setRequestStatus(PartManager.kintaiapproval(partInfo())
					.getApprovalName(
							PartManager.workflow(partInfo())
							.toKintaiApprovalStatus(dto.getWorkflow())
					)
			);
		}
	}

}
