You are here

function commerce_reports_sales in Commerce Reporting 7.4

Same name and namespace in other branches
  1. 7.3 commerce_reports.blocks.inc \commerce_reports_sales()

Implementation of table showing sales overview.

1 call to commerce_reports_sales()
commerce_reports_block_view in ./commerce_reports.module
Implements hook_block_view().
7 string references to 'commerce_reports_sales'
CommerceReportsSalesTestCase::_getDates in src/Tests/CommerceReportsSalesTestCase.php
CommerceReportsSalesTestCase::_test in src/Tests/CommerceReportsSalesTestCase.php
CommerceReportsViewsExportTestCase::testExportRespectsFilters in src/Tests/CommerceReportsViewsExportTestCase.php
CommerceReportsViewsExportTestCase::testSalesViewsDataExport in src/Tests/CommerceReportsViewsExportTestCase.php
commerce_reports_block_view in ./commerce_reports.module
Implements hook_block_view().

... See full list

File

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

Code

function commerce_reports_sales() {
  $sales = array();
  if ($timestamp = strtotime('first day of this month midnight')) {
    $passed_days = format_date(REQUEST_TIME, 'custom', 'j');
    $month_raw = commerce_reports_sales_data($timestamp, $passed_days);
    $month = commerce_reports_sales_format($month_raw, t('Daily average for @month', array(
      '@month' => format_date($timestamp, 'custom', 'F o'),
    )));
    $sales = array_merge($sales, $month);
    $total_days = format_date($timestamp, 'custom', 't');
    $projected_raw = array();
    foreach ($month_raw as $currency => $row) {
      $projected_raw[$currency] = array(
        'count' => round($row['count'] * $total_days, 2),
        'sum' => round($row['sum'] * $total_days),
      );
    }
    $projected = commerce_reports_sales_format($projected_raw, t('Projected totals for @month', array(
      '@month' => format_date($timestamp, 'custom', 'F o'),
    )));
    $sales = array_merge($sales, $projected);
  }
  return array(
    '#theme' => 'table',
    '#rows' => $sales,
    '#header' => array(
      array(
        'data' => t('Sales Data'),
      ),
      array(
        'data' => t('Number of Orders'),
      ),
      array(
        'data' => t('Revenue'),
      ),
    ),
  );
}