From 5ab4dcaee0e9ffbf4e953896fd7ff51bbb4e098a Mon Sep 17 00:00:00 2001 From: Omar Hussein Date: Mon, 12 Feb 2024 12:14:28 +0000 Subject: [PATCH] COMCL-410: Hide unnecessary fields for non active payment plans that are linked to a payment scheme --- .../PageRun/ContributionRecurViewPage.php | 22 +++++++++---------- js/modifyRecurringContributionPage.js | 6 +++++ 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/CRM/MembershipExtras/Hook/PageRun/ContributionRecurViewPage.php b/CRM/MembershipExtras/Hook/PageRun/ContributionRecurViewPage.php index 669f5c40..fadbf4c2 100644 --- a/CRM/MembershipExtras/Hook/PageRun/ContributionRecurViewPage.php +++ b/CRM/MembershipExtras/Hook/PageRun/ContributionRecurViewPage.php @@ -13,6 +13,7 @@ public function handle($page) { private function modifyPageElements() { $contributionData = $this->page->get_template_vars('recur'); + $isActiveRecurringContribution = $this->isActivePaymentPlan($contributionData['id']); $paymentSchemeSchedule = $this->getFuturePaymentSchemeScheduleIfExist($contributionData['id']); CRM_Core_Resources::singleton()->addScriptFile( @@ -24,17 +25,22 @@ private function modifyPageElements() { CRM_MembershipExtras_ExtensionUtil::SHORT_NAME, [ 'recur_contribution' => $contributionData, + 'is_active_recurring_contribution' => $isActiveRecurringContribution, 'payment_scheme_schedule' => $paymentSchemeSchedule, ] ); } + private function isActivePaymentPlan($recurId) { + return \Civi\Api4\ContributionRecur::get(FALSE) + ->addSelect('payment_plan_extra_attributes.is_active') + ->addWhere('id', '=', $recurId) + ->execute() + ->column('payment_plan_extra_attributes.is_active')[0]; + } + private function getFuturePaymentSchemeScheduleIfExist($recurId) { try { - if (!$this->isActivePaymentPlan($recurId)) { - return NULL; - } - $paymentPlanScheduleGenerator = new CRM_MembershipExtras_Service_PaymentScheme_PaymentPlanScheduleGenerator($recurId); $paymentsSchedule = $paymentPlanScheduleGenerator->generateSchedule(); array_walk($paymentsSchedule['instalments'], function (&$value) { @@ -48,12 +54,4 @@ private function getFuturePaymentSchemeScheduleIfExist($recurId) { } } - private function isActivePaymentPlan($recurId) { - return \Civi\Api4\ContributionRecur::get(FALSE) - ->addSelect('payment_plan_extra_attributes.is_active') - ->addWhere('id', '=', $recurId) - ->execute() - ->column('payment_plan_extra_attributes.is_active')[0]; - } - } diff --git a/js/modifyRecurringContributionPage.js b/js/modifyRecurringContributionPage.js index 16302380..9d2a223a 100644 --- a/js/modifyRecurringContributionPage.js +++ b/js/modifyRecurringContributionPage.js @@ -1,4 +1,5 @@ CRM.$(function () { + const isActiveRecurringContribution = CRM.vars.membershipextras.is_active_recurring_contribution; const paymentSchemeSchedule = CRM.vars.membershipextras.payment_scheme_schedule; hideUnnecessaryPaymentPlanFields(); addFuturePaymentSchemeSchedule(); @@ -28,6 +29,11 @@ CRM.$(function () { return; } + // no point in showing future instalments for inactive payment plans + if (!isActiveRecurringContribution) { + return; + } + var paymentSchemeBlock = 'Future payment scheme Instalments'; paymentSchemeBlock += ''; paymentSchemeBlock += '';