JSlip  1.0
UserAcitmController.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__) . '/UserAcitmModel.php');
11 
12 define('PAGER_RPP', 10);
13 
15 {
16  public $rest;
17  public $param;
18  public $model;
19  public $view;
20  public $viewName;
21  public $dat;
22  public $pager;
23  public $err;
24  public $bid;
25  public $basic;
26  public $const;
27 
28  public function main($param) {
29 
30  $this->rest = '';
31  $this->param = $param;
32  $this->bid = $_SESSION['minfo']['bid'];
33  $this->model = new UserAcitmModel($this->bid);
34  $this->view = new View();
35 
36  $this->param['base'] = dirname(__FILE__);
37 
38  $basic = $this->model->getBasicByBid($this->bid);
39  $this->_getConst();
40 
41  if (empty($basic[0])) {
42  $this->_error('基本情報が見つかりません。');
43  return;
44  } else {
45  $this->basic = $basic[0];
46  }
47 
48  if (empty($this->param['act'])) {
49  $this->_list();
50  } else {
51  switch ($this->param['act']) {
52  case 'create': $this->_create(); break;
53  case 'drop': $this->_drop(); break;
54  case 'edit': $this->_edit(); break;
55  case 'remember': $this->_remember(); break;
56  case 'search': $this->_search(); break;
57  case 'check': $this->_check(); break;
58  case 'regist': $this->_regist(); break;
59  default: $this->_list(); break;
60  }
61  }
62  }
63 
64  private function _error($err) {
65 
66  $this->viewName = 'user_acitm_err';
67  $this->err = $err;
68  }
69 
70  private function _list() {
71 
72  $this->viewName = 'user_acitm_list';
73 
74  $this->dat['cnd'] = [
75  'cnd_name' => '',
76  'cnd_kana' => '',
77  'pager' => ['page' => 1, 'rpp' => PAGER_RPP],
78  ];
79 
80  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
81 
82  $_SESSION['user_acitm_list_cnd'] = $this->dat['cnd'];
83  }
84 
85  private function _getConst() {
86  $this->const['c_c0'] = $this->model->getConst('c_c0');
87  $this->const['c_c1'] = $this->model->getConst('c_c1');
88  $this->const['c_c2'] = $this->model->getConst('c_c2');
89  $this->const['c_c3'] = $this->model->getConst('c_c3');
90  $this->const['c_c4'] = $this->model->getConst('c_c4');
91  $this->const['c_deb_cre'] = $this->model->getConst('c_deb_cre');
92  $this->const['c_item_class'] = $this->model->getConst('c_item_class');
93  $this->const['c34'] = $this->model->getC34();
94  }
95 
96  private function _search() {
97 
98  $this->viewName = 'user_acitm_list';
99 
100  $this->dat['cnd'] = [
101  'cnd_name' => $this->param['cnd_name'],
102  'cnd_kana' => $this->param['cnd_kana'],
103  'pager' => ['page' => $this->param['page_curr'], 'rpp' => PAGER_RPP],
104  ];
105 
106  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
107 
108  $_SESSION['user_acitm_list_cnd'] = $this->dat['cnd'];
109  }
110 
111  private function _remember() {
112 
113  $this->viewName = 'user_acitm_list';
114  $this->dat['cnd'] = $_SESSION['user_acitm_list_cnd'];
115  $this->dat['list'] = $this->model->getList($this->dat['cnd']);
116  }
117 
118  private function _edit() {
119 
120  $this->viewName = 'user_acitm_edit';
121  $this->dat = $this->model->getData($this->param['id']);
122  }
123 
124  private function _check() {
125 
126  $err = [];
127 
128  $insert = (empty($this->param['insert'])) ? false : true;
129  $item = $this->param['item'];
130  $kana = $this->param['kana'];
131  $name = $this->param['name'];
132 
133  if (empty($kana)) {
134  $err[] = '勘定名(かな)は必須です。';
135  }
136 
137  if (empty($name)) {
138  $err[] = '勘定名は必須です。';
139  }
140 
141  if ($item == '') {
142  $err[] = '勘定細分コードは必須です。';
143  } else {
144  $v = (int)$item;
145  if ($v < 0 || $v > 99) {
146  $err[] = '勘定細分コードが不正です。';
147  }
148  }
149 
150  if (empty($err)) {
151  if (!empty($this->param['insert'])) {
152  if ($this->model->chkDup($this->param) > 0) {
153  $err[] = 'コードが重複しています。';
154  }
155  }
156  }
157 
158  if (empty($err)) {
159  $this->rest = json_encode(['sts' => 'OK']);
160  } else {
161  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
162  }
163  }
164 
165  private function _regist() {
166 
167  $insert = (empty($this->param['insert'])) ? false : true;
168 
169  if ($insert) {
170  $err = $this->model->insert($this->param);
171  } else {
172  $err = $this->model->regist($this->param);
173  }
174 
175  if (!empty($err)) {
176  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
177  return;
178  }
179 
180  $this->rest = json_encode(['sts' => 'OK']);
181  }
182 
183  private function _create() {
184 
185  $this->viewName = 'user_acitm_create';
186  }
187 
188  private function _drop() {
189 
190  $err = $this->model->delete($this->param);
191 
192  if (!empty($err)) {
193  $this->rest = json_encode(['sts' => 'NG', 'err' => $err]);
194  return;
195  }
196 
197  $this->rest = json_encode(['sts' => 'OK']);
198  }
199 }
UserAcitmController\_search
_search()
Definition: UserAcitmController.php:96
UserAcitmController\_getConst
_getConst()
Definition: UserAcitmController.php:85
UserAcitmController\$viewName
$viewName
Definition: UserAcitmController.php:20
UserAcitmController\$view
$view
Definition: UserAcitmController.php:19
UserAcitmController\_list
_list()
Definition: UserAcitmController.php:70
UserAcitmController\main
main($param)
Definition: UserAcitmController.php:28
UserAcitmController\_remember
_remember()
Definition: UserAcitmController.php:111
UserAcitmController\_edit
_edit()
Definition: UserAcitmController.php:118
View
Definition: View.php:8
UserAcitmController\$err
$err
Definition: UserAcitmController.php:23
UserAcitmController\_regist
_regist()
Definition: UserAcitmController.php:165
PAGER_RPP
const PAGER_RPP
Definition: UserAcitmController.php:12
UserAcitmController\$bid
$bid
Definition: UserAcitmController.php:24
Controller
Definition: Controller.php:15
UserAcitmController\$dat
$dat
Definition: UserAcitmController.php:21
UserAcitmModel
Definition: UserAcitmModel.php:10
UserAcitmController\$model
$model
Definition: UserAcitmController.php:18
UserAcitmController
Definition: UserAcitmController.php:14
UserAcitmController\_error
_error($err)
Definition: UserAcitmController.php:64
UserAcitmController\$param
$param
Definition: UserAcitmController.php:17
UserAcitmController\_check
_check()
Definition: UserAcitmController.php:124
UserAcitmController\_create
_create()
Definition: UserAcitmController.php:183
UserAcitmController\$pager
$pager
Definition: UserAcitmController.php:22
UserAcitmController\$const
$const
Definition: UserAcitmController.php:26
UserAcitmController\_drop
_drop()
Definition: UserAcitmController.php:188
UserAcitmController\$basic
$basic
Definition: UserAcitmController.php:25
UserAcitmController\$rest
$rest
Definition: UserAcitmController.php:16