Ignore:
Timestamp:
Feb 14, 2015 10:38:40 AM (10 years ago)
Author:
dungnv
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • pro-violet-viettel/sourcecode/application/modules/services/controllers/report.php

    r758 r765  
    1 <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
     1<?php
     2
     3if (! defined ( 'BASEPATH' ))
     4        exit ( 'No direct script access allowed' );
    25/**
    36 * Report Class
    4  * 
     7 *
    58 * @author dzungnv02
    6  *
     9 *       
    710 */
    8 
    911class Report extends MX_Controller {
    10        
    1112        private $_server = null;
    1213       
     14        /**
     15         *
     16         */
    1317        function __construct() {
    1418                parent::__construct ();
     
    1721                                'soap_version' => SOAP_1_2,
    1822                                'encoding' => 'UTF-8',
    19                                 'uri' => 'http://tempuri.org/'
     23                                'uri' => 'http://tempuri.org/' 
    2024                ) );
    2125        }
    2226       
     27        /**
     28         *
     29         */
    2330        function __destruct() {
    2431                ini_set ( "soap.wsdl_cache_enabled", "0" );
    2532        }
    2633       
     34        /**
     35         *
     36         */
    2737        public function index() {
    2838                if ($this->uri->segment ( 3 ) == "wsdl") {
     
    3040                        $this->load->view ( 'reportwsdl' );
    3141                        return;
    32                 }
    33                 else {
     42                } else {
    3443                        header ( 'Content-Type: text/html; charset: utf-8' );
    3544                        echo '<div>See Report service <a href="', base_url (), 'violetservice/report/wsdl">WSDL page</a></div>';
     
    3746        }
    3847       
     48        /**
     49         *
     50         * @return multitype:string number |string
     51         */
    3952        public function get() {
    40                 function revenueReport () {
    41                         $aryArgs = func_get_args ();   
    42                         list ( $username, $password, $fromDate, $toDate) = $aryArgs;
    43 
     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                       
    4462                        $CI = & get_instance ();
    45                         if (!$toDate) $toDate = date('Y-m-d');
    46                         $message = validate ($aryArgs);                 
    47                         $success = $message == '' ? 1 : 0;// 0:error; 1:Success;
     63                        if (! $toDate)
     64                                $toDate = date ( 'Y-m-d' );
     65                        $message = validate ( $aryArgs );
     66                        $success = $message == '' ? 1 : 0; // 0:error; 1:Success;
    4867                       
    4968                        if ($success == 1) {
    5069                                $CI->load->model ( 'Services_model' );
    5170                                $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );
    52                                 $from = explode('-', $fromDate);
    53                                 $to = explode('-', $toDate);
    54                                 $input = array('year' => $from[0], 'month' => $from[1], 'to_year' => $to[0], 'to_month' => $to[1], 'to_date' => $to[2]);
    55                                 $result = $CI->objReportModel->exportProvince( $input );
    56                                
    57                                 if (count($result) > 0 && is_array($result)) {
    58                                         //1|20140915|A076|0|0|0|100000|0|0
    59                                         $aryTmp = array();
    60                                         $aryResult = array();
    61                                         foreach ($result as $provinceCode => $record) {
    62                                                 //No|toDate|ProvCode|TBngay|LKTBThang|TongTBNam|DTngay|LuyKeTBThang|TongDTNam
    63                                                 $aryTmp[] = $record['stt'];
    64                                                 $aryTmp[] = implode('', $to);
    65                                                 $aryTmp[] = $provinceCode;
    66                                                 $aryTmp[] = $record['tbng'];
    67                                                 $aryTmp[] = $record['tbt'];
    68                                                 $aryTmp[] = $record['tbn'];
    69                                                 $aryTmp[] = $record['dtng'];
    70                                                 $aryTmp[] = $record['dtt'];
    71                                                 $aryTmp[] = $record['dtn'];
    72                                                 $aryResult[] = implode('|', $aryTmp);
    73                                                 $aryTmp = array();
     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 ();
    7499                                        }
    75100                                       
    76                                         $message = implode("\n", $aryResult);
     101                                        $message = implode ( "\n", $aryResult );
    77102                                        $success = 1;
    78103                                }
    79104                        }
    80105                       
    81                         return array($message, $success, date('YmdHis'));
    82                 }
    83                
    84                 function subscribersReport () {
    85                         $aryArgs = func_get_args ();   
    86                         list ( $username, $password, $fromDate, $toDate) = $aryArgs;
    87 
     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                       
    88121                        $CI = & get_instance ();
    89                         $message = validate ($aryArgs);
    90                         $success = $message == '' ? 1 : 0;// 0:error; 1:Success;
    91                         $message = $message == '' ? 'subscribersReport' : $message;
     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                        }
    92164                       
    93165                        $CI->load->model ( 'Services_model' );
    94                         $CI->load->model ( 'admin/Reportmodel', 'objReportModel' );                     
    95                        
    96                         return array($message, $success, date('YmdHis'));
    97                 }
    98                
    99                 function validate ($aryArgs) {
    100                         list ( $username, $password, $fromDate, $toDate) = $aryArgs;
     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;
    101182                       
    102183                        $CI = & get_instance ();
    103184                        $predefUsername = $CI->config->item ( 'report_username' );
    104185                        $predefPassword = $CI->config->item ( 'report_password' );
    105                                
     186                       
    106187                        $message = '';
    107                                
     188                       
    108189                        if (! $username) {
    109190                                $message = 'Username is required!';
    110                         }else if (! $password) {
    111                                 $message =  'Password is required!';
    112                         }else if ($username != $predefUsername) {
    113                                 $message =  'Username is not corrected!';
    114                         }else if ($password != $predefPassword) {
    115                                 $message =  'Password is not corrected!';
    116                         }else if (! $fromDate) {
    117                                 $message =  'fromDate is required!';
    118                         }else if (!preg_match('/^[0-9]{4}-(0[1-9]|1[0-2])-(0[1-9]|[1-2][0-9]|3[0-1])$/', $fromDate)) {
    119                                 $message =  'fromDate is not corrected!';
    120                         }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)) {
    121                                 $message =  'toDate is not corrected!';
    122                         }
    123 
     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                       
    124205                        return $message;
    125206                }
    126207               
    127                 $this->_server->addFunction ( array('revenueReport', 'subscribersReport'));
     208                $this->_server->addFunction ( array (
     209                                'revenueReport',
     210                                'subscribersReport'
     211                ) );
    128212               
    129213                try {
     
    136220                                $soapOutput = ob_get_clean ();
    137221                        }
    138                                
     222                       
    139223                        if ($soapOutput != '') {
    140                                 error_log(var_export($soapOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservicexml.log');
    141                                
    142                                 $response = preg_match('/revenueReportResponse/', $soapOutput) ? 'revenueReportResponse' : (preg_match('/subscribersReportResponse/', $soapOutput) ? 'subscribersReportResponse':'');
     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' : '');
    143227                               
    144228                                $pattern = '/<[^>]*[^\/]>/i';
    145229                                $aryOutput = preg_split ( $pattern, $soapOutput, - 1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE );
    146                                 error_log(var_export($aryOutput, true) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log');
     230                                error_log ( var_export ( $aryOutput, true ) . "\n\n\n", 3, '/srv/www/sbg/log/reportservice.log' );
    147231                                $aryData = array ();
    148232                                $aryData ['message'] = $aryOutput [1];
     
    159243                } catch ( Exception $e ) {
    160244                        $this->_server->fault ( 'Sender', $e->getMessage () );
    161                 }               
     245                }
    162246        }
    163247}
Note: See TracChangeset for help on using the changeset viewer.