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

import jp.mosp.common.part.KintaiCompilePart;
import jp.mosp.common.part.PartManager;
import jp.mosp.common.part.VariousPart;
import jp.mosp.kintai.dto.MSyukkinboDto;
import jp.mosp.payroll.dao.MKintaiDao;
import jp.mosp.payroll.dao.MKintaiKinmuDao;
import jp.mosp.payroll.dto.CompileAmendmentDto;
import jp.mosp.payroll.dto.MKintaiDto;

public abstract class KintaiCompileAction extends AttendanceTotalAction {

	// 僼傿乕儖僪
	private MKintaiDao	kintaiDao;
	private MKintaiKinmuDao kinmuDao;

	/**
	 * 
	 * @throws Exception
	 */
	private void prepareMkintaiDao() throws Exception {
		// DAO弨旛
		if (VariousPart.chkExistObject(kintaiDao)) {
			return;
		}
		kintaiDao = PartManager.kintaicompile(partInfo()).getMKintaiDao();
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	protected MKintaiDao kintaiDao() throws Exception {
		prepareMkintaiDao();
		return kintaiDao;
	}

	/**
	 * 
	 * @throws Exception
	 */
	private void prepareMkintaiKinmuDao() throws Exception {
		// DAO弨旛
		if (VariousPart.chkExistObject(kinmuDao)) {
			return;
		}
		kinmuDao = PartManager.kintaicompile(partInfo()).getMKintaiKinmuDao();
	}

	/**
	 * 
	 * @return
	 * @throws Exception
	 */
	protected MKintaiKinmuDao kinmuDao() throws Exception {
		prepareMkintaiKinmuDao();
		return kinmuDao;
	}

	/**
	 * 枹彸擣桳柍専嶕
	 * @param dto 			懳徾DTO
	 * @param targetMonth 	慖戰擭寧
	 * @return true乧枹彸擣柍偟丄false乧枹彸擣桳傝
	 * @throws Exception
	 */
	protected boolean checkApproval(CompileAmendmentDto dto, Date targetMonth) throws Exception {
		// 弌嬑曤偺庢摼偲弨旛
		getAttendanceList(dto.getKCode(), targetMonth);
		// 彸擣丒枹彸擣審悢嶌惉
		int[] number = KintaiCompilePart.makeApprovalNumber(attendanceList);
		// 枹彸擣審悢
		if (number[1] == 0 && number[2] > 0) {
			return true;
		}
		return false;
	}

	/**
	 * 嬑懹寧廤寁
	 * @param kCode			懳徾幮堳僐乕僪
	 * @param targetMonth	懳徾擭寧
	 * @return	mKintaiDto	廤寁嵪傒DTO
	 * @throws Exception
	 */
	protected MKintaiDto getCompiledInfo(
			String kCode,
			Date targetMonth,
			List<MSyukkinboDto> attendanceList
	) throws Exception {
		return PartManager.kintaicompile(partInfo()).getCompiledInfo(
				kCode,
				targetMonth,
				attendanceList
		);
	}

}
