report_canceled_orders.php

Go to the documentation of this file.
00001 <?php
00002 
00003 if (!class_exists('report_canceled_orders')) {
00007     class Report_canceled_orders extends report_base
00008     {
00009 
00015         protected $_sThisTemplate = "report_canceled_orders.tpl";
00016 
00022         public function drawReport()
00023         {
00024             $oDb = oxDb::getDb();
00025 
00026             $oSmarty = $this->getSmarty();
00027             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_from'])));
00028             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime($oSmarty->_tpl_vars['time_to'])));
00029 
00030             // collects sessions what executed 'order' function
00031             $sSql = "select 1 from `oxlogs` where oxclass = 'order' and
00032                        oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
00033             if ($oDb->getOne($sSql)) {
00034                 return true;
00035             }
00036 
00037             // collects sessions what executed order class
00038             $sSql = "select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
00039             if ($oDb->getOne($sSql)) {
00040                 return true;
00041             }
00042 
00043             // collects sessions what executed payment class
00044             $sSql = "select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
00045             if ($oDb->getOne($sSql)) {
00046                 return true;
00047             }
00048 
00049             // collects sessions what executed 'user' class
00050             $sSql = "select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
00051             if ($oDb->getOne($sSql)) {
00052                 return true;
00053             }
00054 
00055             // collects sessions what executed 'tobasket' function
00056             $sSql = "select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo";
00057             if ($oDb->getOne($sSql)) {
00058                 return true;
00059             }
00060 
00061             // orders made
00062             $sSql = "select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo";
00063             if ($oDb->getOne($sSql)) {
00064                 return true;
00065             }
00066         }
00067 
00075         protected function _collectSessions($sQ)
00076         {
00077             $aTempOrder = array();
00078             $rs = oxDb::getDb()->execute($sQ);
00079             if ($rs != false && $rs->recordCount() > 0) {
00080                 while (!$rs->EOF) {
00081                     $aTempOrder[$rs->fields[1]] = $rs->fields[0];
00082                     $rs->moveNext();
00083                 }
00084             }
00085 
00086             return $aTempOrder;
00087         }
00088 
00099         protected function _collectOrderSessions($sQ, $aTempOrder, &$aData, $blMonth = true)
00100         {
00101             // collects sessions what executed order class
00102             $aTempExecOrdersSessions = array();
00103             $rs = oxDb::getDb()->execute($sQ);
00104             if ($rs != false && $rs->recordCount() > 0) {
00105                 $iFirstWeekDay = $this->getConfig()->getConfigParam('iFirstWeekDay');
00106                 while (!$rs->EOF) {
00107                     if (!isset($aTempOrder[$rs->fields[1]])) {
00108                         $aTempExecOrdersSessions[$rs->fields[1]] = 1;
00109                         $sKey = strtotime($rs->fields[0]);
00111                         $oUtilsData = oxRegistry::get("oxUtilsDate");
00112                         $sKey = $blMonth ? date("m/Y", $sKey) : $oUtilsData->getWeekNumber($iFirstWeekDay, $sKey);
00113                         if (isset($aData[$sKey])) {
00114                             $aData[$sKey]++;
00115                         }
00116 
00117                     }
00118                     $rs->moveNext();
00119                 }
00120             }
00121 
00122             return $aTempExecOrdersSessions;
00123         }
00124 
00136         protected function _collectPaymentSessions(
00137             $sQ,
00138             $aTempOrder,
00139             $aTempExecOrdersSessions,
00140             &$aDataX2,
00141             $blMonth = true
00142         ) {
00143             $aTempPaymentSessions = array();
00144             $rs = oxDb::getDb()->execute($sQ);
00145             if ($rs != false && $rs->recordCount() > 0) {
00146                 $iFirstWeekDay = $this->getConfig()->getConfigParam('iFirstWeekDay');
00147                 while (!$rs->EOF) {
00148                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00149                         $aTempPaymentSessions[$rs->fields[1]] = 1;
00150                         $sKey = strtotime($rs->fields[0]);
00151                         $sKey = $blMonth ? date("m/Y", $sKey) : oxRegistry::get("oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
00152                         if (isset($aDataX2[$sKey])) {
00153                             $aDataX2[$sKey]++;
00154                         }
00155                     }
00156                     $rs->moveNext();
00157                 }
00158             }
00159 
00160             return $aTempPaymentSessions;
00161         }
00162 
00175         protected function _collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, &$aDataX3, $blMonth = true)
00176         {
00177             $aTempUserSessions = array();
00178             $rs = oxDb::getDb()->execute($sQ);
00179             if ($rs != false && $rs->recordCount() > 0) {
00180                 $iFirstWeekDay = $this->getConfig()->getConfigParam('iFirstWeekDay');
00181                 while (!$rs->EOF) {
00182                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00183                         $aTempUserSessions[$rs->fields[1]] = 1;
00184                         $sKey = strtotime($rs->fields[0]);
00185                         $sKey = $blMonth ? date("m/Y", $sKey) : oxRegistry::get("oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
00186                         if (isset($aDataX3[$sKey])) {
00187                             $aDataX3[$sKey]++;
00188                         }
00189                     }
00190                     $rs->moveNext();
00191                 }
00192             }
00193 
00194             return $aTempUserSessions;
00195         }
00196 
00208         protected function _collectToBasketSessions($sSql, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, &$aDataX4, $blMonth = true)
00209         {
00210             $rs = oxDb::getDb()->execute($sSql);
00211             if ($rs != false && $rs->recordCount() > 0) {
00212                 $iFirstWeekDay = $this->getConfig()->getConfigParam('iFirstWeekDay');
00213                 while (!$rs->EOF) {
00214                     if (!$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00215                         $sKey = strtotime($rs->fields[0]);
00216                         $sKey = $blMonth ? date("m/Y", $sKey) : oxRegistry::get("oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
00217                         if (isset($aDataX4[$sKey])) {
00218                             $aDataX4[$sKey]++;
00219                         }
00220                     }
00221                     $rs->moveNext();
00222                 }
00223             }
00224         }
00225 
00233         protected function _collectOrdersMade($sSql, &$aDataX5, $blMonth = true)
00234         {
00235             $rs = oxDb::getDb()->execute($sSql);
00236             if ($rs != false && $rs->recordCount() > 0) {
00237                 $iFirstWeekDay = $this->getConfig()->getConfigParam('iFirstWeekDay');
00238                 while (!$rs->EOF) {
00239                     $sKey = strtotime($rs->fields[0]);
00240                     $sKey = $blMonth ? date("m/Y", $sKey) : oxRegistry::get("oxUtilsDate")->getWeekNumber($iFirstWeekDay, $sKey);
00241                     if (isset($aDataX5[$sKey])) {
00242                         $aDataX5[$sKey]++;
00243                     }
00244                     $rs->moveNext();
00245                 }
00246             }
00247         }
00248 
00255         protected function _collectOrdersMadeForVisitorWeek($sQ, &$aDataX5)
00256         {
00257             // orders made
00258             $rs = oxDb::getDb()->execute($sQ);
00259             if ($rs != false && $rs->recordCount() > 0) {
00260                 while (!$rs->EOF) {
00261                     $sKey = oxRegistry::get("oxUtilsDate")->getWeekNumber(oxConfig::getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]));
00262                     if (isset($aDataX5[$sKey])) {
00263                         $aDataX5[$sKey]++;
00264                     }
00265                     $rs->moveNext();
00266                 }
00267             }
00268         }
00269 
00273         public function visitor_month()
00274         {
00275             $myConfig = $this->getConfig();
00276             $oDb = oxDb::getDb();
00277 
00278             $dTimeTo = strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"));
00279             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", $dTimeTo));
00280             $dTimeFrom = mktime(23, 59, 59, date("m", $dTimeTo) - 12, date("d", $dTimeTo), date("Y", $dTimeTo));
00281             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", $dTimeFrom));
00282 
00283             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid";
00284 
00285             $aTemp = array();
00286             for ($i = 1; $i <= 12; $i++) {
00287                 $aTemp[date("m/Y", mktime(23, 59, 59, date("m", $dTimeFrom) + $i, date("d", $dTimeFrom), date("Y", $dTimeFrom)))] = 0;
00288             }
00289 
00290             $rs = $oDb->execute($sSQL);
00291 
00292             if ($rs != false && $rs->recordCount() > 0) {
00293                 while (!$rs->EOF) {
00294                     $aTemp[date("m/Y", strtotime($rs->fields[0]))]++;
00295                     $rs->moveNext();
00296                 }
00297             }
00298 
00299             $aDataX = $aTemp;
00300             $aDataY = array_keys($aTemp);
00301             $aDataX2 = $aDataX3 = $aDataX4 = $aDataX5 = $aDataX6 = array_fill_keys($aDataY, 0);
00302 
00303             // collects sessions what executed 'order' function
00304             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00305             $aTempOrder = $this->_collectSessions($sQ);
00306 
00307             // collects sessions what executed order class
00308             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00309             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6);
00310 
00311             // collects sessions what executed payment class
00312             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00313             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2);
00314 
00315             // collects sessions what executed 'user' class
00316             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00317             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2);
00318 
00319             // collects sessions what executed 'tobasket' function
00320             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00321             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4);
00322 
00323             // orders made
00324             $sQ = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
00325             $this->_collectOrdersMade($sQ, $aDataX5);
00326 
00327             header("Content-type: image/png");
00328 
00329             // New graph with a drop shadow
00330             $graph = $this->getGraph(800, 600);
00331 
00332             // Description
00333             $graph->xaxis->setTickLabels($aDataY);
00334 
00335             // Set title and subtitle
00336             $graph->title->set("Monat");
00337 
00338             // Create the bar plot
00339             $bplot2 = new BarPlot(array_values($aDataX2));
00340             $bplot2->setFillColor("#9966cc");
00341             $bplot2->setLegend("Best.Abbr. in Bezahlmethoden");
00342 
00343             // Create the bar plot
00344             $bplot3 = new BarPlot(array_values($aDataX3));
00345             $bplot3->setFillColor("#ffcc00");
00346             $bplot3->setLegend("Best.Abbr. in Benutzer");
00347 
00348             // Create the bar plot
00349             $bplot4 = new BarPlot(array_values($aDataX4));
00350             $bplot4->setFillColor("#6699ff");
00351             $bplot4->setLegend("Best.Abbr. in Warenkorb");
00352 
00353             // Create the bar plot
00354             $bplot6 = new BarPlot(array_values($aDataX6));
00355             $bplot6->setFillColor("#ff0099");
00356             $bplot6->setLegend("Best.Abbr. in Bestellbestaetigung");
00357 
00358             // Create the bar plot
00359             $bplot5 = new BarPlot(array_values($aDataX5));
00360             $bplot5->setFillColor("silver");
00361             $bplot5->setLegend("Bestellungen");
00362 
00363             // Create the grouped bar plot
00364             $gbplot = new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
00365             $graph->add($gbplot);
00366 
00367             // Finally output the  image
00368             $graph->stroke();
00369         }
00370 
00374         public function visitor_week()
00375         {
00376             $myConfig = $this->getConfig();
00377             $oDb = oxDb::getDb();
00378 
00379             $aDataX = array();
00380             $aDataX2 = array();
00381             $aDataX3 = array();
00382             $aDataX4 = array();
00383             $aDataX5 = array();
00384             $aDataX6 = array();
00385             $aDataY = array();
00386 
00387             $sTimeTo = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_to"))));
00388             $sTimeFrom = $oDb->quote(date("Y-m-d H:i:s", strtotime(oxRegistry::getConfig()->getRequestParameter("time_from"))));
00389 
00390             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
00391 
00392             $aTemp = array();
00393             $rs = $oDb->execute($sSQL);
00394 
00395             if ($rs != false && $rs->recordCount() > 0) {
00396                 while (!$rs->EOF) {
00397                     $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam('iFirstWeekDay'), strtotime($rs->fields[0]))]++;
00398                     $rs->moveNext();
00399                 }
00400             }
00401 
00402             // initializing
00403             list($iFrom, $iTo) = $this->getWeekRange();
00404             for ($i = $iFrom; $i < $iTo; $i++) {
00405                 $aDataX[$i] = 0;
00406                 $aDataX2[$i] = 0;
00407                 $aDataX3[$i] = 0;
00408                 $aDataX4[$i] = 0;
00409                 $aDataX5[$i] = 0;
00410                 $aDataX6[$i] = 0;
00411                 $aDataY[] = "KW " . $i;
00412             }
00413 
00414             foreach ($aTemp as $key => $value) {
00415                 $aDataX[$key] = $value;
00416                 $aDataX2[$key] = 0;
00417                 $aDataX3[$key] = 0;
00418                 $aDataX4[$key] = 0;
00419                 $aDataX5[$key] = 0;
00420                 $aDataX6[$key] = 0;
00421                 $aDataY[] = "KW " . $key;
00422             }
00423 
00424             // collects sessions what executed 'order' function
00425             $sQ = "select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00426             $aTempOrder = $this->_collectSessions($sQ);
00427 
00428             // collects sessions what executed order class
00429             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00430             $aTempExecOrdersSessions = $this->_collectOrderSessions($sQ, $aTempOrder, $aDataX6, false);
00431 
00432             // collects sessions what executed payment class
00433             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00434             $aTempPaymentSessions = $this->_collectPaymentSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2, false);
00435 
00436             // collects sessions what executed 'user' class
00437             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00438             $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2, false);
00439 
00440             // collects sessions what executed 'tobasket' function
00441             $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
00442             $this->_collectToBasketSessions($sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4, false);
00443 
00444             // orders made
00445             $sQ = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
00446             $this->_collectOrdersMade($sQ, $aDataX5, false);
00447 
00448             header("Content-type: image/png");
00449 
00450             // New graph with a drop shadow
00451             $graph = $this->getGraph(max(800, count($aDataX) * 80), 600);
00452 
00453             // Description
00454             $graph->xaxis->setTickLabels($aDataY);
00455 
00456             // Set title and subtitle
00457             $graph->title->set("Woche");
00458 
00459             // Create the bar plot
00460             $bplot2 = new BarPlot(array_values($aDataX2));
00461             $bplot2->setFillColor("#9966cc");
00462             $bplot2->setLegend("Best.Abbr. in Bezahlmethoden");
00463 
00464             // Create the bar plot
00465             $bplot3 = new BarPlot(array_values($aDataX3));
00466             $bplot3->setFillColor("#ffcc00");
00467             $bplot3->setLegend("Best.Abbr. in Benutzer");
00468 
00469             // Create the bar plot
00470             $bplot4 = new BarPlot(array_values($aDataX4));
00471             $bplot4->setFillColor("#6699ff");
00472             $bplot4->setLegend("Best.Abbr. in Warenkorb");
00473 
00474             // Create the bar plot
00475             $bplot6 = new BarPlot(array_values($aDataX6));
00476             $bplot6->setFillColor("#ff0099");
00477             $bplot6->setLegend("Best.Abbr. in Bestellbestaetigung");
00478 
00479             // Create the bar plot
00480             $bplot5 = new BarPlot(array_values($aDataX5));
00481             $bplot5->setFillColor("silver");
00482             $bplot5->setLegend("Bestellungen");
00483 
00484             // Create the grouped bar plot
00485             $gbplot = new groupBarPlot(array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
00486             $graph->add($gbplot);
00487 
00488             // Finally output the  image
00489             $graph->stroke();
00490         }
00491     }
00492 }