Skip to content

Commit

Permalink
Add tax rates to metadata
Browse files Browse the repository at this point in the history
This doesn't do anything by itself but it lays the foundation for a solid fix for

#15895 - ie by having minimum_fee_with_tax as part of our
generally available metadata we get out of all the complexity of doing this in the js layer - which is
what is driving that bug
  • Loading branch information
eileenmcnaughton committed Jan 9, 2020
1 parent 91e3e6b commit 42da17f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
7 changes: 7 additions & 0 deletions CRM/Member/BAO/MembershipType.php
Original file line number Diff line number Diff line change
Expand Up @@ -819,6 +819,7 @@ public static function updateAllPriceFieldValue($membershipTypeId, $params) {
public static function getAllMembershipTypes() {
if (!Civi::cache('metadata')->has(__CLASS__ . __FUNCTION__)) {
$types = civicrm_api3('MembershipType', 'get', ['options' => ['limit' => 0, 'sort' => 'weight']])['values'];
$taxRates = CRM_Core_PseudoConstant::getTaxRates();
$keys = ['description', 'relationship_type_id', 'relationship_direction', 'max_related'];
// In order to avoid down-stream e-notices we undo api v3 filtering of NULL values. This is covered
// in Unit tests & ideally we might switch to apiv4 but I would argue we should build caching
Expand All @@ -832,6 +833,12 @@ public static function getAllMembershipTypes() {
if (isset($type['contribution_type_id'])) {
unset($types[$id]['contribution_type_id']);
}
$types[$id]['tax_rate'] = (float) ($taxRates[$type['financial_type_id']] ?? 0.0);
$multiplier = 1;
if ($types[$id]['tax_git rate'] !== 0.0) {
$multiplier += ($types[$id]['tax_rate'] / 100);
}
$types[$id]['minimum_fee_with_tax'] = (float) $types[$id]['minimum_fee'] * $multiplier;
}
Civi::cache('metadata')->set(__CLASS__ . __FUNCTION__, $types);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/CRM/Member/BAO/MembershipTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -795,6 +795,8 @@ public function testBuildMembershipTypeValues() {
'period_type' => 'rolling',
'visibility' => 'Public',
'weight' => '1',
'tax_rate' => 0.0,
'minimum_fee_with_tax' => 100.0,
], $values[1]);
}

Expand Down

0 comments on commit 42da17f

Please sign in to comment.