Changeset 20129


Ignore:
Timestamp:
2011/02/10 15:30:51 (13 years ago)
Author:
kimoto
Message:

売上集計リファクタリング #962

Location:
branches/version-2_5-dev/data
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • branches/version-2_5-dev/data/Smarty/templates/admin/total/page_term.tpl

    r20116 r20129  
    5757     
    5858    <!--{if !$smarty.section.cnt.last}--> 
    59       <td class="center"><!--{*期間*}--><!--{$arrResults[cnt][$keyname]}--><!--{if $keyname == "key_day"}-->(<!--{$arrWDAY[$wday]}-->)<!--{/if}--><!--{$tpl_tail}--></td> 
     59      <td class="center"><!--{*期間*}--><!--{$arrResults[cnt].str_date}--></td> 
    6060    <!--{else}--> 
    6161      <td class="center"><!--{*期間*}-->合計</td> 
    6262    <!--{/if}--> 
    6363     
    64     <td class="right"><!--{*購入件数*}--><!--{$arrResults[cnt].total_order}-->件</td> 
    65     <td class="right"><!--{*男性*}--><!--{$arrResults[cnt].men}--></td> 
    66     <td class="right"><!--{*女性*}--><!--{$arrResults[cnt].women}--></td> 
    67     <td class="right"><!--{*男性(会員)*}--><!--{$arrResults[cnt].men_member}--></td> 
    68     <td class="right"><!--{*男性(非会員)*}--><!--{$arrResults[cnt].men_nonmember}--></td> 
    69     <td class="right"><!--{*女性(会員)*}--><!--{$arrResults[cnt].women_member}--></td> 
    70     <td class="right"><!--{*女性(非会員)*}--><!--{$arrResults[cnt].women_nonmember}--></td> 
     64    <td class="right"><!--{*購入件数*}--><!--{$arrResults[cnt].total_order|number_format}-->件</td> 
     65    <td class="right"><!--{*男性*}--><!--{$arrResults[cnt].men|number_format}--></td> 
     66    <td class="right"><!--{*女性*}--><!--{$arrResults[cnt].women|number_format}--></td> 
     67    <td class="right"><!--{*男性(会員)*}--><!--{$arrResults[cnt].men_member|number_format}--></td> 
     68    <td class="right"><!--{*男性(非会員)*}--><!--{$arrResults[cnt].men_nonmember|number_format}--></td> 
     69    <td class="right"><!--{*女性(会員)*}--><!--{$arrResults[cnt].women_member|number_format}--></td> 
     70    <td class="right"><!--{*女性(非会員)*}--><!--{$arrResults[cnt].women_nonmember|number_format}--></td> 
    7171    <td class="right"><!--{*購入合計*}--><!--{$arrResults[cnt].total|number_format}-->円</td> 
    7272    <td class="right"><!--{*購入平均*}--><!--{$arrResults[cnt].total_average|number_format}-->円</td> 
  • branches/version-2_5-dev/data/class/db/dbfactory/SC_DB_DBFactory_MYSQL.php

    r20116 r20129  
    148148    } 
    149149 
     150 
     151    /** 
     152     * 売上集計の期間別集計のSQLを返す 
     153     * 
     154     * @param mixed $type 
     155     * @return string 検索条件のSQL 
     156     */ 
     157    function getOrderTotalDaysWhereSql($type) { 
     158        switch($type){ 
     159        case 'month': 
     160            $format = '%m'; 
     161            break; 
     162        case 'year': 
     163            $format = '%Y'; 
     164            break; 
     165        case 'wday': 
     166            $format = '%a'; 
     167            break; 
     168        case 'hour': 
     169            $format = '%H'; 
     170            break; 
     171        default: 
     172            $format = '%Y-%m-%d'; 
     173            break; 
     174        } 
     175 
     176        return " date_format(create_date, '".$format."') AS str_date, 
     177            COUNT(order_id) AS total_order, 
     178            SUM(CASE WHEN order_sex = 1 THEN 1 ELSE 0 END) AS men, 
     179            SUM(CASE WHEN order_sex = 2 THEN 1 ELSE 0 END) AS women, 
     180            SUM(CASE WHEN customer_id <> 0 AND order_sex = 1 THEN 1 ELSE 0 END) AS men_member, 
     181            SUM(CASE WHEN customer_id <> 0 AND order_sex = 2 THEN 1 ELSE 0 END) AS women_member, 
     182            SUM(CASE WHEN customer_id = 0 AND order_sex = 1 THEN 1 ELSE 0 END) AS men_nonmember, 
     183            SUM(CASE WHEN customer_id = 0 AND order_sex = 2 THEN 1 ELSE 0 END) AS women_nonmember, 
     184            SUM(total) AS total, 
     185            AVG(total) AS total_average"; 
     186    } 
     187 
     188 
    150189    /** 
    151190     * 文字列連結を行う. 
     
    278317        return $changesql; 
    279318    } 
    280      
     319 
    281320    /** 
    282321     * ARRAY_TO_STRING(ARRAY(A),B) を GROUP_CONCAT() に変換する. 
     
    289328        if(strpos(strtoupper($sql), 'ARRAY_TO_STRING') !== FALSE) { 
    290329            preg_match_all('/ARRAY_TO_STRING.*?\(.*?ARRAY\(.*?SELECT (.+?) FROM (.+?) WHERE (.+?)\).*?\,.*?\'(.+?)\'.*?\)/is', $sql, $match, PREG_SET_ORDER); 
    291              
     330 
    292331            foreach($match as $item) { 
    293332                $replace = 'GROUP_CONCAT(' . $item[1] . ' SEPARATOR \'' . $item[4] . '\') FROM ' . $item[2] . ' WHERE ' . $item[3]; 
     
    297336        return $sql; 
    298337    } 
    299      
     338 
    300339    /** 
    301340     * WHERE 句置換用の配列を返す. 
     
    434473 
    435474    } 
    436      
     475 
    437476    /** 
    438477     * インデックス作成の追加定義を取得する 
  • branches/version-2_5-dev/data/class/db/dbfactory/SC_DB_DBFactory_PGSQL.php

    r20116 r20129  
    129129        return "(SELECT CASE WHEN (SELECT d1.downloadable_days_unlimited FROM dtb_baseinfo d1) = 1 AND o.payment_date IS NOT NULL THEN 1 WHEN DATE(NOW()) <= DATE(o.payment_date + '". $downloadable_days ." days') THEN 1 ELSE 0 END)"; 
    130130    } 
     131 
     132    /** 
     133     * 売上集計の期間別集計のSQLを返す 
     134     * 
     135     * @param mixed $type 
     136     * @return string 検索条件のSQL 
     137     */ 
     138    function getOrderTotalDaysWhereSql($type) { 
     139        switch($type){ 
     140        case 'month': 
     141            $format = 'MM'; 
     142            break; 
     143        case 'year': 
     144            $format = 'YYYY'; 
     145            break; 
     146        case 'wday': 
     147            $format = 'Dy'; 
     148            break; 
     149        case 'hour': 
     150            $format = 'HH24'; 
     151            break; 
     152        default: 
     153            $format = 'YYYY-MM-DD'; 
     154            break; 
     155        } 
     156 
     157        return "to_char(create_date, '".$format."') AS str_date, 
     158            COUNT(order_id) AS total_order, 
     159            SUM(CASE WHEN order_sex = 1 THEN 1 ELSE 0 END) AS men, 
     160            SUM(CASE WHEN order_sex = 2 THEN 1 ELSE 0 END) AS women, 
     161            SUM(CASE WHEN customer_id <> 0 AND order_sex = 1 THEN 1 ELSE 0 END) AS men_member, 
     162            SUM(CASE WHEN customer_id <> 0 AND order_sex = 2 THEN 1 ELSE 0 END) AS women_member, 
     163            SUM(CASE WHEN customer_id = 0 AND order_sex = 1 THEN 1 ELSE 0 END) AS men_nonmember, 
     164            SUM(CASE WHEN customer_id = 0 AND order_sex = 2 THEN 1 ELSE 0 END) AS women_nonmember, 
     165            SUM(total) AS total, 
     166            AVG(total) AS total_average"; 
     167    } 
     168 
    131169 
    132170    /** 
  • branches/version-2_5-dev/data/class/pages/admin/total/LC_Page_Admin_Total.php

    r20116 r20129  
    2121 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. 
    2222 */ 
    23  
    2423// {{{ requires 
    2524require_once(CLASS_REALDIR . "pages/admin/LC_Page_Admin.php"); 
     
    5049        // GDライブラリのインストール判定 
    5150        $this->install_GD = function_exists("gd_info") ? true : false; 
    52         $this->tpl_mainpage = 'total/index.tpl'; 
    53         $this->tpl_subnavi = 'total/subnavi.tpl'; 
    54         $this->tpl_graphsubtitle = 'total/subtitle.tpl'; 
    55         $this->tpl_titleimage = ROOT_URLPATH.'img/title/title_sale.jpg'; 
    56         $this->tpl_mainno = 'total'; 
    57  
    58         $masterData = new SC_DB_MasterData_Ex(); 
    59         $this->arrWDAY = $masterData->getMasterData("mtb_wday"); 
    60         $this->arrSex = $masterData->getMasterData("mtb_sex"); 
    61         $this->arrJob = $masterData->getMasterData("mtb_job"); 
    62         // ページタイトル 
    63         $this->arrTitle[''] = "期間別集計"; 
    64         $this->arrTitle['term'] = "期間別集計"; 
     51        $this->tpl_mainpage         = 'total/index.tpl'; 
     52        $this->tpl_subnavi          = 'total/subnavi.tpl'; 
     53        $this->tpl_graphsubtitle    = 'total/subtitle.tpl'; 
     54        $this->tpl_titleimage       = ROOT_URLPATH.'img/title/title_sale.jpg'; 
     55        $this->tpl_mainno           = 'total'; 
     56 
     57        $masterData                 = new SC_DB_MasterData_Ex(); 
     58        $this->arrWDAY              = $masterData->getMasterData("mtb_wday"); 
     59        $this->arrSex               = $masterData->getMasterData("mtb_sex"); 
     60        $this->arrJob               = $masterData->getMasterData("mtb_job"); 
     61 
     62        // 登録・更新日検索用 
     63        $objDate                    = new SC_Date(); 
     64        $objDate->setStartYear(RELEASE_YEAR); 
     65        $objDate->setEndYear(DATE("Y")); 
     66        $this->arrYear              = $objDate->getYear(); 
     67        $this->arrMonth             = $objDate->getMonth(); 
     68        $this->arrDay               = $objDate->getDay(); 
     69 
     70        // ページタイトル todo あとでなおす 
     71        $this->arrTitle['']         = "期間別集計"; 
     72        $this->arrTitle['term']     = "期間別集計"; 
    6573        $this->arrTitle['products'] = "商品別集計"; 
    66         $this->arrTitle['age'] = "年代別集計"; 
    67         $this->arrTitle['job'] = "職業別集計"; 
    68         $this->arrTitle['member'] = "会員別集計"; 
    69  
    70         // キャッシュ回避のために日付を渡す 
    71         $this->cashtime = time(); 
    72         $this->objBatch = new SC_Batch_Daily_Ex(); 
    73  
    74         // TODO エレガントじゃない... 
    75         if (!isset($_POST['search_startyear'])) $_POST['search_startyear'] = ""; 
    76         if (!isset($_POST['search_startmonth'])) $_POST['search_startmonth'] = ""; 
    77         if (!isset($_POST['search_startday'])) $_POST['search_startday'] = ""; 
    78         if (!isset($_POST['search_endyear'])) $_POST['search_endyear'] = ""; 
    79         if (!isset($_POST['search_endmonth'])) $_POST['search_endmonth'] = ""; 
    80         if (!isset($_POST['search_endday'])) $_POST['search_endday'] = ""; 
    81  
    82         if (!isset($_POST['search_startyear_m'])) $_POST['search_startyear_m'] = ""; 
     74        $this->arrTitle['age']      = "年代別集計"; 
     75        $this->arrTitle['job']      = "職業別集計"; 
     76        $this->arrTitle['member']   = "会員別集計"; 
     77 
     78        // 月度集計のkey名 
     79        $this->arrSearchForm1       = array('search_startyear_m', 'search_startmonth_m'); 
     80 
     81        // 期間別集計のkey名 
     82        $this->arrSearchForm2       = array('search_startyear', 
     83                                            'search_startmonth', 
     84                                            'search_startday', 
     85                                            'search_endyear', 
     86                                            'search_endmonth', 
     87                                            'search_endday'); 
    8388    } 
    8489 
     
    100105    function action() { 
    101106        $objSess = new SC_Session(); 
    102  
    103107        // 認証可否の判定 
    104108        SC_Utils_Ex::sfIsSuccess($objSess); 
    105  
    106         // 入力期間をセッションに記録する 
    107         $this->lfSaveDateSession(); 
    108109 
    109110        if(isset($_GET['draw_image']) && $_GET['draw_image'] != ""){ 
     
    114115 
    115116        // パラメータ管理クラス 
    116         $this->objFormParam = new SC_FormParam(); 
     117        $objFormParam = new SC_FormParam(); 
    117118        // パラメータ情報の初期化 
    118         $this->lfInitParam(); 
    119         $this->objFormParam->setParam($_POST); 
    120         $this->objFormParam->setParam($_GET); 
     119        $this->lfInitParam($objFormParam); 
     120        $objFormParam->setParam($_POST); 
     121        $objFormParam->setParam($_GET); 
    121122 
    122123        // 検索ワードの引き継ぎ 
    123         foreach ($_POST as $key => $val) { 
    124             if (ereg("^search_", $key)) { 
    125                 $this->arrHidden[$key] = $val; 
    126             } 
    127         } 
     124        $this->arrHidden = SC_Utils_Ex::sfFilterKey($_POST, '^search_'); 
    128125 
    129126        switch($this->getMode()) { 
    130127        case 'csv': 
    131128        case 'search': 
    132             // 入力値の変換 
    133             $this->objFormParam->convParam(); 
    134             $this->arrErr = $this->lfCheckError(); 
    135             $arrRet = $this->objFormParam->getHashArray(); 
    136             // 入力エラーなし 
     129 
     130            $this->arrErr = $this->lfCheckError($objFormParam); 
    137131            if (empty($this->arrErr)) { 
    138                 foreach ($arrRet as $key => $val) { 
    139                     if($val == "") { 
    140                         continue; 
    141                     } 
    142                     switch ($key) { 
    143                     case 'search_startyear': 
    144                         $sdate = $this->objFormParam->getValue('search_startyear') . "/" . $this->objFormParam->getValue('search_startmonth') . "/" . $this->objFormParam->getValue('search_startday'); 
    145                         break; 
    146                     case 'search_endyear': 
    147                         $edate = $this->objFormParam->getValue('search_endyear') . "/" . $this->objFormParam->getValue('search_endmonth') . "/" . $this->objFormParam->getValue('search_endday'); 
    148                         break; 
    149                     case 'search_startyear_m': 
    150                         list($sdate, $edate) = SC_Utils_Ex::sfTermMonth($this->objFormParam->getValue('search_startyear_m'), $this->objFormParam->getValue('search_startmonth_m'), CLOSE_DAY); 
    151                         break; 
    152                     default: 
    153                         break; 
    154                     } 
    155                 } 
    156                 if($this->objFormParam->getValue('type') != "") { 
    157                     $type = $this->objFormParam->getValue('type'); 
    158                 } else { 
    159                     $type = ""; 
    160                 } 
    161  
    162                 $page = $this->objFormParam->getValue('page'); 
    163  
    164                 switch($page) { 
    165                     // 商品別集計 
    166                 case 'products': 
    167                     if($type == "") { 
    168                         $type = 'all'; 
    169                     } 
    170                     $this->tpl_page_type = "total/page_products.tpl"; 
    171                     // 未集計データの集計を行う 
    172                     if(!DAILY_BATCH_MODE) { 
    173                         $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); 
    174                     } 
    175                     // 検索結果の取得 
    176                     $this->lfGetOrderProducts($type, $sdate, $edate, $this, $this->install_GD, $mode); 
    177                     break; 
    178                     // 職業別集計 
    179                 case 'job': 
    180                     if($type == "") { 
    181                         $type = 'all'; 
    182                     } 
    183                     $this->tpl_page_type = "total/page_job.tpl"; 
    184                     // 未集計データの集計を行う 
    185                     if(!DAILY_BATCH_MODE) { 
    186                         $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); 
    187                     } 
    188                     // 検索結果の取得 
    189                     $this->lfGetOrderJob($type, $sdate, $edate, $this, $this->install_GD); 
    190                     break; 
    191                     // 会員別集計 
    192                 case 'member': 
    193                     if($type == "") { 
    194                         $type = 'all'; 
    195                     } 
    196                     $this->tpl_page_type = "total/page_member.tpl"; 
    197                     // 未集計データの集計を行う 
    198                     if(!DAILY_BATCH_MODE) { 
    199                         $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); 
    200                     } 
    201                     // 検索結果の取得 
    202                     $this->lfGetOrderMember($type, $sdate, $edate, $this, $this->install_GD); 
    203                     break; 
    204                     // 年代別集計 
    205                 case 'age': 
    206                     if($type == "") { 
    207                         $type = 'all'; 
    208                     } 
    209  
    210                     $this->tpl_page_type = "total/page_age.tpl"; 
    211                     // 未集計データの集計を行う 
    212                     if(!DAILY_BATCH_MODE) { 
    213                         $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); 
    214                     } 
    215                     // 検索結果の取得 
    216                     $this->lfGetOrderAge($type, $sdate, $edate, $this, $this->install_GD); 
    217                     break; 
    218                     // 期間別集計 
    219                 default: 
    220                     if (!isset($type)) $type = ""; 
    221                     if($type == "") { 
    222                         $type = 'day'; 
    223                     } 
    224                     $this->tpl_page_type = "total/page_term.tpl"; 
    225                     // 未集計データの集計を行う 
    226                     if(!DAILY_BATCH_MODE) { 
    227                         $this->objBatch->lfRealTimeDailyTotal($sdate, $edate); 
    228                     } 
    229                     // 検索結果の取得 
    230                     $this->lfGetOrderTerm($type, $sdate, $edate, $this, $this->install_GD); 
    231  
    232                     break; 
    233                 } 
    234                 //TODO 要リファクタリング(MODE if利用) 
     132 
     133                // 日付 
     134                list($sdate, $edate) = $this->lfSetStartEndDate($objFormParam); 
     135 
     136                // ページ 
     137                $page = ($objFormParam->getValue('page')) ? $objFormParam->getValue('page') : 'term'; 
     138 
     139                // 集計種類 
     140                $type = ($objFormParam->getValue('type')) ? $objFormParam->getValue('type'): 'all'; 
     141 
     142                $this->tpl_page_type = "total/page_". $page .".tpl"; 
     143                list($this->arrResults, $this->tpl_image) = call_user_func_array(array($this, 'lfGetOrder'.$page), 
     144                                                                                 array($type, $sdate, $edate)); 
    235145                if($this->getMode() == 'csv') { 
    236146                    // CSV出力タイトル行の取得 
    237                     list($arrTitleCol, $arrDataCol) = $this->lfGetCSVColum($page, $this->keyname); 
     147                    list($arrTitleCol, $arrDataCol) = $this->lfGetCSVColum($page); 
    238148                    $head = SC_Utils_Ex::sfGetCSVList($arrTitleCol); 
    239149                    $data = $this->lfGetDataColCSV($this->arrResults, $arrDataCol); 
     150 
    240151                    // CSVを送信する。 
    241                     SC_Utils_Ex::sfCSVDownload($head.$data, $page."_".$type); 
     152                    list($fime_name, $data) = SC_Utils_Ex::sfGetCSVData($head.$data); 
     153                    $this->sendResponseCSV($fime_name, $data); 
    242154                    exit; 
    243155                } 
     
    245157            break; 
    246158        default: 
    247             if(count($_GET) == 0) { 
    248                 // バッチモードの場合のみ実行する(当日の集計を行うため) 
    249                 if(DAILY_BATCH_MODE) { 
    250                     // 3日前までの集計 
    251                     $this->objBatch->lfStartDailyTotal(3,0); 
    252                 } 
    253             } 
    254             break; 
    255         } 
    256  
    257         // 登録・更新日検索用 
    258         $objDate = new SC_Date(); 
    259         $objDate->setStartYear(RELEASE_YEAR); 
    260         $objDate->setEndYear(DATE("Y")); 
    261         $this->arrYear = $objDate->getYear(); 
    262         $this->arrMonth = $objDate->getMonth(); 
    263         $this->arrDay = $objDate->getDay(); 
     159        } 
     160 
     161 
     162        // 画面宣しても日付が保存される 
     163        $_SESSION           = $this->lfSaveDateSession($_SESSION, $this->arrHidden); 
     164        $objFormParam->setParam($_SESSION['total']); 
    264165        // 入力値の取得 
    265         $this->arrForm = $this->objFormParam->getFormParamList(); 
    266  
    267         $this->tpl_subtitle = $this->arrTitle[$this->objFormParam->getValue('page')]; 
     166        $this->arrForm      = $objFormParam->getFormParamList(); 
     167        $this->tpl_subtitle = $this->arrTitle[$objFormParam->getValue('page')]; 
    268168    } 
    269169 
     
    277177    } 
    278178 
    279     /* セッションに入力期間を記録する */ 
    280     function lfSaveDateSession() { 
    281         if (!isset($_POST['form'])) $_POST['form'] = ""; 
    282  
    283         if($_POST['form'] == 1) { 
    284             $_SESSION['total']['startyear_m'] = $_POST['search_startyear_m']; 
    285             $_SESSION['total']['startmonth_m'] = $_POST['search_startmonth_m']; 
    286         } 
    287  
    288         if($_POST['form'] == 2) { 
    289             $_SESSION['total']['startyear'] = $_POST['search_startyear']; 
    290             $_SESSION['total']['startmonth'] = $_POST['search_startmonth']; 
    291             $_SESSION['total']['startday'] = $_POST['search_startday']; 
    292             $_SESSION['total']['endyear'] = $_POST['search_endyear']; 
    293             $_SESSION['total']['endmonth'] = $_POST['search_endmonth']; 
    294             $_SESSION['total']['endday'] = $_POST['search_endday']; 
    295         } 
    296     } 
    297  
    298     /* デフォルト値の取得 */ 
    299     function lfGetDateDefault() { 
    300         $year = date("Y"); 
    301         $month = date("m"); 
    302         $day = date("d"); 
    303  
    304         $list = isset($_SESSION['total']) ? $_SESSION['total'] : ""; 
    305  
    306         // セッション情報に開始月度が保存されていない。 
    307         if(empty($_SESSION['total']['startyear_m'])) { 
    308             $list['startyear_m'] = $year; 
    309             $list['startmonth_m'] = $month; 
    310         } 
    311  
    312         // セッション情報に開始日付、終了日付が保存されていない。 
    313         if(empty($_SESSION['total']['startyear']) && empty($_SESSION['total']['endyear'])) { 
    314             $list['startyear'] = $year; 
    315             $list['startmonth'] = $month; 
    316             $list['startday'] = $day; 
    317             $list['endyear'] = $year; 
    318             $list['endmonth'] = $month; 
    319             $list['endday'] = $day; 
    320         } 
    321  
    322         return $list; 
    323     } 
    324  
    325179    /* パラメータ情報の初期化 */ 
    326     function lfInitParam() { 
    327         // デフォルト値の取得 
    328         $arrList = $this->lfGetDateDefault(); 
    329  
     180    function lfInitParam(&$objFormParam) { 
    330181        // 月度集計 
    331         $this->objFormParam->addParam("月度", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']); 
    332         $this->objFormParam->addParam("月度", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']); 
     182        $objFormParam->addParam("月度", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     183        $objFormParam->addParam("月度", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
    333184        // 期間集計 
    334         $this->objFormParam->addParam("開始日", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']); 
    335         $this->objFormParam->addParam("開始日", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']); 
    336         $this->objFormParam->addParam("開始日", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']); 
    337         $this->objFormParam->addParam("終了日", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']); 
    338         $this->objFormParam->addParam("終了日", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']); 
    339         $this->objFormParam->addParam("終了日", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']); 
     185        $objFormParam->addParam("開始日", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     186        $objFormParam->addParam("開始日", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     187        $objFormParam->addParam("開始日", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     188        $objFormParam->addParam("終了日", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     189        $objFormParam->addParam("終了日", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
     190        $objFormParam->addParam("終了日", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK")); 
    340191 
    341192        // hiddenデータの取得用 
    342         $this->objFormParam->addParam("", "page"); 
    343         $this->objFormParam->addParam("", "type"); 
    344         $this->objFormParam->addParam("", "mode"); 
    345  
     193        $objFormParam->addParam("", "page"); 
     194        $objFormParam->addParam("", "type"); 
     195        $objFormParam->addParam("", "mode"); 
    346196    } 
    347197 
    348198    /* 入力内容のチェック */ 
    349     function lfCheckError() { 
    350         // 入力データを渡す。 
    351         $arrRet =  $this->objFormParam->getHashArray(); 
    352         $objErr = new SC_CheckError($arrRet); 
    353         $objErr->arrErr = $this->objFormParam->checkError(); 
     199    function lfCheckError(&$objFormParam) { 
     200 
     201        $objFormParam->convParam(); 
     202        $objErr         = new SC_CheckError(); 
     203        $objErr->arrErr = $objFormParam->checkError(); 
    354204 
    355205        // 特殊項目チェック 
    356         if($_POST['form'] == 1) { 
     206        if($objFormParam->getValue('form') == 1) { 
    357207            $objErr->doFunc(array("月度", "search_startyear_m"), array("ONE_EXIST_CHECK")); 
    358208        } 
    359209 
    360         if($_POST['form'] == 2) { 
     210        if($objFormParam->getValue('form') == 2) { 
    361211            $objErr->doFunc(array("期間", "search_startyear", "search_endyear"), array("ONE_EXIST_CHECK")); 
    362212        } 
     
    369219    } 
    370220 
     221 
     222    /* サブナビを移動しても日付が残るようにセッションに入力期間を記録する */ 
     223    function lfSaveDateSession($session, $arrForm) { 
     224 
     225        // session の初期化をする 
     226        if (!isset($session['total'])) { 
     227            $session['total'] = $this->lfGetDateInit(); 
     228        } 
     229 
     230        if (!empty($arrForm)) { 
     231            $session['total'] = array_merge($session['total'], $arrForm); 
     232        } 
     233 
     234        return $session; 
     235    } 
     236 
     237 
     238    /* 日付の初期値 */ 
     239    function lfGetDateInit() { 
     240        $search_startyear_m     = $search_startyear  = $search_endyear  = date("Y"); 
     241        $search_startmonth_m    = $search_startmonth = $search_endmonth = date("m"); 
     242        $search_startday        = $search_endday     = date("d"); 
     243 
     244        return compact($this->arrSearchForm1, $this->arrSearchForm2); 
     245    } 
     246 
     247    /* フォームで入力された日付を適切な形にする */ 
     248    function lfSetStartEndDate(&$objFormParam) { 
     249 
     250        $arrRet = $objFormParam->getHashArray(); 
     251 
     252        foreach ($arrRet as $key => $val) { 
     253            if($val == "") { 
     254                continue; 
     255            } 
     256            switch ($key) { 
     257            case 'search_startyear': 
     258                $sdate = $objFormParam->getValue('search_startyear') . "/" . $objFormParam->getValue('search_startmonth') . "/" . $objFormParam->getValue('search_startday'); 
     259                break; 
     260            case 'search_endyear': 
     261                $edate = $objFormParam->getValue('search_endyear') . "/" . $objFormParam->getValue('search_endmonth') . "/" . $objFormParam->getValue('search_endday'); 
     262                break; 
     263            case 'search_startyear_m': 
     264                list($sdate, $edate) = SC_Utils_Ex::sfTermMonth($objFormParam->getValue('search_startyear_m'), 
     265                                                                $objFormParam->getValue('search_startmonth_m'), 
     266                                                                CLOSE_DAY); 
     267                break; 
     268            default: 
     269                break; 
     270            } 
     271        } 
     272 
     273        return array($sdate, $edate); 
     274    } 
     275 
     276 
    371277    /* 折れ線グラフの作成 */ 
    372278    function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) { 
     
    375281 
    376282        // 結果が0行以上ある場合のみグラフを生成する。 
    377         if(count($arrResults) > 0) { 
     283        if(count($arrResults) > 0 && $this->install_GD) { 
    378284 
    379285            // グラフの生成 
     
    432338        $ret_path = ""; 
    433339        // 結果が0行以上ある場合のみグラフを生成する。 
    434         if(count($arrResults) > 0) { 
     340        if(count($arrResults) > 0 && $this->install_GD) { 
    435341            // グラフの生成 
    436342            $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, 
     
    443349 
    444350            $objGraphPie = new SC_GraphPie(); 
    445  
    446             /* デバッグ表示用 by naka 
    447              foreach($arrList as $key => $val) { 
    448              $objGraphPie->debugPrint("key:$key val:$val"); 
    449              } 
    450             */ 
    451351 
    452352            // データをセットする 
     
    482382 
    483383        // 結果が0行以上ある場合のみグラフを生成する。 
    484         if(count($arrResults) > 0) { 
     384        if(count($arrResults) > 0 && $this->install_GD) { 
    485385            // グラフの生成 
    486386            $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX); 
     
    578478 
    579479    /** 会員別集計 **/ 
    580     function lfGetOrderMember($type, $sdate, $edate, &$objPage, $graph = true) { 
     480    function lfGetOrderMember($type, $sdate, $edate) { 
     481        $objQuery = SC_Query::getSingletonInstance(); 
     482 
    581483        list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); 
     484        $where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL; 
    582485 
    583486        // 会員集計の取得 
    584         $col = "COUNT(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average, order_sex"; 
    585         $from = "dtb_order"; 
    586         $objQuery = new SC_Query(); 
    587         $objQuery->setGroupBy("order_sex"); 
    588  
    589         $tmp_where = $where . " AND customer_id <> 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL; 
    590         $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval); 
    591  
    592         // 会員購入であることを記録する。 
    593         $max = count($arrRet); 
    594         for($i = 0; $i < $max; $i++) { 
    595             $arrRet[$i]['member_name'] = '会員'.$this->arrSex[$arrRet[$i]['order_sex']]; 
    596         } 
    597         $objPage->arrResults = $arrRet; 
    598  
    599         // 非会員集計の取得 
    600         $tmp_where = $where . " AND customer_id = 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL; 
    601         $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval); 
    602         // 非会員購入であることを記録する。 
    603         $max = count($arrRet); 
    604         for($i = 0; $i < $max; $i++) { 
    605             $arrRet[$i]['member_name'] = '非会員'.$this->arrSex[$arrRet[$i]['order_sex']]; 
    606         } 
    607  
    608         $objPage->arrResults = array_merge($objPage->arrResults, $arrRet); 
    609  
    610         // 円グラフの生成 
    611         if($graph) { 
    612             $image_key = "member"; 
    613             $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "member_name", $image_key, "(売上比率)", $sdate, $edate); 
    614         } 
     487        $col        = " 
     488            COUNT(order_id) AS order_count, 
     489            SUM(total) AS total, 
     490            AVG(total) AS total_average, 
     491            CASE 
     492                WHEN customer_id <> 0 AND order_sex = 1 THEN 1 
     493                WHEN customer_id <> 0 AND order_sex = 2 THEN 2 
     494                WHEN customer_id = 0 AND order_sex = 1 THEN 3 
     495                WHEN customer_id = 0 AND order_sex = 2 THEN 4 
     496                ELSE 0 
     497            END AS member, 
     498            order_sex, 
     499            customer_id 
     500                "; 
     501        $from       = "dtb_order"; 
     502 
     503        $objQuery->setGroupBy("member"); 
     504 
     505        $arrTotalResults = $objQuery->select($col, $from, $where, $arrval); 
     506 
     507        foreach($arrTotalResults as &$arrResult) { 
     508            $member_key = $arrResult['order_sex']; 
     509            if($member_key != "") { 
     510                $arrResult['member_name'] = (($arrResult['customer_id']) ? '会員' : '非会員') . $this->arrSex[$member_key]; 
     511            } else { 
     512                $arrResult['member_name'] = "未回答"; 
     513            } 
     514        } 
     515 
     516        $tpl_image = $this->lfGetGraphPie($arrTotalResults, "member_name", "member", "(売上比率)", $sdate, $edate); 
     517 
     518        return array($arrTotalResults, $tpl_image); 
    615519    } 
    616520 
    617521    /** 商品別集計 **/ 
    618     function lfGetOrderProducts($type, $sdate, $edate, &$objPage, $graph = true, $mode = "") { 
     522    function lfGetOrderProducts($type, $sdate, $edate) { 
     523        $objQuery = SC_Query::getSingletonInstance(); 
     524 
    619525        list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); 
    620526 
    621         $where .= " and del_flg=0 and status <> " . ORDER_CANCEL; 
    622  
    623         $sql = "SELECT T1.product_id, T1.product_code, T1.product_name, T1.products_count, T1.order_count, T1.price, T1.total "; 
    624         $sql.= "FROM ( "; 
    625         $sql.= "SELECT product_id, product_name, product_code, price, "; 
    626         $sql.= "COUNT(*) AS order_count, "; 
    627         $sql.= "SUM(quantity) AS products_count, "; 
    628         $sql.= "(price * sum(quantity)) AS total "; 
    629         $sql.= "FROM dtb_order_detail AS T2 WHERE EXISTS (SELECT 1 FROM dtb_order AS T3 WHERE T2.order_id = T3.order_id AND $where ) "; 
    630         $sql.= "GROUP BY product_id, product_name, product_code, price "; 
    631         $sql.= ") AS T1 "; 
    632         $sql.= "ORDER BY T1.total DESC "; 
    633  
     527        $where .= " AND dtb_order.del_flg = 0 AND dtb_order.status <> " . ORDER_CANCEL; 
     528 
     529        $col = " 
     530                product_id, 
     531                product_code, 
     532                product_name, 
     533                SUM(quantity) AS products_count, 
     534                COUNT(order_id) AS order_count, 
     535                price, 
     536                (price * SUM(quantity)) AS total"; 
     537 
     538        $from = "dtb_order_detail JOIN dtb_order USING(order_id)"; 
     539 
     540        /* 
    634541        if($mode != "csv") { 
    635542            $sql.= "LIMIT " . PRODUCTS_TOTAL_MAX; 
    636         } 
    637  
    638         $objQuery = new SC_Query(); 
    639         $objPage->arrResults = $objQuery->getAll($sql, $arrval); 
    640  
    641         // 円グラフの生成 
    642         if($graph) { 
    643             $image_key = "products_" . $type; 
    644             $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "product_name", $image_key, "(売上比率)", $sdate, $edate); 
    645         } 
     543        }*/ 
     544 
     545        // 要index 
     546        //$objQuery->setGroupBy('product_id, product_name, product_code, price'); 
     547        $objQuery->setGroupBy('product_id'); 
     548        $objQuery->setOrder('total DESC'); 
     549        $arrTotalResults = $objQuery->select($col, $from, $where, $arrval); 
     550 
     551        $tpl_image  = $this->lfGetGraphPie($arrTotalResults, "product_name", "products_" . $type, "(売上比率)", $sdate, $edate); 
     552 
     553        return array($arrTotalResults, $tpl_image); 
    646554    } 
    647555 
    648556    /** 職業別集計 **/ 
    649     function lfGetOrderJob($type, $sdate, $edate, &$objPage, $graph = true) { 
    650         list($where, $arrval) = $this->lfGetWhereMember('T2.create_date', $sdate, $edate, $type); 
    651  
    652         $sql = "SELECT job, count(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average "; 
    653         $sql.= "FROM dtb_customer AS T1 LEFT JOIN dtb_order AS T2 USING ( customer_id ) WHERE $where AND T2.del_flg = 0 and T2.status <> " . ORDER_CANCEL; 
    654         $sql.= " GROUP BY job ORDER BY total DESC"; 
    655  
    656         $objQuery = new SC_Query(); 
    657         $objPage->arrResults = $objQuery->getAll($sql, $arrval); 
    658  
    659         $max = count($objPage->arrResults); 
    660         for($i = 0; $i < $max; $i++) { 
    661             $job_key = $objPage->arrResults[$i]['job']; 
     557    function lfGetOrderJob($type, $sdate, $edate) { 
     558        $objQuery = SC_Query::getSingletonInstance(); 
     559        list($where, $arrval) = $this->lfGetWhereMember('dtb_order.create_date', $sdate, $edate, $type); 
     560 
     561        $col    = ' 
     562            job, 
     563            COUNT(order_id) AS order_count, 
     564            SUM(total) AS total, 
     565            AVG(total) AS total_average 
     566            '; 
     567 
     568        $from   = 'dtb_order JOIN dtb_customer USING ( customer_id )'; 
     569 
     570        $where .= " AND dtb_order.del_flg = 0 AND dtb_order.status <> " . ORDER_CANCEL; 
     571 
     572        $objQuery->setGroupBy('job'); 
     573        $objQuery->setOrder('total DESC'); 
     574        $arrTotalResults = $objQuery->select($col, $from, $where, $arrval); 
     575 
     576 
     577        foreach($arrTotalResults as &$arrResult) { 
     578            $job_key = $arrResult['job']; 
    662579            if($job_key != "") { 
    663                 $objPage->arrResults[$i]['job_name'] = $this->arrJob[$job_key]; 
     580                $arrResult['job_name'] = $this->arrJob[$job_key]; 
    664581            } else { 
    665                 $objPage->arrResults[$i]['job_name'] = "未回答"; 
    666             } 
    667         } 
    668  
    669         // 円グラフの生成 
    670         if($graph) { 
    671             $image_key = "job_" . $type; 
    672             $objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "job_name", $image_key, "(売上比率)", $sdate, $edate); 
    673         } 
     582                $arrResult['job_name'] = "未回答"; 
     583            } 
     584 
     585        } 
     586        $tpl_image     = $this->lfGetGraphPie($arrTotalResults, "job_name", "job_" . $type, "(売上比率)", $sdate, $edate); 
     587 
     588        return array($arrResults, $tpl_image); 
    674589    } 
    675590 
    676591    /** 年代別集計 **/ 
    677     function lfGetOrderAge($type, $sdate, $edate, &$objPage, $graph = true) { 
    678  
    679         list($where, $arrval) = $this->lfGetWhereMember('order_date', $sdate, $edate, $type, "member"); 
    680  
    681         $sql = "SELECT SUM(order_count) AS order_count, SUM(total) AS total, start_age, end_age "; 
    682         $sql.= "FROM dtb_bat_order_daily_age WHERE $where "; 
    683         $sql.= "GROUP BY start_age, end_age ORDER BY start_age, end_age"; 
    684  
    685         $objQuery = new SC_Query(); 
    686         $objPage->arrResults = $objQuery->getAll($sql, $arrval); 
    687  
    688         $max = count($objPage->arrResults); 
    689         for($i = 0; $i < $max; $i++) { 
    690             if($objPage->arrResults[$i]['order_count'] > 0) { 
    691                 $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['order_count']); 
    692             } 
    693             $start_age = $objPage->arrResults[$i]['start_age']; 
    694             $end_age = $objPage->arrResults[$i]['end_age']; 
    695             if($start_age != "" || $end_age != "") { 
    696                 if($end_age != 999) { 
    697                     $objPage->arrResults[$i]['age_name'] = $start_age . "~" . $end_age . "歳"; 
    698                 } else { 
    699                     $objPage->arrResults[$i]['age_name'] = $start_age . "歳~"; 
    700                 } 
     592    function lfGetOrderAge($type, $sdate, $edate) { 
     593 
     594        $objQuery = SC_Query::getSingletonInstance(); 
     595 
     596        list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); 
     597 
     598        // todo postgres 
     599        $col    = ' 
     600            trunc((YEAR(create_date) - YEAR(order_birth)) - (RIGHT(create_date, 5) < RIGHT(order_birth, 5)), -1) as age, 
     601            COUNT(order_id) AS order_count, 
     602            SUM(total) AS total, 
     603            AVG(total) AS total_average 
     604            '; 
     605 
     606        $from   = 'dtb_order'; 
     607 
     608        $where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL; 
     609 
     610        $objQuery->setGroupBy('age'); 
     611        $objQuery->setOrder('age DESC'); 
     612        $arrTotalResults = $objQuery->select($col, $from, $where, $arrval); 
     613 
     614        foreach($arrTotalResults as &$arrResult) { 
     615            $age_key = $arrResult['age']; 
     616            if($age_key != "") { 
     617                $arrResult['age_name'] = $arrResult['age'] . '代'; 
    701618            } else { 
    702                 $objPage->arrResults[$i]['age_name'] = "未回答"; 
    703             } 
    704         } 
    705  
    706         // 棒グラフの生成 
    707         if($graph) { 
    708             $image_key = "age_" . $type; 
    709             $xtitle = "(年齢)"; 
    710             $ytitle = "(売上合計)"; 
    711             $objPage->tpl_image = $this->lfGetGraphBar($objPage->arrResults, "age_name", $image_key, $xtitle, $ytitle, $sdate, $edate); 
    712         } 
     619                $arrResult['age_name'] = "未回答"; 
     620            } 
     621 
     622        } 
     623        $tpl_image = $this->lfGetGraphBar($arrTotalResults, "age_name", "age_" . $type, "(年齢)", "(売上合計)", $sdate, $edate); 
     624 
     625        return array($arrTotalResults, $tpl_image); 
    713626    } 
    714627 
    715628    /** 期間別集計 **/ 
    716     function lfGetOrderTerm($type, $sdate, $edate, &$objPage, $graph = true) { 
    717  
    718         $tmp_col = "sum(total_order) as total_order, sum(men) as men, sum(women) as women,"; 
    719         $tmp_col.= "sum(men_member) as men_member, sum(men_nonmember) as men_nonmember,"; 
    720         $tmp_col.= "sum(women_member) as women_member, sum(women_nonmember) as women_nonmember,"; 
    721         $tmp_col.= "sum(total) as total, (avg(total_average)) as total_average"; 
    722         $objQuery = new SC_Query(); 
    723  
    724         switch($type) { 
    725             // 月別 
     629    // todo あいだの日付埋める 
     630    function lfGetOrderTerm($type, $sdate, $edate) { 
     631        $objQuery   = SC_Query::getSingletonInstance(); 
     632 
     633        list($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate); 
     634        $where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL; 
     635 
     636        switch($type){ 
    726637        case 'month': 
    727             $col = $tmp_col . ",key_month"; 
    728             $objQuery->setGroupBy("key_month"); 
    729             $objQuery->setOrder("key_month"); 
    730             $objPage->keyname = "key_month"; 
    731             $objPage->tpl_tail = "月"; 
    732             $from = "dtb_bat_order_daily"; 
    733638            $xtitle = "(月別)"; 
    734639            $ytitle = "(売上合計)"; 
    735             break; 
    736             // 年別 
     640            $format = '%m'; 
     641            break; 
    737642        case 'year': 
    738             $col = $tmp_col . ",key_year"; 
    739             $objQuery->setGroupBy("key_year"); 
    740             $objQuery->setOrder("key_year"); 
    741             $objPage->keyname = "key_year"; 
    742             $objPage->tpl_tail = "年"; 
    743             $from = "dtb_bat_order_daily"; 
    744643            $xtitle = "(年別)"; 
    745644            $ytitle = "(売上合計)"; 
    746             break; 
    747             // 曜日別 
     645            $format = '%Y'; 
     646            break; 
    748647        case 'wday': 
    749             $col = $tmp_col . ",key_wday, wday"; 
    750             $objQuery->setGroupBy("key_wday, wday"); 
    751             $objQuery->setOrder("wday"); 
    752             $objPage->keyname = "key_wday"; 
    753             $objPage->tpl_tail = "曜日"; 
    754             $from = "dtb_bat_order_daily"; 
    755648            $xtitle = "(曜日別)"; 
    756649            $ytitle = "(売上合計)"; 
    757             break; 
    758             // 時間別 
     650            $format = '%a'; 
     651            break; 
    759652        case 'hour': 
    760             $col = $tmp_col . ",hour"; 
    761             $objQuery->setGroupBy("hour"); 
    762             $objQuery->setOrder("hour"); 
    763             $objPage->keyname = "hour"; 
    764             $objPage->tpl_tail = "時"; 
    765             $from = "dtb_bat_order_daily_hour"; 
    766653            $xtitle = "(時間別)"; 
    767654            $ytitle = "(売上合計)"; 
     655            $format = '%H'; 
    768656            break; 
    769657        default: 
    770             $col = "*"; 
    771             $objQuery->setOrder("key_day"); 
    772             $objPage->keyname = "key_day"; 
    773             $from = "dtb_bat_order_daily"; 
    774658            $xtitle = "(日別)"; 
    775659            $ytitle = "(売上合計)"; 
    776             break; 
    777         } 
    778  
    779         if (!isset($where)) $where = ""; 
    780  
    781         // 取得日付の指定 
    782         if($sdate != "") { 
    783             if ($where != "") { 
    784                 $where.= " AND "; 
    785             } 
    786             $where.= " order_date >= '". $sdate ."'"; 
    787         } 
    788  
    789         if($edate != "") { 
    790             if ($where != "") { 
    791                 $where.= " AND "; 
    792             } 
    793             $edate_next = date("Y/m/d",strtotime("1 day" ,strtotime($edate))); 
    794             $where.= " order_date < date('" . $edate_next ."')"; 
    795         } 
    796  
    797         if (!isset($arrval)) $arrval = array(); 
    798  
     660            $format = '%Y-%m-%d'; 
     661 
     662            break; 
     663        } 
     664 
     665        $dbFactory = SC_DB_DBFactory::getInstance(); 
     666        // todo postgres 
     667        $col = $dbFactory->getOrderTotalDaysWhereSql($type); 
     668 
     669        $objQuery->setGroupBy('str_date'); 
     670        $objQuery->setOrder('str_date'); 
    799671        // 検索結果の取得 
    800         $objPage->arrResults = $objQuery->select($col, $from, $where, $arrval); 
    801  
    802         // 折れ線グラフの生成 
    803         if($graph) { 
    804             $image_key = "term_" . $type; 
    805             $objPage->tpl_image = $this->lfGetGraphLine($objPage->arrResults, $objPage->keyname, $image_key, $xtitle, $ytitle, $sdate, $edate); 
    806         } 
    807  
     672        $arrTotalResults = $objQuery->select($col, 'dtb_order', $where); 
     673 
     674        $arrTotalResults = $this->lfAddBlankLine($arrTotalResults, $type, $sdate, $edate); 
     675        // todo GDない場合の処理 
     676        $tpl_image       = $this->lfGetGraphLine($arrTotalResults, 'str_date', "term_" . $type, $xtitle, $ytitle, $sdate, $edate); 
     677        $arrTotalResults = $this->lfAddTotalLine($arrTotalResults); 
     678 
     679        return array($arrTotalResults, $tpl_image); 
     680    } 
     681 
     682    /* 
     683     * 期間中の日付を埋める 
     684     */ 
     685    function lfAddBlankLine($arrResults, $type, $st, $ed) { 
     686 
     687        $arrDateList = $this->lfDateTimeArray($type, $st, $ed); 
     688 
     689        foreach($arrResults as $arrResult) { 
     690            $strdate                = $arrResult['str_date']; 
     691            $arrDateResults[$strdate] = $arrResult; 
     692        } 
     693 
     694        foreach ($arrDateList as $date) { 
     695 
     696            if(array_key_exists($date, $arrDateResults)) { 
     697 
     698                $arrRet[] = $arrDateResults[$date]; 
     699 
     700            } else { 
     701                $arrRet[]['str_date'] = $date; 
     702            } 
     703        } 
     704        return $arrRet; 
     705    } 
     706 
     707 
     708    /* 
     709     * 日付の配列を作成する 
     710     * 
     711     */ 
     712    function lfDateTimeArray($type, $st, $ed) { 
     713        switch($type){ 
     714            case 'month': 
     715                $format        = 'm'; 
     716                break; 
     717            case 'year': 
     718                $format        = 'Y'; 
     719                break; 
     720            case 'wday': 
     721                $format        = 'D'; 
     722                break; 
     723            case 'hour': 
     724                $format        = 'H'; 
     725                break; 
     726            default: 
     727                $format        = 'Y-m-d'; 
     728                break; 
     729        } 
     730 
     731        if ($type == 'hour') { 
     732            $arrDateList = array('00','01','02','03','04','05','06','07','08','09','10','11','12','13','14','15','16','17','18','19','20','21','22','23'); 
     733 
     734        } else { 
     735            $arrDateList = array(); 
     736            $tmp    = strtotime($st); 
     737            $nAday  = 60*60*24; 
     738            $edx    = strtotime($ed); 
     739            while( $tmp < $edx ){ 
     740                $sDate = date($format, $tmp); 
     741                if( !in_array($sDate, $arrDateList) ){ 
     742                    $arrDateList[] = $sDate; 
     743                } 
     744                $tmp += $nAday; 
     745            } 
     746        } 
     747        return $arrDateList; 
     748    } 
     749 
     750 
     751    /* 
     752     * 合計を付与する 
     753     */ 
     754    function lfAddTotalLine($arrResults) { 
    808755        // 検索結果が0でない場合 
    809         if(count($objPage->arrResults) > 0) { 
    810             // 最終集計行取得する 
    811             $col = $tmp_col; 
    812             $objQuery = new SC_Query(); 
    813             $arrRet = $objQuery->select($col, $from, $where, $arrval); 
    814             $arrRet[0][$objPage->keyname] = "合計"; 
    815             $objPage->arrResults[] = $arrRet[0]; 
    816         } 
    817  
    818         // 平均値の計算 
    819         $max = count($objPage->arrResults); 
    820         for($i = 0; $i < $max; $i++) { 
    821             if($objPage->arrResults[$i]['total_order'] > 0) { 
    822                 $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['total_order']); 
    823             } 
    824         } 
    825     } 
     756        if(count($arrResults) > 0) { 
     757 
     758            // 合計の計算 
     759            foreach ($arrResults as $arrResult) { 
     760                foreach(array_keys($arrResult) as $value) { 
     761                    $arrTotal[$value] += $arrResult[$value]; 
     762                } 
     763            } 
     764            // 平均値の計算 
     765            $arrTotal['total_average'] = $arrTotal['total'] / $arrTotal['total_order']; 
     766            $arrResults[] = $arrTotal; 
     767        } 
     768 
     769 
     770        return $arrResults; 
     771    } 
     772 
     773 
    826774 
    827775    // 必要なカラムのみ抽出する(CSVデータで取得する) 
     
    838786    } 
    839787 
    840     function lfGetCSVColum($page, $key = "") { 
     788    function lfGetCSVColum($page) { 
    841789        switch($page) { 
    842790            // 商品別集計 
     
    919867                                 ); 
    920868            $arrDataCol = array( 
    921                                 $key, 
     869                                'str_date', 
    922870                                'total_order', 
    923871                                'men', 
  • branches/version-2_5-dev/data/class/util/SC_Utils.php

    • Property svn:executable set to *
    r20126 r20129  
    675675    } 
    676676 
     677 
     678    /** 
     679     * keyが正規表現にマッチした配列のみ値を返す 
     680     * 
     681     * @param mixed $array 
     682     * @param mixed $regex 
     683     * @access public 
     684     * @return array $results 
     685     */ 
     686    function sfFilterKey($array, $regex) { 
     687        foreach ($array as $key => $val) { 
     688            if (preg_match("/{$regex}/", $key)) { 
     689                $results[$key] = $val; 
     690            } 
     691        } 
     692        return $results; 
     693    } 
     694 
    677695    function sfGetErrorColor($val) { 
    678696        if($val != "") { 
Note: See TracChangeset for help on using the changeset viewer.