def history(): if request.method == 'GET': activeLoan = db.execute( 'SELECT * FROM loans WHERE userId = :userId and status = :status', userId=session["user_id"], status=False) payment = float(activeLoan[0]["monthlyRepayment"]) tbalance = activeLoan[0]["totalCostOfLoan"] totalInterest = activeLoan[0]["totalInterest"] tbalance = activeLoan[0]["totalCostOfLoan"] amountborrowed = activeLoan[0]["loanAmount"] loan_id = activeLoan[0]["id"] repayments_details = db.execute( 'SELECT * FROM repayment WHERE user_id = :userId and loan_id = :loan_id', userId=session["user_id"], loan_id=loan_id) return render_template("paymenthistory.html", activeLoan=activeLoan, payment=naira(payment), tbalance=naira(tbalance), repayments_details=repayments_details, totalInterest=naira(totalInterest), amountborrowed=naira(amountborrowed))
def duepayment(): if request.method == "GET": startdate = datetime.datetime.now() activeLoan = db.execute( 'SELECT * FROM loans WHERE userId = :userId and status = :status', userId=session["user_id"], status="0") date = (startdate + relativedelta(months=+1)).strftime("%x") period = activeLoan[0]["loanPeriod"] tInterest = float(activeLoan[0]["totalInterest"]) payment = float(activeLoan[0]["monthlyRepayment"]) rate = activeLoan[0]["interestRate"] loan_id = activeLoan[0]["id"] tbalance = activeLoan[0]["totalCostOfLoan"] interest = tInterest / period principal = payment - interest balances = [] dates = [] ending_balances = [] for x in range(period): due_date = (startdate + relativedelta(months=+x)).strftime("%x") balance = tbalance - (x * payment) ending_balance = tbalance - ((x + 1) * payment) balance = naira(balance) ending_balances.append(ending_balance) balances.append(balance) dates.append(due_date) # k = db.execute("INSERT INTO repayment (user_id, loan_id, due_date, begining_balance, monthly_payment, principal, interest, ending_balance, payment_proof, payment_mode) VALUES(:user_id, :loan_id, :due_date, :begining_balance, :monthly_payment, :principal, :interest, :ending_balance, :payment_proof, :payment_mode)", # user_id= session["user_id"], loan_id = loan_id, due_date = due_date, begining_balance = balance, monthly_payment = payment, principal = principal, interest = interest, ending_balance= ending_balance, payment_proof = "", payment_mode="") return render_template("duepayment.html", activeLoan=activeLoan, dates=dates, balances=balances, period=period)
def checkprice(): arrival = request.args.get("arrival") rows = db.execute("SELECT price FROM terminals WHERE arrival=:arrival", arrival=arrival) price = naira(rows[0]["price"]) return jsonify(price)
def history(): activeLoan = db.execute( 'SELECT * FROM loans WHERE userId = :userId and status = :status', userId=session["user_id"], status="0") payment = float(activeLoan[0]["monthlyRepayment"]) tbalance = activeLoan[0]["totalCostOfLoan"] # print(userLoans) startdate = datetime.datetime.now() # activeLoan = db.execute('SELECT * FROM loans WHERE userId = :userId and status = :status', userId= session["user_id"], status = "0") # print(activeLoan) date = (startdate + relativedelta(months=+1)).strftime("%x") period = activeLoan[0]["loanPeriod"] tInterest = float(activeLoan[0]["totalInterest"]) # payment = float(activeLoan[0]["monthlyRepayment"]) rate = activeLoan[0]["interestRate"] loan_id = activeLoan[0]["id"] # tbalance = activeLoan[0]["totalCostOfLoan"] interest = tInterest / period principal = payment - interest balances = [] dates = [] ending_balances = [] for x in range(period): due_date = (startdate + relativedelta(months=+x)).strftime("%x") balance = tbalance - (x * payment) ending_balance = tbalance - ((x + 1) * payment) ending_balance = naira(ending_balance) balance = naira(balance) balances.append(balance) dates.append(due_date) ending_balances.append(ending_balance) # k = db.execute("INSERT INTO repayment (user_id, loan_id, due_date, begining_balance, monthly_payment, principal, interest, ending_balance) VALUES(:user_id, :loan_id, :due_date, :begining_balance, :monthly_payment, :principal, :interest, :ending_balance)", # user_id= session["user_id"], loan_id = loan_id, due_date = due_date, begining_balance = balance, monthly_payment = payment, principal = principal, interest = interest, ending_balance= ending_balance, payment_proof = payment_proof,) pmtnum = int(request.args.get("pmtnum")) # pmt = pmtnum + 1 # print(pmt) # print(pmtnum) if pmtnum != "": pmt = pmtnum + 1 return render_template("paymenthistory.html", activeLoan=activeLoan, payment=naira(payment), tbalance=naira(tbalance), balances=balances, dates=dates, ending_balances=ending_balances, principal=naira(principal), pmt=pmt, interest=naira(interest)) else: pmt = period return render_template("paymenthistory.html", activeLoan=activeLoan, payment=naira(payment), tbalance=naira(tbalance), balances=balances, dates=dates, ending_balances=ending_balances, principal=naira(principal), pmt=pmt, interest=naira(interest))
def create(): if session.get("user_id") is None: return render_template("notfound.html", details="Login Is Required") elif request.method == "POST": startdate = datetime.datetime.now() loantype = request.form.get("loantype") amountborrowed = int(request.form.get("amountborrowed")) interestRate = float(request.form.get("interestrate")) period = int(request.form.get("period")) totalInterest = amountborrowed * interestRate totalCostOfLoan = amountborrowed + totalInterest monthlyPayment = totalCostOfLoan / period monthlyInterest = totalInterest / period monthlyPrincipal = monthlyPayment - monthlyInterest # insert loan details into loan table k = db.execute( "INSERT INTO loans (userId, loanType, loanAmount, interestRate, loanPeriod, monthlyRepayment, totalInterest, totalCostOfLoan, startdate) VALUES(:userId, :loanType, :loanAmount, :interestRate, :loanPeriod, :monthlyRepayment, :totalInterest, :totalCostOfLoan, :startdate)", userId=session["user_id"], loanType=loantype, loanAmount=naira(amountborrowed), interestRate=interestRate, loanPeriod=period, monthlyRepayment=monthlyPayment, totalInterest=totalInterest, totalCostOfLoan=totalCostOfLoan, startdate=startdate) return render_template("/success.html") elif request.method == "GET": userLoans = db.execute('SELECT * FROM loans WHERE userId = :userId', userId=session["user_id"]) status = userLoans[0]["status"] if not userLoans or status == "paid": loantype = request.args.get("loantype") if loantype == "Decamini": interestRate = 0.03 return render_template("create.html", loantype=loantype, mini=100000, max=300000, interestRate=interestRate) elif loantype == "Decaflex": interestRate = 0.05 return render_template("create.html", loantype=loantype, mini=310000, max=900000, interestRate=interestRate) elif loantype == "Decalarge": interestRate = 0.10 return render_template("create.html", loantype=loantype, mini=910000, max=2000000, interestRate=interestRate) else: userDetails = db.execute( 'SELECT * FROM users WHERE id = :userId', userId=session["user_id"]) return render_template( "profile.html", message="You have successfully registered", userName=userDetails[0]["username"]) else: return render_template( "noteligible.html", details="Please Pay up before making another application")
def create(): def ableToGetLoan(loantype): if loantype == "Decamini": interestRate = 0.03 return render_template("create.html", loantype=loantype, mini=100000, max=300000, interestRate=interestRate) elif loantype == "Decaflex": interestRate = 0.05 return render_template("create.html", loantype=loantype, mini=310000, max=900000, interestRate=interestRate) elif loantype == "Decalarge": interestRate = 0.10 return render_template("create.html", loantype=loantype, mini=910000, max=2000000, interestRate=interestRate) else: userDetails = db.execute('SELECT * FROM users WHERE id = :userId', userId=session["user_id"]) return render_template("profile.html", message="You have successfully registered", userName=userDetails[0]["username"]) if request.method == "POST": loantype = request.form.get("loantype") amountborrowed = int(request.form.get("amountborrowed")) interestRate = float(request.form.get("interestrate")) period = int(request.form.get("period")) totalInterest = amountborrowed * interestRate totalCostOfLoan = amountborrowed + totalInterest monthlyPayment = totalCostOfLoan / period monthlyInterest = totalInterest / period monthlyPrincipal = monthlyPayment - monthlyInterest startdate = datetime.datetime.now() k = db.execute( "INSERT INTO loans (userId, loanType,startdate, loanAmount, interestRate, loanPeriod, monthlyRepayment, totalInterest, totalCostOfLoan, status) VALUES(:userId, :loanType, :startdate, :loanAmount, :interestRate, :loanPeriod, :monthlyRepayment, :totalInterest, :totalCostOfLoan, :status)", userId=session["user_id"], loanType=loantype, startdate=startdate, loanAmount=amountborrowed, interestRate=interestRate, loanPeriod=period, monthlyRepayment=monthlyPayment, totalInterest=totalInterest, totalCostOfLoan=totalCostOfLoan, status=False) activeLoan = db.execute( 'SELECT * FROM loans WHERE userId = :userId and status = :status', userId=session["user_id"], status=False) # print(activeLoan) payment = float(activeLoan[0]["monthlyRepayment"]) tbalance = activeLoan[0]["totalCostOfLoan"] date = (startdate + relativedelta(months=+1)).strftime("%x") period = activeLoan[0]["loanPeriod"] tInterest = float(activeLoan[0]["totalInterest"]) rate = activeLoan[0]["interestRate"] loan_id = activeLoan[0]["id"] interest = tInterest / period principal = payment - interest principal = naira(principal) interest = naira(interest) for x in range(period): i = x + 1 due_date = (startdate + relativedelta(months=+i)).strftime("%x") balance = tbalance - (x * payment) ending_balance = tbalance - ((x + 1) * payment) ending_balance = naira(ending_balance) balance = naira(balance) k = db.execute( "INSERT INTO repayment (user_id, loan_id, due_date, begining_balance, monthly_payment, principal, interest, ending_balance,status) VALUES(:user_id, :loan_id, :due_date, :begining_balance, :monthly_payment, :principal, :interest, :ending_balance, :status)", user_id=session["user_id"], loan_id=loan_id, due_date=due_date, begining_balance=balance, monthly_payment=payment, principal=principal, interest=interest, ending_balance=ending_balance, status=False) repayments_details = db.execute( 'SELECT * FROM repayment WHERE user_id = :userId and loan_id = :loan_id', userId=session["user_id"], loan_id=loan_id) # print(repayments_details) # return render_template("paymenthistory.html",activeLoan = activeLoan,payment = naira(payment), tbalance =naira(tbalance), principal = principal, interest= interest,repayments_details=repayments_details,totalInterest=naira(totalInterest), amountborrowed= naira(amountborrowed) ) return render_template("/success.html") elif request.method == "GET": userLoans = db.execute( 'SELECT * FROM loans WHERE userId = :userId and status = :status', userId=session["user_id"], status=False) loantype = request.args.get("loantype") if len(userLoans) == 0: return ableToGetLoan(loantype) # status = userLoans[0]["status"] # print(status) # if status == "1": # return ableToGetLoan(loantype) else: return render_template( "noteligible.html", details="Please Pay up before making another application")