Esempio n. 1
0
class Income:
    def __init__(self):
        self.income = Models()
        self.client = Client()

    def add_income(self):
        income_list = []
        id = self.get_id_income()
        income_list.append(id)
        employer = input("Please, enter a Employer name: ")
        if len(employer) <= 50:
            income_list.append(employer.capitalize())
        else:
            print("Employer name is too long. We cannot continue")
            sys.exit(0)
        employment_city = input("Please, enter a Employment city: ")
        if len(employment_city) <= 50:
            income_list.append(employment_city.capitalize())
        else:
            print("Employment city name is too long. We cannot continue")
            sys.exit(0)
        employment_street = input("Please, enter a Employment street: ")
        if len(employment_street) <= 50:
            income_list.append(employment_street.capitalize())
        else:
            print("Employment street name is too long. We cannot continue")
            sys.exit(0)
        nip = input("Please, enter a NIP of the Employer: ")
        if self.income.check_nip(nip) == True:
            print("NIP is correct")
            income_list.append(nip)
        else:
            print("NIP is incorrect")
            sys.exit(0)
        employment_type = input("Please, enter a Employment type: ")
        if len(employment_type) <= 50:
            income_list.append(employment_type.capitalize())
        else:
            print("Employment type name is too long. We cannot continue")
            sys.exit(0)
        net_salary = float(input("Please, enter the net salary: "))
        income_list.append(round(net_salary, 2))
        spouse_net_salary = float(
            input(
                "Please, enter your spouse net salary (if the client does not have a spouse. Enter 0): "
            ))
        income_list.append(round(spouse_net_salary, 2))
        clientid = self.client.get_id_client()
        income_list.append(clientid)
        return income_list

    def get_id_income(self):
        query = "select max(IdIncome) from Income"
        idincome = self.income.read_sql(query)
        if len(idincome) > 0:
            idincome = str(idincome).strip('[(,)]')
            idincome = int(idincome.replace(",", "")) + 1
            return idincome
        else:
            return 1
Esempio n. 2
0
 def __init__(self):
     self.client = Client()
     self.blacklist = Blacklist()
     self.loan = Loan()
     self.models = Models()
     self.income = Income()
     self.expenses = Expenses()
     self.choices = {
         "1": self.create_a_loan_application,
         "2": self.show_history,
         "3": self.search_customer,
         "4": self.check_customer,
         "5": self.quit
     }
Esempio n. 3
0
class Blacklist:
    def __init__(self):
        self.blacklist = Models()


    def check_customer(self, pesel: str):
        query = f"select c.FirstName, c.LastName, c.City, c.PESEL, b.reason from blacklist b left join client c on b.ClientId = c.IdClient where pesel = {pesel}"
        return self.blacklist.read_sql(query)
Esempio n. 4
0
 def __init__(self):
     self.client = Models()
     self.checking = Blacklist()
Esempio n. 5
0
class Client:
    def __init__(self):
        self.client = Models()
        self.checking = Blacklist()

    def show_client(self, pesel: str):
        query = f"""select c.FirstName, c.LastName, c.PESEL, c.City, c.Street, c.Sex, i.Employer, i.EmploymentCity, 
      i.EmploymentStreet, i.NIP, l.IdLoan from client c 
      left join income i on c.IdClient = i.ClientId 
      join loan l on c.IdClient = l.ClientId 
      where c.PESEL = {pesel};
      """
        return self.client.read_sql(query)

    def get_id_client(self):
        query = "select max(IdClient) from Client"
        idclient = self.client.read_sql(query)
        if len(idclient) > 0:
            idclient = str(idclient).strip('[(,)]')
            idclient = int(idclient.replace(",", "")) + 1
            return idclient
        else:
            return 1

    def add_client(self):
        client_list = []
        id = self.get_id_client()
        client_list.append(id)
        pesel = input("Please, enter a PESEL number: ")
        result = self.checking.check_customer(pesel)
        if len(result) > 0:
            print("The customer has been blacklisted. Unfortunately, there is no approval to grant a loan")
            sys.exit(0)
        else:

            if self.client.check_pesel(pesel) == False:
                print("Pesel number is incorrect")
                answer = input(
                    "Please click 'q' if you want to end application or any other button to enter PESEL again: ")
                if answer.lower() == "q":
                    sys.exit(0)
                else:
                    return self.add_client()
            else:
                print("Pesel number is correct")

        first_name = input("Please, enter a first name: ")
        if len(first_name) <= 50:
            client_list.append(first_name.capitalize())
        else:
            print("First name is too long. We cannot continue")
            sys.exit(0)
        last_name = input("Please, enter a last name: ")
        if len(last_name) <= 50:
            client_list.append(last_name.capitalize())
        else:
            print("Last name is too long. We cannot continue")
            sys.exit(0)
        city = input("Please, enter a city: ")
        if len(city) <= 20:
            client_list.append(city.capitalize())
        else:
            print("City name is too long. We cannot continue")
            sys.exit(0)
        street = input("Please, enter a street: ")
        if len(street) <= 30:
            client_list.append(street.capitalize())
        else:
            print("Street name is too long. We cannot continue")
            sys.exit(0)
        sex = input("Please, enter your gender [W] for woman or [M] for man: ")
        if len(sex) == 1:
            if sex.upper() == "W" or sex.upper() == "M":
                client_list.append(sex.capitalize())
            else:
                print("wrong abbreviation")
                sys.exit(0)
        else:
            print("Gender abbreviation is too long. We cannot continue")
            sys.exit(0)
        marital_status = input("Please, enter a marital status: ")
        if len(marital_status) <= 30:
            client_list.append(marital_status.capitalize())
        else:
            print("Martial status name is too long. We cannot continue")
            sys.exit(0)
        client_list.append(pesel)
        return client_list
Esempio n. 6
0
 def __init__(self):
     self.blacklist = Models()
Esempio n. 7
0
class Menu:
    '''Display a menu and respond to choice when run'''
    def __init__(self):
        self.client = Client()
        self.blacklist = Blacklist()
        self.loan = Loan()
        self.models = Models()
        self.income = Income()
        self.expenses = Expenses()
        self.choices = {
            "1": self.create_a_loan_application,
            "2": self.show_history,
            "3": self.search_customer,
            "4": self.check_customer,
            "5": self.quit
        }

    def display_menu(self):
        print("""
Credit Menu
1. Create a loan application
2. Show history
3. Search customer
4. Check customer
5. Quit
""")

    def run(self):
        """Display the menu and respond to choices"""
        while True:
            self.display_menu()
            choice = input("Enter an option: ")
            action = self.choices.get(choice)
            if action:
                action()
            else:
                print(f'{choice} is not a valid choice')

    def create_a_loan_application(self):
        li_client = self.client.add_client()
        print(li_client)
        li_income = self.income.add_income()
        print(li_income)
        li_expenses = self.expenses.add_expenses()
        print(li_expenses)
        li_loan = self.loan.add_loan(li_expenses, li_income)
        print(li_loan)
        print("\n")
        if len(li_client) == 8 and len(li_income) == 9 and len(
                li_expenses) == 4 and len(li_loan) == 8:
            self.models.create_sql_client(li_client)
            self.models.create_sql_income(li_income)
            self.models.create_sql_expenses(li_expenses)
            self.models.create_sql_loan(li_loan)
            if li_loan[7] == "Granted":
                print("There is permission to grant a loan")
                sys.exit(0)
            else:
                print("Unfortunately there is no permission to grant a loan")
                sys.exit(0)
        else:
            print("something went wrong")
            sys.exit(0)

    def show_history(self):
        select_all_history = self.loan.show_history()
        print("Loans history: ")
        print("\n".join(f"Client: {a} {b}, Id_Loan: {c}"
                        for a, b, c in select_all_history))
        print("\n")
        print(
            "to learn more about some loan, please give the loan id number from the listed"
        )

        id_number = int(input("Give the loan id number: "))
        print(
            "_______________________________________________________________________"
        )
        print("\n")
        personal_data = self.loan.show_personal_data(id_number)

        if len(personal_data) > 0:
            print(f"Details for loan number: {id_number} - Personal data: ")
            print("\n".join(
                f" 1. Client full name: {a} {b}\n 2. City: {c}\n 3. Street: {d}\n 4. sex: {e}\n "
                f"5. Marital Status: {f}\n 6. PESEL: {g}"
                for a, b, c, d, e, f, g in personal_data))
            loan_data = self.loan.show_loan_data(id_number)
            print(f"Information about Loan: ")
            print("\n".join(
                f" 7. Id Loan: {a}\n 8. Borrow Amount: {b} PLN\n 9. Installments Number: {c}\n "
                f"10. Interest Rate: {d} %\n 11. Monthly Installment: {e} PLN\n "
                f"12. Total Amount To Give Back: {f} PLN\n 13. Status: {g}"
                for a, b, c, d, e, f, g in loan_data))
            income_data = self.loan.show_income(id_number)
            print(f"Information about client income and employment: ")
            print("\n".join(
                f" 14. Employer: {a}\n 15. Employment Street: {b}\n 16. NIP: {c}\n "
                f"17. Employment Type: {d}\n 18. Net Salary: {e} PLN\n 19. Spouse Salary: {f} PLN"
                for a, b, c, d, e, f in income_data))
            expenses_data = self.loan.show_expenses(id_number)
            print(f"Information about client expenses: ")
            print("\n".join(
                f" 20. All Monthly Credits: {a} PLN\n 21. All Monthly Bills: {b} PLN"
                for a, b in expenses_data))
            print(
                "_______________________________________________________________________"
            )

        else:
            print("wrong id number")

        Menu().run()

    def search_customer(self):
        search_client = input("Please, give PESEL number: ")
        if self.models.check_pesel(search_client) == True:
            print("Pesel is correct")
            show_client = self.client.show_client(search_client)

            if len(show_client) > 0:
                print("\n")
                print("\n".join(
                    f" 1. Client full name: {a} {b}\n 2. PESEL: {c}\n 3. City: {d}\n 4. Street: {e}\n "
                    f"5. Sex: {f}\n 6. Company: {g}\n 7. Company city: {h}\n 8. Company street: {i}\n "
                    f"9. NIP: {j}\n 10. Id Loan: {k}"
                    for a, b, c, d, e, f, g, h, i, j, k in show_client))
            else:
                print("There is no that client")

        else:
            print("pesel is incorrect")
            Menu().run()

    def check_customer(self):
        print('Check the customer if one has been blacklisted!!', '\n')
        pesel = input("To check the customer enter their pesel number: ")
        result = self.blacklist.check_customer(pesel)
        if len(result) > 0:
            print("\n")
            dictionary = {
                "First Name": result[0][0],
                "Last Name": result[0][1],
                "City": result[0][2],
                "PESEL": result[0][3],
                "Reason of being on blacklist": result[0][4]
            }
            print("\n".join(f"{k} -> {v}" for k, v in dictionary.items()))
            print("\n")
            print(
                "The customer has been blacklisted. Unfortunately, there is no approval to grant a loan"
            )
            sys.exit(0)
        else:
            print(
                "The customer has not been blacklisted. You can create a loan application"
            )

    def quit(self):
        print('Thank you for visiting us today.')
        Menu().run()
Esempio n. 8
0
 def __init__(self):
     self.income = Models()
     self.client = Client()
Esempio n. 9
0
 def __init__(self):
     self.loan = Models()
     self.client = Client()
Esempio n. 10
0
class Loan:
    def __init__(self):
        self.loan = Models()
        self.client = Client()

    def add_loan(self, liexpenses: List, liincome: List):
        loan_list = []
        id = self.get_id_loan()
        loan_list.append(id)
        borrow_amount = int(input("Please, enter amount to borrow: "))
        loan_list.append(borrow_amount)
        installments_number = int(input("Please, enter number of installments [max. 60]: "))
        if installments_number <= 60:
            loan_list.append(installments_number)
        else:
            answer = input("Maximum number of installments is 60. Please click 'r' if you want to decrease number "
                           "of installments or any other button to quit the application: ")
            if answer.lower() == "r":
                return self.add_loan(liexpenses, liincome)
            else:
                sys.exit(0)
        interest_rate = float(input("Please, enter the interest rate according to bank offer: "))
        loan_list.append(round(interest_rate, 2))
        clientid = self.client.get_id_client()
        loan_list.append(clientid)
        monthly_installment = (borrow_amount * (1 + interest_rate / 100) / installments_number)
        loan_list.append(round(monthly_installment, 2))
        total_amount_to_give_back = monthly_installment * installments_number
        loan_list.append(round(total_amount_to_give_back, 2))
        all_expenses = liexpenses[1] + liexpenses[2] + monthly_installment
        all_income = liincome[6] + liincome[7]
        if all_income * 0.7 > all_expenses:
            status = "Granted"
        else:
            status = "Rejected"
        loan_list.append(status)
        return loan_list

    def get_id_loan(self):
        query = "select max(IdLoan) from Loan"
        idloan = self.loan.read_sql(query)
        if len(idloan) > 0:
            idloan = str(idloan).strip('[(,)]')
            idloan = int(idloan.replace(",", "")) + 1
            return idloan
        else:
            return 1

    def show_history(self):
        query = f"select c.FirstName, c.LastName, l.IdLoan from client c left join loan l on c.IdClient = l.ClientId"
        return self.loan.read_sql(query)

    def show_personal_data(self, id_number: int):
        query = f"select c.FirstName, c.LastName, c.City, c.Street, c.Sex, c.MaritalStatus, c.Pesel from client " \
            f"c left join loan l on c.IdClient = l.ClientId where IdLoan = {id_number};"
        return self.loan.read_sql(query)

    def show_loan_data(self, id_number: int):
        query = f"select l.IdLoan, l.BorrowAmount, l.InstallmentsNumber, l.InterestRate, l.MonthlyInstallment, " \
            f"l.TotalAmountToGiveBack, l.Status from client c left join loan l " \
            f"on c.IdClient = l.ClientId where IdLoan = {id_number};"
        return self.loan.read_sql(query)

    def show_income(self, id_number: int):
        query = f"select i.Employer, i.EmploymentStreet, i.NIP, i.EmploymentType, i.NetSalary, i.SpouseSalary " \
            f"from client c left join loan l on c.IdClient = l.ClientId join income i on c.IdClient = i.ClientId " \
            f"where IdLoan = {id_number};"
        return self.loan.read_sql(query)

    def show_expenses(self, id_number: int):
        query = f"select e.AllMonthlyCredits, e.AllMonthlyBills from client c " \
            f"left join loan l on c.IdClient = l.ClientId join expenses e on c.IdClient = e.ClientId " \
            f"where IdLoan = {id_number};"
        return self.loan.read_sql(query)