Skip to content

Commit

Permalink
BTHAB-293: Allow extension to update membership minimum fee
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Nov 30, 2023
1 parent 972fad4 commit e8e2312
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CRM/MembershipExtras/API/PaymentSchedule/Base.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

use CRM_MembershipExtras_ExtensionUtil as E;
use CRM_MembershipExtras_Service_MembershipInstalmentsSchedule as InstalmentSchedule;
use CRM_MembershipExtras_Hook_CustomDispatch_CalculateMembershipMinimumFee as CalculateMembershipMinimumFeeHook;

abstract class CRM_MembershipExtras_API_PaymentSchedule_Base {

Expand Down Expand Up @@ -36,6 +37,8 @@ protected function validateSchedule() {
* @throws CRM_MembershipExtras_Exception_InvalidMembershipTypeInstalment
*/
protected function getInstalments(array $membershipTypes, array $nonMembershipPriceFieldValues = []) {
(new CalculateMembershipMinimumFeeHook($membershipTypes, $this->params['contact_id'] ?? NULL))->dispatch();

$joinDate = !empty($this->params['join_date']) ? new DateTime($this->params['join_date']) : NULL;
$startDate = !empty($this->params['start_date']) ? new DateTime($this->params['start_date']) : NULL;
$endDate = !empty($this->params['end_date']) ? new DateTime($this->params['end_date']) : NULL;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Civi\Core\Event\GenericHookEvent;

/**
* Class CRM_MembershipExtras_Hook_CustomDispatch_CalculateMembershipMinimumFee
*/
class CRM_MembershipExtras_Hook_CustomDispatch_CalculateMembershipMinimumFee {

const NAME = 'me.membership.calculate_minimum_fee';

/**
* Membership Types.
*
* @var array
*/
private array $membershipTypes;

/**
* Contact ID.
*
* @var int
*/
private $contactID;

/**
* CRM_MembershipExtras_Hook_CustomDispatch_CalculateMembershipMinimumFee constructor.
*
* @param array $membershipTypes
* @param int $contactID
*/
public function __construct(&$membershipTypes, $contactID) {
$this->membershipTypes =& $membershipTypes;
$this->contactID = $contactID;
}

/**
* Dispatches event.
*/
public function dispatch() {
$event = GenericHookEvent::create(['contactID' => $this->contactID, 'membershipTypes' => &$this->membershipTypes]);
Civi::dispatcher()->dispatch(self::NAME, $event);
}

}
1 change: 1 addition & 0 deletions CRM/MembershipExtras/Page/InstalmentSchedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ private function assignInstalments() {
$params['payment_method'] = CRM_Utils_Request::retrieve('payment_method', 'Int');
$params['start_date'] = CRM_Utils_Request::retrieve('start_date', 'String');
$params['join_date'] = CRM_Utils_Request::retrieve('join_date', 'String');
$params['contact_id'] = CRM_Utils_Request::retrieve('contact_id', 'Int');

try {
$result = civicrm_api3('PaymentSchedule', $action, $params);
Expand Down
8 changes: 7 additions & 1 deletion js/paymentPlanToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
hideOfflineAutorenewField();
preventPaymentTabLinkAction();
toggleNumOfTermsField();
window.isPaymentPlanTabActive = isPaymentPlanTabActive;
window.isPriceSetSelected = isPriceSetSelected;
window.getSelectedPriceFieldValues = getSelectedPriceFieldValues;
});

/**
Expand Down Expand Up @@ -107,7 +110,7 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
assignFirstContributionReceiveDate();
});

$('#payment_plan_schedule, #payment_instrument_id, #start_date, #end_date').change(() => {
$('#payment_plan_schedule, #payment_instrument_id, #start_date, #end_date, #contact_id').change(() => {
if (!isPaymentPlanTabActive()) {
return;
}
Expand Down Expand Up @@ -171,11 +174,14 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
*/
function generateInstalmentSchedule(isPriceSet, startDate) {
let schedule = $('#payment_plan_schedule').val();
const searchParams = new URLSearchParams(window.location.search);
const cid = $('#contact_id').val() ?? searchParams.get('cid');
let params = {
schedule: schedule,
start_date: startDate,
join_date: $('#join_date').val(),
payment_method: $('#payment_instrument_id').val(),
contact_id: cid,
};
if (isPriceSet) {
let selectedPriceFieldValues = getSelectedPriceFieldValues();
Expand Down

0 comments on commit e8e2312

Please sign in to comment.