[REF] Extract & share code to determine revenue recognition date.
authoreileen <emcnaughton@wikimedia.org>
Sun, 26 Jan 2020 22:05:22 +0000 (11:05 +1300)
committereileen <emcnaughton@wikimedia.org>
Tue, 28 Jan 2020 09:07:23 +0000 (22:07 +1300)
This also starts the process of consolidating building the 'contribution params' array

CRM/Event/Form/Participant.php

index 1a42efd40f65c8fad6f6f4acdfd108f8c565d68c..929a130879da3dc3af5e45842869d4413149d0c8 100644 (file)
  */
 
 /**
- *
+ * Back office participant form.
  *
  * @package CRM
  * @copyright CiviCRM LLC https://civicrm.org/licensing
  */
 
 /**
- * This class generates form components for processing a participation
- * in an event
+ * Back office participant form.
  */
 class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment {
 
@@ -1829,15 +1828,13 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
    */
   protected function preparePaidEventProcessing($params): array {
     $participantStatus = CRM_Event_PseudoConstant::participantStatus();
-    $contributionParams = ['skipCleanMoney' => TRUE];
+    $contributionParams = [
+      'skipCleanMoney' => TRUE,
+      'revenue_recognition_date' => $this->getRevenueRecognitionDate(),
+    ];
     $lineItem = [];
     $additionalParticipantDetails = [];
-    if (Civi::settings()->get('deferred_revenue_enabled')) {
-      $eventStartDate = $this->getEventValue('start_date');
-      if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
-        $contributionParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
-      }
-    }
+
     if ($this->isPaymentOnExistingContribution()) {
       $contributionParams['total_amount'] = $this->getParticipantValue('fee_amount');
 
@@ -2050,19 +2047,8 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
         'invoice_id'
       );
     }
+    $contribParams['revenue_recognition_date'] = $this->getRevenueRecognitionDate();
 
-    if (Civi::settings()->get('deferred_revenue_enabled')) {
-      $eventStartDate = CRM_Utils_Array::value(
-        'start_date',
-        CRM_Utils_Array::value(
-          'event',
-          $form->_values
-        )
-      );
-      if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
-        $contribParams['revenue_recognition_date'] = date('Ymd', strtotime($eventStartDate));
-      }
-    }
     //create an contribution address
     // The concept of contributeMode is deprecated. Elsewhere we use the function processBillingAddress() - although
     // currently that is only inherited by back-office forms.
@@ -2228,4 +2214,21 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment
     return $this->_id ?? $this->_pId;
   }
 
+  /**
+   * Get the value for the revenue recognition date field.
+   *
+   * @return string
+   *
+   * @throws \CiviCRM_API3_Exception
+   */
+  protected function getRevenueRecognitionDate() {
+    if (Civi::settings()->get('deferred_revenue_enabled')) {
+      $eventStartDate = $this->getEventValue('start_date');
+      if (strtotime($eventStartDate) > strtotime(date('Ymt'))) {
+        return date('Ymd', strtotime($eventStartDate));
+      }
+    }
+    return '';
+  }
+
 }