PageRenderTime 44ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/fwoq/core/ctls/bills.ctl.php

http://phpfor.googlecode.com/
PHP | 280 lines | 222 code | 46 blank | 12 comment | 31 complexity | 7cf2588939323f484cf8fed8c58bf52e MD5 | raw file
  1. <?php
  2. class bills_ctl extends pagecore{
  3. function _init(){
  4. $this->model = & loader::model('bills');
  5. }
  6. function index(){
  7. need_login('page');
  8. $search['desc'] = safe_convert($this->getRequest('sdesc'));
  9. $search['cate_id'] = intval($this->getRequest('cate'));
  10. $search['type'] = strval($this->getRequest('type'));
  11. $par['page'] = '[#page#]';
  12. if($search['type']){
  13. $par['type'] = $search['type'];
  14. }
  15. if($search['desc']){
  16. $par['desc'] = $search['desc'];
  17. }
  18. if($search['cate_id']!=''){
  19. $par['cate_id'] = $search['cate_id'];
  20. }
  21. $pageurl = site_link('bills','index',$par);
  22. if($search['desc'] || $search['tag']){
  23. $this->output->set('is_search',true);
  24. }else{
  25. $this->output->set('is_search',false);
  26. }
  27. //get page setting
  28. list($pageset,$page_setting_str) = get_page_setting('bills');
  29. //get sort setting
  30. $sort_setting = array(lang('create_time') => 'ct');
  31. list($sort,$sort_list) = get_sort_list($sort_setting,'bills','ct_desc');
  32. $page = intval($this->getGet('page','1'));
  33. $this->model->set_pageset($pageset);
  34. $bills = $this->model->get_all($page,$search,$sort);
  35. $counts = $this->model->get_count('sum(bill_money) as sum','type="income"');
  36. $this->output->set('sum_income',$counts['sum']);
  37. $counts = $this->model->get_count('sum(bill_money) as sum','type="payout"');
  38. $this->output->set('sum_payout',$counts['sum']);
  39. //var_dump($counts);exit;
  40. //$this->output->set('album_col_menu',$this->plugin->filter('album_col_menu',$page_setting_str.$sort_list));
  41. //$this->output->set('album_multi_opt',$this->plugin->filter('album_multi_opt',''));
  42. $this->output->set('bills',$bills['ls']);
  43. $page_obj =& loader::lib('page');
  44. $this->output->set('pagestr',$page_obj->fetch($bills['total'],$bills['current'],$pageurl));
  45. $this->output->set('total_num',$bills['count']);
  46. $this->output->set('search',arr_stripslashes($search));
  47. $title = '';
  48. //???
  49. $crumb_nav = array();
  50. $mdl_cate =& loader::model('category');
  51. $mdl_account =& loader::model('account');
  52. if($search['cate_id'] != ''){
  53. $crumb_nav = $mdl_cate->cate_path_link($search['cate_id']);
  54. foreach($crumb_nav as $b){
  55. $title = $b['name'].' &lt; '.$title;
  56. }
  57. }
  58. if($search['name']){
  59. $crumb_nav[] = array('name'=>lang('search_s',$search['name']));
  60. }
  61. $this->page_crumb($crumb_nav);
  62. //????
  63. $categorylist = $mdl_cate->get_categorys_width_cache();
  64. if($categorylist){
  65. $this->output->set('categorylist',$categorylist);
  66. foreach($categorylist as $v){
  67. $bills_cate[$v['id']] = $v['name'];
  68. }
  69. $this->output->set('bills_cate',$bills_cate);
  70. }
  71. $accountlist = $mdl_account->get_accounts_width_cache();
  72. if($accountlist){
  73. $this->output->set('accountlist',$accountlist);
  74. foreach($accountlist as $v){
  75. $bills_account[$v['id']] = $v['name'];
  76. }
  77. $this->output->set('bills_account',$bills_account);
  78. }
  79. /*??????????*/
  80. /*foreach($bills['ls'] as $v){
  81. $u_search['id'][] = $v['user_id'];
  82. }*/
  83. $users = $this->user->get_all(null,$u_search);
  84. foreach($users as $v){
  85. $users[$v['id']] = $v['user_name'];
  86. }
  87. $this->output->set('users',$users);
  88. //page head
  89. $page_title = $title.$this->setting->get_conf('site.title');
  90. $page_keywords = $this->setting->get_conf('site.keywords');
  91. $page_description = $this->setting->get_conf('site.description');
  92. $this->page_init($page_title,$page_keywords,$page_description);
  93. $this->render();
  94. }
  95. function create(){
  96. need_login('ajax_page');
  97. $type = strval($this->getGet('type'));
  98. $this->output->set('type',$type);
  99. $from = $this->getGet('from');
  100. if($from){
  101. $from = base64_decode($from);
  102. }
  103. $this->output->set('pid',intval($this->getGet('pid')));
  104. $this->output->set('from',$from);
  105. $this->mdl_cate = & loader::model('category');
  106. $cate_list = $this->mdl_cate->get_categorys_width_cache();
  107. $this->output->set('cate_list',$cate_list);
  108. $this->mdl_account = & loader::model('account');
  109. $accountlist = $this->mdl_account->get_flat_account();
  110. $this->output->set('accountlist',$accountlist);
  111. $cate_types = array('payout'=>'??','income'=>'??');
  112. $this->output->set('cate_types',$cate_types);
  113. $this->render();
  114. }
  115. function save(){
  116. need_login('ajax');
  117. $from = $this->getPost('from');
  118. $data['cate_id'] = intval($this->getPost('cate_id'));
  119. $data['account_id'] = intval($this->getPost('account_id'));
  120. $data['bill_time'] = strtotime($this->getPost('bill_time'));
  121. $data['desc'] = safe_convert($this->getPost('desc'));
  122. $data['type'] = $this->getPost('type');
  123. $data['user_id'] = $this->user->uinfo['id'];
  124. $data['bill_money'] = floatval(abs($this->getPost('bill_money')));
  125. $data['create_time'] = time();
  126. if($data['bill_money'] < 0 ){
  127. form_ajax_failed('text',lang('money must not less than 0!'));
  128. }
  129. if(strlen($data['desc']) == 0 ){
  130. form_ajax_failed('text',lang('please enter description!'));
  131. }
  132. if(($id = $this->model->save($data)) == true ){
  133. $mdl_account = & loader::model('account');
  134. $mdl_account->modify_account($data['account_id'],$data['bill_money'],$data['type']); // ??????
  135. if($from){
  136. form_ajax_success('box',lang('create_category_succ').'<script>setTimeout(function(){ Mui.box.show("'.$from.'",true); },1000)</script>');
  137. }else{
  138. form_ajax_success('box',lang('create_category_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
  139. }
  140. }else{
  141. form_ajax_failed('text',lang('create_category_fail'));
  142. }
  143. }
  144. function edit(){
  145. need_login('ajax_page');
  146. $id = intval($this->getGet('id'));
  147. $info = $this->model->get_info($id);
  148. $mdl_cate = & loader::model('category');
  149. $cate_list = $mdl_cate->get_categorys_width_cache();
  150. $this->output->set('cate_list',$cate_list);
  151. $mdl_account = & loader::model('account');
  152. $accountlist = $mdl_account->get_flat_account();
  153. $this->output->set('accountlist',$accountlist);
  154. $info['bill_time'] = date('Y-m-d',$info['bill_time']);
  155. $this->output->set('info',$info);
  156. $this->render();
  157. }
  158. function update(){
  159. need_login('ajax');
  160. $id = intval($this->getGet('id'));
  161. $info = $this->model->get_info($id);
  162. $data['cate_id'] = intval($this->getPost('cate_id'));
  163. $data['account_id'] = intval($this->getPost('account_id'));
  164. $data['bill_time'] = strtotime($this->getPost('bill_time'));
  165. $data['desc'] = safe_convert($this->getPost('desc'));
  166. $data['type'] = $this->getPost('type');
  167. $data['bill_money'] = floatval(abs($this->getPost('bill_money')));
  168. if($data['bill_money'] < 0 ){
  169. form_ajax_failed('text',lang('money must not less than 0!'));
  170. }
  171. if($data['account_id'] < 1){
  172. form_ajax_failed('text',lang('please choose an account!'));
  173. }
  174. if($this->model->update($id,$data)){
  175. $mdl_account = & loader::model('account');
  176. if($info['account_id'] == $data['account_id']){
  177. if($info['type'] == 'income'){
  178. $info['bill_money'] = -$info['bill_money'];
  179. }
  180. if($data['type'] == 'payout'){
  181. $data['bill_money'] = -$data['bill_money'];
  182. }
  183. $changge_money = $data['bill_money']+$info['bill_money'];
  184. $type = ($changge_money > 0)?'income':'payout';
  185. $mdl_account->modify_account($data['account_id'],abs($changge_money),$type);
  186. }else{// ?????????????
  187. $type = ($info['type'] == 'payout')?'income':'payout'; // ?????????????
  188. $mdl_account->modify_account($info['account_id'],abs($info['bill_money']),$type);
  189. $mdl_account->modify_account($data['account_id'],abs($data['bill_money']),$data['type']);
  190. }
  191. if($from){
  192. form_ajax_success('box',lang('create_category_succ').'<script>setTimeout(function(){ Mui.box.show("'.$from.'",true); },1000)</script>');
  193. }else{
  194. form_ajax_success('box',lang('create_category_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
  195. }
  196. }else{
  197. form_ajax_failed('text',lang('create_category_fail'));
  198. }
  199. }
  200. function confirm_cancel(){
  201. need_login('ajax_page');
  202. $id = intval($this->getGet('id'));
  203. $this->output->set('id',$id);
  204. $this->render();
  205. }
  206. function cancel(){
  207. need_login('ajax_page');
  208. $id = intval($this->getGet('id'));
  209. if($this->model->set_status($id,'cancel')){
  210. $info = $this->model->get_info($id);
  211. $type = ($info['type'] == 'payout')?'income':'payout'; // ?????????????
  212. $mdl_account = & loader::model('account');
  213. $mdl_account->modify_account($info['account_id'],abs($info['bill_money']),$type);
  214. ajax_box(lang('modify_success'),null,0.5,$_SERVER['HTTP_REFERER']);
  215. }else{
  216. ajax_box(lang('modify_failed'));
  217. }
  218. }
  219. function confirm_delete(){
  220. need_login('ajax_page');
  221. $id = intval($this->getGet('id'));
  222. $this->output->set('id',$id);
  223. $this->render();
  224. }
  225. function delete(){
  226. need_login('ajax_page');
  227. $id = intval($this->getGet('id'));
  228. if($this->model->trash($id)){
  229. ajax_box(lang('delete_cate_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
  230. }else{
  231. ajax_box(lang('delete_cate_fail'));
  232. }
  233. }
  234. }