{% load club %}
{% block content %}
- <p>Aktywne miesięczne wpłaty: {% club_active_monthly_count %} sztuk, {% club_active_monthly_sum %} zł.</p>
+ <table class="table">
+ <tr>
+ <td>Aktywne miesięczne wpłaty cykliczne:</td>
+ <td>{% club_active_monthly_count %} sztuk</td>
+ <td>{% club_active_monthly_sum %} zł.</td>
+ </tr>
+ <tr>
+ <td>Aktywne roczne wpłaty cykliczne:</td>
+ <td>{% club_active_yearly_count %} sztuk</td>
+ <td>{% club_active_yearly_sum %} zł.</td>
+ </tr>
+ <tr>
+ <td>Jednorazowe wpłaty w ciągu ostatnich 30 dni:</td>
+ <td>{% club_active_30day_count %} sztuk</td>
+ <td>{% club_active_30day_sum %} zł.</td>
+ </tr>
+ </table>
{{ block.super }}
{% endblock content %}
# This file is part of Wolnelektury, licensed under GNU Affero GPLv3 or later.
# Copyright © Fundacja Nowoczesna Polska. See NOTICE for more information.
#
+from datetime import timedelta
from django.db.models import Sum
from django import template
from django.utils.timezone import now
@register.simple_tag
def club_active_monthly_count():
- return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).count()
+ return Schedule.objects.filter(
+ expires_at__gt=now(),
+ monthly=True,
+ is_cancelled=False
+ ).count()
@register.simple_tag
def club_active_monthly_sum():
- return Schedule.objects.filter(expires_at__gt=now(), monthly=True, is_cancelled=False).aggregate(s=Sum('amount'))['s']
+ return Schedule.objects.filter(
+ expires_at__gt=now(),
+ monthly=True,
+ is_cancelled=False
+ ).aggregate(s=Sum('amount'))['s'] or 0
+@register.simple_tag
+def club_active_yearly_count():
+ return Schedule.objects.filter(
+ expires_at__gt=now(),
+ yearly=True,
+ is_cancelled=False
+ ).count()
+
+@register.simple_tag
+def club_active_yearly_sum():
+ return Schedule.objects.filter(
+ expires_at__gt=now(),
+ yearly=True,
+ is_cancelled=False
+ ).aggregate(s=Sum('amount'))['s'] or 0
+
+@register.simple_tag
+def club_active_30day_count():
+ return Schedule.objects.filter(
+ yearly=False, monthly=False,
+ payed_at__gte=now() - timedelta(days=30)
+ ).count()
+
+@register.simple_tag
+def club_active_30day_sum():
+ return Schedule.objects.filter(
+ yearly=False, monthly=False,
+ payed_at__gte=now() - timedelta(days=30)
+ ).aggregate(s=Sum('amount'))['s'] or 0