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 $this->viewName =
'user_menu';
55 if (empty($this->param[
'bid'])) {
56 if (empty($_SESSION[
'minfo'][
'mid'])) {
57 $this->dat = [
'err' =>
'Out of service.'];
58 $this->viewName =
'user_menu_error';
61 if ($_SESSION[
'minfo'][
'role'] ==
'root') {
62 $basic = $this->model->getBasicByBid($_SESSION[
'minfo'][
'bid']);
64 if (empty($_SESSION[
'minfo'][
'bid'])) {
65 $basic = $this->model->getBasicByMid($_SESSION[
'minfo'][
'mid']);
67 $basic = $this->model->getBasicByBid($_SESSION[
'minfo'][
'bid']);
72 $basic = $this->model->getBasicByBid($this->param[
'bid']);
75 $this->dat = [
'basic' => $basic];
77 if (empty($this->dat[
'basic'])) {
78 $this->dat = [
'err' =>
'Out of service.'];
79 $this->viewName =
'user_menu_err';
83 if (empty($this->param[
'bid'])) {
84 $_SESSION[
'minfo'][
'bid'] = $this->dat[
'basic'][0][
'id'];
86 $_SESSION[
'minfo'][
'bid'] = $this->param[
'bid'];
92 $bid = $this->param[
'bid'];
93 $last = $this->model->getLast($bid);
96 $ans = [
'sts' =>
'NG',
'err' =>
'前年度のデータが見つかりません。'];
98 $err = $this->model->useLast($_SESSION[
'minfo'][
'mid'], $last, $bid);
100 $ans = [
'sts' =>
'OK',
'err' =>
''];
102 $ans = [
'sts' =>
'NG',
'err' => $err[
'msg']];
106 $this->rest = json_encode($ans);
110 $cnt = $this->model->cntJournal($this->param[
'bid']);
111 $this->rest = json_encode([
'sts' =>
'OK',
'cnt' =>
$cnt]);
115 $_SESSION[
'minfo'][
'bid'] = $this->param[
'bid'];
116 $this->rest = json_encode([
'sts' =>
'OK']);
120 $this->csv = $this->param[
'tmp_dir'] .
'/slip_' . $_SESSION[
'minfo'][
'bid'] .
'_' . date(
'YmdHis') .
'.csv';
121 $this->model->makeCsv($_SESSION[
'minfo'][
'bid'], $this->csv);
129 $this->viewName =
'user_menu';
131 $upfile = $this->param[
'tmp_dir'] .
'/' . basename($_FILES[
'upfile'][
'name']);
133 if (empty($_FILES[
'upfile'][
'name'])) {
134 $err[
'File Name'] =
'ファイル名が指定されていません。';
135 } elseif (!move_uploaded_file($_FILES[
'upfile'][
'tmp_name'], $upfile)) {
136 $err[
'Upload'] =
'ファイルのアップロードに失敗しました。';
138 $file =
new SplFileObject($upfile);
139 $file->setFlags(SplFileObject::READ_CSV);
140 foreach ($file as $line) {
141 if (!is_null($line[0])) {
148 $validErr = $this->
_ValidImportCsv($_SESSION[
'minfo'][
'bid'], $records);
149 if (empty($validErr)) {
150 $err = $this->model->setImportedCsvData($_SESSION[
'minfo'][
'mid'], $_SESSION[
'minfo'][
'bid'], $records);
152 $err[
'Valid'] = $validErr;
156 $basic = $this->model->getBasicByBid($this->param[
'bid']);
157 $this->dat = [
'err' => $err,
'basic' => $basic];
162 $r0 = (empty($rec[0][0])) ?
'' : $rec[0][0];
163 $r1 = (empty($rec[1][0])) ?
'' : $rec[1][0];
164 $r2 = (empty($rec[2][0])) ?
'' : $rec[2][0];
165 $r3 = (empty($rec[3][0])) ?
'' : $rec[3][0];
166 $r = $r0 . $r1 . $r2 . $r3;
168 if ($r !=
'HEADERBASICHEADERSECTION') {
169 return 'データ・フォーマットが違います。';
172 $cnt = $this->model->cntJournal($bid);
175 return '伝票が入力されています。';
182 header(
'Content-Type: application/octet-stream');
183 header(
'Content-Length: ' . filesize($this->csv));
184 header(
'Content-Disposition: inline; filename=' . basename($this->csv));
185 readfile($this->csv);