% kk_budget_tools.tex 
% Macros to make budget tables for shingaku_field1
% 2015-10-26 Taku Yamanaka (Osaka Univ.)
%-----------------------------------------------------------------
\newcounter{kkCategorySum}
\KLnewcounter{kkAnnualSum}{\KLMaxYear}

\newenvironment{kkBudgetTable}{%
% for begin
%	beginning of kkBudgetTable: \value{KLequipments1}\\
	\setcounter{kkAnnualSum0}{0}%
	\setcounter{kkAnnualSum1}{0}%
	\setcounter{kkAnnualSum2}{0}%
	\setcounter{kkAnnualSum3}{0}%
	\setcounter{kkAnnualSum4}{0}%
	\setcounter{kkAnnualSum5}{0}%	

	\begin{tabular}{|l|l|r|r|r|r|r|r|r|}%
		\hline
		\multicolumn{2}{|l|}{}
		&令和\一年目 　　& 令和\二年目 　　& 令和\三年目 　　
		& 令和\四年目 　　& 令和\五年目 　　& 合計\\
		\multicolumn{2}{|l|}{}
		& (\一年目西暦) 年度 & (\二年目西暦) 年度 & (\三年目西暦) 年度 
		& (\四年目西暦) 年度 & (\五年目西暦) 年度 & \\
		\hline
}{% for end
		\multicolumn{2}{|l|}{合計}
		& \Number{\value{kkAnnualSum1}}	& \Number{\value{kkAnnualSum2}}
		& \Number{\value{kkAnnualSum3}}	& \Number{\value{kkAnnualSum4}}	
		& \Number{\value{kkAnnualSum5}}	& \Number{\value{kkAnnualSum0}}\\
		\hline
	\end{tabular}%
}

\newcommand{\kkKLAddCost}[2]{%
	\setcounter{KLYearCount}{#1}%
	\KLAddCost{#2}%
	\addtocounter{kkAnnualSum0}{#2}%
	\addtocounter{kkAnnualSum#1}{#2}%
}

\newcommand{\kkBudget}[6]{%
	\ifthenelse{\equal{#1}{設備備品費}}{%
		\renewcommand{\KLCostCategory}{KLequipments}
	}{}%
	\ifthenelse{\equal{#1}{消耗品}}{%
		\renewcommand{\KLCostCategory}{KLexpendables}
	}{}%
	\ifthenelse{\equal{#1}{国内旅費}}{%
		\renewcommand{\KLCostCategory}{KLdomestic}
	}{}
	\ifthenelse{\equal{#1}{海外旅費}}{%
		\renewcommand{\KLCostCategory}{KLforeign}
	}{}
	\ifthenelse{\equal{#1}{人件費}}{%
		\renewcommand{\KLCostCategory}{KLgratitude}
	}{}
	\ifthenelse{\equal{#1}{その他}}{%
		\renewcommand{\KLCostCategory}{KLmisc}
	}{}
	\setcounter{kkCategorySum}{0}%
	\addtocounter{kkCategorySum}{#2}%
	\addtocounter{kkCategorySum}{#3}%
	\addtocounter{kkCategorySum}{#4}%
	\addtocounter{kkCategorySum}{#5}%
	\addtocounter{kkCategorySum}{#6}%
	\kkKLAddCost{1}{#2}%
	\kkKLAddCost{2}{#3}%
	\kkKLAddCost{3}{#4}%
	\kkKLAddCost{4}{#5}%
	\kkKLAddCost{5}{#6}%

	\Number{#2} & \Number{#3} & \Number{#4}
	& \Number{#5} & \Number{#6} & \Number{\value{kkCategorySum}}\\%
}

\newcommand{\設備備品費}{\multicolumn{2}{|l|}{設備備品費}}
\newcommand{\消耗品費}{\multicolumn{2}{|l|}{消耗品費}}
\newcommand{\旅費国内}{旅費 & 国内}
\newcommand{\旅費海外}{	& 海外}
\newcommand{\人件費}{\multicolumn{2}{|l|}{人件費・謝金}}
\newcommand{\その他}{\multicolumn{2}{|l|}{その他}}

\newcommand{\kkTotalBudget}{%
	\begin{tabular}{|l|l|r|r|r|r|r|r|r|}%
		\hline
		\multicolumn{2}{|l|}{}
		&\KLTabC{令和\一年目} 　　& 令和\二年目 　　& 令和\三年目 　　
		& 令和\四年目 　　& 令和\五年目 　　& 合計\\
		\multicolumn{2}{|l|}{}
		& (\一年目西暦) 年度 & (\二年目西暦) 年度 & (\三年目西暦) 年度 
		& (\四年目西暦) 年度 & (\五年目西暦) 年度 & \\
		\hline
    		\設備備品費
			& \Number{\value{KLequipments1}} 
                    	& \Number{\value{KLequipments2}} 
                    	& \Number{\value{KLequipments3}} 
                    	& \Number{\value{KLequipments4}} 
                    	& \Number{\value{KLequipments5}} 
                    	& \Number{\value{KLequipments0}}\\
	    	\hline
    		\消耗品費
			& \Number{\value{KLexpendables1}} 
                    	& \Number{\value{KLexpendables2}} 
                    	& \Number{\value{KLexpendables3}} 
                    	& \Number{\value{KLexpendables4}} 
                    	& \Number{\value{KLexpendables5}} 
                    	& \Number{\value{KLexpendables0}}\\
    		\hline
	    	\旅費国内
			& \Number{\value{KLdomestic1}} 
                    	& \Number{\value{KLdomestic2}} 
                    	& \Number{\value{KLdomestic3}} 
                    	& \Number{\value{KLdomestic4}} 
                    	& \Number{\value{KLdomestic5}} 
                    	& \Number{\value{KLdomestic0}}\\
	    	\cline{2-8}
	    	\旅費海外
			& \Number{\value{KLforeign1}} 
                    	& \Number{\value{KLforeign2}} 
                    	& \Number{\value{KLforeign3}} 
                    	& \Number{\value{KLforeign4}} 
                    	& \Number{\value{KLforeign5}} 
                    	& \Number{\value{KLforeign0}}\\
	    	\hline
	    	\人件費	
 			& \Number{\value{KLgratitude1}} 
                    	& \Number{\value{KLgratitude2}} 
                    	& \Number{\value{KLgratitude3}} 
                    	& \Number{\value{KLgratitude4}} 
                    	& \Number{\value{KLgratitude5}} 
                    	& \Number{\value{KLgratitude0}}\\
   		\hline
	    	\その他	
			& \Number{\value{KLmisc1}} 
                    	& \Number{\value{KLmisc2}} 
                    	& \Number{\value{KLmisc3}} 
                    	& \Number{\value{KLmisc4}} 
                    	& \Number{\value{KLmisc5}} 
                    	& \Number{\value{KLmisc0}}\\
	    	\hline
			\multicolumn{2}{|c|}{合計}
			& \Number{\value{KLAnnualSum1}}
			& \Number{\value{KLAnnualSum2}}
			& \Number{\value{KLAnnualSum3}}
			& \Number{\value{KLAnnualSum4}}
			& \Number{\value{KLAnnualSum5}}
			& \Number{\value{KLAnnualSum0}}\\
		\hline
	\end{tabular}
}

%============================================
% for 主な設備備品費
\newcommand{\kkequipment}[5]{%
	#1 & #2 & \Number{#3} & #4 & #5\\
}