8 require_once(dirname(__FILE__) .
'/../../lib/View.php');
9 require_once(dirname(__FILE__) .
'/../../lib/Controller.php');
10 require_once(dirname(__FILE__) .
'/UserMenuModel.php');
28 $this->view =
new View();
30 $this->param[
'base'] = dirname(__FILE__);
32 if (empty($this->param[
'act'])) {
35 switch ($this->param[
'act']) {
36 case 'useLast': $this->
_useLast();
break;
38 case 'setBid': $this->
_setBid();
break;
41 default: $this->
_menu();
break;
53 if ($_SESSION[
'minfo'][
'role'] ==
'root' && !empty($this->param[
'bid'])) {
54 $this->dat = [
'basic' => $this->model->getBasicByBid($this->param[
'bid'])];
55 $this->viewName =
'user_menu';
56 } elseif (empty($_SESSION[
'minfo'][
'mid']) || empty($_SESSION[
'minfo'][
'bcnt'])) {
57 $this->dat = [
'err' =>
'Out of service.'];
58 $this->viewName =
'user_menu_err';
59 } elseif ($_SESSION[
'minfo'][
'bid'] > 0) {
60 $this->dat = [
'basic' => $this->model->getBasicByBid($_SESSION[
'minfo'][
'bid'])];
61 $this->viewName =
'user_menu';
63 $this->dat = [
'basic' => $this->model->getBasicByMid($_SESSION[
'minfo'][
'mid'])];
64 $this->viewName =
'user_menu_select';
70 $bid = $this->param[
'bid'];
71 $last = $this->model->getLast($bid);
74 $ans = [
'sts' =>
'NG',
'err' =>
'前年度のデータが見つかりません。'];
76 $err = $this->model->useLast($_SESSION[
'minfo'][
'mid'], $last, $bid);
78 $ans = [
'sts' =>
'OK',
'err' =>
''];
80 $ans = [
'sts' =>
'NG',
'err' => $err[
'msg']];
84 $this->rest = json_encode($ans);
88 $cnt = $this->model->cntJournal($this->param[
'bid']);
89 $this->rest = json_encode([
'sts' =>
'OK',
'cnt' =>
$cnt]);
93 $_SESSION[
'minfo'][
'bid'] = $this->param[
'bid'];
94 $this->dat = [
'basic' => $this->model->getBasicByBid($_SESSION[
'minfo'][
'bid'])];
95 $this->viewName =
'user_menu';
99 $this->csv = $this->param[
'tmp_dir'] .
'/slip_' . $_SESSION[
'minfo'][
'bid'] .
'_' . date(
'YmdHis') .
'.csv';
100 $this->model->makeCsv($_SESSION[
'minfo'][
'bid'], $this->csv);
108 $this->viewName =
'user_menu';
110 $upfile = $this->param[
'tmp_dir'] .
'/' . basename($_FILES[
'upfile'][
'name']);
112 if (empty($_FILES[
'upfile'][
'name'])) {
113 $err[
'File Name'] =
'ファイル名が指定されていません。';
114 } elseif (!move_uploaded_file($_FILES[
'upfile'][
'tmp_name'], $upfile)) {
115 $err[
'Upload'] =
'ファイルのアップロードに失敗しました。';
117 $file =
new SplFileObject($upfile);
118 $file->setFlags(SplFileObject::READ_CSV);
119 foreach ($file as $line) {
120 if (!is_null($line[0])) {
127 $validErr = $this->
_ValidImportCsv($_SESSION[
'minfo'][
'bid'], $records);
128 if (empty($validErr)) {
129 $err = $this->model->setImportedCsvData($_SESSION[
'minfo'][
'mid'], $_SESSION[
'minfo'][
'bid'], $records);
131 $err[
'Valid'] = $validErr;
135 $basic = $this->model->getBasicByBid($this->param[
'bid']);
136 $this->dat = [
'err' => $err,
'basic' => $basic];
141 $r0 = (empty($rec[0][0])) ?
'' : $rec[0][0];
142 $r1 = (empty($rec[1][0])) ?
'' : $rec[1][0];
143 $r2 = (empty($rec[2][0])) ?
'' : $rec[2][0];
144 $r3 = (empty($rec[3][0])) ?
'' : $rec[3][0];
145 $r = $r0 . $r1 . $r2 . $r3;
147 if ($r !=
'HEADERBASICHEADERSECTION') {
148 return 'データ・フォーマットが違います。';
151 $cnt = $this->model->cntJournal($bid);
154 return '伝票が入力されています。';
161 header(
'Content-Type: application/octet-stream');
162 header(
'Content-Length: ' . filesize($this->csv));
163 header(
'Content-Disposition: inline; filename=' . basename($this->csv));
164 readfile($this->csv);