Revert "[REF] Extract record refund function"
authorEileen McNaughton <eileen@mcnaughty.com>
Mon, 25 Feb 2019 05:55:13 +0000 (18:55 +1300)
committerGitHub <noreply@github.com>
Mon, 25 Feb 2019 05:55:13 +0000 (18:55 +1300)
CRM/Contribute/BAO/Contribution.php [moved from CRM/Financial/BAO/Payment/Contribution.php with 99% similarity]
CRM/Financial/BAO/Payment.php

similarity index 99%
rename from CRM/Financial/BAO/Payment/Contribution.php
rename to CRM/Contribute/BAO/Contribution.php
index 79195dda818ba68d676111100b34a4ab99b517af..010d68df8f1689e60179d0a1b2cfee4d474cd552 100644 (file)
@@ -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) {
index 016378ff34bf79329a69ce3b787468c47f6a3989..e4450042262b100dc2bd3a51d63998718ae606c7 100644 (file)
@@ -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;
-  }
-
 }