Updated files to produce current daily interest accrual information.

This commit is contained in:
john
2024-05-20 17:54:42 -04:00
parent d9d62a09b5
commit d6bd844d5d
2 changed files with 33 additions and 30 deletions

View File

@@ -37,7 +37,7 @@
});
});
</script>
</p>
<p></p>
<div id="tabs">
<ul>
<li><a href="#loan_information">Loan Information</a></li>
@@ -68,9 +68,10 @@
<tr><td><b>Term: </b></td><td>{{model.parameters.periods }} months </td></tr>
<tr><td><b>Next Payment Due Date:</b></td><td> {{model.parameters.next_due_date}} </td></tr>
<tr><td><b>Payment Due:</b></td><td> {{ "$%.2f"|format(model.parameters.next_payment_amt) }} </td></tr>
<tr><td><b>Daily Interest Accrual:</b></td><td> {{ "$%.2f"|format(model.current_daily_interest_accrual) }}</td></tr>
</tbody>
</table>
<p/>
<p></p>
</div>
<div id="loan_history">
<table border="1px" align="center">
@@ -79,7 +80,7 @@
<th colspan="9">Loan History</th>
</tr>
<tr>
<th width='5%'>#</td>
<th width='5%'>#</th>
<th width='10%'>Due Date</th>
<th width='10%'>Date Paid</th>
<th width='10%'>Days Interest</th>
@@ -104,18 +105,18 @@
<td align='right'> {{ "$%.2f"|format(item.new_balance) }} </td>
</tr>
{% if item.month == 12 or loop.last %}
<tr><td colspan='9'"> 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 %}
{% endfor %}
<tr><td colspan='9'"> 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>
</table>
</div>
<div id="loan_accounting">
<h3>Loan Accounting</h3>
<textarea border="1px" width="70%" cols="120" rows="25">
{% for item in model.past_payments %}
{{item.payment_date }} * "{{item.payee}}" "{{item.payee}} Mortgage Payment {{ item.payment_number}}"
{% for item in model.past_payments | reverse %}
{{item.payment_date }} * "{{item.payee}}" "{{item.payee}} Mortgage Payment {{ item.payment_number}}"
{{item.payment_account}} {{ "%.2f"|format(item.payment_amount * -1) }} USD
{{item.loan_account}} {{ "%.2f"|format(item.principal_payment) }} USD
{{item.interest_account}} {{ "%.2f"|format(item.interest_payment) }} USD
@@ -162,7 +163,7 @@
<tr><td align="center" bgcolor="darkgrey">Generate and Send Statement</td></tr>
<tr><td>Send From: {{model.email.from_address}}<br/>Send To: {{model.email.to_address}}</td></tr>
<tr><td bgcolor="beige">Subject:</td></tr>
<tr><td align="center"><textarea type="text" cols="120" name="subject">{{model.email.subject}}</textarea></td></tr>
<tr><td align="center"><textarea cols="120" name="subject">{{model.email.subject}}</textarea></td></tr>
<tr><td bgcolor="beige">Message:</td></tr>
<tr><td align="center"><textarea rows="8" cols="120" name="message">{{model.email.body}}</textarea></td></tr>
<tr><td bgcolor="beige">Send Statement As:</td></tr>
@@ -187,7 +188,7 @@
<table align="center" border="1px" width="75%">
<tr><td align="center" bgcolor="darkgrey">Record a Payment</td></tr>
<tr><td bgcolor="beige">Payment Date:</td></tr>
<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><input type="text" name="amount"></td></tr>
<tr><td bgcolor="beige">Late Fee Amount:</td></tr>
@@ -203,7 +204,7 @@
<table align="center" border="1px" width="75%">
<tr><td align="center" bgcolor="darkgrey">Record an Extra Payment</td></tr>
<tr><td bgcolor="beige">Payment Date:</td></tr>
<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><input type="text" name="amount"></td></tr>
<tr><td><input name="notify" type="checkbox" value="notify"/>Send Payment Recorded Notification</td></tr>

View File

@@ -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__':