Skip to content
Snippets Groups Projects
Commit e47077ce authored by Eileen McNaughton's avatar Eileen McNaughton
Browse files

#2629 show contribution statuses on contribution form

This arose from digging into
#2629
but I think it's a tangent....

However when editing contributions the available statuses
are not dependent on the component. Only the
contribution status is relevant
parent 7dec6f43
Branches
Tags
No related merge requests found
......@@ -208,13 +208,13 @@ LIMIT 1
* Get contribution statuses by entity e.g. contribution, membership or 'participant'
*
* @param string $usedFor
* @param int $id
* @param string $name
* Contribution ID
*
* @return array
* Array of contribution statuses in array('status id' => 'label') format
*/
public static function getContributionStatuses($usedFor = 'contribution', $id = NULL) {
public static function getContributionStatuses($usedFor = 'contribution', $name = NULL) {
if ($usedFor === 'pledge') {
$statusNames = CRM_Pledge_BAO_Pledge::buildOptions('status_id', 'validate');
}
......@@ -232,7 +232,7 @@ LIMIT 1
'Template',
];
// on create fetch statuses on basis of component
if (!$id) {
if (!$name) {
$statusNamesToUnset = array_merge($statusNamesToUnset, [
'Refunded',
'Chargeback',
......@@ -266,8 +266,7 @@ LIMIT 1
}
}
else {
$contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'contribution_status_id');
$name = $statusNames[$contributionStatus] ?? NULL;
switch ($name) {
case 'Completed':
// [CRM-17498] Removing unsupported status change options.
......
......@@ -9,6 +9,7 @@
+--------------------------------------------------------------------+
*/
use Civi\Api4\Contribution;
use Civi\Payment\Exception\PaymentProcessorException;
/**
......@@ -200,6 +201,13 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
*/
public $submitOnce = TRUE;
/**
* Status of contribution prior to edit.
*
* @var string
*/
protected $previousContributionStatus;
/**
* Explicitly declare the form context.
*/
......@@ -459,6 +467,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
* @throws \API_Exception
*/
public function buildQuickForm() {
if ($this->_id) {
......@@ -653,21 +662,11 @@ 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 (!empty($componentDetails['membership'])) {
$component = 'membership';
}
elseif (!empty($componentDetails['participant'])) {
$component = 'participant';
}
}
if ($this->_ppID) {
$component = 'pledge';
}
$status = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses($component, $this->_id);
$status = CRM_Contribute_BAO_Contribution_Utils::getContributionStatuses('contribution', $this->getPreviousContributionStatus());
// define the status IDs that show the cancellation info, see CRM-17589
$cancelInfo_show_ids = [];
......@@ -1828,4 +1827,31 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP
}
}
/**
* Get the contribution ID.
*
* @return int|null
*/
protected function getContributionID(): ?int {
return $this->_id;
}
/**
* Get the selected contribution status.
*
* @return string
*
* @throws \API_Exception
*/
protected function getPreviousContributionStatus(): string {
if (!$this->previousContributionStatus) {
$this->previousContributionStatus = Contribution::get(FALSE)
->addWhere('id', '=', $this->getContributionID())
->addSelect('contribution_status_id:name')
->execute()
->first()['contribution_status_id:name'];
}
return $this->previousContributionStatus;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment