From 7a2aab2ac974fa2f233f495f5504f374a596f920 Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Fri, 16 Aug 2024 08:23:19 +0100 Subject: [PATCH] BTHAMM-31: Prevent resetting contribution total amoun to zero --- js/modifyContributionForm.js | 3 +++ .../Financeextras/Form/Contribute/CustomLineItem.tpl | 12 +++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/js/modifyContributionForm.js b/js/modifyContributionForm.js index acf9f845..0c1e5b57 100644 --- a/js/modifyContributionForm.js +++ b/js/modifyContributionForm.js @@ -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) }); diff --git a/templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl b/templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl index 74e6a35e..823f4a58 100644 --- a/templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl +++ b/templates/CRM/Financeextras/Form/Contribute/CustomLineItem.tpl @@ -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() === '' @@ -42,8 +45,11 @@ $('#selectPriceSet').prepend( `
OR Switch back to using line items
`) $('#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); @@ -58,7 +64,7 @@ $('#totalAmountORPriceSet, #price_set_id').show(); } }); - }, 100); + }, 500); const toggleLineItemOrPricesetFields = (show) => { if (!show) {