1 | <?php |
---|
2 | /* |
---|
3 | * This file is part of EC-CUBE |
---|
4 | * |
---|
5 | * Copyright(c) 2000-2012 LOCKON CO.,LTD. All Rights Reserved. |
---|
6 | * |
---|
7 | * http://www.lockon.co.jp/ |
---|
8 | * |
---|
9 | * This program is free software; you can redistribute it and/or |
---|
10 | * modify it under the terms of the GNU General Public License |
---|
11 | * as published by the Free Software Foundation; either version 2 |
---|
12 | * of the License, or (at your option) any later version. |
---|
13 | * |
---|
14 | * This program is distributed in the hope that it will be useful, |
---|
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
17 | * GNU General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with this program; if not, write to the Free Software |
---|
21 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
---|
22 | */ |
---|
23 | // {{{ requires |
---|
24 | require_once CLASS_EX_REALDIR . 'page_extends/admin/LC_Page_Admin_Ex.php'; |
---|
25 | |
---|
26 | /** |
---|
27 | * 売上集計 のページクラス. |
---|
28 | * |
---|
29 | * @package Page |
---|
30 | * @author LOCKON CO.,LTD. |
---|
31 | * @version $Id$ |
---|
32 | */ |
---|
33 | class LC_Page_Admin_Total extends LC_Page_Admin_Ex { |
---|
34 | |
---|
35 | // }}} |
---|
36 | // {{{ functions |
---|
37 | |
---|
38 | /** |
---|
39 | * Page を初期化する. |
---|
40 | * |
---|
41 | * @return void |
---|
42 | */ |
---|
43 | function init() { |
---|
44 | parent::init(); |
---|
45 | // GDライブラリのインストール判定 |
---|
46 | $this->install_GD = function_exists('gd_info') ? true : false; |
---|
47 | $this->tpl_mainpage = 'total/index.tpl'; |
---|
48 | $this->tpl_graphsubtitle = 'total/subtitle.tpl'; |
---|
49 | $this->tpl_titleimage = ROOT_URLPATH.'img/title/title_sale.jpg'; |
---|
50 | $this->tpl_maintitle = $this->tpl_maintitle = t('TPL_MAINTITLE_010'); |
---|
51 | $this->tpl_mainno = 'total'; |
---|
52 | |
---|
53 | $masterData = new SC_DB_MasterData_Ex(); |
---|
54 | $this->arrWDAY = $masterData->getMasterData('mtb_wday'); |
---|
55 | $this->arrSex = $masterData->getMasterData('mtb_sex'); |
---|
56 | $this->arrJob = $masterData->getMasterData('mtb_job'); |
---|
57 | |
---|
58 | // 登録・更新日検索用 |
---|
59 | $objDate = new SC_Date_Ex(); |
---|
60 | $objDate->setStartYear(RELEASE_YEAR); |
---|
61 | $objDate->setEndYear(DATE('Y')); |
---|
62 | $this->arrYear = $objDate->getYear(); |
---|
63 | $this->arrMonth = $objDate->getMonth(); |
---|
64 | $this->arrDay = $objDate->getDay(); |
---|
65 | |
---|
66 | // ページタイトル todo あとでなおす |
---|
67 | $this->arrTitle[''] = t('LC_Page_Admin_Total_001'); |
---|
68 | $this->arrTitle['term'] = t('LC_Page_Admin_Total_002'); |
---|
69 | $this->arrTitle['products'] = t('LC_Page_Admin_Total_003'); |
---|
70 | $this->arrTitle['age'] = t('LC_Page_Admin_Total_004'); |
---|
71 | $this->arrTitle['job'] = t('LC_Page_Admin_Total_005'); |
---|
72 | $this->arrTitle['member'] = t('LC_Page_Admin_Total_006'); |
---|
73 | |
---|
74 | // 月度集計のkey名 |
---|
75 | $this->arrSearchForm1 = array('search_startyear_m', 'search_startmonth_m'); |
---|
76 | |
---|
77 | // 期間別集計のkey名 |
---|
78 | $this->arrSearchForm2 = array( |
---|
79 | 'search_startyear', |
---|
80 | 'search_startmonth', |
---|
81 | 'search_startday', |
---|
82 | 'search_endyear', |
---|
83 | 'search_endmonth', |
---|
84 | 'search_endday', |
---|
85 | ); |
---|
86 | } |
---|
87 | |
---|
88 | /** |
---|
89 | * Page のプロセス. |
---|
90 | * |
---|
91 | * @return void |
---|
92 | */ |
---|
93 | function process() { |
---|
94 | $this->action(); |
---|
95 | $this->sendResponse(); |
---|
96 | } |
---|
97 | |
---|
98 | /** |
---|
99 | * Page のアクション. |
---|
100 | * |
---|
101 | * @return void |
---|
102 | */ |
---|
103 | function action() { |
---|
104 | |
---|
105 | if (isset($_GET['draw_image']) && $_GET['draw_image'] != '') { |
---|
106 | define('DRAW_IMAGE' , true); |
---|
107 | } else { |
---|
108 | define('DRAW_IMAGE' , false); |
---|
109 | } |
---|
110 | |
---|
111 | // パラメーター管理クラス |
---|
112 | $objFormParam = new SC_FormParam_Ex(); |
---|
113 | // パラメーター情報の初期化 |
---|
114 | $this->lfInitParam($objFormParam); |
---|
115 | $objFormParam->setParam($_REQUEST); |
---|
116 | |
---|
117 | // 検索ワードの引き継ぎ |
---|
118 | $this->arrHidden = $objFormParam->getSearchArray(); |
---|
119 | |
---|
120 | switch ($this->getMode()) { |
---|
121 | case 'csv': |
---|
122 | case 'search': |
---|
123 | |
---|
124 | $this->arrErr = $this->lfCheckError($objFormParam); |
---|
125 | if (empty($this->arrErr)) { |
---|
126 | |
---|
127 | // 日付 |
---|
128 | list($sdate, $edate) = $this->lfSetStartEndDate($objFormParam); |
---|
129 | |
---|
130 | // ページ |
---|
131 | $page = ($objFormParam->getValue('page')) ? $objFormParam->getValue('page') : 'term'; |
---|
132 | |
---|
133 | // 集計種類 |
---|
134 | $type = ($objFormParam->getValue('type')) ? $objFormParam->getValue('type'): 'all'; |
---|
135 | |
---|
136 | $this->tpl_page_type = 'total/page_'. $page .'.tpl'; |
---|
137 | // FIXME 可読性が低いので call_user_func_array を使わない (またはメソッド名を1つの定数値とする) 実装に。 |
---|
138 | list($this->arrResults, $this->tpl_image) = call_user_func_array(array($this, 'lfGetOrder'.$page), |
---|
139 | array($type, $sdate, $edate)); |
---|
140 | if ($this->getMode() == 'csv') { |
---|
141 | // CSV出力タイトル行の取得 |
---|
142 | list($arrTitleCol, $arrDataCol) = $this->lfGetCSVColum($page); |
---|
143 | $head = SC_Utils_Ex::sfGetCSVList($arrTitleCol); |
---|
144 | $data = $this->lfGetDataColCSV($this->arrResults, $arrDataCol); |
---|
145 | |
---|
146 | // CSVを送信する。 |
---|
147 | list($fime_name, $data) = SC_Utils_Ex::sfGetCSVData($head.$data); |
---|
148 | |
---|
149 | $this->sendResponseCSV($fime_name, $data); |
---|
150 | SC_Response_Ex::actionExit(); |
---|
151 | } |
---|
152 | } |
---|
153 | break; |
---|
154 | default: |
---|
155 | break; |
---|
156 | } |
---|
157 | |
---|
158 | // 画面宣しても日付が保存される |
---|
159 | $_SESSION = $this->lfSaveDateSession($_SESSION, $this->arrHidden); |
---|
160 | $objFormParam->setParam($_SESSION['total']); |
---|
161 | // 入力値の取得 |
---|
162 | $this->arrForm = $objFormParam->getFormParamList(); |
---|
163 | $this->tpl_subtitle = $this->arrTitle[$objFormParam->getValue('page')]; |
---|
164 | |
---|
165 | } |
---|
166 | |
---|
167 | /** |
---|
168 | * デストラクタ. |
---|
169 | * |
---|
170 | * @return void |
---|
171 | */ |
---|
172 | function destroy() { |
---|
173 | parent::destroy(); |
---|
174 | } |
---|
175 | |
---|
176 | /* デフォルト値の取得 */ |
---|
177 | function lfGetDateDefault() { |
---|
178 | $year = date('Y'); |
---|
179 | $month = date('m'); |
---|
180 | $day = date('d'); |
---|
181 | |
---|
182 | $list = isset($_SESSION['total']) ? $_SESSION['total'] : ''; |
---|
183 | |
---|
184 | // セッション情報に開始月度が保存されていない。 |
---|
185 | if (empty($_SESSION['total']['startyear_m'])) { |
---|
186 | $list['startyear_m'] = $year; |
---|
187 | $list['startmonth_m'] = $month; |
---|
188 | } |
---|
189 | |
---|
190 | // セッション情報に開始日付、終了日付が保存されていない。 |
---|
191 | if (empty($_SESSION['total']['startyear']) && empty($_SESSION['total']['endyear'])) { |
---|
192 | $list['startyear'] = $year; |
---|
193 | $list['startmonth'] = $month; |
---|
194 | $list['startday'] = $day; |
---|
195 | $list['endyear'] = $year; |
---|
196 | $list['endmonth'] = $month; |
---|
197 | $list['endday'] = $day; |
---|
198 | } |
---|
199 | |
---|
200 | return $list; |
---|
201 | } |
---|
202 | |
---|
203 | /* パラメーター情報の初期化 */ |
---|
204 | function lfInitParam(&$objFormParam) { |
---|
205 | // デフォルト値の取得 |
---|
206 | $arrList = $this->lfGetDateDefault(); |
---|
207 | |
---|
208 | // 月度集計 |
---|
209 | $objFormParam->addParam(t('PARAM_LABEL_MONTHLY'), 'search_startyear_m', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['startyear_m']); |
---|
210 | $objFormParam->addParam(t('PARAM_LABEL_MONTHLY'), 'search_startmonth_m', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['startmonth_m']); |
---|
211 | // 期間集計 |
---|
212 | $objFormParam->addParam(t('PARAM_LABEL_START_DAY'), 'search_startyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['startyear']); |
---|
213 | $objFormParam->addParam(t('PARAM_LABEL_START_DAY'), 'search_startmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['startmonth']); |
---|
214 | $objFormParam->addParam(t('PARAM_LABEL_START_DAY'), 'search_startday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['startday']); |
---|
215 | $objFormParam->addParam(t('PARAM_LABEL_END_DAY'), 'search_endyear', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['endyear']); |
---|
216 | $objFormParam->addParam(t('PARAM_LABEL_END_DAY'), 'search_endmonth', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['endmonth']); |
---|
217 | $objFormParam->addParam(t('PARAM_LABEL_END_DAY'), 'search_endday', INT_LEN, 'n', array('MAX_LENGTH_CHECK', 'NUM_CHECK'), $arrList['endday']); |
---|
218 | |
---|
219 | // hiddenデータの取得用 |
---|
220 | $objFormParam->addParam('', 'page'); |
---|
221 | $objFormParam->addParam('', 'type'); |
---|
222 | $objFormParam->addParam('', 'mode'); |
---|
223 | $objFormParam->addParam('', 'search_form'); |
---|
224 | } |
---|
225 | |
---|
226 | /* 入力内容のチェック */ |
---|
227 | function lfCheckError(&$objFormParam) { |
---|
228 | |
---|
229 | $objFormParam->convParam(); |
---|
230 | $objErr = new SC_CheckError_Ex($objFormParam->getHashArray()); |
---|
231 | $objErr->arrErr = $objFormParam->checkError(); |
---|
232 | |
---|
233 | // 特殊項目チェック |
---|
234 | |
---|
235 | // 月度集計 |
---|
236 | if ($objFormParam->getValue('search_form') == 1) { |
---|
237 | $objErr->doFunc(array(t('PARAM_LABEL_MONTHLY'), 'search_startyear_m', 'search_startmonth_m'), array('FULL_EXIST_CHECK')); |
---|
238 | } |
---|
239 | |
---|
240 | // 期間集計 |
---|
241 | if ($objFormParam->getValue('search_form') == 2) { |
---|
242 | $objErr->doFunc(array(t('PARAM_LABEL_PERIOD_1'), 'search_startyear', 'search_startmonth', 'search_startday'), array('FULL_EXIST_CHECK')); |
---|
243 | $objErr->doFunc(array(t('PARAM_LABEL_PERIOD_2'), 'search_endyear', 'search_endmonth', 'search_endday'), array('FULL_EXIST_CHECK')); |
---|
244 | $objErr->doFunc(array(t('PARAM_LABEL_PERIOD_1'), 'search_startyear', 'search_startmonth', 'search_startday'), array('CHECK_DATE')); |
---|
245 | $objErr->doFunc(array(t('PARAM_LABEL_PERIOD_2'), 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_DATE')); |
---|
246 | $objErr->doFunc(array(t('PARAM_LABEL_PERIOD_1'), t('PARAM_LABEL_PERIOD_2'), 'search_startyear', 'search_startmonth', 'search_startday', 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_SET_TERM')); |
---|
247 | } |
---|
248 | $objErr->doFunc(array(t('PARAM_LABEL_MONTHLY'), 'search_startyear_m', 'search_startmonth_m'), array('ALL_EXIST_CHECK')); |
---|
249 | $objErr->doFunc(array(t('PARAM_LABEL_START_DAY'), 'search_startyear', 'search_startmonth', 'search_startday'), array('CHECK_DATE')); |
---|
250 | $objErr->doFunc(array(t('PARAM_LABEL_END_DAY'), 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_DATE')); |
---|
251 | $objErr->doFunc(array(t('PARAM_LABEL_START_DAY'), t('PARAM_LABEL_END_DAY'), 'search_startyear', 'search_startmonth', 'search_startday', 'search_endyear', 'search_endmonth', 'search_endday'), array('CHECK_SET_TERM')); |
---|
252 | return $objErr->arrErr; |
---|
253 | } |
---|
254 | |
---|
255 | /* サブナビを移動しても日付が残るようにセッションに入力期間を記録する */ |
---|
256 | function lfSaveDateSession($session, $arrForm) { |
---|
257 | |
---|
258 | // session の初期化をする |
---|
259 | if (!isset($session['total'])) { |
---|
260 | $session['total'] = $this->lfGetDateInit(); |
---|
261 | } |
---|
262 | |
---|
263 | if (!empty($arrForm)) { |
---|
264 | $session['total'] = array_merge($session['total'], $arrForm); |
---|
265 | } |
---|
266 | |
---|
267 | return $session; |
---|
268 | } |
---|
269 | |
---|
270 | /* 日付の初期値 */ |
---|
271 | function lfGetDateInit() { |
---|
272 | $search_startyear_m = $search_startyear = $search_endyear = date('Y'); |
---|
273 | $search_startmonth_m = $search_startmonth = $search_endmonth = date('m'); |
---|
274 | $search_startday = $search_endday = date('d'); |
---|
275 | |
---|
276 | return compact($this->arrSearchForm1, $this->arrSearchForm2); |
---|
277 | } |
---|
278 | |
---|
279 | /* フォームで入力された日付を適切な形にする */ |
---|
280 | function lfSetStartEndDate(&$objFormParam) { |
---|
281 | $arrRet = $objFormParam->getHashArray(); |
---|
282 | |
---|
283 | // 月度集計 |
---|
284 | if ($arrRet['search_form'] == 1) { |
---|
285 | list($sdate, $edate) = SC_Utils_Ex::sfTermMonth($arrRet['search_startyear_m'], |
---|
286 | $arrRet['search_startmonth_m'], |
---|
287 | CLOSE_DAY); |
---|
288 | } |
---|
289 | // 期間集計 |
---|
290 | elseif ($arrRet['search_form'] == 2) { |
---|
291 | $sdate = $arrRet['search_startyear'] . '/' . $arrRet['search_startmonth'] . '/' . $arrRet['search_startday']; |
---|
292 | $edate = $arrRet['search_endyear'] . '/' . $arrRet['search_endmonth'] . '/' . $arrRet['search_endday']; |
---|
293 | } |
---|
294 | |
---|
295 | return array($sdate, $edate); |
---|
296 | } |
---|
297 | |
---|
298 | /* 折れ線グラフの作成 */ |
---|
299 | function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate, $xincline) { |
---|
300 | |
---|
301 | $ret_path = ''; |
---|
302 | |
---|
303 | // 結果が0行以上ある場合のみグラフを生成する。 |
---|
304 | if (count($arrResults) > 0 && $this->install_GD) { |
---|
305 | |
---|
306 | // グラフの生成 |
---|
307 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, 'total'); |
---|
308 | |
---|
309 | // 一時ファイル名の取得 |
---|
310 | $pngname = $this->lfGetGraphPng($type); |
---|
311 | |
---|
312 | $path = GRAPH_REALDIR . $pngname; |
---|
313 | |
---|
314 | // ラベル表示インターバルを求める |
---|
315 | $interval = intval(count($arrList) / 20); |
---|
316 | if ($interval < 1) { |
---|
317 | $interval = 1; |
---|
318 | } |
---|
319 | $objGraphLine = new SC_Graph_Line(); |
---|
320 | |
---|
321 | // 値のセット |
---|
322 | $objGraphLine->setData($arrList); |
---|
323 | $objGraphLine->setXLabel(array_keys($arrList)); |
---|
324 | |
---|
325 | // ラベル回転(日本語不可) |
---|
326 | if ($xincline == true) { |
---|
327 | $objGraphLine->setXLabelAngle(45); |
---|
328 | } |
---|
329 | |
---|
330 | // タイトルセット |
---|
331 | $objGraphLine->setXTitle($xtitle); |
---|
332 | $objGraphLine->setYTitle($ytitle); |
---|
333 | |
---|
334 | // メインタイトル作成 |
---|
335 | list($sy, $sm, $sd) = preg_split('|[/ ]|' , $sdate); |
---|
336 | list($ey, $em, $ed) = preg_split('|[/ ]|' , $edate); |
---|
337 | $start_date = t('LC_Page_Admin_Total_007', array('%s1' => $sy, '%s2' => $sm, '%s3' => $sd)); |
---|
338 | $end_date = t('LC_Page_Admin_Total_007', array('%s1' => $ey, '%s2' => $em, '%s3' => $ed)); |
---|
339 | $objGraphLine->drawTitle(t('LC_Page_Admin_Total_008', array('%s1' => $start_date, '%s2' => $end_date))); |
---|
340 | |
---|
341 | // グラフ描画 |
---|
342 | $objGraphLine->drawGraph(); |
---|
343 | |
---|
344 | // グラフの出力 |
---|
345 | if (DRAW_IMAGE) { |
---|
346 | $objGraphLine->outputGraph(); |
---|
347 | SC_Response_Ex::actionExit(); |
---|
348 | } |
---|
349 | |
---|
350 | // ファイルパスを返す |
---|
351 | $ret_path = GRAPH_URLPATH . $pngname; |
---|
352 | } |
---|
353 | return $ret_path; |
---|
354 | } |
---|
355 | |
---|
356 | // 円グラフの作成 |
---|
357 | function lfGetGraphPie($arrResults, $keyname, $type, $title = '', $sdate = '', $edate = '') { |
---|
358 | |
---|
359 | $ret_path = ''; |
---|
360 | // 結果が0行以上ある場合のみグラフを生成する。 |
---|
361 | if (count($arrResults) > 0 && $this->install_GD) { |
---|
362 | // グラフの生成 |
---|
363 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, |
---|
364 | 'total', GRAPH_PIE_MAX, |
---|
365 | GRAPH_LABEL_MAX); |
---|
366 | |
---|
367 | // 一時ファイル名の取得 |
---|
368 | $pngname = $this->lfGetGraphPng($type); |
---|
369 | $path = GRAPH_REALDIR . $pngname; |
---|
370 | |
---|
371 | $objGraphPie = new SC_Graph_Pie(); |
---|
372 | |
---|
373 | // データをセットする |
---|
374 | $objGraphPie->setData($arrList); |
---|
375 | // 凡例をセットする |
---|
376 | $objGraphPie->setLegend(array_keys($arrList)); |
---|
377 | |
---|
378 | // メインタイトル作成 |
---|
379 | list($sy, $sm, $sd) = preg_split('|[/ ]|' , $sdate); |
---|
380 | list($ey, $em, $ed) = preg_split('|[/ ]|' , $edate); |
---|
381 | $start_date = t('LC_Page_Admin_Total_007', array('%s1' => $sy, '%s2' => $sm, '%s3' => $sd)); |
---|
382 | $end_date = t('LC_Page_Admin_Total_007', array('%s1' => $ey, '%s2' => $em, '%s3' => $ed)); |
---|
383 | |
---|
384 | $objGraphPie->drawTitle(t('LC_Page_Admin_Total_008', array('%s1' => $start_date, '%s2' => $end_date))); |
---|
385 | |
---|
386 | // 円グラフ描画 |
---|
387 | $objGraphPie->drawGraph(); |
---|
388 | |
---|
389 | // グラフの出力 |
---|
390 | if (DRAW_IMAGE) { |
---|
391 | $objGraphPie->outputGraph(); |
---|
392 | SC_Response_Ex::actionExit(); |
---|
393 | } |
---|
394 | |
---|
395 | // ファイルパスを返す |
---|
396 | $ret_path = GRAPH_URLPATH . $pngname; |
---|
397 | } |
---|
398 | return $ret_path; |
---|
399 | } |
---|
400 | |
---|
401 | // 棒グラフの作成 |
---|
402 | function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) { |
---|
403 | $ret_path = ''; |
---|
404 | |
---|
405 | // 結果が0行以上ある場合のみグラフを生成する。 |
---|
406 | if (count($arrResults) > 0 && $this->install_GD) { |
---|
407 | // グラフの生成 |
---|
408 | $arrList = SC_Utils_Ex::sfArrKeyValue($arrResults, $keyname, 'total', GRAPH_PIE_MAX, GRAPH_LABEL_MAX); |
---|
409 | |
---|
410 | // 一時ファイル名の取得 |
---|
411 | $pngname = $this->lfGetGraphPng($type); |
---|
412 | $path = GRAPH_REALDIR . $pngname; |
---|
413 | |
---|
414 | $objGraphBar = new SC_Graph_Bar(); |
---|
415 | |
---|
416 | foreach ($arrList as $key => $value) { |
---|
417 | $arrKey[] = mb_ereg_replace('~', '-', $key); |
---|
418 | } |
---|
419 | |
---|
420 | // グラフ描画 |
---|
421 | $objGraphBar->setXLabel($arrKey); |
---|
422 | $objGraphBar->setXTitle($xtitle); |
---|
423 | $objGraphBar->setYTitle($ytitle); |
---|
424 | $objGraphBar->setData($arrList); |
---|
425 | |
---|
426 | // メインタイトル作成 |
---|
427 | $arrKey = array_keys($arrList); |
---|
428 | list($sy, $sm, $sd) = preg_split('|[/ ]|' , $sdate); |
---|
429 | list($ey, $em, $ed) = preg_split('|[/ ]|' , $edate); |
---|
430 | $start_date = t('LC_Page_Admin_Total_007', array('%s1' => $sy, '%s2' => $sm, '%s3' => $sd)); |
---|
431 | $end_date = t('LC_Page_Admin_Total_007', array('%s1' => $ey, '%s2' => $em, '%s3' => $ed)); |
---|
432 | $objGraphBar->drawTitle(t('LC_Page_Admin_Total_008', array('%s1' => $start_date, '%s2' => $end_date))); |
---|
433 | |
---|
434 | $objGraphBar->drawGraph(); |
---|
435 | |
---|
436 | if (DRAW_IMAGE) { |
---|
437 | $objGraphBar->outputGraph(); |
---|
438 | SC_Response_Ex::actionExit(); |
---|
439 | } |
---|
440 | |
---|
441 | // ファイルパスを返す |
---|
442 | $ret_path = GRAPH_URLPATH . $pngname; |
---|
443 | } |
---|
444 | return $ret_path; |
---|
445 | } |
---|
446 | |
---|
447 | // グラフ用のPNGファイル名 |
---|
448 | function lfGetGraphPng($keyname) { |
---|
449 | |
---|
450 | if ($_POST['search_startyear_m'] != '') { |
---|
451 | $pngname = sprintf('%s_%02d%02d.png', $keyname, substr($_POST['search_startyear_m'],2), $_POST['search_startmonth_m']); |
---|
452 | } else { |
---|
453 | $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']); |
---|
454 | } |
---|
455 | return $pngname; |
---|
456 | } |
---|
457 | |
---|
458 | // 会員、非会員集計のWHERE分の作成 |
---|
459 | function lfGetWhereMember($col_date, $sdate, $edate, $type, $col_member = 'customer_id') { |
---|
460 | $where = ''; |
---|
461 | // 取得日付の指定 |
---|
462 | if ($sdate != '') { |
---|
463 | if ($where != '') { |
---|
464 | $where.= ' AND '; |
---|
465 | } |
---|
466 | $where.= " $col_date >= '". $sdate ."'"; |
---|
467 | } |
---|
468 | |
---|
469 | if ($edate != '') { |
---|
470 | if ($where != '') { |
---|
471 | $where.= ' AND '; |
---|
472 | } |
---|
473 | $edate = date('Y/m/d',strtotime('1 day' ,strtotime($edate))); |
---|
474 | $where.= " $col_date < date('" . $edate ."')"; |
---|
475 | } |
---|
476 | |
---|
477 | // 会員、非会員の判定 |
---|
478 | switch ($type) { |
---|
479 | // 全体 |
---|
480 | case 'all': |
---|
481 | break; |
---|
482 | case 'member': |
---|
483 | if ($where != '') { |
---|
484 | $where.= ' AND '; |
---|
485 | } |
---|
486 | $where.= " $col_member <> 0"; |
---|
487 | break; |
---|
488 | case 'nonmember': |
---|
489 | if ($where != '') { |
---|
490 | $where.= ' AND '; |
---|
491 | } |
---|
492 | $where.= " $col_member = 0"; |
---|
493 | break; |
---|
494 | default: |
---|
495 | break; |
---|
496 | } |
---|
497 | |
---|
498 | return array($where, array()); |
---|
499 | } |
---|
500 | |
---|
501 | /** 会員別集計 **/ |
---|
502 | function lfGetOrderMember($type, $sdate, $edate) { |
---|
503 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
504 | |
---|
505 | list($where, $arrWhereVal) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); |
---|
506 | $where .= ' AND del_flg = 0 AND status <> ?'; |
---|
507 | $arrWhereVal[] = ORDER_CANCEL; |
---|
508 | |
---|
509 | // 会員集計の取得 |
---|
510 | $col = <<< __EOS__ |
---|
511 | COUNT(order_id) AS order_count, |
---|
512 | SUM(total) AS total, |
---|
513 | AVG(total) AS total_average, |
---|
514 | CASE |
---|
515 | WHEN customer_id <> 0 THEN 1 |
---|
516 | ELSE 0 |
---|
517 | END AS member, |
---|
518 | order_sex |
---|
519 | __EOS__; |
---|
520 | |
---|
521 | $from = 'dtb_order'; |
---|
522 | |
---|
523 | $objQuery->setGroupBy('member, order_sex'); |
---|
524 | |
---|
525 | $arrTotalResults = $objQuery->select($col, $from, $where, $arrWhereVal); |
---|
526 | |
---|
527 | foreach ($arrTotalResults as $key => $value) { |
---|
528 | $arrResult =& $arrTotalResults[$key]; |
---|
529 | $member_key = $arrResult['order_sex']; |
---|
530 | if ($member_key != '') { |
---|
531 | $arrResult['member_name'] = (($arrResult['member']) ? t('LC_Page_Admin_Total_009') : t('LC_Page_Admin_Total_010')) . $this->arrSex[$member_key]; |
---|
532 | } else { |
---|
533 | $arrResult['member_name'] = t('LC_Page_Admin_Total_011'); |
---|
534 | } |
---|
535 | } |
---|
536 | |
---|
537 | $tpl_image = $this->lfGetGraphPie($arrTotalResults, 'member_name', 'member', t('LC_Page_Admin_Total_039'), $sdate, $edate); |
---|
538 | |
---|
539 | return array($arrTotalResults, $tpl_image); |
---|
540 | } |
---|
541 | |
---|
542 | /** 商品別集計 **/ |
---|
543 | function lfGetOrderProducts($type, $sdate, $edate) { |
---|
544 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
545 | |
---|
546 | list($where, $arrWhereVal) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); |
---|
547 | |
---|
548 | $where .= ' AND dtb_order.del_flg = 0 AND dtb_order.status <> ?'; |
---|
549 | $arrWhereVal[] = ORDER_CANCEL; |
---|
550 | |
---|
551 | $col = <<< __EOS__ |
---|
552 | product_id, |
---|
553 | product_code, |
---|
554 | product_name, |
---|
555 | SUM(quantity) AS products_count, |
---|
556 | COUNT(dtb_order_detail.order_id) AS order_count, |
---|
557 | price, |
---|
558 | (price * SUM(quantity)) AS total |
---|
559 | __EOS__; |
---|
560 | |
---|
561 | $from = 'dtb_order_detail JOIN dtb_order ON dtb_order_detail.order_id = dtb_order.order_id'; |
---|
562 | |
---|
563 | /* |
---|
564 | if ($mode != 'csv') { |
---|
565 | $sql.= 'LIMIT ' . PRODUCTS_TOTAL_MAX; |
---|
566 | }*/ |
---|
567 | |
---|
568 | // 要index |
---|
569 | $objQuery->setGroupBy('product_id, product_name, product_code, price'); |
---|
570 | //$objQuery->setGroupBy('product_id'); |
---|
571 | $objQuery->setOrder('total DESC'); |
---|
572 | $arrTotalResults = $objQuery->select($col, $from, $where, $arrWhereVal); |
---|
573 | |
---|
574 | $tpl_image = $this->lfGetGraphPie($arrTotalResults, 'product_name', 'products_' . $type, t('LC_Page_Admin_Total_039'), $sdate, $edate); |
---|
575 | |
---|
576 | return array($arrTotalResults, $tpl_image); |
---|
577 | } |
---|
578 | |
---|
579 | /** 職業別集計 **/ |
---|
580 | function lfGetOrderJob($type, $sdate, $edate) { |
---|
581 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
582 | list($where, $arrWhereVal) = $this->lfGetWhereMember('dtb_order.create_date', $sdate, $edate, $type); |
---|
583 | |
---|
584 | $col = <<< __EOS__ |
---|
585 | job, |
---|
586 | COUNT(order_id) AS order_count, |
---|
587 | SUM(total) AS total, |
---|
588 | AVG(total) AS total_average |
---|
589 | __EOS__; |
---|
590 | |
---|
591 | $from = 'dtb_order JOIN dtb_customer ON dtb_order.customer_id = dtb_customer.customer_id'; |
---|
592 | |
---|
593 | $where .= ' AND dtb_order.del_flg = 0 AND dtb_order.status <> ?'; |
---|
594 | $arrWhereVal[] = ORDER_CANCEL; |
---|
595 | |
---|
596 | $objQuery->setGroupBy('job'); |
---|
597 | $objQuery->setOrder('total DESC'); |
---|
598 | $arrTotalResults = $objQuery->select($col, $from, $where, $arrWhereVal); |
---|
599 | |
---|
600 | foreach ($arrTotalResults as $key => $value) { |
---|
601 | $arrResult =& $arrTotalResults[$key]; |
---|
602 | $job_key = $arrResult['job']; |
---|
603 | if ($job_key != '') { |
---|
604 | $arrResult['job_name'] = $this->arrJob[$job_key]; |
---|
605 | } else { |
---|
606 | $arrResult['job_name'] = t('LC_Page_Admin_Total_011'); |
---|
607 | } |
---|
608 | |
---|
609 | } |
---|
610 | $tpl_image = $this->lfGetGraphPie($arrTotalResults, 'job_name', 'job_' . $type, t('LC_Page_Admin_Total_039'), $sdate, $edate); |
---|
611 | |
---|
612 | return array($arrTotalResults, $tpl_image); |
---|
613 | } |
---|
614 | |
---|
615 | /** 年代別集計 **/ |
---|
616 | function lfGetOrderAge($type, $sdate, $edate) { |
---|
617 | |
---|
618 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
619 | |
---|
620 | list($where, $arrWhereVal) = $this->lfGetWhereMember('create_date', $sdate, $edate, $type); |
---|
621 | |
---|
622 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
623 | $col = $dbFactory->getOrderTotalAgeColSql() . ' AS age'; |
---|
624 | $col .= ',COUNT(order_id) AS order_count'; |
---|
625 | $col .= ',SUM(total) AS total'; |
---|
626 | $col .= ',AVG(total) AS total_average'; |
---|
627 | |
---|
628 | $from = 'dtb_order'; |
---|
629 | |
---|
630 | $where .= ' AND del_flg = 0 AND status <> ?'; |
---|
631 | $arrWhereVal[] = ORDER_CANCEL; |
---|
632 | |
---|
633 | $objQuery->setGroupBy('age'); |
---|
634 | $objQuery->setOrder('age DESC'); |
---|
635 | $arrTotalResults = $objQuery->select($col, $from, $where, $arrWhereVal); |
---|
636 | |
---|
637 | foreach ($arrTotalResults as $key => $value) { |
---|
638 | $arrResult =& $arrTotalResults[$key]; |
---|
639 | $age_key = $arrResult['age']; |
---|
640 | if ($age_key != '') { |
---|
641 | $arrResult['age_name'] = t('LC_Page_Admin_Total_012', array('%s1' => $arrResult['age'])); |
---|
642 | } else { |
---|
643 | $arrResult['age_name'] = t('LC_Page_Admin_Total_011'); |
---|
644 | } |
---|
645 | |
---|
646 | } |
---|
647 | $tpl_image = $this->lfGetGraphBar($arrTotalResults, 'age_name', 'age_' . $type, t('LC_Page_Admin_Total_013'), t('LC_Page_Admin_Total_014'), $sdate, $edate); |
---|
648 | |
---|
649 | return array($arrTotalResults, $tpl_image); |
---|
650 | } |
---|
651 | |
---|
652 | /** 期間別集計 **/ |
---|
653 | // todo あいだの日付埋める |
---|
654 | function lfGetOrderTerm($type, $sdate, $edate) { |
---|
655 | $objQuery = SC_Query_Ex::getSingletonInstance(); |
---|
656 | |
---|
657 | list($where, $arrWhereVal) = $this->lfGetWhereMember('create_date', $sdate, $edate); |
---|
658 | $where .= ' AND del_flg = 0 AND status <> ?'; |
---|
659 | $arrWhereVal[] = ORDER_CANCEL; |
---|
660 | |
---|
661 | switch ($type) { |
---|
662 | case 'month': |
---|
663 | $xtitle = t('LC_Page_Admin_Total_015'); |
---|
664 | $ytitle = t('LC_Page_Admin_Total_014'); |
---|
665 | $format = '%m'; |
---|
666 | break; |
---|
667 | case 'year': |
---|
668 | $xtitle = t('LC_Page_Admin_Total_016'); |
---|
669 | $ytitle = t('LC_Page_Admin_Total_014'); |
---|
670 | $format = '%Y'; |
---|
671 | break; |
---|
672 | case 'wday': |
---|
673 | $xtitle = t('LC_Page_Admin_Total_017'); |
---|
674 | $ytitle = t('LC_Page_Admin_Total_014'); |
---|
675 | $format = '%a'; |
---|
676 | break; |
---|
677 | case 'hour': |
---|
678 | $xtitle = t('LC_Page_Admin_Total_018'); |
---|
679 | $ytitle = t('LC_Page_Admin_Total_014'); |
---|
680 | $format = '%H'; |
---|
681 | break; |
---|
682 | default: |
---|
683 | $xtitle = t('LC_Page_Admin_Total_019'); |
---|
684 | $ytitle = t('LC_Page_Admin_Total_014'); |
---|
685 | $format = '%Y-%m-%d'; |
---|
686 | $xincline = true; |
---|
687 | break; |
---|
688 | } |
---|
689 | |
---|
690 | $dbFactory = SC_DB_DBFactory_Ex::getInstance(); |
---|
691 | // todo postgres |
---|
692 | $col = $dbFactory->getOrderTotalDaysWhereSql($type); |
---|
693 | |
---|
694 | $objQuery->setGroupBy('str_date'); |
---|
695 | $objQuery->setOrder('str_date'); |
---|
696 | // 検索結果の取得 |
---|
697 | $arrTotalResults = $objQuery->select($col, 'dtb_order', $where, $arrWhereVal); |
---|
698 | |
---|
699 | $arrTotalResults = $this->lfAddBlankLine($arrTotalResults, $type, $sdate, $edate); |
---|
700 | // todo GDない場合の処理 |
---|
701 | $tpl_image = $this->lfGetGraphLine($arrTotalResults, 'str_date', 'term_' . $type, $xtitle, $ytitle, $sdate, $edate, $xincline); |
---|
702 | $arrTotalResults = $this->lfAddTotalLine($arrTotalResults); |
---|
703 | |
---|
704 | return array($arrTotalResults, $tpl_image); |
---|
705 | } |
---|
706 | |
---|
707 | /* |
---|
708 | * 期間中の日付を埋める |
---|
709 | */ |
---|
710 | function lfAddBlankLine($arrResults, $type, $st, $ed) { |
---|
711 | |
---|
712 | $arrDateList = $this->lfDateTimeArray($type, $st, $ed); |
---|
713 | |
---|
714 | foreach ($arrResults as $arrResult) { |
---|
715 | $strdate = $arrResult['str_date']; |
---|
716 | $arrDateResults[$strdate] = $arrResult; |
---|
717 | } |
---|
718 | |
---|
719 | foreach ($arrDateList as $date) { |
---|
720 | |
---|
721 | if (array_key_exists($date, $arrDateResults)) { |
---|
722 | |
---|
723 | $arrRet[] = $arrDateResults[$date]; |
---|
724 | |
---|
725 | } else { |
---|
726 | $arrRet[]['str_date'] = $date; |
---|
727 | } |
---|
728 | } |
---|
729 | return $arrRet; |
---|
730 | } |
---|
731 | |
---|
732 | /* |
---|
733 | * 日付の配列を作成する |
---|
734 | * |
---|
735 | */ |
---|
736 | function lfDateTimeArray($type, $st, $ed) { |
---|
737 | switch ($type) { |
---|
738 | case 'month': |
---|
739 | $format = 'm'; |
---|
740 | break; |
---|
741 | case 'year': |
---|
742 | $format = 'Y'; |
---|
743 | break; |
---|
744 | case 'wday': |
---|
745 | $format = 'D'; |
---|
746 | break; |
---|
747 | case 'hour': |
---|
748 | $format = 'H'; |
---|
749 | break; |
---|
750 | default: |
---|
751 | $format = 'Y-m-d'; |
---|
752 | break; |
---|
753 | } |
---|
754 | |
---|
755 | if ($type == 'hour') { |
---|
756 | $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'); |
---|
757 | |
---|
758 | } else { |
---|
759 | $arrDateList = array(); |
---|
760 | $tmp = strtotime($st); |
---|
761 | $nAday = 60*60*24; |
---|
762 | $edx = strtotime($ed); |
---|
763 | while ($tmp <= $edx) { |
---|
764 | $sDate = date($format, $tmp); |
---|
765 | if (!in_array($sDate, $arrDateList)) { |
---|
766 | $arrDateList[] = $sDate; |
---|
767 | } |
---|
768 | $tmp += $nAday; |
---|
769 | } |
---|
770 | } |
---|
771 | return $arrDateList; |
---|
772 | } |
---|
773 | |
---|
774 | /* |
---|
775 | * 合計を付与する |
---|
776 | */ |
---|
777 | function lfAddTotalLine($arrResults) { |
---|
778 | // 検索結果が0でない場合 |
---|
779 | if (count($arrResults) > 0) { |
---|
780 | |
---|
781 | // 合計の計算 |
---|
782 | foreach ($arrResults as $arrResult) { |
---|
783 | foreach ($arrResult as $key => $value) { |
---|
784 | $arrTotal[$key] += $arrResult[$key]; |
---|
785 | } |
---|
786 | } |
---|
787 | // 平均値の計算 |
---|
788 | $arrTotal['total_average'] = $arrTotal['total'] / $arrTotal['total_order']; |
---|
789 | $arrResults[] = $arrTotal; |
---|
790 | } |
---|
791 | |
---|
792 | return $arrResults; |
---|
793 | } |
---|
794 | |
---|
795 | // 必要なカラムのみ抽出する(CSVデータで取得する) |
---|
796 | function lfGetDataColCSV($arrData, $arrDataCol) { |
---|
797 | $max = count($arrData); |
---|
798 | $csv_data = ''; |
---|
799 | for ($i = 0; $i < $max; $i++) { |
---|
800 | foreach ($arrDataCol as $val) { |
---|
801 | $arrRet[$i][$val] = $arrData[$i][$val]; |
---|
802 | } |
---|
803 | // 期間別集計の合計行の「期間」項目に不要な値が表示されてしまわない様、'合計'と表示する |
---|
804 | if (($i === $max -1) && isset($arrRet[$i]['str_date'])) { |
---|
805 | $arrRet[$i]['str_date'] = t('LC_Page_Admin_Total_020'); |
---|
806 | } |
---|
807 | $csv_data.= SC_Utils_Ex::sfGetCSVList($arrRet[$i]); |
---|
808 | } |
---|
809 | return $csv_data; |
---|
810 | } |
---|
811 | |
---|
812 | function lfGetCSVColum($page) { |
---|
813 | switch ($page) { |
---|
814 | // 商品別集計 |
---|
815 | case 'products': |
---|
816 | $arrTitleCol = array( |
---|
817 | t('LC_Page_Admin_Total_021'), |
---|
818 | t('LC_Page_Admin_Total_022'), |
---|
819 | t('LC_Page_Admin_Total_023'), |
---|
820 | t('LC_Page_Admin_Total_024'), |
---|
821 | t('LC_Page_Admin_Total_025'), |
---|
822 | t('LC_Page_Admin_Total_026'), |
---|
823 | ); |
---|
824 | $arrDataCol = array( |
---|
825 | 'product_code', |
---|
826 | 'product_name', |
---|
827 | 'order_count', |
---|
828 | 'products_count', |
---|
829 | 'price', |
---|
830 | 'total', |
---|
831 | ); |
---|
832 | break; |
---|
833 | // 職業別集計 |
---|
834 | case 'job': |
---|
835 | $arrTitleCol = array( |
---|
836 | t('LC_Page_Admin_Total_027'), |
---|
837 | t('LC_Page_Admin_Total_023'), |
---|
838 | t('LC_Page_Admin_Total_028'), |
---|
839 | t('LC_Page_Admin_Total_029'), |
---|
840 | ); |
---|
841 | $arrDataCol = array( |
---|
842 | 'job_name', |
---|
843 | 'order_count', |
---|
844 | 'total', |
---|
845 | 'total_average', |
---|
846 | ); |
---|
847 | break; |
---|
848 | // 会員別集計 |
---|
849 | case 'member': |
---|
850 | $arrTitleCol = array( |
---|
851 | t('LC_Page_Admin_Total_030'), |
---|
852 | t('LC_Page_Admin_Total_023'), |
---|
853 | t('LC_Page_Admin_Total_028'), |
---|
854 | t('LC_Page_Admin_Total_029'), |
---|
855 | ); |
---|
856 | $arrDataCol = array( |
---|
857 | 'member_name', |
---|
858 | 'order_count', |
---|
859 | 'total', |
---|
860 | 'total_average', |
---|
861 | ); |
---|
862 | break; |
---|
863 | // 年代別集計 |
---|
864 | case 'age': |
---|
865 | $arrTitleCol = array( |
---|
866 | t('LC_Page_Admin_Total_031'), |
---|
867 | t('LC_Page_Admin_Total_023'), |
---|
868 | t('LC_Page_Admin_Total_028'), |
---|
869 | t('LC_Page_Admin_Total_029'), |
---|
870 | ); |
---|
871 | $arrDataCol = array( |
---|
872 | 'age_name', |
---|
873 | 'order_count', |
---|
874 | 'total', |
---|
875 | 'total_average', |
---|
876 | ); |
---|
877 | break; |
---|
878 | // 期間別集計 |
---|
879 | default: |
---|
880 | $arrTitleCol = array( |
---|
881 | t('LC_Page_Admin_Total_032'), |
---|
882 | t('LC_Page_Admin_Total_023'), |
---|
883 | t('LC_Page_Admin_Total_033'), |
---|
884 | t('LC_Page_Admin_Total_034'), |
---|
885 | t('LC_Page_Admin_Total_035'), |
---|
886 | t('LC_Page_Admin_Total_036'), |
---|
887 | t('LC_Page_Admin_Total_037'), |
---|
888 | t('LC_Page_Admin_Total_038'), |
---|
889 | t('LC_Page_Admin_Total_028'), |
---|
890 | t('LC_Page_Admin_Total_029'), |
---|
891 | ); |
---|
892 | $arrDataCol = array( |
---|
893 | 'str_date', |
---|
894 | 'total_order', |
---|
895 | 'men', |
---|
896 | 'women', |
---|
897 | 'men_member', |
---|
898 | 'men_nonmember', |
---|
899 | 'women_member', |
---|
900 | 'women_nonmember', |
---|
901 | 'total', |
---|
902 | 'total_average', |
---|
903 | ); |
---|
904 | break; |
---|
905 | } |
---|
906 | |
---|
907 | return array($arrTitleCol, $arrDataCol); |
---|
908 | } |
---|
909 | } |
---|