Ignore:
Timestamp:
Nov 21, 2014 10:35:14 AM (10 years ago)
Author:
quyenla
Message:
 
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

    r590 r594  
    1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     1<?php
    22
    3 class Home extends MX_Controller
    4 {
    5         public function __construct()
    6         {
    7                 parent::__construct();
    8                 $this->load->helper('cookie');
    9         }
    10        
    11         public function index ()
    12         {         
    13                 $admin_info = $this->session->userdata('adminInfo');
    14                 if ($admin_info)
    15                 {
    16                         $data['statistics'] = $this->getStatistics();
    17             $data['content']="";
     3if (!defined('BASEPATH'))
     4    exit('No direct script access allowed');
     5
     6class Home extends MX_Controller {
     7
     8    public function __construct() {
     9        parent::__construct();
     10        $this->load->helper('cookie');
     11    }
     12
     13    public function index() {
     14        $admin_info = $this->session->userdata('adminInfo');
     15        if ($admin_info) {
     16            $data['statistics'] = $this->getStatistics();
     17            $data['content'] = "";
    1818            $this->load->view('home/index', $data);
    19                 }else
    20                 {
    21                         $this->load->view ( 'login');
    22                 }
    23         }
    24          public function getStatistics() {
    25         $data = array();
     19        } else {
     20            $this->load->view('login');
     21        }
     22    }
    2623
    27         $last_month['start'] = strtotime(date("Y-m-d", strtotime("first day of previous month")) . " 00:00:00");
    28         $last_month['end'] = strtotime(date("Y-m-d", strtotime("last day of previous month")) . " 23:59:59");
    29 
    30         $last_week['start'] = strtotime(date("Y-m-d", strtotime("first day of previous week")) . " 00:00:00");
    31         $last_week['end'] = strtotime(date("Y-m-d", strtotime("last day of previous week")) . " 23:59:59");
    32 
    33         $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
    34         $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
    35 
    36         $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
    37         $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
    38 
    39 
    40 
    41         $last_quarter = $this->getLastquarter();
    42         $last_quarter['start'] = $last_quarter['start'];
    43         $last_quarter['end'] = $last_quarter['end'];
    44 
    45 
    46         $this->load->model('paidlog_model');
    47         $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
    48 
    49         $revenue['last_week'] = 0;
    50         $revenue['last_month'] = 0;
    51         $revenue['last_quarter'] = 0;
    52         $revenue['last_year'] = 0;
    53 
    54         $lastmonth = strtotime("first day of previous month");
    55         $thismonth = strtotime("first day of this month");
    56         $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    57         $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
    58        
    59         $top['last_month']['user']=0;
    60         $top['last_month']['sms']=0;
    61         $top['last_month']['card']=0;
    62         $top['last_month']['collaborator']=0;
    63         $top['this_month']['user']=0;
    64         $top['this_month']['sms']=0;
    65         $top['this_month']['card']=0;
    66         $top['this_month']['collaborator']=0;
    67         foreach ($paidlogs as $paidlog) {
    68 
    69            
    70             if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
    71                 $revenue['last_week']+=$paidlog['amount'];
    72             }
    73             if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
    74                 $revenue['last_month']+=$paidlog['amount'];
    75             }
    76             if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
    77                 $revenue['last_quarter']+=$paidlog['amount'];
    78             }
    79             if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
    80                 $revenue['last_year']+=$paidlog['amount'];
    81             }
    82            
    83            
    84             if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
    85                 $charts['last_month'][0]+=$paidlog['amount'];
    86             }
    87             if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
    88                 $charts['last_month'][1]+=$paidlog['amount'];
    89             }
    90             if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
    91                 $charts['last_month'][2]+=$paidlog['amount'];
    92             }
    93             if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
    94                 $charts['last_month'][3]+=$paidlog['amount'];
    95             }
    96             if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
    97                 $charts['last_month'][4]+=$paidlog['amount'];
    98             }
    99            
    100             if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth)) {
    101                 $top['last_month']['user']++;
    102                 if ($paidlog['paid_type']==1)
    103                 {
    104                    $top['last_month']['sms']+=$paidlog['amount'];
    105                 }
    106                 if ($paidlog['paid_type']==2)
    107                 {
    108                     $top['last_month']['card']+=$paidlog['amount'];
    109                 }
    110                 if ($paidlog['collaborator']!="")
    111                 {
    112                     $top['last_month']['collaborator']+=$paidlog['amount'];
    113                 }
    114             }
    115            
    116            
    117 
    118             if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
    119                 $charts['this_month'][0]+=$paidlog['amount'];
    120             }
    121             if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
    122                 $charts['this_month'][1]+=$paidlog['amount'];
    123             }
    124             if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
    125                 $charts['this_month'][2]+=$paidlog['amount'];
    126             }
    127             if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
    128                 $charts['this_month'][3]+=$paidlog['amount'];
    129             }
    130             if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
    131                 $charts['this_month'][4]+=$paidlog['amount'];
    132             }
    133             if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth )) {
    134                 $top['this_month']['user']++;
    135                 if ($paidlog['paid_type']==1)
    136                 {
    137                    $top['this_month']['sms']+=$paidlog['amount'];
    138                 }
    139                 if ($paidlog['paid_type']==2)
    140                 {
    141                     $top['this_month']['card']+=$paidlog['amount'];
    142                 }
    143                 if ($paidlog['collaborator']!="")
    144                 {
    145                     $top['this_month']['collaborator']+=$paidlog['amount'];
    146                 }
    147             }
    148         }
    149         $percent=array();
    150         foreach ($top['this_month'] as $index=>$value)
    151         {
    152             $percent[$index]['class']="down";
    153             $percent[$index]['display']="giảm";
    154             $percent[$index]['value']="n/a";
    155             if (($top['this_month'][$index]>0)&&($top['last_month'][$index]>0))
    156             {
    157             $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
    158             if ($top['this_month'][$index] > $top['last_month'][$index])
    159             {
    160                $percent[$index]['class']="up";
    161                $percent[$index]['display']="tăng";
    162             }
    163             }
    164         }
    165         $data['percent']=$percent;
    166         $data['top']=$top;
    167         $max = 0;
    168         foreach ($charts['last_month'] as $index => $total) {
    169             if ($total > $max) {
    170                 $max = $total;
    171             }
    172             $chart_last_month[] = array($index, $total);
    173         }
    174         foreach ($charts['this_month'] as $index => $total) {
    175             if ($total > $max) {
    176                 $max = $total;
    177             }
    178             $chart_this_month[] = array($index, $total);
    179         }
    180 
    181         $data['revenue'] = $revenue;
    182         $data['max'] = $max;
    183         $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
    184         $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
    185 
    186         $data['chard'] = $chard;
    187 
     24    public function getStatistics() {
     25        $this->load->model('collabolator_model');
     26        $data = $this->collabolator_model->getStatistics();
    18827        return $this->load->view('home/statistics', $data, true);
    18928    }
    190     public function getLastquarter() {
    191         $current_month = date('m');
    192         $current_year = date('Y');
     29    public function login() {
    19330
    194         if ($current_month >= 1 && $current_month <= 3) {
    195             $start_date = strtotime('1-October-' . ($current_year - 1));  // timestamp or 1-October Last Year 12:00:00 AM
    196             $end_date = strtotime('1-Janauary-' . $current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
    197         } else if ($current_month >= 4 && $current_month <= 6) {
    198             $start_date = strtotime('1-January-' . $current_year);  // timestamp or 1-Janauray 12:00:00 AM
    199             $end_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
    200         } else if ($current_month >= 7 && $current_month <= 9) {
    201             $start_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM
    202             $end_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
    203         } else if ($current_month >= 10 && $current_month <= 12) {
    204             $start_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM
    205             $end_date = strtotime('1-October-' . $current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
     31        $login_name = $this->input->post('login_name');
     32        $passwd = $this->input->post('passwd');
     33
     34        $this->load->model(array('admin_model'));
     35        $data = $this->admin_model->check_login($login_name, $passwd);
     36        if ($data == null) {
     37            $this->session->set_flashdata('login_error', TRUE);
     38            redirect("/admin/home");
     39        } else {
     40            $admindata = array('login_name' => $login_name, 'admin_id' => $data->admin_id, 'role_id' => $data->role_id, 'logined_in' => TRUE);
     41            $this->session->set_userdata('adminInfo', $admindata);
     42            redirect("/admin/home");
    20643        }
    207         return array("start" => $start_date, "end" => $end_date);
    20844    }
    20945
    210        
    211         public function login()
    212         {
    213            
    214                 $login_name = $this->input->post('login_name');
    215                 $passwd = $this->input->post('passwd');
    216                
    217                 $this->load->model(array('admin_model'));
    218                 $data = $this->admin_model->check_login($login_name, $passwd);
    219                 if ($data == null)
    220                 {
    221                         $this->session->set_flashdata('login_error', TRUE);
    222                         redirect("/admin/home");
    223                 }
    224                 else
    225                 {
    226                         $admindata = array('login_name' => $login_name, 'admin_id'=>$data->admin_id, 'role_id'=>$data->role_id, 'logined_in' => TRUE);
    227                         $this->session->set_userdata('adminInfo', $admindata);
    228                         redirect("/admin/home");
    229                 }
    230         }
    231        
    232         public function logout()
    233         {
    234                 $this->session->sess_destroy();
    235                 redirect("/admin/home");
    236         }
     46    public function logout() {
     47        $this->session->sess_destroy();
     48        redirect("/admin/home");
     49    }
     50
    23751}
  • 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()) {
  • pro-violet-viettel/sourcecode/application/modules/admin/models/collabolator_model.php

    r478 r594  
    198198        return $result;
    199199    }
     200    function getStatistics()
     201    {
     202        $data = array();
     203        $last_month['start'] = strtotime(date("Y-m-d", strtotime("first day of previous month")) . " 00:00:00");
     204        $last_month['end'] = strtotime(date("Y-m-d", strtotime("last day of previous month")) . " 23:59:59");
     205
     206        $last_week['start'] = strtotime(date("Y-m-d", strtotime("first day of previous week")) . " 00:00:00");
     207        $last_week['end'] = strtotime(date("Y-m-d", strtotime("last day of previous week")) . " 23:59:59");
     208
     209        $last_week['end'] = strtotime('last sunday') + (24 * 60 * 60 - 1);
     210        $last_week['start'] = ($last_week['end'] - 7 * 24 * 60 * 60 + 1);
     211
     212        $last_year['start'] = strtotime((date("Y") - 1) . "-01-01 00:00:00");
     213        $last_year['end'] = strtotime((date("Y") - 1) . "-12-31 23:59:59");
     214
     215
     216
     217        $last_quarter = $this->getLastquarter();
     218        $last_quarter['start'] = $last_quarter['start'];
     219        $last_quarter['end'] = $last_quarter['end'];
     220
     221
     222        $this->load->model('paidlog_model');
     223        $paidlogs = $this->paidlog_model->getAllPaidlogs($last_year['start']);
     224
     225        $revenue['last_week'] = 0;
     226        $revenue['last_month'] = 0;
     227        $revenue['last_quarter'] = 0;
     228        $revenue['last_year'] = 0;
     229
     230        $lastmonth = strtotime("first day of previous month");
     231        $thismonth = strtotime("first day of this month");
     232        $charts['last_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
     233        $charts['this_month'] = array(0 => 0, 1 => 0, 2 => 0, 3 => 0, 4 => 0);
     234       
     235        $top['last_month']['user']=0;
     236        $top['last_month']['sms']=0;
     237        $top['last_month']['card']=0;
     238        $top['last_month']['collaborator']=0;
     239        $top['this_month']['user']=0;
     240        $top['this_month']['sms']=0;
     241        $top['this_month']['card']=0;
     242        $top['this_month']['collaborator']=0;
     243        foreach ($paidlogs as $paidlog) {
     244
     245           
     246            if (($paidlog['time'] < $last_week['end']) && ($paidlog['time'] > $last_week['start'])) {
     247                $revenue['last_week']+=$paidlog['amount'];
     248            }
     249            if (($paidlog['time'] < $last_month['end']) && ($paidlog['time'] > $last_month['start'])) {
     250                $revenue['last_month']+=$paidlog['amount'];
     251            }
     252            if (($paidlog['time'] < $last_quarter['end']) && ($paidlog['time'] > $last_quarter['start'])) {
     253                $revenue['last_quarter']+=$paidlog['amount'];
     254            }
     255            if (($paidlog['time'] < $last_year['end']) && ($paidlog['time'] > $last_year['start'])) {
     256                $revenue['last_year']+=$paidlog['amount'];
     257            }
     258           
     259           
     260            if (($paidlog['time'] < $lastmonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth)) {
     261                $charts['last_month'][0]+=$paidlog['amount'];
     262            }
     263            if (($paidlog['time'] < $lastmonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (7 * 24 * 60 * 60))) {
     264                $charts['last_month'][1]+=$paidlog['amount'];
     265            }
     266            if (($paidlog['time'] < $lastmonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (14 * 24 * 60 * 60))) {
     267                $charts['last_month'][2]+=$paidlog['amount'];
     268            }
     269            if (($paidlog['time'] < $lastmonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $lastmonth + (21 * 24 * 60 * 60))) {
     270                $charts['last_month'][3]+=$paidlog['amount'];
     271            }
     272            if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth + (28 * 24 * 60 * 60))) {
     273                $charts['last_month'][4]+=$paidlog['amount'];
     274            }
     275           
     276            if (($paidlog['time'] < $thismonth) && ($paidlog['time'] > $lastmonth)) {
     277                $top['last_month']['user']++;
     278                if ($paidlog['paid_type']==1)
     279                {
     280                   $top['last_month']['sms']+=$paidlog['amount'];
     281                }
     282                if ($paidlog['paid_type']==2)
     283                {
     284                    $top['last_month']['card']+=$paidlog['amount'];
     285                }
     286                if ($paidlog['collaborator']!="")
     287                {
     288                    $top['last_month']['collaborator']+=$paidlog['amount'];
     289                }
     290            }
     291           
     292           
     293
     294            if (($paidlog['time'] < $thismonth + (7 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth)) {
     295                $charts['this_month'][0]+=$paidlog['amount'];
     296            }
     297            if (($paidlog['time'] < $thismonth + (14 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (7 * 24 * 60 * 60))) {
     298                $charts['this_month'][1]+=$paidlog['amount'];
     299            }
     300            if (($paidlog['time'] < $thismonth + (21 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (14 * 24 * 60 * 60))) {
     301                $charts['this_month'][2]+=$paidlog['amount'];
     302            }
     303            if (($paidlog['time'] < $thismonth + (28 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (21 * 24 * 60 * 60))) {
     304                $charts['this_month'][3]+=$paidlog['amount'];
     305            }
     306            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth + (28 * 24 * 60 * 60))) {
     307                $charts['this_month'][4]+=$paidlog['amount'];
     308            }
     309            if (($paidlog['time'] < $thismonth + (31 * 24 * 60 * 60)) && ($paidlog['time'] > $thismonth )) {
     310                $top['this_month']['user']++;
     311                if ($paidlog['paid_type']==1)
     312                {
     313                   $top['this_month']['sms']+=$paidlog['amount'];
     314                }
     315                if ($paidlog['paid_type']==2)
     316                {
     317                    $top['this_month']['card']+=$paidlog['amount'];
     318                }
     319                if ($paidlog['collaborator']!="")
     320                {
     321                    $top['this_month']['collaborator']+=$paidlog['amount'];
     322                }
     323            }
     324        }
     325        $percent=array();
     326        foreach ($top['this_month'] as $index=>$value)
     327        {
     328            $percent[$index]['class']="down";
     329            $percent[$index]['display']="giảm";
     330            $percent[$index]['value']="n/a";
     331            if (($top['this_month'][$index]>0)&&($top['last_month'][$index]>0))
     332            {
     333            $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
     334            if ($top['this_month'][$index] > $top['last_month'][$index])
     335            {
     336               $percent[$index]['class']="up";
     337               $percent[$index]['display']="tăng";
     338            }
     339            }
     340        }
     341        $data['percent']=$percent;
     342        $data['top']=$top;
     343        $max = 0;
     344        foreach ($charts['last_month'] as $index => $total) {
     345            if ($total > $max) {
     346                $max = $total;
     347            }
     348            $chart_last_month[] = array($index, $total);
     349        }
     350        foreach ($charts['this_month'] as $index => $total) {
     351            if ($total > $max) {
     352                $max = $total;
     353            }
     354            $chart_this_month[] = array($index, $total);
     355        }
     356
     357        $data['revenue'] = $revenue;
     358        $data['max'] = $max;
     359        $chard[] = array("color" => "#e67e22", "label" => "Tháng hiện tại", "data" => $chart_this_month);
     360        $chard[] = array("color" => "#1abc9c", "label" => "Tháng trước", "data" => $chart_last_month);
     361
     362        $data['chard'] = $chard;
     363        return $data;
     364    }
     365    public function getLastquarter() {
     366        $current_month = date('m');
     367        $current_year = date('Y');
     368
     369        if ($current_month >= 1 && $current_month <= 3) {
     370            $start_date = strtotime('1-October-' . ($current_year - 1));  // timestamp or 1-October Last Year 12:00:00 AM
     371            $end_date = strtotime('1-Janauary-' . $current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
     372        } else if ($current_month >= 4 && $current_month <= 6) {
     373            $start_date = strtotime('1-January-' . $current_year);  // timestamp or 1-Janauray 12:00:00 AM
     374            $end_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
     375        } else if ($current_month >= 7 && $current_month <= 9) {
     376            $start_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM
     377            $end_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
     378        } else if ($current_month >= 10 && $current_month <= 12) {
     379            $start_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM
     380            $end_date = strtotime('1-October-' . $current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
     381        }
     382        return array("start" => $start_date, "end" => $end_date);
     383    }
    200384
    201385}
Note: See TracChangeset for help on using the changeset viewer.