source: branches/dev/html/admin/total/index.php @ 12164

Revision 12164, 23.9 KB checked in by kakinaka, 15 years ago (diff)
Line 
1<?php
2/*
3 * Copyright(c) 2000-2007 LOCKON CO.,LTD. All Rights Reserved.
4 *
5 * http://www.lockon.co.jp/
6 */
7require_once("../require.php");
8require_once("./index_sub.php");
9require_once("../batch/daily.php");
10
11require_once("./class/SC_GraphPie.php");
12require_once("./class/SC_GraphLine.php");
13require_once("./class/SC_GraphBar.php");
14
15// GD¥é¥¤¥Ö¥é¥ê¤Î¥¤¥ó¥¹¥È¡¼¥ëȽÄê
16$install_GD = (function_exists("gd_info"))?true:false;
17
18class LC_Page {
19    var $arrResults;
20    var $keyname;
21    var $tpl_image;
22    var $arrTitle;
23    function LC_Page() {
24        $this->tpl_mainpage = 'total/index.tpl';
25        $this->tpl_subnavi = 'total/subnavi.tpl';
26        $this->tpl_graphsubtitle = 'total/subtitle.tpl';
27        $this->tpl_titleimage = URL_DIR.'img/title/title_sale.jpg';
28        $this->tpl_mainno = 'total';
29        global $arrWDAY;
30        $this->arrWDAY = $arrWDAY;
31        // ¥Ú¡¼¥¸¥¿¥¤¥È¥ë
32        $this->arrTitle[''] = "´ü´ÖÊ̽¸·×";
33        $this->arrTitle['term'] = "´ü´ÖÊ̽¸·×";
34        $this->arrTitle['products'] = "¾¦ÉÊÊ̽¸·×";
35        $this->arrTitle['age'] = "ǯÂåÊ̽¸·×";
36        $this->arrTitle['job'] = "¿¦¶ÈÊ̽¸·×";
37        $this->arrTitle['member'] = "²ñ°÷Ê̽¸·×";
38       
39        // ¥­¥ã¥Ã¥·¥å²óÈò¤Î¤¿¤á¤ËÆüÉÕ¤òÅϤ¹
40        $this->cashtime = time();
41    }
42}
43
44$objPage = new LC_Page();
45$objView = new SC_AdminView();
46$objSess = new SC_Session();
47// ǧ¾Ú²ÄÈݤÎȽÄê
48sfIsSuccess($objSess);
49
50// ÆþÎÏ´ü´Ö¤ò¥»¥Ã¥·¥ç¥ó¤Ëµ­Ï¿¤¹¤ë
51lfSaveDateSession();
52
53if($_GET['draw_image'] != ""){
54    define(DRAW_IMAGE , true);
55}else{
56    define(DRAW_IMAGE , false);
57}
58
59// ¥Ñ¥é¥á¡¼¥¿´ÉÍý¥¯¥é¥¹
60$objFormParam = new SC_FormParam();
61// ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½
62lfInitParam();
63$objFormParam->setParam($_POST);
64$objFormParam->setParam($_GET);
65
66// ¸¡º÷¥ï¡¼¥É¤Î°ú¤­·Ñ¤®
67foreach ($_POST as $key => $val) {
68    if (ereg("^search_", $key)) {
69        $objPage->arrHidden[$key] = $val;       
70    }
71}
72
73$mode = $objFormParam->getValue('mode');
74switch($mode) {
75case 'pdf':
76case 'csv':
77case 'search':
78    // ÆþÎÏÃͤÎÊÑ´¹
79    $objFormParam->convParam();
80    $objPage->arrErr = lfCheckError($arrRet);
81    $arrRet = $objFormParam->getHashArray();
82   
83    // ÆþÎÏ¥¨¥é¡¼¤Ê¤·
84    if (count($objPage->arrErr) == 0) {
85        foreach ($arrRet as $key => $val) {
86            if($val == "") {
87                continue;
88            }
89            switch ($key) {
90            case 'search_startyear':
91                $sdate = $objFormParam->getValue('search_startyear') . "/" . $objFormParam->getValue('search_startmonth') . "/" . $objFormParam->getValue('search_startday');
92                break;
93            case 'search_endyear':
94                $edate = $objFormParam->getValue('search_endyear') . "/" . $objFormParam->getValue('search_endmonth') . "/" . $objFormParam->getValue('search_endday');
95                break;
96            case 'search_startyear_m':
97                list($sdate, $edate) = sfTermMonth($objFormParam->getValue('search_startyear_m'), $objFormParam->getValue('search_startmonth_m'), CLOSE_DAY);
98                break;
99            default:
100                break;
101            }
102        }
103
104        if($objFormParam->getValue('type') != "") {
105            $type = $objFormParam->getValue('type');
106        }
107               
108        $page = $objFormParam->getValue('page');
109        switch($page) {
110        // ¾¦ÉÊÊ̽¸·×
111        case 'products':
112            if($type == "") {
113                $type = 'all';
114            }
115            $objPage->tpl_page_type = "total/page_products.tpl";
116            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
117            if(!DAILY_BATCH_MODE) {
118                lfRealTimeDailyTotal($sdate, $edate);
119            }
120            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
121            $objPage = lfGetOrderProducts($type, $sdate, $edate, $objPage, $install_GD, $mode);
122            break;
123        // ¿¦¶ÈÊ̽¸·×
124        case 'job':
125            if($type == "") {
126                $type = 'all';
127            }
128            $objPage->tpl_page_type = "total/page_job.tpl";
129            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
130            if(!DAILY_BATCH_MODE) {
131                lfRealTimeDailyTotal($sdate, $edate);
132            }
133            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
134            $objPage = lfGetOrderJob($type, $sdate, $edate, $objPage, $install_GD);
135            break;
136        // ²ñ°÷Ê̽¸·×
137        case 'member':
138            if($type == "") {
139                $type = 'all';
140            }
141            $objPage->tpl_page_type = "total/page_member.tpl";
142            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
143            if(!DAILY_BATCH_MODE) {
144                lfRealTimeDailyTotal($sdate, $edate);
145            }
146            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
147            $objPage = lfGetOrderMember($type, $sdate, $edate, $objPage, $install_GD);
148            break;
149        // ǯÂåÊ̽¸·×
150        case 'age':
151            if($type == "") {
152                $type = 'all';
153            }
154           
155            $objPage->tpl_page_type = "total/page_age.tpl";
156            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
157            if(!DAILY_BATCH_MODE) {
158                lfRealTimeDailyTotal($sdate, $edate);
159            }
160            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
161            $objPage = lfGetOrderAge($type, $sdate, $edate, $objPage, $install_GD);
162            break;
163        // ´ü´ÖÊ̽¸·×
164        default:
165            if($type == "") {
166                $type = 'day';
167            }
168            $objPage->tpl_page_type = "total/page_term.tpl";
169            // ̤½¸·×¥Ç¡¼¥¿¤Î½¸·×¤ò¹Ô¤¦
170            if(!DAILY_BATCH_MODE) {
171                lfRealTimeDailyTotal($sdate, $edate);
172            }
173            // ¸¡º÷·ë²Ì¤Î¼èÆÀ
174            $objPage = lfGetOrderTerm($type, $sdate, $edate, $objPage, $install_GD);
175           
176            break;
177        }
178
179        if($mode == 'csv') {
180            // CSV½ÐÎÏ¥¿¥¤¥È¥ë¹Ô¤Î¼èÆÀ
181            list($arrTitleCol, $arrDataCol) = lfGetCSVColum($page, $objPage->keyname);
182            $head = sfGetCSVList($arrTitleCol);
183            $data = lfGetDataColCSV($objPage->arrResults, $arrDataCol);
184            // CSV¤òÁ÷¿®¤¹¤ë¡£
185            sfCSVDownload($head.$data, $page."_".$type);
186            exit;
187        }
188       
189        if($mode == 'pdf') {
190            // CSV½ÐÎÏ¥¿¥¤¥È¥ë¹Ô¤Î¼èÆÀ
191            list($arrTitleCol, $arrDataCol, $arrColSize, $arrAlign, $title) = lfGetPDFColum($page, $type, $objPage->keyname);
192            $head = sfGetPDFList($arrTitleCol);
193            $data = lfGetDataColPDF($objPage->arrResults, $arrDataCol, 40);
194            // PDF½ÐÎÏÍÑ
195            $graph_name = basename($objPage->tpl_image);
196            lfPDFDownload($graph_name, $head . $data, $arrColSize, $arrAlign, $sdate, $edate, $title, $page);
197            exit;
198        }
199    }
200    break;
201default:
202    if(count($_GET) == 0) {
203        // ¥Ð¥Ã¥Á¥â¡¼¥É¤Î¾ì¹ç¤Î¤ß¼Â¹Ô¤¹¤ë
204        if(DAILY_BATCH_MODE) {
205            // 3ÆüÁ°¤Þ¤Ç¤Î½¸·×
206            lfStartDailyTotal(3,0);
207        }
208    }
209    break;
210}
211
212// ÅÐÏ¿¡¦¹¹¿·Æü¸¡º÷ÍÑ
213$objDate = new SC_Date();
214$objDate->setStartYear(RELEASE_YEAR);
215$objDate->setEndYear(DATE("Y"));
216$objPage->arrYear = $objDate->getYear();
217$objPage->arrMonth = $objDate->getMonth();
218$objPage->arrDay = $objDate->getDay();
219// ÆþÎÏÃͤμèÆÀ
220$objPage->arrForm = $objFormParam->getFormParamList();
221
222$objPage->tpl_subtitle = $objPage->arrTitle[$objFormParam->getValue('page')];
223
224$objView->assignobj($objPage);
225$objView->display(MAIN_FRAME);
226
227//---------------------------------------------------------------------------------------------------------------------------
228/* PDF½ÐÎÏ */
229function lfPDFDownload($image, $table, $arrColSize, $arrAlign, $sdate, $edate, $title, $page = "") {
230   
231    $objPdf = new SC_Pdf();
232    $objPdf->setTableColor("CCCCCC", "F0F0F0", "D1DEFE");
233           
234    // ÅÚÂæ¤È¤Ê¤ëPDF¥Õ¥¡¥¤¥ë¤Î»ØÄê
235    $objPdf->setTemplate(PDF_DIR . "total.pdf");
236
237    $disp_sdate = sfDispDBDate($sdate, false);
238    $disp_edate = sfDispDBDate($edate, false);
239               
240    $arrText['title_block'] = $title;
241    $arrText['date_block'] = "$disp_sdate-$disp_edate";
242    $arrImage['graph_block'] = GRAPH_DIR . $image;
243   
244    // ʸËö¤Î\n¤òºï½ü¤¹¤ë
245    $table = ereg_replace("\n$", "", $table);
246    $arrRet = split("\n", $table);
247    $page_max = intval((count($arrRet) / 35) + 1);
248   
249    for($page = 1; $page <= $page_max; $page++) {
250        if($page > 1) {
251            // 2¥Ú¡¼¥¸°Ê¹ß
252            $start_no = 35 * ($page - 1) + 1;
253        } else {
254            // ³«»Ï¥Ú¡¼¥¸
255            $start_no = 1;         
256        }
257               
258        $arrText['page_block'] = $page . " / " . $page_max;
259        $objPdf->setTextBlock($arrText);
260        $objPdf->setImageBlock($arrImage);
261        // ¥Ö¥í¥Ã¥¯ÃͤÎÆþÎÏ
262        $objPdf->writeBlock();
263        // ºÇ½ª¥Ú¡¼¥¸¤Î¤ß¡¢¾¦ÉÊÊ̽¸·×¤Ï¹ç·×¤¬¤Ê¤¤¤Î¤ÇºÇ½ª¹Ô¤Î¿§¤òÊѹ¹¤·¤Ê¤¤¡£
264        if($page == $page_max && $page != 'products') {
265            $last_color_flg = true;
266        } else {
267            $last_color_flg = false;
268        }   
269        $objPdf->writeTableCenter($table, 500, $arrColSize, $arrAlign, 35, $start_no, $last_color_flg);
270        $objPdf->closePage();
271    }
272
273    // PDF¤Î½ÐÎÏ
274    $objPdf->output(); 
275}
276
277/* ¥»¥Ã¥·¥ç¥ó¤ËÆþÎÏ´ü´Ö¤òµ­Ï¿¤¹¤ë */
278function lfSaveDateSession() {
279    if($_POST['form'] == 1) {
280        $_SESSION['total']['startyear_m'] = $_POST['search_startyear_m'];
281        $_SESSION['total']['startmonth_m'] = $_POST['search_startmonth_m'];
282    }
283   
284    if($_POST['form'] == 2) {
285        $_SESSION['total']['startyear'] = $_POST['search_startyear'];
286        $_SESSION['total']['startmonth'] = $_POST['search_startmonth'];
287        $_SESSION['total']['startday'] = $_POST['search_startday'];
288        $_SESSION['total']['endyear'] = $_POST['search_endyear'];
289        $_SESSION['total']['endmonth'] = $_POST['search_endmonth'];
290        $_SESSION['total']['endday'] = $_POST['search_endday'];
291    }
292}
293
294/* ¥Ç¥Õ¥©¥ë¥ÈÃͤμèÆÀ */
295function lfGetDateDefault() {
296    $year = date("Y");
297    $month = date("m");
298    $day = date("d");
299   
300    $list = $_SESSION['total'];
301   
302    // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤Ë³«»Ï·îÅÙ¤¬Êݸ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
303    if($_SESSION['total']['startyear_m'] == "") {
304        $list['startyear_m'] = $year;
305        $list['startmonth_m'] = $month;
306    }
307   
308    // ¥»¥Ã¥·¥ç¥ó¾ðÊó¤Ë³«»ÏÆüÉÕ¡¢½ªÎ»ÆüÉÕ¤¬Êݸ¤µ¤ì¤Æ¤¤¤Ê¤¤¡£
309    if($_SESSION['total']['startyear'] == "" && $_SESSION['total']['endyear'] == "") {
310        $list['startyear'] = $year;
311        $list['startmonth'] = $month;
312        $list['startday'] = $day;
313        $list['endyear'] = $year;
314        $list['endmonth'] = $month;
315        $list['endday'] = $day;
316    }
317   
318    return $list;   
319}
320
321/* ¥Ñ¥é¥á¡¼¥¿¾ðÊó¤Î½é´ü²½ */
322function lfInitParam() {
323    global $objFormParam;
324       
325    // ¥Ç¥Õ¥©¥ë¥ÈÃͤμèÆÀ
326    $arrList = lfGetDateDefault();
327   
328    // ·îÅÙ½¸·×
329    $objFormParam->addParam("·îÅÙ", "search_startyear_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear_m']);
330    $objFormParam->addParam("·îÅÙ", "search_startmonth_m", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth_m']);
331    // ´ü´Ö½¸·×
332    $objFormParam->addParam("³«»ÏÆü", "search_startyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startyear']);
333    $objFormParam->addParam("³«»ÏÆü", "search_startmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startmonth']);
334    $objFormParam->addParam("³«»ÏÆü", "search_startday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['startday']);
335    $objFormParam->addParam("½ªÎ»Æü", "search_endyear", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endyear']);
336    $objFormParam->addParam("½ªÎ»Æü", "search_endmonth", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endmonth']);
337    $objFormParam->addParam("½ªÎ»Æü", "search_endday", INT_LEN, "n", array("MAX_LENGTH_CHECK", "NUM_CHECK"), $arrList['endday']);
338   
339    // hidden¥Ç¡¼¥¿¤Î¼èÆÀÍÑ
340    $objFormParam->addParam("", "page");
341    $objFormParam->addParam("", "type");
342    $objFormParam->addParam("", "mode");
343
344}
345
346/* ÆþÎÏÆâÍƤΥÁ¥§¥Ã¥¯ */
347function lfCheckError() {
348    global $objFormParam;
349    // ÆþÎϥǡ¼¥¿¤òÅϤ¹¡£
350    $arrRet =  $objFormParam->getHashArray();
351    $objErr = new SC_CheckError($arrRet);
352    $objErr->arrErr = $objFormParam->checkError();
353   
354    // Æüì¹àÌÜ¥Á¥§¥Ã¥¯
355    if($_POST['form'] == 1) {
356        $objErr->doFunc(array("·îÅÙ", "search_startyear_m"), array("ONE_EXIST_CHECK"));
357    }
358   
359    if($_POST['form'] == 2) {
360        $objErr->doFunc(array("´ü´Ö", "search_startyear", "search_endyear"), array("ONE_EXIST_CHECK"));
361    }
362           
363    $objErr->doFunc(array("·îÅÙ", "search_startyear_m", "search_startmonth_m"), array("ALL_EXIST_CHECK"));
364    $objErr->doFunc(array("³«»ÏÆü", "search_startyear", "search_startmonth", "search_startday"), array("CHECK_DATE"));
365    $objErr->doFunc(array("½ªÎ»Æü", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_DATE"));
366    $objErr->doFunc(array("³«»ÏÆü", "½ªÎ»Æü", "search_startyear", "search_startmonth", "search_startday", "search_endyear", "search_endmonth", "search_endday"), array("CHECK_SET_TERM"));
367    return $objErr->arrErr;
368}
369
370/* ÀÞ¤ìÀþ¥°¥é¥Õ¤ÎºîÀ® */
371function lfGetGraphLine($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
372   
373    $ret_path = "";
374   
375    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
376    if(count($arrResults) > 0) {
377       
378        // ¥°¥é¥Õ¤ÎÀ¸À®
379        $arrList = sfArrKeyValue($arrResults, $keyname, "total");
380
381        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
382        $pngname = lfGetGraphPng($type);
383       
384        $path = GRAPH_DIR . $pngname;
385       
386        // ¥é¥Ù¥ëɽ¼¨¥¤¥ó¥¿¡¼¥Ð¥ë¤òµá¤á¤ë
387        $interval = intval(count($arrList) / 20);
388        if($interval < 1) {
389            $interval = 1;
390        }
391        $objGraphPie = new SC_GraphPie();
392        $objGraphLine = new SC_GraphLine();
393       
394        // ÃͤΥ»¥Ã¥È
395        $objGraphLine->setData($arrList);
396        $objGraphLine->setXLabel(array_keys($arrList));
397       
398        // ¥é¥Ù¥ë²óž(ÆüËܸìÉÔ²Ä)
399        if($keyname == "key_day"){
400            $objGraphLine->setXLabelAngle(45);
401        }
402
403        // ¥¿¥¤¥È¥ë¥»¥Ã¥È
404        $objGraphLine->setXTitle($xtitle);
405        $objGraphLine->setYTitle($ytitle);
406       
407        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
408        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
409        list($ey, $em, $ed) = split("[/ ]" , $edate);
410        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
411        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
412        $objGraphLine->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
413       
414        // ¥°¥é¥ÕÉÁ²è
415        $objGraphLine->drawGraph();
416       
417        // ¥°¥é¥Õ¤Î½ÐÎÏ
418        if(DRAW_IMAGE){
419            $objGraphLine->outputGraph();
420            exit();
421        }
422
423        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
424        $ret_path = GRAPH_URL . $pngname;
425    }
426    return $ret_path;
427}
428
429// ±ß¥°¥é¥Õ¤ÎºîÀ®
430function lfGetGraphPie($arrResults, $keyname, $type, $title = "", $sdate = "", $edate = "") {
431   
432    $ret_path = "";
433   
434    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
435    if(count($arrResults) > 0) {
436        // ¥°¥é¥Õ¤ÎÀ¸À®
437        $arrList = sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
438       
439        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
440        $pngname = lfGetGraphPng($type);
441        $path = GRAPH_DIR . $pngname;
442       
443        $objGraphPie = new SC_GraphPie();
444       
445        /* ¥Ç¥Ð¥Ã¥°É½¼¨ÍÑ by naka
446        foreach($arrList as $key => $val) {
447            $objGraphPie->debugPrint("key:$key val:$val");
448        }
449        */
450       
451        // ¥Ç¡¼¥¿¤ò¥»¥Ã¥È¤¹¤ë
452        $objGraphPie->setData($arrList);
453        // ËÞÎã¤ò¥»¥Ã¥È¤¹¤ë
454        $objGraphPie->setLegend(array_keys($arrList));
455                               
456        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
457        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
458        list($ey, $em, $ed) = split("[/ ]" , $edate);
459        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
460        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
461        $objGraphPie->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
462               
463        // ±ß¥°¥é¥ÕÉÁ²è
464        $objGraphPie->drawGraph();
465       
466        // ¥°¥é¥Õ¤Î½ÐÎÏ
467        if(DRAW_IMAGE){
468            $objGraphPie->outputGraph();
469            exit();
470        }
471
472        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
473        $ret_path = GRAPH_URL . $pngname;
474    }
475    return $ret_path;
476}
477
478// ËÀ¥°¥é¥Õ¤ÎºîÀ®
479function lfGetGraphBar($arrResults, $keyname, $type, $xtitle, $ytitle, $sdate, $edate) {
480    $ret_path = "";
481   
482    // ·ë²Ì¤¬0¹Ô°Ê¾å¤¢¤ë¾ì¹ç¤Î¤ß¥°¥é¥Õ¤òÀ¸À®¤¹¤ë¡£
483    if(count($arrResults) > 0) {
484        // ¥°¥é¥Õ¤ÎÀ¸À®
485        $arrList = sfArrKeyValue($arrResults, $keyname, "total", GRAPH_PIE_MAX, GRAPH_LABEL_MAX);
486       
487        // °ì»þ¥Õ¥¡¥¤¥ë̾¤Î¼èÆÀ
488        $pngname = lfGetGraphPng($type);
489        $path = GRAPH_DIR . $pngname;
490       
491        $objGraphBar = new SC_GraphBar();
492       
493        foreach(array_keys($arrList) as $val) {
494            $arrKey[] = ereg_replace("¡Á", "-", $val);
495        }
496       
497        // ¥°¥é¥ÕÉÁ²è
498        $objGraphBar->setXLabel($arrKey);
499        $objGraphBar->setXTitle($xtitle);
500        $objGraphBar->setYTitle($ytitle);
501        $objGraphBar->setData($arrList);
502       
503        // ¥á¥¤¥ó¥¿¥¤¥È¥ëºîÀ®
504        $arrKey = array_keys($arrList);
505        list($sy, $sm, $sd) = split("[/ ]" , $sdate);
506        list($ey, $em, $ed) = split("[/ ]" , $edate);
507        $start_date = $sy . "ǯ" . $sm . "·î" . $sd . "Æü";
508        $end_date = $ey . "ǯ" . $em . "·î" . $ed . "Æü";
509        $objGraphBar->drawTitle("½¸·×´ü´Ö¡§" . $start_date . " - " . $end_date);
510       
511        $objGraphBar->drawGraph();
512       
513        if(DRAW_IMAGE){
514            $objGraphBar->outputGraph();
515            exit();
516        }
517       
518        // ¥Õ¥¡¥¤¥ë¥Ñ¥¹¤òÊÖ¤¹
519        $ret_path = GRAPH_URL . $pngname;
520    }
521    return $ret_path;
522}
523
524// ¥°¥é¥ÕÍѤÎPNG¥Õ¥¡¥¤¥ë̾
525function lfGetGraphPng($keyname) {
526    if($_POST['search_startyear_m'] != "") {
527        $pngname = sprintf("%s_%02d%02d.png", $keyname, substr($_POST['search_startyear_m'],2), $_POST['search_startmonth_m']);
528    } else {
529        $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']);
530    }
531    return $pngname;
532}
533
534// ²ñ°÷¡¢Èó²ñ°÷½¸·×¤ÎWHEREʬ¤ÎºîÀ®
535function lfGetWhereMember($col_date, $sdate, $edate, $type, $col_member = "customer_id") {
536    // ¼èÆÀÆüÉդλØÄê
537    if($sdate != "") {
538        if ($where != "") {
539            $where.= " AND ";
540        }           
541        $where.= " $col_date >= '". $sdate ."'";
542    }
543       
544    if($edate != "") {
545        if ($where != "") {
546            $where.= " AND ";
547        }
548        $edate = date("Y/m/d",strtotime("1 day" ,strtotime($edate)));   
549        $where.= " $col_date < date('" . $edate ."')";
550    }
551   
552    // ²ñ°÷¡¢Èó²ñ°÷¤ÎȽÄê
553    switch($type) {
554    // Á´ÂÎ
555    case 'all':
556        break;
557    case 'member':
558        if ($where != "") {
559            $where.= " AND ";
560        }
561        $where.= " $col_member <> 0";
562        break;
563    case 'nonmember':
564        if ($where != "") {
565            $where.= " AND ";
566        }
567        $where.= " $col_member = 0";
568        break;
569    default:
570        break;
571    }
572   
573    return array($where, $arrval);
574}
575
576/** ²ñ°÷Ê̽¸·× **/
577function lfGetOrderMember($type, $sdate, $edate, $objPage, $graph = true) {
578    global $arrSex;
579       
580    list($where, $arrval) = lfGetWhereMember('create_date', $sdate, $edate, $type);
581   
582    // ²ñ°÷½¸·×¤Î¼èÆÀ
583    $col = "COUNT(*) AS order_count, SUM(total) AS total, (AVG(total)) AS total_average, order_sex";
584    $from = "dtb_order";
585    $objQuery = new SC_Query();
586    $objQuery->setGroupBy("order_sex");
587   
588    $tmp_where = $where . " AND customer_id <> 0 AND del_flg = 0 ";
589    $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
590   
591    // ²ñ°÷¹ØÆþ¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤¹¤ë¡£
592    $max = count($arrRet);
593    for($i = 0; $i < $max; $i++) {
594        $arrRet[$i]['member_name'] = '²ñ°÷'.$arrSex[$arrRet[$i]['order_sex']];
595    }
596    $objPage->arrResults = $arrRet;
597   
598    // Èó²ñ°÷½¸·×¤Î¼èÆÀ
599    $tmp_where = $where . " AND customer_id = 0 AND del_flg = 0 ";
600    $arrRet = $objQuery->select($col, $from, $tmp_where, $arrval);
601    // Èó²ñ°÷¹ØÆþ¤Ç¤¢¤ë¤³¤È¤òµ­Ï¿¤¹¤ë¡£
602    $max = count($arrRet);
603    for($i = 0; $i < $max; $i++) {
604        $arrRet[$i]['member_name'] = 'Èó²ñ°÷'.$arrSex[$arrRet[$i]['order_sex']];
605    }
606   
607    $objPage->arrResults = array_merge($objPage->arrResults, $arrRet);
608   
609    // ±ß¥°¥é¥Õ¤ÎÀ¸À®
610    if($graph) {   
611        $image_key = "member";
612        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "member_name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
613    }
614   
615    return $objPage;
616}
617
618/** ¾¦ÉÊÊ̽¸·× **/
619function lfGetOrderProducts($type, $sdate, $edate, $objPage, $graph = true, $mode = "") {
620    list($where, $arrval) = lfGetWhereMember('create_date', $sdate, $edate, $type);
621   
622    $sql = "SELECT T1.product_id, T1.product_code, T1.product_name as name, T1.products_count, T1.order_count, T1.price, T1.total ";
623    $sql.= "FROM ( ";
624    $sql.= "SELECT product_id, product_name, product_code, price, ";
625    $sql.= "COUNT(*) AS order_count, ";
626    $sql.= "SUM(quantity) AS products_count, ";
627    $sql.= "(price * sum(quantity)) AS total ";
628    $sql.= "FROM dtb_order_detail WHERE order_id IN (SELECT order_id FROM dtb_order WHERE $where ) ";
629    $sql.= "GROUP BY product_id, product_name, product_code, price ";
630    $sql.= ") AS T1 ";
631    $sql.= "ORDER BY T1.total DESC ";
632   
633    if($mode != "csv") {
634        $sql.= "LIMIT " . PRODUCTS_TOTAL_MAX;
635    }
636   
637    $objQuery = new SC_Query();
638    $objPage->arrResults = $objQuery->getall($sql, $arrval);
639   
640    // ±ß¥°¥é¥Õ¤ÎÀ¸À®
641    if($graph) {
642        $image_key = "products_" . $type;
643        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
644    }
645   
646    return $objPage;
647}
648
649/** ¿¦¶ÈÊ̽¸·× **/
650function lfGetOrderJob($type, $sdate, $edate, $objPage, $graph = true) {
651    global $arrJob;
652       
653    list($where, $arrval) = lfGetWhereMember('T2.create_date', $sdate, $edate, $type);
654   
655    $sql = "SELECT job, count(*) AS order_count, SUM(total) AS total, (AVG(total)) AS total_average ";
656    $sql.= "FROM dtb_customer AS T1 LEFT JOIN dtb_order AS T2 USING ( customer_id ) WHERE $where AND T2.del_flg = 0 ";
657    $sql.= "GROUP BY job ORDER BY total DESC";
658   
659    $objQuery = new SC_Query();
660    $objPage->arrResults = $objQuery->getall($sql, $arrval);
661           
662    $max = count($objPage->arrResults);
663    for($i = 0; $i < $max; $i++) {
664        $job_key = $objPage->arrResults[$i]['job'];
665        if($job_key != "") {
666            $objPage->arrResults[$i]['job_name'] = $arrJob[$job_key];
667        } else {
668            $objPage->arrResults[$i]['job_name'] = "̤²óÅú";
669        }
670    }
671
672    // ±ß¥°¥é¥Õ¤ÎÀ¸À®   
673    if($graph) {
674        $image_key = "job_" . $type;
675        $objPage->tpl_image = lfGetGraphPie($objPage->arrResults, "job_name", $image_key, "(Çä¾åÈæΨ)", $sdate, $edate);
676    }
677   
678    return $objPage;
679}
680
681/** ǯÂåÊ̽¸·× **/
682function lfGetOrderAge($type, $sdate, $edate, $objPage, $graph = true) {
683
684    list($where, $arrval) = lfGetWhereMember('order_date', $sdate, $edate, $type, "member");
685   
686    $sql = "SELECT SUM(order_count) AS order_count, SUM(total) AS total, start_age, end_age ";
687    $sql.= "FROM dtb_bat_order_daily_age WHERE $where ";
688    $sql.= "GROUP BY start_age, end_age ORDER BY start_age, end_age";
689
690    $objQuery = new SC_Query();
691    $objPage->arrResults = $objQuery->getall($sql, $arrval);
692   
693    $max = count($objPage->arrResults);
694    for($i = 0; $i < $max; $i++) {
695        if($objPage->arrResults[$i]['order_count'] > 0) {
696            $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['order_count']);
697        }   
698        $start_age = $objPage->arrResults[$i]['start_age'];
699        $end_age = $objPage->arrResults[$i]['end_age'];
700        if($start_age != "" || $end_age != "") {
701            if($end_age != 999) {
702                $objPage->arrResults[$i]['age_name'] = $start_age . "¡Á" . $end_age . "ºÐ";
703            } else {
704                $objPage->arrResults[$i]['age_name'] = $start_age . "ºÐ¡Á";
705            }
706        } else {
707            $objPage->arrResults[$i]['age_name'] = "̤²óÅú";
708        }
709    }
710   
711    // ËÀ¥°¥é¥Õ¤ÎÀ¸À®
712    if($graph) {
713        $image_key = "age_" . $type;
714        $xtitle = "(ǯÎð)";
715        $ytitle = "(Çä¾å¹ç·×)";
716        $objPage->tpl_image = lfGetGraphBar($objPage->arrResults, "age_name", $image_key, $xtitle, $ytitle, $sdate, $edate);
717    }
718   
719    return $objPage;
720}
721
722/** ´ü´ÖÊ̽¸·× **/
723function lfGetOrderTerm($type, $sdate, $edate, $objPage, $graph = true) {
724       
725        $tmp_col = "sum(total_order) as total_order, sum(men) as men, sum(women) as women,";
726        $tmp_col.= "sum(men_member) as men_member, sum(men_nonmember) as men_nonmember,";
727        $tmp_col.= "sum(women_member) as women_member, sum(women_nonmember) as women_nonmember,";
728        $tmp_col.= "sum(total) as total, (avg(total_average)) as total_average";
729        $objQuery = new SC_Query();
730       
731        switch($type) {
732        // ·îÊÌ
733        case 'month':
734            $col = $tmp_col . ",key_month";
735            $objQuery->setgroupby("key_month");
736            $objQuery->setOrder("key_month");
737            $objPage->keyname = "key_month";
738            $objPage->tpl_tail = "·î";
739            $from = "dtb_bat_order_daily";
740            $xtitle = "(·îÊÌ)";
741            $ytitle = "(Çä¾å¹ç·×)";
742            break;
743        // ǯÊÌ
744        case 'year':
745            $col = $tmp_col . ",key_year";
746            $objQuery->setgroupby("key_year");
747            $objQuery->setOrder("key_year");
748            $objPage->keyname = "key_year";
749            $objPage->tpl_tail = "ǯ";
750            $from = "dtb_bat_order_daily";
751            $xtitle = "(ǯÊÌ)";
752            $ytitle = "(Çä¾å¹ç·×)";
753            break;
754        // ÍËÆüÊÌ
755        case 'wday':
756            $col = $tmp_col . ",key_wday, wday";
757            $objQuery->setgroupby("key_wday, wday");
758            $objQuery->setOrder("wday");
759            $objPage->keyname = "key_wday";
760            $objPage->tpl_tail = "ÍËÆü";
761            $from = "dtb_bat_order_daily";
762            $xtitle = "(ÍËÆüÊÌ)";
763            $ytitle = "(Çä¾å¹ç·×)";
764            break;
765        // »þ´ÖÊÌ
766        case 'hour':
767            $col = $tmp_col . ",hour";
768            $objQuery->setgroupby("hour");
769            $objQuery->setOrder("hour");
770            $objPage->keyname = "hour";
771            $objPage->tpl_tail = "»þ";
772            $from = "dtb_bat_order_daily_hour";
773            $xtitle = "(»þ´ÖÊÌ)";
774            $ytitle = "(Çä¾å¹ç·×)";
775            break;
776        default:
777            $col = "*";
778            $objQuery->setOrder("key_day");
779            $objPage->keyname = "key_day";
780            $from = "dtb_bat_order_daily";
781            $xtitle = "(ÆüÊÌ)";
782            $ytitle = "(Çä¾å¹ç·×)";
783            break;
784        }
785       
786
787    // ¼èÆÀÆüÉդλØÄê
788        if($sdate != "") {
789            if ($where != "") {
790                $where.= " AND ";
791            }           
792            $where.= " order_date >= '". $sdate ."'";
793        }
794       
795        if($edate != "") {
796            if ($where != "") {
797                $where.= " AND ";
798            }
799            $edate_next = date("Y/m/d",strtotime("1 day" ,strtotime($edate)));
800            $where.= " order_date < date('" . $edate_next ."')";
801        }
802       
803        // ¸¡º÷·ë²Ì¤Î¼èÆÀ
804        $objPage->arrResults = $objQuery->select($col, $from, $where, $arrval);
805       
806        // ÀÞ¤ìÀþ¥°¥é¥Õ¤ÎÀ¸À®   
807        if($graph) {
808            $image_key = "term_" . $type;
809            $objPage->tpl_image = lfGetGraphLine($objPage->arrResults, $objPage->keyname, $image_key, $xtitle, $ytitle, $sdate, $edate);
810        }
811       
812        // ¸¡º÷·ë²Ì¤¬0¤Ç¤Ê¤¤¾ì¹ç
813        if(count($objPage->arrResults) > 0) {
814            // ºÇ½ª½¸·×¹Ô¼èÆÀ¤¹¤ë
815            $col = $tmp_col;
816            $objQuery = new SC_Query();
817            $arrRet = $objQuery->select($col, $from, $where, $arrval);
818            $arrRet[0][$objPage->keyname] = "¹ç·×";
819            $objPage->arrResults[] = $arrRet[0];
820        }
821
822        // Ê¿¶ÑÃͤη׻»
823        $max = count($objPage->arrResults);
824        for($i = 0; $i < $max; $i++) {
825            if($objPage->arrResults[$i]['total_order'] > 0) {
826                $objPage->arrResults[$i]['total_average'] = intval($objPage->arrResults[$i]['total'] / $objPage->arrResults[$i]['total_order']);
827            }
828        }
829       
830        return $objPage;
831}
832
833?>
Note: See TracBrowser for help on using the repository browser.