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

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

report

File size: 4.8 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
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['month'] = $this->uri->segment(4);
73        $data['year'] = $this->uri->segment(5);
74        $data = $this->getdays($data);
75        $result = $this->reportmodel->getPackages($data);
76        $data['provinces'] = $result['provinces'];
77        $data['packages'] = $result['packages'];
78
79        $this->load->library("PHPExcel");
80        $sheet = $this->phpexcel->getActiveSheet();
81        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
82        $sheet->getColumnDimension('A')->setWidth(10);
83        $sheet->getColumnDimension('B')->setWidth(25);
84        $sheet->getColumnDimension('C')->setWidth(15);
85        $sheet->getColumnDimension('D')->setWidth(15);
86        $sheet->getColumnDimension('E')->setWidth(15);
87        $sheet->getColumnDimension('F')->setWidth(15);
88        $sheet->getColumnDimension('G')->setWidth(15);
89        $sheet->getColumnDimension('H')->setWidth(15);
90        $sheet->setCellValue('A1', "Báo cáo doanh thu theo tỉnh");
91        $sheet->setCellValue('A2', "Thời gian: " . $data['month'] . " - " . $data['year']);
92        $sheet->setCellValue('A4', "STT");
93        $sheet->setCellValue('B4', "Mã Tỉnh/Thành phố");
94        $sheet->setCellValue('C4', "Tỉnh/Thành phố");
95        $chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L");
96        $dem = 2;
97        $stt=1;
98        foreach ($data['packages'] as $package) {
99            $dem++;
100            $sheet->setCellValue($chars[$dem] . "4", $package['p_name']);
101            $dem++;
102            $sheet->setCellValue($chars[$dem] . "4", "Tỉ lệ %");
103       
104            $stt++;
105        }
106        $dem++;
107        $sheet->setCellValue($chars[$dem] . ($index + 4), "Tổng TB");
108
109$stt=1;
110        foreach ($data['provinces'] as $index => $provinces) {
111
112            $sheet->setCellValue('A' . ($stt + 5), $provinces['stt']);
113            $sheet->setCellValue('B' . ($stt + 5), $index);
114            $sheet->setCellValue('C' . ($stt + 5), $provinces['province']);
115            $dem = 2;
116            foreach ($provinces['packages'] as $package) {
117                $dem++;
118                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['total']);
119                $dem++;
120                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['percent']);
121            }
122            $dem++;
123           
124            $sheet->setCellValue($chars[$dem] . ($stt + 5), $provinces['total']);
125            $stt++;
126        }
127        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
128        header('Content-Disposition: attachment; filename="doanh_thu_' . $data['month'] . "_" . $data['year'] . '.xls"');
129        $writer->save('php://output');
130    }
131
132}
Note: See TracBrowser for help on using the repository browser.