JSlip  1.0
UserTaxController.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__) . '/UserTaxModel.php');
11 
13 {
14  public $rest;
15  public $param;
16  public $model;
17  public $view;
18  public $viewName;
19  public $dat;
20  public $err;
21  public $bid;
22  public $basic;
23 
24  public function main($param) {
25 
26  $this->rest = '';
27  $this->param = $param;
28  $this->bid = $_SESSION['minfo']['bid'];
29  $this->model = new UserTaxModel($this->bid);
30  $this->view = new View();
31 
32  $this->param['base'] = dirname(__FILE__);
33 
34  $basic = $this->model->getBasicByBid($this->bid);
35 
36  if (empty($basic[0])) {
37  $this->_error('基本情報が見つかりません。');
38  return;
39  } else {
40  $this->basic = $basic[0];
41  }
42 
43  if (empty($this->param['act'])) {
44  $this->_list();
45  } else {
46  switch ($this->param['act']) {
47  case 'create': $this->_create(); break;
48  case 'drop': $this->_drop(); break;
49  case 'edit': $this->_edit(); break;
50  case 'use': $this->_use(); break;
51  case 'check': $this->_check(); break;
52  case 'regist': $this->_regist(); break;
53  default: $this->_list(); break;
54  }
55  }
56  }
57 
58  private function _error($err) {
59 
60  $this->viewName = 'user_tax_err';
61  $this->err = $err;
62  }
63 
64  private function _list() {
65 
66  $this->viewName = 'user_tax_list';
67 
68  $this->dat['list'] = $this->model->getList();
69  }
70 
71  private function _create() {
72 
73  $this->viewName = 'user_tax_create';
74  }
75 
76  private function _edit() {
77 
78  $this->viewName = 'user_tax_edit';
79  $this->dat = $this->model->getData($this->param['id']);
80  }
81 
82  private function _use() {
83 
84  $err = $this->model->setValidFlg($this->param);
85 
86  if (empty($err)) {
87  $this->rest = json_encode(['sts' => 'OK']);
88  } else {
89  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
90  }
91  }
92 
93  private function _check() {
94 
95  $err = [];
96 
97  $insert = (empty($this->param['insert'])) ? false : true;
98  $name = $this->param['name'];
99  @$rate = $this->param['rate'] * 1.0;
100 
101  if (empty($name)) {
102  $err[] = '名称は必須です。';
103  }
104 
105  if ($rate < 0.0001 || $rate >= 100.0) {
106  $err[] = '税率が不正です。rateは、0.0001以上で100未満の間で指定します。';
107  }
108 
109  if ($insert && $this->model->chkDup($name) > 0) {
110  $err[] = '名称は既に存在します。';
111  }
112 
113  if (empty($err)) {
114  $this->rest = json_encode(['sts' => 'OK']);
115  } else {
116  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
117  }
118  }
119 
120  private function _regist() {
121 
122  $insert = (empty($this->param['insert'])) ? false : true;
123 
124  if ($insert) {
125  $err = $this->model->insert($this->param);
126  } else {
127  $err = $this->model->regist($this->param);
128  }
129 
130  if (!empty($err)) {
131  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
132  return;
133  }
134 
135  $this->rest = json_encode(['sts' => 'OK']);
136  }
137 
138  private function _drop() {
139 
140  $err = $this->model->delete($this->param);
141 
142  if (!empty($err)) {
143  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
144  return;
145  }
146 
147  $this->rest = json_encode(['sts' => 'OK']);
148  }
149 }
UserTaxController\_check
_check()
Definition: UserTaxController.php:93
UserTaxController\main
main($param)
Definition: UserTaxController.php:24
UserTaxController\_drop
_drop()
Definition: UserTaxController.php:138
UserTaxController\$rest
$rest
Definition: UserTaxController.php:14
UserTaxController\_use
_use()
Definition: UserTaxController.php:82
UserTaxModel
Definition: UserTaxModel.php:10
View
Definition: View.php:8
UserTaxController\$dat
$dat
Definition: UserTaxController.php:19
UserTaxController\$model
$model
Definition: UserTaxController.php:16
UserTaxController\$basic
$basic
Definition: UserTaxController.php:22
Controller
Definition: Controller.php:15
UserTaxController\_edit
_edit()
Definition: UserTaxController.php:76
UserTaxController\$param
$param
Definition: UserTaxController.php:15
UserTaxController
Definition: UserTaxController.php:12
UserTaxController\$bid
$bid
Definition: UserTaxController.php:21
UserTaxController\_create
_create()
Definition: UserTaxController.php:71
UserTaxController\$err
$err
Definition: UserTaxController.php:20
UserTaxController\_list
_list()
Definition: UserTaxController.php:64
UserTaxController\$view
$view
Definition: UserTaxController.php:17
UserTaxController\_error
_error($err)
Definition: UserTaxController.php:58
UserTaxController\$viewName
$viewName
Definition: UserTaxController.php:18
UserTaxController\_regist
_regist()
Definition: UserTaxController.php:120