source: branches/rel/html/admin/total/index.php @ 13449

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