Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] Interim code cleanup - make the usage of addPayments clearer #16441

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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