Skip to content

Commit

Permalink
Rename var oldestPledgePayment to nextInstallmentdue.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
eileenmcnaughton committed Aug 15, 2017
1 parent 7ce5b64 commit 0a33afe
Showing 1 changed file with 16 additions and 16 deletions.
32 changes: 16 additions & 16 deletions CRM/Pledge/BAO/PledgePayment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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'];
Expand Down

0 comments on commit 0a33afe

Please sign in to comment.