Changeset 713


Ignore:
Timestamp:
Jan 29, 2015 10:36:57 AM (10 years ago)
Author:
quyenla
Message:

Export Excel

Location:
pro-violet-viettel/sourcecode/application/modules/admin
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportpackage.php

    r702 r713  
    2424            $this->load->view('login');
    2525        }
    26    
    2726    }
    2827
     28    public function getProvince($filters = array()) {
    2929
     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);
    3038
    31     public function getProvince($filters = array()) {
    32        
    33         $this->load->model('reportmodel');
    34         $data['month']=date("m");
    35         $data['year']=date("Y");
    36         if ($this->input->post('month')) {
    37           $data['month']=$this->input->post('month');
    38           $data['year']=$this->input->post('year');
    39         }
    40         $data['month_days']=1;
    41         if("".$data['year']."-".$data['month'].""==date("Y-m"))
    42         {
    43         $data['month_days']=date("d");
    44         }
    45         else
    46         {
    47         $data['month_days']=cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31 
    48         }
    49         $data['year_days']=1;
    50         if($data['year']== date("Y"))
    51         {
    52         $data['year_days']=date('z') + 1;
    53         }
    54         else
    55         {
    56         $data['year_days']=date("z", mktime(0,0,0,12,31,$data['year'])) + 1;
    57         }
    58        
    59 
    60        
    61         $result=$this->reportmodel->getPackages($data);
     39        $result = $this->reportmodel->getPackages($data);
    6240        $data['provinces'] = $result['provinces'];
    6341        $data['packages'] = $result['packages'];
    64        
     42
    6543        if ($this->input->is_ajax_request()) {
    6644            return $this->load->view('reportpackage/province', $data);
     
    6947    }
    7048
    71     private function get_fullname($us_id) {
    72         $fullname="";
    73         $src = 'violet';
    74         $token = md5($us_id . self::TOKENPW);
    75         $this->load->model('user_model');
    76         $data = $this->user_model->get_user_info($src, $us_id, $token);
    77         parse_str($data,$data);
    78         if (isset($data['fullname']))
    79         {
    80             $fullname=$data['fullname'];
     49    public function getdays($data) {
     50        $data['month_days'] = 1;
     51        if ("" . $data['year'] . "-" . $data['month'] . "" == date("Y-m")) {
     52            $data['month_days'] = date("d");
     53        } else {
     54            $data['month_days'] = cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31 
    8155        }
    82         return $fullname;
     56        $data['year_days'] = 1;
     57        if ($data['year'] == date("Y")) {
     58            $data['year_days'] = date('z') + 1;
     59        } else {
     60            $data['year_days'] = date("z", mktime(0, 0, 0, 12, 31, $data['year'])) + 1;
     61        }
     62        return $data;
    8363    }
    8464
    85     public function test() {
     65    public function export() {
     66        $this->load->model('reportmodel');
     67        $data['month'] = $this->uri->segment(4);
     68        $data['year'] = $this->uri->segment(5);
     69        $data = $this->getdays($data);
     70        $result = $this->reportmodel->getPackages($data);
     71        $data['provinces'] = $result['provinces'];
     72        $data['packages'] = $result['packages'];
    8673
    87             $provinces=lang('_PROVINCES_');
    88             $sql="SELECT * FROM tbluser";
    89             $query = $this->db->query ($sql);
    90                 $result = $query->result_array();
    91             foreach ($result as $user)
    92             {
    93                 $p=$provinces[rand(0,62)];
    94                 $user['province']=$p;
    95                 $this->db->where('us_id', $user['us_id']);
    96                 $this->db->update('tbluser', $user);
     74        $this->load->library("PHPExcel");
     75        $sheet = $this->phpexcel->getActiveSheet();
     76        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
     77        $sheet->getColumnDimension('A')->setWidth(10);
     78        $sheet->getColumnDimension('B')->setWidth(25);
     79        $sheet->getColumnDimension('C')->setWidth(15);
     80        $sheet->getColumnDimension('D')->setWidth(15);
     81        $sheet->getColumnDimension('E')->setWidth(15);
     82        $sheet->getColumnDimension('F')->setWidth(15);
     83        $sheet->getColumnDimension('G')->setWidth(15);
     84        $sheet->getColumnDimension('H')->setWidth(15);
     85        $sheet->setCellValue('A1', "Báo cáo doanh thu theo tỉnh");
     86        $sheet->setCellValue('A2', "Thời gian: " . $data['month'] . " - " . $data['year']);
     87        $sheet->setCellValue('A4', "STT");
     88        $sheet->setCellValue('B4', "Tỉnh/Thành phố");
     89        $chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L");
     90        $dem = 1;
     91        foreach ($data['packages'] as $package) {
     92            $dem++;
     93            $sheet->setCellValue($chars[$dem] . ($index + 4), $package['p_name']);
     94            $dem++;
     95            $sheet->setCellValue($chars[$dem] . ($index + 4), "Tỉ lệ %");
     96        }
     97        $dem++;
     98        $sheet->setCellValue($chars[$dem] . ($index + 4), "Tổng TB");
     99
     100
     101        foreach ($data['provinces'] as $index => $provinces) {
     102
     103            $sheet->setCellValue('A' . ($index + 5), $provinces['stt']);
     104            $sheet->setCellValue('B' . ($index + 5), $provinces['province']);
     105            $dem = 1;
     106            foreach ($provinces['packages'] as $package) {
     107                $dem++;
     108                $sheet->setCellValue($chars[$dem] . ($index + 5), $package['total']);
     109                $dem++;
     110                $sheet->setCellValue($chars[$dem] . ($index + 5), $package['percent']);
    97111            }
     112            $dem++;
     113            $sheet->setCellValue($chars[$dem] . ($index + 5), $provinces['total']);
     114        }
     115        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
     116        header('Content-Disposition: attachment; filename="doanh_thu_' . $data['month'] . "_" . $data['year'] . '.xls"');
     117        $writer->save('php://output');
    98118    }
    99119
  • pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportprovince.php

    r702 r713  
    2424            $this->load->view('login');
    2525        }
    26    
    2726    }
    2827
     28    public function getProvince($filters = array()) {
    2929
    30 
    31     public function getProvince($filters = array()) {
    32        
    3330        $this->load->model('reportmodel');
    34         $data['month']=date("m");
    35         $data['year']=date("Y");
     31        $data['month'] = date("m");
     32        $data['year'] = date("Y");
    3633        if ($this->input->post('month')) {
    37           $data['month']=$this->input->post('month');
    38           $data['year']=$this->input->post('year');
     34            $data['month'] = $this->input->post('month');
     35            $data['year'] = $this->input->post('year');
    3936        }
    40         $data['month_days']=1;
    41         if("".$data['year']."-".$data['month'].""==date("Y-m"))
    42         {
    43         $data['month_days']=date("d");
    44         }
    45         else
    46         {
    47         $data['month_days']=cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31 
    48         }
    49         $data['year_days']=1;
    50         if($data['year']== date("Y"))
    51         {
    52         $data['year_days']=date('z') + 1;
    53         }
    54         else
    55         {
    56         $data['year_days']=date("z", mktime(0,0,0,12,31,$data['year'])) + 1;
    57         }
    58        
    59      
     37        $data = $this->getdays($data);
    6038        $data['provinces'] = $this->reportmodel->getProvinces($data);
    61 
    62         foreach ($data['provinces'] as $index => $paidlog) {
    63             $data['provinces'][$index]['username'] = @$this->get_fullname($paidlog['us_id']);
    64         }
    6539
    6640        if ($this->input->is_ajax_request()) {
     
    7044    }
    7145
    72     private function get_fullname($us_id) {
    73         $fullname="";
    74         $src = 'violet';
    75         $token = md5($us_id . self::TOKENPW);
    76         $this->load->model('user_model');
    77         $data = $this->user_model->get_user_info($src, $us_id, $token);
    78         parse_str($data,$data);
    79         if (isset($data['fullname']))
    80         {
    81             $fullname=$data['fullname'];
     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 
    8252        }
    83         return $fullname;
     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;
    8460    }
    8561
    86     public function test() {
     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);
    8768
    88             $provinces=lang('_PROVINCES_');
    89             $sql="SELECT * FROM tbluser";
    90             $query = $this->db->query ($sql);
    91                 $result = $query->result_array();
    92             foreach ($result as $user)
    93             {
    94                 $p=$provinces[rand(0,62)];
    95                 $user['province']=$p;
    96                 $this->db->where('us_id', $user['us_id']);
    97                 $this->db->update('tbluser', $user);
    98             }
     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ời gian: " . $data['month'] . " - " . $data['year']);
     82        $sheet->setCellValue('A4', "STT");
     83        $sheet->setCellValue('B4', "Tỉnh/Thành phố");
     84        $sheet->setCellValue('C4', "TB Ngày");
     85        $sheet->setCellValue('D4', "LÅ©y kế TB tháng");
     86        $sheet->setCellValue('E4', "Tổng TB Ngày");
     87        $sheet->setCellValue('F4', "DT Ngày");
     88        $sheet->setCellValue('G4', "LÅ©y kế DT tháng");
     89        $sheet->setCellValue('H4', "Tổng DT năm");
     90
     91        foreach ($data['provinces'] as $index => $provinces) {
     92            $sheet->setCellValue('A' . ($index + 5), $provinces['stt']);
     93            $sheet->setCellValue('B' . ($index + 5), $provinces['province']);
     94            $sheet->setCellValue('C' . ($index + 5), $provinces['tbng']);
     95            $sheet->setCellValue('D' . ($index + 5), $provinces['tbt']);
     96            $sheet->setCellValue('E' . ($index + 5), $provinces['tbn']);
     97            $sheet->setCellValue('F' . ($index + 5), $provinces['dtng']);
     98            $sheet->setCellValue('G' . ($index + 5), $provinces['dtt']);
     99            $sheet->setCellValue('H' . ($index + 5), $provinces['dtn']);
     100        }
     101        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
     102        header('Content-Disposition: attachment; filename="thue_bao_' . $data['month'] . "_" . $data['year'] . '.xls"');
     103        $writer->save('php://output');
    99104    }
    100105
  • pro-violet-viettel/sourcecode/application/modules/admin/views/reportpackage/province.php

    r702 r713  
    77            <!-- PAGE CONTENT BEGINS -->
    88            <div style="padding-bottom:4px" class="table-header">
    9                 Báo cáo doanh thu theo tỉnh / thành phố
     9                Báo cáo doanh thu theo tỉnh / thành phố theo gói cước.
     10            <div class="pull-right" style="margin:5px;">
     11                    <a style="color:#fff" href="<?php echo base_url();?>admin/reportpackage/export/<?php echo $month;?>/<?php echo $year;?>">Xuất ra Excel</a>
     12                </div>
    1013            </div>
    1114            <!-- PAGE CONTENT BEGINS -->
  • pro-violet-viettel/sourcecode/application/modules/admin/views/reportprovince/province.php

    r702 r713  
    88            <div style="padding-bottom:4px" class="table-header">
    99                Báo cáo doanh thu theo tỉnh / thành phố
     10                <div class="pull-right" style="margin:5px;">
     11                    <a style="color:#fff" href="<?php echo base_url();?>admin/reportprovince/export/<?php echo $month;?>/<?php echo $year;?>">Xuất ra Excel</a>
     12                </div>
    1013            </div>
    1114            <!-- PAGE CONTENT BEGINS -->
Note: See TracChangeset for help on using the changeset viewer.