8 require_once(dirname(__FILE__) .
'/../../lib/Model.php');
16 $sql =
"SELECT `name`, `term_year` FROM `t_basic` wHERE `id` = '" . $this->
esc($bid) .
"'";
19 $name = (empty($rec[0][
'name'])) ?
'' : $rec[0][
'name'];
20 $term_year = (empty($rec[0][
'term_year'])) ? -1 : $rec[0][
'term_year'] * 1;
21 $last_year = $term_year - 1;
23 $sql =
"SELECT `id` FROM `t_basic`"
24 .
" wHERE `name` = '" . $this->
esc($name) .
"'"
25 .
" AND `term_year` = '" . $this->
esc($last_year) .
"'"
31 return (empty($rec[0][
'id'])) ? -1 : $rec[0][
'id'];
34 public function useLast($mid, $src, $dst) {
47 }
catch(Exception $e) {
48 $err[
'msg'] = $e->getMessage();
66 $s =
"SELECT * FROM `t_section` WHERE `bid` = '%s' ORDER BY `id`";
69 $sql =
"DELETE FROM `t_section` WHERE `bid` = '" . $this->
esc($dst) .
"'";
70 $ans = $this->
query($sql);
77 $sql =
"INSERT INTO `t_section`"
78 .
" (`bid`, `kana`, `name`, `update_person`)"
80 .
" ('" . $this->
esc($dst) .
"'"
81 .
", '" . $this->
esc($kana) .
"'"
82 .
", '" . $this->
esc($name) .
"'"
83 .
", '" . $this->
esc($mid) .
"'"
86 $ans = $this->
query($sql);
89 }
catch(Exception $e) {
98 $s =
"SELECT * FROM `t_account` WHERE `bid` = '%s' AND `delete_flg` is TRUE ORDER BY `id`";
101 $sql =
"DELETE FROM `t_account`"
102 .
" WHERE `bid` = '" . $this->
esc($dst) .
"'"
103 .
" AND `delete_flg` = TRUE"
105 $ans = $this->
query($sql);
111 $item_ccd = $d[
'item_ccd'];
112 $division = $d[
'division'];
116 $sql =
"INSERT INTO `t_account`"
117 .
" (`bid`, `ccd`, `item`, `item_ccd`, `division`, `kana`, `name`, `delete_flg`, `edit_flg`, `update_person`)"
119 .
" ('" . $this->
esc($dst) .
"'"
120 .
", '" . $this->
esc($ccd) .
"'"
121 .
", '" . $this->
esc($item) .
"'"
122 .
", '" . $this->
esc($item_ccd) .
"'"
123 .
", '" . $this->
esc($division) .
"'"
124 .
", '" . $this->
esc($kana) .
"'"
125 .
", '" . $this->
esc($name) .
"'"
128 .
", '" . $this->
esc($mid) .
"'"
131 $ans = $this->
query($sql);
134 }
catch(Exception $e) {
143 $s =
"SELECT * FROM `t_item` WHERE `bid` = '%s' AND `delete_flg` is TRUE ORDER BY `id`";
146 $sql =
"DELETE FROM `t_item`"
147 .
" WHERE `bid` = '" . $this->
esc($dst) .
"'"
148 .
" AND `delete_flg` = TRUE"
150 $ans = $this->
query($sql);
159 $account = $d[
'account'];
162 $sql =
"INSERT INTO `t_item`"
163 .
" (`bid`, `kcd`, `ccd`, `account`, `item`, `kana`, `name`, `valid_flg`, `delete_flg`, `edit_flg`, `update_person`)"
165 .
" ('" . $this->
esc($dst) .
"'"
166 .
", '" . $this->
esc($kcd) .
"'"
167 .
", '" . $this->
esc($ccd) .
"'"
168 .
", '" . $this->
esc($account) .
"'"
169 .
", '" . $this->
esc($item) .
"'"
170 .
", '" . $this->
esc($kana) .
"'"
171 .
", '" . $this->
esc($name) .
"'"
175 .
", '" . $this->
esc($mid) .
"'"
178 $ans = $this->
query($sql);
181 }
catch(Exception $e) {
189 $sql =
"SELECT COUNT(*) AS `cnt` FROM `t_journal` wHERE `bid` = '" . $this->
esc($bid) .
"'";
193 return $rec[0][
'cnt'] * 1;
200 .
" `id`, `name`, `disp_name`, `term_year`, `term_begin`, `term_end`"
202 .
" WHERE `valid_flg` = TRUE"
203 .
" AND `mid` = '" . $this->
esc($mid) .
"'"
204 .
" ORDER BY `term_year` DESC, `term_begin` DESC, `disp_name` ASC"
209 if (empty($rec[0])) {
213 $rec[0][
'era'] = $this->
era($rec[0][
'id'], $rec[0][
'term_begin']);
222 $f =
new SplFileObject($fname,
'w');
228 $s =
"SELECT `term_year`, `term_begin`, `term_end` FROM `t_basic` WHERE `id` = '%s'";
231 $d[$n++] = [
'HEADER',
'term_year',
'term_begin',
'term_end'];
232 $d[$n++] = [
'BASIC', $r[0][
'term_year'], $r[0][
'term_begin'], $r[0][
'term_end']];
236 $s =
"SELECT `id`, `kana`, `name` FROM `t_section` WHERE `bid` = '%s'";
241 $sect[$v[
'id']] = $v[
'name'];
244 $d[$n++] = [
'HEADER',
'kana',
'name'];
246 $d[$n++] = [
'SECTION',
'--none--'];
249 $d[$n++] = [
'SECTION', $v[
'kana'], $v[
'name']];
255 $s =
"SELECT `ccd`, `item`, `item_ccd`, `division`, `kana`, `name` FROM `t_account`"
256 .
" WHERE `bid` = '%s' AND `delete_flg` = 1";
259 $d[$n++] = [
'HEADER',
'ccd',
'item',
'item_ccd',
'division',
'kana',
'name'];
261 $d[$n++] = [
'ACCOUNT',
'--none--'];
264 $d[$n++] = [
'ACCOUNT', $v[
'ccd'], $v[
'item'], $v[
'item_ccd'], $v[
'division'], $v[
'kana'], $v[
'name']];
270 $s =
"SELECT `kcd`, `kana`, `name` FROM `t_item` WHERE `bid` = '%s' AND `delete_flg` = 1";
273 $d[$n++] = [
'HEADER',
'kcd',
'kana',
'name'];
275 $d[$n++] = [
'ITEM',
'--none--'];
278 $d[$n++] = [
'ITEM', $v[
'kcd'], $v[
'kana'], $v[
'name']];
284 $s =
"SELECT `j`.`id`, `j`.`scd`, `j`.`settled_flg` AS `flg`, `j`.`ymd`,"
285 .
" `s`.`line`, `s`.`debit`, `s`.`credit`, `s`.`amount`, `s`.`remark`"
286 .
" FROM `t_journal` `j` INNER JOIN `t_jslip` `s` ON `j`.`id` = `s`.`jid`"
287 .
" WHERE `j`.`bid` = '%s'"
288 .
" ORDER BY `j`.`scd`, `j`.`settled_flg`, `j`.`ymd`, `j`.`id`, `s`.`line`"
292 $d[$n++] = [
'HEADER',
'id',
'scd',
'flg',
'ymd',
'line',
'debit',
'credit',
'amount',
'remark'];
294 $d[$n++] = [
'SLIP',
'--none--'];
297 $d[$n++] = [
'SLIP', $v[
'id'], $sect[$v[
'scd']], $v[
'flg'], $v[
'ymd'], $v[
'line'], $v[
'debit'], $v[
'credit'], $v[
'amount'], $v[
'remark']];
303 foreach ($d as $line) {
321 foreach (
$dat as $d) {
327 $basic = [$h[1] => $d[1], $h[2] => $d[2], $h[3] => $d[3]];
330 if ($d[1] !=
'--none--') {
331 $section[] = [$h[1] => $d[1], $h[2] => $d[2]];
335 if ($d[1] !=
'--none--') {
336 $account[] = [$h[1] => $d[1], $h[2] => $d[2], $h[3] => $d[3], $h[4] => $d[4], $h[5] => $d[5], $h[6] => $d[6]];
340 if ($d[1] !=
'--none--') {
341 $item[] = [$h[1] => $d[1], $h[2] => $d[2], $h[3] => $d[3]];
345 if ($d[1] !=
'--none--') {
346 $slip[] = [$h[1] => $d[1], $h[2] => $d[2], $h[3] => $d[3], $h[4] => $d[4], $h[5] => $d[5], $h[6] => $d[6], $h[7] => $d[7], $h[8] => $d[8], $h[9] => $d[9]];
353 $err = $this->
_updImportedData($mid, $bid, $basic, $section, $account, $item, $slip);
368 if (!empty($basic)) $this->
_updBasic($bid, $basic);
369 if (!empty($section)) $this->
_updSection($mid, $bid, $section);
370 if (!empty($account)) $this->
_updAccount($mid, $bid, $account);
371 if (!empty($item)) $this->
_updItem($mid, $bid, $item);
372 if (!empty($slip)) $this->
_updSlip($mid, $bid, $slip);
374 }
catch(Exception $e) {
375 $err[
'SQL'] = $e->getMessage();
393 $sql =
"UPDATE `t_basic` SET"
394 .
" `term_year` = '" . $this->
esc(
$dat[
'term_year']) .
"'"
395 .
", `term_begin` = '" . $this->
esc(
$dat[
'term_begin']) .
"'"
396 .
", `term_end` = '" . $this->
esc(
$dat[
'term_end']) .
"'"
397 .
" WHERE `id` = '" . $this->
esc($bid) .
"'"
399 $ans = $this->
query($sql);
401 }
catch(Exception $e) {
409 $sql =
"DELETE FROM `t_section` WHERE `bid` = '" . $this->
esc($bid) .
"'";
410 $ans = $this->
query($sql);
412 foreach (
$dat as $d) {
417 $sql =
"INSERT INTO `t_section`"
418 .
" (`bid`, `kana`, `name`, `update_person`)"
420 .
" ('" . $this->
esc($bid) .
"'"
421 .
", '" . $this->
esc($kana) .
"'"
422 .
", '" . $this->
esc($name) .
"'"
423 .
", '" . $this->
esc($mid) .
"'"
426 $ans = $this->
query($sql);
429 }
catch(Exception $e) {
438 $sql =
"DELETE FROM `t_account`"
439 .
" WHERE `bid` = '" . $this->
esc($bid) .
"'"
440 .
" AND `delete_flg` = TRUE"
442 $ans = $this->
query($sql);
444 foreach (
$dat as $d) {
448 $item_ccd = $d[
'item_ccd'];
449 $division = $d[
'division'];
453 $sql =
"INSERT INTO `t_account`"
454 .
" (`bid`, `ccd`, `item`, `item_ccd`, `division`, `kana`, `name`, `delete_flg`, `edit_flg`, `update_person`)"
456 .
" ('" . $this->
esc($bid) .
"'"
457 .
", '" . $this->
esc($ccd) .
"'"
458 .
", '" . $this->
esc($item) .
"'"
459 .
", '" . $this->
esc($item_ccd) .
"'"
460 .
", '" . $this->
esc($division) .
"'"
461 .
", '" . $this->
esc($kana) .
"'"
462 .
", '" . $this->
esc($name) .
"'"
465 .
", '" . $this->
esc($mid) .
"'"
468 $ans = $this->
query($sql);
471 }
catch(Exception $e) {
479 $sql =
"DELETE FROM `t_item`"
480 .
" WHERE `bid` = '" . $this->
esc($bid) .
"'"
481 .
" AND `delete_flg` = TRUE"
483 $ans = $this->
query($sql);
485 foreach (
$dat as $d) {
491 $ccd = substr($kcd, 0, 4) * 1;
492 $account = substr($kcd, 4, 2) * 1;
493 $item = substr($kcd, 6, 2) * 1;
495 $sql =
"INSERT INTO `t_item`"
496 .
" (`bid`, `kcd`, `ccd`, `account`, `item`, `kana`, `name`, `valid_flg`, `delete_flg`, `edit_flg`, `update_person`)"
498 .
" ('" . $this->
esc($bid) .
"'"
499 .
", '" . $this->
esc($kcd) .
"'"
500 .
", '" . $this->
esc($ccd) .
"'"
501 .
", '" . $this->
esc($account) .
"'"
502 .
", '" . $this->
esc($item) .
"'"
503 .
", '" . $this->
esc($kana) .
"'"
504 .
", '" . $this->
esc($name) .
"'"
508 .
", '" . $this->
esc($mid) .
"'"
511 $ans = $this->
query($sql);
514 }
catch(Exception $e) {
523 $sql =
"SELECT `id`, `name` FROM `t_section` WHERE `bid` = '" . $this->
esc($bid) .
"'";
527 foreach ($rec as $r) {
528 $scd[$r[
'name']] = $r[
'id'];
531 $sql =
"SELECT `id` FROM `t_journal` WHERE `bid` = '" . $this->
esc($bid) .
"'";
534 foreach ($rec as $r) {
535 $sql =
"DELETE FROM `t_jslip` WHERE `jid` = '" . $this->
esc($r[
'id']) .
"'";
536 $ans = $this->
query($sql);
537 $sql =
"DELETE FROM `t_journal` WHERE `id` = '" . $this->
esc($r[
'id']) .
"'";
538 $ans = $this->
query($sql);
542 foreach (
$dat as $d) {
551 foreach ($j as $k => $d) {
552 $sql =
"INSERT INTO `t_journal`"
553 .
" (`bid`, `scd`, `ymd`, `settled_flg`, `not_use_flg`, `update_person`)"
555 .
" ('" . $this->
esc($bid) .
"'"
556 .
", '" . $this->
esc($scd[$d[
'scd']]) .
"'"
557 .
", '" . $this->
esc($d[
'ymd']) .
"'"
558 .
", '" . $this->
esc($d[
'flg']) .
"'"
560 .
", '" . $this->
esc($mid) .
"'"
563 $ans = $this->
query($sql);
568 foreach (
$dat as $d) {
569 $sql =
"INSERT INTO `t_jslip`"
570 .
" (`jid`, `line`, `debit`, `credit`, `amount`, `remark`, `update_person`)"
572 .
" ('" . $this->
esc($jid[$d[
'id'] * 1]) .
"'"
573 .
", '" . $this->
esc($d[
'line']) .
"'"
574 .
", '" . $this->
esc($d[
'debit']) .
"'"
575 .
", '" . $this->
esc($d[
'credit']) .
"'"
576 .
", '" . $this->
esc($d[
'amount']) .
"'"
577 .
", '" . $this->
esc($d[
'remark']) .
"'"
578 .
", '" . $this->
esc($mid) .
"'"
581 $ans = $this->
query($sql);
584 }
catch(Exception $e) {