Unverified Commit 4d8389b7 authored by eileen's avatar eileen 🎱 Committed by GitHub

Merge pull request #11780 from JMAConsulting/CRM-21756

CRM-21756: Freeze total amount field on Edit Contribution if related to Membership or Event registration
parents 99921fb2 6bc9ca96
......@@ -646,6 +646,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
$this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
$component = 'contribution';
$componentDetails = [];
if ($this->_id) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
if (CRM_Utils_Array::value('membership', $componentDetails)) {
......@@ -712,7 +713,6 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
// don't allow price set for contribution if it is related to participant, or if it is a pledge payment
// and if we already have line items for that participant. CRM-5095
if ($buildPriceSet && $this->_id) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
$pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment',
$this->_id,
'id',
......@@ -811,23 +811,24 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
)
);
// if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
// Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
if ($this->_id && ($this->_values['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'))) {
if ($totalAmount) {
$totalAmount->freeze();
}
$paymentInstrument->freeze();
$trxnId->freeze();
$financialType->freeze();
}
// if contribution is related to membership or participant freeze Financial Type, Amount
if ($this->_id && isset($this->_values['tax_amount'])) {
if ($this->_id) {
$componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
$isCancelledStatus = ($this->_values['contribution_status_id'] == CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Cancelled'));
if (CRM_Utils_Array::value('membership', $componentDetails) ||
CRM_Utils_Array::value('participant', $componentDetails) ||
// if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
// Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
$isCancelledStatus
) {
if ($totalAmount) {
$totalAmount->freeze();
$this->getElement('currency')->freeze();
}
if ($isCancelledStatus) {
$paymentInstrument->freeze();
$trxnId->freeze();
}
$financialType->freeze();
$this->assign('freezeFinancialType', TRUE);
......
......@@ -97,6 +97,9 @@
<td class="label">{$form.total_amount.label}</td>
<td {$valueStyle}>
<span id='totalAmount'>{$form.currency.html|crmAddClass:eight}&nbsp;{$form.total_amount.html|crmAddClass:eight}</span>
{if $freezeFinancialType}
{help id="id-total_amount"}
{/if}
{if !$payNow}
{if $hasPriceSets}
<span id='totalAmountORPriceSet'> {ts}OR{/ts}</span>
......
......@@ -30,6 +30,13 @@
{ts}Optional identifier for the contribution source (campaign name, event, mailer, etc.).{/ts}
{/htxt}
{htxt id="id-total_amount-title"}
{ts}Total Amount{/ts}
{/htxt}
{htxt id="id-total_amount"}
{ts 1='target="_blank" href="https://civicrm.org/extensions/line-item-editor"'}You are not allowed to change the total amount as it will lead to incorrect line item entries. You can either delete or recreate or install <a %1>Line Item Editor</a>.{/ts}
{/htxt}
{htxt id="id-financial_type-title"}
{ts}Financial Type{/ts}
{/htxt}
......@@ -78,7 +85,7 @@
<p>
{ts}When contributions are made via a Personal Campaign Page a soft credit (of type 'Personal Campaign Page') is automatically created and assigned to the 'owner' of the the Personal Campaign Page.{/ts}
</p>
{/htxt}
{/htxt}
{htxt id="adjust-payment-amount-title"}
{ts}Payment Amount{/ts}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment