package jp.mosp.payroll.common.action;

import java.io.Serializable;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospException;
import jp.mosp.common.common.MospUtility;
import jp.mosp.common.part.DatePart;
import jp.mosp.human.dto.MKihonDto;
import jp.mosp.payroll.base.AdjustmentAction;
import jp.mosp.payroll.base.Employee;
import jp.mosp.payroll.base.PayrollConst;
import jp.mosp.payroll.common.vo.InsuranceConfSetVo;
import jp.mosp.payroll.common.vo.InsuranceMonthlyCardVo;
import jp.mosp.payroll.dto.CdSocInsuranceDto;

public class InsuranceMonthlyCardAction extends AdjustmentAction {
	
	// コマンド
	private static final String CMD_INSURANCE_CARD_SHOW		= "P4002";	// 参照
	private static final String CMD_INSURANCE_CARD_NEXT		= "P4003";	// 次社員
	private static final String CMD_INSURANCE_CARD_BEFORE		= "P4004";	// 前社員
	private static final String CMD_INSURANCE_CARD_REGIST		= "P4005";	// 登録
	private static final String CMD_INSURANCE_RECAL			= "P4006";	// 再計算
	public  static final String CMD_INSURANCE_CARD_BACK		= "P4007";	// 戻し
	public  static final String CMD_INSURANCE_CARD_NEWKCODE	= "P4008";	// 社員コード変更

	private	int		nowYear = 0;										// 今年度計算用
	private	Date	startDate	=	null;								// 算定開始日付（年・月）
	private	Date	tekiyouDate	=	null;								// 適用日付（年・月）

	/**
	 * アクション
	 */
	public void action() throws Exception {
		int	intCalcDate				=	0;			//徴収年月取得用work
		InsuranceConfSetVo	confVo;
		// DBコネクション取得
		getConnection();
		// PAYROLL権限確認
		confirmPayrollAuth();
		Date nowDateTmp = getSystemDate();				//本日日付を取得
		nowYear	=	MospUtility.getYear(nowDateTmp);	//今年を取得
		// VOの取得及び設定
		InsuranceMonthlyCardVo vo	=	new InsuranceMonthlyCardVo();
		vo = (InsuranceMonthlyCardVo)getStoredVo(vo.getClassName());
		if (vo == null || cmd.equals(CMD_INSURANCE_CARD_SHOW)) {
			vo = new InsuranceMonthlyCardVo();
			storeVo(vo.getClassName(), vo);
		}
		prepareDao();	//DBデータ操作準備
		vo.initVo(cfg, msg, cmd, aspUser, user);
		vo.clearMessage();
		vo.clearErrField();
		setVo(vo);			// VO及びフォワード先URLの設定
		setUrl(vo.getRetUrl());
		setNameArray(vo);	// 名称取得用配列取得

		confVo	=	(InsuranceConfSetVo)getStoredVo(PayrollConst.VO_INSURANCECONF_SET); // 算定・月変条件設定VOの取得
		vo.setConfVo( confVo );	// 算定・月変条件設定VOの設定

		//昇(降)給開始月（年月）を取得設定
		if((confVo.prmSyoukyuTuki == null) || (confVo.prmSyoukyuTuki.equals("0"))){
			intCalcDate = (nowYear * 10000) + (PayrollConst.MONTH_SYOUKYU_DEFAULT * 100) + PayrollConst.TIME_DEFAULT_DAY;
		}else{
			intCalcDate = (nowYear * 10000) + (Integer.valueOf(confVo.prmSyoukyuTuki) * 100 ) + PayrollConst.TIME_DEFAULT_DAY;
		}
		startDate = DatePart.convIntegerDateToDate(intCalcDate);

		//適用月（年月）を取得設定
		if(confVo.idButtonSyori.equals(InsuranceConfSetVo.PRM_CKR_SANTEI_KISO)){	//算定基礎指定の場合
			intCalcDate = (nowYear * 10000) + (PayrollConst.MONTH_TEKIYOU_DEFAULT * 100) + PayrollConst.TIME_DEFAULT_DAY;
		}else{
			if((confVo.prmSyoukyuTuki == null) || (confVo.prmSyoukyuTuki.equals("0"))){
				intCalcDate = (nowYear * 10000) + (PayrollConst.MONTH_TEKIYOU_DEFAULT * 100) + PayrollConst.TIME_DEFAULT_DAY;
			}else{
				intCalcDate = (nowYear * 10000) + ((Integer.valueOf(confVo.prmSyoukyuTuki) + 3 ) * 100 ) + PayrollConst.TIME_DEFAULT_DAY;
			}
		}
		tekiyouDate = DatePart.convIntegerDateToDate(intCalcDate);
		
		// 和暦年テーブル設定
		vo.aryCode  = getCodeArray(PayrollConst.TID_JAPANESE);
		vo.listConf = getConfList(PayrollConst.CONF_ID_JP_IMP_CAL);
		
		// コマンド毎の処理
		if (cmd.equals(CMD_INSURANCE_CARD_SHOW)) {		//初期表示
			// 人事情報取得
			List<Employee> listEmployee = new ArrayList<Employee>();
			vo.setTargetMonth( nowDateTmp ); //画面表示用ヘッダー日付設定
			confVo.setParamsAll(request);	// 算定・月変条件設定画面の引継ぎパラメータの設定
			//6月1日の在籍する社員が対象のため今年の6月1日を設定
			Calendar cal1 = Calendar.getInstance();
			Calendar cal2 = Calendar.getInstance();
			cal1.set(nowYear, PayrollConst.MONTH_SANTEI_DEFAULT, PayrollConst.TIME_DEFAULT_DAY,0,0,0);
			cal2.set(nowYear, PayrollConst.TIME_ADJ_PAY_MONTH, PayrollConst.TIME_DAY_MAX,0,0,0);
			int	TargetDate		=	DatePart.convDateToInteger(cal1.getTime());
			int	LastYearDate	=	DatePart.convDateToInteger(cal2.getTime());
			List<MKihonDto>	listKcode =	mKihonPayrollDao.findForSection(TargetDate, LastYearDate);
			for(int i=0; i< listKcode.size(); i++){
				Employee employee = getEmployee( listKcode.get(i).getKCode() );
				if(null != employee){
					listEmployee.add( employee );
				}
			}
			if(confVo.idButtonJyouken.equals(InsuranceConfSetVo.PRM_CKR_JYUNJYO_KCODE)){	//表示順テーブルの作成(社員順)
				util.sortList(listEmployee, new CompKCode());		// 社員コードでソート
			}else if(confVo.idButtonJyouken.equals(InsuranceConfSetVo.PRM_CKR_JYUNJYO_BUSHO)){	// ラジオボタン「所属順」選択
				util.sortList(listEmployee, new CompSCode());		// 所属順でソート
			}else if(confVo.idButtonJyouken.equals(InsuranceConfSetVo.PRM_CKR_JYUNJYO_KENPO)){	// ラジオボタン「健保順」選択
				util.sortList(listEmployee, new CompKenCode());		// 健保順でソート
			}else if(confVo.idButtonJyouken.equals(InsuranceConfSetVo.PRM_CKR_JYUNJYO_KOUNEN)){	// ラジオボタン「厚年順」選択
				util.sortList(listEmployee, new CompKonCode());		// 厚年順でソート
			}
			confVo.listEmployee	=	listEmployee;
			if(confVo.listEmployee.size() <= 0 ){
				String errMessage = MospUtility.getMessage(msg, PayrollConst.MSG_NO_SANTEI_KCODE, "");
				addErrMessage(errMessage);
				throw new MospException(PayrollConst.EX_NO_HUMAN_DATA, errMessage);
			}else{
				vo.kCodeIndx	= 0;
				vo.setParams(request);	// 算定・月変条件設定画面の引継ぎパラメータの設定
				show(vo, confVo, 0);	// 表示
			}
		} else if (cmd.equals(CMD_INSURANCE_CARD_NEXT))   {	 // 次社員表示
			if( vo.kCodeIndx >= (confVo.listEmployee.size() - 1)){
				String errMessage = MospUtility.getMessage(msg, PayrollConst.MSG_NO_NEXT_KCODE, "");
				addErrMessage(errMessage);
				throw new MospException(PayrollConst.EX_NO_HUMAN_DATA, errMessage);
			}
			vo.kCodeIndx++;
			show(vo, confVo, vo.kCodeIndx);	// 表示
		} else if (cmd.equals(CMD_INSURANCE_CARD_BEFORE)) {	 // 前社員表示
			if( vo.kCodeIndx <= 0 ){
				vo.kCodeIndx = 0;
				String errMessage = MospUtility.getMessage(msg, PayrollConst.MSG_NO_BEFORE_KCODE, "");
				addErrMessage(errMessage);
				throw new MospException(PayrollConst.EX_NO_HUMAN_DATA, errMessage);
			}
			vo.kCodeIndx--;
			show(vo, confVo, vo.kCodeIndx);	// 表示

		} else if (cmd.equals(CMD_INSURANCE_CARD_REGIST)){	 	// 登録
			vo.setParams(request);	// 算定・月変条件設定画面の引継ぎパラメータの設定
			CdSocInsuranceDto socDto = vo.cdSocInsuranceDto;
			if(null == socDto){
				socDto = new CdSocInsuranceDto();
				vo.cdSocInsuranceDto = socDto;
			}
			setToSocInsuranceFromView(vo, socDto);
			if(2 == vo.dbTableFlg){ //DBのデータフラグが「2:既存データ」の場合
				cdSocInsuranceDao.update(socDto);
			}else{
				cdSocInsuranceDao.insert(socDto);
			}
			commit();
			// メッセージ設定
			setMessage(MospUtility.getMessage(msg, "IC0001", ""));
			// 画面表示処理
			show(vo, confVo, vo.kCodeIndx);	// 表示
		} else if (cmd.equals(CMD_INSURANCE_RECAL)){	 	// 再計算
			vo.setTargetMonth( nowDateTmp ); //画面表示用ヘッダー日付設定
			vo.setParams(request);	// 算定・月変条件設定画面の引継ぎパラメータの設定
			// 計算
			reCalc( vo );
		} else if (cmd.equals(CMD_INSURANCE_CARD_BACK)){		// 戻し			
		} else if (cmd.equals(CMD_INSURANCE_CARD_NEWKCODE)){	// 社員コード変更			
			int			tmpGetFlg	= 0;
			Employee	employee	= null;
			vo.setTargetMonth( nowDateTmp ); //画面表示用ヘッダー日付設定
			vo.setParams(request);	// 算定・月変条件設定画面の引継ぎパラメータの設定
			String ChgKcode = vo.getTxtChangeKCode();
			for(int i=0; i< confVo.listEmployee.size(); i++){
				employee = confVo.listEmployee.get(i);
				if((null != employee) && (employee.getKCode().equals(ChgKcode))){
					tmpGetFlg = 1;
					vo.kCodeIndx = i;
					break;
				}
			}
			if(tmpGetFlg == 0){
				String errMessage = MospUtility.getMessage(msg, PayrollConst.MSG_NO_SELECT_KCODE, "");
				addErrMessage(errMessage);
				throw new MospException(PayrollConst.EX_NO_HUMAN_DATA, errMessage);
			}else{
				show(vo, confVo, vo.kCodeIndx);	// 表示
			}
		} else {
			throw new MospException(MospConst.EX_CMD_INVALID);
		}
	}
	
	/**
	 * 算定処理画面表示
	 * @param vo   設定対象VO
	 * @param indx 表示対象の社員テーブルイインデックス（先頭社員インデックス：０）
	 * @throws Exception 
	 */
	private void show( InsuranceMonthlyCardVo vo, InsuranceConfSetVo	confVo, int indx ) throws Exception {
		int		intCalcDate;
		Date targetMonth;
		Employee employee	=	null;
		if(confVo.listEmployee.size() < indx ){
			String errMessage = MospUtility.getMessage(msg, PayrollConst.MSG_NO_SANTEI_KCODE, "");
			addErrMessage(errMessage);
			throw new MospException(PayrollConst.EX_NO_HUMAN_DATA, errMessage);
		}

		//昇(降)給開始月（年月）の3ヵ月後の月設定
		if((confVo.prmSyoukyuTuki == null) || (confVo.prmSyoukyuTuki.equals("0"))){
			intCalcDate = (nowYear * 10000) + ((PayrollConst.MONTH_SYOUKYU_DEFAULT + 3 ) * 100) + PayrollConst.TIME_DEFAULT_DAY;
		}else{
			intCalcDate = (nowYear * 10000) + ((Integer.valueOf(confVo.prmSyoukyuTuki ) + 3) * 100 ) + PayrollConst.TIME_DEFAULT_DAY;
		}
		targetMonth	=DatePart.convIntegerDateToDate(intCalcDate);
		
		
		employee = confVo.listEmployee.get(indx);
		
		cdSocInsuranceDto = null;
		vo.dbTableFlg = 1; //DBのデータフラグに「1:新規データ」を設定する				
		if(null != employee){
			mKihonDto = mKihonPayrollDao.findForKey(employee.getKCode());
			cdSocInsuranceDto =  cdSocInsuranceDao.findForKey(employee.getKCode(), tekiyouDate);		
			if(null == cdSocInsuranceDto){
				cdSocInsuranceDto = new CdSocInsuranceDto();
				cdSocInsuranceDto.setCalcResult(0);
				cdSocInsuranceDto.setExpectedDate(tekiyouDate);
				cdSocInsuranceDto.setRaiseDownSalaryDate(startDate);
				cdSocInsuranceDto.setCalcResult(0);
				calcPayBasicDate( employee.getKCode(), targetMonth);	//cdSocInsuranceDtoのNEWと前3ヶ月の報酬金額設定
				getStandardPayment( employee.getKCode(), targetMonth);	// 標準報酬月額取得
				setSocInsuranceDto( employee, confVo, cdSocInsuranceDto );
			}else{
				vo.dbTableFlg = 2; //DBのデータフラグに「2:既存データ」を設定
			}
			vo.setFields( employee, cdSocInsuranceDto );
		}
	}

	/**
	 * 名称取得用配列取得
	 * @param vo 設定対象VO
	 * @throws IllegalAccessException 
	 * @throws NoSuchFieldException 
	 * @throws SQLException 
	 * @throws ClassNotFoundException 
	 */
	private void setNameArray(
			InsuranceMonthlyCardVo vo
	) throws SQLException, NoSuchFieldException, IllegalAccessException, ClassNotFoundException {
		// DBコネクション取得
		getConnection();
		// 取得済確認
		if (vo.aryStation != null) {
			return;
		}
		// 配列取得
		vo.aryStation  = getStationArrayAll() ;
		vo.aryPosition = getPositionArrayAll();
		vo.aryEra      = getCodeArray(PayrollConst.TID_JAPANESE);
		vo.aryRelation = getCodeArray(PayrollConst.TID_RELATION);
		// 和暦設定取得
		vo.listConf = getConfList(PayrollConst.CONF_ID_JP_IMP_CAL);
	}

	/**
	 * 社会保険計算データVOの設定
	 * @param employee 人事基本データ集合Dao
	 * @param calcDate	算定・月変更での徴収月計算日
	 * @param confVo 設定条件VO
	 * @param socDto 社会保険データVOインスタンス
	 */
	private void setSocInsuranceDto(Employee employee, InsuranceConfSetVo confVo, CdSocInsuranceDto socDto ){
		if(null == employee){
			return;
		}
		socDto.setKCode					(employee.getKCode()					);	// 社員コード
		socDto.setKName					(employee.getKName()					);	// 社員氏名
		socDto.setSCode					(employee.getSectionCode()				);	// 所属コード
		socDto.setCalcDate				(tekiyouDate							);	// 計算年月
		socDto.setRaiseDownSalaryDate	(startDate					 			);	// 昇降給年月
		socDto.setExpectedDate			(tekiyouDate							);	// 適用年月
	}


	/**
	 * 画面から社会保険計算データVOの設定
	 * @param confVo 設定条件VO
	 * @param socDto 社会保険データVOインスタンス
	 */
	private void setToSocInsuranceFromView(InsuranceMonthlyCardVo vo, CdSocInsuranceDto socDto ){
		socDto.setKCode(vo.getEscLblKCode());													// 社員コード
		socDto.setKName(vo.getEscLblKName());													// 社員氏名
		socDto.setSCode(vo.getEscLblStationCode());												// 所属コード
		socDto.setCalcDate(tekiyouDate);														// 計算年月

		if(!vo.getEscTxtPayBasicMonth1      ().equals("")) socDto.setPayBasicMonth1(Integer.valueOf      (vo.getEscTxtPayBasicMonth1()      ));		// 支払基礎日数1(月)
		if(!vo.getEscTxtPayBasicMonth2      ().equals("")) socDto.setPayBasicMonth2(Integer.valueOf      (vo.getEscTxtPayBasicMonth2()      ));		// 支払基礎日数2(月)
		if(!vo.getEscTxtPayBasicMonth3      ().equals("")) socDto.setPayBasicMonth3(Integer.valueOf      (vo.getEscTxtPayBasicMonth3()      ));		// 支払基礎日数3(月)
		if(!vo.getEscTxtPayBasicDay1        ().equals("")) socDto.setPayBasicDay1(Integer.valueOf        (vo.getEscTxtPayBasicDay1()        ));		// 支払基礎日数1(日)
		if(!vo.getEscTxtPayBasicDay2        ().equals("")) socDto.setPayBasicDay2(Integer.valueOf        (vo.getEscTxtPayBasicDay2()        ));		// 支払基礎日数2(日)
		if(!vo.getEscTxtPayBasicDay3        ().equals("")) socDto.setPayBasicDay3(Integer.valueOf        (vo.getEscTxtPayBasicDay3()        ));		// 支払基礎日数3(日)
		if(!vo.getEscTxtPayAmount1          ().equals("")) socDto.setPayAmount1(Integer.valueOf          (vo.getEscTxtPayAmount1()          ));		// 金銭の額1
		if(!vo.getEscTxtPayAmount2          ().equals("")) socDto.setPayAmount2(Integer.valueOf          (vo.getEscTxtPayAmount2()          ));		// 金銭の額2
		if(!vo.getEscTxtPayAmount3          ().equals("")) socDto.setPayAmount3(Integer.valueOf          (vo.getEscTxtPayAmount3()          ));		// 金銭の額3
		if(!vo.getEscTxtGoodsAmount1        ().equals("")) socDto.setGoodsAmount1(Integer.valueOf        (vo.getEscTxtGoodsAmount1()        ));		// 現物の額1
		if(!vo.getEscTxtGoodsAmount2        ().equals("")) socDto.setGoodsAmount2(Integer.valueOf        (vo.getEscTxtGoodsAmount2()        ));		// 現物の額2
		if(!vo.getEscTxtGoodsAmount3        ().equals("")) socDto.setGoodsAmount3(Integer.valueOf        (vo.getEscTxtGoodsAmount3()        ));		// 現物の額3
		if(!vo.getEscTxtRewardTotal1        ().equals("")) socDto.setRewardTotal1(Integer.valueOf        (vo.getEscTxtRewardTotal1()        ));		// 報酬合計1
		if(!vo.getEscTxtRewardTotal2        ().equals("")) socDto.setRewardTotal2(Integer.valueOf        (vo.getEscTxtRewardTotal2()        ));		// 報酬合計2
		if(!vo.getEscTxtRewardTotal3        ().equals("")) socDto.setRewardTotal3(Integer.valueOf        (vo.getEscTxtRewardTotal3()        ));		// 報酬合計3
		if(!vo.getEscTxtRewardTotalSum      ().equals("")) socDto.setRewardTotalSum(Integer.valueOf      (vo.getEscTxtRewardTotalSum()      ));		// 報酬総額
		if(!vo.getEscTxtAverageThreeMonths  ().equals("")) socDto.setAverageThreeMonths(Integer.valueOf  (vo.getEscTxtAverageThreeMonths()  ));		// ３ヶ月平均
		if(!vo.getEscTxtEditAverage         ().equals("")) socDto.setEditAverage(Integer.valueOf         (vo.getEscTxtEditAverage ()        ));		// 修正平均
		if(!vo.getEscTxtRaiseDownSalaryBasis().equals("")) socDto.setRaiseDownSalaryBasis(Integer.valueOf(vo.getEscTxtRaiseDownSalaryBasis()));		// 昇降給差の月額
		
		socDto.setRaiseDownSalaryDate(startDate);												// 昇降給年月
		socDto.setExpectedDate(tekiyouDate);													// 適用年月
		if(vo.confVo.idButtonSyori.equals(InsuranceConfSetVo.PRM_CKR_SANTEI_KISO)){ //算定基礎指定の場合
			socDto.setCalcResult(1);												 //計算結果に算定適応待：１設定
		}else{																		 //算定基礎以外指定の場合
			socDto.setCalcResult(3);												 //計算結果に月変適応待：３設定
		}
	}

	/**
	 * 画面データによる社会保険データの再計算
	 * @param vo 画面VO
	 */
	private void reCalc(InsuranceMonthlyCardVo vo){
		int intCntManth             = 0; // 計算可能月数
		int intPayBasicDay1         = 0; // 1ヶ月前基礎日数
		int intPayBasicDay2         = 0; // 2ヶ月前基礎日数
		int intPayBasicDay3         = 0; // 3ヶ月前基礎日数
		int intPayAmount1           = 0; // 1ヶ月前報酬額
		int intPayAmount2           = 0; // 2ヶ月前報酬額
		int intPayAmount3           = 0; // 3ヶ月前報酬額
		int intGoodsAmount1         = 0; // 1ヶ月前現物支給額
		int intGoodsAmount2         = 0; // 2ヶ月前現物支給額
		int intGoodsAmount3         = 0; // 3ヶ月前現物支給額
		int intRewardTotal1         = 0; // 1ヶ月前合計額
		int intRewardTotal2         = 0; // 2ヶ月前合計額
		int intRewardTotal3         = 0; // 3ヶ月前合計額
		int intRewardTotalSum       = 0; // 総報酬額
		int intAverageThreeMonths   = 0; // 3ヶ月間平均額
		int intEditAverage          = 0; // 修正平均額
		int intHealthDecGrade       = 0; // 後健康保険等級
		int intHealthDecPremium     = 0; // 後健康保険
		int intPensionDecGrade      = 0; // 後厚生年金等級
		int intPensionDecPremium    = 0; // 後厚生年金報酬額
		int intRaiseDownSalaryBasis = 0; // 昇降給差の月額
		int intRetroactivePayment   = 0; // 遡及支払額

		if(!vo.getEscTxtPayBasicDay1        ().equals("")) intPayBasicDay1            = Integer.valueOf( vo.getEscTxtPayBasicDay1      ()  ); // 1ヶ月前基礎日数
		if(!vo.getEscTxtPayBasicDay2        ().equals("")) intPayBasicDay2            = Integer.valueOf( vo.getEscTxtPayBasicDay2      ()  ); // 2ヶ月前基礎日数
		if(!vo.getEscTxtPayBasicDay3        ().equals("")) intPayBasicDay3            = Integer.valueOf( vo.getEscTxtPayBasicDay3      ()  ); // 3ヶ月前基礎日数
		if(!vo.getEscTxtPayAmount1          ().equals("")) intPayAmount1              = Integer.valueOf( vo.getEscTxtPayAmount1        ()  ); // 1ヶ月前報酬額
		if(!vo.getEscTxtPayAmount2          ().equals("")) intPayAmount2              = Integer.valueOf( vo.getEscTxtPayAmount2        ()  ); // 2ヶ月前報酬額
		if(!vo.getEscTxtPayAmount3          ().equals("")) intPayAmount3              = Integer.valueOf( vo.getEscTxtPayAmount3        ()  ); // 3ヶ月前報酬額
		if(!vo.getEscTxtGoodsAmount1        ().equals("")) intGoodsAmount1            = Integer.valueOf( vo.getEscTxtGoodsAmount1      ()  ); // 1ヶ月前現物支給額
		if(!vo.getEscTxtGoodsAmount2        ().equals("")) intGoodsAmount2            = Integer.valueOf( vo.getEscTxtGoodsAmount2      ()  ); // 2ヶ月前現物支給額
		if(!vo.getEscTxtGoodsAmount3        ().equals("")) intGoodsAmount3            = Integer.valueOf( vo.getEscTxtGoodsAmount3      ()  ); // 3ヶ月前現物支給額
		if(!vo.getEscTxtRaiseDownSalaryBasis().equals("")) intRaiseDownSalaryBasis    = Integer.valueOf( vo.getEscTxtRaiseDownSalaryBasis()); // 昇降給差の月額;
		if(!vo.getEscTxtRetroactivePayment  ().equals("")) intRetroactivePayment      = Integer.valueOf( vo.getEscTxtRetroactivePayment()  ); // 遡及支払額
		
		//		 1ヶ月前
		if(intPayBasicDay1 >= 17){
			intRewardTotal1 = intPayAmount1 + intGoodsAmount1;
			intRewardTotalSum = intRewardTotalSum + intRewardTotal1;
			intCntManth++;
		}

		// 2ヶ月前
		if(intPayBasicDay2 >= 17){
			intRewardTotal2 = intPayAmount2 + intGoodsAmount2;
			intRewardTotalSum = intRewardTotalSum + intRewardTotal2;
			intCntManth++;
		}

		// 3ヶ月前
		if(intPayBasicDay3 >= 17){
			intRewardTotal3 = intPayAmount3 + intGoodsAmount3;
			intRewardTotalSum = intRewardTotalSum + intRewardTotal3;
			intCntManth++;
		}

		// 平均
		if((0 < intRewardTotalSum) && (0 < intCntManth)){
			intAverageThreeMonths = intRewardTotalSum / intCntManth;
		}

		// 遡及支払額及び昇降給差額修正平均金額
		if((0 < intCntManth) && (0 < intRewardTotalSum) && ((0 < intRetroactivePayment) || (0 < intRaiseDownSalaryBasis ))){
			if(intRewardTotalSum >= intRetroactivePayment){
				intEditAverage = ((intRewardTotalSum - intRetroactivePayment) + (intRaiseDownSalaryBasis * 2 )) / intCntManth;
			}
		}

		if( intEditAverage > 0 ){
			intHealthDecGrade    = getHealthDecGrade   (intEditAverage );
			intPensionDecGrade   = getPensionDecGrade  (intEditAverage );
			intHealthDecPremium  = getHealthDecPremium (intEditAverage );
			intPensionDecPremium = getPensionDecPremium(intEditAverage );
		}else{
			intHealthDecGrade    = getHealthDecGrade   (intAverageThreeMonths );
			intPensionDecGrade   = getPensionDecGrade  (intAverageThreeMonths );
			intHealthDecPremium  = getHealthDecPremium (intAverageThreeMonths );
			intPensionDecPremium = getPensionDecPremium(intAverageThreeMonths );
		}

		vo.setTxtRewardTotal1        ( String.valueOf( intRewardTotal1         ));
		vo.setTxtRewardTotal2        ( String.valueOf( intRewardTotal2         ));
		vo.setTxtRewardTotal3        ( String.valueOf( intRewardTotal3         ));
		vo.setTxtRewardTotalSum      ( String.valueOf( intRewardTotalSum       ));
		vo.setTxtAverageThreeMonths  ( String.valueOf( intAverageThreeMonths   ));
		vo.setTxtEditAverage         ( String.valueOf( intEditAverage          ));
		vo.setTxtHealthDecGrade      ( String.valueOf( intHealthDecGrade       ));
		vo.setTxtHealthDecPremium    ( String.valueOf( intHealthDecPremium     ));
		vo.setTxtPensionDecGrade     ( String.valueOf( intPensionDecGrade      ));
		vo.setTxtPensionDecPremium   ( String.valueOf( intPensionDecPremium    ));
		vo.setTxtRaiseDownSalaryBasis( String.valueOf( intRaiseDownSalaryBasis ));
		vo.setTxtRetroactivePayment  ( String.valueOf( intRetroactivePayment   ));
	}
	
	
	/**
	 * 社員コードによる比較クラス
	 */
	protected static class CompKCode implements Comparator<Object>, Serializable {
		private static final long serialVersionUID = -7706459710514164329L;
		public int compare(Object obj1, Object obj2) {
			Employee dto1 = (Employee)obj1;
			Employee dto2 = (Employee)obj2;
			return dto1.getKCode().compareTo(dto2.getKCode());
		}
	}

	/**
	 * 所属コードによる比較クラス
	 */
	protected static class CompSCode implements Comparator<Object>, Serializable {
		private static final long serialVersionUID = 3372034311242969584L;
		public int compare(Object obj1, Object obj2) {
			Employee dto1 = (Employee)obj1;
			Employee dto2 = (Employee)obj2;
			return dto1.getSectionCode().compareTo(dto2.getSectionCode());
		}
	}

	/**
	 * 健保番号による比較クラス
	 */
	protected static class CompKenCode implements Comparator<Object>, Serializable {
		private static final long serialVersionUID = -7057285913026987313L;
		public int compare(Object obj1, Object obj2) {
			Employee dto1 = (Employee)obj1;
			Employee dto2 = (Employee)obj2;
			return dto1.getKenpoNo().compareTo(dto2.getKenpoNo());
		}
	}

	/**
	 * 厚年番号による比較クラス
	 */
	protected static class CompKonCode implements Comparator<Object>, Serializable {
		private static final long serialVersionUID = 5471303087653114594L;
		public int compare(Object obj1, Object obj2) {
			Employee dto1 = (Employee)obj1;
			Employee dto2 = (Employee)obj2;
			return dto1.getKohoNo().compareTo(dto2.getKohoNo());
		}
	}

	
	
}
