source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/home.php @ 586

Last change on this file since 586 was 586, checked in by quyenla, 10 years ago

HOME

File size: 9.9 KB
RevLine 
[339]1<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
[324]2
3class 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        {
[360]13           
[324]14                $admin_info = $this->session->userdata('adminInfo');
15                if ($admin_info)
16                {
[586]17                        $data['statistics'] = $this->getStatistics();
18            $data['content']="";
19            $this->load->view('home/index', $data);
[324]20                }else
21                {
22                        $this->load->view ( 'login');
23                }
24        }
[586]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
[324]207       
208        public function login()
209        {
[360]210           
[423]211                $login_name = $this->input->post('login_name');
212                $passwd = $this->input->post('passwd');
[324]213               
214                $this->load->model(array('admin_model'));
[423]215                $data = $this->admin_model->check_login($login_name, $passwd);
[324]216                if ($data == null)
217                {
218                        $this->session->set_flashdata('login_error', TRUE);
219                        redirect("/admin/home");
220                }
221                else
222                {
[423]223                        $admindata = array('login_name' => $login_name, 'admin_id'=>$data->admin_id, "logined_in" => TRUE);
[324]224                        $this->session->set_userdata('adminInfo', $admindata);
225                        redirect("/admin/home");
226                }
227        }
228       
229        public function logout()
230        {
231                $this->session->sess_destroy();
232                redirect("/admin/home");
233        }
234}
Note: See TracBrowser for help on using the repository browser.