[339] | 1 | <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
|
---|
[324] | 2 |
|
---|
| 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 | {
|
---|
[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";
|
---|
[587] | 155 | $percent[$index]['value']="n/a";
|
---|
| 156 | if (($top['this_month'][$index]>0)&&($top['last_month'][$index]>0))
|
---|
| 157 | {
|
---|
[586] | 158 | $percent[$index]['value']=round((($top['this_month'][$index] / $top['last_month'][$index])*100),1);
|
---|
| 159 | if ($top['this_month'][$index] > $top['last_month'][$index])
|
---|
| 160 | {
|
---|
| 161 | $percent[$index]['class']="up";
|
---|
| 162 | $percent[$index]['display']="tÄng";
|
---|
| 163 | }
|
---|
[587] | 164 | }
|
---|
[586] | 165 | }
|
---|
| 166 | $data['percent']=$percent;
|
---|
| 167 | $data['top']=$top;
|
---|
| 168 | $max = 0;
|
---|
| 169 | foreach ($charts['last_month'] as $index => $total) {
|
---|
| 170 | if ($total > $max) {
|
---|
| 171 | $max = $total;
|
---|
| 172 | }
|
---|
| 173 | $chart_last_month[] = array($index, $total);
|
---|
| 174 | }
|
---|
| 175 | foreach ($charts['this_month'] as $index => $total) {
|
---|
| 176 | if ($total > $max) {
|
---|
| 177 | $max = $total;
|
---|
| 178 | }
|
---|
| 179 | $chart_this_month[] = array($index, $total);
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | $data['revenue'] = $revenue;
|
---|
| 183 | $data['max'] = $max;
|
---|
| 184 | $chard[] = array("color" => "#e67e22", "label" => "Tháng hiá»n tại", "data" => $chart_this_month);
|
---|
| 185 | $chard[] = array("color" => "#1abc9c", "label" => "Tháng trưá»c", "data" => $chart_last_month);
|
---|
| 186 |
|
---|
| 187 | $data['chard'] = $chard;
|
---|
| 188 |
|
---|
| 189 | return $this->load->view('home/statistics', $data, true);
|
---|
| 190 | }
|
---|
| 191 | public function getLastquarter() {
|
---|
| 192 | $current_month = date('m');
|
---|
| 193 | $current_year = date('Y');
|
---|
| 194 |
|
---|
| 195 | if ($current_month >= 1 && $current_month <= 3) {
|
---|
| 196 | $start_date = strtotime('1-October-' . ($current_year - 1)); // timestamp or 1-October Last Year 12:00:00 AM
|
---|
| 197 | $end_date = strtotime('1-Janauary-' . $current_year); // // timestamp or 1-January 12:00:00 AM means end of 31 December Last year
|
---|
| 198 | } else if ($current_month >= 4 && $current_month <= 6) {
|
---|
| 199 | $start_date = strtotime('1-January-' . $current_year); // timestamp or 1-Janauray 12:00:00 AM
|
---|
| 200 | $end_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM means end of 31 March
|
---|
| 201 | } else if ($current_month >= 7 && $current_month <= 9) {
|
---|
| 202 | $start_date = strtotime('1-April-' . $current_year); // timestamp or 1-April 12:00:00 AM
|
---|
| 203 | $end_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM means end of 30 June
|
---|
| 204 | } else if ($current_month >= 10 && $current_month <= 12) {
|
---|
| 205 | $start_date = strtotime('1-July-' . $current_year); // timestamp or 1-July 12:00:00 AM
|
---|
| 206 | $end_date = strtotime('1-October-' . $current_year); // timestamp or 1-October 12:00:00 AM means end of 30 September
|
---|
| 207 | }
|
---|
| 208 | return array("start" => $start_date, "end" => $end_date);
|
---|
| 209 | }
|
---|
| 210 |
|
---|
[324] | 211 |
|
---|
| 212 | public function login()
|
---|
| 213 | {
|
---|
[360] | 214 |
|
---|
[423] | 215 | $login_name = $this->input->post('login_name');
|
---|
| 216 | $passwd = $this->input->post('passwd');
|
---|
[324] | 217 |
|
---|
| 218 | $this->load->model(array('admin_model'));
|
---|
[423] | 219 | $data = $this->admin_model->check_login($login_name, $passwd);
|
---|
[324] | 220 | if ($data == null)
|
---|
| 221 | {
|
---|
| 222 | $this->session->set_flashdata('login_error', TRUE);
|
---|
| 223 | redirect("/admin/home");
|
---|
| 224 | }
|
---|
| 225 | else
|
---|
| 226 | {
|
---|
[423] | 227 | $admindata = array('login_name' => $login_name, 'admin_id'=>$data->admin_id, "logined_in" => TRUE);
|
---|
[324] | 228 | $this->session->set_userdata('adminInfo', $admindata);
|
---|
| 229 | redirect("/admin/home");
|
---|
| 230 | }
|
---|
| 231 | }
|
---|
| 232 |
|
---|
| 233 | public function logout()
|
---|
| 234 | {
|
---|
| 235 | $this->session->sess_destroy();
|
---|
| 236 | redirect("/admin/home");
|
---|
| 237 | }
|
---|
| 238 | } |
---|