Skip to content

Commit

Permalink
Sort payments correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
pingiun committed Nov 17, 2024
1 parent 0f52137 commit ac138fc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/Entity/Member.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use App\Entity\Membership\MembershipStatus;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\Common\Collections\{ ArrayCollection, Collection };
use Doctrine\Common\Collections\{ArrayCollection, Collection, Criteria, Order};
use Symfony\Component\Validator\Constraints as Assert;
use DateTime;
use Symfony\Component\Security\Core\User\UserInterface;
Expand Down Expand Up @@ -255,6 +255,13 @@ public function getPaidContributionPayments(): Collection { return $this->contri

public function getContributionPayments(): Collection { return $this->contributionPayments; }

public function getLastContributionPaymentsForListing(): Collection
{
$criteria = Criteria::create()
->orderBy(["paymentTime" => Order::Descending])->setMaxResults(5);
return $this->contributionPayments->matching($criteria)->filter(fn($payment) => $payment->getStatus() == ContributionPayment::STATUS_PAID);
}

public function isAdmin(): bool { return in_array('ROLE_ADMIN', $this->getRoles()); }
public function setIsAdmin(bool $isAdmin): void {
if ($isAdmin)
Expand Down
2 changes: 1 addition & 1 deletion templates/user/details.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@
</tr>
</thead>
<tbody>
{% for contributionPayment in app.user.paidContributionPayments[:5] %}
{% for contributionPayment in app.user.getLastContributionPaymentsForListing %}
<tr>
<td>{{ contributionPayment.paymentTime|format_date('long') }}</td>
<td>{{ contributionPayment.amountInCents|format_price }}</td>
Expand Down

0 comments on commit ac138fc

Please sign in to comment.