Changeset 586


Ignore:
Timestamp:
Nov 20, 2014 4:49:30 PM (10 years ago)
Author:
quyenla
Message:

HOME

Location:
pro-violet-viettel/sourcecode/application/modules/admin
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/admin/controllers/home.php

    r424 r586  
    1515                if ($admin_info)
    1616                {
    17                         $this->load->view('index');
     17                        $data['statistics'] = $this->getStatistics();
     18            $data['content']="";
     19            $this->load->view('home/index', $data);
    1820                }else
    1921                {
     
    2123                }
    2224        }
     25         public function getStatistics() {
     26        $data = array();
     27
     28        $last_month['start'] = strtotime(date("Y-m-d", strtotime("first day of previous month")) . " 00:00:00");
     29        $last_month['end'] = strtotime(date("Y-m-d", strtotime("last day of previous month")) . " 23:59:59");
     30
     31        $last_week['start'] = strtotime(date("Y-m-d", strtotime("first day of previous week")) . " 00:00:00");
     32        $last_week['end'] = strtotime(date("Y-m-d", strtotime("last day of previous week")) . " 23:59:59");
     33
     34        $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
     35        $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
     36
     37        $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
     38        $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
     39
     40
     41
     42        $last_quarter = $this->getLastquarter();
     43        $last_quarter['start'] = $last_quarter['start'];
     44        $last_quarter['end'] = $last_quarter['end'];
     45
     46
     47        $this->load->model('paidlog_model');
     48        $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
     49
     50        $revenue['last_week'] = 0;
     51        $revenue['last_month'] = 0;
     52        $revenue['last_quarter'] = 0;
     53        $revenue['last_year'] = 0;
     54
     55        $lastmonth = strtotime("first day of previous month");
     56        $thismonth = strtotime("first day of this month");
     57        $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
     58        $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
     59       
     60        $top['last_month']['user']=0;
     61        $top['last_month']['sms']=0;
     62        $top['last_month']['card']=0;
     63        $top['last_month']['collaborator']=0;
     64        $top['this_month']['user']=0;
     65        $top['this_month']['sms']=0;
     66        $top['this_month']['card']=0;
     67        $top['this_month']['collaborator']=0;
     68        foreach ($paidlogs as $paidlog) {
     69
     70           
     71            if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
     72                $revenue['last_week']+=$paidlog['amount'];
     73            }
     74            if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
     75                $revenue['last_month']+=$paidlog['amount'];
     76            }
     77            if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
     78                $revenue['last_quarter']+=$paidlog['amount'];
     79            }
     80            if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
     81                $revenue['last_year']+=$paidlog['amount'];
     82            }
     83           
     84           
     85            if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
     86                $charts['last_month'][0]+=$paidlog['amount'];
     87            }
     88            if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
     89                $charts['last_month'][1]+=$paidlog['amount'];
     90            }
     91            if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
     92                $charts['last_month'][2]+=$paidlog['amount'];
     93            }
     94            if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
     95                $charts['last_month'][3]+=$paidlog['amount'];
     96            }
     97            if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
     98                $charts['last_month'][4]+=$paidlog['amount'];
     99            }
     100           
     101            if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth)) {
     102                $top['last_month']['user']++;
     103                if ($paidlog['paid_type']==1)
     104                {
     105                   $top['last_month']['sms']+=$paidlog['amount'];
     106                }
     107                if ($paidlog['paid_type']==2)
     108                {
     109                    $top['last_month']['card']+=$paidlog['amount'];
     110                }
     111                if ($paidlog['collaborator']!="")
     112                {
     113                    $top['last_month']['collaborator']+=$paidlog['amount'];
     114                }
     115            }
     116           
     117           
     118
     119            if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
     120                $charts['this_month'][0]+=$paidlog['amount'];
     121            }
     122            if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
     123                $charts['this_month'][1]+=$paidlog['amount'];
     124            }
     125            if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
     126                $charts['this_month'][2]+=$paidlog['amount'];
     127            }
     128            if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
     129                $charts['this_month'][3]+=$paidlog['amount'];
     130            }
     131            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
     132                $charts['this_month'][4]+=$paidlog['amount'];
     133            }
     134            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth )) {
     135                $top['this_month']['user']++;
     136                if ($paidlog['paid_type']==1)
     137                {
     138                   $top['this_month']['sms']+=$paidlog['amount'];
     139                }
     140                if ($paidlog['paid_type']==2)
     141                {
     142                    $top['this_month']['card']+=$paidlog['amount'];
     143                }
     144                if ($paidlog['collaborator']!="")
     145                {
     146                    $top['this_month']['collaborator']+=$paidlog['amount'];
     147                }
     148            }
     149        }
     150        $percent=array();
     151        foreach ($top['this_month'] as $index=>$value)
     152        {
     153            $percent[$index]['class']="down";
     154            $percent[$index]['display']="giảm";
     155            $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
     156            if ($top['this_month'][$index] > $top['last_month'][$index])
     157            {
     158               $percent[$index]['class']="up";
     159               $percent[$index]['display']="tăng";
     160            }
     161        }
     162        $data['percent']=$percent;
     163        $data['top']=$top;
     164        $max = 0;
     165        foreach ($charts['last_month'] as $index => $total) {
     166            if ($total > $max) {
     167                $max = $total;
     168            }
     169            $chart_last_month[] = array($index, $total);
     170        }
     171        foreach ($charts['this_month'] as $index => $total) {
     172            if ($total > $max) {
     173                $max = $total;
     174            }
     175            $chart_this_month[] = array($index, $total);
     176        }
     177
     178        $data['revenue'] = $revenue;
     179        $data['max'] = $max;
     180        $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
     181        $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
     182
     183        $data['chard'] = $chard;
     184
     185        return $this->load->view('home/statistics', $data, true);
     186    }
     187    public function getLastquarter() {
     188        $current_month = date('m');
     189        $current_year = date('Y');
     190
     191        if ($current_month >= 1 && $current_month <= 3) {
     192            $start_date = strtotime('1-October-' . ($current_year - 1));  // timestamp or 1-October Last Year 12:00:00 AM
     193            $end_date = strtotime('1-Janauary-' . $current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
     194        } else if ($current_month >= 4 && $current_month <= 6) {
     195            $start_date = strtotime('1-January-' . $current_year);  // timestamp or 1-Janauray 12:00:00 AM
     196            $end_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
     197        } else if ($current_month >= 7 && $current_month <= 9) {
     198            $start_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM
     199            $end_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
     200        } else if ($current_month >= 10 && $current_month <= 12) {
     201            $start_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM
     202            $end_date = strtotime('1-October-' . $current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
     203        }
     204        return array("start" => $start_date, "end" => $end_date);
     205    }
     206
    23207       
    24208        public function login()
  • pro-violet-viettel/sourcecode/application/modules/admin/controllers/report.php

    r503 r586  
    5959        $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    6060        $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
     61
    6162        foreach ($paidlogs as $paidlog) {
    6263
     
    7374                $revenue['last_year']+=$paidlog['amount'];
    7475            }
     76           
     77           
    7578            if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
    7679                $charts['last_month'][0]+=$paidlog['amount'];
     
    8689            }
    8790            if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
    88                 $charts['last_month'][3]+=$paidlog['amount'];
    89             }
     91                $charts['last_month'][4]+=$paidlog['amount'];
     92            }
     93           
    9094
    9195            if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
     
    102106            }
    103107            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
    104                 $charts['this_month'][3]+=$paidlog['amount'];
    105             }
     108                $charts['this_month'][4]+=$paidlog['amount'];
     109            }
     110           
    106111        }
    107112        $max = 0;
  • pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php

    r444 r586  
    5757        // get all paidlogs from the last years until now
    5858        $from = date("Y-m-d 00:00:00",$from);
    59         $sql="SELECT * FROM ".$this->table_name." WHERE paid_time > '".$from."'";
     59        $sql="SELECT * FROM ".$this->table_name." INNER JOIN tbluser ON tbluser.us_id = ".$this->table_name.".us_id WHERE ".$this->table_name.".paid_time > '".$from."'";
    6060        $result = $this->db->query($sql)->result_array();
    6161        foreach ($result as $index=>$paidlog)
Note: See TracChangeset for help on using the changeset viewer.