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

Make getTotalPayments return 0 instead of NULL #16129

Merged
merged 1 commit into from
Jan 24, 2020

Conversation

mattwire
Copy link
Contributor

Overview

When the sum of all payments on a contribution = 0 the function returns NULL because it's returning the result of an SQL query. But that's not much use and means we have to do extra work to coalesce NULL into 0 when coding.

Before

NULL returned if no payments made on a contribution.

After

0 returned if no payments made on a contribution.

Technical Details

NULL != 0! Especially for money. This makes the function return what you'd expect it to return.

Comments

@eileenmcnaughton Related to #16025

@civibot
Copy link

civibot bot commented Dec 20, 2019

(Standard links)

@civibot civibot bot added the master label Dec 20, 2019
@eileenmcnaughton
Copy link
Contributor

@mattwire I agree with this but changing to returning float could break any strict comparisons. I think it's only called twice outside tests so I put up this PR to explicitly cast in one to be sure. The other is the dreaded subtractCurrencies....

@eileenmcnaughton
Copy link
Contributor

@mattwire - so the only other thing this feeds is subtract currencies. I'm not too sure what effect changing to a float will have there

@civicrm civicrm deleted a comment from eileenmcnaughton Jan 9, 2020
@mattwire
Copy link
Contributor Author

@eileenmcnaughton I've updated this slightly so that getTotalPayments() doesn't do the ? 0 check as we are now expecting a float. The subtractCurrencies function will handle either string or float as input as it checks via is_numeric before using the input parameters as floats.

If tests pass I think this is good to merge?

@mattwire mattwire added the merge ready PR will be merged after a few days if there are no objections label Jan 13, 2020
@eileenmcnaughton
Copy link
Contributor

I haven't gotten my head around it bu @agileware-fj might have

@jitendrapurohit
Copy link
Contributor

r-jira - Pass
r-test - Pass
r-code -

I think it should be fine with just

return (float) CRM_Core_DAO::singleValueQuery($sql, [
   1 => [$contributionID, 'Integer'],
   2 => [implode(',', $statusIDs), 'CommaSeparatedIntegers'],
]);

instead of assigning it to $totalAmount and then returning the variable? Thoughts @mattwire ?

r-run - Pass

Tested by calling this function at different stages of a payment (Pending, Pending refund, Partially Paid, etc). It returns the correct total amount in all the cases.

r-users - Pass
r-technical - Pass
r-maint - Pass
r-doc - Pass

@eileenmcnaughton
Copy link
Contributor

@mattwire please go ahead & merge once you have considered @jitendrapurohit's feedback

@mattwire
Copy link
Contributor Author

@jitendrapurohit Thanks for the review - you are right. Merge on pass

@mattwire mattwire added merge on pass and removed merge ready PR will be merged after a few days if there are no objections labels Jan 23, 2020
@seamuslee001 seamuslee001 merged commit e4bf580 into civicrm:master Jan 24, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants