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

Last change on this file since 838 was 818, checked in by namnd, 10 years ago
File size: 5.0 KB
RevLine 
[702]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
[713]28    public function getProvince($filters = array()) {
[702]29
30        $this->load->model('reportmodel');
[761]31        $data['date']=1;
[713]32        $data['month'] = date("m");
33        $data['year'] = date("Y");
[818]34        $data['to_date']= 31;
[761]35        $data['to_month'] = date("m");
36        $data['to_year'] = date("Y");
[702]37        if ($this->input->post('month')) {
[713]38            $data['month'] = $this->input->post('month');
39            $data['year'] = $this->input->post('year');
[702]40        }
[713]41        $data = $this->getdays($data);
[702]42
[713]43        $result = $this->reportmodel->getPackages($data);
[702]44        $data['provinces'] = $result['provinces'];
45        $data['packages'] = $result['packages'];
[818]46                $data['totalVip'] = $result['totalVip'];
[702]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
[713]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 
[702]59        }
[713]60        $data['year_days'] = 1;
[751]61       
[713]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;
[702]68    }
69
[713]70    public function export() {
71        $this->load->model('reportmodel');
[818]72                $data['date']=1;
[713]73        $data['month'] = $this->uri->segment(4);
74        $data['year'] = $this->uri->segment(5);
[818]75                $data['to_date']=31;
76        $data['to_month'] = date("m");
77        $data['to_year'] = date("Y");
[713]78        $data = $this->getdays($data);
79        $result = $this->reportmodel->getPackages($data);
80        $data['provinces'] = $result['provinces'];
81        $data['packages'] = $result['packages'];
[818]82                $data['totalVip'] = $result['totalVip'];
[702]83
[713]84        $this->load->library("PHPExcel");
85        $sheet = $this->phpexcel->getActiveSheet();
86        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
87        $sheet->getColumnDimension('A')->setWidth(10);
88        $sheet->getColumnDimension('B')->setWidth(25);
89        $sheet->getColumnDimension('C')->setWidth(15);
90        $sheet->getColumnDimension('D')->setWidth(15);
91        $sheet->getColumnDimension('E')->setWidth(15);
92        $sheet->getColumnDimension('F')->setWidth(15);
93        $sheet->getColumnDimension('G')->setWidth(15);
94        $sheet->getColumnDimension('H')->setWidth(15);
95        $sheet->setCellValue('A1', "Báo cáo doanh thu theo tỉnh");
96        $sheet->setCellValue('A2', "Thời gian: " . $data['month'] . " - " . $data['year']);
97        $sheet->setCellValue('A4', "STT");
[756]98        $sheet->setCellValue('B4', "Mã Tỉnh/Thành phố");
99        $sheet->setCellValue('C4', "Tỉnh/Thành phố");
[713]100        $chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L");
[756]101        $dem = 2;
[755]102        $stt=1;
[713]103        foreach ($data['packages'] as $package) {
104            $dem++;
[756]105            $sheet->setCellValue($chars[$dem] . "4", $package['p_name']);
[713]106            $dem++;
[756]107            $sheet->setCellValue($chars[$dem] . "4", "Tỉ lệ %");
[755]108       
109            $stt++;
[713]110        }
111        $dem++;
112        $sheet->setCellValue($chars[$dem] . ($index + 4), "Tổng TB");
113
[755]114$stt=1;
[713]115        foreach ($data['provinces'] as $index => $provinces) {
116
[755]117            $sheet->setCellValue('A' . ($stt + 5), $provinces['stt']);
[756]118            $sheet->setCellValue('B' . ($stt + 5), $index);
119            $sheet->setCellValue('C' . ($stt + 5), $provinces['province']);
120            $dem = 2;
[713]121            foreach ($provinces['packages'] as $package) {
122                $dem++;
[755]123                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['total']);
[713]124                $dem++;
[755]125                $sheet->setCellValue($chars[$dem] . ($stt + 5), $package['percent']);
[702]126            }
[713]127            $dem++;
[755]128           
129            $sheet->setCellValue($chars[$dem] . ($stt + 5), $provinces['total']);
130            $stt++;
[713]131        }
132        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
133        header('Content-Disposition: attachment; filename="doanh_thu_' . $data['month'] . "_" . $data['year'] . '.xls"');
134        $writer->save('php://output');
[702]135    }
136
137}
Note: See TracBrowser for help on using the repository browser.