8 require_once(dirname(__FILE__) .
'/../../lib/View.php');
9 require_once(dirname(__FILE__) .
'/../../lib/Controller.php');
10 require_once(dirname(__FILE__) .
'/UserJournalModel.php');
12 define(
'PAGER_RPP', 3);
41 $this->bid = $_SESSION[
'minfo'][
'bid'];
43 $this->view =
new View();
46 $this->param[
'base'] = dirname(__FILE__);
48 $basic = $this->model->getBasicByBid($this->bid);
51 $this->
_error(
'基本情報が見つかりません。');
57 $this->begin = str_replace(
'-',
'/', $this->basic[
'term_begin']);
58 $this->end = str_replace(
'-',
'/', $this->basic[
'term_end']);
60 $this->dat[
'limit'] = $this->model->getLimit();
62 if (empty($this->param[
'act'])) {
65 switch ($this->param[
'act']) {
66 case 'create': $this->
_create();
break;
67 case 'drop': $this->
_drop();
break;
68 case 'edit': $this->
_edit();
break;
70 case 'tax': $this->
_tax();
break;
71 case 'remember': $this->
_remember();
break;
72 case 'search': $this->
_search();
break;
73 case 'check': $this->
_check();
break;
74 case 'regist': $this->
_regist();
break;
75 default: $this->
_list();
break;
82 $this->viewName =
'user_journal_err';
88 $this->viewName =
'user_journal_list';
99 'pager' => [
'page' => 1,
'rpp' =>
PAGER_RPP],
102 $this->dat[
'list'] = $this->model->getList($this->dat[
'cnd']);
103 $this->kcd = $this->model->getKcd($this->bid);
104 $this->section = $this->model->getSection($this->bid);
105 $this->settled = $this->model->getConst(
'c_settled');
107 $_SESSION[
'user_journal_list_cnd'] = $this->dat[
'cnd'];
112 $this->viewName =
'user_journal_list';
114 $this->dat[
'cnd'] = [
115 'cnd_scd' => $this->param[
'cnd_scd'],
116 'cnd_begin' => $this->param[
'cnd_begin'],
117 'cnd_end' => $this->param[
'cnd_end'],
118 'cnd_denpyo' => $this->param[
'cnd_denpyo'],
119 'cnd_kcd' => $this->param[
'cnd_kcd'],
120 'cnd_remark' => $this->param[
'cnd_remark'],
121 'cnd_stflg' => $this->param[
'cnd_stflg'],
122 'cnd_nuflg' => $this->param[
'cnd_nuflg'],
123 'pager' => [
'page' => $this->param[
'page_curr'],
'rpp' =>
PAGER_RPP],
126 $this->dat[
'list'] = $this->model->getList($this->dat[
'cnd']);
127 $this->kcd = $this->model->getKcd($this->bid);
128 $this->section = $this->model->getSection($this->bid);
129 $this->settled = $this->model->getConst(
'c_settled');
131 $_SESSION[
'user_journal_list_cnd'] = $this->dat[
'cnd'];
136 $this->viewName =
'user_journal_list';
137 $this->dat[
'cnd'] = $_SESSION[
'user_journal_list_cnd'];
138 $this->dat[
'list'] = $this->model->getList($this->dat[
'cnd']);
139 $this->kcd = $this->model->getKcd($this->bid);
140 $this->section = $this->model->getSection($this->bid);
141 $this->settled = $this->model->getConst(
'c_settled');
146 $this->viewName =
'user_journal_edit';
148 $this->mode =
'edit';
149 $this->dat = $this->model->getData($this->param[
'id']);
150 $this->item[
'name'] = $this->model->getItemByName($this->bid);
151 $this->item[
'time'] = $this->model->getItemByTime($this->bid);
152 $this->sect = $this->model->getSection($this->bid);
153 $this->stld = $this->model->getConst(
'c_settled');
158 $this->viewName =
'user_journal_edit';
160 $this->mode =
'duplicate';
161 $this->dat = $this->model->getData($this->param[
'id']);
162 $this->item[
'name'] = $this->model->getItemByName($this->bid);
163 $this->item[
'time'] = $this->model->getItemByTime($this->bid);
164 $this->sect = $this->model->getSection($this->bid);
165 $this->stld = $this->model->getConst(
'c_settled');
170 $this->singleViewName =
'user_journal_tax';
172 $round = $this->model->getRound($this->bid);
173 $tax = $this->model->getTax($this->bid);
174 $val = $this->param[
'val'] * 1.0;
177 $rname = $round[
'name'];
181 $ans[
'rname'] = $rname;
186 foreach ($tax as $k => $d) {
188 $r = $d[
'rate'] * 1.0;
191 case -1: $t = floor($t);
break;
192 case 0: $t = round($t);
break;
193 case 1: $t = ceil($t);
break;
195 $ans[
'otax'][$k] = [
'name' => $n,
'tax' => $t];
199 foreach ($tax as $k => $d) {
201 $r = $d[
'rate'] * 1.0;
202 $t = ($val * $r) / (1.0 + $r);
204 case -1: $t = floor($t);
break;
205 case 0: $t = round($t);
break;
206 case 1: $t = ceil($t);
break;
208 $ans[
'itax'][$k] = [
'name' => $n,
'tax' => $t];
218 $insert = (empty($this->param[
'insert'])) ?
false :
true;
219 $ymd = $this->param[
'arg'][
'ymd'];
220 $dat = $this->param[
'arg'][
'dat'];
223 $err[] =
'伝票日付は必須です。';
225 if (!$this->
chkYmd($ymd)) {
226 $err[] =
'不正な伝票日付です。';
228 if ($ymd < $this->begin || $this->end < $ymd) {
229 $err[] =
'伝票日付が範囲外です。';
238 foreach (
$dat as $k => $d) {
240 if ($d[
'deb_name'] == -1 && $d[
'cre_name'] == -1) {
246 if ($d[
'deb_name'] == -1 || $d[
'cre_name'] == -1) {
247 $err[] = $k .
'行目:借方科目または貸方科目が指定されていません。';
250 if ($d[
'deb_name'] == $d[
'cre_name']) {
251 $err[] = $k .
'行目:借方科目と貸方科目が同じです。';
254 if ($d[
'deb_amount'] == 0 && $d[
'cre_amount'] == 0) {
255 $err[] = $k .
'行目:金額が入力されていません。';
258 if ($d[
'remark'] ==
'') {
259 $err[] = $k .
'行目:摘要が入力されていません。';
262 $deb_sum += $d[
'deb_amount'];
263 $cre_sum += $d[
'cre_amount'];
266 if ($deb_sum != $cre_sum) {
267 $err[] =
'合計が等しくありません。';
275 $this->rest = json_encode([
'sts' =>
'OK']);
277 $this->rest = json_encode([
'sts' =>
'NG',
'err' =>
$err]);
283 if ($this->param[
'arg'][
'settled_flg'] == -1) {
287 $insert = (empty($this->param[
'insert'])) ?
false :
true;
290 $err = $this->model->insert($this->param);
292 $err = $this->model->regist($this->param);
296 $this->rest = json_encode([
'sts' =>
'NG',
'err' =>
$err]);
300 $this->rest = json_encode([
'sts' =>
'OK']);
305 $this->viewName =
'user_journal_create';
306 $this->item[
'name'] = $this->model->getItemByName($this->bid);
307 $this->item[
'time'] = $this->model->getItemByTime($this->bid);
308 $this->sect = $this->model->getSection($this->bid);
309 $this->stld = $this->model->getConst(
'c_settled');
314 $err = $this->model->delete($this->param);
317 $this->rest = json_encode([
'sts' =>
'NG',
'err' =>
$err]);
321 $this->rest = json_encode([
'sts' =>
'OK']);