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

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

report

File size: 4.3 KB
Line 
1<?php
2
3if (!defined('BASEPATH'))
4    exit('No direct script access allowed');
5
6class Reportprovince 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        $this->load->model('reportmodel');
16    }
17
18    public function index() {
19        $data = array();
20        $admin_info = $this->session->userdata('adminInfo');
21        if ($admin_info) {
22            $data['content'] = $this->getProvince();
23            $this->load->view('reportprovince/index', $data);
24        } else {
25            $this->load->view('login');
26        }
27    }
28
29    public function getProvince($filters = array()) {
30
31        $this->load->model('reportmodel');
32        $data['date'] = 1;
33        $data['month'] = date("m");
34        $data['year'] = date("Y");
35        $data['to_date'] = 31;
36        $data['to_month'] = date("m");
37        $data['to_year'] = date("Y");
38        if ($this->input->post('month')) {
39            $data['month'] = $this->input->post('month');
40            $data['year'] = $this->input->post('year');
41        }
42        $data['provinces'] = $this->reportmodel->getProvinces($data);
43
44        if ($this->input->is_ajax_request()) {
45            return $this->load->view('reportprovince/province', $data);
46        }
47        return $this->load->view('reportprovince/province', $data, true);
48    }
49
50 
51
52    public function export() {
53        $this->load->model('reportmodel');
54        $data['month'] = $this->uri->segment(4);
55        $data['year'] = $this->uri->segment(5);
56       
57        $data['provinces'] = $this->reportmodel->getProvinces($data);
58
59        $this->load->library("PHPExcel");
60        $sheet = $this->phpexcel->getActiveSheet();
61        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
62        $sheet->getColumnDimension('A')->setWidth(10);
63        $sheet->getColumnDimension('B')->setWidth(25);
64        $sheet->getColumnDimension('C')->setWidth(25);
65        $sheet->getColumnDimension('D')->setWidth(15);
66        $sheet->getColumnDimension('E')->setWidth(15);
67        $sheet->getColumnDimension('F')->setWidth(15);
68        $sheet->getColumnDimension('G')->setWidth(15);
69        $sheet->getColumnDimension('H')->setWidth(15);
70        $sheet->getColumnDimension('I')->setWidth(15);
71        $sheet->getColumnDimension('J')->setWidth(15);
72        $sheet->setCellValue('A1', "Báo cáo thuê bao theo tỉnh");
73        $sheet->setCellValue('A2', "Tháng: " . $data['month'] . " - " . $data['year']);
74        //$sheet->setCellValue('C2', "Ngày: ".date('d')." - ".date('m')." - ". date('Y')."");
75        $sheet->setCellValue('A4', "STT");
76        $sheet->setCellValue('B4', "Ngày");
77        $sheet->setCellValue('C4', "Mã Tỉnh/Thành Phố");
78        $sheet->setCellValue('D4', "Tỉnh/Thành phố");
79        $sheet->setCellValue('E4', "TB Ngày");
80        $sheet->setCellValue('F4', "LÅ©y kế TB tháng");
81        $sheet->setCellValue('G4', "Tổng TB Ngày");
82        $sheet->setCellValue('H4', "DT Ngày");
83        $sheet->setCellValue('I4', "LÅ©y kế DT tháng");
84        $sheet->setCellValue('J4', "Tổng DT năm");
85        $dem=0;
86        foreach ($data['provinces'] as $index => $provinces) {
87            $sheet->setCellValue('A' . ($dem + 5), $provinces['stt']);
88            $sheet->setCellValue('B' . ($dem + 5), date('d')." - ".date('m')." - ". date('Y'));
89            $sheet->setCellValue('C' . ($dem + 5), $index);
90            $sheet->setCellValue('D' . ($dem + 5), $provinces['province']);
91            $sheet->setCellValue('E' . ($dem + 5), $provinces['tbng']);
92            $sheet->setCellValue('F' . ($dem + 5), $provinces['tbt']);
93            $sheet->setCellValue('G' . ($dem + 5), $provinces['tbn']);
94            $sheet->setCellValue('H' . ($dem + 5), $provinces['dtng']);
95            $sheet->setCellValue('I' . ($dem + 5), $provinces['dtt']);
96            $sheet->setCellValue('J' . ($dem + 5), $provinces['dtn']);
97            $dem++;
98        }
99        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
100                header('Content-Type: application/vnd.ms-excel');
101        header('Content-Disposition: attachment; filename="thue_bao_' . $data['month'] . "_" . $data['year'] . '.xls"');
102        $writer->save('php://output');
103    }
104   
105}
Note: See TracBrowser for help on using the repository browser.