diff --git a/mortgage/templates/main.html b/mortgage/templates/main.html index 5a6217c..72e004e 100644 --- a/mortgage/templates/main.html +++ b/mortgage/templates/main.html @@ -37,7 +37,7 @@ }); }); -

+

@@ -79,7 +80,7 @@ - @@ -104,18 +105,18 @@ {% if item.month == 12 or loop.last %} - + {% endif %} {% endfor %} - +
Loan History
# + # Due Date Date Paid Days Interest {{ "$%.2f"|format(item.new_balance) }}
Total interest paid in {{item.year}} is {{ "$%.2f"|format(item.annual_interest_to_date) }}.
Total interest paid in {{item.year}} is {{ "$%.2f"|format(item.annual_interest_to_date) }}.
Total interest paid to date is {{ "$%.2f"|format(model.total_interest_paid_to_date) }}.
Total interest paid to date is {{ "$%.2f"|format(model.total_interest_paid_to_date) }}.

Loan Accounting

+ Message: Send Statement As: @@ -187,7 +188,7 @@ - + @@ -203,7 +204,7 @@
Record a Payment
Payment Date:
Payment Amount:
Late Fee Amount:
- + diff --git a/mortgage/web.py b/mortgage/web.py index f28db28..d737b22 100644 --- a/mortgage/web.py +++ b/mortgage/web.py @@ -1,4 +1,3 @@ -import json import jinja2 import smtplib import os @@ -13,19 +12,19 @@ from email import encoders import couchdb try: - dbUserName = os.environ['COUCHDB_USERNAME'] + dbUserName = os.environ['COUCHDB_USERNAME'] except: - dbUserName = 'admin' + dbUserName = 'admin' try: - dbPassword = os.environ['COUCHDB_PW'] + dbPassword = os.environ['COUCHDB_PW'] except: - dbPassword = 'ams19230' + dbPassword = 'ams19230' try: - dbHost = os.environ['COUCHDB_HOST'] + dbHost = os.environ['COUCHDB_HOST'] except: - dbHost = 'couch.jkent.org' + dbHost = 'couch.jkent.org' connectString = f'https://{dbUserName}:{dbPassword}@{dbHost}/' print(connectString) @@ -50,7 +49,7 @@ app = Flask(__name__) @app.route('/') def hello(): - loans = getLoanFiles(database) + loans = getLoanFiles() #if a loan was not specified, choose the first loan and reload page with it if 'loan' in request.args: @@ -117,7 +116,7 @@ def update_file(): if proceed_flag is True: payment_history.append([payment_date, str(payment_amount), str(late_fee), str(extra_payment)]) - database[document_id]=document + database[document_id] = document messages.append("The payment was successfully written. ") # see if an email notification was requested, if not, exit now @@ -189,7 +188,7 @@ def send_statement(): ###### -def getLoanFiles(directory): +def getLoanFiles(): #iterate over each of the documents found in the mortgage couchdb #database and pull their display name loans = [] @@ -201,25 +200,26 @@ def getLoanFiles(directory): return loans + def createLoanEntryMenuItem(loanName, document_id): x = {} x['name'] = loanName x['document_id'] = document_id return x + ###### # Datastore Manipulation Functions ###### - def getStatementHeader(datastore): return datastore['header'] def getAccounting(datastore): try: - return datastore['accounting'] + return datastore['accounting'] except: - return {"payment_account":"", "loan_account":"", "interest_account": ""} + return {"payment_account": "", "loan_account": "", "interest_account": ""} def getEmailInformation(datastore): @@ -281,17 +281,16 @@ def getBorrower(datastore): def getDatastore(document_id=None): - if document_id == None: + if document_id is None: quit("Invalid document.") datastore = database[document_id] return datastore + ###### # Loan Calculation Functions ###### - - def amortizeLoan(loan): # loop over the payments and calculate the actual amortization monthly_payment = loan["parameters"]["monthly_payment"] @@ -331,7 +330,8 @@ def amortizeLoan(loan): % (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_daily_interest = (remaining_principal * daily_interest_rate).quantize(Decimal("0.00")) + new_interest = (days_since_last_payment * new_daily_interest).quantize(Decimal("0.00")) new_principal = payment_amount - new_interest - late_fee interest_paid_through_date = payment_date total_interest = total_interest + new_interest @@ -346,8 +346,8 @@ def amortizeLoan(loan): payment_record['bill_date'] = next_bill_date payment_record['payment_date'] = payment_date payment_record['days_of_interest'] = days_since_last_payment + payment_record['daily_interest'] = new_daily_interest payment_record['payment_amount'] = payment_amount - principal_payment = payment_amount - new_interest - late_fee payment_record['principal_payment'] = payment_amount - new_interest - late_fee payment_record['interest_payment'] = new_interest payment_record['new_balance'] = remaining_principal @@ -388,6 +388,7 @@ def amortizeLoan(loan): # loop over remaining scheduled payments and present estimated amortization while (payment_number <= total_periods) and (remaining_principal > 0): days_since_last_payment = (next_bill_date - interest_paid_through_date).days + new_daily_interest = (remaining_principal * daily_interest_rate).quantize(Decimal("0.00")) new_interest = (days_since_last_payment * remaining_principal * daily_interest_rate).quantize(Decimal("0.00")) # make sure the last payment isn't too much @@ -405,6 +406,7 @@ def amortizeLoan(loan): future_payment_record['payment_number'] = payment_number future_payment_record['payment_date'] = next_bill_date future_payment_record['days_of_interest'] = days_since_last_payment + future_payment_record['daily_interest'] = new_daily_interest future_payment_record['payment_amount'] = monthly_payment future_payment_record['principal_payment'] = new_principal future_payment_record['interest_payment'] = new_interest @@ -417,7 +419,7 @@ def amortizeLoan(loan): next_bill_date = date(year=old_bill_date.year, month=old_bill_date.month + 1, day=payment_day_of_month) else: next_bill_date = date(year=old_bill_date.year + 1, month=1, day=payment_day_of_month) - + loan["current_daily_interest_accrual"] = (remaining_principal * daily_interest_rate).quantize(Decimal("0.00")) loan["balloon_payment"] = remaining_principal loan["past_payments"] = past_payments loan["future_payments"] = future_payments @@ -529,7 +531,7 @@ def selectTemplate(formatType): def main(): app.debug = True - app.run(host = '0.0.0.0', port='8000') + app.run(host='0.0.0.0', port=8000) if __name__ == '__main__':
Record an Extra Payment
Payment Date:
Payment Amount:
Send Payment Recorded Notification