diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 581251f49acd..1f7f86cd7e20 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -442,6 +442,12 @@ public function setDefaultValues() { $defaults['refund_trxn_id'] = $defaults['trxn_id'] ?? NULL; } + if (!empty($defaults['contribution_status_id']) + && ('Template' === CRM_Contribute_PseudoConstant::contributionStatus($defaults['contribution_status_id'], 'name')) + ) { + $this->getElement('contribution_status_id')->freeze(); + } + if (!$this->_id && empty($defaults['receive_date'])) { $defaults['receive_date'] = date('Y-m-d H:i:s'); } @@ -701,7 +707,8 @@ public function buildQuickForm() { } // add various dates - $this->addField('receive_date', ['entity' => 'contribution'], !$this->_mode, FALSE); + $receiveDateRequired = !($this->_values['is_test'] ?? FALSE) && ((int) $this->_values['is_template'] !== 1); + $this->addField('receive_date', ['entity' => 'contribution'], $receiveDateRequired, FALSE); $this->addField('receipt_date', ['entity' => 'contribution'], FALSE, FALSE); $this->addField('cancel_date', ['entity' => 'contribution', 'label' => ts('Cancelled / Refunded Date')], FALSE, FALSE); @@ -889,6 +896,7 @@ public static function formRule($fields, $files, $self) { if (($self->_action & CRM_Core_Action::UPDATE) && $self->_id && $self->_values['contribution_status_id'] != $fields['contribution_status_id'] + && $self->_values['contribution_status_id'] != CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Template') ) { CRM_Contribute_BAO_Contribution::checkStatusValidation($self->_values, $fields, $errors); }