Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php	(revision 758)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php	(revision 765)
@@ -1,14 +1,18 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
+
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 /**
  * Report Class
- * 
+ *
  * @author dzungnv02
- *
+ *        
  */
-
 class Report extends MX_Controller {
-	
 	private $_server = null;
 	
+	/**
+	 * 
+	 */
 	function __construct() {
 		parent::__construct ();
@@ -17,12 +21,18 @@
 				'soap_version' => SOAP_1_2,
 				'encoding' => 'UTF-8',
-				'uri' => 'http://tempuri.org/'
+				'uri' => 'http://tempuri.org/' 
 		) );
 	}
 	
+	/**
+	 * 
+	 */
 	function __destruct() {
 		ini_set ( "soap.wsdl_cache_enabled", "0" );
 	}
 	
+	/**
+	 * 
+	 */
 	public function index() {
 		if ($this->uri->segment ( 3 ) == "wsdl") {
@@ -30,6 +40,5 @@
 			$this->load->view ( 'reportwsdl' );
 			return;
-		}
-		else {
+		} else {
 			header ( 'Content-Type: text/html; charset: utf-8' );
 			echo '<div>See Report service <a href="', base_url (), 'violetservice/report/wsdl">WSDL page</a></div>';
@@ -37,93 +46,168 @@
 	}
 	
+	/**
+	 * 
+	 * @return multitype:string number |string
+	 */
 	public function get() {
-		function revenueReport () {
-			$aryArgs = func_get_args ();	
-			list ( $username, $password, $fromDate, $toDate) = $aryArgs;
-
+		
+		/**
+		 * 
+		 * @return multitype:string number
+		 */
+		function revenueReport() {
+			$aryArgs = func_get_args ();
+			list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
+			
 			$CI = & get_instance ();
-			if (!$toDate) $toDate = date('Y-m-d');
-			$message = validate ($aryArgs);			
-			$success = $message == '' ? 1 : 0;// 0:error; 1:Success;
+			if (! $toDate)
+				$toDate = date ( 'Y-m-d' );
+			$message = validate ( $aryArgs );
+			$success = $message == '' ? 1 : 0; // 0:error; 1:Success;
 			
 			if ($success == 1) {
 				$CI->load->model ( 'Services_model' );
 				$CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
-				$from = explode('-', $fromDate);
-				$to = explode('-', $toDate);
-				$input = array('year' => $from[0], 'month' => $from[1], 'to_year' => $to[0], 'to_month' => $to[1], 'to_date' => $to[2]);
-				$result = $CI->objReportModel->exportProvince( $input );
-				
-				if (count($result) > 0 && is_array($result)) {
-					//1|20140915|A076|0|0|0|100000|0|0
-					$aryTmp = array();
-					$aryResult = array();
-					foreach ($result as $provinceCode => $record) {
-						//No|toDate|ProvCode|TBngay|LKTBThang|TongTBNam|DTngay|LuyKeTBThang|TongDTNam
-						$aryTmp[] = $record['stt'];
-						$aryTmp[] = implode('', $to);
-						$aryTmp[] = $provinceCode;
-						$aryTmp[] = $record['tbng'];
-						$aryTmp[] = $record['tbt'];
-						$aryTmp[] = $record['tbn'];
-						$aryTmp[] = $record['dtng'];
-						$aryTmp[] = $record['dtt'];
-						$aryTmp[] = $record['dtn'];
-						$aryResult[] = implode('|', $aryTmp);
-						$aryTmp = array();
+				$from = explode ( '-', $fromDate );
+				$to = explode ( '-', $toDate );
+				$input = array (
+						'year' => $from [0],
+						'month' => $from [1],
+						'to_year' => $to [0],
+						'to_month' => $to [1],
+						'to_date' => $to [2] 
+				);
+				$result = $CI->objReportModel->exportProvince ( $input );
+				
+				if (count ( $result ) > 0 && is_array ( $result )) {
+					// 1|20140915|A076|0|0|0|100000|0|0
+					$aryTmp = array ();
+					$aryResult = array ();
+					foreach ( $result as $provinceCode => $record ) {
+						// No|toDate|ProvCode|TBngay|LKTBThang|TongTBNam|DTngay|LuyKeTBThang|TongDTNam
+						$aryTmp [] = $record ['stt'];
+						$aryTmp [] = implode ( '', $to );
+						$aryTmp [] = $record ['ma'];
+						$aryTmp [] = $record ['thue_bao_ngay'];
+						$aryTmp [] = $record ['thue_bao_thang'];
+						$aryTmp [] = $record ['thue_bao_nam'];
+						$aryTmp [] = $record ['doanh_thu_ngay'];
+						$aryTmp [] = $record ['doanh_thu_thang'];
+						$aryTmp [] = $record ['doanh_thu_nam'];
+						$aryResult [] = implode ( '|', $aryTmp );
+						$aryTmp = array ();
 					}
 					
-					$message = implode("\n", $aryResult);
+					$message = implode ( "\n", $aryResult );
 					$success = 1;
 				}
 			}
 			
-			return array($message, $success, date('YmdHis'));
-		}
-		
-		function subscribersReport () {
-			$aryArgs = func_get_args ();	
-			list ( $username, $password, $fromDate, $toDate) = $aryArgs;
-
+			return array (
+					$message,
+					$success,
+					date ( 'YmdHis' ) 
+			);
+		}
+		
+		/**
+		 * 
+		 * @return multitype:string number
+		 */
+		function subscribersReport() {
+			$aryArgs = func_get_args ();
+			list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
+			
 			$CI = & get_instance ();
-			$message = validate ($aryArgs);
-			$success = $message == '' ? 1 : 0;// 0:error; 1:Success;
-			$message = $message == '' ? 'subscribersReport' : $message;
+			$message = validate ( $aryArgs );
+			$success = $message == '' ? 1 : 0; // 0:error; 1:Success;
+			
+			if ($success == 1) {
+				$CI->load->model ( 'Services_model' );
+				$CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
+				$from = explode ( '-', $fromDate );
+				$to = explode ( '-', $toDate );
+				$input = array (
+						'year' => $from [0],
+						'month' => $from [1],
+						'date' => $from [2],
+						'to_year' => $to [0],
+						'to_month' => $to [1],
+						'to_date' => $to [2] 
+				);
+				$result = $CI->objReportModel->exportPackage ( $input );
+				
+				if (count ( $result ) > 0 && is_array ( $result )) {
+					$aryTmp = array ();
+					$aryResult = array ();
+					foreach ( $result as $provinceCode => $record ) {
+						$aryTmp [] = $record ['stt'];
+						$aryTmp [] = implode ( '', $to );
+						$aryTmp [] = $record ['ma'];
+						$aryTmp [] = $record ['tong_so_VIP 1'];
+						$aryTmp [] = $record ['ti_le_VIP 1'];
+						$aryTmp [] = $record ['tong_so_VIP 3'];
+						$aryTmp [] = $record ['ti_le_VIP 3'];
+						$aryTmp [] = $record ['tong_so_VIP 6'];
+						$aryTmp [] = $record ['ti_le_VIP 6'];
+						$aryTmp [] = $record ['tong_so_VIP 12'];
+						$aryTmp [] = $record ['ti_le_VIP 12'];
+						$aryTmp [] = $record ['tong_so_tb'];
+						$aryResult [] = implode ( '|', $aryTmp );
+						$aryTmp = array ();
+					}
+					
+					$message = implode ( "\n", $aryResult );
+					$success = 1;
+				}
+			}
 			
 			$CI->load->model ( 'Services_model' );
-			$CI->load->model ( 'admin/Reportmodel', 'objReportModel' );			
-			
-			return array($message, $success, date('YmdHis'));
-		}
-		
-		function validate ($aryArgs) {
-			list ( $username, $password, $fromDate, $toDate) = $aryArgs;
+			$CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
+			
+			return array (
+					$message,
+					$success,
+					date ( 'YmdHis' ) 
+			);
+		}
+		
+		/**
+		 * 
+		 * @param unknown $aryArgs
+		 * @return string
+		 */
+		function validate($aryArgs) {
+			list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
 			
 			$CI = & get_instance ();
 			$predefUsername = $CI->config->item ( 'report_username' );
 			$predefPassword = $CI->config->item ( 'report_password' );
-				
+			
 			$message = '';
-				
+			
 			if (! $username) {
 				$message = 'Username is required!';
-			}else if (! $password) {
-				$message =  'Password is required!';
-			}else if ($username != $predefUsername) {
-				$message =  'Username is not corrected!';
-			}else if ($password != $predefPassword) {
-				$message =  'Password is not corrected!';
-			}else if (! $fromDate) {
-				$message =  'fromDate is required!';
-			}else if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $fromDate)) {
-				$message =  'fromDate is not corrected!';
-			}else if ($toDate && !preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $toDate)) {
-				$message =  'toDate is not corrected!';
-			}
-
+			} else if (! $password) {
+				$message = 'Password is required!';
+			} else if ($username != $predefUsername) {
+				$message = 'Username is not corrected!';
+			} else if ($password != $predefPassword) {
+				$message = 'Password is not corrected!';
+			} else if (! $fromDate) {
+				$message = 'fromDate is required!';
+			} else if (! preg_match ( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $fromDate )) {
+				$message = 'fromDate is not corrected!';
+			} else if ($toDate && ! preg_match ( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $toDate )) {
+				$message = 'toDate is not corrected!';
+			}
+			
 			return $message;
 		}
 		
-		$this->_server->addFunction ( array('revenueReport', 'subscribersReport'));
+		$this->_server->addFunction ( array (
+				'revenueReport',
+				'subscribersReport' 
+		) );
 		
 		try {
@@ -136,13 +220,13 @@
 				$soapOutput = ob_get_clean ();
 			}
-				
+			
 			if ($soapOutput != '') {
-				error_log(var_export($soapOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log');
-				
-				$response = preg_match('/revenueReportResponse/', $soapOutput) ? 'revenueReportResponse' : (preg_match('/subscribersReportResponse/', $soapOutput) ? 'subscribersReportResponse':'');
+				error_log ( var_export ( $soapOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log' );
+				
+				$response = preg_match ( '/revenueReportResponse/', $soapOutput ) ? 'revenueReportResponse' : (preg_match ( '/subscribersReportResponse/', $soapOutput ) ? 'subscribersReportResponse' : '');
 				
 				$pattern = '/<[^>]*[^\/]>/i';
 				$aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
-				error_log(var_export($aryOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log');
+				error_log ( var_export ( $aryOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log' );
 				$aryData = array ();
 				$aryData ['message'] = $aryOutput [1];
@@ -159,5 +243,5 @@
 		} catch ( Exception $e ) {
 			$this->_server->fault ( 'Sender', $e->getMessage () );
-		}		
+		}
 	}
 }
