From 49bbb50ecba6e430a00abdb15520bbfdbcb4aac0 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 f227519e7f..add9aacac3 100644 --- a/CRM/Member/BAO/MembershipType.php +++ b/CRM/Member/BAO/MembershipType.php @@ -819,6 +819,7 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { 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 @@ class CRM_Member_BAO_MembershipType extends CRM_Member_DAO_MembershipType { 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_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 f722f117e0..08b4942939 100644 --- a/tests/phpunit/CRM/Member/BAO/MembershipTest.php +++ b/tests/phpunit/CRM/Member/BAO/MembershipTest.php @@ -795,6 +795,8 @@ class CRM_Member_BAO_MembershipTest extends CiviUnitTestCase { 'period_type' => 'rolling', 'visibility' => 'Public', 'weight' => '1', + 'tax_rate' => 0.0, + 'minimum_fee_with_tax' => 100.0, ], $values[1]); } -- 2.25.1