/fwoq/core/ctls/bills.ctl.php
PHP | 280 lines | 222 code | 46 blank | 12 comment | 31 complexity | 7cf2588939323f484cf8fed8c58bf52e MD5 | raw file
- <?php
- class bills_ctl extends pagecore{
-
- function _init(){
- $this->model = & loader::model('bills');
- }
-
- function index(){
- need_login('page');
- $search['desc'] = safe_convert($this->getRequest('sdesc'));
- $search['cate_id'] = intval($this->getRequest('cate'));
- $search['type'] = strval($this->getRequest('type'));
- $par['page'] = '[#page#]';
- if($search['type']){
- $par['type'] = $search['type'];
- }
- if($search['desc']){
- $par['desc'] = $search['desc'];
- }
- if($search['cate_id']!=''){
- $par['cate_id'] = $search['cate_id'];
- }
- $pageurl = site_link('bills','index',$par);
-
- if($search['desc'] || $search['tag']){
- $this->output->set('is_search',true);
- }else{
- $this->output->set('is_search',false);
- }
-
- //get page setting
- list($pageset,$page_setting_str) = get_page_setting('bills');
- //get sort setting
- $sort_setting = array(lang('create_time') => 'ct');
- list($sort,$sort_list) = get_sort_list($sort_setting,'bills','ct_desc');
-
- $page = intval($this->getGet('page','1'));
- $this->model->set_pageset($pageset);
- $bills = $this->model->get_all($page,$search,$sort);
-
- $counts = $this->model->get_count('sum(bill_money) as sum','type="income"');
- $this->output->set('sum_income',$counts['sum']);
- $counts = $this->model->get_count('sum(bill_money) as sum','type="payout"');
- $this->output->set('sum_payout',$counts['sum']);
- //var_dump($counts);exit;
-
- //$this->output->set('album_col_menu',$this->plugin->filter('album_col_menu',$page_setting_str.$sort_list));
- //$this->output->set('album_multi_opt',$this->plugin->filter('album_multi_opt',''));
- $this->output->set('bills',$bills['ls']);
- $page_obj =& loader::lib('page');
- $this->output->set('pagestr',$page_obj->fetch($bills['total'],$bills['current'],$pageurl));
- $this->output->set('total_num',$bills['count']);
- $this->output->set('search',arr_stripslashes($search));
- $title = '';
- //???
- $crumb_nav = array();
- $mdl_cate =& loader::model('category');
- $mdl_account =& loader::model('account');
- if($search['cate_id'] != ''){
- $crumb_nav = $mdl_cate->cate_path_link($search['cate_id']);
- foreach($crumb_nav as $b){
- $title = $b['name'].' < '.$title;
- }
- }
- if($search['name']){
- $crumb_nav[] = array('name'=>lang('search_s',$search['name']));
- }
-
- $this->page_crumb($crumb_nav);
- //????
- $categorylist = $mdl_cate->get_categorys_width_cache();
- if($categorylist){
- $this->output->set('categorylist',$categorylist);
- foreach($categorylist as $v){
- $bills_cate[$v['id']] = $v['name'];
- }
- $this->output->set('bills_cate',$bills_cate);
- }
- $accountlist = $mdl_account->get_accounts_width_cache();
- if($accountlist){
- $this->output->set('accountlist',$accountlist);
- foreach($accountlist as $v){
- $bills_account[$v['id']] = $v['name'];
- }
- $this->output->set('bills_account',$bills_account);
- }
-
- /*??????????*/
- /*foreach($bills['ls'] as $v){
- $u_search['id'][] = $v['user_id'];
- }*/
- $users = $this->user->get_all(null,$u_search);
- foreach($users as $v){
- $users[$v['id']] = $v['user_name'];
- }
- $this->output->set('users',$users);
- //page head
- $page_title = $title.$this->setting->get_conf('site.title');
- $page_keywords = $this->setting->get_conf('site.keywords');
- $page_description = $this->setting->get_conf('site.description');
-
- $this->page_init($page_title,$page_keywords,$page_description);
- $this->render();
- }
-
- function create(){
- need_login('ajax_page');
- $type = strval($this->getGet('type'));
- $this->output->set('type',$type);
- $from = $this->getGet('from');
- if($from){
- $from = base64_decode($from);
- }
- $this->output->set('pid',intval($this->getGet('pid')));
- $this->output->set('from',$from);
-
- $this->mdl_cate = & loader::model('category');
- $cate_list = $this->mdl_cate->get_categorys_width_cache();
- $this->output->set('cate_list',$cate_list);
-
- $this->mdl_account = & loader::model('account');
- $accountlist = $this->mdl_account->get_flat_account();
- $this->output->set('accountlist',$accountlist);
-
- $cate_types = array('payout'=>'??','income'=>'??');
- $this->output->set('cate_types',$cate_types);
-
- $this->render();
- }
- function save(){
- need_login('ajax');
- $from = $this->getPost('from');
- $data['cate_id'] = intval($this->getPost('cate_id'));
- $data['account_id'] = intval($this->getPost('account_id'));
- $data['bill_time'] = strtotime($this->getPost('bill_time'));
- $data['desc'] = safe_convert($this->getPost('desc'));
-
- $data['type'] = $this->getPost('type');
-
- $data['user_id'] = $this->user->uinfo['id'];
- $data['bill_money'] = floatval(abs($this->getPost('bill_money')));
- $data['create_time'] = time();
- if($data['bill_money'] < 0 ){
- form_ajax_failed('text',lang('money must not less than 0!'));
- }
-
- if(strlen($data['desc']) == 0 ){
- form_ajax_failed('text',lang('please enter description!'));
- }
-
-
- if(($id = $this->model->save($data)) == true ){
- $mdl_account = & loader::model('account');
- $mdl_account->modify_account($data['account_id'],$data['bill_money'],$data['type']); // ??????
- if($from){
- form_ajax_success('box',lang('create_category_succ').'<script>setTimeout(function(){ Mui.box.show("'.$from.'",true); },1000)</script>');
- }else{
- form_ajax_success('box',lang('create_category_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
- }
- }else{
- form_ajax_failed('text',lang('create_category_fail'));
- }
- }
- function edit(){
- need_login('ajax_page');
- $id = intval($this->getGet('id'));
-
- $info = $this->model->get_info($id);
- $mdl_cate = & loader::model('category');
- $cate_list = $mdl_cate->get_categorys_width_cache();
- $this->output->set('cate_list',$cate_list);
- $mdl_account = & loader::model('account');
- $accountlist = $mdl_account->get_flat_account();
- $this->output->set('accountlist',$accountlist);
-
-
- $info['bill_time'] = date('Y-m-d',$info['bill_time']);
- $this->output->set('info',$info);
- $this->render();
- }
-
- function update(){
- need_login('ajax');
- $id = intval($this->getGet('id'));
- $info = $this->model->get_info($id);
-
- $data['cate_id'] = intval($this->getPost('cate_id'));
- $data['account_id'] = intval($this->getPost('account_id'));
- $data['bill_time'] = strtotime($this->getPost('bill_time'));
- $data['desc'] = safe_convert($this->getPost('desc'));
- $data['type'] = $this->getPost('type');
- $data['bill_money'] = floatval(abs($this->getPost('bill_money')));
- if($data['bill_money'] < 0 ){
- form_ajax_failed('text',lang('money must not less than 0!'));
- }
- if($data['account_id'] < 1){
- form_ajax_failed('text',lang('please choose an account!'));
- }
- if($this->model->update($id,$data)){
- $mdl_account = & loader::model('account');
- if($info['account_id'] == $data['account_id']){
- if($info['type'] == 'income'){
- $info['bill_money'] = -$info['bill_money'];
- }
- if($data['type'] == 'payout'){
- $data['bill_money'] = -$data['bill_money'];
- }
-
- $changge_money = $data['bill_money']+$info['bill_money'];
- $type = ($changge_money > 0)?'income':'payout';
- $mdl_account->modify_account($data['account_id'],abs($changge_money),$type);
- }else{// ?????????????
- $type = ($info['type'] == 'payout')?'income':'payout'; // ?????????????
- $mdl_account->modify_account($info['account_id'],abs($info['bill_money']),$type);
-
- $mdl_account->modify_account($data['account_id'],abs($data['bill_money']),$data['type']);
- }
-
- if($from){
- form_ajax_success('box',lang('create_category_succ').'<script>setTimeout(function(){ Mui.box.show("'.$from.'",true); },1000)</script>');
- }else{
- form_ajax_success('box',lang('create_category_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
- }
- }else{
- form_ajax_failed('text',lang('create_category_fail'));
- }
- }
-
- function confirm_cancel(){
- need_login('ajax_page');
- $id = intval($this->getGet('id'));
- $this->output->set('id',$id);
- $this->render();
- }
- function cancel(){
- need_login('ajax_page');
- $id = intval($this->getGet('id'));
- if($this->model->set_status($id,'cancel')){
- $info = $this->model->get_info($id);
- $type = ($info['type'] == 'payout')?'income':'payout'; // ?????????????
- $mdl_account = & loader::model('account');
- $mdl_account->modify_account($info['account_id'],abs($info['bill_money']),$type);
- ajax_box(lang('modify_success'),null,0.5,$_SERVER['HTTP_REFERER']);
- }else{
- ajax_box(lang('modify_failed'));
- }
- }
- function confirm_delete(){
- need_login('ajax_page');
- $id = intval($this->getGet('id'));
- $this->output->set('id',$id);
- $this->render();
- }
- function delete(){
- need_login('ajax_page');
- $id = intval($this->getGet('id'));
-
- if($this->model->trash($id)){
- ajax_box(lang('delete_cate_succ'),null,0.5,$_SERVER['HTTP_REFERER']);
- }else{
- ajax_box(lang('delete_cate_fail'));
- }
- }
-
- }