diff --git a/membershipworks/views.py b/membershipworks/views.py index ab20034..9b0dafc 100644 --- a/membershipworks/views.py +++ b/membershipworks/views.py @@ -8,6 +8,8 @@ from django.db.models import OuterRef, Q, Subquery from django.db.models.functions import TruncMonth, TruncYear from django.shortcuts import render from django.template.defaultfilters import floatformat +from django.utils.html import format_html +from django.utils.safestring import SafeString from django.views.generic import DetailView, ListView from django.views.generic.dates import ( ArchiveIndexView, @@ -299,17 +301,34 @@ class InvoiceTable(tables.Table): self.event = kwargs.pop("event") super().__init__(*args, **kwargs) + @staticmethod + def _math_header(name: str, formula: str) -> SafeString: + return format_html( + '{}
[{}]
', + name, + formula, + ) + label = tables.Column("Ticket Type", footer="Subtotals") list_price = InvoiceMoneyColumn("Ticket Price") - actual_price = InvoiceMoneyColumn("Actual Price [P]") - quantity = tables.Column("Quantity [Q]", footer=lambda table: table.event.quantity) - amount = InvoiceMoneyFooterColumn("Amount [A = P * Q]") - materials = InvoiceMoneyFooterColumn("CMS Collected Materials Fee [M = m * Q]") - amount_without_materials = InvoiceMoneyFooterColumn( - "Event Revenue Base [B = A - M]" + actual_price = InvoiceMoneyColumn(_math_header("Actual Price", "P")) + quantity = tables.Column( + _math_header("Quantity", "Q"), + footer=lambda table: table.event.quantity, + ) + amount = InvoiceMoneyFooterColumn(_math_header("Amount", "A=P*Q")) + materials = InvoiceMoneyFooterColumn( + _math_header("CMS Collected Materials Fee", "M=m*Q") + ) + amount_without_materials = InvoiceMoneyFooterColumn( + _math_header("Event Revenue Base", "B=A-M") + ) + instructor_revenue = InvoiceMoneyFooterColumn( + _math_header("Instructor Percentage Revenue", "R=B*I") + ) + instructor_amount = InvoiceMoneyFooterColumn( + _math_header("Amount Due to Instructor", "R+M") ) - instructor_revenue = InvoiceMoneyFooterColumn("Instructor Revenue [R = B * I]") - instructor_amount = InvoiceMoneyFooterColumn("Amount Due to Instructor [R + M]") class Meta: attrs = {