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

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

report

File size: 4.4 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    }
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('reportprovince/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        $data['provinces'] = $this->reportmodel->getProvinces($data);
39
40        if ($this->input->is_ajax_request()) {
41            return $this->load->view('reportprovince/province', $data);
42        }
43        return $this->load->view('reportprovince/province', $data, true);
44    }
45
46    public function getdays($data) {
47        $data['month_days'] = 1;
48        if ("" . $data['year'] . "-" . $data['month'] . "" == date("Y-m")) {
49            $data['month_days'] = date("d");
50        } else {
51            $data['month_days'] = cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31 
52        }
53        $data['year_days'] = 1;
54        if ($data['year'] == date("Y")) {
55            $data['year_days'] = date('z') + 1;
56        } else {
57            $data['year_days'] = date("z", mktime(0, 0, 0, 12, 31, $data['year'])) + 1;
58        }
59        return $data;
60    }
61
62    public function export() {
63        $this->load->model('reportmodel');
64        $data['month'] = $this->uri->segment(4);
65        $data['year'] = $this->uri->segment(5);
66        $data = $this->getdays($data);
67        $data['provinces'] = $this->reportmodel->getProvinces($data);
68
69        $this->load->library("PHPExcel");
70        $sheet = $this->phpexcel->getActiveSheet();
71        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
72        $sheet->getColumnDimension('A')->setWidth(10);
73        $sheet->getColumnDimension('B')->setWidth(25);
74        $sheet->getColumnDimension('C')->setWidth(15);
75        $sheet->getColumnDimension('D')->setWidth(15);
76        $sheet->getColumnDimension('E')->setWidth(15);
77        $sheet->getColumnDimension('F')->setWidth(15);
78        $sheet->getColumnDimension('G')->setWidth(15);
79        $sheet->getColumnDimension('H')->setWidth(15);
80        $sheet->setCellValue('A1', "Báo cáo thuê bao theo tỉnh");
81        $sheet->setCellValue('A2', "Tháng: " . $data['month'] . " - " . $data['year']);
82        $sheet->setCellValue('C2', "Ngày: ".date('d')." - ".date('m')." - ". date('Y')."");
83        $sheet->setCellValue('A4', "STT");
84        $sheet->setCellValue('B4', "Tỉnh/Thành phố");
85        $sheet->setCellValue('C4', "TB Ngày");
86        $sheet->setCellValue('D4', "LÅ©y kế TB tháng");
87        $sheet->setCellValue('E4', "Tổng TB Ngày");
88        $sheet->setCellValue('F4', "DT Ngày");
89        $sheet->setCellValue('G4', "LÅ©y kế DT tháng");
90        $sheet->setCellValue('H4', "Tổng DT năm");
91
92        foreach ($data['provinces'] as $index => $provinces) {
93            $sheet->setCellValue('A' . ($index + 5), $provinces['stt']);
94            $sheet->setCellValue('B' . ($index + 5), $provinces['province']);
95            $sheet->setCellValue('C' . ($index + 5), $provinces['tbng']);
96            $sheet->setCellValue('D' . ($index + 5), $provinces['tbt']);
97            $sheet->setCellValue('E' . ($index + 5), $provinces['tbn']);
98            $sheet->setCellValue('F' . ($index + 5), $provinces['dtng']);
99            $sheet->setCellValue('G' . ($index + 5), $provinces['dtt']);
100            $sheet->setCellValue('H' . ($index + 5), $provinces['dtn']);
101        }
102        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
103                header('Content-Type: application/vnd.ms-excel');
104        header('Content-Disposition: attachment; filename="thue_bao_' . $data['month'] . "_" . $data['year'] . '.xls"');
105        $writer->save('php://output');
106    }
107
108}
Note: See TracBrowser for help on using the repository browser.