% sfseikyu.sty 
% by Shinsaku Fujita 
% Copyright (C) S. Fujita (2000). All rights reserved. 
% Version 1.00 2000/01/05
%
%  作成者: 藤田眞作
%          fujitas@chem.kit.ac.jp
%
%   藤田眞作著「入門・縦横文書術」所載
%
%\typeout{Option Style `sfseikyu.sty' by S. Fujita}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\j@urnalname{sfseikyu}
\def\versi@ndate{January 5, 2000}
\def\versi@nno{ver1.00}
\def\copyrighth@lder{SF} % Shinsaku Fujita
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\typeout{Option Style `\j@urnalname' (\versi@nno) <\versi@ndate>\space 
[\copyrighth@lder]}
\typeout{藤田眞作著「入門・縦横文書術」所載}
%
\@ifundefined{tatesuji}{\input{tatesuji.sty}}{}
% From chemist.sty by Shinsaku Fujita
\def\yen{\leavevmode\hbox{\setbox0=\hbox{Y}%
\setbox1=\vbox{\hrule height.05\ht0 width.96\wd0%
\kern.18\ht0\hrule height.05\ht0 width.96\wd0}%
\setbox1=\hbox to\wd0{\raise.3\ht0\box1\hss}%
{\ooalign{\hfil\box1\hfil\crcr\box0}}}}
%
% カウンター
%
\newcount\seikyuitem
\newcount\kingaku
\newcount\@tempcntc
\newcount\@tempcntd
\newcount\@tempcnte
\newcount\@tempcntf
\seikyuitem=0
\kingaku=0
%
% 文字の大きさ
%
\let\daijisize=\LARGE
\let\atenasize=\Large
%
% 品目
%
\def\hinmoku#1#2#3#4{\advance\seikyuitem by1%品目の種類数
%%%\global\advance\kingaku by#4
\def\tempaaa{}%
\@tfor\member:=#4\do{\edef\tempccc{,}%コンマは除く
\ifx\member\tempccc\relax\else\edef\tempaaa{\tempaaa\member}\fi}%
\@tempcntf=\tempaaa 
\global\advance\kingaku by\@tempcntf%累積金額
%\the\kingaku AAAAA
\expandafter\gdef\csname\the\seikyuitem item\endcsname{#1}%
\expandafter\gdef\csname\the\seikyuitem num\endcsname{#2}%
\expandafter\gdef\csname\the\seikyuitem @\endcsname{#3}%
\expandafter\gdef\csname\the\seikyuitem price\endcsname{#4}}
%
% 項目
%
\def\kokyaku#1{\gdef\@kokyaku{#1}}
\def\zenkaku{\char\jis"2121}
\def\seikyusha#1{\gdef\@seikyusha{#1}}
\def\seikyujusho#1{\gdef\@seikyujusho{#1}}
\def\seikyutel#1{\gdef\@seikyutel{#1}}
\def\seikyubango#1{\gdef\@seikyubango{#1}}
\def\yubinbango#1{\gdef\@yubinbango{#1}}
\seikyujusho{〒0123-4444 京都市〇△区△□町000番地}
\seikyusha{藤田 眞作}
\seikyutel{333-444-5555}
\yubinbango{1111-0000}
\seikyubango{}
%
% 消費税計算
%
\newif\ifshohizeisw \shohizeiswtrue
%
% 三桁ごとに区切る
%
\def\sanketakugiri#1\@nil{\@tempcntc=0\relax
%\expandafter\@tfor\expandafter\member\expandafter:%
%\expandafter=#1\do{\edef\tempccc{,}%
\@tfor\member:=#1\do{\edef\tempccc{,}%
\ifx\member\tempccc\relax\else\advance\@tempcntc by1\fi}
\@tempcntd=\@tempcntc\relax
\divide\@tempcntd by3\relax
\chardef\@maxtemp=\@tempcntd
\multiply\@tempcntd by3\relax
\advance\@tempcntc by-\@tempcntd \relax%剰余mod3
\@tempcntd=0\relax
\ifnum\@tempcntc=0\relax
\@tempcnte=2\relax\else
\@tempcnte=1\relax\fi
%\expandafter\@tfor\expandafter\member\expandafter:%
%\expandafter=#1\do{%
\@tfor\member:=#1\do{%
\edef\tempccc{,}%
\ifx\member\tempccc\relax\else
\advance\@tempcntd by1
\member%
\ifnum\@tempcnte>\@maxtemp\relax\else
\ifnum\@tempcntc>0\relax
\ifnum\@tempcntd=\@tempcntc\relax ,\relax
\advance\@tempcnte by1
\@tempcntd=0\relax
\@tempcntc=0\relax\fi
\else
\ifnum\@tempcntd=3 ,\relax\@tempcntd=0\relax
\advance\@tempcnte by1\relax
\fi\fi\fi\fi}}
%
% 枠と共に出力
%
\unitlength=1mm
\long\def\seikyushowaku{%
\par
\noindent
\@tempcnta=0
\@tempcntb=0
\begin{picture}(160,140)(0,0)
\put(60,130){\line(1,0){40}}
\put(60,130){\makebox(40,6){\daijisize\bf 請\zenkaku 求\zenkaku 書}}
\put(110,118){\makebox(50,5)[rb]{%
\ifx\@date\empty 平成 ~~ 年 ~~ 月 ~~ 日\else\@date\fi}}
\put(0,112){\makebox(42,6)[lb]{\atenasize \@kokyaku}}
\put(42,112){\makebox(8,6)[rb]{\atenasize\bf 様}}
\put(0,112){\line(1,0){50}}
\thicklines
\put(10,100){\line(1,0){140}}
\put(10,94){\line(1,0){140}}
%\put(10,16){\line(1,0){140}}
%\put(10,22){\line(1,0){140}}
\thinlines
%\multiput(10,88)(0,-6){11}{\line(1,0){140}}
\multiput(10,88)(0,-6){9}{\line(1,0){140}}
%\put(89,100){\line(0,-1){84}}
%\put(107,100){\line(0,-1){84}}
%\put(125,100){\line(0,-1){84}}
\put(10,94){%
\makebox(80,6){\strut 品\zenkaku\zenkaku\zenkaku\zenkaku 目}%
\makebox(15,6){\strut 数\zenkaku 量}\makebox(2,6){}%
\makebox(17,6){\strut 単\zenkaku 価}\makebox(2,6){}%
\makebox(23,6){\strut 金\zenkaku 額}}
\ifnum\seikyuitem>10\relax
\typeout{Seikyusho: Two Many Items}
\put(10,90){\strut 請求書の品目が10種類を越えています。}
\else
\loop%品目を指定された数だけループで出力
\advance\@tempcnta by1
\@tempcntb=-\@tempcnta \multiply\@tempcntb by6\relax%
\advance\@tempcntb by94\relax
%\put(10,88){%
\put(10,\the\@tempcntb){%
\makebox(6,6)[r]{\strut%
\footnotesize\it \the\@tempcnta.}%
\makebox(4,6){}%
\makebox(70,6)[l]{\strut%
\expandafter\csname\the\@tempcnta item\endcsname}%
\makebox(15,6)[r]{\strut%
\expandafter\csname\the\@tempcnta num\endcsname}%
\makebox(2,6){}%
\makebox(17,6)[r]{\strut%
\edef\tempbbb{\expandafter\csname\the\@tempcnta @\endcsname}%
\expandafter\sanketakugiri\tempbbb\@nil}%
\makebox(2,6){}%
\makebox(23,6)[r]{\strut%
\edef\tempbbb{\expandafter\csname\the\@tempcnta price\endcsname}%
\expandafter\sanketakugiri\tempbbb\@nil}}
\ifnum\@tempcnta<\seikyuitem \repeat%ループの終わり
\fi
%区切りを重ね書き
\ifnum\seikyuitem>10\relax\else
\thicklines
\put(10,\the\@tempcntb){\line(1,0){140}}
\thinlines
\fi
%合計
\typeout{Seikyusho: Total\space=\space\the\kingaku}%
\advance\@tempcnta by1
\@tempcntb=-\@tempcnta \multiply\@tempcntb by6\relax%
\advance\@tempcntb by94\relax
\ifnum\seikyuitem>10\relax\else
\put(10,\the\@tempcntb){%
\makebox(80,6){\strut 合\zenkaku\zenkaku\zenkaku\zenkaku 計}%
\makebox(15,6){\strut}\makebox(2,6){}%
\makebox(17,6){\strut}\makebox(2,6){}%
\makebox(23,6)[r]{\strut\edef\tempbbb{\the\kingaku}%
\expandafter\sanketakugiri\tempbbb\@nil}}\fi
%消費税5%
\ifshohizeisw
\@tempcntc=\kingaku \multiply\@tempcntc by5\relax
\divide\@tempcntc by100\relax
\typeout{Seikyusho: Tax\space=\space\the\@tempcntc}%
\advance\@tempcnta by1
\@tempcntb=-\@tempcnta \multiply\@tempcntb by6\relax%
\advance\@tempcntb by94\relax
\ifnum\seikyuitem>10\relax\else
%\ifshohizeisw%% bug fix: moved to line 192, 2002/04/30
\put(10,\the\@tempcntb){%
\makebox(80,6){\strut 消\hskip1.5zw 費\hskip1.5zw 税
\hbox to0pt{~~(5\%)\hss}}%
\makebox(15,6){\strut}\makebox(2,6){}%
\makebox(17,6){\strut}\makebox(2,6){}%
\makebox(23,6)[r]{\strut\edef\tempbbb{\the\@tempcntc}%
\expandafter\sanketakugiri\tempbbb\@nil}}\fi\fi
%
% 項目が9以上のときは、行を増やす。ただし、上限10項目
%
\ifnum\@tempcnta<11
\thicklines
\put(10,28){\line(1,0){140}}
\put(10,34){\line(1,0){140}}
\thinlines
\put(89,100){\line(0,-1){72}}
\put(107,100){\line(0,-1){72}}
\put(125,100){\line(0,-1){72}}
\else
\thicklines
\put(10,16){\line(1,0){140}}
\put(10,22){\line(1,0){140}}
\thinlines
\put(89,100){\line(0,-1){84}}
\put(107,100){\line(0,-1){84}}
\put(125,100){\line(0,-1){84}}
\multiput(10,34)(0,-6){2}{\line(1,0){140}}
\fi
%
% 請求額
%
\advance\@tempcntc by\kingaku
\typeout{Seikyusho: Account\space=\space\the\@tempcntc}%
\ifnum\@tempcnta<11
\put(10,28){%
\makebox(80,6){\strut 請\hskip1.5zw 求\hskip1.5zw 額}%
\makebox(15,6){\strut}\makebox(2,6){}%
\makebox(17,6){\strut}\makebox(2,6){}%
\ifnum\seikyuitem>10\relax\else
\makebox(23,6)[r]{\strut\edef\tempbbb{\the\@tempcntc}%
\yen\kern-.2zw\expandafter\sanketakugiri\tempbbb\@nil}\fi}
\ifx\@seikyubango\empty\else
\put(10,22){%
\makebox(150,6)[l]{(\small 請求番号\@seikyubango)}}\fi
\put(10,16){\strut 上記の通りご請求申し上げます。}
\put(90,14){\makebox(70,6)[lb]{\atenasize \@seikyusha
\hskip2zw{\footnotesize 印}{\kern-.8zw$\bigcirc$}}}
\put(94,8){\makebox(60,6)[lb]{\footnotesize 〒\@yubinbango}}
\put(94,4){\makebox(60,6)[lb]{\footnotesize \@seikyujusho}}
\put(94,0){\makebox(60,6)[lb]{\footnotesize 電話\@seikyutel}}
\else
\put(10,16){%
\makebox(80,6){\strut 請\hskip1.5zw 求\hskip1.5zw 額}%
\makebox(15,6){\strut}\makebox(2,6){}%
\makebox(17,6){\strut}\makebox(2,6){}%
\makebox(23,6)[r]{\strut\edef\tempbbb{\the\@tempcntc}%
\yen\kern-.2zw\expandafter\sanketakugiri\tempbbb\@nil}}
\ifx\@seikyubango\empty\else
\put(10,10){%
\makebox(150,6)[l]{(\small 請求番号\@seikyubango)}}\fi
\put(10,4){\strut 上記の通りご請求申し上げます。}
\put(90,2){\makebox(70,6)[lb]{\atenasize \@seikyusha
\hskip2zw{\footnotesize 印}{\kern-.8zw$\bigcirc$}}}
\put(94,-4){\makebox(60,6)[lb]{\footnotesize 〒\@yubinbango}}
\put(94,-8){\makebox(60,6)[lb]{\footnotesize \@seikyujusho}}
\put(94,-12){\makebox(60,6)[lb]{\footnotesize 電話\@seikyutel}}
\fi
\end{picture}}
\endinput
%
%以下は実例
%
\documentclass[a4j]{jarticle}
\usepackage{sfseikyu}

\textwidth=16cm
\oddsidemargin=-0.1cm
\pagestyle{empty}

\begin{document}
%\shohizeiswfalse
%%%デフォルトは消費税を計算\shohizeitrue
\seikyubango{0123}
\date{平成12年1月5日}
%\date{}%年月日を出力しない。
%\dateを指定しないと処理日の日付
\kokyaku{四井五菱株式会社}
\hinmoku{化学者・生化学者のための\LaTeX }{1冊}{4800}{4800}
\hinmoku{\LaTeX まくろの八衢}{1冊}{2330}{2330}
\hinmoku{\LaTeX 本づくりの八衢}{1冊}{3107}{3107}
\hinmoku{\LaTeX2e 階梯}{1冊}{2718}{2718}
\hinmoku{続\LaTeX2e 階梯・縦組編}{1冊}{3500}{3500}
\hinmoku{XyMTeX---Typesetting$\cdots$}{1冊}{5500}{5500}
%\hinmoku{書籍g}{1冊}{1800}{1800}
%\hinmoku{書籍h}{3冊}{500}{1500}
%\hinmoku{雑誌a}{1冊}{1000}{1000}
%\hinmoku{雑誌b}{1冊}{800}{800}
%\hinmoku{俗悪雑誌j}{1冊}{500}{5000}%11項目以上はエラー
\yubinbango{0123-4444}
\seikyujusho{京都市〇△区△□町000番地}
\seikyusha{藤　田　眞　作}
\seikyutel{333-444-5555}
\seikyushowaku
\end{document}
