Index: pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 764)
+++ pro-violet-viettel/sourcecode/application/modules/admin/controllers/user.php	(revision 765)
@@ -1,189 +1,170 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
 
-class User extends MX_Controller
-{
-	
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
+
+class User extends MX_Controller {
 	const TOKENPW = 'violet';
-	
-	public function __construct()
-	{
-		parent::__construct();
-		$this->load->helper('cookie');
+	public function __construct() {
+		parent::__construct ();
+		$this->load->helper ( 'cookie' );
+		$this->load->helper('language');
+		$this->lang->load('messages', 'message');
 	}
 	
-	public function index()
-	{
-		$admin_info = $this->session->userdata('adminInfo');
-		if ($admin_info)
-		{
-			$data['content'] = $this->get_users();
-			$this->load->view('user/index', $data);
-		}else
-		{
-			$this->load->view('login');
+	public function index() {
+		$admin_info = $this->session->userdata ( 'adminInfo' );
+		if ($admin_info) {
+			$data ['content'] = $this->get_users ();
+			$this->load->view ( 'user/index', $data );
+		} else {
+			$this->load->view ( 'login' );
 		}
 	}
 	
-	public function get_users()
-	{
-		$this->load->helper('pagging');
-		$this->load->model('user_model');
-		$data['current_page'] = $this->uri->segment(4, 1);
-		$data['itemsoptions'] = array(10, 25, 50, 100);
-		$data['perpage'] = 10;
-		$data['statusoptions'] = array(0=>"Táº¥t cáº£", 1=>"ÄÃ£ ÄÄng kÃœ", 2=>"DÃ¹ng thá»­");
-		$data['status'] = 0;
-		if ($this->input->post('status')) 
-		{
-			$data['status'] = (int)$this->input->post('status') ;
+	public function get_users() {
+		$this->load->helper ( 'pagging' );
+		$this->load->model ( 'user_model' );
+		$provinces = lang('_PROVINCES_');
+		error_log(var_export($provinces, TRUE), 3, '/srv/www/sbg/log/provinces.log');
+		
+		$data ['current_page'] = $this->uri->segment ( 4, 1 );
+		$data ['itemsoptions'] = array (
+				10,
+				25,
+				50,
+				100 
+		);
+		$data ['perpage'] = 10;
+		$data ['statusoptions'] = array (
+				0 => "Táº¥t cáº£",
+				1 => "ÄÃ£ ÄÄng kÃœ",
+				2 => "DÃ¹ng thá»­" 
+		);
+		$data ['status'] = 0;
+		if ($this->input->post ( 'status' )) {
+			$data ['status'] = ( int ) $this->input->post ( 'status' );
 		}
-		$data['keyword'] = "";
-		$data['sorting_order']="sorting_desc";
-        $data['sorting_field']="created_time";
-		if ($this->input->post('sorting_order')) {
-			if ($this->input->post('sorting_order') != "sorting")
-			{
-				$data['sorting_order'] = $this->input->post('sorting_order');
-				$data['sorting_field'] = $this->input->post('sorting_field'); 
+		$data ['keyword'] = "";
+		$data ['sorting_order'] = "sorting_desc";
+		$data ['sorting_field'] = "created_time";
+		if ($this->input->post ( 'sorting_order' )) {
+			if ($this->input->post ( 'sorting_order' ) != "sorting") {
+				$data ['sorting_order'] = $this->input->post ( 'sorting_order' );
+				$data ['sorting_field'] = $this->input->post ( 'sorting_field' );
 			}
 		}
-		if ($this->input->post('items')) 
-		{
-			$data['perpage'] = $this->input->post('items');
+		if ($this->input->post ( 'items' )) {
+			$data ['perpage'] = $this->input->post ( 'items' );
 		}
-		if ($this->input->post('keyword')) {
-            $data['keyword'] = $this->input->post('keyword');
-        }
-		$data['daterange_start'] = "";
-		$data['daterange_end'] = "";
-		if ($this->input->post('daterange')){
-			$daterange = explode(" - ", $this->input->post('daterange'));
-			$daterange[0] = str_replace('/', '-', $daterange[0]);
-			$daterange[1] = str_replace('/', '-', $daterange[1]);
-			$data['daterange_start'] = date('Y-m-d H:i:s', strtotime($daterange[0]));
-			$data['daterange_end'] = date('Y-m-d H:is:s', strtotime($daterange[1].' + 1 day'));
+		if ($this->input->post ( 'keyword' )) {
+			$data ['keyword'] = $this->input->post ( 'keyword' );
 		}
-		$data['start'] = ($data['current_page'] - 1) * $data['perpage'];
-		$data['total'] = $this->user_model->get_total_users($data);
-		$us = $this->user_model->get_list_users($data);
-		$users = array();
+		$data ['daterange_start'] = "";
+		$data ['daterange_end'] = "";
+		if ($this->input->post ( 'daterange' )) {
+			$daterange = explode ( " - ", $this->input->post ( 'daterange' ) );
+			$daterange [0] = str_replace ( '/', '-', $daterange [0] );
+			$daterange [1] = str_replace ( '/', '-', $daterange [1] );
+			$data ['daterange_start'] = date ( 'Y-m-d H:i:s', strtotime ( $daterange [0] ) );
+			$data ['daterange_end'] = date ( 'Y-m-d H:is:s', strtotime ( $daterange [1] . ' + 1 day' ) );
+		}
+		$data ['start'] = ($data ['current_page'] - 1) * $data ['perpage'];
+		$data ['total'] = $this->user_model->get_total_users ( $data );
+		$us = $this->user_model->get_list_users ( $data );
+		$users = array ();
 		
-		foreach($us as $u) {
-			$id = $u['us_id'];
-			//$username = $this->get_username($id);
-			$userinfo = $this->get_userinfo($id);
-			if($userinfo){
-				$u['username'] = $userinfo['username'];
-				$u['province'] = $userinfo['province'];
-				array_push($users, $u);
+		foreach ( $us as $u ) {
+			$u ['province'] = isset($provinces[$u ['province']]) ? $provinces[$u ['province']] : $u ['province'];
+			$userinfo = $this->get_userinfo ( $u ['us_id'] );
+			if ($userinfo) {
+				$u ['username'] = $userinfo ['username'];
 			}
+			array_push ( $users, $u );
 		}
 		
-		$data['users'] = $users;
-		$data['paging_url'] = base_url() . "admin/nguoi_dung/trang/";
-		$data['num_links'] = 2;
-		$data['paging'] = pagging($data);
-		if ($this->input->is_ajax_request())
-		{
-			return $this->load->view('user/listview', $data);
+		$data ['users'] = $users;
+		$data ['paging_url'] = base_url () . "admin/nguoi_dung/trang/";
+		$data ['num_links'] = 2;
+		$data ['paging'] = pagging ( $data );
+		
+		if ($this->input->is_ajax_request ()) {
+			return $this->load->view ( 'user/listview', $data );
 		}
-		return $this->load->view('user/listview', $data, true);
+		return $this->load->view ( 'user/listview', $data, true );
 	}
 	
-	public function edit_user()
-	{
-		$admin_info = $this->session->userdata('adminInfo');
-		if ($admin_info)
-		{
-			$input = $this->input->post();
-			$result = array();
-			$result['success'] = 0;
-			$us_id = (int)$this->uri->segment(4, 0);
-			if ($us_id==0){
-				$result['success'] = 0;
-			}else
-			{
-				$this->load->model('user_model');
-				$input['updated_time'] = date("Y-m-d H:i:s");
-				$this->user_model->update($us_id, $input);
-				$result['success'] = 1;
+	public function edit_user() {
+		$admin_info = $this->session->userdata ( 'adminInfo' );
+		if ($admin_info) {
+			$input = $this->input->post ();
+			$result = array ();
+			$result ['success'] = 0;
+			$us_id = ( int ) $this->uri->segment ( 4, 0 );
+			if ($us_id == 0) {
+				$result ['success'] = 0;
+			} else {
+				$this->load->model ( 'user_model' );
+				$input ['updated_time'] = date ( "Y-m-d H:i:s" );
+				$this->user_model->update ( $us_id, $input );
+				$result ['success'] = 1;
 			}
-			echo json_encode($result);
-		}else
-		{
-			$this->load->view('login');
+			echo json_encode ( $result );
+		} else {
+			$this->load->view ( 'login' );
 		}
 	}
 	
-	public function delete_user()
-	{
-		$admin_info = $this->session->userdata('adminInfo');
-		if ($admin_info)
-		{
-			$result = array();
-			$result['success'] = 0;
-			$us_id = (int)$this->uri->segment(4, 0);
-			if ($us_id == 0){
-				$result['success'] = 0;
-			}else
-			{
-				$this->load->model('user_model');
-				$this->user_model->delete($us_id);
-				$result['success'] = 1;
+	public function delete_user() {
+		$admin_info = $this->session->userdata ( 'adminInfo' );
+		if ($admin_info) {
+			$result = array ();
+			$result ['success'] = 0;
+			$us_id = ( int ) $this->uri->segment ( 4, 0 );
+			if ($us_id == 0) {
+				$result ['success'] = 0;
+			} else {
+				$this->load->model ( 'user_model' );
+				$this->user_model->delete ( $us_id );
+				$result ['success'] = 1;
 			}
-			echo json_encode($result);
-		}else
-		{
-			$this->load->view('login');
+			echo json_encode ( $result );
+		} else {
+			$this->load->view ( 'login' );
 		}
 	}
 	
-	public function get_user_by_id()
-	{
-		$admin_info = $this->session->userdata('adminInfo');
-		if ($admin_info)
-		{
-			$result = array();
-			$result['success'] = 0;
-			$us_id = (int)$this->uri->segment(4, 0);
-			if ($us_id == 0)
-			{
-				$result['success'] = 0;	
-			}else
-			{
-				$this->load->model('user_model');
-				$data = $this->user_model->search_by_id($us_id);
-				$result['item'] = $data;
-				$result['success'] = 1;
+	public function get_user_by_id() {
+		$admin_info = $this->session->userdata ( 'adminInfo' );
+		if ($admin_info) {
+			$result = array ();
+			$result ['success'] = 0;
+			$us_id = ( int ) $this->uri->segment ( 4, 0 );
+			if ($us_id == 0) {
+				$result ['success'] = 0;
+			} else {
+				$this->load->model ( 'user_model' );
+				$data = $this->user_model->search_by_id ( $us_id );
+				$result ['item'] = $data;
+				$result ['success'] = 1;
 			}
-			echo json_encode($result);
-		}else
-		{
-			$this->load->view('login');
+			echo json_encode ( $result );
+		} else {
+			$this->load->view ( 'login' );
 		}
 	}
 	
-	private function get_userinfo($us_id)
-	{
+	private function get_userinfo($us_id) {
 		$src = 'violet';
-		$token = md5($us_id.self::TOKENPW);
-		$this->load->model('user_model');
-		$data = $this->user_model->get_user_info($src, $us_id, $token);
-		//var_dump($data);
-		$result = array();
-		parse_str($data, $result);
+		$token = md5 ( $us_id . self::TOKENPW );
+		$this->load->model ( 'user_model' );
+		$data = $this->user_model->get_user_info ( $src, $us_id, $token );
+		// var_dump($data);
+		$result = array ();
+		parse_str ( $data, $result );
 		return $result;
 		/*
-		if (strpos($data, '&')){
-			$arr_users = explode("&", $data);
-			$str_username = $arr_users[1];
-			$arr_username = explode("=", $str_username);
-			return $arr_username[1];
-		}else
-		{
-			return "";
-		}*/
-
+		 * if (strpos($data, '&')){ $arr_users = explode("&", $data); $str_username = $arr_users[1]; $arr_username = explode("=", $str_username); return $arr_username[1]; }else { return ""; }
+		 */
 	}
-	
 }
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php	(revision 764)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php	(revision 765)
@@ -1,213 +1,254 @@
 <?php
-
-if (!defined('BASEPATH'))
-    exit('No direct script access allowed');
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 
 class Reportmodel extends MY_Model {
-
-    protected $table_name = 'tblpaidlog';
-    protected $id_name = 'id';
-
-    function __construct() {
-        parent::__construct();
-        $this->load->helper('language');
-        $this->lang->load('messages', 'message');
-    }
-
-    function getProvinces($input) {
-
-        $from="tblpaidlog.paid_time >= '" . $input['year'] . "-" . $input['month'] . "-" . $input['date'] . " 00:00:00'";
-        $to="tblpaidlog.paid_time <= '" . $input['to_year'] . "-" . $input['to_month'] . "-" . $input['to_date'] . " 23:59:59'";
-        
-        $provinces = lang('_PROVINCES_');
-        // Tinh doanh thu theo tinh theo nam
-        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >= '" . $input['year'] . "-01-01' AND tblpaidlog.paid_time <= '" . ($input['year'] + 1) . "-01-01' GROUP BY tbluser.province";
-        $query = $this->db->query($sql);
-        $dtns = $query->result_array();
-        
-        // tinh doanh thu theo thang
-        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE $from AND $to  GROUP BY tbluser.province";
-        $query = $this->db->query($sql);
-        $dtts = $query->result_array();
-        
-        // tinh doanh thu trong ngay hien tai
-        if (isset($input['to_month']))
-        {
-        $sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >= '" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 00:00:00' AND  tblpaidlog.paid_time <= '" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 23:59:59'  GROUP BY tbluser.province";
-        }
-        $query = $this->db->query($sql);
-        $dtng = $query->result_array();
-
-        // Tinh thue bao theo tinh theo nam
-        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input['year'] . "-01-01' AND tbluser.created_time <= '" . ($input['year'] + 1) . "-01-01' GROUP BY tbluser.province";
-        $query = $this->db->query($sql);
-        $tbns = $query->result_array();
-
-        // tinh thue bao theo thang
-        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND  $to GROUP BY tbluser.province";
-        $query = $this->db->query($sql);
-        $tbts = $query->result_array();
-        
-         // tinh thue bao theo ngay
-        $sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >='" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 00:00:00' AND tbluser.created_time <= '" . $input['to_year'] . "-" . $input['to_month'] . "-".$input['to_date']." 23:59:59'  GROUP BY tbluser.province";
-        
-        $query = $this->db->query($sql);
-        $tbng = $query->result_array(); 
-        
-
-        $dem=1;
-        foreach ($provinces as $index2 => $province) {
-            $provinces[$index2] = array("stt" => ($dem), "province" => $province, "dtn" => 0, "dtt" => 0, "dtng" => 0, "tbn" => 0, "tbt" => 0, "tbng" => 0);
-            foreach ($dtns as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['dtn'] = $data['total'];
-                }
-            } 
-            foreach ($dtng as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['dtng'] = $data['total'];
-                }
-            }
-            foreach ($dtts as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['dtt'] = $data['total'];
-                    
-                }
-            }
-
-            foreach ($tbns as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['tbn'] = $data['total'];
-                }
-            }
-            foreach ($tbng as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['tbng'] = $data['total'];
-                }
-            }
-            foreach ($tbts as $data) {
-                if ($index2 == $data['province']) {
-                    $provinces[$index2]['tbt'] = $data['total'];
-                }
-            }
-            $dem++;
-        }
-       
-        return $provinces;
-    }
-
-    function getPackages($input) {
-
-        $provinces = lang('_PROVINCES_');
-        // tinh thue bao theo thang
-        $sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id  WHERE tbluser.created_time >= '" . $input['year'] . "-" . $input['month'] . "-" . $input['date'] . "' AND tbluser.created_time <= '" . $input['to_year'] . "-" . $input['to_month'] . "-" . $input['to_date'] . "' AND tblservicepackage.p_period > 0 ";
-        $query = $this->db->query($sql);
-        $users = $query->result_array();
-
-
-        $sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
-        $query = $this->db->query($sql);
-        $packages = $query->result_array();
-        foreach ($packages as $index => $package) {
-            $packages[$index]['users'] = array();
-            foreach ($users as $user) {
-                if ($user['p_id'] == $package['p_id']) {
-                    $packages[$index]['users'][] = $user;
-                }
-            }
-        }
-
-        foreach ($provinces as $index => $province) {
-            $provinces[$index] = array("province" => $province);
-        }
-        $dem=1;
-        foreach ($provinces as $index => $province) {
-            $provinces[$index]['stt'] = $dem;
-            $provinces[$index]['total'] = 0;
-            $totaluser = 0;
-            foreach ($packages as $index2 => $package) {
-                $provinces[$index]['packages'][$package['p_name']]['users'] = array();
-                $provinces[$index]['packages'][$package['p_name']]['total'] = 0;
-                $total = 0;
-                foreach ($package['users'] as $user) {
-                    if ($index == $user['province']) {
-                        $total = $total + 1;
-                        $totaluser = $totaluser + 1;
-                        $provinces[$index]['total'] = $totaluser;
-                        $provinces[$index]['packages'][$package['p_name']]['total'] = $total;
-
-                        $provinces[$index]['packages'][$package['p_name']]['users'][] = $user;
-                    }
-                }
-            }
-            $dem++;
-        }
-        foreach ($provinces as $index => $province) {
-            foreach ($packages as $index2 => $package) {
-                $provinces[$index]['packages'][$package['p_name']]['percent'] = 0;
-                if ($provinces[$index]['packages'][$package['p_name']]['total'] > 0 && $province['total'] > 0) {
-                    $provinces[$index]['packages'][$package['p_name']]['percent'] = round($provinces[$index]['packages'][$package['p_name']]['total'] / $province['total'], 2) * 100;
-                }
-            }
-        }
-
-        $data['packages'] = $packages;
-        $data['provinces'] = $provinces;
-        return $data;
-    }
-    public function exportProvince($input)
-    {   
-        //$input['date']=1;
-        //$input['month']=1;
-        //$input['year']=2014;
-        //$input['to_month']=1;
-        //$input['to_year']=2015;
-        //$input['to_date']=15;
-        if (isset($input['to_month']))
-        {
-            $date=$input['to_year'].$input['to_month'].$input['to_date'];
-        }
-        else {
-            $date=date("Ymd");
-        }
-        $provinces=array();
-        $data=$this->getProvinces($input);
-        foreach ($data as $index=>$province)
-        {
-            $provinces[]=array("stt"=>$province['stt'],"ngay"=>$date,"ma"=>$index,"tinh"=>$province['province'],"thue_bao_ngay"=>$province['tbng'],"thue_bao_thang"=>$province['tbt'],"thue_bao_nam"=>$province['tbn'],"doanh_thu_ngay"=>$province['dtng'],"doanh_thu_thang"=>$province['dtt'],"doanh_thu_nam"=>$province['dtn']);
-        }
-        return $provinces;
-    }
-    public function exportPackage($input)
-    {
-       // $input['date']=1;
-        //$input['month']=1;
-      //  $input['year']=2014;
-      // $input['to_month']=1;
-       // $input['to_year']=2015;
-       // $input['to_date']=15;
-        if (isset($input['month']))
-        {
-            $date=$input['year'].$input['month'];
-        }
-        else {
-            $date=date("Ym");
-        }
-        $result=array();
-        $data=$this->getPackages($input);
-        $data=$data['provinces'];
-        foreach ($data as $index=>$province)
-        {
-                $package=array();
-                foreach ($province['packages'] as $index2=>$packages)
-                {
-                    $package=  array_merge($package,array("tong_so_".$index2=>$packages['total'],"ti_le_".$index2=>$packages['percent']));
-                }
-                $tong=array("tong_so_tb"=>$province['total']);
-                $province=array("stt"=>$province['stt'],"ngay"=>$date,"ma"=>$index,"tinh"=>$province['province']);
-                $provinces[]= array_merge($province,$package,$tong);
-        }
-        return $provinces;
-    }
-
+	
+	protected $table_name = 'tblpaidlog';	
+	protected $id_name = 'id';
+	
+	/**
+	 * 
+	 */
+	function __construct() {
+		parent::__construct ();
+		$this->load->helper ( 'language' );
+		$this->lang->load ( 'messages', 'message' );
+	}
+	
+	/**
+	 * 
+	 * @param unknown $input
+	 * @return Ambigous <multitype:number unknown , unknown, string>
+	 */
+	function getProvinces($input) {
+		$from = "tblpaidlog.paid_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . " 00:00:00'";
+		$to = "tblpaidlog.paid_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59'";
+		
+		$provinces = lang ( '_PROVINCES_' );
+		// Tinh doanh thu theo tinh theo nam
+		$sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >= '" . $input ['year'] . "-01-01' AND tblpaidlog.paid_time <= '" . ($input ['year'] + 1) . "-01-01' GROUP BY tbluser.province";
+		$query = $this->db->query ( $sql );
+		$dtns = $query->result_array ();
+		
+		// tinh doanh thu theo thang
+		$sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE $from AND $to  GROUP BY tbluser.province";
+		$query = $this->db->query ( $sql );
+		$dtts = $query->result_array ();
+		
+		// tinh doanh thu trong ngay hien tai
+		if (isset ( $input ['to_month'] )) {
+			$sql = "SELECT *,SUM(amount) as total FROM tblpaidlog LEFT JOIN tbluser ON tbluser.us_id=tblpaidlog.us_id WHERE tblpaidlog.paid_time >= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 00:00:00' AND  tblpaidlog.paid_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59'  GROUP BY tbluser.province";
+		}
+		$query = $this->db->query ( $sql );
+		$dtng = $query->result_array ();
+		
+		// Tinh thue bao theo tinh theo nam
+		$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01' GROUP BY tbluser.province";
+		$query = $this->db->query ( $sql );
+		$tbns = $query->result_array ();
+		
+		// tinh thue bao theo thang
+		$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE $from AND  $to GROUP BY tbluser.province";
+		$query = $this->db->query ( $sql );
+		$tbts = $query->result_array ();
+		
+		// tinh thue bao theo ngay
+		$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >='" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 00:00:00' AND tbluser.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59'  GROUP BY tbluser.province";
+		
+		$query = $this->db->query ( $sql );
+		$tbng = $query->result_array ();
+		
+		$dem = 1;
+		
+		foreach ( $provinces as $index2 => $province ) {
+			$provinces [$index2] = array (
+					"stt" => ($dem),
+					"province" => $province,
+					"dtn" => 0,
+					"dtt" => 0,
+					"dtng" => 0,
+					"tbn" => 0,
+					"tbt" => 0,
+					"tbng" => 0 
+			);
+			foreach ( $dtns as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['dtn'] = $data ['total'];
+				}
+			}
+			foreach ( $dtng as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['dtng'] = $data ['total'];
+				}
+			}
+			foreach ( $dtts as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['dtt'] = $data ['total'];
+				}
+			}
+			
+			foreach ( $tbns as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['tbn'] = $data ['total'];
+				}
+			}
+			foreach ( $tbng as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['tbng'] = $data ['total'];
+				}
+			}
+			foreach ( $tbts as $data ) {
+				if ($index2 == $data ['province']) {
+					$provinces [$index2] ['tbt'] = $data ['total'];
+				}
+			}
+			$dem ++;
+		}
+		
+		return $provinces;
+	}
+	
+	/**
+	 * 
+	 * @param unknown $input
+	 * @return Ambigous <multitype:, number, string>
+	 */
+	function getPackages($input) {
+		$provinces = lang ( '_PROVINCES_' );
+		// tinh thue bao theo thang
+		$sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id  WHERE tbluser.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 ";
+		$query = $this->db->query ( $sql );
+		$users = $query->result_array ();
+		
+		$sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
+		$query = $this->db->query ( $sql );
+		$packages = $query->result_array ();
+		foreach ( $packages as $index => $package ) {
+			$packages [$index] ['users'] = array ();
+			foreach ( $users as $user ) {
+				if ($user ['p_id'] == $package ['p_id']) {
+					$packages [$index] ['users'] [] = $user;
+				}
+			}
+		}
+		
+		foreach ( $provinces as $index => $province ) {
+			$provinces [$index] = array (
+					"province" => $province 
+			);
+		}
+		$dem = 1;
+		foreach ( $provinces as $index => $province ) {
+			$provinces [$index] ['stt'] = $dem;
+			$provinces [$index] ['total'] = 0;
+			$totaluser = 0;
+			foreach ( $packages as $index2 => $package ) {
+				$provinces [$index] ['packages'] [$package ['p_name']] ['users'] = array ();
+				$provinces [$index] ['packages'] [$package ['p_name']] ['total'] = 0;
+				$total = 0;
+				foreach ( $package ['users'] as $user ) {
+					if ($index == $user ['province']) {
+						$total = $total + 1;
+						$totaluser = $totaluser + 1;
+						$provinces [$index] ['total'] = $totaluser;
+						$provinces [$index] ['packages'] [$package ['p_name']] ['total'] = $total;
+						
+						$provinces [$index] ['packages'] [$package ['p_name']] ['users'] [] = $user;
+					}
+				}
+			}
+			$dem ++;
+		}
+		foreach ( $provinces as $index => $province ) {
+			foreach ( $packages as $index2 => $package ) {
+				$provinces [$index] ['packages'] [$package ['p_name']] ['percent'] = 0;
+				if ($provinces [$index] ['packages'] [$package ['p_name']] ['total'] > 0 && $province ['total'] > 0) {
+					$provinces [$index] ['packages'] [$package ['p_name']] ['percent'] = round ( $provinces [$index] ['packages'] [$package ['p_name']] ['total'] / $province ['total'], 2 ) * 100;
+				}
+			}
+		}
+		
+		$data ['packages'] = $packages;
+		$data ['provinces'] = $provinces;
+		return $data;
+	}
+	
+	/**
+	 * 
+	 * @param unknown $input
+	 * @return multitype:multitype:unknown string Ambigous <Ambigous, multitype:number unknown , unknown, string>
+	 */
+	public function exportProvince($input) {
+		// $input['date']=1;
+		// $input['month']=1;
+		// $input['year']=2014;
+		// $input['to_month']=1;
+		// $input['to_year']=2015;
+		// $input['to_date']=15;
+		if (isset ( $input ['to_month'] )) {
+			$date = $input ['to_year'] . $input ['to_month'] . $input ['to_date'];
+		} else {
+			$date = date ( "Ymd" );
+		}
+		$provinces = array ();
+		$data = $this->getProvinces ( $input );
+		foreach ( $data as $index => $province ) {
+			$provinces [] = array (
+					"stt" => $province ['stt'],
+					"ngay" => $date,
+					"ma" => $index,
+					"tinh" => $province ['province'],
+					"thue_bao_ngay" => $province ['tbng'],
+					"thue_bao_thang" => $province ['tbt'],
+					"thue_bao_nam" => $province ['tbn'],
+					"doanh_thu_ngay" => $province ['dtng'],
+					"doanh_thu_thang" => $province ['dtt'],
+					"doanh_thu_nam" => $province ['dtn'] 
+			);
+		}
+		return $provinces;
+	}
+	
+	/**
+	 * 
+	 * @param unknown $input
+	 * @return multitype:
+	 */
+	public function exportPackage($input) {
+		// $input['date']=1;
+		// $input['month']=1;
+		// $input['year']=2014;
+		// $input['to_month']=1;
+		// $input['to_year']=2015;
+		// $input['to_date']=15;
+		if (isset ( $input ['month'] )) {
+			$date = $input ['year'] . $input ['month'];
+		} else {
+			$date = date ( "Ym" );
+		}
+		$result = array ();
+		$data = $this->getPackages ( $input );
+		$data = $data ['provinces'];
+		foreach ( $data as $index => $province ) {
+			$package = array ();
+			foreach ( $province ['packages'] as $index2 => $packages ) {
+				$package = array_merge ( $package, array (
+						"tong_so_" . $index2 => $packages ['total'],
+						"ti_le_" . $index2 => $packages ['percent'] 
+				) );
+			}
+			$tong = array (
+					"tong_so_tb" => $province ['total'] 
+			);
+			$province = array (
+					"stt" => $province ['stt'],
+					"ngay" => $date,
+					"ma" => $index,
+					"tinh" => $province ['province'] 
+			);
+			$provinces [] = array_merge ( $province, $package, $tong );
+		}
+		return $provinces;
+	}
 }
Index: pro-violet-viettel/sourcecode/application/modules/admin/views/user/listview.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/views/user/listview.php	(revision 764)
+++ pro-violet-viettel/sourcecode/application/modules/admin/views/user/listview.php	(revision 765)
@@ -150,5 +150,5 @@
 <?php
 foreach ($users as $user) {
-    ?>
+?>
                                 <tr class="odd">
                                     <td class="center  sorting_1">
