From 42da17f39125ae6e40ebf1a2efe71ba594724e27 Mon Sep 17 00:00:00 2001 From: eileen Date: Fri, 3 Jan 2020 11:03:04 +1300 Subject: [PATCH] Add tax rates to metadata This doesn't do anything by itself but it lays the foundation for a solid fix for https://github.com/civicrm/civicrm-core/pull/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 --- CRM/Member/BAO/MembershipType.php | 7 +++++++ tests/phpunit/CRM/Member/BAO/MembershipTest.php | 2 ++ 2 files changed, 9 insertions(+) diff --git a/CRM/Member/BAO/MembershipType.php b/CRM/Member/BAO/MembershipType.php index f227519e7fec..61a6ad9c5c3b 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -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 @@ -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); } diff --git a/tests/phpunit/CRM/Member/BAO/MembershipTest.php b/tests/phpunit/CRM/Member/BAO/MembershipTest.php index f722f117e06d..08b494293962 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -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]); }