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

Last change on this file since 818 was 818, checked in by namnd, 10 years ago
File size: 5.0 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Reportpackage 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        $data = array();
19        $admin_info = $this->session->userdata('adminInfo');
20        if ($admin_info) {
21            $data['content'] = $this->getProvince();
22            $this->load->view('reportpackage/index', $data);
23        } else {
24            $this->load->view('login');
25        }
26    }
27
28    public function getProvince($filters = array()) {
29
30        $this->load->model('reportmodel');
31        $data['date']=1;
32        $data['month'] = date("m");
33        $data['year'] = date("Y");
34        $data['to_date']= 31;
35        $data['to_month'] = date("m");
36        $data['to_year'] = date("Y");
37        if ($this->input->post('month')) {
38            $data['month'] = $this->input->post('month');
39            $data['year'] = $this->input->post('year');
40        }
41        $data = $this->getdays($data);
42
43        $result = $this->reportmodel->getPackages($data);
44        $data['provinces'] = $result['provinces'];
45        $data['packages'] = $result['packages'];
46                $data['totalVip'] = $result['totalVip'];
47        if ($this->input->is_ajax_request()) {
48            return $this->load->view('reportpackage/province', $data);
49        }
50        return $this->load->view('reportpackage/province', $data, true);
51    }
52
53    public function getdays($data) {
54        $data['month_days'] = 1;
55        if ("" . $data['year'] . "-" . $data['month'] . "" == date("Y-m")) {
56            $data['month_days'] = date("d");
57        } else {
58            $data['month_days'] = cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31 
59        }
60        $data['year_days'] = 1;
61       
62        if ($data['year'] == date("Y")) {
63            $data['year_days'] = date('z') + 1;
64        } else {
65            $data['year_days'] = date("z", mktime(0, 0, 0, 12, 31, $data['year'])) + 1;
66        }
67        return $data;
68    }
69
70    public function export() {
71        $this->load->model('reportmodel');
72                $data['date']=1;
73        $data['month'] = $this->uri->segment(4);
74        $data['year'] = $this->uri->segment(5);
75                $data['to_date']=31;
76        $data['to_month'] = date("m");
77        $data['to_year'] = date("Y");
78        $data = $this->getdays($data);
79        $result = $this->reportmodel->getPackages($data);
80        $data['provinces'] = $result['provinces'];
81        $data['packages'] = $result['packages'];
82                $data['totalVip'] = $result['totalVip'];
83
84        $this->load->library("PHPExcel");
85        $sheet = $this->phpexcel->getActiveSheet();
86        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
87        $sheet->getColumnDimension('A')->setWidth(10);
88        $sheet->getColumnDimension('B')->setWidth(25);
89        $sheet->getColumnDimension('C')->setWidth(15);
90        $sheet->getColumnDimension('D')->setWidth(15);
91        $sheet->getColumnDimension('E')->setWidth(15);
92        $sheet->getColumnDimension('F')->setWidth(15);
93        $sheet->getColumnDimension('G')->setWidth(15);
94        $sheet->getColumnDimension('H')->setWidth(15);
95        $sheet->setCellValue('A1', "Báo cáo doanh thu theo tỉnh");
96        $sheet->setCellValue('A2', "Thời gian: " . $data['month'] . " - " . $data['year']);
97        $sheet->setCellValue('A4', "STT");
98        $sheet->setCellValue('B4', "Mã Tỉnh/Thành phố");
99        $sheet->setCellValue('C4', "Tỉnh/Thành phố");
100        $chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L");
101        $dem = 2;
102        $stt=1;
103        foreach ($data['packages'] as $package) {
104            $dem++;
105            $sheet->setCellValue($chars[$dem] . "4", $package['p_name']);
106            $dem++;
107            $sheet->setCellValue($chars[$dem] . "4", "Tỉ lệ %");
108       
109            $stt++;
110        }
111        $dem++;
112        $sheet->setCellValue($chars[$dem] . ($index + 4), "Tổng TB");
113
114$stt=1;
115        foreach ($data['provinces'] as $index => $provinces) {
116
117            $sheet->setCellValue('A' . ($stt + 5), $provinces['stt']);
118            $sheet->setCellValue('B' . ($stt + 5), $index);
119            $sheet->setCellValue('C' . ($stt + 5), $provinces['province']);
120            $dem = 2;
121            foreach ($provinces['packages'] as $package) {
122                $dem++;
123                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['total']);
124                $dem++;
125                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['percent']);
126            }
127            $dem++;
128           
129            $sheet->setCellValue($chars[$dem] . ($stt + 5), $provinces['total']);
130            $stt++;
131        }
132        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
133        header('Content-Disposition: attachment; filename="doanh_thu_' . $data['month'] . "_" . $data['year'] . '.xls"');
134        $writer->save('php://output');
135    }
136
137}
Note: See TracBrowser for help on using the repository browser.