1 | <?php
|
---|
2 |
|
---|
3 | if (! defined ( 'BASEPATH' ))
|
---|
4 | exit ( 'No direct script access allowed' );
|
---|
5 | /**
|
---|
6 | * Report Class
|
---|
7 | *
|
---|
8 | * @author dzungnv02
|
---|
9 | *
|
---|
10 | */
|
---|
11 | class Report extends MX_Controller {
|
---|
12 | private $_server = null;
|
---|
13 |
|
---|
14 | /**
|
---|
15 | *
|
---|
16 | */
|
---|
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',
|
---|
23 | 'uri' => 'http://tempuri.org/'
|
---|
24 | ) );
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | *
|
---|
29 | */
|
---|
30 | function __destruct() {
|
---|
31 | ini_set ( "soap.wsdl_cache_enabled", "0" );
|
---|
32 | }
|
---|
33 |
|
---|
34 | /**
|
---|
35 | *
|
---|
36 | */
|
---|
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;
|
---|
42 | } else {
|
---|
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 |
|
---|
48 | /**
|
---|
49 | *
|
---|
50 | * @return multitype:string number |string
|
---|
51 | */
|
---|
52 | public function get() {
|
---|
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 |
|
---|
62 | $CI = & get_instance ();
|
---|
63 | if (! $toDate)
|
---|
64 | $toDate = date ( 'Y-m-d' );
|
---|
65 | $message = validate ( $aryArgs );
|
---|
66 | $success = $message == '' ? 1 : 0; // 0:error; 1:Success;
|
---|
67 |
|
---|
68 | if ($success == 1) {
|
---|
69 | $CI->load->model ( 'Services_model' );
|
---|
70 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
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 );
|
---|
81 |
|
---|
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 ();
|
---|
99 | }
|
---|
100 |
|
---|
101 | $message = implode ( "\n", $aryResult );
|
---|
102 | $success = 1;
|
---|
103 | }
|
---|
104 | }
|
---|
105 |
|
---|
106 | return array (
|
---|
107 | $message,
|
---|
108 | $success,
|
---|
109 | date ( 'YmdHis' )
|
---|
110 | );
|
---|
111 | }
|
---|
112 |
|
---|
113 | /**
|
---|
114 | *
|
---|
115 | * @return multitype:string number
|
---|
116 | */
|
---|
117 | function subscribersReport() {
|
---|
118 | $aryArgs = func_get_args ();
|
---|
119 | list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
|
---|
120 |
|
---|
121 | $CI = & get_instance ();
|
---|
122 | $message = validate ( $aryArgs );
|
---|
123 | $success = $message == '' ? 1 : 0; // 0:error; 1:Success;
|
---|
124 |
|
---|
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 |
|
---|
165 | $CI->load->model ( 'Services_model' );
|
---|
166 | $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
|
---|
167 |
|
---|
168 | return array (
|
---|
169 | $message,
|
---|
170 | $success,
|
---|
171 | date ( 'YmdHis' )
|
---|
172 | );
|
---|
173 | }
|
---|
174 |
|
---|
175 | /**
|
---|
176 | *
|
---|
177 | * @param unknown $aryArgs
|
---|
178 | * @return string
|
---|
179 | */
|
---|
180 | function validate($aryArgs) {
|
---|
181 | list ( $username, $password, $fromDate, $toDate ) = $aryArgs;
|
---|
182 |
|
---|
183 | $CI = & get_instance ();
|
---|
184 | $predefUsername = $CI->config->item ( 'report_username' );
|
---|
185 | $predefPassword = $CI->config->item ( 'report_password' );
|
---|
186 |
|
---|
187 | $message = '';
|
---|
188 |
|
---|
189 | if (! $username) {
|
---|
190 | $message = 'Username is required!';
|
---|
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!';
|
---|
203 | }
|
---|
204 |
|
---|
205 | return $message;
|
---|
206 | }
|
---|
207 |
|
---|
208 | $this->_server->addFunction ( array (
|
---|
209 | 'revenueReport',
|
---|
210 | 'subscribersReport'
|
---|
211 | ) );
|
---|
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 | }
|
---|
222 |
|
---|
223 | if ($soapOutput != '') {
|
---|
224 | error_log ( var_export ( $soapOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log' );
|
---|
225 |
|
---|
226 | $response = preg_match ( '/revenueReportResponse/', $soapOutput ) ? 'revenueReportResponse' : (preg_match ( '/subscribersReportResponse/', $soapOutput ) ? 'subscribersReportResponse' : '');
|
---|
227 |
|
---|
228 | $pattern = '/<[^>]*[^\/]>/i';
|
---|
229 | $aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
|
---|
230 | error_log ( var_export ( $aryOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log' );
|
---|
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 () );
|
---|
245 | }
|
---|
246 | }
|
---|
247 | } |
---|