source: pro-violet-viettel/sourcecode/application/modules/collaborator/controllers/home.php

Last change on this file was 906, checked in by namnd, 10 years ago
File size: 13.7 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Home extends MX_Controller {
7
8        const TOKENPW = 'violet';
9
10    public function __construct() {
11        parent::__construct();
12        $this->load->helper('cookie');
13                $this->load->helper('language');
14                $this->lang->load('messages', 'message');
15    }
16
17    public function index() {
18               
19        $collaborator_info = $this->session->userdata('collaboratorInfo');
20        if ($collaborator_info) {
21                        $id = $collaborator_info['id'];
22            $data['statistics'] = $this->getStatistics($id);
23                        $data['content'] = $this->getCollaboratorsUsers();
24            $this->load->view('collaborator/reportAsistant/indexCollaborator', $data);
25        } else {
26            $this->load->view('login');
27        }
28    }
29
30    public function login() {
31               
32        $login_name = $this->input->post('login_name');
33        $passwd = $this->input->post('passwd');
34               
35        $this->load->model('admin/Collabolator_model');
36        $data = $this->Collabolator_model->check_login($login_name, $passwd);
37        if ($data == null) {
38            $this->session->set_flashdata('login_error', TRUE);
39            redirect("/cong_tac_vien");
40        } else {
41            $collaboratorData = array('login_name' => $login_name, 'id' => $data->id, 'fullname' => $data->full_name, 'logined_in' => TRUE);
42            $this->session->set_userdata('collaboratorInfo', $collaboratorData);
43            redirect("/cong_tac_vien");
44        }
45    }
46
47    public function logout() {
48                $this->session->unset_userdata('collaboratorInfo');
49        redirect("/collaborator");
50    }
51   
52    public function is_timeout()
53    {
54        $result['login']=1;
55        $collaborator_infor = $this->session->userdata('collaboratorInfo');
56        if (!$collaborator_infor) {
57            $result['login']=0;
58        }
59        echo json_encode($result);
60    }
61
62    public function getStatistics($id = false) {
63        $data = array();
64
65        $this_year['start'] = strtotime(date("Y") . "-01-01 00:00:00");
66
67        $this->load->model('admin/collabolator_model');
68        $collaborators = $this->collabolator_model->getAllCollaboratorUser($this_year['start'], $id);
69        for ($i = 1; $i <= 12; $i++) {
70            $statistics[$i] = 0;
71        }
72        $y = date("Y");
73        foreach ($collaborators as $collaborator) {
74            for ($i = 1; $i <= 12; $i++) {
75                if ($i < 12) {
76                    if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime($y . "-" . ($i + 1) . "-1 00:00:00")))) {
77                        $statistics[$i] ++;
78                    }
79                } else {
80                    if (($collaborator['time'] > strtotime($y . "-" . $i . "-1 00:00:00")) && (($collaborator['time'] < strtotime(($y + 1) . "-1-1 00:00:00")))) {
81                        $statistics[$i] ++;
82                    }
83                }
84            }
85        }
86
87        $max = 0;
88        foreach ($statistics as $index => $total) {
89            if ($total > $max) {
90                $max = $total;
91            }
92            $chart[] = array($index, $total);
93        }
94
95        $data['max'] = $max;
96        $chard[] = array("color" => "#e67e22", "label" => "Lượng người dùng giới thiệu bởi cộng tác viên theo từng tháng", "data" => $chart);
97        $data['chard'] = $chard;
98         
99        return $this->load->view('collaborator/reportAsistant/statistics', $data, true);
100    }
101
102    public function getLastquarter() {
103        $current_month = date('m');
104        $current_year = date('Y');
105
106        if ($current_month >= 1 && $current_month <= 3) {
107            $start_date = strtotime('1-October-' . ($current_year - 1));  // timestamp or 1-October Last Year 12:00:00 AM
108            $end_date = strtotime('1-Janauary-' . $current_year);  // // timestamp or 1-January  12:00:00 AM means end of 31 December Last year
109        } else if ($current_month >= 4 && $current_month <= 6) {
110            $start_date = strtotime('1-January-' . $current_year);  // timestamp or 1-Janauray 12:00:00 AM
111            $end_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM means end of 31 March
112        } else if ($current_month >= 7 && $current_month <= 9) {
113            $start_date = strtotime('1-April-' . $current_year);  // timestamp or 1-April 12:00:00 AM
114            $end_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM means end of 30 June
115        } else if ($current_month >= 10 && $current_month <= 12) {
116            $start_date = strtotime('1-July-' . $current_year);  // timestamp or 1-July 12:00:00 AM
117            $end_date = strtotime('1-October-' . $current_year);  // timestamp or 1-October 12:00:00 AM means end of 30 September
118        }
119        return array("start" => $start_date, "end" => $end_date);
120    }
121
122
123    public function getCollaboratorsUsers() {
124                $collaborator_info = $this->session->userdata('collaboratorInfo');
125        if ($collaborator_info) {
126                        $this->load->helper('pagging');
127                        $this->load->model('admin/collabolator_model');
128                        $data['current_page'] = $this->uri->segment(5, 1);
129                       
130                        $data['itemsoptions'] = array(10, 25, 50, 100);
131                        $data['perpage'] = 10;
132                        $id = $collaborator_info['id'];
133            $data['id'] = $id;
134                       
135                        $data['keyword'] = "";
136                        $data['sorting_order'] = "sorting_desc";
137                        $data['sorting_field'] = "user_created_time";
138
139                        if ($this->input->post('sorting_order')) {
140                                if ($this->input->post('sorting_order') != "sorting") {
141                                        $data['sorting_order'] = $this->input->post('sorting_order');
142                                        $data['sorting_field'] = $this->input->post('sorting_field');
143                                }
144                        }
145                        if ($this->input->post('items')) {
146                                $data['perpage'] = $this->input->post('items');
147                        }
148                        if ($this->input->post('keyword')) {
149                                $data['search_field'] = "";
150                                $data['keyword'] = $this->input->post('keyword');
151
152                                if (preg_match("/[0-9]/", $data['keyword'])) {
153                                        $data['search_field'] = "cellphone";
154                                }
155                        }
156
157                        $data['daterange_start'] = "";
158                        $data['daterange_end'] = "";
159                        if ($this->input->post('daterange')){
160                                $daterange = explode(" - ", $this->input->post('daterange'));
161                                $daterange[0] = str_replace('/', '-', $daterange[0]);
162                                $daterange[1] = str_replace('/', '-', $daterange[1]);
163                                $data['date_start'] = $daterange[0];
164                                $data['date_end'] = $daterange[1];
165                                $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
166                                $data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day'));
167                        }
168                       
169                        $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
170                        $data['total'] = $this->collabolator_model->countCountCollaboratorUsers($data);
171                        $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data);
172                        foreach ($data['paidlogs'] as $index => $paidlog)
173                        {
174                                $data['paidlogs'][$index]['username'] = $this->get_fullname($paidlog['us_id']);
175                        }
176                        $data['paging_url'] = base_url() . "collaborator/home/getCollaboratorsUsers/".$data['id'];
177                        $data['num_links'] = 2;
178                        $data['paging'] = pagging($data);
179               
180                        if ($this->input->is_ajax_request()) {
181                                return $this->load->view('collaborator/reportAsistant/listview_user', $data);
182                        }
183                        return $this->load->view('collaborator/reportAsistant/listview_user', $data, true);
184                }else{
185                        $this->load->view('login');
186                }
187    }
188
189    private function get_fullname($us_id) {
190        $fullname="";
191        $src = 'SBG';
192        $token = md5($us_id . self::TOKENPW);
193        $this->load->model('admin/user_model');
194        $data = $this->user_model->get_user_info($src, $us_id, $token);
195        parse_str($data,$data);
196        if (isset($data['fullname']))
197        {
198            $fullname=$data['fullname'];
199        }
200        return $fullname;
201    }
202       
203       
204        public function export(){
205               
206                $collaborator_info = $this->session->userdata('collaboratorInfo');
207        if ($collaborator_info) {
208                        $id = $collaborator_info['id'];
209            $data['id'] = $id;
210                        $data['fullname'] = $collaborator_info['fullname'];
211                        $this->load->model('admin/collabolator_model');
212                        //$data['perpage'] = $this->uri->segment(4, 10);
213                        $data['keyword'] = $this->uri->segment(5);
214                        if ($data['keyword'] == 'default') $data['keyword'] = null;
215                        if (preg_match("/[0-9]/", $data['keyword'])) {
216                                        $data['search_field'] = "cellphone";
217                        }
218                        $data['daterange_start'] = $this->uri->segment(6);
219                        $data['daterange_end'] = $this->uri->segment(7);
220                        if ($data['daterange_start'] == 'default') $data['daterange_start'] = null;
221                        if ($data['daterange_end'] == 'default') $data['daterange_end'] = null;
222                        if ($data['daterange_start'])
223                                $data['daterange_start'] = date ( 'Y-m-d H:i:s', strtotime ( $data ['daterange_start'] ) );
224                        if ($data['daterange_end'])
225                                $data['daterange_end'] = date ( 'Y-m-d H:i:s', strtotime ( $data['daterange_end'] . ' + 1 day' ) );
226                       
227                        $data['sorting_field'] = "user_created_time";
228                        $data['sorting_order'] = $this->uri->segment(8);
229                       
230                        $data['paidlogs'] = $this->collabolator_model->getCountCollaboratorUsers($data);
231                       
232                        foreach ($data['paidlogs'] as $index => $paidlog)
233                        {
234                                $data['paidlogs'][$index]['username'] = $this->get_fullname($paidlog['us_id']);
235                        }
236                        $users = $data['paidlogs'];
237                       
238                        ob_end_clean();
239                        $this->load->library("PHPExcel");
240                        $sheet = $this->phpexcel->getActiveSheet();
241                       
242                        $sheet->setTitle("bao cao cua CTV " . date('m') . " - " . date('Y'));
243                        $sheet->getColumnDimension('A')->setWidth(10);
244                        $sheet->getColumnDimension('B')->setWidth(25);
245                        $sheet->getColumnDimension('C')->setWidth(25);
246                        $sheet->getColumnDimension('D')->setWidth(25);
247                        $sheet->getColumnDimension('E')->setWidth(15);
248                        $sheet->getColumnDimension('F')->setWidth(15);
249                        $sheet->getColumnDimension('G')->setWidth(15);
250                        $sheet->getColumnDimension('H')->setWidth(25);
251                        $sheet->getColumnDimension('I')->setWidth(25);
252                       
253                       
254                        $sheet->setCellValue('B1', "TẬP ĐOÀN VIỄN THÔNG QUÂN ĐỘI");
255                        $style = array(
256                                'font' => array('bold' => true, 'size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
257                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
258                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
259                                                                        'wrap' => true )
260                        );
261                        $sheet->mergeCells('B1:E1');
262                        $sheet->getStyle('B1')->applyFromArray($style);
263                       
264                        $sheet->setCellValue('B2', "TỔNG CÔNG TY VIỄN THÔNG VIETTEL");
265                        $style = array(
266                                'font' => array('size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
267                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
268                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
269                                                                        'wrap' => true )
270                        );
271                        $sheet->mergeCells('B2:E2');
272                        $sheet->getStyle('B2')->applyFromArray($style);
273                       
274                       
275                        $sheet->setCellValue('A4', "DANH SÁCH NGƯỜI DÙNG DO CỘNG TÁC VIÊN GIỚI THIỆU");
276                        $style = array(
277                                'font' => array('bold' => true, 'size' => 14, 'name' =>'Cambria'),
278                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
279                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
280                                                                        'wrap' => true )
281                        );
282                        $sheet->mergeCells('A4:E4');
283                        $sheet->getStyle('A4')->applyFromArray($style);
284                       
285                       
286                       
287                        $style = array(
288                                'font' => array('size' => 11, 'name' =>'Cambria'),
289                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
290                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
291                                                                        'wrap' => true),
292                                'borders' =>    array(
293                                        'allborders' => array(
294                                                'style' => \PHPExcel_Style_Border::BORDER_THIN
295                                                )
296                                )
297                        );
298                       
299                        $sheet->setCellValue('B6', "Từ ngày: ".$data['daterange_start']);
300                        $sheet->setCellValue('C6', "Đến ngày: ".$data['daterange_end']);
301                        $sheet->setCellValue('B7', "Ngày kết xuất: ".date("d")."/".date("m")."/".date("Y"));
302                        $sheet->setCellValue('C7', "CTV: ".$data['fullname']);
303                       
304                        $sheet->getStyle('B6')->applyFromArray($style);
305                        $sheet->getStyle('C6')->applyFromArray($style);
306                        $sheet->getStyle('B7')->applyFromArray($style);
307                        $sheet->getStyle('C7')->applyFromArray($style);
308                       
309                        $sheet->setCellValue('A9', 'STT');
310                        $sheet->setCellValue('B9', 'Tên người dùng');
311                        $sheet->setCellValue('C9', 'Số thuê bao');
312                        $sheet->setCellValue('D9', 'Ngày giờ giới thiệu');
313                        $style = array(
314                                'font' => array('bold' => true, 'size' => 11, 'name' =>'Cambria'),
315                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
316                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
317                                                                        'wrap' => true),
318                                'borders' =>    array(
319                                        'allborders' => array(
320                                                'style' => \PHPExcel_Style_Border::BORDER_THIN
321                                                )
322                                )
323                        );
324                        $sheet->getStyle('A9:D9')->applyFromArray($style);
325                       
326                        $style = array(
327                                'font' => array('size' => 11, 'name' =>'Cambria'),
328                                'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
329                                                                        'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
330                                                                        'wrap' => true),
331                                'borders' =>    array(
332                                        'allborders' => array(
333                                                'style' => \PHPExcel_Style_Border::BORDER_THIN
334                                                )
335                                )
336                        );
337                       
338                        $dem = 0;
339                        foreach ($users as $index => $user):
340                                $sheet->setCellValue('A' . ($dem + 10), $index + 1);
341                                $sheet->setCellValue('B' . ($dem + 10), $user['username']);
342                                $sheet->setCellValueExplicit('C' . ($dem + 10), $user['user_cellphone'], PHPExcel_Cell_DataType::TYPE_STRING);
343                                $sheet->setCellValue('D' . ($dem + 10), $user['user_created_time']);
344                                $sheet->getStyle('A' . ($dem + 10).':D'.($dem + 10))->applyFromArray($style);
345                                $dem++;
346                        endforeach;
347                       
348                        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
349                        header('Content-Type: application/vnd.ms-excel');
350                        header('Content-Disposition: attachment; filename="danhsachnguoidung_ctv_'.date('d/m/Y').'.xls"');
351                        $writer->save('php://output');
352                }else{
353                        $this->load->view('login');
354                }
355        }
356       
357}
Note: See TracBrowser for help on using the repository browser.