Ignore:
Timestamp:
Nov 21, 2014 10:35:14 AM (11 years ago)
Author:
quyenla
Message:
 
File:
1 edited

Legend:

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

    r586 r594  
    2626
    2727    public function getStatistics() {
    28         $data = array();
    29 
    30         $last_month['start'] = strtotime(date("Y-m-d", strtotime("first day of previous month")) . " 00:00:00");
    31         $last_month['end'] = strtotime(date("Y-m-d", strtotime("last day of previous month")) . " 23:59:59");
    32 
    33         $last_week['start'] = strtotime(date("Y-m-d", strtotime("first day of previous week")) . " 00:00:00");
    34         $last_week['end'] = strtotime(date("Y-m-d", strtotime("last day of previous week")) . " 23:59:59");
    35 
    36         $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
    37         $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
    38 
    39         $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
    40         $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
    41 
    42 
    43 
    44         $last_quarter = $this->getLastquarter();
    45         $last_quarter['start'] = $last_quarter['start'];
    46         $last_quarter['end'] = $last_quarter['end'];
    47 
    48 
    49         $this->load->model('paidlog_model');
    50         $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
    51 
    52         $revenue['last_week'] = 0;
    53         $revenue['last_month'] = 0;
    54         $revenue['last_quarter'] = 0;
    55         $revenue['last_year'] = 0;
    56 
    57         $lastmonth = strtotime("first day of previous month");
    58         $thismonth = strtotime("first day of this month");
    59         $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    60         $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    61 
    62         foreach ($paidlogs as $paidlog) {
    63 
    64             if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
    65                 $revenue['last_week']+=$paidlog['amount'];
    66             }
    67             if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
    68                 $revenue['last_month']+=$paidlog['amount'];
    69             }
    70             if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
    71                 $revenue['last_quarter']+=$paidlog['amount'];
    72             }
    73             if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
    74                 $revenue['last_year']+=$paidlog['amount'];
    75             }
    76            
    77            
    78             if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
    79                 $charts['last_month'][0]+=$paidlog['amount'];
    80             }
    81             if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
    82                 $charts['last_month'][1]+=$paidlog['amount'];
    83             }
    84             if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
    85                 $charts['last_month'][2]+=$paidlog['amount'];
    86             }
    87             if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
    88                 $charts['last_month'][3]+=$paidlog['amount'];
    89             }
    90             if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
    91                 $charts['last_month'][4]+=$paidlog['amount'];
    92             }
    93            
    94 
    95             if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
    96                 $charts['this_month'][0]+=$paidlog['amount'];
    97             }
    98             if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
    99                 $charts['this_month'][1]+=$paidlog['amount'];
    100             }
    101             if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
    102                 $charts['this_month'][2]+=$paidlog['amount'];
    103             }
    104             if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
    105                 $charts['this_month'][3]+=$paidlog['amount'];
    106             }
    107             if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
    108                 $charts['this_month'][4]+=$paidlog['amount'];
    109             }
    110            
    111         }
    112         $max = 0;
    113         foreach ($charts['last_month'] as $index => $total) {
    114             if ($total > $max) {
    115                 $max = $total;
    116             }
    117             $chart_last_month[] = array($index, $total);
    118         }
    119         foreach ($charts['this_month'] as $index => $total) {
    120             if ($total > $max) {
    121                 $max = $total;
    122             }
    123             $chart_this_month[] = array($index, $total);
    124         }
    125 
    126         $data['revenue'] = $revenue;
    127         $data['max'] = $max;
    128         $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
    129         $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
    130         $data['chard'] = $chard;
    131 
     28        $this->load->model('collabolator_model');
     29        $data = $this->collabolator_model->getStatistics();
    13230        return $this->load->view('report/statistics', $data, true);
    13331    }
    13432
    135     public function getLastquarter() {
    136         $current_month = date('m');
    137         $current_year = date('Y');
    138 
    139         if ($current_month >= 1 && $current_month <= 3) {
    140             $start_date = strtotime('1-October-' . ($current_year - 1));  // timestamp or 1-October Last Year 12:00:00 AM
    141             $end_date = strtotime('1-Janauary-' . $current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
    142         } else if ($current_month >= 4 && $current_month <= 6) {
    143             $start_date = strtotime('1-January-' . $current_year);  // timestamp or 1-Janauray 12:00:00 AM
    144             $end_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
    145         } else if ($current_month >= 7 && $current_month <= 9) {
    146             $start_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM
    147             $end_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
    148         } else if ($current_month >= 10 && $current_month <= 12) {
    149             $start_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM
    150             $end_date = strtotime('1-October-' . $current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
    151         }
    152         return array("start" => $start_date, "end" => $end_date);
    153     }
    15433
    15534    public function getPaidlogs($filters = array()) {
Note: See TracChangeset for help on using the changeset viewer.