Skip to content

Commit

Permalink
add profit column, change colors
Browse files Browse the repository at this point in the history
  • Loading branch information
marosmola committed Oct 31, 2020
1 parent db87a1f commit ee95015
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 29 deletions.
16 changes: 11 additions & 5 deletions teachers/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ def changelist_view(self, request, extra_context=None):
month_year = "{}-{}".format(salary['month'].month, salary['month'].year)
data[month_year] = {
"salaries": salary['total'],
"fees": 0
"fees": 0,
"profit": salary['total']
}

for fee in monthly_fees:
month_year = "{}-{}".format(fee['month'].month, fee['month'].year)
data[month_year]['fees'] = fee['total']

if month_year in data:
data[month_year]['fees'] = fee['total']
data[month_year]['profit'] = data[month_year]['salaries'] - fee['total']
else:
data[month_year]['salaries'] = 0
data[month_year]['fees'] = fee['total']
data[month_year]['profit'] = 0 - fee['total']

# Prepare data to graph format
labels, salaries, fees = ([] for i in range(3))
Expand All @@ -141,11 +147,11 @@ def changelist_view(self, request, extra_context=None):
'labels': labels,
'datasets': [{
'label': "Teacher",
'backgroundColor': "blue",
'backgroundColor': "#F5DD5D",
'data': salaries
}, {
'label': "Student",
'backgroundColor': "red",
'backgroundColor': "#44B78B",
'data': fees
}]
}
Expand Down
54 changes: 30 additions & 24 deletions teachers/templates/admin/sale_summary_change_list.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{% extends 'admin/change_list.html' %}
{% block content_title %}
<h1>Finance Summary </h1>
<h1>Finance Summary</h1>
{% endblock %}

{% load humanize %}
Expand All @@ -11,29 +11,35 @@ <h1>Finance Summary </h1>
<table>
<thead>
<tr>
<th>
<th style="padding: 8px;">
<div class=”text”>
Month
</div>
</th>
<th>
<th style="padding: 8px;">
<div class=”text”>
Salaries
</div>
</th>
<th>
<th style="padding: 8px;">
<div class=”text”>
Fees
</div>
</th>
<th style="padding: 8px;">
<div class=”text”>
<strong>Profit</strong>
</div>
</th>
</tr>
</thead>
<tbody>
{% for key, value in data.items %}
<tr class="{% cycle 'row1' 'row2' %}">
<td> {{ key }} </td>
<td> {{ value.salaries }} </td>
<td> {{ value.fees }} </td>
<td>{{ key }}</td>
<td>{{ value.salaries }}</td>
<td>{{ value.fees }}</td>
<td><strong>{{ value.profit }}</strong></td>
</tr>
{% endfor %}
</tbody>
Expand All @@ -42,25 +48,25 @@ <h1>Finance Summary </h1>

<script src="https://cdn.jsdelivr.net/npm/chart.js@2.8.0"></script>
<script type="text/javascript">
var ctx = document.getElementById("myChart").getContext("2d");
var data = JSON.parse("{{ graph_data | escapejs }}")
var ctx = document.getElementById("myChart").getContext("2d");
var data = JSON.parse("{{ graph_data | escapejs }}")

var myBarChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
responsive: false,
barValueSpacing: 20,
scales: {
yAxes: [{
ticks: {
min: 0,
}
}]
var myBarChart = new Chart(ctx, {
type: 'bar',
data: data,
options: {
responsive: false,
barValueSpacing: 20,
scales: {
yAxes: [{
ticks: {
min: 0,
}
}]
}
}
}
});
});

</script>
{% endblock %}
{% block pagination %}{% endblock %}
{% block pagination %}{% endblock %}

0 comments on commit ee95015

Please sign in to comment.