Index: /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportpackage.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportpackage.php	(revision 712)
+++ /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportpackage.php	(revision 713)
@@ -24,43 +24,21 @@
             $this->load->view('login');
         }
-    
     }
 
+    public function getProvince($filters = array()) {
 
+        $this->load->model('reportmodel');
+        $data['month'] = date("m");
+        $data['year'] = date("Y");
+        if ($this->input->post('month')) {
+            $data['month'] = $this->input->post('month');
+            $data['year'] = $this->input->post('year');
+        }
+        $data = $this->getdays($data);
 
-    public function getProvince($filters = array()) {
-        
-        $this->load->model('reportmodel');
-        $data['month']=date("m");
-        $data['year']=date("Y");
-        if ($this->input->post('month')) {
-          $data['month']=$this->input->post('month');
-          $data['year']=$this->input->post('year');
-        }
-        $data['month_days']=1;
-        if("".$data['year']."-".$data['month'].""==date("Y-m"))
-        {
-        $data['month_days']=date("d");
-        }
-        else
-        {
-        $data['month_days']=cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31  
-        }
-        $data['year_days']=1;
-        if($data['year']== date("Y"))
-        {
-        $data['year_days']=date('z') + 1;
-        }
-        else
-        {
-        $data['year_days']=date("z", mktime(0,0,0,12,31,$data['year'])) + 1;
-        }
-        
-
-        
-        $result=$this->reportmodel->getPackages($data);
+        $result = $this->reportmodel->getPackages($data);
         $data['provinces'] = $result['provinces'];
         $data['packages'] = $result['packages'];
-        
+
         if ($this->input->is_ajax_request()) {
             return $this->load->view('reportpackage/province', $data);
@@ -69,31 +47,73 @@
     }
 
-    private function get_fullname($us_id) {
-        $fullname="";
-        $src = 'violet';
-        $token = md5($us_id . self::TOKENPW);
-        $this->load->model('user_model');
-        $data = $this->user_model->get_user_info($src, $us_id, $token);
-        parse_str($data,$data);
-        if (isset($data['fullname']))
-        {
-            $fullname=$data['fullname'];
+    public function getdays($data) {
+        $data['month_days'] = 1;
+        if ("" . $data['year'] . "-" . $data['month'] . "" == date("Y-m")) {
+            $data['month_days'] = date("d");
+        } else {
+            $data['month_days'] = cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31  
         }
-        return $fullname;
+        $data['year_days'] = 1;
+        if ($data['year'] == date("Y")) {
+            $data['year_days'] = date('z') + 1;
+        } else {
+            $data['year_days'] = date("z", mktime(0, 0, 0, 12, 31, $data['year'])) + 1;
+        }
+        return $data;
     }
 
-    public function test() {
+    public function export() {
+        $this->load->model('reportmodel');
+        $data['month'] = $this->uri->segment(4);
+        $data['year'] = $this->uri->segment(5);
+        $data = $this->getdays($data);
+        $result = $this->reportmodel->getPackages($data);
+        $data['provinces'] = $result['provinces'];
+        $data['packages'] = $result['packages'];
 
-            $provinces=lang('_PROVINCES_');
-            $sql="SELECT * FROM tbluser";
-            $query = $this->db->query ($sql);
-		$result = $query->result_array();
-            foreach ($result as $user)
-            {
-                $p=$provinces[rand(0,62)];
-                $user['province']=$p;
-                $this->db->where('us_id', $user['us_id']);
-		$this->db->update('tbluser', $user);
+        $this->load->library("PHPExcel");
+        $sheet = $this->phpexcel->getActiveSheet();
+        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
+        $sheet->getColumnDimension('A')->setWidth(10);
+        $sheet->getColumnDimension('B')->setWidth(25);
+        $sheet->getColumnDimension('C')->setWidth(15);
+        $sheet->getColumnDimension('D')->setWidth(15);
+        $sheet->getColumnDimension('E')->setWidth(15);
+        $sheet->getColumnDimension('F')->setWidth(15);
+        $sheet->getColumnDimension('G')->setWidth(15);
+        $sheet->getColumnDimension('H')->setWidth(15);
+        $sheet->setCellValue('A1', "BÃ¡o cÃ¡o doanh thu theo tá»nh");
+        $sheet->setCellValue('A2', "Thá»i gian: " . $data['month'] . " - " . $data['year']);
+        $sheet->setCellValue('A4', "STT");
+        $sheet->setCellValue('B4', "Tá»nh/ThÃ nh phá»");
+        $chars = array("A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L");
+        $dem = 1;
+        foreach ($data['packages'] as $package) {
+            $dem++;
+            $sheet->setCellValue($chars[$dem] . ($index + 4), $package['p_name']);
+            $dem++;
+            $sheet->setCellValue($chars[$dem] . ($index + 4), "Tá» lá» %");
+        }
+        $dem++;
+        $sheet->setCellValue($chars[$dem] . ($index + 4), "Tá»ng TB");
+
+
+        foreach ($data['provinces'] as $index => $provinces) {
+
+            $sheet->setCellValue('A' . ($index + 5), $provinces['stt']);
+            $sheet->setCellValue('B' . ($index + 5), $provinces['province']);
+            $dem = 1;
+            foreach ($provinces['packages'] as $package) {
+                $dem++;
+                $sheet->setCellValue($chars[$dem] . ($index + 5), $package['total']);
+                $dem++;
+                $sheet->setCellValue($chars[$dem] . ($index + 5), $package['percent']);
             }
+            $dem++;
+            $sheet->setCellValue($chars[$dem] . ($index + 5), $provinces['total']);
+        }
+        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
+        header('Content-Disposition: attachment; filename="doanh_thu_' . $data['month'] . "_" . $data['year'] . '.xls"');
+        $writer->save('php://output');
     }
 
Index: /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportprovince.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportprovince.php	(revision 712)
+++ /pro-violet-viettel/sourcecode/application/modules/admin/controllers/reportprovince.php	(revision 713)
@@ -24,43 +24,17 @@
             $this->load->view('login');
         }
-    
     }
 
+    public function getProvince($filters = array()) {
 
-
-    public function getProvince($filters = array()) {
-        
         $this->load->model('reportmodel');
-        $data['month']=date("m");
-        $data['year']=date("Y");
+        $data['month'] = date("m");
+        $data['year'] = date("Y");
         if ($this->input->post('month')) {
-          $data['month']=$this->input->post('month');
-          $data['year']=$this->input->post('year');
+            $data['month'] = $this->input->post('month');
+            $data['year'] = $this->input->post('year');
         }
-        $data['month_days']=1;
-        if("".$data['year']."-".$data['month'].""==date("Y-m"))
-        {
-        $data['month_days']=date("d");
-        }
-        else
-        {
-        $data['month_days']=cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31  
-        }
-        $data['year_days']=1;
-        if($data['year']== date("Y"))
-        {
-        $data['year_days']=date('z') + 1;
-        }
-        else
-        {
-        $data['year_days']=date("z", mktime(0,0,0,12,31,$data['year'])) + 1;
-        }
-        
-     
+        $data = $this->getdays($data);
         $data['provinces'] = $this->reportmodel->getProvinces($data);
-
-        foreach ($data['provinces'] as $index => $paidlog) {
-            $data['provinces'][$index]['username'] = @$this->get_fullname($paidlog['us_id']); 
-        }
 
         if ($this->input->is_ajax_request()) {
@@ -70,31 +44,62 @@
     }
 
-    private function get_fullname($us_id) {
-        $fullname="";
-        $src = 'violet';
-        $token = md5($us_id . self::TOKENPW);
-        $this->load->model('user_model');
-        $data = $this->user_model->get_user_info($src, $us_id, $token);
-        parse_str($data,$data);
-        if (isset($data['fullname']))
-        {
-            $fullname=$data['fullname'];
+    public function getdays($data) {
+        $data['month_days'] = 1;
+        if ("" . $data['year'] . "-" . $data['month'] . "" == date("Y-m")) {
+            $data['month_days'] = date("d");
+        } else {
+            $data['month_days'] = cal_days_in_month(CAL_GREGORIAN, $data['month'], $data['year']); // 31  
         }
-        return $fullname;
+        $data['year_days'] = 1;
+        if ($data['year'] == date("Y")) {
+            $data['year_days'] = date('z') + 1;
+        } else {
+            $data['year_days'] = date("z", mktime(0, 0, 0, 12, 31, $data['year'])) + 1;
+        }
+        return $data;
     }
 
-    public function test() {
+    public function export() {
+        $this->load->model('reportmodel');
+        $data['month'] = $this->uri->segment(4);
+        $data['year'] = $this->uri->segment(5);
+        $data = $this->getdays($data);
+        $data['provinces'] = $this->reportmodel->getProvinces($data);
 
-            $provinces=lang('_PROVINCES_');
-            $sql="SELECT * FROM tbluser";
-            $query = $this->db->query ($sql);
-		$result = $query->result_array();
-            foreach ($result as $user)
-            {
-                $p=$provinces[rand(0,62)];
-                $user['province']=$p;
-                $this->db->where('us_id', $user['us_id']);
-		$this->db->update('tbluser', $user);
-            }
+        $this->load->library("PHPExcel");
+        $sheet = $this->phpexcel->getActiveSheet();
+        $sheet->setTitle("bao cao thue bao " . $data['month'] . " - " . $data['year']);
+        $sheet->getColumnDimension('A')->setWidth(10);
+        $sheet->getColumnDimension('B')->setWidth(25);
+        $sheet->getColumnDimension('C')->setWidth(15);
+        $sheet->getColumnDimension('D')->setWidth(15);
+        $sheet->getColumnDimension('E')->setWidth(15);
+        $sheet->getColumnDimension('F')->setWidth(15);
+        $sheet->getColumnDimension('G')->setWidth(15);
+        $sheet->getColumnDimension('H')->setWidth(15);
+        $sheet->setCellValue('A1', "BÃ¡o cÃ¡o thuÃª bao theo tá»nh");
+        $sheet->setCellValue('A2', "Thá»i gian: " . $data['month'] . " - " . $data['year']);
+        $sheet->setCellValue('A4', "STT");
+        $sheet->setCellValue('B4', "Tá»nh/ThÃ nh phá»");
+        $sheet->setCellValue('C4', "TB NgÃ y");
+        $sheet->setCellValue('D4', "LÅ©y káº¿ TB thÃ¡ng");
+        $sheet->setCellValue('E4', "Tá»ng TB NgÃ y");
+        $sheet->setCellValue('F4', "DT NgÃ y");
+        $sheet->setCellValue('G4', "LÅ©y káº¿ DT thÃ¡ng");
+        $sheet->setCellValue('H4', "Tá»ng DT nÄm");
+
+        foreach ($data['provinces'] as $index => $provinces) {
+            $sheet->setCellValue('A' . ($index + 5), $provinces['stt']);
+            $sheet->setCellValue('B' . ($index + 5), $provinces['province']);
+            $sheet->setCellValue('C' . ($index + 5), $provinces['tbng']);
+            $sheet->setCellValue('D' . ($index + 5), $provinces['tbt']);
+            $sheet->setCellValue('E' . ($index + 5), $provinces['tbn']);
+            $sheet->setCellValue('F' . ($index + 5), $provinces['dtng']);
+            $sheet->setCellValue('G' . ($index + 5), $provinces['dtt']);
+            $sheet->setCellValue('H' . ($index + 5), $provinces['dtn']);
+        }
+        $writer = new PHPExcel_Writer_Excel5($this->phpexcel);
+        header('Content-Disposition: attachment; filename="thue_bao_' . $data['month'] . "_" . $data['year'] . '.xls"');
+        $writer->save('php://output');
     }
 
Index: /pro-violet-viettel/sourcecode/application/modules/admin/views/reportpackage/province.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/admin/views/reportpackage/province.php	(revision 712)
+++ /pro-violet-viettel/sourcecode/application/modules/admin/views/reportpackage/province.php	(revision 713)
@@ -7,5 +7,8 @@
             <!-- PAGE CONTENT BEGINS -->
             <div style="padding-bottom:4px" class="table-header">
-                BÃ¡o cÃ¡o doanh thu theo tá»nh / thÃ nh phá»
+                BÃ¡o cÃ¡o doanh thu theo tá»nh / thÃ nh phá» theo gÃ³i cÆ°á»c.
+            <div class="pull-right" style="margin:5px;">
+                    <a style="color:#fff" href="<?php echo base_url();?>admin/reportpackage/export/<?php echo $month;?>/<?php echo $year;?>">Xuáº¥t ra Excel</a>
+                </div>
             </div>
             <!-- PAGE CONTENT BEGINS -->
Index: /pro-violet-viettel/sourcecode/application/modules/admin/views/reportprovince/province.php
===================================================================
--- /pro-violet-viettel/sourcecode/application/modules/admin/views/reportprovince/province.php	(revision 712)
+++ /pro-violet-viettel/sourcecode/application/modules/admin/views/reportprovince/province.php	(revision 713)
@@ -8,4 +8,7 @@
             <div style="padding-bottom:4px" class="table-header">
                 BÃ¡o cÃ¡o doanh thu theo tá»nh / thÃ nh phá»
+                <div class="pull-right" style="margin:5px;">
+                    <a style="color:#fff" href="<?php echo base_url();?>admin/reportprovince/export/<?php echo $month;?>/<?php echo $year;?>">Xuáº¥t ra Excel</a>
+                </div>
             </div>
             <!-- PAGE CONTENT BEGINS -->
