Esempio n. 1
0
def pay_loan(id):  #client_id
    paid = int(request.json["amount"])
    loan = Loan.pay_loan(Loan, id)
    to_pay = loan.principle_interest
    date = datetime.now()
    if loan.pay:
        Payment.make_payment(Payment, to_pay, paid, date, loan.id, loan)
    else:
        balance = to_pay - paid
        Payment(to_pay, paid, date, balance, loan)
        Loan.update_pay(Loan, loan.id, balance)

    Loan.check_balance(Loan, loan.id)

    return request.json
Esempio n. 2
0
def get_image(id):
    loan = Loan.get_client_loan(Loan, id)
    file_path = os.path.join("./application/static", loan.collaterals[0].image)
    abs_path = os.path.abspath(os.path.dirname(__file__))
    path = abs_path.replace("/views/Loan", "/static")

    return send_file(path + "/" + loan.collaterals[0].image,
                     mimetype='image/*')
Esempio n. 3
0
def view_letter(id):
    loan = Loan.get_client_loan(Loan, id)
    file_path = os.path.join("./application/static", loan.G_LC_letter)
    abs_path = os.path.abspath(os.path.dirname(__file__))
    path = abs_path.replace("/views/Loan", "/static")

    print(loan.G_LC_letter)

    return send_file(path + "/" + loan.G_LC_letter, mimetype='application/pdf')
Esempio n. 4
0
def get_file(filename, id):
    loan = Loan.get_client_loan(Loan, id)
    for file in loan.collaterals[0].files:
        if file.filename == filename:
            file_path = os.path.join("./application/static", file.filename)
            abs_path = os.path.abspath(os.path.dirname(__file__))
            path = abs_path.replace("/views/Loan", "/static")
            return send_file(path + "/" + file.filename,
                             mimetype='application/pdf')
Esempio n. 5
0
def forward_mag(id):
    reason = request.json['reason']
    Loan.forward_manager(Loan, id, reason)

    return request.json
Esempio n. 6
0
def forward_CEO(id):
    reason = request.json['reason']
    Loan.forward_ceo(Loan, id, reason)

    return request.json
Esempio n. 7
0
def getLoan(id):
    status = request.json["status"]

    return Loan.get_loan_details(Loan, id, status)
Esempio n. 8
0
def get_client_loans(id):
    loans = Loan.get_client_loans(Loan, id)

    return loans_schema.dumps(loans)
Esempio n. 9
0
def delete(id):
    Loan.delete_loan(Loan, id)

    return json.dumps({"operation": "True"})
Esempio n. 10
0
def issue_payment(id):
    Loan.issue_payment(Loan, id)

    return json.dumps({"operation": "True"})
Esempio n. 11
0
def accept(id):
    Loan.accept_loan(Loan, id)

    return json.dumps({"operation": "True"})
Esempio n. 12
0
def reject(id):
    rejection_reason = request.json["rejection_reason"]
    Loan.reject_loan(Loan, id, rejection_reason)

    return request.json
Esempio n. 13
0
def getRequest(id):
    return Loan.get_loan_request(Loan, id)
Esempio n. 14
0
def payment_details(id):
    payments = Loan.check_payments(Loan, id)
    return payments_schema.dumps(payments)
Esempio n. 15
0
def get_clients():
    loans = Loan.get_loans(Loan)
    return loans_schema.dumps(loans)
Esempio n. 16
0
def loanRequest(id):
    if request.files:
        for file_name in request.files:
            file_path = os.path.join("./application/static", file_name)
            file = request.files[file_name]
            file.save(file_path)

        client_loan_information = ast.literal_eval(
            request.headers["loan-information"])["_map"]
        amount_requested = client_loan_information['loan_amount_requested']
        previous_loan_performance = client_loan_information[
            'previous_loan_records']
        amount_issued = client_loan_information['issued_amount']
        interest_rate = client_loan_information['interest_rate']
        loan_type = client_loan_information['loan_type']
        interest = client_loan_information['interest']
        principle_interest = client_loan_information['principle_interest']
        issue_date = changeDate(client_loan_information['issue_date'])
        pay_date = changeDate(client_loan_information['pay_date'])
        range = pay_date - issue_date
        period = range.days

        guarantor_names = client_loan_information['guarantors_names']
        guarantor_dob = changeDate(client_loan_information['gdob_date'])
        guarantor_sex = client_loan_information['sex']
        guarantor_nin = client_loan_information['gnin']
        guarantor_telephone = "+256" + client_loan_information[
            'telephone_number']
        guarantor_email = client_loan_information['email']
        guarantor_residence = client_loan_information['residence']
        guarantor_occupation = client_loan_information['occupation']
        guarantor_work_place = client_loan_information['work_place']
        guarantor_work_place_address = client_loan_information[
            'work_place_address']
        guarantor_lc1 = client_loan_information['LC1']

        client = Client.read_client(Client, id)
        client_names = " ".join([client.surname, client.first_name])
        Client.change_state(Client, id)

        # loan
        loan = Loan(client_names, amount_requested, period,
                    previous_loan_performance, amount_issued, interest_rate,
                    loan_type, interest, principle_interest,
                    principle_interest, guarantor_names, guarantor_dob,
                    guarantor_telephone, guarantor_email, guarantor_residence,
                    guarantor_work_place, guarantor_work_place_address,
                    guarantor_occupation, guarantor_nin, guarantor_lc1,
                    pay_date, client)

        # collaterals
        asset_name = client_loan_information['asset_name']
        value = client_loan_information['value']
        location = client_loan_information['location']
        description = client_loan_information['description']
        image = client_loan_information['collateral_image_file']

        # loan = Loan.getClientLoan(Loan, id)

        collateral = Collateral(asset_name, value, location, description,
                                image, loan)

        for file in client_loan_information['supporting_files']['files']:
            Documents(file['name'], collateral)

        return True

    else:
        return False