Skip to content

Commit

Permalink
[REF] Extract & share code to determine revenue recognition date.
Browse files Browse the repository at this point in the history
This also starts the process of consolidating building the 'contribution params' array
  • Loading branch information
eileenmcnaughton committed Jan 27, 2020
1 parent c2009ff commit 9cb73a8
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
*/

/**
*
* 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 {

Expand Down Expand Up @@ -1829,18 +1828,15 @@ public function buildEventFeeForm($form) {
*/
protected function preparePaidEventProcessing($params): array {
$participantStatus = CRM_Event_PseudoConstant::participantStatus();
$contributionParams = ['skipCleanMoney' => TRUE];
$contributionParams = [
'skipCleanMoney' => TRUE,
'revenue_recognition_date' => $this->getRevenueRecognitionDate(),
'total_amount' => $this->isPaymentOnExistingContribution() ? $this->getParticipantValue('fee_amount') : $params['amount'],
];
$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');

if ($this->isPaymentOnExistingContribution()) {
$params['discount_id'] = NULL;
//re-enter the values for UPDATE mode
$params['fee_level'] = $params['amount_level'] = $this->getParticipantValue('fee_level');
Expand Down Expand Up @@ -1884,7 +1880,6 @@ protected function preparePaidEventProcessing($params): array {
}

$params['fee_level'] = $params['amount_level'];
$contributionParams['total_amount'] = $params['amount'];
if ($this->_quickConfig && !empty($params['total_amount']) &&
$params['status_id'] != array_search('Partially paid', $participantStatus)
) {
Expand Down Expand Up @@ -2050,19 +2045,8 @@ public function processContribution(
'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.
Expand Down Expand Up @@ -2228,4 +2212,21 @@ protected function getParticipantID() {
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 '';
}

}

0 comments on commit 9cb73a8

Please sign in to comment.