backoffice: add totals to the bottom of ticket type details table
This commit is contained in:
parent
02b796e90b
commit
a494bdfd4b
|
@ -9,17 +9,17 @@
|
||||||
<span class="h3">BackOffice - {{ camp.title }} {{ product_list.0.ticket_type.name }} Ticket Product Stats</span>
|
<span class="h3">BackOffice - {{ camp.title }} {{ product_list.0.ticket_type.name }} Ticket Product Stats</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="panel-body">
|
<div class="panel-body">
|
||||||
<p class="lead">This view shows a table of each product associated with the ticket type <b>{{ product_list.0.ticket_type.name }}</b> along with the number sold, cost, price, profit and margin for each product.</p>
|
<p class="lead">This view shows a table of each product associated with the ticket type <b>{{ product_list.0.ticket_type.name }}</b> along with the number sold, cost, price, and profit for each product.</p>
|
||||||
<table class="table table-hover datatable">
|
<table class="table table-hover datatable">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Product</th>
|
<th>Product</th>
|
||||||
<th class="text-right">Revenue</th>
|
<th class="text-right">Income</th>
|
||||||
<th class="text-right">Cost</th>
|
<th class="text-right">Cost</th>
|
||||||
<th class="text-right">Profit</th>
|
<th class="text-right">Profit</th>
|
||||||
<th class="text-center">Orders</th>
|
<th class="text-center">Orders</th>
|
||||||
<th class="text-center">Units Sold</th>
|
<th class="text-center">Units Sold</th>
|
||||||
<th class="text-right">Total Revenue</th>
|
<th class="text-right">Total Income</th>
|
||||||
<th class="text-right">Total Cost</th>
|
<th class="text-right">Total Cost</th>
|
||||||
<th class="text-right">Total Profit</th>
|
<th class="text-right">Total Profit</th>
|
||||||
</tr>
|
</tr>
|
||||||
|
@ -33,13 +33,25 @@
|
||||||
<td class="text-right">{{ p.profit|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.profit|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-center">{{ p.paid_order_count }}</td>
|
<td class="text-center">{{ p.paid_order_count }}</td>
|
||||||
<td class="text-center">{{ p.total_units_sold }}</td>
|
<td class="text-center">{{ p.total_units_sold }}</td>
|
||||||
<td class="text-right">{{ p.total_revenue|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.total_income|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-right">{{ p.total_cost|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.total_cost|floatformat:"2" }} DKK</td>
|
||||||
<td class="text-right">{{ p.total_profit|floatformat:"2" }} DKK</td>
|
<td class="text-right">{{ p.total_profit|floatformat:"2" }} DKK</td>
|
||||||
</tr>
|
</tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</tbody>
|
</tbody>
|
||||||
|
<tfoot>
|
||||||
|
<tr>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" colspan=4><b>Totals (All amounts include 25% Danish VAT)</td>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" class="text-center"><b>{{ total_orders }}</td>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" class="text-center"><b>{{ total_units }}</td>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" class="text-right"><b>{{ total_income|floatformat:"2" }} DKK</td>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" class="text-right"><b>{{ total_cost|floatformat:"2" }} DKK</td>
|
||||||
|
<td style="padding-left: 10px; padding-right: 10px" class="text-right"><b>{{ total_profit|floatformat:"2" }} DKK</td>
|
||||||
|
</tr>
|
||||||
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
<br>
|
||||||
|
<p class="lead">Note: This view only shows tickets, which are generated based on paid orders. Unpaid orders are not included here.</p>
|
||||||
<a class="btn btn-default" href="{% url 'backoffice:shop_ticket_stats' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Back to Ticket Types</a>
|
<a class="btn btn-default" href="{% url 'backoffice:shop_ticket_stats' camp_slug=camp.slug %}"><i class="fas fa-undo"></i> Back to Ticket Types</a>
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -214,3 +214,18 @@ class ShopTicketStatsDetailView(CampViewMixin, OrgaTeamPermissionMixin, ListView
|
||||||
return Product.statsobjects.with_ticket_stats().filter(
|
return Product.statsobjects.with_ticket_stats().filter(
|
||||||
ticket_type_id=self.kwargs["pk"]
|
ticket_type_id=self.kwargs["pk"]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_context_data(self, *args, **kwargs):
|
||||||
|
context = super().get_context_data(*args, **kwargs)
|
||||||
|
context["total_orders"] = 0
|
||||||
|
context["total_units"] = 0
|
||||||
|
context["total_income"] = 0
|
||||||
|
context["total_cost"] = 0
|
||||||
|
context["total_profit"] = 0
|
||||||
|
for product in context["product_list"]:
|
||||||
|
context["total_orders"] += product.paid_order_count
|
||||||
|
context["total_units"] += product.total_units_sold
|
||||||
|
context["total_income"] += product.total_income
|
||||||
|
context["total_cost"] += product.total_cost
|
||||||
|
context["total_profit"] += product.total_profit
|
||||||
|
return context
|
||||||
|
|
|
@ -400,7 +400,7 @@ class ProductStatsManager(models.Manager):
|
||||||
self.filter(orderproductrelation__order__paid=True)
|
self.filter(orderproductrelation__order__paid=True)
|
||||||
.annotate(total_units_sold=Sum("orderproductrelation__quantity"))
|
.annotate(total_units_sold=Sum("orderproductrelation__quantity"))
|
||||||
.annotate(profit=F("price") - F("cost"))
|
.annotate(profit=F("price") - F("cost"))
|
||||||
.annotate(total_revenue=F("price") * F("total_units_sold"))
|
.annotate(total_income=F("price") * F("total_units_sold"))
|
||||||
.annotate(total_cost=F("cost") * F("total_units_sold"))
|
.annotate(total_cost=F("cost") * F("total_units_sold"))
|
||||||
.annotate(total_profit=F("profit") * F("total_units_sold"))
|
.annotate(total_profit=F("profit") * F("total_units_sold"))
|
||||||
.annotate(paid_order_count=Count("orderproductrelation__order"))
|
.annotate(paid_order_count=Count("orderproductrelation__order"))
|
||||||
|
|
Loading…
Reference in a new issue