[765] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | if (! defined ( 'BASEPATH' ))
|
---|
| 4 | exit ( 'No direct script access allowed' );
|
---|
[758] | 5 | /**
|
---|
| 6 | * Report Class
|
---|
[765] | 7 | *
|
---|
[758] | 8 | * @author dzungnv02
|
---|
[765] | 9 | *
|
---|
[758] | 10 | */
|
---|
| 11 | class Report extends MX_Controller {
|
---|
| 12 | private $_server = null;
|
---|
| 13 |
|
---|
[765] | 14 | /**
|
---|
| 15 | *
|
---|
| 16 | */
|
---|
[758] | 17 | function __construct() {
|
---|
| 18 | parent::__construct ();
|
---|
| 19 | ini_set ( "soap.wsdl_cache_enabled", "1" );
|
---|
| 20 | $this->_server = new SoapServer ( NULL, array (
|
---|
| 21 | 'soap_version' => SOAP_1_2,
|
---|
| 22 | 'encoding' => 'UTF-8',
|
---|
[765] | 23 | 'uri' => 'http://tempuri.org/'
|
---|
[758] | 24 | ) );
|
---|
| 25 | }
|
---|
| 26 |
|
---|
[765] | 27 | /**
|
---|
| 28 | *
|
---|
| 29 | */
|
---|
[758] | 30 | function __destruct() {
|
---|
| 31 | ini_set ( "soap.wsdl_cache_enabled", "0" );
|
---|
| 32 | }
|
---|
| 33 |
|
---|
[765] | 34 | /**
|
---|
| 35 | *
|
---|
| 36 | */
|
---|
[758] | 37 | public function index() {
|
---|
| 38 | if ($this->uri->segment ( 3 ) == "wsdl") {
|
---|
| 39 | header ( 'Content-Type: text/xml; charset: utf-8' );
|
---|
| 40 | $this->load->view ( 'reportwsdl' );
|
---|
| 41 | return;
|
---|
[765] | 42 | } else {
|
---|
[758] | 43 | header ( 'Content-Type: text/html; charset: utf-8' );
|
---|
| 44 | echo '<div>See Report service <a href="', base_url (), 'violetservice/report/wsdl">WSDL page</a></div>';
|
---|
| 45 | }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
[765] | 48 | /**
|
---|
| 49 | *
|
---|
| 50 | * @return multitype:string number |string
|
---|
| 51 | */
|
---|
[758] | 52 | public function get() {
|
---|
[765] | 53 |
|
---|
| 54 | /**
|
---|
| 55 | *
|
---|
| 56 | * @return multitype:string number
|
---|
| 57 | */
|
---|
| 58 | function revenueReport() {
|
---|
| 59 | $aryArgs = func_get_args ();
|
---|
| 60 | list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
|
---|
| 61 |
|
---|
[758] | 62 | $CI = & get_instance ();
|
---|
[765] | 63 | if (! $toDate)
|
---|
| 64 | $toDate = date ( 'Y-m-d' );
|
---|
| 65 | $message = validate ( $aryArgs );
|
---|
| 66 | $success = $message == '' ? 1 : 0; // 0:error; 1:Success;
|
---|
[758] | 67 |
|
---|
| 68 | if ($success == 1) {
|
---|
| 69 | $CI->load->model ( 'Services_model' );
|
---|
| 70 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
[765] | 71 | $from = explode ( '-', $fromDate );
|
---|
| 72 | $to = explode ( '-', $toDate );
|
---|
| 73 | $input = array (
|
---|
| 74 | 'year' => $from [0],
|
---|
| 75 | 'month' => $from [1],
|
---|
| 76 | 'to_year' => $to [0],
|
---|
| 77 | 'to_month' => $to [1],
|
---|
| 78 | 'to_date' => $to [2]
|
---|
| 79 | );
|
---|
| 80 | $result = $CI->objReportModel->exportProvince ( $input );
|
---|
[758] | 81 |
|
---|
[765] | 82 | if (count ( $result ) > 0 && is_array ( $result )) {
|
---|
| 83 | // 1|20140915|A076|0|0|0|100000|0|0
|
---|
| 84 | $aryTmp = array ();
|
---|
| 85 | $aryResult = array ();
|
---|
| 86 | foreach ( $result as $provinceCode => $record ) {
|
---|
| 87 | // No|toDate|ProvCode|TBngay|LKTBThang|TongTBNam|DTngay|LuyKeTBThang|TongDTNam
|
---|
| 88 | $aryTmp [] = $record ['stt'];
|
---|
| 89 | $aryTmp [] = implode ( '', $to );
|
---|
| 90 | $aryTmp [] = $record ['ma'];
|
---|
| 91 | $aryTmp [] = $record ['thue_bao_ngay'];
|
---|
| 92 | $aryTmp [] = $record ['thue_bao_thang'];
|
---|
| 93 | $aryTmp [] = $record ['thue_bao_nam'];
|
---|
| 94 | $aryTmp [] = $record ['doanh_thu_ngay'];
|
---|
| 95 | $aryTmp [] = $record ['doanh_thu_thang'];
|
---|
| 96 | $aryTmp [] = $record ['doanh_thu_nam'];
|
---|
| 97 | $aryResult [] = implode ( '|', $aryTmp );
|
---|
| 98 | $aryTmp = array ();
|
---|
[758] | 99 | }
|
---|
| 100 |
|
---|
[765] | 101 | $message = implode ( "\n", $aryResult );
|
---|
[758] | 102 | $success = 1;
|
---|
| 103 | }
|
---|
| 104 | }
|
---|
| 105 |
|
---|
[765] | 106 | return array (
|
---|
| 107 | $message,
|
---|
| 108 | $success,
|
---|
| 109 | date ( 'YmdHis' )
|
---|
| 110 | );
|
---|
[758] | 111 | }
|
---|
| 112 |
|
---|
[765] | 113 | /**
|
---|
| 114 | *
|
---|
| 115 | * @return multitype:string number
|
---|
| 116 | */
|
---|
| 117 | function subscribersReport() {
|
---|
| 118 | $aryArgs = func_get_args ();
|
---|
| 119 | list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
|
---|
| 120 |
|
---|
[758] | 121 | $CI = & get_instance ();
|
---|
[765] | 122 | $message = validate ( $aryArgs );
|
---|
| 123 | $success = $message == '' ? 1 : 0; // 0:error; 1:Success;
|
---|
[758] | 124 |
|
---|
[765] | 125 | if ($success == 1) {
|
---|
| 126 | $CI->load->model ( 'Services_model' );
|
---|
| 127 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
| 128 | $from = explode ( '-', $fromDate );
|
---|
| 129 | $to = explode ( '-', $toDate );
|
---|
| 130 | $input = array (
|
---|
| 131 | 'year' => $from [0],
|
---|
| 132 | 'month' => $from [1],
|
---|
| 133 | 'date' => $from [2],
|
---|
| 134 | 'to_year' => $to [0],
|
---|
| 135 | 'to_month' => $to [1],
|
---|
| 136 | 'to_date' => $to [2]
|
---|
| 137 | );
|
---|
| 138 | $result = $CI->objReportModel->exportPackage ( $input );
|
---|
| 139 |
|
---|
| 140 | if (count ( $result ) > 0 && is_array ( $result )) {
|
---|
| 141 | $aryTmp = array ();
|
---|
| 142 | $aryResult = array ();
|
---|
| 143 | foreach ( $result as $provinceCode => $record ) {
|
---|
| 144 | $aryTmp [] = $record ['stt'];
|
---|
| 145 | $aryTmp [] = implode ( '', $to );
|
---|
| 146 | $aryTmp [] = $record ['ma'];
|
---|
| 147 | $aryTmp [] = $record ['tong_so_VIP 1'];
|
---|
| 148 | $aryTmp [] = $record ['ti_le_VIP 1'];
|
---|
| 149 | $aryTmp [] = $record ['tong_so_VIP 3'];
|
---|
| 150 | $aryTmp [] = $record ['ti_le_VIP 3'];
|
---|
| 151 | $aryTmp [] = $record ['tong_so_VIP 6'];
|
---|
| 152 | $aryTmp [] = $record ['ti_le_VIP 6'];
|
---|
| 153 | $aryTmp [] = $record ['tong_so_VIP 12'];
|
---|
| 154 | $aryTmp [] = $record ['ti_le_VIP 12'];
|
---|
| 155 | $aryTmp [] = $record ['tong_so_tb'];
|
---|
| 156 | $aryResult [] = implode ( '|', $aryTmp );
|
---|
| 157 | $aryTmp = array ();
|
---|
| 158 | }
|
---|
| 159 |
|
---|
| 160 | $message = implode ( "\n", $aryResult );
|
---|
| 161 | $success = 1;
|
---|
| 162 | }
|
---|
| 163 | }
|
---|
| 164 |
|
---|
[758] | 165 | $CI->load->model ( 'Services_model' );
|
---|
[765] | 166 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
[758] | 167 |
|
---|
[765] | 168 | return array (
|
---|
| 169 | $message,
|
---|
| 170 | $success,
|
---|
| 171 | date ( 'YmdHis' )
|
---|
| 172 | );
|
---|
[758] | 173 | }
|
---|
| 174 |
|
---|
[765] | 175 | /**
|
---|
| 176 | *
|
---|
| 177 | * @param unknown $aryArgs
|
---|
| 178 | * @return string
|
---|
| 179 | */
|
---|
| 180 | function validate($aryArgs) {
|
---|
| 181 | list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
|
---|
[758] | 182 |
|
---|
| 183 | $CI = & get_instance ();
|
---|
| 184 | $predefUsername = $CI->config->item ( 'report_username' );
|
---|
| 185 | $predefPassword = $CI->config->item ( 'report_password' );
|
---|
[765] | 186 |
|
---|
[758] | 187 | $message = '';
|
---|
[765] | 188 |
|
---|
[758] | 189 | if (! $username) {
|
---|
| 190 | $message = 'Username is required!';
|
---|
[765] | 191 | } else if (! $password) {
|
---|
| 192 | $message = 'Password is required!';
|
---|
| 193 | } else if ($username != $predefUsername) {
|
---|
| 194 | $message = 'Username is not corrected!';
|
---|
| 195 | } else if ($password != $predefPassword) {
|
---|
| 196 | $message = 'Password is not corrected!';
|
---|
| 197 | } else if (! $fromDate) {
|
---|
| 198 | $message = 'fromDate is required!';
|
---|
| 199 | } else if (! preg_match ( '/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $fromDate )) {
|
---|
| 200 | $message = 'fromDate is not corrected!';
|
---|
| 201 | } 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 )) {
|
---|
| 202 | $message = 'toDate is not corrected!';
|
---|
[758] | 203 | }
|
---|
[765] | 204 |
|
---|
[758] | 205 | return $message;
|
---|
| 206 | }
|
---|
| 207 |
|
---|
[765] | 208 | $this->_server->addFunction ( array (
|
---|
| 209 | 'revenueReport',
|
---|
| 210 | 'subscribersReport'
|
---|
| 211 | ) );
|
---|
[758] | 212 |
|
---|
| 213 | try {
|
---|
| 214 | ob_start ();
|
---|
| 215 | $soapOutput = '';
|
---|
| 216 | $request = '';
|
---|
| 217 | $this->_server->handle ();
|
---|
| 218 |
|
---|
| 219 | if (ob_get_length () > 0) {
|
---|
| 220 | $soapOutput = ob_get_clean ();
|
---|
| 221 | }
|
---|
[765] | 222 |
|
---|
[758] | 223 | if ($soapOutput != '') {
|
---|
[765] | 224 | error_log ( var_export ( $soapOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log' );
|
---|
[758] | 225 |
|
---|
[765] | 226 | $response = preg_match ( '/revenueReportResponse/', $soapOutput ) ? 'revenueReportResponse' : (preg_match ( '/subscribersReportResponse/', $soapOutput ) ? 'subscribersReportResponse' : '');
|
---|
[758] | 227 |
|
---|
| 228 | $pattern = '/<[^>]*[^\/]>/i';
|
---|
| 229 | $aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
---|
[765] | 230 | error_log ( var_export ( $aryOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log' );
|
---|
[758] | 231 | $aryData = array ();
|
---|
| 232 | $aryData ['message'] = $aryOutput [1];
|
---|
| 233 | $aryData ['success'] = $aryOutput [2];
|
---|
| 234 | $aryData ['receiveTime'] = $aryOutput [3];
|
---|
| 235 | $aryData ['response'] = $response;
|
---|
| 236 | $xml = $this->load->view ( 'report', $aryData, TRUE );
|
---|
| 237 | header ( 'Content-Type: text/xml; charset: utf-8' );
|
---|
| 238 | echo $xml;
|
---|
| 239 | } else {
|
---|
| 240 | header ( 'Content-Type: text/html; charset: utf-8' );
|
---|
| 241 | echo 'See service <a href="' . base_url () . 'violetservice/report/wsdl">WSDL page</a>';
|
---|
| 242 | }
|
---|
| 243 | } catch ( Exception $e ) {
|
---|
| 244 | $this->_server->fault ( 'Sender', $e->getMessage () );
|
---|
[765] | 245 | }
|
---|
[758] | 246 | }
|
---|
| 247 | } |
---|