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

import java.util.Date;

import jp.mosp.common.common.BaseVo;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;
import jp.mosp.common.common.MospUtility;
import jp.mosp.payroll.base.PayrollAction;
import jp.mosp.payroll.base.PayrollConst;
import jp.mosp.payroll.payment.vo.PaymentReportVo;

/**
 * 給与帳票出力画面における処理を行う。<br><br>
 * 以下のコマンドを扱う。
 * <ul><li>
 * {@link #CMD_SHOW}
 * </li></ul>
 */
public class PaymentReportAction extends PayrollAction {
	
	/**
	 * 画面表示コマンド。<br><br>
	 * 給与計算中の年月を取得、表示する。<br>
	 * もし給与計算中の年月がなかった場合は、システム年月を表示する。<br>
	 */
	public static final String CMD_SHOW = "P1260";
	
	/**
	 * Actionの初期化を行う。<br><br>
	 * 以下の処理を行う。
	 * <ul><li>
	 * {@link PayrollAction#PayrollAction()}
	 * </li></ul>
	 */
	public PaymentReportAction() {
		super();
	}
	
	/* (non-Javadoc)
	 * @see jp.mosp.common.common.BaseAction#getSpecificVo()
	 */
	@Override
	protected BaseVo getSpecificVo() {
		return new PaymentReportVo();
	}
	
	/**
	 * アクション。<br>
	 * 詳細は、クラス説明を参照。<br>
	 */
	public void action() throws Exception {
		// VO取得及び設定
		prepareVo();
		if (this.cmd.equals(CMD_SHOW)) {
			// 画面表示
			show();
		} else {
			throw new MospException(MospConst.EX_CMD_INVALID);
		}
	}
	
	/**
	 * 画面表示処理を行う。<br><br>
	 * @throws Exception 
	 */
	private void show() throws Exception {
		// コネクション取得
		getConnection();
		// VO取得
		PaymentReportVo vo = (PaymentReportVo)getVo();
		// システム日付取得
		Date sysDate = new Date();
		// プルダウンアイテム設定
		vo.setPitYear(getYearArray(
				PayrollConst.DEFAULT_CURRENT_YEAR, MospUtility.getYear(sysDate) + 1));
		vo.setPitMonth(getMonthArray());
		vo.setPitOutYear(getYearArray(
				PayrollConst.DEFAULT_CURRENT_YEAR, MospUtility.getYear(sysDate) + 1));
		vo.setPitOutMonth(getMonthArray());
		vo.setPitOffice  (getOfficeArray());
		vo.setPitSection (getSectionArrayAll());
		// 計算中情報取得
		Date current = getCurrent(PayrollConst.OFFICE_ALL, PayrollConst.CALC_PAYMENT);
		// 計算中情報確認
		if (current == null) {
			// VOフィールド設定
			vo.setPltYear (MospUtility.getYear (sysDate));
			vo.setPltMonth(MospUtility.getMonth(sysDate));
			vo.setPltOutYear (MospUtility.getYear (sysDate));
			vo.setPltOutMonth(MospUtility.getMonth(sysDate));
			return;
		}
		// VOフィールド設定
		vo.setPltYear (MospUtility.getYear (current));
		vo.setPltMonth(MospUtility.getMonth(current));
		vo.setPltOutYear (MospUtility.getYear (sysDate));
		vo.setPltOutMonth(MospUtility.getMonth(sysDate));
	}

}
