Index: pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php	(revision 838)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/paidlog_model.php	(revision 883)
@@ -13,4 +13,5 @@
 	}
 	function getPaidlogs($data) {
+		
 		if ($data['paid_type'] == 0){
 			$sql = "SELECT SUM(amount) as total_amount FROM tblpaidlog";
@@ -19,4 +20,5 @@
 		}
 		$r = $this->db->query($sql)->row_array();
+		
 		$total_amount = (int)$r['total_amount'];
         $sql = "SELECT * FROM " . $this->table_name. " INNER JOIN tbluser ON tbluser.us_id = tblpaidlog.us_id ";
@@ -54,10 +56,15 @@
 			}
 		}
-		if ($data['start']){
+
+		//if ($data['start']){
+		
 			$sql=$sql . " " . $order . " LIMIT " . $data['start'] . ", " . $data['perpage'] . " ";
-		}
+		//}
+	
         //return $this->db->query($sql)->result_array();
 		$re = $this->db->query($sql)->result_array();
+		
 		$result['paid_logs'] = $re;
+		
 		$result['total_amount'] = $total_amount;
 		return $result;
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php	(revision 838)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/reportmodel.php	(revision 883)
@@ -28,5 +28,6 @@
 		$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";
+		//$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";
+		$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 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 );
 		$dtns = $query->result_array ();
@@ -46,7 +47,7 @@
 		
 		// Tinh thue bao theo tinh theo nam
-		$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01 00:00:00' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01 23:59:59' GROUP BY tbluser.province";
-		$query = $this->db->query ( $sql );
-		write_file('./log/test.log', date('d-m-Y H:i:s').": ".$sql."\n", FOPEN_WRITE_CREATE);
+		//$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01 00:00:00' AND tbluser.created_time <= '" . ($input ['year'] + 1) . "-01-01 23:59:59' GROUP BY tbluser.province";
+		$sql = "SELECT *,count(us_id) as total FROM tbluser WHERE tbluser.created_time >= '" . $input ['year'] . "-01-01 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 );
 		$tbns = $query->result_array ();
 		
@@ -146,7 +147,8 @@
 		// tinh thue bao theo thang
 		//$sql = "SELECT * FROM tbluser LEFT JOIN tblservicepackage ON tbluser.p_id=tblservicepackage.p_id LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblservicepackage.p_period > 0 ";
-		$sql = "SELECT * FROM tbluser LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . "' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . "'";
+		$sql = "SELECT * FROM tbluser LEFT JOIN tblregisterpackagelog ON tbluser.cellphone = tblregisterpackagelog.username WHERE tbluser.updated_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . " 00:00:00' AND tbluser.updated_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59' AND tblregisterpackagelog.created_time >= '" . $input ['year'] . "-" . $input ['month'] . "-" . $input ['date'] . " 00:00:00' AND tblregisterpackagelog.created_time <= '" . $input ['to_year'] . "-" . $input ['to_month'] . "-" . $input ['to_date'] . " 23:59:59'";
 		$query = $this->db->query ( $sql );
 		$users = $query->result_array ();
+		//write_file('./log/sql.log', date("d-m-Y H:i:s").": ".$sql."\n", FOPEN_WRITE_CREATE);
 		
 		$sql = "SELECT * FROM tblservicepackage WHERE p_period>0";
Index: pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php	(revision 838)
+++ pro-violet-viettel/sourcecode/application/modules/admin/models/user_model.php	(revision 883)
@@ -40,7 +40,13 @@
 			if (strlen($data['keyword'])>0){
 				if ($data['status']==0){
-					if (strlen($data['province_code'])>0){
-						if(strlen($data['daterange_start'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+					if (strlen($data['province'])>0){
+						if (strlen($data['district'])>0){
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}
+						}else{
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}
 						}
 					}else{
@@ -54,10 +60,19 @@
 				}else
 				{
-					if (strlen($data['province_code'])>0){
-						if(strlen($data['daterange_start'])>0){
-							$sql.=" AND province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
-						}else{
-							$sql.=" AND province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
-						}
+					if (strlen($data['province'])>0){
+						if (strlen($data['district'])>0){
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
+							}
+						}else{
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" AND province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
+							}
+						}
+						
 					}
 				}
@@ -66,31 +81,52 @@
 				if(strlen($data['daterange_start'])>0){
 					if ($data['status']==0){
-						if (strlen($data['province_code'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+							}else{
+								$sql.=" WHERE province = '".$data['province']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+							}
 						}else{
 							$sql.=" WHERE (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
 						}
 					}else{
-						if (strlen($data['province_code'])>0){
-							$sql.=" AND province = '".$data['province_code']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}
 						}else{
 							$sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
 						}
+
 					}		
 				}
 				else{
 					if ($data['status']==0){
-						if (strlen($data['province_code'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."'"; 
-						}
-					}else{
-						if (strlen($data['province_code'])>0){
-							$sql.=" AND province = '".$data['province_code']."'";
-						}
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."'";
+							}else{
+								$sql.=" WHERE province = '".$data['province']."'";
+							}
+						}
+					}else{
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."'";
+							}else{
+								$sql.=" AND province = '".$data['province']."'";
+
+							}
+						}
+						
 					}		
 				}
 			}
 		}
+	
 		$order = "";
+		
 		if ($data['sorting_order'] != "sorting") {
 			if($data['sorting_field'] != "status"){
@@ -101,5 +137,5 @@
 			}
 		}
-		write_file('./log/test.log', date("d-m-Y: H:i:s"). ": ".$sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage'] , FOPEN_WRITE_CREATE);
+		//write_file('./log/sql.log', date("d-m-Y: H:i:s"). ": ".$sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']."\n" , FOPEN_WRITE_CREATE);
 		return $this->db->query($sql." ".$order." LIMIT ".$data['start'].", ".$data['perpage']." ")->result_array();
 	}
@@ -126,8 +162,15 @@
 			if (strlen($data['keyword'])>0){
 				if ($data['status']==0){
-					if (strlen($data['province_code'])>0){
-						if(strlen($data['daterange_start'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
-						}
+					if (strlen($data['province'])>0){
+						if (strlen($data['district'])>0){
+							if(strlen($data['daterange_start'])>0){
+							$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+						}
+						}else{
+							if(strlen($data['daterange_start'])>0){
+							$sql.=" WHERE province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+						}
+						}
+						
 					}else{
 						if(strlen($data['daterange_start'])>0){
@@ -140,9 +183,17 @@
 				}else
 				{
-					if (strlen($data['province_code'])>0){
-						if(strlen($data['daterange_start'])>0){
-							$sql.=" AND province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
-						}else{
-							$sql.=" AND province = '".$data['province_code']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
+					if (strlen($data['province'])>0){
+						if (strlen($data['district'])>0){
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
+							}	
+						}else{
+							if(strlen($data['daterange_start'])>0){
+								$sql.=" AND province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND (cellphone LIKE '%".$data['keyword']."%' OR collaborator LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%' OR acc_balanced LIKE '%".$data['keyword']."%' OR district LIKE '%".$data['keyword']."%' OR province LIKE '%".$data['keyword']."%') ";
+							}
 						}
 					}
@@ -152,12 +203,20 @@
 				if(strlen($data['daterange_start'])>0){
 					if ($data['status']==0){
-						if (strlen($data['province_code'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+							}else{
+								$sql.=" WHERE province = '".$data['province']."' AND created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."'";
+							}
 						}else{
 							$sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
 						}
 					}else{
-						if (strlen($data['province_code'])>0){
-							$sql.=" AND province = '".$data['province_code']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}else{
+								$sql.=" AND province = '".$data['province']."' AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
+							}
 						}else{
 							$sql.=" AND (created_time BETWEEN '".$data['daterange_start']."' AND '".$data['daterange_end']."')";
@@ -167,10 +226,18 @@
 				else{
 					if ($data['status']==0){
-						if (strlen($data['province_code'])>0){
-							$sql.=" WHERE province = '".$data['province_code']."'"; 
-						}
-					}else{
-						if (strlen($data['province_code'])>0){
-							$sql.=" AND province = '".$data['province_code']."'";
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" WHERE province = '".$data['province']."' AND district = '".$data['district']."'";
+							}else{
+								$sql.=" WHERE province = '".$data['province']."'";
+							} 
+						}
+					}else{
+						if (strlen($data['province'])>0){
+							if (strlen($data['district'])>0){
+								$sql.=" AND province = '".$data['province']."' AND district = '".$data['district']."'";
+							}else{
+								$sql.=" AND province = '".$data['province']."'";
+							}
 						}
 					}		
@@ -191,3 +258,21 @@
 	}
 	
+	public function getDistrictByProvince($provinceId){
+		$sql = "SELECT * FROM tbldistrict WHERE province_id = ?";
+		$query = $this->db->query ( $sql, array (
+				$provinceId
+		) );
+		$results = $query->result_array();
+		return $results;
+	}
+	
+	public function getDistrictByIdAndProvince($districtId, $provinceId){
+		$sql = "SELECT * FROM tbldistrict WHERE district_id = ? AND province_id = ?";
+		$query = $this->db->query ( $sql,array ($districtId, $provinceId) );
+		if ($query->num_rows () > 0) {
+			$row = $query->row_array ();
+			return $row;
+		}
+		
+	}
 }
