8 require_once(dirname(__FILE__) .
'/../../lib/Model.php');
25 $fmt =
"SELECT COUNT(`s`.`id`) AS `cnt`"
26 .
" FROM `t_journal` `j`"
27 .
" INNER JOIN `t_jslip` `s` ON `j`.`id` = `s`.`jid`"
28 .
" WHERE `j`.`bid` = '%s'"
30 $sql = sprintf($fmt, $this->
esc($this->bid));
35 $limit[
'cnt_slip'] = $rec[0][
'cnt'];
36 $limit[
'chk_slip'] = ($limit[
'cnt_slip'] > $limit[
'max_slip']) ?
'NG' :
'OK';
56 $where =
" WHERE `j`.`bid` = '" . $this->
esc($this->bid) .
"'"
57 .
" AND `j`.`ymd` >= '" . $this->
esc($cnd[
'cnd_begin']) .
"'"
58 .
" AND `j`.`ymd` <= '" . $this->
esc($cnd[
'cnd_end']) .
"'"
61 if ($cnd[
'cnd_scd'] !=
'-1') {
62 $where .=
" AND `j`.`scd` = '" . $this->
esc($cnd[
'cnd_scd']) .
"'";
65 if ($cnd[
'cnd_denpyo'] !=
'') {
66 $where .=
" AND `j`.`id` = '" . $this->
esc($cnd[
'cnd_denpyo']) .
"'";
69 if ($cnd[
'cnd_kcd'] !=
'-1') {
70 $where .=
" AND (`s`.`debit` = '" . $this->
esc($cnd[
'cnd_kcd']) .
"'"
72 .
" `s`.`credit` = '" . $this->
esc($cnd[
'cnd_kcd']) .
"'"
77 if ($cnd[
'cnd_remark'] !=
'') {
78 $where .=
" AND `s`.`remark` LIKE '%" . $this->
esc($cnd[
'cnd_remark']) .
"%'";
81 if ($cnd[
'cnd_stflg'] !=
'-2') {
82 $where .=
" AND `j`.`settled_flg` = '" . $this->
esc($cnd[
'cnd_stflg']) .
"'";
85 if ($cnd[
'cnd_nuflg'] !=
'-1') {
86 $where .=
" AND `j`.`not_use_flg` = '" . $this->
esc($cnd[
'cnd_nuflg']) .
"'";
94 $sql =
"SELECT DISTINCT `j`.`id`"
95 .
" FROM `t_journal` `j`"
96 .
" INNER JOIN `t_jslip` `s` ON `j`.`id` = `s`.`jid`"
100 $cnt = (empty($rec)) ? 0 : count($rec);
112 $sql =
"SELECT DISTINCT"
113 .
" `j`.`id`" .
"AS id"
114 .
", `j`.`scd`" .
"AS scd"
115 .
", `j`.`ymd`" .
"AS ymd"
116 .
", `j`.`settled_flg`" .
"AS settled_flg"
117 .
", `j`.`not_use_flg`" .
"AS not_use_flg"
118 .
" FROM `t_journal` `j`"
119 .
" INNER JOIN `t_jslip` `s` ON `j`.`id` = `s`.`jid`"
121 .
" ORDER BY `ymd`, `id`"
122 .
" LIMIT " . $pg[
'ofst'] .
", " . $pg[
'rpp']
126 foreach ($jod as $j) {
135 .
" WHERE `jid` = '" . $j[
'id'] .
"'"
140 foreach ($rec as $d) {
141 $jsd[$j[
'id']][$d[
'id']] = [
142 'line' => $d[
'line'],
143 'debit' => $d[
'debit'],
144 'credit' => $d[
'credit'],
145 'amount' => $d[
'amount'],
146 'remark' => $d[
'remark'],
155 'last' => $pg[
'last'],
156 'page' => $pg[
'page'],
157 'rec' => [
'journal' => $jod,
'slip' => $jsd],
165 $sql =
"SELECT * FROM `t_journal` WHERE `id` = '" . $this->
esc($id) .
"'";
168 if (empty($jod[0])) {
173 $sql =
"SELECT * FROM `t_jslip`"
174 .
" WHERE `jid` = '" . $this->
esc($id) .
"'"
181 return (empty($rec[0])) ? [] : [
'journal' => $jod[0],
'slip' => $rec];
188 $bid = $param[
'bid'];
189 $arg = $param[
'arg'];
197 $sql =
"DELETE FROM `t_jslip` WHERE `jid` = '" . $this->
esc($jid) .
"'";
198 $ans = $this->
query($sql);
200 $sql =
"UPDATE `t_journal` SET"
201 .
" `bid` = '" . $this->
esc(
$bid) .
"'"
202 .
", `scd` = '" . $this->
esc($arg[
'scd']) .
"'"
203 .
", `ymd` = '" . $this->
esc($arg[
'ymd']) .
"'"
204 .
", `settled_flg` = '" . $this->
esc($arg[
'settled_flg']) .
"'"
205 .
", `not_use_flg` = '" . $this->
esc($arg[
'not_use_flg']) .
"'"
206 .
", `update_person` = '" . $_SESSION[
'minfo'][
'mid'] .
"'"
207 .
" WHERE `id` = '" . $this->
esc($arg[
'jid']) .
"'"
209 $ans = $this->
query($sql);
212 foreach ($arg[
'dat'] as $k => $d) {
214 if ($d[
'deb_name'] == -1 && $d[
'cre_name'] == -1) {
218 $kcd[] = $d[
'deb_name'];
219 $kcd[] = $d[
'cre_name'];
221 $amt = ($d[
'deb_amount'] > 0) ? $d[
'deb_amount'] : $d[
'cre_amount'];
222 $amt = str_replace(
',',
'', $amt);
224 $sql =
"INSERT INTO `t_jslip`"
225 .
" (`jid`, `line`, `debit`, `credit`, `amount`, `remark`, `update_person`)"
227 .
" ('" . $this->
esc($jid) .
"'"
228 .
", '" . $this->
esc($n) .
"'"
229 .
", '" . $this->
esc($d[
'deb_name']) .
"'"
230 .
", '" . $this->
esc($d[
'cre_name']) .
"'"
231 .
", '" . $this->
esc($amt) .
"'"
232 .
", '" . $this->
esc($d[
'remark']) .
"'"
233 .
", '" . $_SESSION[
'minfo'][
'mid'].
"'"
236 $ans = $this->
query($sql);
239 foreach ($kcd as $d) {
240 $sql =
"UPDATE `t_item` SET"
241 .
" `dummy` = '" . date(
'YmdJis') .
"'"
242 .
" WHERE `bid` = '" . $this->
esc(
$bid) .
"'"
243 .
" AND `kcd` = '" . $this->
esc($d) .
"'"
245 $ans = $this->
query($sql);
248 }
catch(Exception $e) {
249 $err = $e->getMessage();
267 $bid = $param[
'bid'];
268 $arg = $param[
'arg'];
275 $sql =
"INSERT INTO `t_journal`"
276 .
" (`bid`, `scd`, `ymd`, `settled_flg`, `not_use_flg`, `update_person`)"
278 .
" ('" . $this->
esc(
$bid) .
"'"
279 .
", '" . $this->
esc($arg[
'scd']) .
"'"
280 .
", '" . $this->
esc($arg[
'ymd']) .
"'"
281 .
", " . $this->
esc($arg[
'settled_flg'])
282 .
", " . $this->
esc($arg[
'not_use_flg'])
283 .
", '" . $_SESSION[
'minfo'][
'mid'].
"'"
286 $ans = $this->
query($sql);
290 foreach ($arg[
'dat'] as $k => $d) {
292 if ($d[
'deb_name'] == -1 && $d[
'cre_name'] == -1) {
296 $kcd[] = $d[
'deb_name'];
297 $kcd[] = $d[
'cre_name'];
299 $amt = ($d[
'deb_amount'] > 0) ? $d[
'deb_amount'] : $d[
'cre_amount'];
300 $amt = str_replace(
',',
'', $amt);
302 $sql =
"INSERT INTO `t_jslip`"
303 .
" (`jid`, `line`, `debit`, `credit`, `amount`, `remark`, `update_person`)"
305 .
" ('" . $this->
esc($jid) .
"'"
306 .
", '" . $this->
esc($n) .
"'"
307 .
", '" . $this->
esc($d[
'deb_name']) .
"'"
308 .
", '" . $this->
esc($d[
'cre_name']) .
"'"
309 .
", '" . $this->
esc($amt) .
"'"
310 .
", '" . $this->
esc($d[
'remark']) .
"'"
311 .
", '" . $_SESSION[
'minfo'][
'mid'].
"'"
314 $ans = $this->
query($sql);
317 foreach ($kcd as $d) {
318 $sql =
"UPDATE `t_item` SET"
319 .
" `dummy` = '" . date(
'YmdJis') .
"'"
320 .
" WHERE `bid` = '" . $this->
esc(
$bid) .
"'"
321 .
" AND `kcd` = '" . $this->
esc($d) .
"'"
323 $ans = $this->
query($sql);
326 }
catch(Exception $e) {
327 $err = $e->getMessage();
341 public function delete($param) {
344 $dno = $param[
'dno'];
351 $sql =
"DELETE FROM `t_jslip` WHERE `jid` = '" . $this->
esc($dno) .
"'";
352 $ans = $this->
query($sql);
354 $sql =
"DELETE FROM `t_journal` WHERE `id` = '" . $this->
esc($dno) .
"'";
355 $ans = $this->
query($sql);
357 }
catch(Exception $e) {
358 $err = $e->getMessage();
376 $sql =
"SELECT `r`.*"
377 .
" FROM `t_basic` `b`"
378 .
" INNER JOIN `c_round` `r` ON `b`.`round` = `r`.`c0`"
379 .
" WHERE `b`.`id` = '" . $this->
esc($id) .
"'"
385 return (empty($rec[0])) ? [] : $rec[0];
392 $sql =
"SELECT `rate`, `name` FROM `t_tax` WHERE `bid` = '1' AND `valid_flg` IS TRUE ORDER BY `rate`";