From 6d0cf504023789b8feadad8fddb2c7449d0f814a Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Fri, 1 May 2015 11:42:49 -0600 Subject: [PATCH] CRM-16367 (back office contribution form) move refactored pledge update function out of contribution form to BAO --- CRM/Contribute/BAO/Contribution.php | 65 ++++++++++++++++++++++++++ CRM/Contribute/Form/Contribution.php | 68 +--------------------------- 2 files changed, 66 insertions(+), 67 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 127b17871f..0eb3b8ad32 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3720,4 +3720,69 @@ WHERE con.id = {$contributionId} } } + /** + * Update related pledge payment payments. + * + * @param string $action + * @param int $pledgePaymentID + * @param int $contributionID + * @param bool $adjustTotalAmount + * @param float $total_amount + * @param float $original_total_amount + * @param int $contribution_status_id + * @param int $original_contribution_status_id + */ + protected function updateRelatedPledge( + $action, + $pledgePaymentID, + $contributionID, + $adjustTotalAmount, + $total_amount, + $original_total_amount, + $contribution_status_id, + $original_contribution_status_id + ) { + if (!$pledgePaymentID || $action & CRM_Core_Action::ADD && !$contributionID) { + return; + } + + if ($pledgePaymentID) { + //store contribution id in payment record. + CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentID, 'contribution_id', $contributionID); + } + else { + $pledgePaymentID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', + $contributionID, + 'id', + 'contribution_id' + ); + } + $pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', + $contributionID, + 'pledge_id', + 'contribution_id' + ); + + $updatePledgePaymentStatus = FALSE; + + // If either the status or the amount has changed we update the pledge status. + if ($action & CRM_Core_Action::ADD) { + $updatePledgePaymentStatus = TRUE; + } + elseif ($action & CRM_Core_Action::UPDATE && (($original_contribution_status_id != $contribution_status_id) || + ($original_total_amount != $total_amount)) + ) { + $updatePledgePaymentStatus = TRUE; + } + + if ($updatePledgePaymentStatus) { + CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, + array($pledgePaymentID), + $contribution_status_id, + NULL, + $total_amount, + $adjustTotalAmount + ); + } + } } diff --git a/CRM/Contribute/Form/Contribution.php b/CRM/Contribute/Form/Contribution.php index 8bda25ee0a..e8446484b6 100644 --- a/CRM/Contribute/Form/Contribution.php +++ b/CRM/Contribute/Form/Contribution.php @@ -1820,7 +1820,7 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP $sendReceipt = CRM_Contribute_Form_AdditionalInfo::emailReceipt($this, $formValues); } - $this->updateRelatedPledge( + CRM_Contribute_BAO_Contribution::updateRelatedPledge( $action, $pledgePaymentID, $contribution->id, @@ -1846,70 +1846,4 @@ class CRM_Contribute_Form_Contribution extends CRM_Contribute_Form_AbstractEditP } } - /** - * Update related pledge payment payments. - * - * @param string $action - * @param int $pledgePaymentID - * @param int $contributionID - * @param bool $adjustTotalAmount - * @param float $total_amount - * @param float $original_total_amount - * @param int $contribution_status_id - * @param int $original_contribution_status_id - */ - protected function updateRelatedPledge( - $action, - $pledgePaymentID, - $contributionID, - $adjustTotalAmount, - $total_amount, - $original_total_amount, - $contribution_status_id, - $original_contribution_status_id - ) { - if (!$pledgePaymentID || $action & CRM_Core_Action::ADD && !$contributionID) { - return; - } - - if ($pledgePaymentID) { - //store contribution id in payment record. - CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $pledgePaymentID, 'contribution_id', $contributionID); - } - else { - $pledgePaymentID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', - $contributionID, - 'id', - 'contribution_id' - ); - } - $pledgeID = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', - $contributionID, - 'pledge_id', - 'contribution_id' - ); - - $updatePledgePaymentStatus = FALSE; - - // If either the status or the amount has changed we update the pledge status. - if ($action & CRM_Core_Action::ADD) { - $updatePledgePaymentStatus = TRUE; - } - elseif ($action & CRM_Core_Action::UPDATE && (($original_contribution_status_id != $contribution_status_id) || - ($original_total_amount != $total_amount)) - ) { - $updatePledgePaymentStatus = TRUE; - } - - if ($updatePledgePaymentStatus) { - CRM_Pledge_BAO_PledgePayment::updatePledgePaymentStatus($pledgeID, - array($pledgePaymentID), - $contribution_status_id, - NULL, - $total_amount, - $adjustTotalAmount - ); - } - } - } -- 2.25.1