function commerce_reports_geckoboard_sales_monthly in Commerce Reporting 7.4
Same name and namespace in other branches
- 7.3 modules/geckoboard/commerce_reports_geckoboard.module \commerce_reports_geckoboard_sales_monthly()
Geckoboard hook: Monthly sales
1 string reference to 'commerce_reports_geckoboard_sales_monthly'
- commerce_reports_geckoboard_geckoboardapi in modules/
geckoboard/ commerce_reports_geckoboard.module - Implements hook_geckoboard().
File
- modules/
geckoboard/ commerce_reports_geckoboard.module, line 123
Code
function commerce_reports_geckoboard_sales_monthly() {
$basequery = db_select('commerce_line_item', 'li')
->fields('li', array(
'line_item_id',
))
->condition('li.type', 'product')
->condition('o.status', array(
'pending',
'processing',
'completed',
));
$basequery
->addExpression('SUM(quantity)', 'quantity');
$basequery
->join('commerce_order', 'o', 'o.order_id = li.order_id');
// This month
$thismonth = mktime(0, 0, 0, date('n'), 1);
$thismonthend = mktime(0, 0, 0, date('n') + 1, 1);
$query = clone $basequery;
$query
->condition('o.created', $thismonth, '>=')
->condition('o.created', $thismonthend, '<');
$result = $query
->execute()
->fetchField(1);
$thismonth = (int) $result;
// Last month
$lastmonth = mktime(0, 0, 0, date('n') - 1, 1);
$lastmonthend = mktime(0, 0, 0, date('n'), 1);
$query = clone $basequery;
$query
->condition('o.created', $lastmonth, '>=')
->condition('o.created', $lastmonthend, '<');
$result = $query
->execute()
->fetchField(1);
$lastmonth = (int) $result;
$lastmonth_text = t('@units last month', array(
'@units' => $lastmonth,
));
return _commerce_reports_geckoboard_texthelper($thismonth, $lastmonth_text);
}