From 7b5169d036530c8f8cb86ac709be43ca69948106 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 17 May 2017 06:17:27 +0530 Subject: [PATCH 1/3] CRM-20585, Added unit test to check to and from entries in financial trxn table for deferred revenue ---------------------------------------- * CRM-20585: Correct the from and to accounts for deferred revenue transactions https://issues.civicrm.org/jira/browse/CRM-20585 --- .../CRM/Contribute/BAO/ContributionTest.php | 56 +++++++++++++++++++ 1 file changed, 56 insertions(+) diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index 005a14d8c84f..e485c85e8333 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1248,4 +1248,60 @@ public function testReplaceContributionTokens() {

Contribution Receive Date: May 11th, 2015


", $contributionDetails[$contactId2]['html'], "The html does not match"); } + /** + * Test for contribution with deferred revenue. + */ + public function testContributionWithDeferredRevenue() { + $contactId = $this->individualCreate(); + Civi::settings()->set('deferred_revenue_enabled', TRUE); + $params = array( + 'contact_id' => $contactId, + 'receive_date' => '20120511', + 'total_amount' => 100.00, + 'financial_type_id' => 'Event Fee', + 'trxn_id' => 12345, + 'invoice_id' => 67890, + 'source' => 'SSF', + 'contribution_status_id' => 'Completed', + 'revenue_recognition_date' => date('Ymd', strtotime("+3 month")), + ); + $contribution = $this->callAPISuccess('contribution', 'create', $params); + + $this->callAPISuccessGetCount('EntityFinancialTrxn', array( + 'entity_table' => "civicrm_contribution", + 'entity_id' => $contribution['id'], + ), 2); + + $checkAgainst = array( + 'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee', + 'financial_trxn_id.from_financial_account_id.name' => 'Event Fee', + 'financial_trxn_id' => '2' + ); + $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array( + 'return' => array( + "financial_trxn_id.from_financial_account_id.name", + "financial_trxn_id.to_financial_account_id.name", + "financial_trxn_id", + ), + 'entity_table' => "civicrm_contribution", + 'entity_id' => $contribution['id'], + 'financial_trxn_id.is_payment' => 0, + ), $checkAgainst); + + $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array( + 'entity_table' => "civicrm_financial_item", + 'financial_trxn_id' => $result['financial_trxn_id'], + 'return' => array('entity_id'), + )); + + $checkAgainst = array( + 'financial_account_id.name' => 'Deferred Revenue - Event Fee', + 'id' => $result['entity_id'], + ); + $result = $this->callAPISuccessGetSingle('FinancialItem', array( + 'id' => $result['entity_id'], + 'return' => array("financial_account_id.name"), + ), $checkAgainst); + } + } From f818aed574288827b47f399e39cae85ffa2e4751 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Wed, 17 May 2017 06:53:52 +0530 Subject: [PATCH 2/3] --CRM-20585, fixed financial trxn entry for deferred revenue CRM-20585, fixed jenkins style ---------------------------------------- * CRM-20585: Correct the from and to accounts for deferred revenue transactions https://issues.civicrm.org/jira/browse/CRM-20585 --- CRM/Core/BAO/FinancialTrxn.php | 4 ++-- tests/phpunit/CRM/Contribute/BAO/ContributionTest.php | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CRM/Core/BAO/FinancialTrxn.php b/CRM/Core/BAO/FinancialTrxn.php index 31e04c38d3d0..d09ac055180b 100644 --- a/CRM/Core/BAO/FinancialTrxn.php +++ b/CRM/Core/BAO/FinancialTrxn.php @@ -685,10 +685,10 @@ public static function createDeferredTrxn($lineItems, $contributionDetails, $upd } foreach ($results['values'] as $result) { if ($result['account_relationship'] == $accountRel) { - $trxnParams['to_financial_account_id'] = $result['financial_account_id']; + $trxnParams['from_financial_account_id'] = $result['financial_account_id']; } else { - $trxnParams['from_financial_account_id'] = $result['financial_account_id']; + $trxnParams['to_financial_account_id'] = $result['financial_account_id']; } } foreach ($deferredRevenue['revenue'] as $revenue) { diff --git a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php index e485c85e8333..c2ca619c11e0 100644 --- a/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php +++ b/tests/phpunit/CRM/Contribute/BAO/ContributionTest.php @@ -1275,7 +1275,7 @@ public function testContributionWithDeferredRevenue() { $checkAgainst = array( 'financial_trxn_id.to_financial_account_id.name' => 'Deferred Revenue - Event Fee', 'financial_trxn_id.from_financial_account_id.name' => 'Event Fee', - 'financial_trxn_id' => '2' + 'financial_trxn_id' => '2', ); $result = $this->callAPISuccessGetSingle('EntityFinancialTrxn', array( 'return' => array( From bb40e74438a731ea4cf9cb3978acc9be52212ce8 Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Sun, 21 May 2017 00:14:06 +0530 Subject: [PATCH 3/3] CRM-20585, changed query since to financial accoun holds deferred revenue now ---------------------------------------- * CRM-20585: Correct the from and to accounts for deferred revenue transactions https://issues.civicrm.org/jira/browse/CRM-20585 --- CRM/Report/Form/Contribute/DeferredRevenue.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CRM/Report/Form/Contribute/DeferredRevenue.php b/CRM/Report/Form/Contribute/DeferredRevenue.php index 9447082bc8c5..72f5a5e32474 100644 --- a/CRM/Report/Form/Contribute/DeferredRevenue.php +++ b/CRM/Report/Form/Contribute/DeferredRevenue.php @@ -302,7 +302,7 @@ public function from() { ON entity_financial_trxn_item.entity_id = {$this->_aliases['civicrm_financial_item']}.id AND entity_financial_trxn_item.entity_table = 'civicrm_financial_item' INNER JOIN civicrm_financial_trxn {$this->_aliases['civicrm_financial_trxn_1']} - ON {$this->_aliases['civicrm_financial_trxn_1']}.from_financial_account_id = {$this->_aliases['civicrm_financial_account']}.id + ON {$this->_aliases['civicrm_financial_trxn_1']}.to_financial_account_id = {$this->_aliases['civicrm_financial_account']}.id AND {$this->_aliases['civicrm_financial_trxn_1']}.id = entity_financial_trxn_item.financial_trxn_id INNER JOIN civicrm_entity_financial_trxn financial_trxn_contribution ON financial_trxn_contribution.financial_trxn_id = {$this->_aliases['civicrm_financial_trxn_1']}.id