01.
<?php
02.
if
( ! defined(
'BASEPATH'
))
exit
(
'No direct script access allowed'
);
03.
class
Ledger
extends
CI_Controller {
04.
private
$ss
;
05.
public
function
index(){
06.
$this
->load->library(
'session'
);
07.
$this
->ss=(
array
)
$this
->session->userdata(
'profile'
);
08.
if
(!isset(
$ss
[
'id'
]))
exit
(
'No found session id '
);
09.
if
(!isset(
$_REQUEST
[
'run'
]))
exit
(
'No found request run'
);
10.
$rq
=
$_REQUEST
;
11.
switch
(
$rq
[
'run'
]){
12.
case
'save_main'
:
$this
->save_main(
$rq
);
break
;
13.
case
'save_group'
:
$this
->save_group(
$rq
);
break
;
14.
case
'save_ledger'
:
$this
->save_ledger(
$rq
);
break
;
15.
case
'test'
:
echo
'TEST'
;
16.
}
17.
}
18.
private
function
save_main(
$rq
){
19.
if
(
$rq
[
'm_id'
]!==
'insert'
){
20.
$id
=
intval
(
$rq
[
'm_id'
]);
$where
=
"m_id = $id"
;
21.
$str
=
$this
->db->update_string(
'acc_ledger_main'
,
$rq
[
'ro'
],
$where
);
22.
$this
->db->query(
$str
);
23.
}
else
{
24.
$ro
=
$rq
[
'ro'
];
25.
if
(
$ro
[
'main_id'
]>
''
){
26.
$ro
[
'user_id'
]=
$this
->ss[
'id'
];
27.
$str
=
$this
->db->insert_string(
'acc_ledger_main'
,
$ro
);
28.
$this
->db->query(
$str
);
29.
}
else
{
30.
$str
=
'INSERT INTO acc_ledger_main '
.
31.
'SELECT null, ?, max(main_id) + 1, ? , ? '
.
32.
'FROM acc_ledger_main where user_id='
.
$ss
[
'id'
];
33.
$this
->db->query(
$str
,
array
(
$this
->ss[
'id'
],
$ro
[
'main_name'
],
$ro
[
'main_is_cr'
]));
34.
}
35.
$id
=
$this
->db->insert_id();
36.
}
37.
$rs
=
$this
->db->query(
'select * from acc_ledger_main where m_id='
.
$id
);
38.
$row
=
$rs
->result_array();
39.
echo
json_encode(
array
(
'type'
=>
'complete'
,
'id'
=>
$id
,
'str'
=>
$str
,
'ro'
=>
$row
[0] ) );
40.
}
41.
private
function
save_group(
$rq
){
42.
if
(
$rq
[
'id'
]!==
'insert'
){
43.
$id
=
intval
(
$rq
[
'id'
]);
44.
$where
=
"g_id = $id"
;
45.
$str
=
$this
->db->update_string(
'acc_ledger_grouup'
,
$rq
[
'ro'
],
$where
);
46.
$this
->db->query(
$str
);
47.
}
else
{
48.
$str
=
$this
->db->insert_string(
'acc_ledger_grouup'
,
$rq
[
'ro'
] );
49.
$this
->db->query(
$str
);
$id
=
$this
->db->insert_id();
50.
}
51.
echo
json_encode(
array
(
'type'
=>
'complete'
,
'id'
=>
$id
,
'str'
=>
$str
) );
52.
}
53.
private
function
save_ledger(
$rq
){
54.
if
(
$rq
[
'id'
]!==
'insert'
){
55.
$id
=
intval
(
$rq
[
'id'
]);
56.
$where
=
"id = $id"
;
57.
$str
=
$this
->db->update_string(
'acc_ledger'
,
$rq
[
'ro'
],
$where
);
58.
$this
->db->query(
$str
);
59.
}
else
{
60.
$str
=
$this
->db->insert_string(
'acc_ledger'
,
$rq
[
'ro'
] );
61.
$this
->db->query(
$str
);
$id
=
$this
->db->insert_id();
62.
}
63.
echo
json_encode(
array
(
'type'
=>
'complete'
,
'id'
=>
$id
,
'str'
=>
$str
) );
64.
}
65.
}
66.
?>