From 2f8a402e9f1eb5ab9cd061e9105a7c2a3935718e Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 28 Apr 2020 10:34:21 +1200 Subject: [PATCH] Move batch-form support code back to the form I've dug around onn this and there is no reason for this code to be in the BAO - it is only relevant to support this form & should live there. Longer term the form should call api v4.... --- CRM/Batch/Form/Entry.php | 20 +++++++++++++++++++- CRM/Contribute/BAO/Contribution.php | 21 --------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/CRM/Batch/Form/Entry.php b/CRM/Batch/Form/Entry.php index c8ccc6719d..e60ababdb4 100644 --- a/CRM/Batch/Form/Entry.php +++ b/CRM/Batch/Form/Entry.php @@ -565,9 +565,27 @@ class CRM_Batch_Form_Entry extends CRM_Core_Form { } } $value['line_item'] = $lineItem; - $value['skipCleanMoney'] = TRUE; + //finally call contribution create for all the magic $contribution = CRM_Contribute_BAO_Contribution::create($value); + // This code to retrieve the contribution has been moved here from the contribution create + // api. It may not be required. + $titleFields = [ + 'contact_id', + 'total_amount', + 'currency', + 'financial_type_id', + ]; + $retrieveRequired = 0; + foreach ($titleFields as $titleField) { + if (!isset($contribution->$titleField)) { + $retrieveRequired = 1; + break; + } + } + if ($retrieveRequired == 1) { + $contribution->find(TRUE); + } $batchTypes = CRM_Core_PseudoConstant::get('CRM_Batch_DAO_Batch', 'type_id', ['flip' => 1], 'validate'); if (!empty($this->_batchInfo['type_id']) && ($this->_batchInfo['type_id'] == $batchTypes['Pledge Payment'])) { $adjustTotalAmount = FALSE; diff --git a/CRM/Contribute/BAO/Contribution.php b/CRM/Contribute/BAO/Contribution.php index 3f2d17d920..d2c99595fb 100644 --- a/CRM/Contribute/BAO/Contribution.php +++ b/CRM/Contribute/BAO/Contribution.php @@ -508,27 +508,6 @@ class CRM_Contribute_BAO_Contribution extends CRM_Contribute_DAO_Contribution { CRM_Core_BAO_Note::add($noteParams); } - // make entry in batch entity batch table - if (!empty($params['batch_id'])) { - // in some update cases we need to get extra fields - ie an update that doesn't pass in all these params - $titleFields = [ - 'contact_id', - 'total_amount', - 'currency', - 'financial_type_id', - ]; - $retrieveRequired = 0; - foreach ($titleFields as $titleField) { - if (!isset($contribution->$titleField)) { - $retrieveRequired = 1; - break; - } - } - if ($retrieveRequired == 1) { - $contribution->find(TRUE); - } - } - CRM_Contribute_BAO_ContributionSoft::processSoftContribution($params, $contribution); $transaction->commit(); -- 2.25.1