Source for file LC_Page_Admin_Total.php
Documentation is available at LC_Page_Admin_Total.php
* This file is part of EC-CUBE
* Copyright(c) 2000-2011 LOCKON CO.,LTD. All Rights Reserved.
* http://www.lockon.co.jp/
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php';
require_once CLASS_REALDIR . 'graph/SC_GraphPie.php';
require_once CLASS_REALDIR . 'graph/SC_GraphLine.php';
require_once CLASS_REALDIR . 'graph/SC_GraphBar.php';
* @author LOCKON CO.,LTD.
* @version $Id: LC_Page_Admin_Total.php 20970 2011-06-10 10:27:24Z Seasoft $
$this->tpl_mainpage = 'total/index.tpl';
$this->tpl_graphsubtitle = 'total/subtitle.tpl';
$this->tpl_titleimage = ROOT_URLPATH. 'img/title/title_sale.jpg';
$this->tpl_maintitle = '売上集計';
$this->tpl_mainno = 'total';
$masterData = new SC_DB_MasterData_Ex();
$this->arrWDAY = $masterData->getMasterData("mtb_wday");
$this->arrSex = $masterData->getMasterData("mtb_sex");
$this->arrJob = $masterData->getMasterData("mtb_job");
$objDate = new SC_Date_Ex();
$objDate->setStartYear(RELEASE_YEAR);
$objDate->setEndYear(DATE('Y'));
$this->arrYear = $objDate->getYear();
$this->arrMonth = $objDate->getMonth();
$this->arrDay = $objDate->getDay();
$this->arrTitle[''] = "期間別集計";
$this->arrTitle['term'] = "期間別集計";
$this->arrTitle['products'] = "商品別集計";
$this->arrTitle['age'] = "年代別集計";
$this->arrTitle['job'] = "職業別集計";
$this->arrTitle['member'] = "会員別集計";
$this->arrSearchForm1 = array('search_startyear_m', 'search_startmonth_m');
$this->arrSearchForm2 = array('search_startyear',
if(isset ($_GET['draw_image']) && $_GET['draw_image'] != ""){
$objFormParam = new SC_FormParam_Ex();
$objFormParam->setParam($_POST);
$objFormParam->setParam($_GET);
$this->arrHidden = $objFormParam->getSearchArray();
switch($this->getMode()) {
if (empty($this->arrErr)) {
$page = ($objFormParam->getValue('page')) ? $objFormParam->getValue('page') : 'term';
$type = ($objFormParam->getValue('type')) ? $objFormParam->getValue('type'): 'all';
$this->tpl_page_type = "total/page_". $page . ".tpl";
array($type, $sdate, $edate));
if($this->getMode() == 'csv') {
$head = SC_Utils_Ex::sfGetCSVList($arrTitleCol);
list ($fime_name, $data) = SC_Utils_Ex::sfGetCSVData($head. $data);
$this->sendResponseCSV($fime_name, $data);
$objFormParam->setParam($_SESSION['total']);
$this->arrForm = $objFormParam->getFormParamList();
$this->tpl_subtitle = $this->arrTitle[$objFormParam->getValue('page')];
$list = isset ($_SESSION['total']) ? $_SESSION['total'] : "";
// セッション情報に開始月度が保存されていない。
if(empty($_SESSION['total']['startyear_m'])) {
$list['startyear_m'] = $year;
$list['startmonth_m'] = $month;
// セッション情報に開始日付、終了日付が保存されていない。
if(empty($_SESSION['total']['startyear']) && empty($_SESSION['total']['endyear'])) {
$list['startyear'] = $year;
$list['startmonth'] = $month;
$list['startday'] = $day;
$list['endyear'] = $year;
$list['endmonth'] = $month;
$objFormParam->addParam("月度", "search_startyear_m", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']);
$objFormParam->addParam("月度", "search_startmonth_m", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']);
$objFormParam->addParam("開始日", "search_startyear", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']);
$objFormParam->addParam("開始日", "search_startmonth", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']);
$objFormParam->addParam("開始日", "search_startday", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']);
$objFormParam->addParam("終了日", "search_endyear", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']);
$objFormParam->addParam("終了日", "search_endmonth", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']);
$objFormParam->addParam("終了日", "search_endday", INT_LEN, 'n', array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']);
$objFormParam->addParam("", 'page');
$objFormParam->addParam("", 'type');
$objFormParam->addParam("", 'mode');
$objFormParam->addParam("", 'form');
$objFormParam->convParam();
$objErr = new SC_CheckError_Ex();
$objErr->arrErr = $objFormParam->checkError();
if($objFormParam->getValue('form') == 1) {
$objErr->doFunc(array("月度", "search_startyear_m"), array("ONE_EXIST_CHECK"));
if($objFormParam->getValue('form') == 2) {
$objErr->doFunc(array("期間", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("FULL_EXIST_CHECK"));
$objErr->doFunc(array("月度", "search_startyear_m", "search_startmonth_m"), array("ALL_EXIST_CHECK"));
$objErr->doFunc(array("開始日", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
$objErr->doFunc(array("終了日", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
$objErr->doFunc(array("開始日", "終了日", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
/* サブナビを移動しても日付が残るようにセッションに入力期間を記録する */
if (!isset ($session['total'])) {
$session['total'] = array_merge($session['total'], $arrForm);
$search_startyear_m = $search_startyear = $search_endyear = date('Y');
$search_startmonth_m = $search_startmonth = $search_endmonth = date('m');
$search_startday = $search_endday = date('d');
return compact($this->arrSearchForm1, $this->arrSearchForm2);
/* フォームで入力された日付を適切な形にする */
$arrRet = $objFormParam->getHashArray();
foreach ($arrRet as $key => $val) {
$sdate = $objFormParam->getValue('search_startyear') . "/" . $objFormParam->getValue('search_startmonth') . "/" . $objFormParam->getValue('search_startday');
$edate = $objFormParam->getValue('search_endyear') . "/" . $objFormParam->getValue('search_endmonth') . "/" . $objFormParam->getValue('search_endday');
case 'search_startyear_m':
list ($sdate, $edate) = SC_Utils_Ex::sfTermMonth($objFormParam->getValue('search_startyear_m'),
$objFormParam->getValue('search_startmonth_m'),
return array($sdate, $edate);
function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0 && $this->install_GD) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, 'total');
$path = GRAPH_REALDIR . $pngname;
$objGraphLine->setData($arrList);
if($keyname == "key_day"){
$objGraphLine->setXLabelAngle(45);
$objGraphLine->setXTitle($xtitle);
$objGraphLine->setYTitle($ytitle);
list ($sy, $sm, $sd) = preg_split("|[/ ]|" , $sdate);
list ($ey, $em, $ed) = preg_split("|[/ ]|" , $edate);
$start_date = $sy . "年" . $sm . "月" . $sd . "日";
$end_date = $ey . "年" . $em . "月" . $ed . "日";
$objGraphLine->drawTitle("集計期間:" . $start_date . " - " . $end_date);
$objGraphLine->drawGraph();
$objGraphLine->outputGraph();
$ret_path = GRAPH_URLPATH . $pngname;
function lfGetGraphPie($arrResults, $keyname, $type, $title = "", $sdate = "", $edate = "") {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0 && $this->install_GD) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname,
$path = GRAPH_REALDIR . $pngname;
$objGraphPie->setData($arrList);
list ($sy, $sm, $sd) = preg_split("|[/ ]|" , $sdate);
list ($ey, $em, $ed) = preg_split("|[/ ]|" , $edate);
$start_date = $sy . "年" . $sm . "月" . $sd . "日";
$end_date = $ey . "年" . $em . "月" . $ed . "日";
$objGraphPie->drawTitle("集計期間:" . $start_date . " - " . $end_date);
$objGraphPie->drawGraph();
$objGraphPie->outputGraph();
$ret_path = GRAPH_URLPATH . $pngname;
function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0 && $this->install_GD) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, 'total', GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
$path = GRAPH_REALDIR . $pngname;
$objGraphBar->setXLabel($arrKey);
$objGraphBar->setXTitle($xtitle);
$objGraphBar->setYTitle($ytitle);
$objGraphBar->setData($arrList);
list ($sy, $sm, $sd) = preg_split("|[/ ]|" , $sdate);
list ($ey, $em, $ed) = preg_split("|[/ ]|" , $edate);
$start_date = $sy . "年" . $sm . "月" . $sd . "日";
$end_date = $ey . "年" . $em . "月" . $ed . "日";
$objGraphBar->drawTitle("集計期間:" . $start_date . " - " . $end_date);
$objGraphBar->drawGraph();
$objGraphBar->outputGraph();
$ret_path = GRAPH_URLPATH . $pngname;
if($_POST['search_startyear_m'] != "") {
$pngname = sprintf("%s_%02d%02d.png", $keyname, substr($_POST['search_startyear_m'],2), $_POST['search_startmonth_m']);
$pngname = sprintf("%s_%02d%02d%02d_%02d%02d%02d.png", $keyname, substr($_POST['search_startyear'], 2), $_POST['search_startmonth'], $_POST['search_startday'], substr($_POST['search_endyear'],2), $_POST['search_endmonth'], $_POST['search_endday']);
function lfGetWhereMember($col_date, $sdate, $edate, $type, $col_member = "customer_id") {
$where.= " $col_date >= '". $sdate . "'";
$where.= " $col_date < date('" . $edate . "')";
$where.= " $col_member <> 0";
$where.= " $col_member = 0";
return array($where, array());
$objQuery = SC_Query_Ex::getSingletonInstance();
list ($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
$where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL;
COUNT(order_id) AS order_count,
AVG(total) AS total_average,
WHEN customer_id <> 0 THEN 1
$objQuery->setGroupBy("member, order_sex");
$arrTotalResults = $objQuery->select($col, $from, $where, $arrval);
$arrResult = & $arrTotalResults[$key];
$member_key = $arrResult['order_sex'];
$arrResult['member_name'] = (($arrResult['member']) ? '会員' : '非会員') . $this->arrSex[$member_key];
$arrResult['member_name'] = "未回答";
$tpl_image = $this->lfGetGraphPie($arrTotalResults, "member_name", 'member', "(売上比率)", $sdate, $edate);
return array($arrTotalResults, $tpl_image);
$objQuery = SC_Query_Ex::getSingletonInstance();
list ($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
$where .= " AND dtb_order.del_flg = 0 AND dtb_order.status <> " . ORDER_CANCEL;
SUM(quantity) AS products_count,
COUNT(order_id) AS order_count,
(price * SUM(quantity)) AS total";
$from = "dtb_order_detail JOIN dtb_order USING(order_id)";
$sql.= "LIMIT " . PRODUCTS_TOTAL_MAX;
$objQuery->setGroupBy('product_id, product_name, product_code, price');
//$objQuery->setGroupBy('product_id');
$objQuery->setOrder('total DESC');
$arrTotalResults = $objQuery->select($col, $from, $where, $arrval);
$tpl_image = $this->lfGetGraphPie($arrTotalResults, "product_name", "products_" . $type, "(売上比率)", $sdate, $edate);
return array($arrTotalResults, $tpl_image);
$objQuery = SC_Query_Ex::getSingletonInstance();
list ($where, $arrval) = $this->lfGetWhereMember('dtb_order.create_date', $sdate, $edate, $type);
COUNT(order_id) AS order_count,
AVG(total) AS total_average
$from = 'dtb_order JOIN dtb_customer USING ( customer_id )';
$where .= " AND dtb_order.del_flg = 0 AND dtb_order.status <> " . ORDER_CANCEL;
$objQuery->setGroupBy('job');
$objQuery->setOrder('total DESC');
$arrTotalResults = $objQuery->select($col, $from, $where, $arrval);
$arrResult = & $arrTotalResults[$key];
$job_key = $arrResult['job'];
$arrResult['job_name'] = $this->arrJob[$job_key];
$arrResult['job_name'] = "未回答";
$tpl_image = $this->lfGetGraphPie($arrTotalResults, "job_name", "job_" . $type, "(売上比率)", $sdate, $edate);
return array($arrTotalResults, $tpl_image);
$objQuery = SC_Query_Ex::getSingletonInstance();
list ($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$col = $dbFactory->getOrderTotalAgeColSql() . ' AS age,
COUNT(order_id) AS order_count,
AVG(total) AS total_average
$where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL;
$objQuery->setGroupBy('age');
$objQuery->setOrder('age DESC');
$arrTotalResults = $objQuery->select($col, $from, $where, $arrval);
$arrResult = & $arrTotalResults[$key];
$age_key = $arrResult['age'];
$arrResult['age_name'] = $arrResult['age'] . '代';
$arrResult['age_name'] = "未回答";
$tpl_image = $this->lfGetGraphBar($arrTotalResults, "age_name", "age_" . $type, "(年齢)", "(売上合計)", $sdate, $edate);
return array($arrTotalResults, $tpl_image);
$objQuery = SC_Query_Ex::getSingletonInstance();
$where .= " AND del_flg = 0 AND status <> " . ORDER_CANCEL;
$dbFactory = SC_DB_DBFactory_Ex::getInstance();
$col = $dbFactory->getOrderTotalDaysWhereSql($type);
$objQuery->setGroupBy('str_date');
$objQuery->setOrder('str_date');
$arrTotalResults = $objQuery->select($col, 'dtb_order', $where);
$arrTotalResults = $this->lfAddBlankLine($arrTotalResults, $type, $sdate, $edate);
$tpl_image = $this->lfGetGraphLine($arrTotalResults, 'str_date', "term_" . $type, $xtitle, $ytitle, $sdate, $edate);
return array($arrTotalResults, $tpl_image);
foreach($arrResults as $arrResult) {
$strdate = $arrResult['str_date'];
$arrDateResults[$strdate] = $arrResult;
foreach ($arrDateList as $date) {
$arrRet[] = $arrDateResults[$date];
$arrRet[]['str_date'] = $date;
$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');
$sDate = date($format, $tmp);
if(count($arrResults) > 0) {
foreach ($arrResults as $arrResult) {
$arrTotal[$value] += $arrResult[$value];
$arrTotal['total_average'] = $arrTotal['total'] / $arrTotal['total_order'];
$arrResults[] = $arrTotal;
// 必要なカラムのみ抽出する(CSVデータで取得する)
for($i = 0; $i < $max; $i++ ) {
foreach($arrDataCol as $val) {
$arrRet[$i][$val] = $arrData[$i][$val];
$csv_data.= SC_Utils_Ex::sfGetCSVList($arrRet[$i]);
return array($arrTitleCol, $arrDataCol);
Documentation generated on Fri, 24 Feb 2012 14:01:53 +0900 by Seasoft
|