From 0a33afe582b1a8e786f92a722ff1447d6aa237e1 Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 15 Aug 2017 16:11:33 -0400 Subject: [PATCH] Rename var oldestPledgePayment to nextInstallmentdue. I'm having serious serious issues reading this code. Renaming the variable is a step towards making sense of it. actually refers to the next pledge payment installment that is unpaid, matching from the oldest --- CRM/Pledge/BAO/PledgePayment.php | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/CRM/Pledge/BAO/PledgePayment.php b/CRM/Pledge/BAO/PledgePayment.php index b0cfcf84cdc3..edfa0ab16d0d 100644 --- a/CRM/Pledge/BAO/PledgePayment.php +++ b/CRM/Pledge/BAO/PledgePayment.php @@ -495,7 +495,7 @@ public static function updatePledgePaymentStatus( 2 => array($pledgeID, 'Integer'), ); - $dao = CRM_Core_DAO::executeQuery($query, $params); + CRM_Core_DAO::executeQuery($query, $params); return $pledgeStatusID; } @@ -823,47 +823,47 @@ public static function adjustPledgePayment($pledgeID, $actualAmount, $pledgeSche $payment = self::add($pledgeParams); } else { - $oldestPayment = self::getOldestPledgePayment($pledgeID); + $nextPledgeInstallmentDue = self::getOldestPledgePayment($pledgeID); if (!$paymentContributionId) { // means we are editing payment scheduled payment, so get the second pending to update. - $oldestPayment = self::getOldestPledgePayment($pledgeID, 2); - if (($oldestPayment['count'] != 1) && ($oldestPayment['id'] == $pPaymentId)) { - $oldestPayment = self::getOldestPledgePayment($pledgeID); + $nextPledgeInstallmentDue = self::getOldestPledgePayment($pledgeID, 2); + if (($nextPledgeInstallmentDue['count'] != 1) && ($nextPledgeInstallmentDue['id'] == $pPaymentId)) { + $nextPledgeInstallmentDue = self::getOldestPledgePayment($pledgeID); } } - if ($oldestPayment) { + if ($nextPledgeInstallmentDue) { // not the last scheduled payment and the actual amount is less than the expected , add it to oldest pending. - if (($actualAmount != $pledgeScheduledAmount) && (($actualAmount < $pledgeScheduledAmount) || (($actualAmount - $pledgeScheduledAmount) < $oldestPayment['amount']))) { - $oldScheduledAmount = $oldestPayment['amount']; + if (($actualAmount != $pledgeScheduledAmount) && (($actualAmount < $pledgeScheduledAmount) || (($actualAmount - $pledgeScheduledAmount) < $nextPledgeInstallmentDue['amount']))) { + $oldScheduledAmount = $nextPledgeInstallmentDue['amount']; $newScheduledAmount = $oldScheduledAmount + ($pledgeScheduledAmount - $actualAmount); // store new amount in oldest pending payment record. CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', - $oldestPayment['id'], + $nextPledgeInstallmentDue['id'], 'scheduled_amount', $newScheduledAmount ); - if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'contribution_id', 'id')) { + if (CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $nextPledgeInstallmentDue['id'], 'contribution_id', 'id')) { CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', - $oldestPayment['id'], + $nextPledgeInstallmentDue['id'], 'contribution_id', $paymentContributionId ); } } - elseif (($actualAmount > $pledgeScheduledAmount) && (($actualAmount - $pledgeScheduledAmount) >= $oldestPayment['amount'])) { + elseif (($actualAmount > $pledgeScheduledAmount) && (($actualAmount - $pledgeScheduledAmount) >= $nextPledgeInstallmentDue['amount'])) { // here the actual amount is greater than expected and also greater than the next installment amount, so update the next installment as complete and again add it to next subsequent pending payment // set the actual amount of the next pending to '0', set contribution Id to current contribution Id and status as completed - $paymentId = array($oldestPayment['id']); + $paymentId = array($nextPledgeInstallmentDue['id']); self::updatePledgePayments($pledgeID, array_search('Completed', $allStatus), $paymentId, 0, $paymentContributionId); - CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $oldestPayment['id'], 'scheduled_amount', 0, 'id'); - + CRM_Core_DAO::setFieldValue('CRM_Pledge_DAO_PledgePayment', $nextPledgeInstallmentDue['id'], 'scheduled_amount', 0, 'id'); + $nextPledgeInstallmentDue = self::getOldestPledgePayment($pledgeID); if (!$paymentContributionId) { // means we are editing payment scheduled payment. $oldestPaymentAmount = self::getOldestPledgePayment($pledgeID, 2); } $newActualAmount = round(($actualAmount - $pledgeScheduledAmount), CRM_Utils_Money::getCurrencyPrecision()); - $newPledgeScheduledAmount = $oldestPayment['amount']; + $newPledgeScheduledAmount = $nextPledgeInstallmentDue['amount']; if (!$paymentContributionId) { $newActualAmount = ($actualAmount - $pledgeScheduledAmount); $newPledgeScheduledAmount = $oldestPaymentAmount['amount'];