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

Last change on this file since 758 was 756, checked in by quyenla, 10 years ago

report update

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