package jp.mosp.payroll.common.vo;

import java.util.Iterator;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import jp.mosp.common.dto.MosPConfDto;
import jp.mosp.payroll.base.PayrollConst;
import jp.mosp.payroll.dto.CdAdjustmentDto;

public class AdjustmentListVo extends AdjustmentCardVo {
	
	private static final long	serialVersionUID		= 4435830626039652278L;
	
	// URL、CSS
	private static final String	RETURN_URL				= "/jsp/payroll/common/adjustmentList.jsp";
	private static final String	EXTRA_JS				= "/pub/payroll/common/js/adjustmentList.js";
	private static final String	EXTRA_CSS				= "/pub/payroll/common/css/adjustmentList.css";
	
	// 画面サブタイトル
	public final String			SUB_TITLE				= PayrollConst.TTL_ADJUSTMENT_LIST;
	
	// パラメータ名
	public static final String	PRM_TXT_K_CODE			= "txtKCode";
	public static final String	PRM_TXT_K_NAME			= "txtKName";
	public static final String	PRM_TXT_K_KANA			= "txtKKana";
	public static final String	PRM_PLT_ADJUST_YEAR		= "pltAdjustYear";
	public static final String	PRM_PLT_ADJUST_STATUS	= "pltAdjustStatus";
	public static final String	PRM_TXT_INC_TAX_FROM	= "txtIncTaxFrom";
	public static final String	PRM_TXT_INC_TAX_TO		= "txtIncTaxTo";
	public static final String	PRM_PLT_REPORT_YEAR		= "pltReportYear";
	
	// フィールド名及び制限
	public static final String	NAM_K_CODE				= PayrollConst.NAM_M_KIHON_KCODE;
	public static final String	NAM_K_KANA				= PayrollConst.NAM_K_KANA;
	public static final String	NAM_ADJUST_YEAR			= PayrollConst.NAM_ADJUST_YEAR;
	public static final String	NAM_FINAL_INCOME_TAX	= PayrollConst.NAM_FINAL_INCOME_TAX;
	public static final int		LEN_K_CODE				= PayrollConst.LEN_K_CODE;
	public static final int		LEN_K_NAME				= PayrollConst.LEN_K_NAME;
	public static final int		LEN_MONEY_AMOUNT		= PayrollConst.LEN_MONEY_AMOUNT;
	
	// フィールド
	private String[]			aryKCode;
	private String[]			aryAdjustYear;
	private String[]			aryAdjustStatus;
	private String[]			aryTaxGap;
	private String[]			aryFinalIncomeTax;
	private String[]			aryIncomeDeductSum;
	private String[]			aryIncomeTaxSum;
	private String[]			aryTaxedPaymentSum;
	
	private String				txtKCode;
	private String				txtKName;
	private String				txtKKana;
	private int					pltAdjustYear;
	private String				pltAdjustStatus;
	private String				txtIncTaxFrom;
	private String				txtIncTaxTo;
	private int					pltReportYear;
	
	// プルダウンリスト
	public String[][]			aryPltAdjustYear;
	public String[][]			aryPltAdjustSatus;
	public String[][]			aryGender;
	// 設定テーブル
	public List<MosPConfDto>	listConf;
	
	// ソートキー
	public final String			KEY_K_CODE				= "keyKCode";
	public final String			KEY_ADJUST_YEAR			= "keyAdjustYear";
	public final String			KEY_ADJUST_STATUS		= "keyAdjustStatus";
	public final String			KEY_TAX_GAP				= "keyTaxGap";
	public final String			KEY_FINAL_INCOME_TAX	= "keyFinalIncomeTax";
	public final String			KEY_INCOME_DEDUCT_SUM	= "keyIncomeDeductSum";
	public final String			KEY_INCOME_TAX_SUM		= "keyIncomeTaxSum";
	public final String			KEY_TAXED_PAYMENT_SUM	= "keyTaxedPaymentSum";
	

	/**
	 * コンストラクタ
	 */
	public AdjustmentListVo() {
		super();
		setRetUrl(RETURN_URL);
		setExtraJs(EXTRA_JS);
		setExtraCss(EXTRA_CSS);
		txtKCode = "";
		txtKName = "";
		txtKKana = "";
		pltAdjustYear = 0;
		pltAdjustStatus = "";
		txtIncTaxFrom = "";
		txtIncTaxTo = "";
		pltReportYear = 0;
		aryKCode = new String[0];
		aryAdjustYear = new String[0];
		aryAdjustStatus = new String[0];
		aryTaxGap = new String[0];
		aryFinalIncomeTax = new String[0];
		aryIncomeDeductSum = new String[0];
		aryIncomeTaxSum = new String[0];
		aryTaxedPaymentSum = new String[0];
		setFormerKey(KEY_K_CODE);
	}
	
	/**
	 * パラメータ設定
	 * @param request リクエスト
	 */
	@Override
	public void setParams(HttpServletRequest request) {
		txtKCode = request.getParameter(PRM_TXT_K_CODE);
		txtKName = request.getParameter(PRM_TXT_K_NAME);
		txtKKana = request.getParameter(PRM_TXT_K_KANA);
		pltAdjustYear = getIntParam(request.getParameter(PRM_PLT_ADJUST_YEAR));
		pltAdjustStatus = request.getParameter(PRM_PLT_ADJUST_STATUS);
		txtIncTaxFrom = request.getParameter(PRM_TXT_INC_TAX_FROM);
		txtIncTaxTo = request.getParameter(PRM_TXT_INC_TAX_TO);
		pltReportYear = getIntParam(request.getParameter(PRM_PLT_REPORT_YEAR));
	}
	
	/**
	 * フィールド設定
	 * @param list 社員リスト
	 */
	@Override
	public void setFields(List list) {
		// リストの設定
		this.list = list;
		// データ総数の取得
		count = list.size();
		// 配列の初期化
		aryKCode = new String[count];
		aryAdjustYear = new String[count];
		aryAdjustStatus = new String[count];
		aryTaxGap = new String[count];
		aryFinalIncomeTax = new String[count];
		aryIncomeDeductSum = new String[count];
		aryIncomeTaxSum = new String[count];
		aryTaxedPaymentSum = new String[count];
		// データの設定
		int i = 0;
		Iterator it = list.iterator();
		while (it.hasNext()) {
			CdAdjustmentDto dto = (CdAdjustmentDto)it.next();
			aryKCode[i] = escapeHTML(dto.getKCode());
			aryAdjustYear[i] = String.valueOf(dto.getAdjustYear());
			aryAdjustStatus[i] = escapeHTML(getCodeName(dto.getAdjustStatus(), aryPltAdjustSatus));
			aryTaxGap[i] = insertComma(String.valueOf(dto.getTaxGap()));
			aryFinalIncomeTax[i] = insertComma(String.valueOf(dto.getFinalIncomeTax()));
			aryIncomeDeductSum[i] = insertComma(String.valueOf(dto.getIncomeDeductSum()));
			aryIncomeTaxSum[i] = insertComma(String.valueOf(dto.getIncomeTaxSum()));
			aryTaxedPaymentSum[i] = insertComma(String.valueOf(dto.getTaxedPaymentSum()));
			i++;
		}
	}
	
	/**
	 * JavaScript設定
	 * @param cls 情報取得クラス
	 * @throws IllegalAccessException
	 */
	@Override
	public String getDirectJs(Class cls) throws IllegalAccessException {
		StringBuffer sb = new StringBuffer();
		sb.append(super.getDirectJs(cls));
		return sb.toString();
	}
	
	// アクセサメソッド
	public String[] getEscAryKCode() {
		return aryKCode.clone();
	}
	
	public String[] getEscAryAdjustYear() {
		return aryAdjustYear.clone();
	}
	
	public String[] getEscAryAdjustStatus() {
		return aryAdjustStatus.clone();
	}
	
	public String[] getEscAryTaxGap() {
		return aryTaxGap.clone();
	}
	
	public String[] getEscAryFinalIncomeTax() {
		return aryFinalIncomeTax.clone();
	}
	
	public String[] getEscAryIncomeDeductSum() {
		return aryIncomeDeductSum.clone();
	}
	
	public String[] getEscAryIncomeTaxSum() {
		return aryIncomeTaxSum.clone();
	}
	
	public String[] getEscAryTaxedPaymentSum() {
		return aryTaxedPaymentSum.clone();
	}
	
	public String getTxtKCode() {
		return txtKCode;
	}
	
	public String getTxtKName() {
		return txtKName;
	}
	
	public String getTxtKKana() {
		return txtKKana;
	}
	
	public int getPltAdjustYear() {
		return pltAdjustYear;
	}
	
	public String getPltAdjustStatus() {
		return pltAdjustStatus;
	}
	
	public String getTxtIncTaxFrom() {
		return txtIncTaxFrom;
	}
	
	public String getTxtIncTaxTo() {
		return txtIncTaxTo;
	}
	
	public int getPltReportYear() {
		return pltReportYear;
	}
	
	public String getEscTxtKCode() {
		return escapeHTML(txtKCode);
	}
	
	public String getEscTxtKName() {
		return escapeHTML(txtKName);
	}
	
	public String getEscTxtKKana() {
		return escapeHTML(txtKKana);
	}
	
	public String getEscTxtIncTaxFrom() {
		return escapeHTML(txtIncTaxFrom);
	}
	
	public String getEscTxtIncTaxTo() {
		return escapeHTML(txtIncTaxTo);
	}
	
	public String getStrAdjustYear() {
		return String.valueOf(pltAdjustYear);
	}
	
	public String getStrReportYear() {
		return String.valueOf(pltReportYear);
	}
	
	public void setPltAdjustYear(int pltAdjustYear) {
		this.pltAdjustYear = pltAdjustYear;
	}
	
	public void setPltAdjustStatus(String pltAdjustStatus) {
		this.pltAdjustStatus = pltAdjustStatus;
	}
	
	public void setPltReportYear(int pltReportYear) {
		this.pltReportYear = pltReportYear;
	}
	
}
