3 if ( !class_exists(
'report_canceled_orders' ) ) {
7 class Report_canceled_orders
extends report_base
14 protected $_sThisTemplate =
"report_canceled_orders.tpl";
21 public function drawReport()
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'] ) ) );
30 if ( $oDb->getOne(
"select 1 from `oxlogs` where oxclass = 'order' and oxfnc = 'execute' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
35 if ( $oDb->getOne(
"select 1 from `oxlogs` where oxclass = 'order' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
40 if ( $oDb->getOne(
"select 1 from `oxlogs` where oxclass = 'payment' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
45 if ( $oDb->getOne(
"select 1 from `oxlogs` where oxclass = 'user' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
50 if ( $oDb->getOne(
"select 1 from `oxlogs` where oxclass = 'basket' and oxtime >= $sTimeFrom and oxtime <= $sTimeTo" ) ) {
55 if ( $oDb->getOne(
"select 1 from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo" ) ) {
67 protected function _collectSessions( $sQ )
69 $aTempOrder = array();
71 if ( $rs !=
false && $rs->recordCount() > 0) {
73 $aTempOrder[$rs->fields[1]] = $rs->fields[0];
90 protected function _collectOrderSessions( $sQ, $aTempOrder, &$aDataX6, $blMonth =
true )
93 $aTempExecOrdersSessions = array();
95 if ($rs !=
false && $rs->recordCount() > 0) {
96 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay' );
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] ) ) {
111 return $aTempExecOrdersSessions;
125 protected function _collectPaymentSessions( $sQ, $aTempOrder, $aTempExecOrdersSessions, &$aDataX2, $blMonth =
true )
127 $aTempPaymentSessions = array();
129 if ( $rs !=
false && $rs->recordCount() > 0 ) {
130 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay' );
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]) ) {
143 return $aTempPaymentSessions;
158 protected function _collectUserSessionsForVisitorMonth( $sQ, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, &$aDataX3, $blMonth =
true )
160 $aTempUserSessions = array();
162 if ($rs !=
false && $rs->recordCount() > 0) {
163 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay' );
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]) ) {
177 return $aTempUserSessions;
193 protected function _collectToBasketSessions( $sSql, $aTempOrder, $aTempExecOrdersSessions, $aTempPaymentSessions, $aTempUserSessions, &$aDataX4, $blMonth =
true )
196 if ($rs !=
false && $rs->recordCount() > 0) {
197 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay' );
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]) ) {
220 protected function _collectOrdersMade( $sSql, &$aDataX5, $blMonth =
true )
223 if ( $rs !=
false && $rs->recordCount() > 0 ) {
224 $iFirstWeekDay = $this->getConfig()->getConfigParam(
'iFirstWeekDay' );
226 $sKey = strtotime( $rs->fields[0] );
227 $sKey = $blMonth ? date(
"m/Y", $sKey ) :
oxRegistry::get(
"oxUtilsDate")->getWeekNumber( $iFirstWeekDay, $sKey );
228 if ( isset($aDataX5[$sKey]) ) {
244 protected function _collectOrdersMadeForVisitorWeek( $sQ, &$aDataX5 )
248 if ( $rs !=
false && $rs->recordCount() > 0 ) {
249 while ( !$rs->EOF ) {
251 if ( isset( $aDataX5[$sKey] ) ) {
264 public function visitor_month()
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 ) );
274 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= {$sTimeFrom} and oxtime <= {$sTimeTo} group by oxsessid";
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;
281 $rs = $oDb->execute( $sSQL );
283 if ($rs !=
false && $rs->recordCount() > 0) {
285 $aTemp[date(
"m/Y", strtotime( $rs->fields[0] ) )]++;
291 $aDataY = array_keys( $aTemp );
292 $aDataX2 = $aDataX3 = $aDataX4 = $aDataX5 = $aDataX6 = array_fill_keys( $aDataY, 0 );
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 );
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 );
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 );
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 );
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 );
315 $sQ =
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
316 $this->_collectOrdersMade( $sQ, $aDataX5 );
318 header(
"Content-type: image/png" );
321 $graph = $this->getGraph( 800, 600 );
324 $graph->xaxis->setTickLabels( $aDataY );
327 $graph->title->set(
"Monat" );
330 $bplot2 =
new BarPlot( array_values( $aDataX2 ) );
331 $bplot2->setFillColor(
"#9966cc" );
332 $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden" );
335 $bplot3 =
new BarPlot( array_values( $aDataX3 ) );
336 $bplot3->setFillColor(
"#ffcc00" );
337 $bplot3->setLegend(
"Best.Abbr. in Benutzer" );
340 $bplot4 =
new BarPlot( array_values( $aDataX4 ) );
341 $bplot4->setFillColor(
"#6699ff" );
342 $bplot4->setLegend(
"Best.Abbr. in Warenkorb" );
345 $bplot6 =
new BarPlot( array_values( $aDataX6 ) );
346 $bplot6->setFillColor(
"#ff0099" );
347 $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung" );
350 $bplot5 =
new BarPlot( array_values( $aDataX5 ) );
351 $bplot5->setFillColor(
"silver" );
352 $bplot5->setLegend(
"Bestellungen" );
355 $gbplot =
new groupBarPlot( array( $bplot4, $bplot3, $bplot2, $bplot6, $bplot5 ) );
356 $graph->add( $gbplot );
367 public function visitor_week()
383 $sSQL =
"select oxtime, count(*) as nrof from oxlogs where oxtime >= $sTimeFrom and oxtime <= $sTimeTo group by oxsessid order by oxtime";
386 $rs = $oDb->execute( $sSQL);
388 if ($rs !=
false && $rs->recordCount() > 0) {
390 $aTemp[
oxRegistry::get(
"oxUtilsDate")->getWeekNumber(
$myConfig->getConfigParam(
'iFirstWeekDay' ), strtotime( $rs->fields[0]))]++;
396 list( $iFrom, $iTo ) = $this->getWeekRange();
397 for ( $i = $iFrom; $i < $iTo; $i++ ) {
404 $aDataY[] =
"KW ".$i;
407 foreach ( $aTemp as $key => $value) {
408 $aDataX[$key] = $value;
414 $aDataY[] =
"KW ".$key;
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 );
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 );
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 );
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 );
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 );
438 $sQ =
"select oxorderdate from oxorder where oxorderdate >= $sTimeFrom and oxorderdate <= $sTimeTo order by oxorderdate";
439 $this->_collectOrdersMade( $sQ, $aDataX5,
false );
441 header(
"Content-type: image/png" );
444 $graph = $this->getGraph( max( 800, count( $aDataX ) * 80 ), 600 );
447 $graph->xaxis->setTickLabels( $aDataY );
450 $graph->title->set(
"Woche" );
453 $bplot2 =
new BarPlot( array_values( $aDataX2 ) );
454 $bplot2->setFillColor(
"#9966cc" );
455 $bplot2->setLegend(
"Best.Abbr. in Bezahlmethoden" );
458 $bplot3 =
new BarPlot( array_values( $aDataX3 ) );
459 $bplot3->setFillColor(
"#ffcc00" );
460 $bplot3->setLegend(
"Best.Abbr. in Benutzer" );
463 $bplot4 =
new BarPlot( array_values( $aDataX4 ) );
464 $bplot4->setFillColor(
"#6699ff" );
465 $bplot4->setLegend(
"Best.Abbr. in Warenkorb" );
468 $bplot6 =
new BarPlot( array_values( $aDataX6 ) );
469 $bplot6->setFillColor(
"#ff0099" );
470 $bplot6->setLegend(
"Best.Abbr. in Bestellbestaetigung" );
473 $bplot5 =
new BarPlot( array_values( $aDataX5 ) );
474 $bplot5->setFillColor(
"silver" );
475 $bplot5->setLegend(
"Bestellungen" );
478 $gbplot =
new groupBarPlot( array( $bplot4, $bplot3, $bplot2, $bplot6, $bplot5 ) );
479 $graph->add( $gbplot );