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-2010 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_PATH . "pages/LC_Page.php");
require_once(CLASS_EX_PATH . "batch_extends/SC_Batch_Daily_Ex.php");
require_once(CLASS_PATH . "graph/SC_GraphPie.php");
require_once(CLASS_PATH . "graph/SC_GraphLine.php");
require_once(CLASS_PATH . "graph/SC_GraphBar.php");
* @author LOCKON CO.,LTD.
$this->tpl_subnavi = 'total/subnavi.tpl';
$this->tpl_graphsubtitle = 'total/subtitle.tpl';
$this->tpl_titleimage = URL_DIR. 'img/title/title_sale.jpg';
$masterData = new SC_DB_MasterData_Ex();
$this->arrWDAY = $masterData->getMasterData("mtb_wday");
$this->arrSex = $masterData->getMasterData("mtb_sex");
$this->arrJob = $masterData->getMasterData("mtb_job");
$this->arrTitle[''] = "期間別集計";
$this->arrTitle['term'] = "期間別集計";
$this->arrTitle['products'] = "商品別集計";
$this->arrTitle['age'] = "年代別集計";
$this->arrTitle['job'] = "職業別集計";
$this->arrTitle['member'] = "会員別集計";
$this->cashtime = time();
$this->objBatch = new SC_Batch_Daily_Ex();
if (!isset ($_POST['search_startyear'])) $_POST['search_startyear'] = "";
if (!isset ($_POST['search_startmonth'])) $_POST['search_startmonth'] = "";
if (!isset ($_POST['search_startday'])) $_POST['search_startday'] = "";
if (!isset ($_POST['search_endyear'])) $_POST['search_endyear'] = "";
if (!isset ($_POST['search_endmonth'])) $_POST['search_endmonth'] = "";
if (!isset ($_POST['search_endday'])) $_POST['search_endday'] = "";
if (!isset ($_POST['search_startyear_m'])) $_POST['search_startyear_m'] = "";
SC_Utils_Ex::sfIsSuccess($objSess);
if(isset ($_GET['draw_image']) && $_GET['draw_image'] != ""){
$this->objFormParam->setParam($_POST);
$this->objFormParam->setParam($_GET);
foreach ($_POST as $key => $val) {
if (ereg("^search_", $key)) {
$this->arrHidden[$key] = $val;
$mode = $this->objFormParam->getValue('mode');
$this->objFormParam->convParam();
$arrRet = $this->objFormParam->getHashArray();
if (empty($this->arrErr)) {
foreach ($arrRet as $key => $val) {
$sdate = $this->objFormParam->getValue('search_startyear') . "/" . $this->objFormParam->getValue('search_startmonth') . "/" . $this->objFormParam->getValue('search_startday');
$edate = $this->objFormParam->getValue('search_endyear') . "/" . $this->objFormParam->getValue('search_endmonth') . "/" . $this->objFormParam->getValue('search_endday');
case 'search_startyear_m':
list ($sdate, $edate) = SC_Utils_Ex::sfTermMonth($this->objFormParam->getValue('search_startyear_m'), $this->objFormParam->getValue('search_startmonth_m'), CLOSE_DAY);
if($this->objFormParam->getValue('type') != "") {
$type = $this->objFormParam->getValue('type');
$page = $this->objFormParam->getValue('page');
$this->tpl_page_type = "total/page_products.tpl";
$this->objBatch->lfRealTimeDailyTotal($sdate, $edate);
$this->tpl_page_type = "total/page_job.tpl";
$this->objBatch->lfRealTimeDailyTotal($sdate, $edate);
$this->lfGetOrderJob($type, $sdate, $edate, $this, $this->install_GD);
$this->tpl_page_type = "total/page_member.tpl";
$this->objBatch->lfRealTimeDailyTotal($sdate, $edate);
$this->tpl_page_type = "total/page_age.tpl";
$this->objBatch->lfRealTimeDailyTotal($sdate, $edate);
$this->lfGetOrderAge($type, $sdate, $edate, $this, $this->install_GD);
if (!isset ($type)) $type = "";
$this->tpl_page_type = "total/page_term.tpl";
$this->objBatch->lfRealTimeDailyTotal($sdate, $edate);
$this->lfGetOrderTerm($type, $sdate, $edate, $this, $this->install_GD);
list ($arrTitleCol, $arrDataCol) = $this->lfGetCSVColum($page, $this->keyname);
$head = SC_Utils_Ex::sfGetCSVList($arrTitleCol);
SC_Utils_Ex::sfCSVDownload($head. $data, $page. "_". $type);
list ($arrTitleCol, $arrDataCol, $arrColSize, $arrAlign, $title) = $this->lfGetPDFColum($page, $type, $this->keyname);
$head = SC_Utils_Ex::sfGetPDFList($arrTitleCol);
$graph_name = basename($this->tpl_image);
$this->lfPDFDownload($graph_name, $head . $data, $arrColSize, $arrAlign, $sdate, $edate, $title, $page);
// バッチモードの場合のみ実行する(当日の集計を行うため)
$this->objBatch->lfStartDailyTotal(3,0);
$objDate->setStartYear(RELEASE_YEAR);
$objDate->setEndYear(DATE("Y"));
$this->arrYear = $objDate->getYear();
$this->arrMonth = $objDate->getMonth();
$this->arrDay = $objDate->getDay();
$this->arrForm = $this->objFormParam->getFormParamList();
$this->tpl_subtitle = $this->arrTitle[$this->objFormParam->getValue('page')];
$objView->assignobj($this);
$objView->display(MAIN_FRAME);
function lfPDFDownload($image, $table, $arrColSize, $arrAlign, $sdate, $edate, $title, $page = "") {
$objPdf->setTableColor("CCCCCC", "F0F0F0", "D1DEFE");
$objPdf->setTemplate(PDF_DIR . "total.pdf");
$disp_sdate = sfDispDBDate($sdate, false);
$disp_edate = sfDispDBDate($edate, false);
$arrText['title_block'] = $title;
$arrText['date_block'] = "$disp_sdate-$disp_edate";
$arrImage['graph_block'] = GRAPH_DIR . $image;
$arrRet = split("\n", $table);
for($page = 1; $page <= $page_max; $page++ ) {
$start_no = 35 * ($page - 1) + 1;
$arrText['page_block'] = $page . " / " . $page_max;
$objPdf->setTextBlock($arrText);
$objPdf->setImageBlock($arrImage);
// 最終ページのみ、商品別集計は合計がないので最終行の色を変更しない。
if($page == $page_max && $page != 'products') {
$objPdf->writeTableCenter($table, 500, $arrColSize, $arrAlign, 35, $start_no, $last_color_flg);
if (!isset ($_POST['form'])) $_POST['form'] = "";
if($_POST['form'] == 1) {
$_SESSION['total']['startyear_m'] = $_POST['search_startyear_m'];
$_SESSION['total']['startmonth_m'] = $_POST['search_startmonth_m'];
if($_POST['form'] == 2) {
$_SESSION['total']['startyear'] = $_POST['search_startyear'];
$_SESSION['total']['startmonth'] = $_POST['search_startmonth'];
$_SESSION['total']['startday'] = $_POST['search_startday'];
$_SESSION['total']['endyear'] = $_POST['search_endyear'];
$_SESSION['total']['endmonth'] = $_POST['search_endmonth'];
$_SESSION['total']['endday'] = $_POST['search_endday'];
$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;
$this->objFormParam->addParam("月度", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']);
$this->objFormParam->addParam("月度", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']);
$this->objFormParam->addParam("開始日", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']);
$this->objFormParam->addParam("開始日", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']);
$this->objFormParam->addParam("開始日", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']);
$this->objFormParam->addParam("終了日", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']);
$this->objFormParam->addParam("終了日", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']);
$this->objFormParam->addParam("終了日", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']);
$this->objFormParam->addParam("", "page");
$this->objFormParam->addParam("", "type");
$this->objFormParam->addParam("", "mode");
$arrRet = $this->objFormParam->getHashArray();
$objErr->arrErr = $this->objFormParam->checkError();
if($_POST['form'] == 1) {
$objErr->doFunc(array("月度", "search_startyear_m"), array("ONE_EXIST_CHECK"));
if($_POST['form'] == 2) {
$objErr->doFunc(array("期間", "search_startyear", "search_endyear"), array("ONE_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"));
function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, "total");
$path = GRAPH_DIR . $pngname;
$objGraphLine->setData($arrList);
if($keyname == "key_day"){
$objGraphLine->setXLabelAngle(45);
$objGraphLine->setXTitle($xtitle);
$objGraphLine->setYTitle($ytitle);
list ($sy, $sm, $sd) = split("[/ ]" , $sdate);
list ($ey, $em, $ed) = 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_URL . $pngname;
function lfGetGraphPie($arrResults, $keyname, $type, $title = "", $sdate = "", $edate = "") {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname,
$path = GRAPH_DIR . $pngname;
foreach($arrList as $key => $val) {
$objGraphPie->debugPrint("key:$key val:$val");
$objGraphPie->setData($arrList);
list ($sy, $sm, $sd) = split("[/ ]" , $sdate);
list ($ey, $em, $ed) = 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_URL . $pngname;
function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
// 結果が0行以上ある場合のみグラフを生成する。
if(count($arrResults) > 0) {
$arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
$path = GRAPH_DIR . $pngname;
$objGraphBar->setXLabel($arrKey);
$objGraphBar->setXTitle($xtitle);
$objGraphBar->setYTitle($ytitle);
$objGraphBar->setData($arrList);
list ($sy, $sm, $sd) = split("[/ ]" , $sdate);
list ($ey, $em, $ed) = 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_URL . $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());
list ($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
$col = "COUNT(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average, order_sex";
$objQuery->setGroupBy("order_sex");
$tmp_where = $where . " AND customer_id <> 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL;
$arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
for($i = 0; $i < $max; $i++ ) {
$arrRet[$i]['member_name'] = '会員'. $this->arrSex[$arrRet[$i]['order_sex']];
$objPage->arrResults = $arrRet;
$tmp_where = $where . " AND customer_id = 0 AND del_flg = 0 AND status <> " . ORDER_CANCEL;
$arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
for($i = 0; $i < $max; $i++ ) {
$arrRet[$i]['member_name'] = '非会員'. $this->arrSex[$arrRet[$i]['order_sex']];
$objPage->arrResults = array_merge($objPage->arrResults, $arrRet);
$objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "member_name", $image_key, "(売上比率)", $sdate, $edate);
function lfGetOrderProducts($type, $sdate, $edate, &$objPage, $graph = true, $mode = "") {
list ($where, $arrval) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type);
$where .= " and del_flg=0 and status <> " . ORDER_CANCEL;
$sql = "SELECT T1.product_id, T1.product_code, T1.product_name, T1.products_count, T1.order_count, T1.price, T1.total ";
$sql.= "SELECT product_id, product_name, product_code, price, ";
$sql.= "COUNT(*) AS order_count, ";
$sql.= "SUM(quantity) AS products_count, ";
$sql.= "(price * sum(quantity)) AS total ";
$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 ) ";
$sql.= "GROUP BY product_id, product_name, product_code, price ";
$sql.= "ORDER BY T1.total DESC ";
$sql.= "LIMIT " . PRODUCTS_TOTAL_MAX;
$objPage->arrResults = $objQuery->getAll($sql, $arrval);
$image_key = "products_" . $type;
$objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "product_name", $image_key, "(売上比率)", $sdate, $edate);
function lfGetOrderJob($type, $sdate, $edate, &$objPage, $graph = true) {
list ($where, $arrval) = $this->lfGetWhereMember('T2.create_date', $sdate, $edate, $type);
$sql = "SELECT job, count(*) AS order_count, SUM(total) AS total, trunc(AVG(total),0) AS total_average ";
$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;
$sql.= " GROUP BY job ORDER BY total DESC";
$objPage->arrResults = $objQuery->getAll($sql, $arrval);
$max = count($objPage->arrResults);
for($i = 0; $i < $max; $i++ ) {
$job_key = $objPage->arrResults[$i]['job'];
$objPage->arrResults[$i]['job_name'] = $this->arrJob[$job_key];
$objPage->arrResults[$i]['job_name'] = "未回答";
$image_key = "job_" . $type;
$objPage->tpl_image = $this->lfGetGraphPie($objPage->arrResults, "job_name", $image_key, "(売上比率)", $sdate, $edate);
function lfGetOrderAge($type, $sdate, $edate, &$objPage, $graph = true) {
list ($where, $arrval) = $this->lfGetWhereMember('order_date', $sdate, $edate, $type, "member");
$sql = "SELECT SUM(order_count) AS order_count, SUM(total) AS total, start_age, end_age ";
$sql.= "FROM dtb_bat_order_daily_age WHERE $where ";
$sql.= "GROUP BY start_age, end_age ORDER BY start_age, end_age";
$objPage->arrResults = $objQuery->getAll($sql, $arrval);
$max = count($objPage->arrResults);
for($i = 0; $i < $max; $i++ ) {
if($objPage->arrResults[$i]['order_count'] > 0) {
$objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['order_count']);
$start_age = $objPage->arrResults[$i]['start_age'];
$end_age = $objPage->arrResults[$i]['end_age'];
if($start_age != "" || $end_age != "") {
$objPage->arrResults[$i]['age_name'] = $start_age . "〜" . $end_age . "歳";
$objPage->arrResults[$i]['age_name'] = $start_age . "歳〜";
$objPage->arrResults[$i]['age_name'] = "未回答";
$image_key = "age_" . $type;
$objPage->tpl_image = $this->lfGetGraphBar($objPage->arrResults, "age_name", $image_key, $xtitle, $ytitle, $sdate, $edate);
function lfGetOrderTerm($type, $sdate, $edate, &$objPage, $graph = true) {
$tmp_col = "sum(total_order) as total_order, sum(men) as men, sum(women) as women,";
$tmp_col.= "sum(men_member) as men_member, sum(men_nonmember) as men_nonmember,";
$tmp_col.= "sum(women_member) as women_member, sum(women_nonmember) as women_nonmember,";
$tmp_col.= "sum(total) as total, (avg(total_average)) as total_average";
$col = $tmp_col . ",key_month";
$objQuery->setGroupBy("key_month");
$objQuery->setOrder("key_month");
$objPage->keyname = "key_month";
$objPage->tpl_tail = "月";
$from = "dtb_bat_order_daily";
$col = $tmp_col . ",key_year";
$objQuery->setGroupBy("key_year");
$objQuery->setOrder("key_year");
$objPage->keyname = "key_year";
$objPage->tpl_tail = "年";
$from = "dtb_bat_order_daily";
$col = $tmp_col . ",key_wday, wday";
$objQuery->setGroupBy("key_wday, wday");
$objQuery->setOrder("wday");
$objPage->keyname = "key_wday";
$objPage->tpl_tail = "曜日";
$from = "dtb_bat_order_daily";
$col = $tmp_col . ",hour";
$objQuery->setGroupBy("hour");
$objQuery->setOrder("hour");
$objPage->keyname = "hour";
$objPage->tpl_tail = "時";
$from = "dtb_bat_order_daily_hour";
$objQuery->setOrder("key_day");
$objPage->keyname = "key_day";
$from = "dtb_bat_order_daily";
if (!isset ($where)) $where = "";
$where.= " order_date >= '". $sdate . "'";
$where.= " order_date < date('" . $edate_next . "')";
if (!isset ($arrval)) $arrval = array();
$objPage->arrResults = $objQuery->select($col, $from, $where, $arrval);
$image_key = "term_" . $type;
$objPage->tpl_image = $this->lfGetGraphLine($objPage->arrResults, $objPage->keyname, $image_key, $xtitle, $ytitle, $sdate, $edate);
if(count($objPage->arrResults) > 0) {
$arrRet = $objQuery->select($col, $from, $where, $arrval);
$arrRet[0][$objPage->keyname] = "合計";
$objPage->arrResults[] = $arrRet[0];
$max = count($objPage->arrResults);
for($i = 0; $i < $max; $i++ ) {
if($objPage->arrResults[$i]['total_order'] > 0) {
$objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['total_order']);
// 必要なカラムのみ抽出する(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]);
// 必要なカラムのみ抽出する(PDFデータで取得する)
for($i = 0; $i < $max; $i++ ) {
foreach($arrDataCol as $val) {
$arrRet[$i][$val] = SC_Utils_Ex::sfCutString($arrData[$i][$val], $len);
$csv_data.= SC_Utils_Ex::sfGetPDFList($arrRet[$i]);
$arrSUBNAME['day'] = "日別";
$arrSUBNAME['month'] = "月別";
$arrSUBNAME['year'] = "年別";
$arrSUBNAME['hour'] = "時間別";
$arrSUBNAME['wday'] = "曜日別";
$arrSUBNAME['all'] = "全体";
$arrSUBNAME['member'] = "会員";
$arrSUBNAME['nonmember'] = "非会員";
$title = "商品別集計(" . $arrSUBNAME[$type] . ")";
$title = "職業別集計(" . $arrSUBNAME[$type] . ")";
$title = "会員別集計(" . $arrSUBNAME[$type] . ")";
$title = "年代別集計(" . $arrSUBNAME[$type] . ")";
$title = "期間別集計(" . $arrSUBNAME[$type] . ")";
return array($arrTitleCol, $arrDataCol, $arrColSize, $arrAlign, $title);
return array($arrTitleCol, $arrDataCol);
Documentation generated on Fri, 24 Feb 2012 13:59:14 +0900 by Seasoft
|