[702] | 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 | } |
---|
| 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 | |
---|
[713] | 28 | public function getProvince($filters = array()) { |
---|
[702] | 29 | |
---|
| 30 | $this->load->model('reportmodel'); |
---|
[713] | 31 | $data['month'] = date("m"); |
---|
| 32 | $data['year'] = date("Y"); |
---|
[702] | 33 | if ($this->input->post('month')) { |
---|
[713] | 34 | $data['month'] = $this->input->post('month'); |
---|
| 35 | $data['year'] = $this->input->post('year'); |
---|
[702] | 36 | } |
---|
[713] | 37 | $data = $this->getdays($data); |
---|
[702] | 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 | |
---|
[713] | 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 |
---|
[702] | 52 | } |
---|
[713] | 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; |
---|
[702] | 60 | } |
---|
| 61 | |
---|
[713] | 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); |
---|
[702] | 68 | |
---|
[713] | 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"); |
---|
[745] | 81 | $sheet->setCellValue('A2', "Tháng: " . $data['month'] . " - " . $data['year']); |
---|
[746] | 82 | $sheet->setCellValue('C2', "Ngà y: ".date('d')." - ".date('m')." - ". date('Y').""); |
---|
[713] | 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); |
---|
[737] | 103 | header('Content-Type: application/vnd.ms-excel'); |
---|
[713] | 104 | header('Content-Disposition: attachment; filename="thue_bao_' . $data['month'] . "_" . $data['year'] . '.xls"'); |
---|
| 105 | $writer->save('php://output'); |
---|
[702] | 106 | } |
---|
| 107 | |
---|
| 108 | } |
---|