/*
 * MosP - Mind Open Source Project    http://www.mosp.jp/
 * Copyright (C) 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.kintai.report.action;

import java.io.File;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import jp.mosp.common.CommonConst;
import jp.mosp.common.common.BaseVo;
import jp.mosp.common.common.MospConst;
import jp.mosp.common.common.MospUtility;
import jp.mosp.common.common.PoiUtility;
import jp.mosp.common.utils.DateUtil;
import jp.mosp.common.utils.StringUtil;
import jp.mosp.common.utils.TimeUtil;
import jp.mosp.kintai.common.action.KintaiCommonAction;
import jp.mosp.kintai.report.dao.AttendanceManagementDao;
import jp.mosp.kintai.report.dto.AttendanceManagementDto;
import jp.mosp.payroll.vo.AttendanceExportCardVo;

import org.jopendocument.dom.spreadsheet.Sheet;
import org.jopendocument.dom.spreadsheet.SpreadSheet;

/**
 * @author yoshida
 *
 */
public class AttendanceManagementAction extends KintaiCommonAction {
	
	private int								row					= 0;	//Row(行) 0〜
	private int								pageno				= 0;	//ページ数
	private static final int				END_PAGE_L			= 50;	//1ページの最終行数
	private int								gyol				= 2;	//明細の改行数
	private int								titlel				= 3;	//1ページのタイトル印刷位置
	private int								firstl				= 8;	//1ページの明細開始位置
	private int								endl;						//最終位置getLastRow()で取得
	private static final int				LAST_L				= 46;	//1ページの明細最終行(合計行は含まない)
	private static final int				TOTAL_L				= 48;	//1ページの合計印刷行	
	private String							file1				= "";
	private int								printcnt			= 0;
	
	// エクセル・セル番号
	private static final int[]				CC					= { 12, 19, 26, 33, 40, 47, 54, 61, 68, 75, 82, 89, 96,
		103, 110												};
	
	private String							simei				= "";
	
	private double							snissu				= 0;
	private int								kinmuji				= 0;
	private int								kyukeiji			= 0;
	private double							yukyu				= 0;
	private double							tokukyu				= 0;
	private double							kekkin				= 0;
	private double							skekkin				= 0;
	private int								tisokai				= 0;
	private int								tijikan				= 0;
	private int								zajikan				= 0;
	private int								ksjikan				= 0;
	private int								snjikan				= 0;
	private int								kaikin				= 0;
	private int								syokujikaisu		= 0;
	private int								cyokukaisu1			= 0;
	private int								cyokukaisu2			= 0;
	private int								cyokukaisu3			= 0;
	private int								hokakaisu1			= 0;
	private int								hokakaisu2			= 0;
	private int								hokakaisu3			= 0;
	private int								hokakaisu4			= 0;
	private int								hokakaisu5			= 0;
	
	private double							totalSNissu			= 0;
	private int								totalKinmuJi		= 0;
	private int								totalKyukeiJi		= 0;
	private double							totalYukyu			= 0;
	private double							totalTokukyu		= 0;
	private double							totalKekkin			= 0;
	private double							totalSKekkin		= 0;
	private int								totalTisoKai		= 0;
	private int								totalTiJikan		= 0;
	private int								totalZaJikan		= 0;
	private int								totalKsJikan		= 0;
	private int								totalSnJikan		= 0;
	private int								totalKaikin			= 0;
	private int								totalSyokujiKaisu	= 0;
	private int								totalCyokuKaisu1	= 0;
	private int								totalCyokuKaisu2	= 0;
	private int								totalCyokuKaisu3	= 0;
	private int								totalHokaKaisu1		= 0;
	private int								totalHokaKaisu2		= 0;
	private int								totalHokaKaisu3		= 0;
	private int								totalHokaKaisu4		= 0;
	private int								totalHokaKaisu5		= 0;
	
	private String							sectionName			= "";
	private String							targetYear			= "";
	private String							targetMonth			= "";
	
	private List<AttendanceManagementDto>	managementList;
	
	private static final int				CELL_K_NAME			= 1;
	private static final int				CELL_YEAR			= 6;
	private static final int				CELL_MONTH			= 12;
	private static final int				CELL_SECTION		= 93;
	
	// OpenDocument用
	private static final int				PAGE_END_ROW		= 50;	// 1ページの終了位置
	private static final int				TITLE_ROW			= 3;	// タイトル開始位置
	private static final int				DETAIL_ROW			= 7;	// 1ページの明細開始位置
	private static final int				TOTAL_ROW			= 47;	// 1ページの合計開始位置
	private static final int				LEN_EMPLOYEE		= 20;	// 1ページの最大人数
																		
	
	/**
	 * コンストラクタ
	 */
	public AttendanceManagementAction() {
		super();
		setNeedProcSeq(false);
		final int endline = 50;
		endl = endline; //最終位置getLastRow()で取得
	}
	
	/**
	 * アクション
	 */
	public void action() throws Exception {
		getConnection();
		// VOの取得
		AttendanceExportCardVo vo = (AttendanceExportCardVo)prepareVo();
		// パラメータ取得
		vo.setParams(request);
		Date targetYearMonth = DateUtil.getYearMonth(vo.getPltYear(), vo.getPltMonth());
		// 所属名設定
		if (vo.getPltSection().equals(CommonConst.NAM_COMMON_STRING_INITIAL_VALUE)) {
			sectionName = CommonConst.NAM_ALL_SECTION;
		} else {
			sectionName = getSectionName(vo.getPltSection());
		}
		// 年月
		targetYear = String.valueOf(MospUtility.getYear(targetYearMonth));
		targetMonth = String.valueOf(MospUtility.getMonth(targetYearMonth));
		// 検索
		AttendanceManagementDao dao = new AttendanceManagementDao();
		dao.initDao(cfg, cmd, aspUser, user, conn);
		managementList = dao.findForCondition(DateUtil.convDateToStringYearMonthShort(targetYearMonth), vo
			.getPltSection());
		// 帳票設定
		StringBuffer fileName = new StringBuffer();
		fileName.append(DateUtil.convDateToStringYearMonth(targetYearMonth));
		fileName.append(CommonConst.FILE_NAME_SEPARATOR);
		fileName.append(vo.getPltSection());
		fileName.append(CommonConst.FILE_NAME_SEPARATOR);
		// 帳票作成
		if (StringUtil.isNotNull(cfg.getProperty(CommonConst.PPT_KINTAI_USE_ODF))) {
			// ODS
			request.setAttribute(MospConst.ATT_FILE_OBJECT, makeSpreadSheet());
			// ファイル名
			fileName.append(CommonConst.FILE_SAMP_M_KINTAIKANRI_ODS);
		} else {
			// XLS
			request.setAttribute(MospConst.ATT_FILE_OBJECT, makeWorkbook().getWorkbook());
			// ファイル名
			fileName.append(CommonConst.FILE_SAMP_M_KINTAIKANRI);
		}
		request.setAttribute(MospConst.ATT_FILE_NAME, fileName.toString());
	}
	
	@Override
	protected BaseVo getSpecificVo() {
		return new AttendanceExportCardVo();
	}
	
	/**
	 * 勤怠管理情報一覧作成
	 * @return PoiUtilityインスタンス
	 * @throws Exception    	例外処理が発生した場合
	 */
	private PoiUtility makeWorkbook() throws Exception {
		// 帳票作成準備
		PoiUtility poi = new PoiUtility();
		StringBuffer sb = new StringBuffer();
		sb.append(cfg.getProperty(MospConst.PPT_APP_DOCBASE));
		sb.append(CommonConst.TEMPLATE_M_KINTAIKANRI);
		poi.crtNewDocR(0, sb.toString());
		// ヘッダー情報設定
		printTitle(poi);
		// データ表示
		Iterator<AttendanceManagementDto> it = managementList.iterator();
		while (it.hasNext()) {
			AttendanceManagementDto dto = it.next();
			simei = dto.getSimei();
			snissu = Double.valueOf(dto.getSNissu());
			kinmuji = Integer.valueOf(dto.getKinmuJi());
			kyukeiji = Integer.valueOf(dto.getKyukeiJi());
			yukyu = Double.valueOf(dto.getYukyu());
			tokukyu = Double.valueOf(dto.getTokuKyu());
			kekkin = Double.valueOf(dto.getKekkin());
			skekkin = Double.valueOf(dto.getSKekkin());
			tisokai = Integer.valueOf(dto.getTiSoKai());
			tijikan = Integer.valueOf(dto.getTiJikan());
			zajikan = Integer.valueOf(dto.getZaJikan());
			ksjikan = Integer.valueOf(dto.getKsJikan());
			snjikan = Integer.valueOf(dto.getSnJikan());
			kaikin = Integer.valueOf(dto.getKaikin());
			syokujikaisu = Integer.valueOf(dto.getSyokujiKaisu());
			cyokukaisu1 = Integer.valueOf(dto.getCyokuKaisu1());
			cyokukaisu2 = Integer.valueOf(dto.getCyokuKaisu2());
			cyokukaisu3 = Integer.valueOf(dto.getCyokuKaisu3());
			hokakaisu1 = Integer.valueOf(dto.getHokaKaisu1());
			hokakaisu2 = Integer.valueOf(dto.getHokaKaisu2());
			hokakaisu3 = Integer.valueOf(dto.getHokaKaisu3());
			hokakaisu4 = Integer.valueOf(dto.getHokaKaisu4());
			hokakaisu5 = Integer.parseInt(dto.getHokaKaisu5());
			// 明細印刷
			printDetail(poi);
			// 合計
			addTotal();
		}
		if (printcnt > 0) {
			// 総合計印刷
			printTotal(poi);
			printEnding(poi);
		} else {
			// データ無し印刷
			printNothing(poi);
		}
		return poi;
	}
	
	/**
	 * タイトル印刷メソッド
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void printTitle(PoiUtility poi) throws Exception {
		// 改ページ
		pageno++;
		//タイトル印刷位置算出
		row = (pageno - 1) * END_PAGE_L + (titlel - 1);
		//タイトル,日付
		row++;
		// 年月日
		poi.prtItem(row, CELL_YEAR, targetYear);
		poi.prtItem(row, CELL_MONTH, targetMonth);
		// 所属
		poi.prtItem(row, CELL_SECTION, sectionName);
		// 明細印刷位置算出
		row = (pageno - 1) * END_PAGE_L + (firstl - 1 - gyol);
	}
	
	/**
	 * 明細印刷
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void printDetail(PoiUtility poi) throws Exception {
		// 改頁確認
		chkNewPage(poi);
		// 氏名
		poi.prtItem(row, CELL_K_NAME, simei);
		// 上段項目
		poi.prtItem(row, CC[0], String.valueOf(snissu));
		poi.prtItem(row, CC[1], getHourString(TimeUtil.convIntegerTimeToDoubleTime(kinmuji)));
		poi.prtItem(row, CC[2], getHourString(TimeUtil.convIntegerTimeToDoubleTime(zajikan)));
		poi.prtItem(row, CC[3], getHourString(TimeUtil.convIntegerTimeToDoubleTime(snjikan)));
		poi.prtItem(row, CC[4], getHourString(TimeUtil.convIntegerTimeToDoubleTime(tijikan)));
		poi.prtItem(row, CC[5], tisokai);
		poi.prtItem(row, CC[7], syokujikaisu);
		poi.prtItem(row, CC[8], cyokukaisu2);
		poi.prtItem(row, CC[9], hokakaisu1);
		poi.prtItem(row, CC[10], hokakaisu3);
		poi.prtItem(row, CC[11], hokakaisu5);
		poi.prtItem(row, CC[12], String.valueOf(yukyu));
		poi.prtItem(row, CC[13], String.valueOf(tokukyu));
		// 下段項目
		poi.prtItem(row + 1, CC[0], "");
		poi.prtItem(row + 1, CC[1], getHourString(TimeUtil.convIntegerTimeToDoubleTime(kyukeiji)));
		poi.prtItem(row + 1, CC[2], getHourString(TimeUtil.convIntegerTimeToDoubleTime(ksjikan)));
		poi.prtItem(row + 1, CC[7], cyokukaisu1);
		poi.prtItem(row + 1, CC[8], cyokukaisu3);
		poi.prtItem(row + 1, CC[9], hokakaisu2);
		poi.prtItem(row + 1, CC[10], hokakaisu4);
		poi.prtItem(row + 1, CC[11], kaikin);
		poi.prtItem(row + 1, CC[12], String.valueOf(kekkin));
		poi.prtItem(row + 1, CC[13], String.valueOf(skekkin));
		// 明細印刷件数
		printcnt++;
	}
	
	/**
	 * 合計印刷位置算出
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void printTotal(PoiUtility poi) throws Exception {
		row = (pageno - 1) * END_PAGE_L + (TOTAL_L - 1);
		// 支給項目
		poi.prtItem(row, CC[0], String.valueOf(totalSNissu));
		poi.prtItem(row, CC[1], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKinmuJi)));
		poi.prtItem(row, CC[2], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalZaJikan)));
		poi.prtItem(row, CC[3], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalSnJikan)));
		poi.prtItem(row, CC[4], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalTiJikan)));
		poi.prtItem(row, CC[5], totalTisoKai);
		poi.prtItem(row, CC[7], totalSyokujiKaisu);
		poi.prtItem(row, CC[8], totalCyokuKaisu2);
		poi.prtItem(row, CC[9], totalHokaKaisu1);
		poi.prtItem(row, CC[10], totalHokaKaisu3);
		poi.prtItem(row, CC[11], totalHokaKaisu5);
		poi.prtItem(row, CC[12], String.valueOf(totalYukyu));
		poi.prtItem(row, CC[13], String.valueOf(totalTokukyu));
		// 控除項目
		poi.prtItem(row + 1, CC[1], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKyukeiJi)));
		poi.prtItem(row + 1, CC[2], getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKsJikan)));
		poi.prtItem(row + 1, CC[7], totalCyokuKaisu1);
		poi.prtItem(row + 1, CC[8], totalCyokuKaisu3);
		poi.prtItem(row + 1, CC[9], totalHokaKaisu2);
		poi.prtItem(row + 1, CC[10], totalHokaKaisu4);
		poi.prtItem(row + 1, CC[11], totalKaikin);
		poi.prtItem(row + 1, CC[12], String.valueOf(totalKekkin));
		poi.prtItem(row + 1, CC[13], String.valueOf(totalSKekkin));
		// 明細印刷件数
		printcnt++;
	}
	
	/**
	 * 新しい頁作成メソッド
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void chkNewPage(PoiUtility poi) throws Exception {
		// オープン
		if (pageno == 0) {
			// Pageを再生成
			crtNewDoc(poi);
			// タイトル印刷
			printTitle(poi);
		}
		if (row >= ((pageno - 1) * END_PAGE_L + (LAST_L - gyol))) {
			// オーバーフロー又は最初の印刷の時、タイトル印刷
			printTitle(poi);
		}
		// 改行
		row += gyol;
	}
	
	/**
	 * 新しい頁作成メソッド
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void crtNewDoc(PoiUtility poi) throws Exception {
		poi.crtNewDocR(0, file1);
		// 最終行取得
		endl = poi.getLastRow();
	}
	
	/**
	 * データ無し印刷メソッド
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void printNothing(PoiUtility poi) throws Exception {
		// 改頁確認
		chkNewPage(poi);
		poi.prtItem(7, 1, CommonConst.MSG_ATTENDANCE_REPORT_NO_DATA);
	}
	
	/**
	 * 帳票終了
	 * @param poi PoiUtilityインスタンス
	 * @throws Exception   	例外処理が発生した場合
	 */
	private void printEnding(PoiUtility poi) throws Exception {
		// 印刷ｙ座標
		// 終了後の最初の行
		row = pageno * END_PAGE_L;
		boolean syori = true;
		// 残り行を削除する
		for (; row <= endl; row++) {
			if (syori) {
				poi.dltRow(row);
			}
		}
	}
	
	/**
	 * 勤怠管理情報一覧作成
	 * @return SpreadSheetインスタンス
	 * @throws Exception    	例外処理が発生した場合
	 */
	private SpreadSheet makeSpreadSheet() throws Exception {
		// テンプレートファイル
		StringBuffer sb = new StringBuffer();
		sb.append(cfg.getProperty(MospConst.PPT_APP_DOCBASE));
		sb.append(CommonConst.TEMPLATE_M_KINTAIKANRI_ODS);
		// 帳票作成
		SpreadSheet ss = SpreadSheet.createFromFile(new File(sb.toString()));
		// シート
		Sheet sheet = ss.getSheet(0);
		// 初期値
		pageno = 0;
		// タイトル
		printTitle(sheet);
		// データ表示
		Iterator<AttendanceManagementDto> it = managementList.iterator();
		int count = 0;
		while (it.hasNext()) {
			AttendanceManagementDto dto = it.next();
			// 氏名
			sheet.getCellAt(CELL_K_NAME, row).setValue(dto.getSimei());
			snissu = Double.valueOf(dto.getSNissu());
			kinmuji = Integer.valueOf(dto.getKinmuJi());
			kyukeiji = Integer.valueOf(dto.getKyukeiJi());
			yukyu = Double.valueOf(dto.getYukyu());
			tokukyu = Double.valueOf(dto.getTokuKyu());
			kekkin = Double.valueOf(dto.getKekkin());
			skekkin = Double.valueOf(dto.getSKekkin());
			tisokai = Integer.valueOf(dto.getTiSoKai());
			tijikan = Integer.valueOf(dto.getTiJikan());
			zajikan = Integer.valueOf(dto.getZaJikan());
			ksjikan = Integer.valueOf(dto.getKsJikan());
			snjikan = Integer.valueOf(dto.getSnJikan());
			kaikin = Integer.valueOf(dto.getKaikin());
			syokujikaisu = Integer.valueOf(dto.getSyokujiKaisu());
			cyokukaisu1 = Integer.valueOf(dto.getCyokuKaisu1());
			cyokukaisu2 = Integer.valueOf(dto.getCyokuKaisu2());
			cyokukaisu3 = Integer.valueOf(dto.getCyokuKaisu3());
			hokakaisu1 = Integer.valueOf(dto.getHokaKaisu1());
			hokakaisu2 = Integer.valueOf(dto.getHokaKaisu2());
			hokakaisu3 = Integer.valueOf(dto.getHokaKaisu3());
			hokakaisu4 = Integer.valueOf(dto.getHokaKaisu4());
			hokakaisu5 = Integer.parseInt(dto.getHokaKaisu5());
			// 詳細印刷
			printDetail(sheet);
			// 合計
			addTotal();
			// 次の人へ
			row += 2;
			count++;
			// 最後の一人
			if (!it.hasNext()) {
				// 合計行へ移動
				row = pageno * PAGE_END_ROW + TOTAL_ROW;
				// 合計印刷
				printTotal(sheet);
			}
			if (count == LEN_EMPLOYEE) {
				// 初期化
				count = 0;
				// 次ページへ遷移
				addPageNo(sheet);
			}
		}
		return ss;
	}
	
	/**
	 * タイトル印刷メソッド
	 * @param sheet SpreadSheetインスタンス
	 */
	private void printTitle(Sheet sheet) {
		row = pageno * PAGE_END_ROW + TITLE_ROW;
		// 年月
		sheet.getCellAt(CELL_YEAR, row).setValue(targetYear);
		sheet.getCellAt(CELL_MONTH, row).setValue(targetMonth);
		// 所属
		sheet.getCellAt(CELL_SECTION, row).setValue(sectionName);
		// 明細行へ移動
		row = pageno * PAGE_END_ROW + DETAIL_ROW;
	}
	
	/**
	 * 次ページへ移動
	 * @param sheet SpreadSheetインスタンス
	 */
	private void addPageNo(Sheet sheet) {
		// ページ加算
		pageno++;
		// ページの先頭行へ移動
		row = pageno * PAGE_END_ROW;
		// タイトル設定
		printTitle(sheet);
	}
	
	/**
	 * 詳細印刷
	 * @param sheet SpreadSheetインスタンス
	 */
	private void printDetail(Sheet sheet) {
		// 上段項目
		int upper = row;
		sheet.getCellAt(CC[0], upper).setValue(String.valueOf(snissu));
		sheet.getCellAt(CC[1], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(kinmuji)));
		sheet.getCellAt(CC[2], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(zajikan)));
		sheet.getCellAt(CC[3], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(snjikan)));
		sheet.getCellAt(CC[4], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(tijikan)));
		sheet.getCellAt(CC[5], upper).setValue(tisokai);
		sheet.getCellAt(CC[7], upper).setValue(syokujikaisu);
		sheet.getCellAt(CC[8], upper).setValue(cyokukaisu2);
		sheet.getCellAt(CC[9], upper).setValue(hokakaisu1);
		sheet.getCellAt(CC[10], upper).setValue(hokakaisu3);
		sheet.getCellAt(CC[11], upper).setValue(hokakaisu5);
		sheet.getCellAt(CC[12], upper).setValue(String.valueOf(yukyu));
		sheet.getCellAt(CC[13], upper).setValue(String.valueOf(tokukyu));
		// 下段項目
		int lower = row + 1;
		sheet.getCellAt(CC[0], lower).setValue("");
		sheet.getCellAt(CC[1], lower).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(kyukeiji)));
		sheet.getCellAt(CC[2], lower).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(ksjikan)));
		sheet.getCellAt(CC[7], lower).setValue(cyokukaisu1);
		sheet.getCellAt(CC[8], lower).setValue(cyokukaisu3);
		sheet.getCellAt(CC[9], lower).setValue(hokakaisu2);
		sheet.getCellAt(CC[10], lower).setValue(hokakaisu4);
		sheet.getCellAt(CC[11], lower).setValue(kaikin);
		sheet.getCellAt(CC[12], lower).setValue(String.valueOf(kekkin));
		sheet.getCellAt(CC[13], lower).setValue(String.valueOf(skekkin));
	}
	
	/**
	 * 合計印刷
	 * @param sheet SpreadSheetインスタンス
	 */
	private void printTotal(Sheet sheet) {
		// 上段項目
		int upper = row;
		sheet.getCellAt(CC[0], upper).setValue(String.valueOf(totalSNissu));
		sheet.getCellAt(CC[1], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKinmuJi)));
		sheet.getCellAt(CC[2], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalZaJikan)));
		sheet.getCellAt(CC[3], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalSnJikan)));
		sheet.getCellAt(CC[4], upper).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalTiJikan)));
		sheet.getCellAt(CC[5], upper).setValue(totalTisoKai);
		sheet.getCellAt(CC[7], upper).setValue(totalSyokujiKaisu);
		sheet.getCellAt(CC[8], upper).setValue(totalCyokuKaisu2);
		sheet.getCellAt(CC[9], upper).setValue(totalHokaKaisu1);
		sheet.getCellAt(CC[10], upper).setValue(totalHokaKaisu3);
		sheet.getCellAt(CC[11], upper).setValue(totalHokaKaisu5);
		sheet.getCellAt(CC[12], upper).setValue(String.valueOf(totalYukyu));
		sheet.getCellAt(CC[13], upper).setValue(String.valueOf(totalTokukyu));
		// 下段項目
		int lower = row + 1;
		sheet.getCellAt(CC[0], lower).setValue("");
		sheet.getCellAt(CC[1], lower).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKyukeiJi)));
		sheet.getCellAt(CC[2], lower).setValue(getHourString(TimeUtil.convIntegerTimeToDoubleTime(totalKsJikan)));
		sheet.getCellAt(CC[7], lower).setValue(totalCyokuKaisu1);
		sheet.getCellAt(CC[8], lower).setValue(totalCyokuKaisu3);
		sheet.getCellAt(CC[9], lower).setValue(totalHokaKaisu2);
		sheet.getCellAt(CC[10], lower).setValue(totalHokaKaisu4);
		sheet.getCellAt(CC[11], lower).setValue(totalKaikin);
		sheet.getCellAt(CC[12], lower).setValue(String.valueOf(totalKekkin));
		sheet.getCellAt(CC[13], lower).setValue(String.valueOf(totalSKekkin));
	}
	
	/**
	 * 合計
	 */
	private void addTotal() {
		totalSNissu += snissu;
		totalKinmuJi += kinmuji;
		totalKyukeiJi += kyukeiji;
		totalYukyu += yukyu;
		totalTokukyu += tokukyu;
		totalKekkin += kekkin;
		totalSKekkin += skekkin;
		totalTisoKai += tisokai;
		totalTiJikan += tijikan;
		totalZaJikan += zajikan;
		totalKsJikan += ksjikan;
		totalSnJikan += snjikan;
		totalKaikin += kaikin;
		totalSyokujiKaisu += syokujikaisu;
		totalCyokuKaisu1 += cyokukaisu1;
		totalCyokuKaisu2 += cyokukaisu2;
		totalCyokuKaisu3 += cyokukaisu3;
		totalHokaKaisu1 += hokakaisu1;
		totalHokaKaisu2 += hokakaisu2;
		totalHokaKaisu3 += hokakaisu3;
		totalHokaKaisu4 += hokakaisu4;
		totalHokaKaisu5 += hokakaisu5;
	}
	
}
