Skip to content

Commit

Permalink
Merge pull request #12314 from mattwire/CRM-21682_cleanup_recordAddit…
Browse files Browse the repository at this point in the history
…ionalPayment

Cleanup recordAdditionalPayment towards #11556
  • Loading branch information
eileenmcnaughton authored Jun 15, 2018
2 parents e67ad14 + 4197d36 commit 8bc8a91
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -3837,7 +3837,6 @@ public static function validateFinancialType($financialTypeId, $relationName = '
* @return null|object
*/
public static function recordAdditionalPayment($contributionId, $trxnsData, $paymentType = 'owed', $participantId = NULL, $updateStatus = TRUE) {
$statusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$getInfoOf['id'] = $contributionId;
$defaults = array();
$contributionDAO = CRM_Contribute_BAO_Contribution::retrieve($getInfoOf, $defaults, CRM_Core_DAO::$_nullArray);
Expand All @@ -3855,7 +3854,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
$trxnsData['trxn_date'] = !empty($trxnsData['trxn_date']) ? $trxnsData['trxn_date'] : date('YmdHis');
$arAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contributionDAO->financial_type_id, 'Accounts Receivable Account is');

// get the paid status id
$completedStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed');
$paidStatus = CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialItem', 'status_id', 'Paid');

if ($paymentType == 'owed') {
Expand Down Expand Up @@ -3890,7 +3889,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
WHERE eft.entity_table = 'civicrm_contribution'
AND eft.entity_id = {$contributionId}
AND ft.to_financial_account_id != {$toFinancialAccount}
AND ft.status_id = {$statusId}
AND ft.status_id = {$completedStatusId}
";
$query = CRM_Core_DAO::executeQuery($sql);
$query->fetch();
Expand All @@ -3900,7 +3899,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
if ($contributionDAO->total_amount == $sumOfPayments) {
// update contribution status and
// clean cancel info (if any) if prev. contribution was updated in case of 'Refunded' => 'Completed'
$contributionDAO->contribution_status_id = $statusId;
$contributionDAO->contribution_status_id = $completedStatusId;
$contributionDAO->cancel_date = 'null';
$contributionDAO->cancel_reason = NULL;
$netAmount = !empty($trxnsData['net_amount']) ? NULL : $trxnsData['total_amount'];
Expand All @@ -3909,7 +3908,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
$contributionDAO->save();

//Change status of financial record too
$financialTrxn->status_id = $statusId;
$financialTrxn->status_id = $completedStatusId;
$financialTrxn->save();

// note : not using the self::add method,
Expand Down Expand Up @@ -3958,7 +3957,7 @@ public static function recordAdditionalPayment($contributionId, $trxnsData, $pay
// which in 'Pending Refund' => 'Completed' is not useful, instead specific financial record updates
// are coded below i.e. just updating financial_item status to 'Paid'
if ($updateStatus) {
$contributionDetails = CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $statusId);
CRM_Core_DAO::setFieldValue('CRM_Contribute_BAO_Contribution', $contributionId, 'contribution_status_id', $completedStatusId);
}
// add financial item entry
$lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contributionDAO->id);
Expand Down

0 comments on commit 8bc8a91

Please sign in to comment.