Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

COMCL-410: Hide unnecessary fields for non active payment plans that are linked to a payment scheme #520

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 10 additions & 12 deletions CRM/MembershipExtras/Hook/PageRun/ContributionRecurViewPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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) {
Expand All @@ -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];
}

}
6 changes: 6 additions & 0 deletions js/modifyRecurringContributionPage.js
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -28,6 +29,11 @@ CRM.$(function () {
return;
}

// no point in showing future instalments for inactive payment plans
if (!isActiveRecurringContribution) {
return;
}

var paymentSchemeBlock = '<tr><td class="label">Future payment scheme Instalments</td><td>';
paymentSchemeBlock += '<table>';
paymentSchemeBlock += '<thead>';
Expand Down
Loading