Added late fee logic to calculation logic and the templates.

user: JohnKent
branch 'default'
added .hgignore
changed mortgage/templates/main.html
changed mortgage/templates/statement.html.jinja
changed mortgage/templates/statement.pdf.jinja
changed mortgage/templates/statement.text.jinja
changed mortgage/web.py
This commit is contained in:
JohnKent
2020-06-23 22:03:38 -04:00
parent 219c1ada2f
commit e5830536a1
6 changed files with 40 additions and 22 deletions

3
.hgignore Normal file
View File

@@ -0,0 +1,3 @@
./venv/
.hgignore
.Python

View File

@@ -74,17 +74,18 @@
<table border="1px" align="center"> <table border="1px" align="center">
<thead> <thead>
<tr> <tr>
<th colspan="8">Loan History</th> <th colspan="9">Loan History</th>
</tr> </tr>
<tr> <tr>
<th width='5%'>#</td> <th width='5%'>#</td>
<th width='10%'>Due Date</th> <th width='10%'>Due Date</th>
<th width='10%'>Date Paid</th> <th width='10%'>Date Paid</th>
<th width='10%'>Days Interest</th> <th width='10%'>Days Interest</th>
<th width='15%' align='right'>Payment Amt</th> <th width='12%' align='right'>Payment Amt</th>
<th width='15%' align='right'>Principal Pmt</th> <th width='12%' align='right'>Principal Pmt</th>
<th width='15%' align='right'>Interest Pmt</th> <th width='12%' align='right'>Interest Pmt</th>
<th width='20%' align='right'>New Balance</th> <th width='10%' align='right'>Late Fee</th>
<th width='24%' align='right'>New Balance</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@@ -97,13 +98,14 @@
<td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td> <td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td>
<td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.late_fee) }} </td>
<td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td> <td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td>
</tr> </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> <tr><td colspan='9'"> Total interest paid in {{item.year}} is {{ "$%.2f"|format(item.annual_interest_to_date) }}.</td></tr>
{% endif %} {% endif %}
{% endfor %} {% endfor %}
<tr><td colspan='8'"> Total interest paid to date is {{ "$%.2f"|format(model.total_interest_paid_to_date) }}.</td></tr> <tr><td colspan='9'"> Total interest paid to date is {{ "$%.2f"|format(model.total_interest_paid_to_date) }}.</td></tr>
</tbody> </tbody>
</table> </table>
</div> </div>
@@ -172,6 +174,8 @@
<tr><td><input type="date" name="date"</td></tr> <tr><td><input type="date" name="date"</td></tr>
<tr><td bgcolor="beige">Payment Amount:</td></tr> <tr><td bgcolor="beige">Payment Amount:</td></tr>
<tr><td><input type="text" name="amount"></td></tr> <tr><td><input type="text" name="amount"></td></tr>
<tr><td bgcolor="beige">Late Fee Amount:</td></tr>
<tr><td><input type="text" name="latefee"></td></tr>
<tr><td><button>Record Payment</button></td></tr> <tr><td><button>Record Payment</button></td></tr>
</table> </table>
</form> </form>

View File

@@ -27,10 +27,11 @@
<th width='10%'>Due Date</th> <th width='10%'>Due Date</th>
<th width='10%'>Date Paid</th> <th width='10%'>Date Paid</th>
<th width='10%'>Days Interest</th> <th width='10%'>Days Interest</th>
<th width='15%' align='right'>Payment Amt</th> <th width='12%' align='right'>Payment Amt</th>
<th width='15%' align='right'>Principal Pmt</th> <th width='12%' align='right'>Principal Pmt</th>
<th width='15%' align='right'>Interest Pmt</th> <th width='12%' align='right'>Interest Pmt</th>
<th width='20%' align='right'>New Balance</th> <th width='10%' align='right'>Late Fee</th>
<th width='19%' align='right'>New Balance</th>
</tr></thead> </tr></thead>
<tbody> <tbody>
{% for item in model.past_payments %} {% for item in model.past_payments %}
@@ -41,6 +42,7 @@
<td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td> <td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td>
<td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.late_fee) }} </td>
<td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td> <td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td>
</tr> </tr>
{% if item.month == 12 or loop.last %} {% if item.month == 12 or loop.last %}

View File

@@ -27,10 +27,11 @@
<th width='10%'>Due Date</th> <th width='10%'>Due Date</th>
<th width='10%'>Date Paid</th> <th width='10%'>Date Paid</th>
<th width='10%'>Days Interest</th> <th width='10%'>Days Interest</th>
<th width='15%' align='right'>Payment Amt</th> <th width='12%' align='right'>Payment Amt</th>
<th width='15%' align='right'>Principal Pmt</th> <th width='12%' align='right'>Principal Pmt</th>
<th width='15%' align='right'>Interest Pmt</th> <th width='12%' align='right'>Interest Pmt</th>
<th width='20%' align='right'>New Balance</th> <th width='10%' align='right'>Late Fee</th>
<th width='24%' align='right'>New Balance</th>
</tr></thead> </tr></thead>
<tbody> <tbody>
{% for item in model.past_payments %} {% for item in model.past_payments %}
@@ -41,6 +42,7 @@
<td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td> <td align='right'> {{ "$%.2f"|format(item.payment_amount) }} </td>
<td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.principal_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td> <td align='right'> {{ "$%.2f"|format(item.interest_payment) }} </td>
<td align='right'> {{ "$%.2f"|format(item.late_fee) }} </td>
<td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td> <td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td>
</tr> </tr>
{% if item.month == 12 or loop.last %} {% if item.month == 12 or loop.last %}
@@ -56,9 +58,9 @@
<table> <table>
<thead> <thead>
<tr> <tr>
<th width='8%'>#</th> <th width='10%'>#</th>
<th width='15%'>Due Date</th> <th width='15%'>Due Date</th>
<th width='8%'>Days Interest</th> <th width='10%'>Days Interest</th>
<th width='15%' align='right'>Payment Amt</th> <th width='15%' align='right'>Payment Amt</th>
<th width='15%' align='right'>Principal Pmt</th> <th width='15%' align='right'>Principal Pmt</th>
<th width='15%' align='right'>Interest Pmt</th> <th width='15%' align='right'>Interest Pmt</th>

View File

@@ -7,6 +7,7 @@ Payment History
Payment Amount Payment Amount
Principal Payment Principal Payment
Interest Payment Interest Payment
Late Fee
New Balance New Balance
{% for item in past_payments %} {% for item in past_payments %}
@@ -17,6 +18,7 @@ Payment History
{{ item.payment_amount }} {{ item.payment_amount }}
{{ item.principal_payment }} {{ item.principal_payment }}
{{ item.interest_payment }} {{ item.interest_payment }}
{{ item.late_fee }}
{{ item.new_balance }} {{ item.new_balance }}
{% if item.print_interest_total %} {% if item.print_interest_total %}

View File

@@ -74,9 +74,9 @@ def update_file():
if proceed_flag is True: if proceed_flag is True:
try: try:
backup_filename = loanFile + ".backup-" + datetime.now().strftime("%Y-%m-%d %H-%M-%S") backup_filename = loanFile + ".backup-" + datetime.now().strftime("%Y-%m-%d %H-%M-%S") + ".json"
backup_file = open(getFullPathofLoanFile(backup_filename), 'w+') backup_file = open(getFullPathofLoanFile(backup_filename), 'w+')
json.dump(data, backup_file) json.dump(data, backup_file, indent=2)
backup_file.close() backup_file.close()
except: except:
messages.append("A backup file could not be created. Your payment was not recorded.") messages.append("A backup file could not be created. Your payment was not recorded.")
@@ -88,7 +88,7 @@ def update_file():
try: try:
payment_history.append( [payment_date, str(payment_amount)]) payment_history.append( [payment_date, str(payment_amount)])
file = open(getFullPathofLoanFile(loanFile), 'w+') file = open(getFullPathofLoanFile(loanFile), 'w+')
json.dump(data, file) json.dump(data, file, indent=2)
file.close() file.close()
except: except:
messages.append("An error occurred writing to the file. Your payment file may be corrupt, " + \ messages.append("An error occurred writing to the file. Your payment file may be corrupt, " + \
@@ -252,6 +252,10 @@ def amortizeLoan(loan):
payment_date = datetime.strptime((payment[0]), '%Y-%m-%d').date() payment_date = datetime.strptime((payment[0]), '%Y-%m-%d').date()
payment_amount = Decimal(payment[1]).quantize(Decimal("1.00")) payment_amount = Decimal(payment[1]).quantize(Decimal("1.00"))
days_since_last_payment = (payment_date - interest_paid_through_date).days days_since_last_payment = (payment_date - interest_paid_through_date).days
if len(payment)>2:
late_fee = Decimal(payment[2]).quantize(Decimal("1.00"))
else:
late_fee = Decimal("0.00")
#check for out of order payments, generally a sign of a data entry problem, especially years #check for out of order payments, generally a sign of a data entry problem, especially years
if days_since_last_payment < 0: if days_since_last_payment < 0:
@@ -260,7 +264,7 @@ def amortizeLoan(loan):
quit() quit()
new_interest = (days_since_last_payment * remaining_principal * daily_interest_rate).quantize(Decimal("0.00")) new_interest = (days_since_last_payment * remaining_principal * daily_interest_rate).quantize(Decimal("0.00"))
new_principal = payment_amount - new_interest new_principal = payment_amount - new_interest - late_fee
interest_paid_through_date = payment_date interest_paid_through_date = payment_date
total_interest = total_interest + new_interest total_interest = total_interest + new_interest
annual_interest = annual_interest + new_interest annual_interest = annual_interest + new_interest
@@ -276,11 +280,12 @@ def amortizeLoan(loan):
payment_record['payment_date'] = payment_date payment_record['payment_date'] = payment_date
payment_record['days_of_interest'] = days_since_last_payment payment_record['days_of_interest'] = days_since_last_payment
payment_record['payment_amount'] = payment_amount payment_record['payment_amount'] = payment_amount
payment_record['principal_payment'] = payment_amount - new_interest payment_record['principal_payment'] = payment_amount - new_interest - late_fee
payment_record['interest_payment'] = new_interest payment_record['interest_payment'] = new_interest
payment_record['new_balance'] = remaining_principal payment_record['new_balance'] = remaining_principal
payment_record['interest_to_date'] = total_interest payment_record['interest_to_date'] = total_interest
payment_record['annual_interest_to_date'] = annual_interest payment_record['annual_interest_to_date'] = annual_interest
payment_record['late_fee'] = late_fee
past_payments.append(payment_record) past_payments.append(payment_record)
payment_number = payment_number + 1 payment_number = payment_number + 1