Skip to content

Commit

Permalink
Merge pull request #11780 from JMAConsulting/CRM-21756
Browse files Browse the repository at this point in the history
CRM-21756: Freeze total amount field on Edit Contribution if related to Membership or Event registration
  • Loading branch information
eileenmcnaughton authored Mar 11, 2018
2 parents 99921fb + 6bc9ca9 commit 4d8389b
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 15 deletions.
29 changes: 15 additions & 14 deletions CRM/Contribute/Form/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,7 @@ public function buildQuickForm() {
$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)) {
Expand Down Expand Up @@ -712,7 +713,6 @@ public function buildQuickForm() {
// 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',
Expand Down Expand Up @@ -811,23 +811,24 @@ public function buildQuickForm() {
)
);

// 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);
Expand Down
3 changes: 3 additions & 0 deletions templates/CRM/Contribute/Form/Contribution.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
9 changes: 8 additions & 1 deletion templates/CRM/Contribute/Page/Tab.hlp
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down Expand Up @@ -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}
Expand Down

0 comments on commit 4d8389b

Please sign in to comment.