Skip to content

Commit

Permalink
Add year selection to tax letter
Browse files Browse the repository at this point in the history
  • Loading branch information
mprunell committed Jan 1, 2021
1 parent 7e1ccd0 commit bee2946
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
10 changes: 7 additions & 3 deletions smallslive/static/js/white-border-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ function replaceWhiteSelects(divElement) {
$(a).click();
}
});

for (j = 0; j < selElmnt.length; j++) {
var firstIsTitle = currentSelect.classList.contains('firstistitle');
var start_j = 0;
if (firstIsTitle) {
start_j= 1;
}
for (j = start_j; j < selElmnt.length; j++) {
/*for each option in the original select element,
create a new DIV that will act as an option item:*/
c = document.createElement("DIV");
Expand All @@ -42,7 +46,7 @@ function replaceWhiteSelects(divElement) {
$(this).click();
}
});
if (option.getAttribute("noSelect") === "1") {
if (option.getAttribute("F") === "1") {
continue;
}

Expand Down
2 changes: 1 addition & 1 deletion smallslive/templates/account/tax-letter.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
The SmallsLIVE Foundation for Jazz Arts & Education thanks you for your generous donation.
Your help supports the musicians and the venues and continues our mission of presenting live jazz music in New York City.
</p>
<p>Your donation for this tax year was: ${{ charges_value }} of which {% if charges_value == deductable_value %} 100% {% else %} ${{ deductable_value }} {% endif %} is tax deductible.</p>
<p>Your donation for the {{ year }} tax year was: ${{ charges_value }} of which {% if charges_value == deductable_value %} 100% {% else %} ${{ deductable_value }} {% endif %} is tax deductible.</p>

<p>The SmallsLIVE Foundation, INC. Tax ID is 38-4083862.</p>

Expand Down
15 changes: 13 additions & 2 deletions smallslive/templates/account/user_settings_new.html
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,7 @@
You have not yet made a donation
</div>
</div>

<button href="{% url 'user_tax_letter' %}" class="white-border-button disabled" disabled>Download tax document</button>
<button class="white-border-button disabled" disabled>Download tax document</button>
{% else %}
{{ first_charge.date|date:"d/m/Y" }}: ${{ first_charge.amount }}
</div>
Expand All @@ -119,6 +118,14 @@
<div class="text5">Total donations this tax year</div>
<div class="text9 accent-color">${{ charges_value }}</div>
</div>
<div class="white-border-select spaced firstistitle">
<select id="download-tax-select">
<option value="">Download tax document</option>
<option value="2020">2020</option>
<option value="2021">2021</option>
</select>
</div>

<a href="{% url 'user_tax_letter' %}" class="white-border-button">Download tax document</a>
{% endif %}
{% endwith %}
Expand Down Expand Up @@ -266,6 +273,10 @@
$streamingDialog.modal('hide');
});

$("#download-tax-select").change(function () {
window.location = "{% url 'user_tax_letter' %}?year=" + $(this).val();
});

});

function endDonation(){
Expand Down
6 changes: 4 additions & 2 deletions smallslive/users/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,15 @@ def unsubscribe_from_newsletter(self, request=None):
def is_first_login(self):
return self.date_joined == self.last_login

def get_donations(self, this_year=True):
def get_donations(self, this_year=True, year=None):
# Assume always USD.
qs = self.donations.filter(user=self, confirmed=True)
if this_year:
if this_year or year:
current_date = timezone.now()
first_day = current_date.replace(month=1, day=1, hour=0,
minute=0, second=0, microsecond=0)
if year:
first_day = first_day.replace(year=year)
qs = qs.filter(date__gte=first_day)

return qs
Expand Down
13 changes: 9 additions & 4 deletions smallslive/users/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,9 @@ class UserTaxLetterHtml(TemplateView):
def get_context_data(self, **kwargs):
context = super(UserTaxLetterHtml, self).get_context_data(**kwargs)
customer = self.request.user.customer
customer_charges = customer.subscriber.get_donations()
year = self.request.GET.get('year', str(timezone.now().year))
year = int(year)
customer_charges = customer.subscriber.get_donations(year=year)
charges_value = 0
deductable_value = 0
for charge in customer_charges:
Expand All @@ -352,7 +354,7 @@ def get_context_data(self, **kwargs):
context['customer'] = customer
context['deductable_value'] = deductable_value
context['charges_value'] = charges_value
context['year'] = timezone.now().year
context['year'] = year

return context

Expand All @@ -368,7 +370,9 @@ class UserTaxLetter(PDFTemplateView):
def get_context_data(self, **kwargs):
context = super(UserTaxLetter, self).get_context_data(**kwargs)
customer = self.request.user.customer
customer_charges = self.request.user.get_donations()
year = self.request.GET.get('year', str(timezone.now().year))
year = int(year)
customer_charges = self.request.user.get_donations(year=year)
charges_value = 0
deductable_value = 0
for charge in customer_charges:
Expand All @@ -380,7 +384,8 @@ def get_context_data(self, **kwargs):
context['customer'] = customer
context['charges_value'] = charges_value
context['deductable_value'] = deductable_value
context['year'] = timezone.now().year
context['year'] = year

return context


Expand Down

0 comments on commit bee2946

Please sign in to comment.