Updated the template to print the correct interest information. Fixed logic in script to send correct interest information to the template. Added ability to do a test run to a different email address with a real data file (the debug flag replaces the email address with a hard coded one). Added an aborting checking that the payments are listed in order.

This commit is contained in:
JohnKent
2019-03-05 00:09:56 -05:00
parent f5c78ca7dc
commit 4dae3256c5
3 changed files with 25 additions and 8 deletions

View File

@@ -114,6 +114,13 @@ def amortizeLoan(loan):
payment_date = datetime.strptime((payment[0]), '%Y-%m-%d').date()
payment_amount = Decimal(payment[1]).quantize(Decimal("1.00"))
days_since_last_payment = (payment_date - interest_paid_through_date).days
#check for out of order payments, generally a sign of a data entry problem, especially years
if days_since_last_payment < 0:
print "Payment Number %s appears out of order. The payment date '%s' is before the previous payment on '%s'." \
% (payment_number, payment_date, interest_paid_through_date)
quit()
new_interest = (days_since_last_payment * remaining_principal * daily_interest_rate).quantize(Decimal("0.00"))
new_principal = payment_amount - new_interest
interest_paid_through_date = payment_date
@@ -121,6 +128,7 @@ def amortizeLoan(loan):
annual_interest = annual_interest + new_interest
remaining_principal = remaining_principal - new_principal
# create the payment record for the template to render
payment_record = {}
payment_record['year']=next_bill_date.year
@@ -143,6 +151,7 @@ def amortizeLoan(loan):
if old_bill_date.month < 12:
next_bill_date = date(year=old_bill_date.year, month=old_bill_date.month + 1, day=payment_day_of_month)
else:
annual_interest = Decimal("0.00")
next_bill_date = date(year=old_bill_date.year + 1, month=1, day = payment_day_of_month)
loan["total_interest_paid_to_date"] = total_interest
@@ -278,10 +287,14 @@ def main():
# at closing. The first payment will incur interest from one month before the bill is due.
# read in the file
test_flag = True
#test_flag = False
test_address = 'jkent3rd@yahoo.com'
filename = "./testloan.json"
# filename = "./10Kloan.json"
# filename = "./dadmortgage.json"
# filename = "./brendamortgage.json"
#filename = "./10Kloan.json"
#filename = "./dadmortgage.json"
#filename = "./brendamortgage.json"
#filename = "./greenfield_mortgage.json"
template_filename = "statement.pdf.jinja"
@@ -299,8 +312,10 @@ def main():
emailParameters = loan["email"]
msg = generateEmail(emailParameters["from_address"], emailParameters["to_address"], emailParameters["subject"],
emailParameters["body"], pdfAttachment, report)
sendEmail(msg, emailParameters["from_address"], emailParameters["to_address"], emailParameters['password'])
if test_flag == False:
sendEmail(msg, emailParameters["from_address"], emailParameters["to_address"], emailParameters['password'])
else:
sendEmail(msg, emailParameters["from_address"], test_address, emailParameters['password'])
if __name__ == '__main__':
main()

View File

@@ -43,7 +43,7 @@
<td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td>
</tr>
{% if item.month == '12' or loop.last %}
{% if item.month == 12 or loop.last %}
<tr><td colspan='8'"> Total interest paid in {{item.year}} is {{ "$%.2f"|format(item.annual_interest_to_date) }}.</td></tr>
{% endif %}
{% endfor %}

View File

@@ -4,7 +4,7 @@
"format": "html",
"email": {
"from_address": "jkent3rd@gmail.com",
"to_address": "jkent3rd@yahoo.com",
"to_address": "jkent3rd@gmail.com",
"server": "smtp.gmail.com",
"password": "pvyrbcnzrjoizprn",
"template": "./template.txt",
@@ -38,7 +38,9 @@
["2018-09-26", "589.00"],
["2018-10-15", "0"],
["2018-11-29", "589.00"],
["2018-12-31", "589.00"]
["2018-12-31", "589.00"],
["2019-01-28", "589.00"],
["2019-03-15", "589.00"]
],
"borrower": {
"name": "Bear Houses, LLC",