Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php	(revision 751)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php	(revision 758)
@@ -0,0 +1,163 @@
+<?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 ();
+		ini_set ( "soap.wsdl_cache_enabled", "1" );
+		$this->_server = new SoapServer ( NULL, array (
+				'soap_version' => SOAP_1_2,
+				'encoding' => 'UTF-8',
+				'uri' => 'http://tempuri.org/'
+		) );
+	}
+	
+	function __destruct() {
+		ini_set ( "soap.wsdl_cache_enabled", "0" );
+	}
+	
+	public function index() {
+		if ($this->uri->segment ( 3 ) == "wsdl") {
+			header ( 'Content-Type: text/xml; charset: utf-8' );
+			$this->load->view ( 'reportwsdl' );
+			return;
+		}
+		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>';
+		}
+	}
+	
+	public function get() {
+		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 ($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();
+					}
+					
+					$message = implode("\n", $aryResult);
+					$success = 1;
+				}
+			}
+			
+			return array($message, $success, date('YmdHis'));
+		}
+		
+		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;
+			
+			$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 = & 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!';
+			}
+
+			return $message;
+		}
+		
+		$this->_server->addFunction ( array('revenueReport', 'subscribersReport'));
+		
+		try {
+			ob_start ();
+			$soapOutput = '';
+			$request = '';
+			$this->_server->handle ();
+			
+			if (ob_get_length () > 0) {
+				$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':'');
+				
+				$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');
+				$aryData = array ();
+				$aryData ['message'] = $aryOutput [1];
+				$aryData ['success'] = $aryOutput [2];
+				$aryData ['receiveTime'] = $aryOutput [3];
+				$aryData ['response'] = $response;
+				$xml = $this->load->view ( 'report', $aryData, TRUE );
+				header ( 'Content-Type: text/xml; charset: utf-8' );
+				echo $xml;
+			} else {
+				header ( 'Content-Type: text/html; charset: utf-8' );
+				echo 'See service <a href="' . base_url () . 'violetservice/report/wsdl">WSDL page</a>';
+			}
+		} catch ( Exception $e ) {
+			$this->_server->fault ( 'Sender', $e->getMessage () );
+		}		
+	}
+}
Index: pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 751)
+++ pro-violet-viettel/sourcecode/application/modules/services/controllers/viettel.php	(revision 758)
@@ -1,96 +1,116 @@
-<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
+<?php
+
+if (! defined ( 'BASEPATH' ))
+	exit ( 'No direct script access allowed' );
 /**
  * Viettel Class
- * 
+ *
  * @author dzungnv02
- *
+ *        
  */
-
-class Viettel extends MX_Controller 
-{
-	
+class Viettel extends MX_Controller {
 	private $_server = null;
 	
 	function __construct() {
 		parent::__construct ();
-		ini_set("soap.wsdl_cache_enabled","1");
-		$this->_server = new SoapServer(NULL,
-				array('soap_version' => SOAP_1_2, 'encoding' => 'UTF-8', 'uri' => 'http://tempuri.org/')
-		);
-	}
-
-	public function index () 
-	{
-		if($this->uri->segment(4) == "wsdl") {
-			header('Content-Type: text/xml; charset: utf-8');
-			$this->load->view('mowsdl');
-		} else {
-			header('Content-Type: text/html; charset: utf-8');
-			echo 'See service <a href="'.base_url().'violetservice/soanbai/mo/wsdl">WSDL page</a>';
-		}			
+		ini_set ( "soap.wsdl_cache_enabled", "1" );
+		$this->_server = new SoapServer ( NULL, array (
+				'soap_version' => SOAP_1_2,
+				'encoding' => 'UTF-8',
+				'uri' => 'http://tempuri.org/' 
+		) );
 	}
 	
-	public function mo() 
-	{	
-		function messageReceiver(){
-			$aryArgs = func_get_args();
-			$aryExport = array('Username' => $aryArgs[0], 'Password' => $aryArgs[1], 'RequestID' => $aryArgs[2],'UserID' => $aryArgs[3],'ReceiverID' => $aryArgs[4],'ServiceID' => $aryArgs[5],'CommandCode' => $aryArgs[6], 'Info' => $aryArgs[7], 'ReceiveTime' => $aryArgs[8]);
-
-			error_log(date('Y-m-d H:i:s').' -- VARIABLES: '. var_export($aryExport, TRUE). "\n", 3, '/srv/www/sbg/log/sms.log');
-			list($username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $info, $receiveTime) = $aryArgs;
+	function __destruct() {
+		ini_set ( "soap.wsdl_cache_enabled", "0" );
+	}
+	
+	public function index() {
+		if ($this->uri->segment ( 4 ) == "wsdl") {
+			header ( 'Content-Type: text/xml; charset: utf-8' );
+			$this->load->view ( 'mowsdl' );
+		} else {
+			header ( 'Content-Type: text/html; charset: utf-8' );
+			echo 'See service <a href="' . base_url () . 'violetservice/soanbai/mo/wsdl">WSDL page</a>';
+		}
+	}
+	
+	public function mo() {
+		function messageReceiver() {
+			$aryArgs = func_get_args ();
+			$aryExport = array (
+					'Username' => $aryArgs [0],
+					'Password' => $aryArgs [1],
+					'RequestID' => $aryArgs [2],
+					'UserID' => $aryArgs [3],
+					'ReceiverID' => $aryArgs [4],
+					'ServiceID' => $aryArgs [5],
+					'CommandCode' => $aryArgs [6],
+					'Info' => $aryArgs [7],
+					'ReceiveTime' => $aryArgs [8] 
+			);
 			
-			$msgType = '0'; //text message
-			$errCode = '1'; //#1:error; 1:Success;
+			error_log ( date ( 'Y-m-d H:i:s' ) . ' -- VARIABLES: ' . var_export ( $aryExport, TRUE ) . "\n", 3, '/srv/www/sbg/log/sms.log' );
+			list ( $username, $password, $requestID, $userID, $receiverID, $serviceID, $commandCode, $info, $receiveTime ) = $aryArgs;
 			
-			$CI =& get_instance();			
-			$mo_username = $CI->config->item('mo_username');
-			$mo_password = $CI->config->item('mo_password');
-
-			if (!$username) return '0|0|Username is required!';
-			if (!$password) return '0|0|Password is required!';
-			if ($username != $mo_username) return '0|0|Username is not corrected!';
-			if ($password != $mo_password) return '0|0|Password is not corrected!';
-			if (!$requestID) return '0|0|requestID is required!';			
-			if (!$userID) return '0|0|UserID is required!';
-			if (!$serviceID) return '0|0|serviceID is required!';
-			if ($serviceID != '8062') return '0|0|serviceID is not corrected!';
-
-			$CI->load->model('Services_model');
-			$CI->load->model('frontend/User_model', 'objUserModel');
-			$result = $CI->Services_model->processMORequest($userID, $info);
-			error_log(date('Y-m-d H:i:s').' -- INFO VAR: '. var_export($info, TRUE). "\n\n", 3, '/srv/www/sbg/log/sms.log');
-			$CI->objUserModel->insertSmslog($receiverID, $serviceID, $commandCode, $info, $receiveTime);
+			$msgType = '0'; // text message
+			$errCode = '1'; // #1:error; 1:Success;
 			
-			$aryResult = explode ('|', $result);
-			return $aryResult[0].'|'.$msgType.'|'.$aryResult[1];
+			$CI = & get_instance ();
+			$mo_username = $CI->config->item ( 'mo_username' );
+			$mo_password = $CI->config->item ( 'mo_password' );
+			
+			if (! $username)
+				return '0|0|Username is required!';
+			if (! $password)
+				return '0|0|Password is required!';
+			if ($username != $mo_username)
+				return '0|0|Username is not corrected!';
+			if ($password != $mo_password)
+				return '0|0|Password is not corrected!';
+			if (! $requestID)
+				return '0|0|requestID is required!';
+			if (! $userID)
+				return '0|0|UserID is required!';
+			if (! $serviceID)
+				return '0|0|serviceID is required!';
+			if ($serviceID != '8062')
+				return '0|0|serviceID is not corrected!';
+			
+			$CI->load->model ( 'Services_model' );
+			$CI->load->model ( 'frontend/User_model', 'objUserModel' );
+			$result = $CI->Services_model->processMORequest ( $userID, $info );
+			error_log ( date ( 'Y-m-d H:i:s' ) . ' -- INFO VAR: ' . var_export ( $info, TRUE ) . "\n\n", 3, '/srv/www/sbg/log/sms.log' );
+			$CI->objUserModel->insertSmslog ( $receiverID, $serviceID, $commandCode, $info, $receiveTime );
+			
+			$aryResult = explode ( '|', $result );
+			return $aryResult [0] . '|' . $msgType . '|' . $aryResult [1];
 		}
 		
-		$this->_server->addFunction('messageReceiver');
+		$this->_server->addFunction ( 'messageReceiver' );
 		
 		try {
-			ob_start();
+			ob_start ();
 			$soapOutput = '';
-			$this->_server->handle();
-				
-			if (ob_get_length() > 0) {
-				$soapOutput = ob_get_clean();
+			$this->_server->handle ();
+			
+			if (ob_get_length () > 0) {
+				$soapOutput = ob_get_clean ();
 			}
-				
+			
 			if ($soapOutput != '') {
 				$pattern = '/<[^>]*[^\/]>/i';
-				$aryOutput = preg_split ($pattern, $soapOutput, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE);
-				$aryData = array();
-				$aryData['message'] = $aryOutput[1];
-				$xml = $this->load->view('mo', $aryData, TRUE);
-				header('Content-Type: text/xml; charset: utf-8');
+				$aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
+				$aryData = array ();
+				$aryData ['message'] = $aryOutput [1];
+				$xml = $this->load->view ( 'mo', $aryData, TRUE );
+				header ( 'Content-Type: text/xml; charset: utf-8' );
 				echo $xml;
+			} else {
+				header ( 'Content-Type: text/html; charset: utf-8' );
+				echo 'See service <a href="' . base_url () . 'violetservice/soanbai/mo/wsdl">WSDL page</a>';
 			}
-			else {
-				header('Content-Type: text/html; charset: utf-8');
-				echo 'See service <a href="'.base_url().'violetservice/soanbai/mo/wsdl">WSDL page</a>';
-			}
-		}
-		catch (Exception $e) {
-			$this->_server->fault('Sender', $e->getMessage());
+		} catch ( Exception $e ) {
+			$this->_server->fault ( 'Sender', $e->getMessage () );
 		}
 	}
Index: pro-violet-viettel/sourcecode/application/modules/services/views/report.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/views/report.php	(revision 758)
+++ pro-violet-viettel/sourcecode/application/modules/services/views/report.php	(revision 758)
@@ -0,0 +1,9 @@
+<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
+	<S:Body>
+		<<?php echo $response?> xmlns="http://tempuri.org/">
+			<return><?php echo $message;?></return>
+			<success><?php echo $success;?></success>
+			<receiveTime><?php echo $receiveTime;?></receiveTime>
+		</<?php echo $response?>>
+	</S:Body>
+</S:Envelope>
Index: pro-violet-viettel/sourcecode/application/modules/services/views/reportwsdl.php
===================================================================
--- pro-violet-viettel/sourcecode/application/modules/services/views/reportwsdl.php	(revision 758)
+++ pro-violet-viettel/sourcecode/application/modules/services/views/reportwsdl.php	(revision 758)
@@ -0,0 +1,98 @@
+<?php echo "<?xml version='1.0' encoding='UTF-8'?>";?>
+<wsdl:definitions xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:tm="http://microsoft.com/wsdl/mime/textMatching/" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:mime="http://schemas.xmlsoap.org/wsdl/mime/" xmlns:tns="http://tempuri.org/" xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:soap12="http://schemas.xmlsoap.org/wsdl/soap12/" xmlns:http="http://schemas.xmlsoap.org/wsdl/http/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" targetNamespace="http://tempuri.org/">
+  <wsdl:types>
+    <s:schema elementFormDefault="qualified" targetNamespace="http://tempuri.org/">
+      <s:element name="revenueReport">
+        <s:complexType>
+          <s:sequence>
+            <s:element minOccurs="1" maxOccurs="1" name="username" type="s:string"/>
+            <s:element minOccurs="1" maxOccurs="1" name="password" type="s:string"/>
+            <s:element minOccurs="1" maxOccurs="1" name="fromDate" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="toDate" type="s:string"/>            
+          </s:sequence>
+        </s:complexType>
+      </s:element>
+      <s:element name="revenueReportResponse">
+        <s:complexType>
+          <s:sequence>
+            <s:element minOccurs="0" maxOccurs="1" name="return" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="success" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="receiveTime" type="s:string"/>
+          </s:sequence>
+        </s:complexType>       
+      </s:element>
+      <!-- subscribersReport -->
+      <s:element name="subscribersReport">
+        <s:complexType>
+          <s:sequence>
+            <s:element minOccurs="1" maxOccurs="1" name="username" type="s:string"/>
+            <s:element minOccurs="1" maxOccurs="1" name="password" type="s:string"/>
+            <s:element minOccurs="1" maxOccurs="1" name="fromDate" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="toDate" type="s:string"/>
+          </s:sequence>
+        </s:complexType>
+      </s:element>
+      <s:element name="subscribersReportResponse">
+        <s:complexType>
+          <s:sequence>
+            <s:element minOccurs="0" maxOccurs="1" name="return" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="success" type="s:string"/>
+            <s:element minOccurs="0" maxOccurs="1" name="receiveTime" type="s:string"/>
+          </s:sequence>
+        </s:complexType>
+      </s:element>
+    </s:schema>
+  </wsdl:types>
+  <wsdl:message name="revenueReportSoapIn">
+    <wsdl:part name="parameters" element="tns:revenueReport"/>
+  </wsdl:message>
+  <wsdl:message name="revenueReportSoapOut">
+    <wsdl:part name="parameters" element="tns:revenueReportResponse"/>
+  </wsdl:message>
+  
+  <wsdl:message name="subscribersReportSoapIn">
+    <wsdl:part name="parameters" element="tns:subscribersReport"/>
+  </wsdl:message>
+  <wsdl:message name="subscribersReportSoapOut">
+    <wsdl:part name="parameters" element="tns:subscribersReportResponse"/>
+  </wsdl:message>
+      
+  <wsdl:portType name="reportReceiver">
+    <wsdl:operation name="revenueReport">
+      <wsdl:input message="tns:revenueReportSoapIn"/>
+      <wsdl:output message="tns:revenueReportSoapOut"/>
+    </wsdl:operation>
+    <wsdl:operation name="subscribersReport">
+      <wsdl:input message="tns:subscribersReportSoapIn"/>
+      <wsdl:output message="tns:subscribersReportSoapOut"/>
+    </wsdl:operation>    
+  </wsdl:portType>
+  <!-- subscribersReport -->
+
+  <wsdl:binding name="reportReceiver" type="tns:reportReceiver">
+    <soap:binding transport="http://schemas.xmlsoap.org/soap/http"/>
+    <wsdl:operation name="revenueReport">
+      <soap:operation soapAction="http://tempuri.org/revenueReport" style="document"/>
+      <wsdl:input>
+        <soap:body use="literal"/>
+      </wsdl:input>
+      <wsdl:output>
+        <soap:body use="literal"/>
+      </wsdl:output>
+    </wsdl:operation>    
+    <wsdl:operation name="subscribersReport">
+      <soap:operation soapAction="http://tempuri.org/subscribersReport" style="document"/>
+      <wsdl:input>
+        <soap:body use="literal"/>
+      </wsdl:input>
+      <wsdl:output>
+        <soap:body use="literal"/>
+      </wsdl:output>
+    </wsdl:operation>    
+  </wsdl:binding>
+  <wsdl:service name="reportReceiver">
+    <wsdl:port name="reportReceiver" binding="tns:reportReceiver">
+      <soap:address location="<?php echo base_url();?>violetservice/report/getreport"/>
+    </wsdl:port>
+  </wsdl:service>
+</wsdl:definitions>
