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

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