JSlip  1.0
tex_tmplt_ledger.php
Go to the documentation of this file.
1 <?php
8 define('MAX_LINES_PAR_PAGE', 42);
9 
10 class tex_tmplt
11 {
12  private $csvfile;
13  private $dat;
14 
15  // for amount
16  private function amount($x)
17  {
18  return ($x == 0) ? "" : "{\\tt{" . str_replace("-", "▲", number_format($x)) . "}}";
19  }
20 
21  // TABセパレータCSVファイルからデータを取得し$datにデータを設定します。
22  private function set_dat()
23  {
24  $csv = file($this->csvfile); // TABセパレータCSVファイル・データ読み込み
25  $data_n = 0;
26  $cnt = count($csv);
27  for ($i = 0; $i < $cnt; $i++) {
28  $rec = explode("\t", $csv[$i]);
29  switch ($rec[0]) {
30  case "title":
31  case "name":
32  case "era":
33  case "rows":
34  $this->dat[$rec[0]] = trim($rec[1]);
35  break;
36  case "field":
37  $this->dat[$rec[0]]["n"] = trim($rec[1]);
38  $this->dat[$rec[0]]["m"] = trim($rec[2]);
39  $this->dat[$rec[0]]["mmdd"] = trim($rec[3]);
40  $this->dat[$rec[0]]["memo"] = trim($rec[4]);
41  $this->dat[$rec[0]]["item"] = trim($rec[5]);
42  $this->dat[$rec[0]]["other"] = trim($rec[6]);
43  $this->dat[$rec[0]]["amount0"] = trim($rec[7]);
44  $this->dat[$rec[0]]["amount1"] = trim($rec[8]);
45  $this->dat[$rec[0]]["remain"] = trim($rec[9]);
46  $this->dat[$rec[0]]["name"] = trim($rec[10]);
47  break;
48  case "data":
49  $this->dat[$rec[0]][$data_n]["n"] = trim($rec[1]);
50  $this->dat[$rec[0]][$data_n]["m"] = trim($rec[2]);
51  $this->dat[$rec[0]][$data_n]["mmdd"] = trim($rec[3]);
52  $this->dat[$rec[0]][$data_n]["memo"] = trim($rec[4]);
53  $this->dat[$rec[0]][$data_n]["item"] = trim($rec[5]);
54  $this->dat[$rec[0]][$data_n]["other"] = trim($rec[6]);
55  $this->dat[$rec[0]][$data_n]["amount0"] = trim($rec[7]);
56  $this->dat[$rec[0]][$data_n]["amount1"] = trim($rec[8]);
57  $this->dat[$rec[0]][$data_n]["remain"] = trim($rec[9]);
58  $this->dat[$rec[0]][$data_n]["name"] = trim($rec[10]);
59  $data_n++;
60  break;
61  }
62  }
63  }
64 
65  // 主処理
66  public function main()
67  {
68  $this->set_dat();
69  }
70 
71  // make a page
72  public function make_a_page($n)
73  {
74  $d = $this->dat["data"];
75  $name = $this->dat["name"];
76  $era = $this->dat["era"];
77  $m = $d[$n]["m"];
78  $mm = $d[$n]["m"] % 100;
79  $item = $d[$n]["item"];
80  $inam = $d[$n]["name"];
81 
82  echo "\\begin{center}\n";
83  echo "\\begin{tabular}{ccc}\n";
84  echo "\\multicolumn{2}{l}{\\makebox[12.5cm][l]{" . $name . "}} & ";
85  echo "\\makebox[2.5cm][r]{\\tt{" . $item . "}} \\\\\n";
86  echo "\\makebox[2.5cm][l]{} & ";
87  echo "\\underline{\\makebox[10cm][c]{\\bf{" . $inam . "}}} & ";
88  echo "\\makebox[2.5cm][r]{" . $era . "年度} \\\\\n";
89  echo "\\multicolumn{2}{l}{\\makebox[12.5cm][c]{}} & ";
90  echo "\\makebox[2.5cm][r]{" . $mm . "月度} \\\\\n";
91  echo "\\end{tabular}\n";
92 
93  echo "\\begin{center}\n";
94  echo "\\begin{tabular}{cccccc}\n";
95  echo "\\Hline\n";
96  echo "\\makebox[0.8cm][c]{\\bf{日付}} \\Vline & ";
97  echo "\\makebox[5.0cm][c]{\\bf{摘  要}} \\Vline & ";
98  echo "\\makebox[0.5cm][c]{\\bf{丁数\\ \\ }} \\Vline & ";
99  echo "\\makebox[2.2cm][c]{\\bf{借 方}} \\Vline & ";
100  echo "\\makebox[2.2cm][c]{\\bf{貸 方}} \\Vline & ";
101  echo "\\makebox[2.2cm][c]{\\bf{差引残高}} \\\\\n";
102  echo "\\Hline\n";
103 
104  $max = $n + MAX_LINES_PAR_PAGE;
105  $x = $n;
106  $month = $mm;
107  while ($n < $max)
108  {
109  if (!isset($d[$n]["item"])) {
110  break;
111  }
112 
113  if ($item != $d[$n]["item"]) {
114  break;
115  }
116 
117  $mm = $d[$n]["m"] % 100;
118  $md = "{\\tt{" . $d[$n]["mmdd"] . "}}";
119  $memo = $d[$n]["memo"];
120  $other = intval($d[$n]["other"] / 10000);
121  $am0 = $d[$n]["amount0"];
122  $am1 = $d[$n]["amount1"];
123  $rem = $d[$n]["remain"];
124 
125  $other = ($other == 0) ? "" : "{\\tt{" . $other . "}}";
126  $am0 = ($am0 == 0) ? "" : $this->amount($am0);
127  $am1 = ($am1 == 0) ? "" : $this->amount($am1);
128  $rem = ($rem == 0) ? "" : $this->amount($rem);
129 
130  if ($x != $n) {
131  if ($month != $mm) {
132  $month = $mm;
133  echo "\\Hline\n";
134  } else {
135  echo "\\hline\n";
136  }
137  }
138 
139  echo "\\makebox[0.8cm][c]{" . $md ."} & ";
140  echo "\\makebox[5.0cm][l]{" . $memo ."} & ";
141  echo "\\makebox[0.5cm][c]{" . $other ."} & ";
142  echo "\\makebox[2.2cm][r]{" . $am0 ."} & ";
143  echo "\\makebox[2.2cm][r]{" . $am1 ."} & ";
144  echo "\\makebox[2.2cm][r]{" . $rem ."} \\\\\n";
145 
146  $n++;
147  }
148 
149  echo "\\Hline\n";
150  echo "\\end{tabular}\n";
151  echo "\\end{center}\n";
152  echo "\\newpage\n";
153 
154  return $n;
155  }
156 
157  // check data for debug
158  public function chk_dat()
159  {
160  echo "title = " . $this->dat["title"] . "\n\n";
161  echo "name = " . $this->dat["name"] . "\n\n";
162  echo "era = " . $this->dat["era"] . "\n\n";
163  echo "rows = " . $this->dat["rows"] . "\n\n";
164 
165  echo $this->dat["field"]["n"] . ", " .
166  $this->dat["field"]["m"] . ", " .
167  $this->dat["field"]["mmdd"] . ", " .
168  $this->dat["field"]["memo"] . ", " .
169  $this->dat["field"]["item"] . ", " .
170  $this->dat["field"]["other"] . ", " .
171  $this->dat["field"]["amount0"] . ", " .
172  $this->dat["field"]["amount1"] . ", " .
173  $this->dat["field"]["remain"] . ", " .
174  $this->dat["field"]["name"] . "\n\n";
175 
176  $cnt = $this->dat["rows"];
177  for ($i = 0; $i < $cnt; $i++) {
178  echo $this->dat["data"][$i]["n"] . ", " .
179  $this->dat["data"][$i]["m"] . ", " .
180  $this->dat["data"][$i]["mmdd"] . ", " .
181  $this->dat["data"][$i]["memo"] . ", " .
182  $this->dat["data"][$i]["item"] . ", " .
183  $this->dat["data"][$i]["other"] . ", " .
184  $this->dat["data"][$i]["amount0"] . ", " .
185  $this->dat["data"][$i]["amount1"] . ", " .
186  $this->dat["data"][$i]["remain"] . ", " .
187  $this->dat["data"][$i]["name"] . "\n\n";
188  }
189  }
190 
191  // 表示データ取得
192  public function get_dat()
193  {
194  return $this->dat;
195  }
196 
197  // 明示的コンストラクタ
198  public function __construct($filename)
199  {
200  $this->csvfile = $filename;
201  $this->dat = array();
202  }
203 }
204 
205 $my = new tex_tmplt($argv[1]);
206 $my->main();
207 $dat = $my->get_dat();
208 ?>
209 \documentclass[a4j]{jarticle}
210 
211 \usepackage{supertabular}
212 
213 \pagestyle{plain}
214 
215 \topmargin -25mm
216 \oddsidemargin 0mm
217 \evensidemargin 0mm
218 \textheight 260mm
219 \textwidth 160mm
220 \parindent 1zw
221 \parskip 0.5zw
222 
223 % 太い罫線のために
224 \def\Hline{\noalign{\hrule height .5mm}}
225 \def\Vline{\vrule width .5mm}
226 
227 \begin{document}
228 
229 <?php
230 if (0) {
231  $my->chk_dat();
232 } else {
233  $n = 0;
234  $cnt = $dat["rows"];
235  while ($n < $cnt)
236  $n = $my->make_a_page($n, $cnt);
237 }
238 ?>
239 
240 \end{document}
$dat
$dat
Definition: tex_tmplt_ledger.php:207
tex_tmplt\get_dat
get_dat()
Definition: tex_tmplt_ledger.php:192
tex_tmplt\chk_dat
chk_dat()
Definition: tex_tmplt_ledger.php:158
tex_tmplt\$dat
$dat
Definition: tex_tmplt_bs.php:13
tex_tmplt\$csvfile
$csvfile
Definition: tex_tmplt_bs.php:12
MAX_LINES_PAR_PAGE
const MAX_LINES_PAR_PAGE
Definition: tex_tmplt_ledger.php:8
tex_tmplt\amount
amount($x)
Definition: tex_tmplt_ledger.php:16
tex_tmplt\main
main()
Definition: tex_tmplt_ledger.php:66
$cnt
$cnt
Definition: tex_tmplt_ledger.php:234
tex_tmplt\make_a_page
make_a_page($n)
Definition: tex_tmplt_ledger.php:72
tex_tmplt\__construct
__construct($filename)
Definition: tex_tmplt_ledger.php:198
tex_tmplt\set_dat
set_dat()
Definition: tex_tmplt_ledger.php:22
tex_tmplt
Definition: tex_tmplt_bs.php:10
$my
$my
Definition: tex_tmplt_ledger.php:205