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

fix broken custom payment history #448 #449

Merged
merged 2 commits into from
Dec 30, 2024

Conversation

beesaferoot
Copy link
Contributor

@beesaferoot beesaferoot commented Dec 22, 2024

Brief summary of the change made

Fixes payment history display on customer detail page. Closes #448

Are there any other side effects of this change that we should be aware of?

Describe how you tested your changes?

Pull Request checklist

Please confirm you have completed any of the necessary steps below.

  • Meaningful Pull Request title and description
  • Changes tested as described above
  • Added appropriate documentation for the change.
  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

@beesaferoot beesaferoot requested a review from dmohns December 23, 2024 09:31
@@ -36,7 +36,7 @@ public function transaction(): BelongsTo {
public function getFlow(string $payer_type, int $payer_id, string $period, $limit = null, string $order = 'ASC') {
$sql = 'SELECT sum(amount) as amount, payment_type, CONCAT_WS("/", '.$period.') as aperiod from'.
' payment_histories where payer_id=:payer_id and payer_type=:payer_type '.
'GROUP by concat( '.$period.'), payment_type ORDER BY created_at '.$order;
'GROUP by aperiod, payment_type ORDER BY aperiod '.$order;
Copy link
Member

@dmohns dmohns Dec 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we should change the ORDER BY clause here. Because then the result is weird. For example:

image

It get's ordered lexiographically. And then it doesn't match a timeline

image

(12-2023 appearing in the middle of 2024)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch! Had to remove created_at to get the query to work. Now that I understand this better I think I could get this work.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the error is very misleading in this situation. The ORDER BY created_at has nothing to do with the error, even though the error suggest it 😛.

In fact, if you remove the ORDER BY created_at entirely, the error still persists.

It's only about the GROUP BY clause.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to order by created_at, the bar chart is now orderly correctly.

Screenshot 2024-12-28 at 8 18 29 PM

@dmohns
Copy link
Member

dmohns commented Dec 23, 2024

Adding a little more context as to why this issue started appearing.

In #385 we introduced strict mode for Tenant databases. In this mode, all columns in the SELECT clause must either appear in the GROUP BY clause or be used in an aggregate function.

That's why

"SQLSTATE[42000]: Syntax error or access violation: 1055 'DemoCompany_1.payment_histories.created_at' isn't in GROUP BY"

started to appear.

@beesaferoot beesaferoot force-pushed the fix-customer-page-payment-history branch from 3d7ecea to b8d131c Compare December 28, 2024 19:15
@beesaferoot
Copy link
Contributor Author

@munyanezaarmel Please help review this fix.

@beesaferoot beesaferoot merged commit 2d65345 into main Dec 30, 2024
11 checks passed
@beesaferoot beesaferoot deleted the fix-customer-page-payment-history branch December 30, 2024 08:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug]: Customer Detail Payment History is broken
3 participants