From a9c48769340f894480961e2dd109e2f8b1230deb Mon Sep 17 00:00:00 2001 From: Pradeep Nayak Date: Thu, 11 Aug 2016 08:32:36 +0530 Subject: [PATCH] CRM-16189, added code to create accounts receivable transaction for participant payment ---------------------------------------- * CRM-16189: Improve support for Accrual Method bookkeeping https://issues.civicrm.org/jira/browse/CRM-16189 --- CRM/Contribute/BAO/Contribution.php | 21 ++++++++++++++------- CRM/Event/Form/Participant.php | 4 ++++ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 8950429a71..7ce25e4995 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -5304,23 +5304,27 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co * * @param array $params * + * @param string $context + * */ - public static function recordAlwaysAccountsReceivable(&$params) { + public static function recordAlwaysAccountsReceivable(&$params, $context = NULL) { if (!self::checkContributeSettings('always_post_to_accounts_receivable')) { return NULL; } - + $statusId = $params['contribution']->contribution_status_id; $contributionStatuses = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name'); - $contributionStatus = empty($params['contribution_status_id']) ? NULL : $contributionStatuses[$params['contribution_status_id']]; + $contributionStatus = empty($statusId) ? NULL : $contributionStatuses[$statusId]; // Return if contribution status is not completed. if ($contributionStatus != 'Completed') { return NULL; } - $params['contribution_status_id'] = $params['contribution']->contribution_status_id = array_search('Pending', $contributionStatuses); - $params['is_pay_later'] = $params['contribution']->is_pay_later = TRUE; - - self::recordFinancialAccounts($params); + if (empty($context)) { + $params['contribution_status_id'] = $params['contribution']->contribution_status_id = array_search('Pending', $contributionStatuses); + $params['is_pay_later'] = $params['contribution']->is_pay_later = TRUE; + + self::recordFinancialAccounts($params); + } $params['prevContribution'] = self::getOriginalContribution($params['contribution']->id); $params['prevContribution']->contribution_status_id = array_search('Pending', $contributionStatuses); @@ -5330,6 +5334,9 @@ LEFT JOIN civicrm_contribution on (civicrm_contribution.contact_id = civicrm_co unset($params['is_pay_later']); $params['contribution']->is_pay_later = NULL; $params['id'] = $params['contribution']->id; + if (!empty($context)) { + self::recordFinancialAccounts($params); + } } } diff --git a/CRM/Event/Form/Participant.php b/CRM/Event/Form/Participant.php index 06b04f8d65..19e00c3f8e 100644 --- a/CRM/Event/Form/Participant.php +++ b/CRM/Event/Form/Participant.php @@ -1454,6 +1454,10 @@ class CRM_Event_Form_Participant extends CRM_Contribute_Form_AbstractEditPayment CRM_Contribute_BAO_Contribution::addPayments($value, $contributions); } } + if (CRM_Utils_Array::value($num, $contributions)) { + $trxnParams = array('contribution' => $contributions[$num]); + CRM_Contribute_BAO_Contribution::recordAlwaysAccountsReceivable($trxnParams, 'Participant'); + } } } -- 2.25.1