Skip to content

Commit

Permalink
MAE-1178: Fix pro rata calculation for membership
Browse files Browse the repository at this point in the history
  • Loading branch information
Muhammad Shahrukh committed Sep 6, 2024
1 parent 1275459 commit 7eaa0e0
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions js/paymentPlanToggler.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
*/
function initializeMembershipForm() {
selectPaymentPlanTab(togglerValue);
addContributionAmountHandler();
}

/**
Expand Down Expand Up @@ -302,6 +303,7 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
function setMembershipFormEvents() {
setupPayPlanTogglingEvents();
setScheduleEvents();
contributionAmountHandler();
}

/**
Expand Down Expand Up @@ -474,6 +476,48 @@ function paymentPlanToggler(togglerValue, currencySymbol) {
$(".ui-dialog-buttonset button, .crm-submit-buttons button").prop('disabled',true);
});
}

function contributionAmountHandler() {
let membershipTypeId = $('#membership_type_id_1').val();
let isPriceSet = isPriceSetSelected();
if (membershipTypeId > 0 || isPriceSet) {
if ($('#start_date').val() === '' && $('#join_date').length && $('#join_date').val() !== '') {
$('#start_date').val($('#join_date').val());
$('#start_date').next('.hasDatepicker').datepicker('setDate', new Date($('#join_date').val()));
}
let params = {
start_date: $('#start_date').val(),
payment_method: $('#payment_instrument_id').val(),
schedule: 'monthly',
};
let action = 'getbymembershiptype';

if (isPriceSet) {
let selectedPriceFieldValues = getSelectedPriceFieldValues();
params.price_field_values = {'IN': selectedPriceFieldValues};
action = 'getbypricefieldvalues';
} else {
params.membership_type_id= membershipTypeId;
}

CRM.api3('PaymentSchedule', action, params).then(function (result) {
if (result.is_error === 0) {
updateTotalAmount(result.values.total_amount, isPriceSet);
$('#end_date').val(result.values.membership_end_date);
$('#end_date').next('.hasDatepicker').datepicker('setDate', new Date(result.values.membership_end_date));
} else {
CRM.alert(result.error_message, 'Error', 'error');
}
});
}
}

function addContributionAmountHandler() {
if (($('#membership_type_id_1').length || $('#price_set_id').length) && $('#start_date').length) {
$(document).off( 'change', '#membership_type_id_1, #start_date, #priceset :input');
$(document).on( 'change', '#membership_type_id_1, #start_date, #priceset :input', contributionAmountHandler);
}
}
});

}

0 comments on commit 7eaa0e0

Please sign in to comment.