You are here

function commerce_reports_sales_data in Commerce Reporting 7.3

Same name and namespace in other branches
  1. 7.4 commerce_reports.blocks.inc \commerce_reports_sales_data()

Helper function that retrieves sales data from a certain starting point.

1 call to commerce_reports_sales_data()
commerce_reports_sales in ./commerce_reports.blocks.inc
Implementation of table showing sales overview.

File

./commerce_reports.blocks.inc, line 43
Provides all statistics and other features that are not powered by Views.

Code

function commerce_reports_sales_data($start = 0, $time_periods = 1) {
  $sales = array();
  $result = db_query('SELECT SUM(amount) AS sum, AVG(amount) AS average, COUNT(*) AS count, currency_code FROM {commerce_payment_transaction} cpt WHERE created >= :start  GROUP by currency_code', array(
    ':start' => $start,
  ));
  while ($row = $result
    ->fetchAssoc()) {
    $currency = $row['currency_code'];
    unset($row['currency_code']);
    $sales[$currency] = $row;
    $sales[$currency]['count'] = round($sales[$currency]['count'] / $time_periods, 2);
    $sales[$currency]['sum'] = round($sales[$currency]['sum'] / $time_periods);
  }
  return $sales;
}