Skip to content

Commit

Permalink
CRM-21026 fix issue with ContributionCount not including disabled fin…
Browse files Browse the repository at this point in the history
…ancialtypes
  • Loading branch information
seamuslee001 committed Aug 6, 2017
1 parent a41914a commit 614676d
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 7 deletions.
6 changes: 3 additions & 3 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -604,8 +604,8 @@ public static function create(&$params, $ids = array()) {
if ($retrieveRequired == 1) {
$contribution->find(TRUE);
}
$contributionTypes = CRM_Contribute_PseudoConstant::financialType();
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionTypes[$contribution->financial_type_id] . ')';
$contributionType = CRM_Contribute_PseudoConstant::financialType($contribution->financial_type_id);
$title = CRM_Contact_BAO_Contact::displayName($contribution->contact_id) . ' - (' . CRM_Utils_Money::format($contribution->total_amount, $contribution->currency) . ' ' . ' - ' . $contributionType . ')';

$recentOther = array();
if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
Expand Down Expand Up @@ -2132,7 +2132,7 @@ public static function contributionCount($contactId, $includeSoftCredit = TRUE)
if (!$contactId) {
return 0;
}
CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
CRM_Financial_BAO_FinancialType::getAllAvailableFinancialTypes($financialTypes);
$additionalWhere = " AND contribution.financial_type_id IN (0)";
$liWhere = " AND i.financial_type_id IN (0)";
if (!empty($financialTypes)) {
Expand Down
8 changes: 6 additions & 2 deletions CRM/Contribute/PseudoConstant.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,17 @@ class CRM_Contribute_PseudoConstant extends CRM_Core_PseudoConstant {
*
*
* @param int $id
* @param bool $includeDisabled
*
* @return array
* array reference of all financial types if any
*/
public static function &financialType($id = NULL) {
public static function &financialType($id = NULL, $includeDisabled = FALSE) {
if (!self::$financialType) {
$condition = " is_active = 1 ";
$condition = "";
if (!$includeDisabled) {
$condition = " is_active = 1 ";
}
CRM_Core_PseudoConstant::populate(
self::$financialType,
'CRM_Financial_DAO_FinancialType',
Expand Down
40 changes: 38 additions & 2 deletions CRM/Financial/BAO/FinancialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,40 @@ public static function permissionedFinancialTypes(&$permissions, $descriptions)
}
}

/**
* CRM-21206
* Wrapper aroung getAvaliableFinancialTypes to get all including disabled FinancialTypes
* @param array $financialTypes
* (reference ) an array of financial types
* @param int|string $action
* the type of action, can be add, view, edit, delete
* @param bool $resetCache
* load values from static cache
*
* @return array
*/
public static function getAllAvailableFinancialTypes(&$financialTypes = NULL, $action = CRM_Core_Action::VIEW, $resetCache = FALSE) {
self::getAvailableFinancialTypes($financialTypes, $action, $resetCache, TRUE);
return $financialTypes;
}

/**
* CRM-21206
* Wrapper aroung getAvaliableFinancialTypes to get all FinancialTypes Excluding Disabled ones.
* @param array $financialTypes
* (reference ) an array of financial types
* @param int|string $action
* the type of action, can be add, view, edit, delete
* @param bool $resetCache
* load values from static cache
*
* @return array
*/
public static function getAllEnabledAvailableFinancialTypes(&$financialTypes = NULL, $action = CRM_Core_Action::VIEW, $resetCache = FALSE) {
self::getAvailableFinancialTypes($financialTypes, $action, $resetCache);
return $financialTypes;
}

/**
* Get available Financial Types.
*
Expand All @@ -254,12 +288,14 @@ public static function permissionedFinancialTypes(&$permissions, $descriptions)
* the type of action, can be add, view, edit, delete
* @param bool $resetCache
* load values from static cache
* @param bool $includeDisabled
* Whether we should load in disabled FinancialTypes or Not
*
* @return array
*/
public static function getAvailableFinancialTypes(&$financialTypes = NULL, $action = CRM_Core_Action::VIEW, $resetCache = FALSE) {
public static function getAvailableFinancialTypes(&$financialTypes = NULL, $action = CRM_Core_Action::VIEW, $resetCache = FALSE, $includeDisabled = FALSE) {
if (empty($financialTypes)) {
$financialTypes = CRM_Contribute_PseudoConstant::financialType();
$financialTypes = CRM_Contribute_PseudoConstant::financialType(NULL, $includeDisabled);
}
if (!self::isACLFinancialTypeStatus()) {
return $financialTypes;
Expand Down
36 changes: 36 additions & 0 deletions tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,42 @@ public function testCreateWithCustomData() {
$this->assertEquals($contactId, $contribution->contact_id, 'Check for contact id for Conribution.');
}

/**
* CRM-21026 Test ContributionCount after contribution created with disabled FT
*/
public function testContributionCountDisabledFinancialType() {
$contactId = $this->individualCreate();
$financialType = array(
'name' => 'grassvariety1' . substr(sha1(rand()), 0, 7),
'is_reserved' => 0,
'is_active' => 0,
);
$finType = $this->callAPISuccess('financial_type', 'create', $financialType);
$params = array(
'contact_id' => $contactId,
'currency' => 'USD',
'financial_type_id' => $finType['id'],
'contribution_status_id' => 1,
'payment_instrument_id' => 1,
'source' => 'STUDENT',
'receive_date' => '20080522000000',
'receipt_date' => '20080522000000',
'id' => NULL,
'non_deductible_amount' => 0.00,
'total_amount' => 200.00,
'fee_amount' => 5,
'net_amount' => 195,
'trxn_id' => '22ereerwww322323',
'invoice_id' => '22ed39c9e9ee6ef6031621ce0eafe6da70',
'thankyou_date' => '20080522',
);
$contribution = CRM_Contribute_BAO_Contribution::create($params);
CRM_Contribute_PseudoConstant::flush('financialType');
$testResult = $this->callAPISuccess('financial_type', 'create', array('is_active' => 0, 'id' => $finType['id']));
$contributionCount = CRM_Contribute_BAO_Contribution::contributionCount($contactId);
$this->assertEquals(1, $contributionCount);
}

/**
* DeleteContribution() method
*/
Expand Down

0 comments on commit 614676d

Please sign in to comment.