function commerce_reports_sales in Commerce Reporting 7.3
Same name and namespace in other branches
- 7.4 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().
5 string references to 'commerce_reports_sales'
- CommerceReportsSalesTestCase::_getDates in tests/
commerce_reports.test - CommerceReportsSalesTestCase::_test in tests/
commerce_reports.test - commerce_reports_block_view in ./
commerce_reports.module - Implements hook_block_view().
- commerce_reports_commerce_reports_dashboard in ./
commerce_reports.module - Implements hook_commerce_reports_dashboard().
- commerce_reports_views_default_views in includes/
views/ commerce_reports.views_default.inc - Implements hook_views_default_views().
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'),
),
),
);
}