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     {
00014         protected $_sThisTemplate = "report_canceled_orders.tpl";
00015 
00021         public function drawReport()
00022         {
00023             $oDb = oxDb::getDb();
00024 
00025             $oSmarty    = $this->getSmarty();
00026             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
00027             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
00028 
00029             // collects sessions what executed 'order' function
00030             if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00031                 return true;
00032             }
00033 
00034             // collects sessions what executed order class
00035             if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00036                 return true;
00037             }
00038 
00039             // collects sessions what executed payment class
00040             if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00041                 return true;
00042             }
00043 
00044             // collects sessions what executed 'user' class
00045             if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00046                 return true;
00047             }
00048 
00049             // collects sessions what executed 'tobasket' function
00050             if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTime_from and oxtime <= $sTime_to" ) ) {
00051                 return true;
00052             }
00053 
00054             // orders made
00055             if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to" ) ) {
00056                 return true;
00057             }
00058         }
00059 
00065         public function visitor_month()
00066         {
00067             $myConfig = $this->getConfig();
00068             $oDb = oxDb::getDb();
00069 
00070             $aDataX = array();
00071             $aDataY = array();
00072 
00073             $dTimeTo    = strtotime( oxConfig::getParameter( "time_to"));
00074             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00075             $dTimeFrom  = mktime( 23, 59, 59, date( "m", $dTimeTo )-12, date( "d", $dTimeTo ), date( "Y", $dTimeTo ) );
00076             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00077 
00078             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00079             //die($sSQL);
00080             $aTemp = array();
00081             for ( $i = 1; $i <= 12; $i++)
00082                 $aTemp[date( "m/Y", mktime(23, 59, 59, date( "m", $dTimeFrom)+$i, date( "d", $dTimeFrom), date( "Y", $dTimeFrom)) )] = 0;
00083 
00084             $rs = $oDb->execute( $sSQL);
00085             $blData = false;
00086             if ($rs != false && $rs->recordCount() > 0) {
00087                 while (!$rs->EOF) {
00088                     $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00089                     $rs->moveNext();
00090                     $blData = true;
00091                 }
00092             }
00093 
00094             $aDataX2  = array();
00095             $aDataX3  = array();
00096             if ($blData) {
00097                 foreach ( $aTemp as $key => $value) {
00098                     $aDataX[$key]   = $value;
00099                     $aDataX2[$key]  = 0;
00100                     $aDataX3[$key]  = 0;
00101                     $aDataX4[$key]  = 0;
00102                     $aDataX5[$key]  = 0;
00103                     $aDataX6[$key]  = 0;
00104                     $aDataY[]       = $key;
00105                 }
00106             }
00107             // collects sessions what executed 'order' function
00108             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00109             $aTempOrder = array();
00110             $rs = $oDb->execute( $sSQL);
00111             if ($rs != false && $rs->recordCount() > 0) {
00112                 while (!$rs->EOF) {
00113                     $aTempOrder[$rs->fields[1]] = $rs->fields[0];
00114                     $rs->moveNext();
00115                 }
00116             }
00117 
00118             // collects sessions what executed order class
00119             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00120             $aTempExecOrders = array();
00121             $aTempExecOrdersSessions = array();
00122             $rs = $oDb->execute( $sSQL);
00123             if ($rs != false && $rs->recordCount() > 0) {
00124                 while (!$rs->EOF) {
00125                     if (!isset($aTempOrder[$rs->fields[1]])) {
00126                         $aTempExecOrdersSessions[$rs->fields[1]] = 1;
00127                         $aTempExecOrders[date( "m/Y", strtotime( $rs->fields[0]))]++;
00128                     }
00129                     $rs->moveNext();
00130                 }
00131             }
00132 
00133             foreach ( $aTempExecOrders as $key => $value) {
00134                 if (isset($aDataX6[$key]))
00135                     $aDataX6[$key] = $value;
00136             }
00137 
00138             // collects sessions what executed payment class
00139             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00140             $aTempPayment = array();
00141             $aTempPaymentSessions = array();
00142             $rs = $oDb->execute( $sSQL);
00143             if ($rs != false && $rs->recordCount() > 0) {
00144                 while (!$rs->EOF) {
00145                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00146                         $aTempPaymentSessions[$rs->fields[1]] = 1;
00147                         $aTempPayment[date( "m/Y", strtotime( $rs->fields[0]))]++;
00148                     }
00149                     $rs->moveNext();
00150                 }
00151             }
00152 
00153             foreach ( $aTempPayment as $key => $value) {
00154                 if (isset($aDataX2[$key]))
00155                     $aDataX2[$key] = $value;
00156             }
00157 
00158             // collects sessions what executed 'user' class
00159             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00160             $aTempUser = array();
00161             $aTempUserSessions = array();
00162             $rs = $oDb->execute( $sSQL);
00163             if ($rs != false && $rs->recordCount() > 0) {
00164                 while (!$rs->EOF) {
00165                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00166                         $aTempUserSessions[$rs->fields[1]] = 1;
00167                         $aTempUser[date( "m/Y", strtotime( $rs->fields[0]))]++;
00168                     }
00169                     $rs->moveNext();
00170                 }
00171             }
00172 
00173             foreach ( $aTempUser as $key => $value) {
00174                 if (isset($aDataX3[$key]))
00175                     $aDataX3[$key] = $value;
00176             }
00177 
00178             // collects sessions what executed 'tobasket' function
00179             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00180             $aTempBasket = array();
00181             $rs = $oDb->execute( $sSQL);
00182             if ($rs != false && $rs->recordCount() > 0) {
00183                 while (!$rs->EOF) {
00184                     if (!$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]]))
00185                         $aTempBasket[date( "m/Y", strtotime( $rs->fields[0]))]++;
00186                     $rs->moveNext();
00187                 }
00188             }
00189 
00190             foreach ( $aTempBasket as $key => $value) {
00191                 if (isset($aDataX4[$key]))
00192                     $aDataX4[$key] = $value;
00193             }
00194 
00195             // orders made
00196             $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00197             $aTemp = array();
00198             $rs = $oDb->execute( $sSQL);
00199             if ($rs != false && $rs->recordCount() > 0) {
00200                 while (!$rs->EOF) {
00201                     $aTemp[date( "m/Y", strtotime( $rs->fields[0]))]++;
00202                     $rs->moveNext();
00203                 }
00204             }
00205 
00206             foreach ( $aTemp as $key => $value) {
00207                 if (isset($aDataX5[$key]))
00208                     $aDataX5[$key] = $value;
00209             }
00210 
00211             header ("Content-type: image/png" );
00212 
00213             // New graph with a drop shadow
00214             $graph = new Graph(800, 600);
00215 
00216             $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00217 
00218             // Use a "text" X-scale
00219             $graph->setScale("textlin");
00220 
00221             // Label align for X-axis
00222             $graph->xaxis->setLabelAlign('center', 'top', 'right');
00223 
00224             // Label align for Y-axis
00225             $graph->yaxis->setLabelAlign('right', 'bottom');
00226 
00227             $graph->setShadow();
00228             // Description
00229             $graph->xaxis->setTickLabels( $aDataY);
00230 
00231 
00232             // Set title and subtitle
00233             $graph->title->set("Monat");
00234 
00235             // Use built in font
00236             $graph->title->setFont(FF_FONT1, FS_BOLD);
00237 
00238             $aDataFinalX2 = array();
00239             foreach ( $aDataX2 as $dData)
00240                 $aDataFinalX2[] = $dData;
00241 
00242             // Create the bar plot
00243             $bplot2 = new BarPlot( $aDataFinalX2);
00244             $bplot2->setFillColor ("#9966cc");
00245             //$bplot2->setLegend("Kaeufer");
00246             $bplot2->setLegend("Best.Abbr. in Bezahlmethoden");
00247 
00248             $aDataFinalX3 = array();
00249             foreach ( $aDataX3 as $dData)
00250                 $aDataFinalX3[] = $dData;
00251 
00252             // Create the bar plot
00253             $bplot3 = new BarPlot( $aDataFinalX3);
00254             $bplot3->setFillColor ("#ffcc00");
00255             $bplot3->setLegend("Best.Abbr. in Benutzer");
00256 
00257             $aDataFinalX4 = array();
00258             foreach ( $aDataX4 as $dData)
00259                 $aDataFinalX4[] = $dData;
00260 
00261             // Create the bar plot
00262             $bplot4 = new BarPlot( $aDataFinalX4);
00263             $bplot4->setFillColor ("#6699ff");
00264             $bplot4->setLegend("Best.Abbr. in Warenkorb");
00265 
00266             $aDataFinalX6 = array();
00267             foreach ( $aDataX6 as $dData)
00268                 $aDataFinalX6[] = $dData;
00269 
00270             // Create the bar plot
00271             $bplot6 = new BarPlot( $aDataFinalX6);
00272             $bplot6->setFillColor ("#ff0099");
00273             $bplot6->setLegend("Best.Abbr. in Bestellbestaetigung");
00274 
00275             $aDataFinalX5 = array();
00276             foreach ( $aDataX5 as $dData)
00277                 $aDataFinalX5[] = $dData;
00278 
00279             // Create the bar plot
00280             $bplot5 = new BarPlot( $aDataFinalX5);
00281             $bplot5->setFillColor ("silver");
00282             $bplot5->setLegend("Bestellungen");
00283 
00284             // Create the grouped bar plot
00285             $gbplot = new groupBarPlot (array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
00286             $graph->add( $gbplot);
00287 
00288             // Finally output the  image
00289             $graph->stroke();
00290 
00291         }
00292 
00298         public function visitor_week()
00299         {
00300             $myConfig = $this->getConfig();
00301             $oDb = oxDb::getDb();
00302 
00303             $aDataX = array();
00304             $aDataY = array();
00305 
00306             $dTimeTo    = strtotime( oxConfig::getParameter( "time_to"));
00307             $sTime_to   = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
00308             $dTimeFrom  = strtotime( oxConfig::getParameter( "time_from"));
00309             $sTime_from = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
00310 
00311             $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid order by oxtime";
00312 
00313             $aTemp = array();
00314             $rs = $oDb->execute( $sSQL);
00315             $blData = false;
00316             if ($rs != false && $rs->recordCount() > 0) {
00317                 while (!$rs->EOF) {
00318                     $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00319                     $rs->moveNext();
00320                     $blData = true;
00321                 }
00322             }
00323 
00324             $aDataX2  = array();
00325             $aDataX3  = array();
00326             if ($blData) {
00327                 foreach ( $aTemp as $key => $value) {
00328                     $aDataX[$key]   = $value;
00329                     $aDataX2[$key]  = 0;
00330                     $aDataX3[$key]  = 0;
00331                     $aDataX4[$key]  = 0;
00332                     $aDataX5[$key]  = 0;
00333                     $aDataX6[$key]  = 0;
00334                     $aDataY[]       = "KW ".$key;
00335                 }
00336             }
00337             // collects sessions what executed 'order' function
00338             $sSQL = "select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00339             $aTempOrder = array();
00340             $rs = $oDb->execute( $sSQL);
00341             if ($rs != false && $rs->recordCount() > 0) {
00342                 while (!$rs->EOF) {
00343                     $aTempOrder[$rs->fields[1]] = $rs->fields[0];
00344                     $rs->moveNext();
00345                 }
00346             }
00347 
00348             // collects sessions what executed order class
00349             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00350             $aTempExecOrders = array();
00351             $aTempExecOrdersSessions = array();
00352             $rs = $oDb->execute( $sSQL);
00353             if ($rs != false && $rs->recordCount() > 0) {
00354                 while (!$rs->EOF) {
00355                     if (!isset($aTempOrder[$rs->fields[1]])) {
00356                         $aTempExecOrdersSessions[$rs->fields[1]] = 1;
00357                         //$aTempExecOrders[date( "W", strtotime( $rs->fields[0]))]++;
00358                         $aTempExecOrders[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00359                     }
00360                     $rs->moveNext();
00361                 }
00362             }
00363 
00364             foreach ( $aTempExecOrders as $key => $value) {
00365                 if (isset($aDataX6[$key]))
00366                     $aDataX6[$key] = $value;
00367             }
00368 
00369             // collects sessions what executed payment class
00370             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00371             $aTempPayment = array();
00372             $aTempPaymentSessions = array();
00373             $rs = $oDb->execute( $sSQL);
00374             if ($rs != false && $rs->recordCount() > 0) {
00375                 while (!$rs->EOF) {
00376                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00377                         $aTempPaymentSessions[$rs->fields[1]] = 1;
00378                         //$aTempPayment[date( "W", strtotime( $rs->fields[0]))]++;
00379                         $aTempPayment[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00380                     }
00381                     $rs->moveNext();
00382                 }
00383             }
00384 
00385             foreach ( $aTempPayment as $key => $value) {
00386                 if (isset($aDataX2[$key]))
00387                     $aDataX2[$key] = $value;
00388             }
00389 
00390             // collects sessions what executed 'user' class
00391             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00392             $aTempUser = array();
00393             $aTempUserSessions = array();
00394             $rs = $oDb->execute( $sSQL);
00395             if ($rs != false && $rs->recordCount() > 0) {
00396                 while (!$rs->EOF) {
00397                     if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
00398                         $aTempUserSessions[$rs->fields[1]] = 1;
00399                         //$aTempUser[date( "W", strtotime( $rs->fields[0]))]++;
00400                         $aTempUser[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00401                     }
00402                     $rs->moveNext();
00403                 }
00404             }
00405 
00406             foreach ( $aTempUser as $key => $value) {
00407                 if (isset($aDataX3[$key]))
00408                     $aDataX3[$key] = $value;
00409             }
00410 
00411             // collects sessions what executed 'tobasket' function
00412             $sSQL = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTime_from and oxtime <= $sTime_to group by oxsessid";
00413             $aTempBasket = array();
00414             $rs = $oDb->execute( $sSQL);
00415             if ($rs != false && $rs->recordCount() > 0) {
00416                 while (!$rs->EOF) {
00417                     if (!$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]]))
00418                         $aTempBasket[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00419                     $rs->moveNext();
00420                 }
00421             }
00422 
00423             foreach ( $aTempBasket as $key => $value) {
00424                 if (isset($aDataX4[$key]))
00425                     $aDataX4[$key] = $value;
00426             }
00427 
00428             // orders made
00429             $sSQL = "select oxorderdate from oxorder where oxorderdate >= $sTime_from and oxorderdate <= $sTime_to order by oxorderdate";
00430             $aTemp = array();
00431             $rs = $oDb->execute( $sSQL);
00432             if ($rs != false && $rs->recordCount() > 0) {
00433                 while (!$rs->EOF) {
00434                     //$aTemp[date( "W", strtotime( $rs->fields[0]))]++;
00435                     $aTemp[oxUtilsDate::getInstance()->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
00436                     $rs->moveNext();
00437                 }
00438             }
00439 
00440             foreach ( $aTemp as $key => $value) {
00441                 if (isset($aDataX5[$key]))
00442                     $aDataX5[$key] = $value;
00443             }
00444 
00445 
00446             header ("Content-type: image/png" );
00447 
00448             // New graph with a drop shadow
00449             $graph = new Graph( max( 800, count( $aDataX) * 80), 600);
00450 
00451             $graph->setBackgroundImage( $myConfig->getAbsAdminImageDir()."/reportbgrnd.jpg", BGIMG_FILLFRAME);
00452 
00453             // Use a "text" X-scale
00454             $graph->setScale("textlin");
00455 
00456             // Label align for X-axis
00457             $graph->xaxis->setLabelAlign('center', 'top', 'right');
00458 
00459             // Label align for Y-axis
00460             $graph->yaxis->setLabelAlign('right', 'bottom');
00461 
00462             $graph->setShadow();
00463             // Description
00464             $graph->xaxis->setTickLabels( $aDataY);
00465 
00466 
00467             // Set title and subtitle
00468             $graph->title->set("Woche");
00469 
00470             // Use built in font
00471             $graph->title->setFont(FF_FONT1, FS_BOLD);
00472 
00473             $aDataFinalX2 = array();
00474             foreach ( $aDataX2 as $dData)
00475                 $aDataFinalX2[] = $dData;
00476 
00477             // Create the bar plot
00478             $bplot2 = new BarPlot( $aDataFinalX2);
00479             $bplot2->setFillColor ("#9966cc");
00480             $bplot2->setLegend("Best.Abbr. in Bezahlmethoden");
00481 
00482             $aDataFinalX3 = array();
00483             foreach ( $aDataX3 as $dData)
00484                 $aDataFinalX3[] = $dData;
00485 
00486             // Create the bar plot
00487             $bplot3 = new BarPlot( $aDataFinalX3);
00488             $bplot3->setFillColor ("#ffcc00");
00489             $bplot3->setLegend("Best.Abbr. in Benutzer");
00490 
00491             $aDataFinalX4 = array();
00492             foreach ( $aDataX4 as $dData)
00493                 $aDataFinalX4[] = $dData;
00494 
00495             // Create the bar plot
00496             $bplot4 = new BarPlot( $aDataFinalX4);
00497             $bplot4->setFillColor ("#6699ff");
00498             $bplot4->setLegend("Best.Abbr. in Warenkorb");
00499 
00500             $aDataFinalX6 = array();
00501             foreach ( $aDataX6 as $dData)
00502                 $aDataFinalX6[] = $dData;
00503 
00504             // Create the bar plot
00505             $bplot6 = new BarPlot( $aDataFinalX6);
00506             $bplot6->setFillColor ("#ff0099");
00507             $bplot6->setLegend("Best.Abbr. in Bestellbestaetigung");
00508 
00509             $aDataFinalX5 = array();
00510             foreach ( $aDataX5 as $dData)
00511                 $aDataFinalX5[] = $dData;
00512 
00513             // Create the bar plot
00514             $bplot5 = new BarPlot( $aDataFinalX5);
00515             $bplot5->setFillColor ("silver");
00516             $bplot5->setLegend("Bestellungen");
00517 
00518             // Create the grouped bar plot
00519             $gbplot = new groupBarPlot (array($bplot4, $bplot3, $bplot2, $bplot6, $bplot5));
00520             $graph->add( $gbplot);
00521 
00522             // Finally output the  image
00523             $graph->stroke();
00524         }
00525     }
00526 }

Generated on Tue Sep 29 16:45:12 2009 for OXID eShop CE by  doxygen 1.5.5