From: eileen Date: Thu, 11 Feb 2016 03:07:10 +0000 (+1300) Subject: CRM-18018 fix lybunt report regression X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=3fd9a92abe8e5b32d326d3d5a281ce484cc24777;p=civicrm-core.git CRM-18018 fix lybunt report regression --- diff --git a/CRM/Report/Form/Contribute/Lybunt.php b/CRM/Report/Form/Contribute/Lybunt.php index ccb859aec5..e8aa289650 100644 --- a/CRM/Report/Form/Contribute/Lybunt.php +++ b/CRM/Report/Form/Contribute/Lybunt.php @@ -213,6 +213,7 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { 'title' => ts('Last Year Total'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_MONEY, + 'required' => TRUE, ), 'civicrm_life_time_total' => array( 'title' => ts('Lifetime Total'), @@ -714,26 +715,6 @@ class CRM_Report_Form_Contribute_Lybunt extends CRM_Report_Form { $this->sqlArray = array(); } - /** - * Are we ordering by the latest year total. - * - * If we are we need to drop the rollup to do the ordering. - * - * Without bigger changes we can't get the lifetime total and order by - * the latest year total in the same query. - * - * @return bool - */ - public function isOrderByLastYearTotal() { - $this->storeOrderByArray(); - foreach ($this->_orderByArray as $orderBy) { - if (stristr($orderBy, 'contribution_civireport.total_amount')) { - return TRUE; - } - } - return FALSE; - } - /** * @param $rows */ diff --git a/tests/phpunit/api/v3/ReportTemplateTest.php b/tests/phpunit/api/v3/ReportTemplateTest.php index e7f09ffe48..a617455584 100644 --- a/tests/phpunit/api/v3/ReportTemplateTest.php +++ b/tests/phpunit/api/v3/ReportTemplateTest.php @@ -247,4 +247,30 @@ class api_v3_ReportTemplateTest extends CiviUnitTestCase { $this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); } + /** + * Test Lybunt report to check basic inclusion of a contact who gave in the year before the chosen year. + */ + public function testLybuntReportWithFYDataOrderByLastYearAmount() { + $inInd = $this->individualCreate(); + $outInd = $this->individualCreate(); + $this->contributionCreate(array('contact_id' => $inInd, 'receive_date' => '2014-10-01')); + $this->contributionCreate(array('contact_id' => $outInd, 'receive_date' => '2015-03-01', 'trxn_id' => NULL, 'invoice_id' => NULL)); + $this->callAPISuccess('Setting', 'create', array('fiscalYearStart' => array('M' => 7, 'd' => 1))); + $rows = $this->callAPISuccess('report_template', 'getrows', array( + 'report_id' => 'contribute/lybunt', + 'yid_value' => 2015, + 'yid_op' => 'fiscal', + 'options' => array('metadata' => array('sql')), + 'fields' => array('first_name'), + 'order_bys' => array( + array( + 'column' => 'last_year_total_amount', + 'order' => 'ASC', + ), + ), + )); + + $this->assertEquals(2, $rows['count'], "Report failed - the sql used to generate the results was " . print_r($rows['metadata']['sql'], TRUE)); + } + }