Skip to content

Commit

Permalink
BTHAMM-31: Prevent resetting contribution total amoun to zero
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed Aug 16, 2024
1 parent 922180e commit 7a2aab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 3 additions & 0 deletions js/modifyContributionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const totalChanged = new CustomEvent("totalChanged", {});
const recordPaymentAmount = document.querySelector("input[name=fe_record_payment_amount]");
$('#total_amount').on("change", function() {
recordPaymentAmount.value = Number($('#total_amount').val()).toFixed(2);
if ($('#total_amount').val() == 0 && $('#line-total').data('raw-total') > 0) {
return
}
recordPaymentAmount.dispatchEvent(totalChanged)
});

Expand Down
12 changes: 9 additions & 3 deletions templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
CRM.$(function($) {
const submittedRows = $.parseJSON('{/literal}{$lineItemSubmitted}{literal}');
const action = '{/literal}{$action}{literal}';
const nonEmtyFinancialTypes = $('table#info select[id^="item_financial_type_id_"]').filter(function() {
return this.value;
});
isNotQuickConfig = '{/literal}{$pricesetFieldsCount}{literal}'
const isEmptyPriceSet = !$('#price_set_id').length || $('#price_set_id').val() === ''

Expand Down Expand Up @@ -42,8 +45,11 @@
$('#selectPriceSet').prepend( `<div id="lineItemSwitch" class="crm-hover-button">OR <a href="#">Switch back to using line items</a></div>`)
$('#lineItemSwitch').css('display', 'block').on('click', () => $('#price_set_id').val('').change())
if ((isEmptyPriceSet) && submittedRows.length <= 0) {
$('#add-items').click()
const hasValues = nonEmtyFinancialTypes.each(function() {
$(this).val(this.value).trigger('change');
}).length > 0;
if (!hasValues && isEmptyPriceSet && submittedRows.length <= 0) {
$('#add-items').click();
}
toggleLineItemOrPricesetFields(isEmptyPriceSet);

Expand All @@ -58,7 +64,7 @@
$('#totalAmountORPriceSet, #price_set_id').show();
}
});
}, 100);
}, 500);

const toggleLineItemOrPricesetFields = (show) => {
if (!show) {
Expand Down

0 comments on commit 7a2aab2

Please sign in to comment.