1 | <?php |
---|
2 | |
---|
3 | if (!defined('BASEPATH')) |
---|
4 | exit('No direct script access allowed'); |
---|
5 | |
---|
6 | class 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 | public function test() |
---|
105 | { |
---|
106 | $input['date']=1; |
---|
107 | $input['month']=1; |
---|
108 | $input['year']=2014; |
---|
109 | $input['to_month']=1; |
---|
110 | $input['to_year']=2015; |
---|
111 | $input['to_date']=15; |
---|
112 | $data=$this->reportmodel->exportPackage($input); |
---|
113 | echo "<pre>"; |
---|
114 | print_r ($data); |
---|
115 | echo "</pre>"; |
---|
116 | } |
---|
117 | } |
---|