JSlip  1.0
UserCalcController.php
Go to the documentation of this file.
1 <?php
8 require_once(dirname(__FILE__) . '/../../lib/View.php');
9 require_once(dirname(__FILE__) . '/../../lib/Controller.php');
10 require_once(dirname(__FILE__) . '/../../lib/Tex.php');
11 require_once(dirname(__FILE__) . '/UserCalcModel.php');
12 
14 {
15  public $rest;
16  public $param;
17  public $model;
18  public $view;
19  public $viewName;
20  public $tex;
21  public $pdf;
22  public $tsv;
23  public $tmplt;
24  public $err;
25  public $bid;
26  public $basic;
27  public $begin;
28  public $end;
29  public $lcdt;
30 
31  public function main($param) {
32 
33  $this->rest = '';
34  $this->pdf = '';
35  $this->param = $param;
36  $this->bid = $_SESSION['minfo']['bid'];
37  $this->model = new UserCalcModel($this->bid);
38  $this->view = new View();
39  $this->tex = new Tex();
40 
41  $this->param['base'] = dirname(__FILE__);
42 
43  $basic = $this->model->getBasicByBid($this->bid);
44 
45  if (empty($basic[0])) {
46  $this->_error('基本情報が見つかりません。');
47  return;
48  } else {
49  $this->basic = $basic[0];
50  }
51 
52  $this->begin = str_replace('-', '/', $this->basic['term_begin']);
53  $this->end = str_replace('-', '/', $this->basic['term_end']);
54  $this->lcdt = str_replace('-', '/', $this->model->lastCalculatedDate);
55 
56  if (empty($this->param['act'])) {
57  $this->_menu();
58  } else {
59  switch ($this->param['act']) {
60  case 'calculate': $this->_calculate(); break;
61  case 'slip': $this->_slip(); break;
62  case 'ledger': $this->_ledger(); break;
63  case 'tb_detail': $this->_tb_detail(); break;
64  case 'tb': $this->_tb(); break;
65  case 'pl': $this->_pl(); break;
66  case 'bs': $this->_bs(); break;
67  case 'pls': $this->_pls(); break;
68  case 'bss': $this->_bss(); break;
69  default: $this->_menu(); break;
70  }
71  }
72  }
73 
74  public function dispPdf() {
75  $this->_dispPdf();
76  $this->_clearFiles();
77  }
78 
79  private function _error($err) {
80  $this->viewName = 'user_calc_err';
81  $this->err = $err;
82  }
83 
84  private function _menu() {
85  $this->viewName = 'user_calc_menu';
86  }
87 
88  private function _calculate() {
89 
90  $err = $this->model->calculate($this->basic);
91 
92  if (empty($err)) {
93  $this->lcdt = str_replace('-', '/', $this->model->lastCalculatedDate);
94  } else {
95  $this->_error($err);
96  return;
97  }
98 
99  $this->viewName = 'user_calc_menu';
100  }
101 
102  private function _slip() {
103 
104  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
105  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
106  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_slip.php';
107 
108  $this->model->setTsvSlip($this->basic, $this->tsv);
109  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
110  }
111 
112  private function _ledger() {
113 
114  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
115  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
116  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_ledger.php';
117 
118  $this->model->setTsvLedger($this->basic, $this->tsv);
119  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
120  }
121 
122  private function _tb_detail() {
123 
124  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
125  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
126  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_tb_detail.php';
127 
128  $this->model->setTsvTbDetail($this->basic, $this->tsv);
129  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
130  }
131 
132  private function _tb() {
133 
134  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
135  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
136  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_tb.php';
137 
138  $this->model->setTsvTb($this->basic, $this->tsv);
139  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
140  }
141 
142  private function _pl() {
143 
144  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
145  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
146  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_pl.php';
147 
148  $this->model->setTsvPl($this->basic, $this->tsv);
149  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
150  }
151 
152  private function _bs() {
153 
154  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
155  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
156  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_bs.php';
157 
158  $this->model->setTsvBs($this->basic, $this->tsv);
159  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
160  }
161 
162  private function _pls() {
163 
164  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
165  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
166  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_pls.php';
167 
168  $this->model->setTsvPls($this->basic, $this->tsv);
169  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
170  }
171 
172  private function _bss() {
173 
174  $this->pdf = $this->param['tmp_dir'] . '/' . $this->tex->pdf;
175  $this->tsv = $this->param['tmp_dir'] . '/' . $this->tex->tsv;
176  $this->tmplt = $this->param['base'] . '/tex/tex_tmplt_bss.php';
177 
178  $this->model->setTsvBss($this->basic, $this->tsv);
179  $this->tex->makePdf($this->param['tmp_dir'], $this->tmplt, $this->tsv);
180  }
181 
182  private function _dispPdf() {
183  header('Content-type: application/pdf');
184  header('Content-Length: ' . filesize($this->pdf));
185  header('Content-Disposition: inline; filename=' . basename($this->pdf));
186  readfile($this->pdf);
187  }
188 
189  private function _clearFiles() {
190  exec(UTL_DELETE . ' -f ' . $this->param['tmp_dir'] . '/' . $this->tex->uid . '.*');
191  }
192 }
UserCalcController\_tb_detail
_tb_detail()
Definition: UserCalcController.php:122
UserCalcModel
Definition: UserCalcModel.php:10
UserCalcController\_ledger
_ledger()
Definition: UserCalcController.php:112
UserCalcController\_menu
_menu()
Definition: UserCalcController.php:84
UserCalcController\$tmplt
$tmplt
Definition: UserCalcController.php:23
UserCalcController\$param
$param
Definition: UserCalcController.php:16
UserCalcController\_bs
_bs()
Definition: UserCalcController.php:152
UserCalcController\$viewName
$viewName
Definition: UserCalcController.php:19
UserCalcController\_clearFiles
_clearFiles()
Definition: UserCalcController.php:189
UserCalcController\_calculate
_calculate()
Definition: UserCalcController.php:88
UserCalcController\_bss
_bss()
Definition: UserCalcController.php:172
UserCalcController\$basic
$basic
Definition: UserCalcController.php:26
UserCalcController\$view
$view
Definition: UserCalcController.php:18
UserCalcController\_slip
_slip()
Definition: UserCalcController.php:102
UserCalcController\_pl
_pl()
Definition: UserCalcController.php:142
View
Definition: View.php:8
UTL_DELETE
const UTL_DELETE
Definition: local.php:52
UserCalcController\dispPdf
dispPdf()
Definition: UserCalcController.php:74
UserCalcController\$bid
$bid
Definition: UserCalcController.php:25
Controller
Definition: Controller.php:15
UserCalcController\$lcdt
$lcdt
Definition: UserCalcController.php:29
UserCalcController\_pls
_pls()
Definition: UserCalcController.php:162
UserCalcController\$pdf
$pdf
Definition: UserCalcController.php:21
UserCalcController\_dispPdf
_dispPdf()
Definition: UserCalcController.php:182
UserCalcController\_tb
_tb()
Definition: UserCalcController.php:132
UserCalcController\$end
$end
Definition: UserCalcController.php:28
UserCalcController\$tsv
$tsv
Definition: UserCalcController.php:22
UserCalcController
Definition: UserCalcController.php:13
UserCalcController\main
main($param)
Definition: UserCalcController.php:31
UserCalcController\_error
_error($err)
Definition: UserCalcController.php:79
UserCalcController\$err
$err
Definition: UserCalcController.php:24
UserCalcController\$model
$model
Definition: UserCalcController.php:17
UserCalcController\$rest
$rest
Definition: UserCalcController.php:15
UserCalcController\$begin
$begin
Definition: UserCalcController.php:27
Tex
Definition: Tex.php:8
UserCalcController\$tex
$tex
Definition: UserCalcController.php:20