OXID eShop CE  4.8.12
 All Classes Files Functions Variables Pages
report_canceled_orders.php
Go to the documentation of this file.
1 <?php
2 
3 if ( !class_exists( 'report_canceled_orders' ) ) {
7 class Report_canceled_orders extends report_base
8 {
14  protected $_sThisTemplate = "report_canceled_orders.tpl";
15 
21  public function drawReport()
22  {
23  $oDb = oxDb::getDb();
24 
25  $oSmarty = $this->getSmarty();
26  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_from'] ) ) );
27  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", strtotime( $oSmarty->_tpl_vars['time_to'] ) ) );
28 
29  // collects sessions what executed 'order' function
30  if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
31  return true;
32  }
33 
34  // collects sessions what executed order class
35  if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
36  return true;
37  }
38 
39  // collects sessions what executed payment class
40  if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
41  return true;
42  }
43 
44  // collects sessions what executed 'user' class
45  if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
46  return true;
47  }
48 
49  // collects sessions what executed 'tobasket' function
50  if ( $oDb->getOne( "select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
51  return true;
52  }
53 
54  // orders made
55  if ( $oDb->getOne( "select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo" ) ) {
56  return true;
57  }
58  }
59 
67  protected function _collectSessions( $sQ )
68  {
69  $aTempOrder = array();
70  $rs = oxDb::getDb()->execute( $sQ );
71  if ( $rs != false && $rs->recordCount() > 0) {
72  while ( !$rs->EOF ) {
73  $aTempOrder[$rs->fields[1]] = $rs->fields[0];
74  $rs->moveNext();
75  }
76  }
77  return $aTempOrder;
78  }
79 
90  protected function _collectOrderSessions( $sQ, $aTempOrder, &$aDataX6, $blMonth = true )
91  {
92  // collects sessions what executed order class
93  $aTempExecOrdersSessions = array();
94  $rs = oxDb::getDb()->execute( $sQ );
95  if ($rs != false && $rs->recordCount() > 0) {
96  $iFirstWeekDay = $this->getConfig()->getConfigParam( 'iFirstWeekDay' );
97  while ( !$rs->EOF ) {
98  if ( !isset($aTempOrder[$rs->fields[1]] ) ) {
99  $aTempExecOrdersSessions[$rs->fields[1]] = 1;
100  $sKey = strtotime( $rs->fields[0] );
101  $sKey = $blMonth ? date( "m/Y", $sKey ) : oxRegistry::get("oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey );
102  if ( isset( $aDataX6[$sKey] ) ) {
103  $aDataX6[$sKey]++;
104  }
105 
106  }
107  $rs->moveNext();
108  }
109  }
110 
111  return $aTempExecOrdersSessions;
112  }
113 
125  protected function _collectPaymentSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, &$aDataX2, $blMonth = true )
126  {
127  $aTempPaymentSessions = array();
128  $rs = oxDb::getDb()->execute( $sQ );
129  if ( $rs != false && $rs->recordCount() > 0 ) {
130  $iFirstWeekDay = $this->getConfig()->getConfigParam( 'iFirstWeekDay' );
131  while (!$rs->EOF) {
132  if ( !isset( $aTempOrder[$rs->fields[1]]) && !isset( $aTempExecOrdersSessions[$rs->fields[1]] ) ) {
133  $aTempPaymentSessions[$rs->fields[1]] = 1;
134  $sKey = strtotime( $rs->fields[0] );
135  $sKey = $blMonth ? date( "m/Y", $sKey ) : oxRegistry::get("oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey);
136  if ( isset($aDataX2[$sKey]) ) {
137  $aDataX2[$sKey]++;
138  }
139  }
140  $rs->moveNext();
141  }
142  }
143  return $aTempPaymentSessions;
144  }
145 
158  protected function _collectUserSessionsForVisitorMonth( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, &$aDataX3, $blMonth = true )
159  {
160  $aTempUserSessions = array();
161  $rs = oxDb::getDb()->execute( $sQ );
162  if ($rs != false && $rs->recordCount() > 0) {
163  $iFirstWeekDay = $this->getConfig()->getConfigParam( 'iFirstWeekDay' );
164  while (!$rs->EOF) {
165  if (!isset($aTempOrder[$rs->fields[1]]) && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]])) {
166  $aTempUserSessions[$rs->fields[1]] = 1;
167  $sKey = strtotime( $rs->fields[0] );
168  $sKey = $blMonth ? date( "m/Y", $sKey ) : oxRegistry::get("oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey);
169  if ( isset($aDataX3[$sKey]) ) {
170  $aDataX3[$sKey]++;
171  }
172  }
173  $rs->moveNext();
174  }
175  }
176 
177  return $aTempUserSessions;
178  }
179 
193  protected function _collectToBasketSessions( $sSql, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, &$aDataX4, $blMonth = true )
194  {
195  $rs = oxDb::getDb()->execute( $sSql);
196  if ($rs != false && $rs->recordCount() > 0) {
197  $iFirstWeekDay = $this->getConfig()->getConfigParam( 'iFirstWeekDay' );
198  while (!$rs->EOF) {
199  if ( !$aTempOrder[$rs->fields[1]] && !isset($aTempPaymentSessions[$rs->fields[1]]) && !isset($aTempUserSessions[$rs->fields[1]]) && !isset($aTempExecOrdersSessions[$rs->fields[1]] ) ) {
200  $sKey = strtotime( $rs->fields[0] );
201  $sKey = $blMonth ? date( "m/Y", $sKey ) : oxRegistry::get("oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey );
202  if ( isset($aDataX4[$sKey]) ) {
203  $aDataX4[$sKey]++;
204  }
205  }
206  $rs->moveNext();
207  }
208  }
209  }
210 
220  protected function _collectOrdersMade( $sSql, &$aDataX5, $blMonth = true )
221  {
222  $rs = oxDb::getDb()->execute( $sSql );
223  if ( $rs != false && $rs->recordCount() > 0 ) {
224  $iFirstWeekDay = $this->getConfig()->getConfigParam( 'iFirstWeekDay' );
225  while (!$rs->EOF) {
226  $sKey = strtotime( $rs->fields[0] );
227  $sKey = $blMonth ? date( "m/Y", $sKey ) : oxRegistry::get("oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey );
228  if ( isset($aDataX5[$sKey]) ) {
229  $aDataX5[$sKey]++;
230  }
231  $rs->moveNext();
232  }
233  }
234  }
235 
244  protected function _collectOrdersMadeForVisitorWeek( $sQ, &$aDataX5 )
245  {
246  // orders made
247  $rs = oxDb::getDb()->execute( $sQ );
248  if ( $rs != false && $rs->recordCount() > 0 ) {
249  while ( !$rs->EOF ) {
250  $sKey = oxRegistry::get("oxUtilsDate")->getWeekNumber( oxConfig::getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0] ) );
251  if ( isset( $aDataX5[$sKey] ) ) {
252  $aDataX5[$sKey]++;
253  }
254  $rs->moveNext();
255  }
256  }
257  }
258 
264  public function visitor_month()
265  {
266  $myConfig = $this->getConfig();
267  $oDb = oxDb::getDb();
268 
269  $dTimeTo = strtotime( oxConfig::getParameter( "time_to" ) );
270  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", $dTimeTo ) );
271  $dTimeFrom = mktime( 23, 59, 59, date( "m", $dTimeTo )-12, date( "d", $dTimeTo ), date( "Y", $dTimeTo ) );
272  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", $dTimeFrom ) );
273 
274  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid";
275 
276  $aTemp = array();
277  for ( $i = 1; $i <= 12; $i++) {
278  $aTemp[date( "m/Y", mktime( 23, 59, 59, date( "m", $dTimeFrom ) + $i, date( "d", $dTimeFrom ), date( "Y", $dTimeFrom ) ) ) ] = 0;
279  }
280 
281  $rs = $oDb->execute( $sSQL );
282 
283  if ($rs != false && $rs->recordCount() > 0) {
284  while (!$rs->EOF) {
285  $aTemp[date( "m/Y", strtotime( $rs->fields[0] ) )]++;
286  $rs->moveNext();
287  }
288  }
289 
290  $aDataX = $aTemp;
291  $aDataY = array_keys( $aTemp );
292  $aDataX2 = $aDataX3 = $aDataX4 = $aDataX5 = $aDataX6 = array_fill_keys( $aDataY, 0 );
293 
294  // collects sessions what executed 'order' function
295  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
296  $aTempOrder = $this->_collectSessions( $sQ );
297 
298  // collects sessions what executed order class
299  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
300  $aTempExecOrdersSessions = $this->_collectOrderSessions( $sQ, $aTempOrder, $aDataX6 );
301 
302  // collects sessions what executed payment class
303  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
304  $aTempPaymentSessions = $this->_collectPaymentSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2 );
305 
306  // collects sessions what executed 'user' class
307  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
308  $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2 );
309 
310  // collects sessions what executed 'tobasket' function
311  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
312  $this->_collectToBasketSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4 );
313 
314  // orders made
315  $sQ = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
316  $this->_collectOrdersMade( $sQ, $aDataX5 );
317 
318  header( "Content-type: image/png" );
319 
320  // New graph with a drop shadow
321  $graph = $this->getGraph( 800, 600 );
322 
323  // Description
324  $graph->xaxis->setTickLabels( $aDataY );
325 
326  // Set title and subtitle
327  $graph->title->set( "Monat" );
328 
329  // Create the bar plot
330  $bplot2 = new BarPlot( array_values( $aDataX2 ) );
331  $bplot2->setFillColor( "#9966cc" );
332  $bplot2->setLegend( "Best.Abbr. in Bezahlmethoden" );
333 
334  // Create the bar plot
335  $bplot3 = new BarPlot( array_values( $aDataX3 ) );
336  $bplot3->setFillColor( "#ffcc00" );
337  $bplot3->setLegend( "Best.Abbr. in Benutzer" );
338 
339  // Create the bar plot
340  $bplot4 = new BarPlot( array_values( $aDataX4 ) );
341  $bplot4->setFillColor( "#6699ff" );
342  $bplot4->setLegend( "Best.Abbr. in Warenkorb" );
343 
344  // Create the bar plot
345  $bplot6 = new BarPlot( array_values( $aDataX6 ) );
346  $bplot6->setFillColor( "#ff0099" );
347  $bplot6->setLegend( "Best.Abbr. in Bestellbestaetigung" );
348 
349  // Create the bar plot
350  $bplot5 = new BarPlot( array_values( $aDataX5 ) );
351  $bplot5->setFillColor( "silver" );
352  $bplot5->setLegend( "Bestellungen" );
353 
354  // Create the grouped bar plot
355  $gbplot = new groupBarPlot( array( $bplot4, $bplot3, $bplot2, $bplot6, $bplot5 ) );
356  $graph->add( $gbplot );
357 
358  // Finally output the image
359  $graph->stroke();
360  }
361 
367  public function visitor_week()
368  {
369  $myConfig = $this->getConfig();
370  $oDb = oxDb::getDb();
371 
372  $aDataX = array();
373  $aDataX2 = array();
374  $aDataX3 = array();
375  $aDataX4 = array();
376  $aDataX5 = array();
377  $aDataX6 = array();
378  $aDataY = array();
379 
380  $sTimeTo = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_to" ) ) ) );
381  $sTimeFrom = $oDb->quote( date( "Y-m-d H:i:s", strtotime( oxConfig::getParameter( "time_from")) ) );
382 
383  $sSQL = "select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
384 
385  $aTemp = array();
386  $rs = $oDb->execute( $sSQL);
387 
388  if ($rs != false && $rs->recordCount() > 0) {
389  while (!$rs->EOF) {
390  $aTemp[oxRegistry::get("oxUtilsDate")->getWeekNumber($myConfig->getConfigParam( 'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
391  $rs->moveNext();
392  }
393  }
394 
395  // initializing
396  list( $iFrom, $iTo ) = $this->getWeekRange();
397  for ( $i = $iFrom; $i < $iTo; $i++ ) {
398  $aDataX[$i] = 0;
399  $aDataX2[$i] = 0;
400  $aDataX3[$i] = 0;
401  $aDataX4[$i] = 0;
402  $aDataX5[$i] = 0;
403  $aDataX6[$i] = 0;
404  $aDataY[] = "KW ".$i;
405  }
406 
407  foreach ( $aTemp as $key => $value) {
408  $aDataX[$key] = $value;
409  $aDataX2[$key] = 0;
410  $aDataX3[$key] = 0;
411  $aDataX4[$key] = 0;
412  $aDataX5[$key] = 0;
413  $aDataX6[$key] = 0;
414  $aDataY[] = "KW ".$key;
415  }
416 
417  // collects sessions what executed 'order' function
418  $sQ = "select oxtime, oxsessid FROM `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
419  $aTempOrder = $this->_collectSessions( $sQ );
420 
421  // collects sessions what executed order class
422  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
423  $aTempExecOrdersSessions = $this->_collectOrderSessions( $sQ, $aTempOrder, $aDataX6, false );
424 
425  // collects sessions what executed payment class
426  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
427  $aTempPaymentSessions = $this->_collectPaymentSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aDataX2, false );
428 
429  // collects sessions what executed 'user' class
430  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
431  $aTempUserSessions = $this->_collectUserSessionsForVisitorMonth( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aDataX2, false );
432 
433  // collects sessions what executed 'tobasket' function
434  $sQ = "select oxtime, oxsessid from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid";
435  $this->_collectToBasketSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, $aDataX4, false );
436 
437  // orders made
438  $sQ = "select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
439  $this->_collectOrdersMade( $sQ, $aDataX5, false );
440 
441  header( "Content-type: image/png" );
442 
443  // New graph with a drop shadow
444  $graph = $this->getGraph( max( 800, count( $aDataX ) * 80 ), 600 );
445 
446  // Description
447  $graph->xaxis->setTickLabels( $aDataY );
448 
449  // Set title and subtitle
450  $graph->title->set( "Woche" );
451 
452  // Create the bar plot
453  $bplot2 = new BarPlot( array_values( $aDataX2 ) );
454  $bplot2->setFillColor( "#9966cc" );
455  $bplot2->setLegend( "Best.Abbr. in Bezahlmethoden" );
456 
457  // Create the bar plot
458  $bplot3 = new BarPlot( array_values( $aDataX3 ) );
459  $bplot3->setFillColor( "#ffcc00" );
460  $bplot3->setLegend( "Best.Abbr. in Benutzer" );
461 
462  // Create the bar plot
463  $bplot4 = new BarPlot( array_values( $aDataX4 ) );
464  $bplot4->setFillColor( "#6699ff" );
465  $bplot4->setLegend( "Best.Abbr. in Warenkorb" );
466 
467  // Create the bar plot
468  $bplot6 = new BarPlot( array_values( $aDataX6 ) );
469  $bplot6->setFillColor( "#ff0099" );
470  $bplot6->setLegend( "Best.Abbr. in Bestellbestaetigung" );
471 
472  // Create the bar plot
473  $bplot5 = new BarPlot( array_values( $aDataX5 ) );
474  $bplot5->setFillColor( "silver" );
475  $bplot5->setLegend( "Bestellungen" );
476 
477  // Create the grouped bar plot
478  $gbplot = new groupBarPlot( array( $bplot4, $bplot3, $bplot2, $bplot6, $bplot5 ) );
479  $graph->add( $gbplot );
480 
481  // Finally output the image
482  $graph->stroke();
483  }
484 }
485 }