Skip to content

Commit

Permalink
Merge pull request #10367 from JMAConsulting/CRM-20585
Browse files Browse the repository at this point in the history
CRM-20585 -Correct the from and to accounts for deferred revenue transactions
  • Loading branch information
colemanw authored May 22, 2017
2 parents ce10860 + bb40e74 commit cdc6de7
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 3 deletions.
4 changes: 2 additions & 2 deletions CRM/Core/BAO/FinancialTrxn.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Report/Form/Contribute/DeferredRevenue.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1248,4 +1248,60 @@ public function testReplaceContributionTokens() {
<p>Contribution Receive Date: May 11th, 2015</p></br>", $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);
}

}

0 comments on commit cdc6de7

Please sign in to comment.