From c7bfc4cb65ed82835e0e284494b4af02f9c81683 Mon Sep 17 00:00:00 2001 From: Eileen McNaughton Date: Mon, 25 Feb 2019 18:55:13 +1300 Subject: [PATCH] Revert "[REF] Extract record refund function" --- .../BAO}/Contribution.php | 37 +++++++++++- CRM/Financial/BAO/Payment.php | 57 ------------------- 2 files changed, 35 insertions(+), 59 deletions(-) rename CRM/{Financial/BAO/Payment => Contribute/BAO}/Contribution.php (99%) diff --git a/CRM/Financial/BAO/Payment/Contribution.php b/CRM/Contribute/BAO/Contribution.php similarity index 99% rename from CRM/Financial/BAO/Payment/Contribution.php rename to CRM/Contribute/BAO/Contribution.php index 79195dda81..010d68df8f 100644 --- a/CRM/Financial/BAO/Payment/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -3903,10 +3903,43 @@ WHERE eft.financial_trxn_id IN ({$trxnId}, {$baseTrxnId['financialTrxnId']}) } } elseif ($paymentType == 'refund') { - $financialTrxn = CRM_Financial_BAO_Payment::recordRefundPayment($contributionId, $trxnsData, $updateStatus); + $trxnsData['total_amount'] = $trxnsData['net_amount'] = -$trxnsData['total_amount']; + $trxnsData['from_financial_account_id'] = $arAccountId; + $trxnsData['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded'); + // record the entry + $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnsData); + + // note : not using the self::add method, + // the reason because it performs 'status change' related code execution for financial records + // 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) { + 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); + if (!empty($lineItems)) { + foreach ($lineItems as $lineItemId => $lineItemValue) { + // don't record financial item for cancelled line-item + if ($lineItemValue['qty'] == 0) { + continue; + } + $paid = $lineItemValue['line_total'] * ($financialTrxn->total_amount / $contributionDAO->total_amount); + $addFinancialEntry = array( + 'transaction_date' => $financialTrxn->trxn_date, + 'contact_id' => $contributionDAO->contact_id, + 'amount' => round($paid, 2), + 'currency' => $contributionDAO->currency, + 'status_id' => $paidStatus, + 'entity_id' => $lineItemId, + 'entity_table' => 'civicrm_line_item', + ); + $trxnIds['id'] = $financialTrxn->id; + CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds); + } + } if ($participantId) { // update participant status - // @todo this doesn't make sense... $participantStatuses = CRM_Event_PseudoConstant::participantStatus(); $ids = CRM_Event_BAO_Participant::getParticipantIds($contributionId); foreach ($ids as $val) { diff --git a/CRM/Financial/BAO/Payment.php b/CRM/Financial/BAO/Payment.php index 016378ff34..e445004226 100644 --- a/CRM/Financial/BAO/Payment.php +++ b/CRM/Financial/BAO/Payment.php @@ -289,61 +289,4 @@ class CRM_Financial_BAO_Payment { return $filteredParams; } - /** - * @param $contributionId - * @param $trxnData - * @param $updateStatus - * - deprecate this param - * - * @todo - make this protected once recordAdditionalPayment no longer calls it. - * - * @return CRM_Financial_DAO_FinancialTrxn - */ - public static function recordRefundPayment($contributionId, $trxnData, $updateStatus) { - $contributionDAO = new CRM_Contribute_BAO_Contribution(); - $contributionDAO->id = $contributionId; - $contributionDAO->find(TRUE); - - $paidStatus = CRM_Core_PseudoConstant::getKey('CRM_Financial_DAO_FinancialItem', 'status_id', 'Paid'); - $arAccountId = CRM_Contribute_PseudoConstant::getRelationalFinancialAccount($contributionDAO->financial_type_id, 'Accounts Receivable Account is'); - $completedStatusId = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Completed'); - - $trxnData['total_amount'] = $trxnData['net_amount'] = -$trxnData['total_amount']; - $trxnData['from_financial_account_id'] = $arAccountId; - $trxnData['status_id'] = CRM_Core_PseudoConstant::getKey('CRM_Contribute_BAO_Contribution', 'contribution_status_id', 'Refunded'); - // record the entry - $financialTrxn = CRM_Contribute_BAO_Contribution::recordFinancialAccounts($params, $trxnData); - - // note : not using the self::add method, - // the reason because it performs 'status change' related code execution for financial records - // 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) { - 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); - if (!empty($lineItems)) { - foreach ($lineItems as $lineItemId => $lineItemValue) { - // don't record financial item for cancelled line-item - if ($lineItemValue['qty'] == 0) { - continue; - } - $paid = $lineItemValue['line_total'] * ($financialTrxn->total_amount / $contributionDAO->total_amount); - $addFinancialEntry = [ - 'transaction_date' => $financialTrxn->trxn_date, - 'contact_id' => $contributionDAO->contact_id, - 'amount' => round($paid, 2), - 'currency' => $contributionDAO->currency, - 'status_id' => $paidStatus, - 'entity_id' => $lineItemId, - 'entity_table' => 'civicrm_line_item', - ]; - $trxnIds = ['id' => $financialTrxn->id]; - CRM_Financial_BAO_FinancialItem::create($addFinancialEntry, NULL, $trxnIds); - } - } - return $financialTrxn; - } - } -- 2.25.1