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

import java.util.Date;

import jp.mosp.common.CommonConst;
import jp.mosp.common.MosPAction;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;
import jp.mosp.common.common.MospUtility;

import jp.mosp.payroll.vo.AttendanceExportCardVo;

public class AttendanceExportCardAction extends MosPAction {

	// コマンド
	private static final String CMD_EXPORT_CARD_SHOW = "P1050";

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

	/**
	 * アクション
	 */
	public void action() throws Exception {
		// DBコネクション取得
		getConnection();
		// PAYROLL権限確認
		confirmPayrollAuth();
		// VOの取得
		AttendanceExportCardVo vo = getInitVo();
		init(vo);
		// コマンド毎の処理
		if (cmd.equals(CMD_EXPORT_CARD_SHOW)) {
			// 表示			
			show(vo);
		} else {
			throw new MospException(MospConst.EX_CMD_INVALID);
		}
	}

	protected AttendanceExportCardVo getInitVo() {
		AttendanceExportCardVo vo = null;
		Object obj = session.getAttribute(MospConst.ATT_FORMER_VO);
		if (obj instanceof AttendanceExportCardVo) {
			vo = (AttendanceExportCardVo)obj;
		} else {
			vo = new AttendanceExportCardVo();
		}	
		return vo;
	}

	/**
	 * 初期処理
	 * @param vo			対象VO
	 * @throws Exception
	 */
	protected void init(AttendanceExportCardVo vo) throws Exception {
		vo.clearMessage();
		vo.clearErrField();
		vo.initVo(cfg, msg, cmd, aspUser, user);
		// VO及びフォワード先URLの設定
		setVo(vo);
		setUrl(vo.getRetUrl());
		session.setAttribute(MospConst.ATT_FORMER_VO, vo);
		// ユーザー情報取得
		getInfo(user.getUserId());
		// プルダウン取得
		if (hasCalculateAuth()) {
			vo.aryPltSection = util.addArrayFirstRowValue(
					getSectionArrayAll(), 
					CommonConst.NAM_COMMON_STRING_INITIAL_VALUE,
					CommonConst.NAM_ALL_SECTION
			);
		} else {
			vo.aryPltSection = getSectionArrayForManager();
		}
		// 年度リスト取得
		vo.aryPltYear = util.getYearArray(MospUtility.getYear(getCalcMonth()), 1, 1);
		// 月リスト取得
		vo.aryPltMonth = util.getMonthArray();
	}

	/**
	 * 表示
	 * @param vo			対象VO
	 * @throws Exception
	 */
	protected void show(AttendanceExportCardVo vo) throws Exception {
		// 勤怠計算対象年月取得
		Date current = getCalcMonth();
		vo.setPltYear(String.valueOf(MospUtility.getYear(current)));
		vo.setPltMonth(String.valueOf(MospUtility.getMonth(current)));
		vo.setPltSection(mKihon.getSCode());
	}

}
