Skip to content

Commit

Permalink
[REF] Interim code cleanup - make the usage of addPayments clearer
Browse files Browse the repository at this point in the history
This brings the condition back to the calling function which clarifies what is going on with it
  • Loading branch information
eileenmcnaughton committed Jan 31, 2020
1 parent 423af74 commit 0623f99
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 24 deletions.
37 changes: 15 additions & 22 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4834,38 +4834,31 @@ protected static function getRecurringContributionDescription($contribution, $ev
*
* Replace with Order.create->Payment.create flow.
*
* @param array $contributions
* @param array $contribution
*
* @throws \CiviCRM_API3_Exception
*/
public static function addPayments($contributions) {
public static function addPayments($contribution) {
// get financial trxn which is a payment
$ftSql = "SELECT ft.id, ft.total_amount
FROM civicrm_financial_trxn ft
INNER JOIN civicrm_entity_financial_trxn eft ON eft.financial_trxn_id = ft.id AND eft.entity_table = 'civicrm_contribution'
WHERE eft.entity_id = %1 AND ft.is_payment = 1 ORDER BY ft.id DESC LIMIT 1";
$contributionStatus = CRM_Core_PseudoConstant::get('CRM_Contribute_DAO_Contribution', 'contribution_status_id', [
'labelColumn' => 'name',

$ftDao = CRM_Core_DAO::executeQuery($ftSql, [
1 => [
$contribution->id,
'Integer',
],
]);
foreach ($contributions as $contribution) {
if ($contributionStatus[$contribution->contribution_status_id] !== 'Partially paid') {
continue;
}
$ftDao = CRM_Core_DAO::executeQuery($ftSql, [
1 => [
$contribution->id,
'Integer',
],
]);
$ftDao->fetch();
$ftDao->fetch();

// store financial item Proportionaly.
$trxnParams = [
'total_amount' => $ftDao->total_amount,
'contribution_id' => $contribution->id,
];
self::assignProportionalLineItems($trxnParams, $ftDao->id, $contribution->total_amount);
}
// store financial item Proportionaly.
$trxnParams = [
'total_amount' => $ftDao->total_amount,
'contribution_id' => $contribution->id,
];
self::assignProportionalLineItems($trxnParams, $ftDao->id, $contribution->total_amount);
}

/**
Expand Down
2 changes: 2 additions & 0 deletions CRM/Core/BAO/CustomField.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,8 @@ public static function create($params) {
* Array of arrays as would be passed into create
* @param array $defaults
* Default parameters to be be merged into each of the params.
*
* @throws \CiviCRM_API3_Exception
*/
public static function bulkSave($bulkParams, $defaults = []) {
$addedColumns = $sql = $tables = $customFields = [];
Expand Down
6 changes: 5 additions & 1 deletion CRM/Event/Form/Participant.php
Original file line number Diff line number Diff line change
Expand Up @@ -1410,10 +1410,14 @@ public function submit($params) {
$lineItem[$this->_priceSetId][$lineKey] = $line;
}
CRM_Price_BAO_LineItem::processPriceSet($participants[$num]->id, $lineItem, CRM_Utils_Array::value($num, $contributions, NULL), 'civicrm_participant');
CRM_Contribute_BAO_Contribution::addPayments($contributions);
}
}
}
foreach ($contributions as $contribution) {
if ('Partially paid' === CRM_Core_PseudoConstant::getName('CRM_Contribute_BAO_Contribution', 'contribution_status_id', $contribution->contribution_status_id)) {
CRM_Contribute_BAO_Contribution::addPayments($contribution);
}
}
}

$updateStatusMsg = NULL;
Expand Down
2 changes: 1 addition & 1 deletion tests/phpunit/CRM/Contribute/BAO/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -683,7 +683,7 @@ public function testAddPayments() {
// want to deprecate & remove & the test relies on bad data asa starting point.
// End goal is the Order.create->Payment.create flow.
CRM_Core_DAO::executeQuery('DELETE FROM civicrm_entity_financial_trxn WHERE entity_table = "civicrm_financial_item"');
CRM_Contribute_BAO_Contribution::addPayments([$contribution]);
CRM_Contribute_BAO_Contribution::addPayments($contribution);
$this->checkItemValues($contribution);
}

Expand Down

0 comments on commit 0623f99

Please sign in to comment.