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
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. 3
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. 4
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)