/** * Generate the KPI table for orders, visitors, conversion rate etc. * Will use the time period from the request if one exists (GET or COOKIE) * or falls back to the last week. * * @return string The generated HTML for the performance indicators table. */ public function GeneratePerformanceIndicatorsTable() { if (!$this->auth->HasPermission(AUTH_Statistics_Overview)) { return false; } // If we don't have a period coming in via the URL, use the default if (!isset($_GET['period'])) { // Is it set in a cookie? if (isset($_COOKIE['DashboardPerformanceIndicatorsPeriod'])) { $period = $_COOKIE['DashboardPerformanceIndicatorsPeriod']; } else { $period = 'week'; } } else { $period = $_GET['period']; } // Determine for which dates we need to fetch the statistics switch ($period) { case 'week': $lastPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d') - 13, isc_date('y')); $thisPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d') - 6, isc_date('y')); break; case 'month': $lastPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m') - 2, isc_date('d'), isc_date('y')); $thisPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m') - 1, isc_date('d'), isc_date('y')); break; case 'year': $lastPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d'), isc_date('y') - 2); $thisPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d'), isc_date('y') - 1); break; default: $period = 'day'; $lastPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d') - 1, isc_date('y')); $thisPeriodFrom = isc_gmmktime(0, 0, 0, isc_date('m'), isc_date('d'), isc_date('y')); } $this->template->Assign('LastPeriodHeader', GetLang('Last' . ucfirst($period))); $this->template->Assign('ThisPeriodHeader', GetLang('This' . ucfirst($period))); // Run up until 1 second before the current period. Subtracting 1 second allows us to generate displayable dates for the period. $lastPeriodTo = $thisPeriodFrom - 1; if ($period != 'day') { $this->template->Assign('LastPeriodDateRange', CDate($lastPeriodFrom) . ' - ' . CDate($lastPeriodTo)); $this->template->Assign('ThisPeriodDateRange', CDate($thisPeriodFrom) . ' - ' . CDate(time())); } else { $this->template->Assign('LastPeriodDateRange', CDate($lastPeriodFrom)); $this->template->Assign('ThisPeriodDateRange', CDate($thisPeriodFrom)); } // Calculate the number of orders and the total revenue $vendorAdd = ''; if ($this->auth->GetVendorId()) { $vendorAdd .= " AND ordvendorid='" . $this->auth->GetVendorId() . "'"; } $query = "\n\t\t\tSELECT SUM(ordtotalamount) AS totalrevenue, COUNT(orderid) AS numorders\n\t\t\tFROM [|PREFIX|]orders\n\t\t\tWHERE ordstatus IN (" . implode(',', GetPaidOrderStatusArray()) . ") AND orddate >= '" . $lastPeriodFrom . "' AND orddate <= '" . $lastPeriodTo . "' " . $vendorAdd . "\n\t\t"; $result = $this->db->Query($query); $lastPeriodOrderStats = $this->db->Fetch($result); $query = "\n\t\t\tSELECT SUM(ordtotalamount) AS totalrevenue, COUNT(orderid) AS numorders\n\t\t\tFROM [|PREFIX|]orders\n\t\t\tWHERE ordstatus IN (" . implode(',', GetPaidOrderStatusArray()) . ") AND orddate >= '" . $thisPeriodFrom . "' " . $vendorAdd . "\n\t\t"; $result = $this->db->Query($query); $thisPeriodOrderStats = $this->db->Fetch($result); // Calculate the number of visitors if (!$this->auth->GetVendorId()) { $query = "\n\t\t\t\tSELECT SUM(numuniques)\n\t\t\t\tFROM [|PREFIX|]unique_visitors\n\t\t\t\tWHERE datestamp >= '" . $lastPeriodFrom . "' AND datestamp <= '" . $lastPeriodTo . "'\n\t\t\t"; $lastPeriodVisitorStats = $this->db->FetchOne($query); $query = "\n\t\t\t\tSELECT SUM(numuniques)\n\t\t\t\tFROM [|PREFIX|]unique_visitors\n\t\t\t\tWHERE datestamp >= '" . $thisPeriodFrom . "'\n\t\t\t"; $thisPeriodVisitorStats = $this->db->FetchOne($query); // Calculate the percentage change in visitors between the last period and the current period $visitorChange = $thisPeriodVisitorStats - $lastPeriodVisitorStats; $prefix = ''; if ($visitorChange == 0) { $visitorChangePercent = 0; } else { if ($lastPeriodVisitorStats > 0) { $visitorChangePercent = round($visitorChange / $lastPeriodVisitorStats * 100, 2); } else { $visitorChangePercent = 100; } } if ($visitorChangePercent > 0) { $prefix = '+'; $this->template->Assign('NumVisitorsChangeClass', 'Positive'); } else { if ($visitorChangePercent < 0) { $this->template->Assign('NumVisitorsChangeClass', 'Negative'); } } $visitorChangePercent = $prefix . number_format($visitorChangePercent, 2) . '%'; $this->template->Assign('LastPeriodNumVisitors', number_format($lastPeriodVisitorStats)); $this->template->Assign('ThisPeriodNumVisitors', number_format($thisPeriodVisitorStats)); $this->template->Assign('NumVisitorsChange', $visitorChangePercent); $lastConversion = 0; if ($lastPeriodVisitorStats > 0) { $lastConversion = $lastPeriodOrderStats['numorders'] / $lastPeriodVisitorStats * 100; } $this->template->Assign('LastPeriodConversionRate', number_format(round($lastConversion, 2), 2)); $thisConversion = 0; if ($thisPeriodVisitorStats > 0) { $thisConversion = $thisPeriodOrderStats['numorders'] / $thisPeriodVisitorStats * 100; } $this->template->Assign('ThisPeriodConversionRate', number_format(round($thisConversion, 2), 2)); // Calculate the difference between the two conversion dates to get the change $conversionChangePercent = $thisConversion - $lastConversion; $prefix = ''; if ($conversionChangePercent > 0) { $prefix = '+'; $this->template->Assign('ConversionChangeClass', 'Positive'); } else { if ($conversionChangePercent < 0) { $this->template->Assign('ConversionChangeClass', 'Negative'); } } $conversionChangePercent = $prefix . number_format($conversionChangePercent, 2) . '%'; $this->template->Assign('ConversionChange', $conversionChangePercent); } else { $this->template->Assign('HideConversionRate', 'display: none'); $this->template->Assign('HideVisitorStats', 'display: none'); } // Calculate the percentage change in revenue between the last period and the current period $revenueChange = $thisPeriodOrderStats['totalrevenue'] - $lastPeriodOrderStats['totalrevenue']; $prefix = ''; if ($revenueChange == 0) { $revenueChangePercent = 0; } else { if ($lastPeriodOrderStats['totalrevenue'] > 0) { $revenueChangePercent = round($revenueChange / $lastPeriodOrderStats['totalrevenue'] * 100, 2); } else { $revenueChangePercent = 100; } } if ($revenueChangePercent > 0) { $prefix = '+'; $this->template->Assign('TotalRevenueChangeClass', 'Positive'); } else { if ($revenueChangePercent < 0) { $this->template->Assign('TotalRevenueChangeClass', 'Negative'); } } $revenueChangePercent = $prefix . number_format($revenueChangePercent, 2) . '%'; // Calculate the percentage change in the number of orders in the last period and the current period $numOrdersChange = $thisPeriodOrderStats['numorders'] - $lastPeriodOrderStats['numorders']; $prefix = ''; if ($numOrdersChange == 0) { $numOrdersChangePercent = 0; } else { if ($lastPeriodOrderStats['numorders'] > 0) { $numOrdersChangePercent = round($numOrdersChange / $lastPeriodOrderStats['numorders'] * 100, 2); } else { $numOrdersChangePercent = 100; } } if ($numOrdersChangePercent > 0) { $prefix = '+'; $this->template->Assign('NumOrdersChangeClass', 'Positive'); } else { if ($numOrdersChangePercent < 0) { $this->template->Assign('NumOrdersChangeClass', 'Negative'); } } $numOrdersChangePercent = $prefix . number_format($numOrdersChangePercent, 2) . '%'; $this->template->Assign('LastPeriodRevenue', FormatPrice($lastPeriodOrderStats['totalrevenue'])); $this->template->Assign('LastPeriodNumOrders', number_format($lastPeriodOrderStats['numorders'])); $this->template->Assign('ThisPeriodRevenue', FormatPrice($thisPeriodOrderStats['totalrevenue'])); $this->template->Assign('ThisPeriodNumOrders', number_format($thisPeriodOrderStats['numorders'])); $this->template->Assign('TotalRevenueChange', $revenueChangePercent); $this->template->Assign('NumOrdersChange', $numOrdersChangePercent); // If they've just changed periods, store it in a cookie if (isset($_GET['period'])) { isc_setcookie('DashboardPerformanceIndicatorsPeriod', $period); } return $this->template->GetSnippet('DashboardPerformanceIndicators'); }
// Do we need to show the cart contents side box at all? if(!isset($_SESSION['QUOTE']) || getCustomerQuote()->getNumItems() == 0) { $GLOBALS['HidePanels'][] = "SideCartContents"; } $GLOBALS['ISC_CLASS_TEMPLATE'] = new TEMPLATE("ISC_LANG"); $GLOBALS['ISC_CLASS_TEMPLATE']->FrontEnd(); if(isset($_GET['fullSite'])) { if($_GET['fullSite'] > 0) { isc_setcookie('mobileViewFullSite', 1); } else { isc_setcookie('mobileViewFullSite', 0); $_COOKIE['mobileViewFullSite'] = 0; } } // Is this a mobile device? if(canViewMobileSite() && empty($_GET['fullSite']) && empty($_COOKIE['mobileViewFullSite']) ) { define('IS_MOBILE', true); $GLOBALS['ISC_CLASS_TEMPLATE']->setIsMobileDevice(true); // Reload the template configuration based on the mobile template $GLOBALS['TPL_CFG'] = $GLOBALS['ISC_CLASS_TEMPLATE']->getTemplateConfiguration(); } $GLOBALS['ISC_CLASS_TEMPLATE']->SetTemplateBase(ISC_BASE_PATH . "/templates"); $GLOBALS['ISC_CLASS_TEMPLATE']->panelPHPDir = ISC_BASE_PATH . "/includes/display/";