The tool can now update payment history.

This commit is contained in:
JohnKent
2019-07-10 22:57:55 -04:00
parent 717210636d
commit af033464ad

72
web.py
View File

@@ -1,4 +1,4 @@
from flask import Flask, render_template, request, redirect, url_for
from flask import Flask, render_template, request, redirect
import json
from decimal import *
from datetime import *
@@ -32,15 +32,72 @@ def hello():
else:
return redirect('/?loan=' + loans[0]['filename'])
loan = loadLoanInformation('/Users/john/PycharmProjects/mortgage/' + filename)
loan = loadLoanInformation(getFullPathofLoanFile(filename))
amortizeLoan(loan)
return render_template('main.html', filename=filename, loans=loans, model=loan)
@app.route('/update_file')
@app.route('/update_file', methods=['POST'])
def update_file():
loanFile = request.form['loan']
return redirect( '/?loan=' + loan )
messages = []
loanFile = request.form["loan"]
data = getDatastore(getFullPathofLoanFile(loanFile))
payment_history = data["payments"]
if 'date' in request.form:
if (request.form['date'] == ''):
now = datetime.now()
payment_date = str(now.strftime("%Y-%m-%d"))
messages.append("No date was provided. Assuming today's date of " + payment_date + ".")
else:
payment_date = request.form['date']
messages.append("Date provided: " + payment_date + ".")
else:
now = datetime.now()
payment_date = str(now.strftime("%Y-%m-%d"))
payment_amount = Decimal('0.00')
proceed_flag = True
if 'amount' in request.form:
if (request.form['amount'] != ''):
try:
payment_amount = Decimal(request.form['amount'])
messages.append("Amount provided: " + str(payment_amount) + ".")
except:
payment_amount = Decimal('0.00')
messages.append("The amount provided could not be interpreted. Your payment was not recorded.")
proceed_flag = False
else:
pass
if proceed_flag is True:
try:
backup_filename = loanFile + ".backup-" + datetime.now().strftime("%Y-%m-%d %H-%M-%S")
backup_file = open(getFullPathofLoanFile(backup_filename), 'w+')
json.dump(data, backup_file)
backup_file.close()
except:
messages.append("A backup file could not be created. Your payment was not recorded.")
proceed_flag = False
else:
messages.append("A backup of your file was created: '" + backup_filename +"'" )
if proceed_flag is True:
try:
payment_history.append( [payment_date, str(payment_amount)])
file = open(getFullPathofLoanFile(loanFile), 'w+')
json.dump(data, file)
file.close()
except:
messages.append("An error occurred writing to the file. Your payment file may be corrupt, " + \
"please consider rolling back to the backup created above.")
else:
messages.append("The payment was successfully written. ")
return render_template('add.html', filename=loanFile, messages=messages)
@app.route('/send_statement', methods=['POST'])
def send_statement():
@@ -49,7 +106,7 @@ def send_statement():
message = request.form["message"]
style = request.form["style"]
loan = loadLoanInformation('/Users/john/PycharmProjects/mortgage/' + loanFile)
loan = loadLoanInformation(getFullPathofLoanFile(loanFile))
amortizeLoan(loan)
reportCreated = False
@@ -89,6 +146,9 @@ def addLoan(loanName, fileName):
x['filename'] = fileName
return x
def getFullPathofLoanFile(filename):
return '/Users/john/PycharmProjects/mortgage/' + filename
###################
# from old code #
###################