source: pro-violet-viettel/sourcecode/application/modules/admin/controllers/report.php @ 818

Last change on this file since 818 was 818, checked in by namnd, 10 years ago
File size: 10.8 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Report extends MX_Controller {
7
8    const TOKENPW = 'violet';
9
10    public function __construct() {
11        parent::__construct();
12        $this->load->helper('cookie');
13    }
14
15    public function index() {
16        $data = array();
17        $admin_info = $this->session->userdata('adminInfo');
18        if ($admin_info) {
19            $data['statistics'] = $this->getStatistics();
20            $data['content'] = $this->getPaidlogs();
21            $this->load->view('report/index', $data);
22        } else {
23            $this->load->view('login');
24        }
25    }
26
27    public function getStatistics() {
28        $this->load->model('collabolator_model');
29        $data = $this->collabolator_model->getStatistics();
30        return $this->load->view('report/statistics', $data, true);
31    }
32
33
34    public function getPaidlogs($filters = array()) {
35        $this->load->helper('pagging');
36        $this->load->model('paidlog_model');
37        $data['current_page'] = $this->uri->segment(4, 1);
38        $data['itemsoptions'] = array(10, 25, 50, 100);
39        $data['perpage'] = 10;
40        $data['keyword'] = "";
41        $data['sorting_order'] = "sorting_desc";
42        $data['sorting_field'] = "paid_id";
43
44        if ($this->input->post('sorting_order')) {
45            if ($this->input->post('sorting_order') != "sorting") {
46                $data['sorting_order'] = $this->input->post('sorting_order');
47                $data['sorting_field'] = $this->input->post('sorting_field');
48            }
49        }
50        if ($this->input->post('items')) {
51            $data['perpage'] = $this->input->post('items');
52        }
53        if ($this->input->post('keyword')) {
54            $data['search_field'] = "";
55            $data['keyword'] = $this->input->post('keyword');
56
57            if (preg_match("/[0-9]/", $data['keyword'])) {
58                $data['search_field'] = "cellphone";
59            }
60        }
61               
62                $data ['paid_types'] = array (
63                                        0 => "Tất cả",
64                                        1 => "SMS",
65                                        2 => "Card",
66                );
67                $data ['paid_type'] = 0;
68                if ($this->input->post ( 'paid_type' )) {
69                        $data ['paid_type'] = ( int ) $this->input->post ( 'paid_type' );
70                }
71               
72                $data['daterange_start'] = "";
73                $data['daterange_end'] = "";
74                if ($this->input->post('daterange')){
75                        $daterange = explode(" - ", $this->input->post('daterange'));
76                        $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
77                        $data['daterange_end'] = date('Y-m-d 23:59:59', strtotime($daterange[1]));
78                }
79        $data['start'] = ($data['current_page'] - 1) * $data['perpage'];
80        $data['total'] = $this->paidlog_model->countPaidlog($data);
81        $data['paidlogs'] = $this->paidlog_model->getPaidlogs($data)['paid_logs'];
82                $data['total_amount'] = $this->paidlog_model->getPaidlogs($data)['total_amount'];
83               
84        $data['paging_url'] = base_url() . "/admin/doanh_thu_tong_hop/trang/";
85        $data['num_links'] = 2;
86        $data['paging'] = pagging($data);
87        foreach ($data['paidlogs'] as $index => $paidlog) {
88            $data['paidlogs'][$index]['username'] = @$this->get_fullname($paidlog['us_id']);
89        }
90               
91        if ($this->input->is_ajax_request()) {
92            return $this->load->view('report/listview', $data);
93        }
94        return $this->load->view('report/listview', $data, true);
95    }
96
97    private function get_fullname($us_id) {
98        $fullname="";
99        $src = 'violet';
100        $token = md5($us_id . self::TOKENPW);
101        $this->load->model('user_model');
102        $data = $this->user_model->get_user_info($src, $us_id, $token);
103        parse_str($data,$data);
104        if (isset($data['fullname']))
105        {
106            $fullname=$data['fullname'];
107        }
108        return $fullname;
109    }
110
111    public function test() {
112
113        /*
114          for ($i = 1; $i <= 5000; $i++) {
115          $input['us_id'] = rand(1, 100);
116          $input['paid_type'] = rand(1, 2);
117          $input['amount'] = rand(3, 10) * 1000;
118          $time = (rand((time() - (12 * 30 * 24 * 60 * 60)), time()));
119          $input['paid_time'] = date("Y-m-d H:i:s", $time);
120          $this->load->model('paidlog_model');
121          $this->paidlog_model->insert($input);
122          }
123
124          die();
125         */
126        for ($i = 1; $i <= 200; $i++) {
127            $input['us_id'] = $i;
128            $input['cellphone'] = "01234567" . (100 + $i);
129            $input['collaborator'] = rand(1, 100);
130            $input['acc_balanced'] = rand(100000, 1000000);
131            $input['expire_date'] = date("Y-m-d H:i:s", time());
132            $time = (rand((time() - (12 * 30 * 24 * 60 * 60)), time()));
133            $input['created_time'] = date("Y-m-d H:i:s", $time);
134            $input['updated_time'] = date("Y-m-d H:i:s", $time);
135            $this->load->model('user_model');
136            $this->user_model->insert($input);
137        }
138    }
139       
140        public function export(){
141        $this->load->model('paidlog_model');
142                $data ['paid_types'] = array (
143                                        0 => "Tất cả",
144                                        1 => "SMS",
145                                        2 => "Card",
146                );
147                $data ['paid_type'] = 0;
148                if ($this->input->post ( 'paid_type' )) {
149                        $data ['paid_type'] = ( int ) $this->input->post ( 'paid_type' );
150                }
151               
152                $data['daterange_start'] = "";
153                $data['daterange_end'] = "";
154                if ($this->input->post('daterange')){
155                        $daterange = explode(" - ", $this->input->post('daterange'));
156                        $data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
157                        $data['daterange_end'] = date('Y-m-d 23:59:59', strtotime($daterange[1]));
158                }
159        $data['total'] = $this->paidlog_model->countPaidlog($data);
160        $data['paidlogs'] = $this->paidlog_model->getPaidlogs($data)['paid_logs'];
161                $data['total_amount'] = $this->paidlog_model->getPaidlogs($data)['total_amount'];
162               
163        foreach ($data['paidlogs'] as $index => $paidlog) {
164            $data['paidlogs'][$index]['username'] = $this->get_fullname($paidlog['us_id']);
165        }
166               
167               
168        $this->load->library("PHPExcel");
169        $sheet = $this->phpexcel->getActiveSheet();
170               
171        $sheet->setTitle("bao cao tong hop ");
172        $sheet->getColumnDimension('A')->setWidth(20);
173        $sheet->getColumnDimension('B')->setWidth(25);
174        $sheet->getColumnDimension('C')->setWidth(15);
175        $sheet->getColumnDimension('D')->setWidth(15);
176        $sheet->getColumnDimension('E')->setWidth(25);
177
178               
179       
180                $sheet->setCellValue('B1', "TẬP ĐOÀN VIỄN THÔNG QUÂN ĐỘI");
181                $style = array(
182                        'font' => array('bold' => true, 'size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
183                        'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
184                                                                'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
185                                                                'wrap' => true )
186                );
187                $sheet->mergeCells('B1:E1');
188                $sheet->getStyle('B1')->applyFromArray($style);
189               
190                $sheet->setCellValue('B2', "TỔNG CÔNG TY VIỄN THÔNG VIETTEL");
191                $style = array(
192                        'font' => array('size' => 12, 'name' =>'Cambria', 'color' => array('rgb' => '0070bf')),
193                        'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
194                                                                'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
195                                                                'wrap' => true )
196                );
197                $sheet->mergeCells('B2:E2');
198                $sheet->getStyle('B2')->applyFromArray($style);
199               
200               
201                $sheet->setCellValue('A4', "BÁO CÁO DOANH THU TỔNG HỢP");
202               
203                $style = array(
204                        'font' => array('size' => 11, 'name' =>'Cambria'),
205                        'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT,
206                                                                'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
207                                                                'wrap' => true ),
208                        'borders' =>    array(
209                                'allborders' => array(
210                                        'style' => \PHPExcel_Style_Border::BORDER_THIN
211                                        )
212                        )
213                );
214                $sheet->setCellValue('B6', "Từ ngày: ". $data['daterange_start']);
215                $sheet->setCellValue('C6', "Đến ngày: ". $data['daterange_end']);
216                $sheet->setCellValue('B7', "Ngày kết xuất: ".date("d")."/".date("m")."/".date("Y"));
217                $sheet->setCellValue('C7', "Nhân viên kết xuất: ");
218               
219                $sheet->getStyle('B6')->applyFromArray($style);
220                $sheet->getStyle('C6')->applyFromArray($style);
221                $sheet->getStyle('B7')->applyFromArray($style);
222                $sheet->getStyle('C7')->applyFromArray($style);
223               
224               
225                $style = array(
226                        'font' => array('bold' => true, 'size' => 14, 'name' =>'Cambria'),
227                        'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
228                                                                'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
229                                                                'wrap' => true )
230                );
231                $sheet->mergeCells('A4:E4');
232                $sheet->getStyle('A4')->applyFromArray($style);
233               
234                $sheet->setCellValue('A9', 'Số điện thoại');
235                $style = array(
236                        'font' => array('bold' => true, 'size' => 11, 'name' =>'Cambria'),
237                        'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER,
238                                                                'vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER,
239                                                                'wrap' => true),
240                        'borders' =>    array(
241                                'allborders' => array(
242                                        'style' => \PHPExcel_Style_Border::BORDER_THIN
243                                        )
244                        )
245                );
246               
247                $sheet->setCellValue('B9', 'Họ tên');
248                $sheet->setCellValue('C9', "Số tiền (VNĐ)");
249                $sheet->setCellValue('D9', "SMS/Card");
250                $sheet->setCellValue('E9', "Ngày");           
251               
252                $sheet->getStyle('A9:E9')->applyFromArray($style);
253               
254                $sheet->setCellValue('A10', "Tổng");
255                $sheet->mergeCells('A10:B10');
256                $sheet->getStyle('A10:B10')->applyFromArray($style);
257               
258                $style = array(
259                        'font' => array('bold' => true, 'size' => 11, 'name' =>'Cambria'),
260                        'alignment' => array('vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER),
261                        'borders' =>    array(
262                                'allborders' => array(
263                                        'style' => \PHPExcel_Style_Border::BORDER_THIN
264                                        )
265                        )
266                );
267               
268                $sheet->setCellValue('C10', $data['total_amount']);
269                $sheet->getStyle('C10:E10')->applyFromArray($style);
270
271                $style = array(
272                        'font' => array('size' => 11, 'name' =>'Cambria'),
273                        'alignment' => array('vertical' => \PHPExcel_Style_Alignment::VERTICAL_CENTER),
274                        'borders' =>    array(
275                                'allborders' => array(
276                                        'style' => \PHPExcel_Style_Border::BORDER_THIN
277                                        )
278                        )
279                );
280
281        $dem=0;
282        foreach ($data['paidlogs'] as $index => $paidlog) {
283                        $type = "";
284           // $sheet->setCellValue('A' . ($dem + 11), $paidlog['cellphone']);
285                    if ($paidlog['paid_type'] == 1) {
286                                $type = "SMS";
287                        }else {
288                                $type = "Card";
289                        }
290                        $sheet->setCellValueExplicit('A' . ($dem + 11), $paidlog['cellphone'], PHPExcel_Cell_DataType::TYPE_STRING);
291                       
292            $sheet->setCellValue('B' . ($dem + 11), $paidlog['username']);
293            $sheet->setCellValue('C' . ($dem + 11), $paidlog['amount']);
294            $sheet->setCellValue('D' . ($dem + 11), $type);
295                        $sheet->setCellValue('E' . ($dem + 11), $paidlog['paid_time']);
296                        $sheet->getStyle('A'. ($dem + 11).':E'.($dem + 11))->applyFromArray($style);
297            $dem++;
298        }
299        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
300                header('Content-Type: application/vnd.ms-excel');
301        header('Content-Disposition: attachment; filename="bao_cao_tong_hop_'.date('d-m-Y').'.xls"');
302        $writer->save('php://output');
303        }
304}
Note: See TracBrowser for help on using the repository browser.