-
Notifications
You must be signed in to change notification settings - Fork 16
Creditor simple stats #226
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
base: master
Are you sure you want to change the base?
Changes from 5 commits
9fff458
d71e068
c87f367
9b5defc
855b384
4a33915
383ef14
82bf0ac
e059375
f7a8e7c
eb61c4e
f8324c7
331ba90
25dac00
462dbd8
7ae25b0
6cb680b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
{% extends "admin/base.html" %} | ||
|
||
{% load i18n %} | ||
|
||
|
||
{% block extrastyle %} | ||
<style> | ||
@media print | ||
{ | ||
.no-print, .no-print * | ||
{ | ||
display: none !important; | ||
} | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
|
||
{% block title %} {{ site_title|default:_('Django site admin') }}{% endblock %} | ||
|
||
|
||
|
||
{% block content %} | ||
|
||
<div style="float: right; max-width:400px"> | ||
|
||
<h3>{% trans "Filter by transaction types" %}</h3> | ||
<span><a style="display: inline-block; margin-right: 10px;" href="{% url 'table_m' year=year month=month %}">{% trans "All types" %}</a></span> | ||
{% for t in tags %} | ||
{% if t.pk = tag_pk %} | ||
<span style="border: solid 2pt red; display: inline-block; margin-right: 10px"><a href="{% url 'table_m' year=year month=month tag=t.pk|stringformat:"i" %}">{{ t.label }}</a></span> | ||
{% else %} | ||
<span><a style="display: inline-block; margin-right: 10px;" href="{% url 'table_m' year=year month=month tag=t.pk|stringformat:"i" %}">{{ t.label }}</a></span> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
<h3>{% trans "Month selection" %}</h3> | ||
<table> | ||
{% for y in years %} | ||
<tr> | ||
{% if tag %} | ||
<th><a href="{% url 'table_y' year=y tag=tag_pk %}">{{ y }}</a></th> | ||
{% else %} | ||
<th><a href="{% url 'table_y' year=y %}">{{ y }}</a></th> | ||
{% endif %} | ||
{% for m in months %} | ||
{% if y = year and m = month %} | ||
<td style="border: solid 2pt red;"><a href="{% url 'table_m' year=y month=m tag=tag_pk %}">{{ m }}</a></td> | ||
{% else %} | ||
<td><a href="{% url 'table_m' year=y month=m tag=tag_pk %}">{{ m }}</a></td> | ||
{% endif %} | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
|
||
|
||
<h1>{{ month }}-{{ year }} {{ tag.label }}</h1> | ||
|
||
<h3>{% trans "Summary" %}</h3> | ||
<table> | ||
<tr><th>{% trans "Income" %}</th><td>{{ income.sum }}</td></tr> | ||
<tr><th>{% trans "Receivables" %}</th><td>{{ receivables.sum }}</td></tr> | ||
<tr><th>{% trans "Balance" %}</th><td>{{ total.sum }}</td></tr> | ||
</table> | ||
|
||
|
||
<h3>{% trans "Frequency table" %}</h3> | ||
<table> | ||
<tr> | ||
<th>{% trans "Amount" %}</th> | ||
<th>{% trans "Freq" %}</th> | ||
</tr> | ||
{% for f in freq_table %} | ||
<tr> | ||
<th>{{ f.amount }}</th> | ||
<td>{{ f.freq }}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
|
||
|
||
<h3>{% trans "Transactions" %}</h3> | ||
|
||
<table> | ||
{% for list_item in object_list %} | ||
<tr> | ||
<td>{{ list_item.owner }}</td> | ||
{% if list_item.amount < 0 %}<td style="color: red;">{{ list_item.amount }}</td> | ||
{% else %}<td style="color: green;">+{{ list_item.amount }}</td>{% endif %} | ||
<td>{{ list_item.tag }}</td> | ||
<td>{{ list_item.stamp }}</td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
{% endblock content %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
{% extends "admin/base.html" %} | ||
|
||
{% load i18n %} | ||
{% load aggregation_utils %} | ||
|
||
{% block extrastyle %} | ||
<style> | ||
@media print | ||
{ | ||
.no-print, .no-print * | ||
{ | ||
display: none !important; | ||
} | ||
} | ||
</style> | ||
{% endblock %} | ||
|
||
|
||
{% block title %} {{ site_title|default:_('Django site admin') }}{% endblock %} | ||
|
||
|
||
{% block content %} | ||
|
||
|
||
<div style="float: right; max-width:400px"> | ||
|
||
<h3>{% trans "Filter by transaction types" %}</h3> | ||
<span><a style="display: inline-block; margin-right: 10px;" href="{% url 'table_y' year=year %}">{% trans "All types" %}</a></span> | ||
{% for t in tags %} | ||
{% if t.pk = tag_pk %} | ||
<span style="border: solid 2pt red; display: inline-block; margin-right: 10px"><a href="{% url 'table_y' year=year tag=t.pk|stringformat:"i" %}">{{ t.label }}</a></span> | ||
{% else %} | ||
<span><a style="display: inline-block; margin-right: 10px;" href="{% url 'table_y' year=year tag=t.pk|stringformat:"i" %}">{{ t.label }}</a></span> | ||
{% endif %} | ||
{% endfor %} | ||
|
||
|
||
<h3>{% trans "Month selection" %}</h3> | ||
<table> | ||
{% for y in years %} | ||
<tr> | ||
<th><a href="{% url 'table_y' year=y tag=tag_pk %}">{{ y }}</a></th> | ||
{% for m in months %} | ||
<td><a href="{% url 'table_m' year=y month=m tag=tag_pk %}">{{ m }}</a></td> | ||
{% endfor %} | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
</div> | ||
|
||
<div style="clear: left"> | ||
|
||
|
||
|
||
<h1>{{ year }} {{ tag.label }}</h1> | ||
|
||
<h3>{% trans "Summary" %}</h3> | ||
<p>{% trans "Year" %} {{ year }}</p> | ||
|
||
<table border="1"> | ||
<tr> | ||
<th>{% trans "Month" %}</th> | ||
<th>{% trans "Income" %}</th> | ||
<th>{% trans "Receivables" %}</th> | ||
<th>{% trans "Total" %}</th> | ||
</tr> | ||
{% for m in months %} | ||
<tr> | ||
<th><a href="{% url 'table_m' year=year month=m tag=tag_pk %}">{{ m }}</a></th> | ||
<td><span style="color: green;">{{income|month_sum_value:m}}</span></td> | ||
<td><span style="color: red;">{{receivables|month_sum_value:m}}</span></td> | ||
<td>{% if total|month_sum_value:m < 0 %}<span style="color: red;">{% else %}<span style="color: green;">{% endif %}{{total|month_sum_value:m}}</span></td> | ||
</tr> | ||
{% endfor %} | ||
</table> | ||
|
||
</div> | ||
|
||
{% endblock content %} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# -*- coding: utf-8 -*- |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
from django import template | ||
|
||
register = template.Library() | ||
|
||
@register.filter | ||
def month_sum_value(month_array, month): | ||
for d in month_array: | ||
if str(month) == d['month']: | ||
return d['sum'] | ||
return '.' | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.conf.urls import url | ||
from django.contrib.auth.decorators import permission_required | ||
|
||
from . import views | ||
|
||
urlpatterns = [ | ||
url(r'^transaction_table/$', permission_required('is_staff')(views.TransactionYearView.as_view()), name="table_y"), | ||
|
||
url(r'^transaction_table/(?P<year>[0-9]{4})/$', permission_required('is_staff')(views.TransactionYearView.as_view()), name="table_y"), | ||
url(r'^transaction_table/(?P<year>[0-9]{4})/tag=(?P<tag>[0-9]+)$', permission_required('is_staff')(views.TransactionYearView.as_view()), name="table_y"), | ||
|
||
url(r'^transaction_table/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/$', permission_required('is_staff')(views.TransactionMonthView.as_view()), name="table_m"), | ||
url(r'^transaction_table/(?P<year>[0-9]{4})/(?P<month>[0-9]{2})/tag=(?P<tag>[0-9]+)$', permission_required('is_staff')(views.TransactionMonthView.as_view()), name="table_m"), | ||
] |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,78 @@ | ||
# -*- coding: utf-8 -*- | ||
from django.shortcuts import render | ||
from django.views.generic import ListView | ||
from creditor.models import Transaction, TransactionTag | ||
from django.db.models import Sum, Count | ||
from django.utils import timezone | ||
|
||
# Create your views here. | ||
|
||
class TransactionMonthView(ListView): | ||
model = Transaction | ||
template_name = "admin/table.html" | ||
|
||
param_tag = None | ||
def get_queryset(self): | ||
|
||
self.param_year = self.kwargs['year'] | ||
self.param_month = self.kwargs['month'] | ||
|
||
if('tag' in self.kwargs and int(self.kwargs['tag']) in TransactionTag.objects.values_list('pk', flat=True)): | ||
#print(TransactionTag.objects.filter(pk=int(self.kwargs['tag']))[0]) | ||
self.param_tag = TransactionTag.objects.filter(pk=int(self.kwargs['tag']))[0] | ||
return Transaction.objects.filter(stamp__year=self.param_year).filter(stamp__month=self.param_month).filter(tag__pk=self.param_tag.pk).order_by('owner__lname','owner__fname') | ||
|
||
return Transaction.objects.filter(stamp__year=self.param_year).filter(stamp__month=self.param_month).order_by('owner__lname','owner__fname') | ||
|
||
|
||
def get_context_data(self, **kwargs): | ||
context = super(TransactionMonthView, self).get_context_data(**kwargs) | ||
context['income'] = self.get_queryset().filter(amount__gte=0).aggregate(sum=Sum('amount')) | ||
context['receivables'] = self.get_queryset().filter(amount__lt=0).aggregate(sum=Sum('amount')) | ||
context['freq_table'] = self.get_queryset().values('amount').annotate(freq=Count('amount')).order_by('-amount') | ||
context['total'] = self.get_queryset().aggregate(sum=Sum('amount')) | ||
context['year'] = self.param_year | ||
context['tag'] = self.param_tag | ||
context['tag_pk'] = 0 if self.param_tag == None else self.param_tag.pk | ||
#context['tag_label'] = self.param_tag.label | ||
context['month'] = self.param_month.rjust(2, "0") | ||
context['months'] = ['01','02','03','04','05','06','07','08','09','10','11','12'] | ||
context['years'] = [str(d.year) for d in Transaction.objects.datetimes('stamp', 'year')] | ||
context['tags'] = TransactionTag.objects.values('pk','label').order_by('pk') | ||
|
||
return context | ||
|
||
class TransactionYearView(ListView): | ||
model = Transaction | ||
template_name = "admin/table_year.html" | ||
|
||
param_year = timezone.now().year | ||
param_tag = None | ||
def get_queryset(self): | ||
|
||
if('year' in self.kwargs): | ||
self.param_year = self.kwargs['year'] | ||
|
||
# tag number must refer to existing TransactionTag | ||
if('tag' in self.kwargs and int(self.kwargs['tag']) in TransactionTag.objects.values_list('pk', flat=True)): | ||
self.param_tag = TransactionTag.objects.filter(pk=int(self.kwargs['tag']))[0] | ||
#self.tag_label = TransactionTag.objects.filter(pk=self.param_tag)[0] | ||
#self.param_tag = self.kwargs['tag'] | ||
return Transaction.objects.filter(stamp__year=self.param_year).filter(tag__pk=self.param_tag.pk) | ||
|
||
return Transaction.objects.filter(stamp__year=self.param_year) | ||
|
||
|
||
def get_context_data(self, **kwargs): | ||
context = super(TransactionYearView, self).get_context_data(**kwargs) | ||
context['receivables'] = self.get_queryset().filter(amount__lt=0).extra(select={'month': "to_char(stamp, 'MM' )"}).values('month').annotate(sum=Sum('amount')).order_by() | ||
context['income'] = self.get_queryset().filter(amount__gte=0).extra(select={'month': "to_char(stamp, 'MM' )"}).values('month').annotate(sum=Sum('amount')).order_by() | ||
context['total'] = self.get_queryset().extra(select={'month': "to_char(stamp, 'MM' )"}).values('month').annotate(sum=Sum('amount')).order_by() | ||
context['tag'] = self.param_tag | ||
context['tag_pk'] = 0 if self.param_tag == None else self.param_tag.pk | ||
#context['tag_label'] = None if self.param_tag == None else self.param_tag.label | ||
context['year'] = self.param_year | ||
context['months'] = ['01','02','03','04','05','06','07','08','09','10','11','12'] | ||
context['years'] = [d.year for d in Transaction.objects.datetimes('stamp', 'year')] | ||
context['tags'] = TransactionTag.objects.values('pk','label').order_by('pk') | ||
|
||
return context |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this should be under /admin/ -urlspace somehow ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Solution now in f7a8e7c. Though, might not be the ideal way to handle this.