From aed609bbcb4cc4a4115cea161589bb123a207e04 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Tue, 5 Sep 2023 11:13:30 +1200 Subject: [PATCH] Move function to only form that calls it There was a time when we were moving stuff into AbstractEditPayment but really it is better to have private functions when we have done the work to determine that they are only used from one place - because then we know we can edit / fix them I did a universe search & this is a straight move to a child class --- CRM/Contribute/Form/AbstractEditPayment.php | 76 --------------------- CRM/Contribute/Form/Contribution.php | 76 +++++++++++++++++++++ 2 files changed, 76 insertions(+), 76 deletions(-) diff --git a/CRM/Contribute/Form/AbstractEditPayment.php b/CRM/Contribute/Form/AbstractEditPayment.php index 90b2fe1522..4b90f3508d 100644 --- a/CRM/Contribute/Form/AbstractEditPayment.php +++ b/CRM/Contribute/Form/AbstractEditPayment.php @@ -410,82 +410,6 @@ class CRM_Contribute_Form_AbstractEditPayment extends CRM_Contact_Form_Task { return $submittedValues['currency'] ?? $this->_values['currency'] ?? CRM_Core_Config::singleton()->defaultCurrency; } - public function preProcessPledge() { - //get the payment values associated with given pledge payment id OR check for payments due. - $this->_pledgeValues = []; - if ($this->_ppID) { - $payParams = ['id' => $this->_ppID]; - - CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); - $this->_pledgeID = $this->_pledgeValues['pledgePayment']['pledge_id'] ?? NULL; - $paymentStatusID = $this->_pledgeValues['pledgePayment']['status_id'] ?? NULL; - $this->_id = $this->_pledgeValues['pledgePayment']['contribution_id'] ?? NULL; - - //get all status - $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { - CRM_Core_Error::statusBounce(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); - } - - //get the pledge values associated with given pledge payment. - - $ids = []; - $pledgeParams = ['id' => $this->_pledgeID]; - CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); - $this->assign('ppID', $this->_ppID); - } - else { - // Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206 - if (isset($this->_contactID)) { - $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); - - if (!empty($contactPledges)) { - $payments = $paymentsDue = NULL; - $multipleDue = FALSE; - foreach ($contactPledges as $key => $pledgeId) { - $payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId); - if ($payments) { - if ($paymentsDue) { - $multipleDue = TRUE; - break; - } - else { - $paymentsDue = $payments; - } - } - } - if ($multipleDue) { - // Show link to pledge tab since more than one pledge has a payment due - $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', - "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge" - ); - CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. Click here to view their Pledges tab and verify whether this contribution should be applied as a pledge payment.', [1 => $pledgeTab]), ts('Notice'), 'alert'); - } - elseif ($paymentsDue) { - // Show user link to oldest Pending or Overdue pledge payment - $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']); - $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date')); - if ($this->_mode) { - $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', - "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live" - ); - } - else { - $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', - "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge" - ); - } - CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. Click here to enter a pledge payment.', [ - 1 => $ppUrl, - 2 => $ppAmountDue, - 3 => $ppSchedDate, - ]), ts('Notice'), 'alert'); - } - } - } - } - } - /** * @param array $submittedValues * diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 90b2e0636c..b35e3d1f22 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -330,6 +330,82 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } + private function preProcessPledge(): void { + //get the payment values associated with given pledge payment id OR check for payments due. + $this->_pledgeValues = []; + if ($this->_ppID) { + $payParams = ['id' => $this->_ppID]; + + CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']); + $this->_pledgeID = $this->_pledgeValues['pledgePayment']['pledge_id'] ?? NULL; + $paymentStatusID = $this->_pledgeValues['pledgePayment']['status_id'] ?? NULL; + $this->_id = $this->_pledgeValues['pledgePayment']['contribution_id'] ?? NULL; + + //get all status + $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); + if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) { + CRM_Core_Error::statusBounce(ts("Pledge payment status should be 'Pending' or 'Overdue'.")); + } + + //get the pledge values associated with given pledge payment. + + $ids = []; + $pledgeParams = ['id' => $this->_pledgeID]; + CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids); + $this->assign('ppID', $this->_ppID); + } + else { + // Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206 + if (isset($this->_contactID)) { + $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID); + + if (!empty($contactPledges)) { + $payments = $paymentsDue = NULL; + $multipleDue = FALSE; + foreach ($contactPledges as $key => $pledgeId) { + $payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId); + if ($payments) { + if ($paymentsDue) { + $multipleDue = TRUE; + break; + } + else { + $paymentsDue = $payments; + } + } + } + if ($multipleDue) { + // Show link to pledge tab since more than one pledge has a payment due + $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', + "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge" + ); + CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. Click here to view their Pledges tab and verify whether this contribution should be applied as a pledge payment.', [1 => $pledgeTab]), ts('Notice'), 'alert'); + } + elseif ($paymentsDue) { + // Show user link to oldest Pending or Overdue pledge payment + $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']); + $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date')); + if ($this->_mode) { + $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', + "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live" + ); + } + else { + $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', + "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge" + ); + } + CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. Click here to enter a pledge payment.', [ + 1 => $ppUrl, + 2 => $ppAmountDue, + 3 => $ppSchedDate, + ]), ts('Notice'), 'alert'); + } + } + } + } + } + /** * Set default values. * -- 2.25.1