Exemplo n.º 1
0
    def __init__(self, show_menu=True):

        self.items_per_page = 10

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        if show_menu:
            self.menu()
Exemplo n.º 2
0
    def __init__(self, employee_id, employee_role):

        self.items_per_page = 10
        self.employee_role = employee_role
        self.employee_id = employee_id

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        self.menu()
Exemplo n.º 3
0
class EmployeeUI:
    def __init__(self, employee_id, employee_role):

        self.items_per_page = 10
        self.employee_role = employee_role
        self.employee_id = employee_id

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        self.menu()

    def create(self):
        counter = 0

        role = ""
        name = ""
        email = ""
        ssn = ""
        phone = ""
        homephone = ""
        address = ""
        postal = ""
        location_id = ""

        location_id_page = 1
        role_page = 1
        while True:

            location = self.logic.get_location_by_id(location_id)
            if location is None:
                location = ""

            self.printer.header("Create employee")
            print(
                f"Role:\t\t\t\t{role}\nName:\t\t\t\t{name}\nEmail:\t\t\t\t{email}\nSocial security number:\t\t{ssn}\nMobile phone:\t\t\t{phone}\nHome phone:\t\t\t{homephone}\nAddress:\t\t\t{address}\nPostal code:\t\t\t{postal}\nLocation:\t\t\t{location}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.notification()
            next_input = True
            data = None
            try:
                if counter == 0:
                    data = self.input.get_option("role", [
                        "Admin", "Delivery", "Booking", "Mechanic", "Financial"
                    ],
                                                 current_page=role_page,
                                                 warning_msg=self.warning_msg)
                    if data[0]:
                        role = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                        role_page = data[2]
                elif counter == 1:
                    data = self.input.get_input("name", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        name = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 2:
                    data = self.input.get_input("email", ["required", "email"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        email = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 3:
                    data = self.input.get_input("social security number",
                                                ["required", "ssn"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        ssn = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 4:
                    data = self.input.get_input("mobile phone",
                                                ["required", "phone"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        phone = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 5:
                    data = self.input.get_input("home phone",
                                                ["required", "phone"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        homephone = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 6:
                    data = self.input.get_input("address", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        address = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 7:
                    data = self.input.get_input("postal code", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        postal = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 8:
                    locations = self.logic.get_all_locations()
                    available_locations = [[location.id, location]
                                           for location in locations]
                    location_input = self.input.get_option(
                        "location",
                        available_locations,
                        current_page=location_id_page,
                        warning_msg=self.warning_msg)
                    if location_input[0] == True:
                        location_id = location_input[1]
                    else:
                        next_input = False
                        self.warning_msg = location_input[1]
                        location_id_page = location_input[2]
                elif counter > 8:
                    new_employee = Employee(role, name, address, postal, ssn,
                                            phone, homephone, email,
                                            location_id)
                    confirmation = input(
                        "Are you sure you want to create this employee? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                    ).lower()
                    if confirmation == 'y':
                        self.logic.create_employee(new_employee)
                        return True
                    return False
                if next_input:
                    counter += 1
            except ValueError:
                break

    def menu_options(self):
        if self.employee_role.lower() == "admin":
            return {
                "View employees": self.view,
                "Create an employee": self.create
            }

    # Prints out employee's menu
    def menu(self):
        while True:
            menu_options = self.menu_options()
            self.printer.header("Employees Menu")
            self.printer.print_menu_options(menu_options)
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == 'q':
                break
            try:
                list(menu_options.values())[int(action) - 1]()
            except:
                self.warning_msg = "Please select available option"

    # Prints out all employee
    def view(self, created=False):
        current_page = 1
        while True:
            employees = self.logic.get_all_employees()
            employees_count = len(employees)
            last_page = int(employees_count / self.items_per_page) + (
                employees_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else employees_count

            self.printer.header("View employees")
            self.print(employees, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect employee: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            elif action == 's' or action == "select":
                employee_id = input("Select employee by ID: ").lower()
                if employee_id == 'q':
                    break
                employee = self.logic.get_employee_by_id(employee_id)
                if employee is None:
                    self.warning_msg = "Employee not found"
                else:
                    self.employee(employee_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out single employee
    def employee(self, employee_id):
        while True:
            employee = self.logic.get_employee_by_id(employee_id)
            self.printer.header("View employee")
            print(
                "ID:\t\t\t\t{}\nRole:\t\t\t\t{}\nName:\t\t\t\t{}\nEmail:\t\t\t\t{}\nSocial security number:\t\t{}\nMobile phone:\t\t\t{}\nHome phone:\t\t\t{}\nAddress:\t\t\t{}\nPostal code:\t\t\t{}\nLocation:\t\t\t{}\n"
                .format(employee_id, employee.role, employee.name,
                        employee.email, employee.ssn, employee.phone,
                        employee.homephone, employee.address, employee.postal,
                        self.logic.get_location_by_id(employee.location_id)))
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()
            action = input("(E)dit / (D)elete: ").lower()
            if action == 'q':
                break
            elif action == 'e' or action == 'edit':
                self.edit(employee_id)
            elif action == 'd' or action == 'delete':
                if self.employee_id != employee_id:
                    if self.delete(employee_id):
                        self.success_msg = "Employee has been deleted"
                        break
                else:
                    self.warning_msg = "You can't delete yourself"
            else:
                self.warning_msg = "Please select available option"

    # Prints out table of employee
    def print(self, employees, start, end, current_page, last_page):
        if len(employees) > 0:
            print("|{:^6}|{:^15}|{:^20}|{:^25}|{:^14}|{:^20}|{:^26}|".format(
                "ID", "Role", "Name", "Email", "SSN", "Mobile phone",
                "Location"))
            print('-' * 134)
            for i in range(start, end):
                print(
                    "|{:^6}|{:<15}|{:<20}|{:<25}|{:<14}|{:<20}|{:<26}|".format(
                        employees[i].id, employees[i].role, employees[i].name,
                        employees[i].email, employees[i].ssn,
                        employees[i].phone,
                        self.logic.get_location_by_id(
                            employees[i].location_id).__str__()))
            print("{:^134}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No employees found"

    def edit(self, employee_id):
        location_id_page = 1
        role_page = 1
        while True:
            employee = self.logic.get_employee_by_id(employee_id)
            update = {}
            self.printer.header("Edit employee")
            print(
                f"ID:\t\t\t\t{employee_id}\nRole:\t\t\t\t{employee.role}\nName:\t\t\t\t{employee.name}\nEmail:\t\t\t\t{employee.email}\nSocial security number:\t\t{employee.ssn}\nMobile phone:\t\t\t{employee.phone}\nHome phone:\t\t\t{employee.homephone}\nAddress:\t\t\t{employee.address}\nPostal code:\t\t\t{employee.postal}\nLocation:\t\t\t{self.logic.get_location_by_id(employee.location_id)}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.printer.print_options([
                'Edit role', 'Edit email', 'Edit mobile phone',
                'Edit home phone', 'Edit address', 'Edit postal code',
                'Edit location'
            ])
            self.printer.new_line()
            self.notification()
            while True:
                action = input("Choose an option: ").lower()
                data = None
                try:
                    if action == "q":
                        return
                    elif action == "1":
                        while True:
                            data = self.input.get_option(
                                "role", [
                                    "Admin", "Delivery", "Booking", "Mechanic",
                                    "Financial"
                                ],
                                current_page=role_page,
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["role"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                                role_page = data[2]

                    elif action == "2":
                        while True:
                            data = self.input.get_input(
                                "email", ["required", "email"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["email"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "3":
                        while True:
                            data = self.input.get_input(
                                "mobile phone", ["required", "phone"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["phone"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "4":
                        while True:
                            data = self.input.get_input(
                                "home phone", ["required", "phone"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["homephone"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "5":
                        while True:
                            data = self.input.get_input(
                                "address", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["address"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "6":
                        while True:
                            data = self.input.get_input(
                                "postal code", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["postal"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "7":
                        while True:
                            locations = self.logic.get_all_locations()
                            available_locations = [[location.id, location]
                                                   for location in locations]
                            data = self.input.get_option(
                                "location",
                                available_locations,
                                current_page=location_id_page,
                                warning_msg=self.warning_msg)
                            if data[0] == True:
                                update["location_id"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                                location_id_page = data[2]
                    else:
                        self.warning_msg = "Please select available option"
                    if (len(update) > 0):
                        self.logic.update_employee(employee_id, update)
                        self.success_msg = "Employee has been modified"
                    break
                except ValueError:
                    break

    # Delete employee
    def delete(self, id):
        confirmation = input(
            "Are you sure you want to delete this employee? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
        ).lower()
        if confirmation == 'y':
            self.logic.delete_employee(id)
            return True
        return False

    # Outputs warnings and success messages
    def notification(self):
        if not self.warning_msg == "":
            self.printer.print_warning(self.warning_msg)
            self.warning_msg = ""
        elif not self.success_msg == "":
            self.printer.print_success(self.success_msg)
            self.success_msg = ""
        else:
            self.printer.new_line()
Exemplo n.º 4
0
class LocationUI:
    def __init__(self, employee_id, employee_role):

        self.items_per_page = 10

        self.employee_id = employee_id
        self.employee_role = employee_role

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        self.menu()

    def create(self):
        counter = 0

        country = ""
        airport = ""
        phone = ""
        hours = ""

        while True:

            self.printer.header("Create location")
            print(
                f"Country:\t\t\t{country}\nAirport:\t\t\t{airport}\nPhone:\t\t\t\t{phone}\nHours:\t\t\t\t{hours}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.notification()
            next_input = True
            data = None
            try:
                if counter == 0:
                    data = self.input.get_input("country", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        country = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 1:
                    data = self.input.get_input("airport", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        airport = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 2:
                    data = self.input.get_input("phone", ["required", "phone"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        phone = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 3:
                    data = self.input.get_input("hours", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        hours = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter > 3:
                    new_location = Location(country, airport, phone, hours)
                    confirmation = input(
                        "Are you sure you want to create this location? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                    ).lower()
                    if confirmation == 'y':
                        self.logic.create_location(new_location)
                        return True
                    return False
                if next_input:
                    counter += 1
            except ValueError:
                break

    def menu_options(self):
        if self.employee_role.lower() == "admin":
            return {
                "Create a location": self.create,
                "View locations": self.view
            }
        elif self.employee_role.lower() == "booking":
            return {"View locations": self.view}

    def menu(self):
        while True:
            menu_options = self.menu_options()
            self.printer.header("Locations Menu")
            self.printer.print_menu_options(menu_options)
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()
            if action == 'q':
                break
            try:
                list(menu_options.values())[int(action) - 1]()
            except:
                self.warning_msg = "Please select available option"

    # Prints out all location
    def view(self, created=False):
        current_page = 1
        while True:
            locations = self.logic.get_all_locations()
            locations_count = len(locations)
            last_page = int(locations_count / self.items_per_page) + (
                locations_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else locations_count

            self.printer.header("View locations")
            self.print(locations, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect location: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currently on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currently on the first page"
            elif action == 's' or action == "select":
                location_id = input("Select location by ID: ").lower()
                if location_id == 'q':
                    break
                location = self.logic.get_location_by_id(location_id)
                if location is None:
                    self.warning_msg = "Location not found"
                else:
                    self.location(location_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out single location
    def location(self, location_id):
        while True:
            location = self.logic.get_location_by_id(location_id)
            self.printer.header("View location")
            print(
                "ID:\t\t\t\t{}\nCountry:\t\t\t{}\nAirport:\t\t\t{}\nPhone:\t\t\t\t{}\nOpening hours:\t\t\t{}\n"
                .format(location.id, location.country, location.airport,
                        location.phone, location.hours))
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()
            action = input("(E)dit / (D)elete: ").lower()
            if action == 'q':
                break
            elif action == 'e' or action == 'edit':
                self.edit(location_id)
            elif action == 'd' or action == 'delete':
                if self.delete(location_id):
                    self.success_msg = "Location has been deleted"
                    break
            else:
                self.warning_msg = "Please select available option"

    # Prints out table of location
    def print(self, locations, start, end, current_page, last_page):
        if len(locations) > 0:
            print("|{:^6}|{:^18}|{:^18}|{:^20}|{:^20}|".format(
                "ID", "Country", "Airport", "Phone", "Opening hours"))
            print('-' * 88)
            for i in range(start, end):
                print("|{:^6}|{:<18}|{:<18}|{:<20}|{:<20}|".format(
                    locations[i].id, locations[i].country,
                    locations[i].airport, locations[i].phone,
                    locations[i].hours))
            print("{:^88}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No locations found"

    def edit(self, location_id):
        while True:
            location = self.logic.get_location_by_id(location_id)
            update = {}
            self.printer.header("Edit location")
            print(
                f"ID:\t\t\t\t{location_id}\nCountry:\t\t\t{location.country}\nAirport:\t\t\t{location.airport}\nPhone:\t\t\t\t{location.phone}\nOpening hours:\t\t\t{location.hours}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.printer.print_options([
                'Edit country', 'Edit airport', 'Edit phone',
                'Edit opening hours'
            ])
            self.printer.new_line()
            self.notification()
            while True:
                action = input("Choose an option: ").lower()
                data = None
                try:
                    if action == "q":
                        return
                    elif action == "1":
                        while True:
                            data = self.input.get_input(
                                "country", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["country"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "2":
                        while True:
                            data = self.input.get_input(
                                "airport", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["airport"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "3":
                        while True:
                            data = self.input.get_input(
                                "phone", ["required", "phone"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["phone"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "4":
                        while True:
                            data = self.input.get_input(
                                "opening hours", ["required", "hours"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["hours"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    else:
                        self.warning_msg = "Please select available option"
                    if (len(update) > 0):
                        self.logic.update_location(location_id, update)
                        self.success_msg = "Location has been modified"
                    break
                except ValueError:
                    break

    # Delete location
    def delete(self, id):
        confirmation = input(
            "Are you sure you want to delete this location? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
        ).lower()
        if confirmation == 'y':
            self.logic.delete_location(id)
            return True
        return False

    # Outputs warnings and success messages
    def notification(self):
        if not self.warning_msg == "":
            self.printer.print_warning(self.warning_msg)
            self.warning_msg = ""
        elif not self.success_msg == "":
            self.printer.print_success(self.success_msg)
            self.success_msg = ""
        else:
            self.printer.new_line()
Exemplo n.º 5
0
class CustomerUI:
    def __init__(self, show_menu=True):

        self.items_per_page = 10

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        if show_menu:
            self.menu()

    def create(self):
        counter = 0

        name = ""
        address = ""
        postal = ""
        ssn = ""
        phone = ""
        email = ""
        country = ""

        while True:
            self.printer.header("Create customer")
            print(
                f"Name:\t\t\t\t{name}\nAddress:\t\t\t{address}\nPostal code:\t\t\t{postal}\nPhone:\t\t\t\t{phone}\nSocial security number:\t\t{ssn}\nEmail:\t\t\t\t{email}\nCountry:\t\t\t{country}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.notification()
            next_input = True
            data = None
            try:
                if counter == 0:
                    data = self.input.get_input("name", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        name = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 1:
                    data = self.input.get_input("address", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        address = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 2:
                    data = self.input.get_input("postal code", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        postal = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 3:
                    data = self.input.get_input("phone", ["required", "phone"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        phone = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 4:
                    data = self.input.get_input("social security number",
                                                ["required", "ssn"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        ssn = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 5:
                    data = self.input.get_input("email", ["required", "email"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        email = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 6:
                    data = self.input.get_input("country", ["required"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        country = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter > 6:
                    new_customer = Customer(name, address, postal, ssn, phone,
                                            email, country)
                    confirmation = input(
                        "Are you sure you want to create this customer? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                    ).lower()
                    if confirmation == 'y':
                        return self.logic.create_customer(new_customer)
                    return False
                if next_input:
                    counter += 1
            except ValueError:
                break

    # Prints out customer's menu
    def menu(self):
        while True:
            self.printer.header("Customers Menu")
            self.printer.print_options(['Create a customer', 'View customers'])
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == '1':
                if self.create():
                    self.success_msg = "New customer has been created"
                    self.view(True)
            elif action == '2':
                self.view()
            elif action == 'q':
                break
            else:
                self.warning_msg = "Please select available option"

    # Prints out all customer
    def view(self, created=False):
        current_page = 1
        while True:
            customers = self.logic.get_all_customers()
            customers_count = len(customers)
            last_page = int(customers_count / self.items_per_page) + (
                customers_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else customers_count

            self.printer.header("View customers")
            self.print(customers, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect customer: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            elif action == 's' or action == "select":
                customer_id = input("Select customer by ID: ").lower()
                if customer_id == 'q':
                    break
                customer = self.logic.get_customer_by_id(customer_id)
                if customer is None:
                    self.warning_msg = "customer not found"
                else:
                    self.customer(customer_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out single customer
    def customer(self, customer_id):
        while True:
            customer = self.logic.get_customer_by_id(customer_id)
            self.printer.header("View customer")
            print(
                "ID:\t\t\t\t{}\nName:\t\t\t\t{}\nAddress:\t\t\t{}\nPostal:\t\t\t\t{}\nSocial security number:\t\t{}\nPhone:\t\t\t\t{}\nEmail:\t\t\t\t{}\nCountry:\t\t\t{}\n"
                .format(customer_id, customer.name, customer.address,
                        customer.postal, customer.ssn, customer.phone,
                        customer.email, customer.country))
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()
            action = input("(E)dit / (D)elete: ").lower()
            if action == 'q':
                break
            elif action == 'e' or action == 'edit':
                self.edit(customer_id)
            elif action == 'd' or action == 'delete':
                if self.delete(customer_id):
                    self.success_msg = "Customer has been deleted"
                    break
            else:
                self.warning_msg = "Please select available option"

    # Prints out table of customer
    def print(self, customers, start, end, current_page, last_page):
        if len(customers) > 0:
            print("|{:^6}|{:^25}|{:^25}|{:^30}|{:^30}|{:^20}|{:^30}|{:^20}|".
                  format("ID", "Name", "Address", "Postal",
                         "Social security number", "Phone", "Email",
                         "Country"))
            print('-' * 195)
            for i in range(start, end):
                print(
                    "|{:^6}|{:<25}|{:<25}|{:<30}|{:<30}|{:<20}|{:<30}|{:<20}|".
                    format(customers[i].id, customers[i].name,
                           customers[i].address, customers[i].postal,
                           customers[i].ssn, customers[i].phone,
                           customers[i].email, customers[i].country))
            print("{:^190}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No customers found"

    def edit(self, customer_id):
        while True:
            customer = self.logic.get_customer_by_id(customer_id)
            update = {}
            self.printer.header("Edit customer")
            print(
                f"ID:\t\t\t\t{customer_id}\nName:\t\t\t\t{customer.name}\nAddress:\t\t\t{customer.address}\nPostal code:\t\t\t{customer.postal}\nSocial security number:\t\t{customer.ssn}\nPhone:\t\t\t\t{customer.phone}\nEmail:\t\t\t\t{customer.email}\nCountry:\t\t\t{customer.country}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.printer.print_options([
                'Edit address', 'Edit postal code', 'Edit phone', 'Edit email',
                'Edit country'
            ])
            self.printer.new_line()
            self.notification()
            while True:
                action = input("Choose an option: ").lower()
                data = None
                try:
                    if action == "q":
                        return
                    elif action == "1":
                        while True:
                            data = self.input.get_input(
                                "address", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["address"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "2":
                        while True:
                            data = self.input.get_input(
                                "postal code", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["postal"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "3":
                        while True:
                            data = self.input.get_input(
                                "phone", ["required", "phone"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["phone"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "4":
                        while True:
                            data = self.input.get_input(
                                "email", ["required", "email"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["email"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "5":
                        while True:
                            data = self.input.get_input(
                                "country", ["required"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["country"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    else:
                        self.warning_msg = "Please select available option"
                    if (len(update) > 0):
                        self.logic.update_customer(customer_id, update)
                        self.success_msg = "Customer has been modified"
                    break
                except ValueError:
                    break

    # Delete customer
    def delete(self, id):
        confirmation = input(
            "Are you sure you want to delete this customer? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
        ).lower()
        if confirmation == 'y':
            self.logic.delete_customer(id)
            return True
        return False

    # Outputs warnings and success messages
    def notification(self):
        if not self.warning_msg == "":
            self.printer.print_warning(self.warning_msg)
            self.warning_msg = ""
        elif not self.success_msg == "":
            self.printer.print_success(self.success_msg)
            self.success_msg = ""
        else:
            self.printer.new_line()
Exemplo n.º 6
0
class FinanceUI:
    #initialize
    def __init__(self, employee_id, employee_role):

        self.items_per_page = 10

        self.employee_id = employee_id
        self.employee_role = employee_role

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.success_msg = ""
        self.warning_msg = ""

        self.menu()

    #Menu Options
    def menu_options(self):
        if self.employee_role.lower() == "admin":
            return {
                "View overview": self.overview,
                "View invoices": self.invoice
            }
        elif self.employee_role.lower() == "financial":
            return {
                "View overview": self.overview,
                "View invoices": self.invoice
            }

    def menu(self):
        while True:
            menu_options = self.menu_options()
            self.printer.header("Finance Menu")
            self.printer.print_menu_options(menu_options)
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == 'q':
                return
            try:
                list(menu_options.values())[int(action) - 1]()
            except:
                self.warning_msg = "Please select available option"

    def overview(self):
        while True:
            self.printer.header("Overview Menu")
            self.printer.print_options([
                'Income overview', 'Utilization overview', 'Invoice overview'
            ])
            self.printer.new_line(3)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == '1':
                self.income_overview()
            elif action == '2':
                self.utilization_overview()
            elif action == '3':
                self.invoice_overview()
            elif action == 'q':
                break
            else:
                self.warning_msg = "Please select available option"

    def invoice(self):
        while True:
            self.printer.header("Invoice Menu")
            self.printer.print_options(['Print invoice', 'Unpaid invoices'])
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == '1':
                self.view_invoices()
            elif action == '2':
                self.unpaid_invoice()
            elif action == 'q':
                break
            else:
                self.warning_msg = "Please select available option"

    #Overview Functions
    def income_overview(self):
        while True:
            self.printer.header("Income overview menu")
            self.printer.print_options(
                ['Branch Income', 'Vehicle Type Income'])
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()

            if action == '1':
                self.branch_report()
            elif action == '2':
                self.vehicle_type_report()
            elif action == 'q':
                break
            else:
                self.warning_msg = "Please select available option"

    def utilization_overview(self):
        while True:
            vehicles = self.logic.get_all_vehicles()
            vehicles_dict = self.create_utilazation_report(vehicles)
            self.printer.header("Utilization Overview")
            self.print_utilazation_report(vehicles_dict)
            self.printer.new_line()
            self.printer.print_fail("Press any key to go back")
            self.notification()
            action = input("Choose an option: ").lower()
            if action == 'q':
                break
            else:
                break
            break

    def branch_report(self):
        while True:
            try:
                while True:
                    date_1 = self.input.get_input("date from(DD/MM/YYYY)",
                                                  ["required", "date"],
                                                  warning_msg=self.warning_msg)
                    if date_1[0]:
                        date_1 = date_1[1]
                        break
                    else:
                        self.printer.print_warning(date_1[1])
                while True:
                    date_2 = self.input.get_input("date to(DD/MM/YYYY)",
                                                  ["required", "date"],
                                                  warning_msg=self.warning_msg)
                    if date_2[0]:
                        date_2 = date_2[1]
                        break
                    else:
                        self.printer.print_warning(date_2[1])

                contracts = self.logic.filter_contracts(
                    {"date": [date_1, date_2]})
                contract_dict = self.create_branch_report(contracts)
                self.printer.header("Branch Report")
                print("\n".join("\t{:^20} {:^20}".format(
                    self.logic.get_location_by_id(k).country, v)
                                for k, v in contract_dict.items()))
                self.printer.new_line()
                self.printer.print_fail("Press any key to go back")
                self.notification()
                action = input("Choose an option: ").lower()
                if action == 'q':
                    break
                else:
                    break
                break
            except ValueError:
                break

    def vehicle_type_report(self):
        while True:
            try:
                while True:
                    date_1 = self.input.get_input("date from(DD/MM/YYYY)",
                                                  ["required", "date"],
                                                  warning_msg=self.warning_msg)
                    if date_1[0]:
                        date_1 = date_1[1]
                        break
                    else:
                        self.printer.print_warning(date_1[1])
                while True:
                    date_2 = self.input.get_input("date to(DD/MM/YYYY)",
                                                  ["required", "date"],
                                                  warning_msg=self.warning_msg)
                    if date_2[0]:
                        date_2 = date_2[1]
                        break
                    else:
                        self.printer.print_warning(date_2[1])

                contracts = self.logic.filter_contracts(
                    {"date": [date_1, date_2]})
                contract_dict = self.create_vehicletype_report(contracts)
                self.printer.header("Vehicle Type Report")
                print("\n".join("\t{:^20} {:^20}".format(k, v)
                                for k, v in contract_dict.items()))
                self.printer.new_line()
                self.printer.print_fail("Press any key to go back")
                self.notification()
                action = input("Choose an option: ").lower()
                if action == 'q':
                    break
                else:
                    break
                break
            except ValueError:
                break

    def invoice_overview(self, created=False):
        current_page = 1
        try:
            while True:
                date_1 = self.input.get_input("date from(DD/MM/YYYY)",
                                              ["required", "date"],
                                              warning_msg=self.warning_msg)
                if date_1[0]:
                    date_1 = date_1[1]
                    break
                else:
                    self.printer.print_warning(date_1[1])
            while True:
                date_2 = self.input.get_input("date to(DD/MM/YYYY)",
                                              ["required", "date"],
                                              warning_msg=self.warning_msg)
                if date_2[0]:
                    date_2 = date_2[1]
                    break
                else:
                    self.printer.print_warning(date_2[1])
        except ValueError:
            return

        while True:
            contracts = self.logic.filter_contracts({"date": [date_1, date_2]})
            contracts_count = len(contracts)
            last_page = int(contracts_count / self.items_per_page) + (
                contracts_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else contracts_count

            self.printer.header("Invoice Overview")
            self.print_invoice_overview(contracts, start, end, current_page,
                                        last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("(N)ext page / (P)revious page: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            else:
                self.warning_msg = "Please select available option"

    #Invoice Functions
    def view_invoices(self, created=False):
        current_page = 1
        while True:
            contracts = self.logic.get_all_contracts()
            contracts_count = len(contracts)
            last_page = int(contracts_count / self.items_per_page) + (
                contracts_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else contracts_count

            self.printer.header("View Invoices")
            self.print(contracts, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect Invoice: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            elif action == 's' or action == "select":
                contract_id = input("Select invoice by ID: ").lower()
                if contract_id == 'q':
                    break
                contract = self.logic.get_contract_by_id(contract_id)
                if contract is None:
                    self.warning_msg = "contract not found"
                else:
                    self.print_invoice(contract_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out single invoice
    def print_invoice(self, contract_id):
        while True:
            contract = self.logic.get_contract_by_id(contract_id)
            self.printer.header("Invoice")
            print(
                "ID:{}\nCustomer:\t{}\nContract date:\t\t{}\nContract status:\t{}\nTotal:\t\t\t{}\nPaid:\t\t\t{}\n"
                .format(contract_id,
                        self.logic.get_customer_by_id(contract.customer_id),
                        contract.contract_date, contract.contract_status,
                        contract.total, contract.paid))
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()
            action = input("Select Option: ").lower()
            if action == 'q':
                break
            else:
                self.warning_msg = "Please select available option"

    # Prints out all Unpaid invoices
    def unpaid_invoice(self, created=False):
        current_page = 1
        try:
            while True:
                date_1 = self.input.get_input("date from(DD/MM/YYYY)",
                                              ["required", "date"],
                                              warning_msg=self.warning_msg)
                if date_1[0]:
                    date_1 = date_1[1]
                    break
                else:
                    self.printer.print_warning(date_1[1])
            while True:
                date_2 = self.input.get_input("date to(DD/MM/YYYY)",
                                              ["required", "date"],
                                              warning_msg=self.warning_msg)
                if date_2[0]:
                    date_2 = date_2[1]
                    break
                else:
                    self.printer.print_warning(date_2[1])
                break
        except ValueError:
            return

        while True:
            contracts = self.logic.filter_contracts({
                "date": [date_1, date_2],
                "status": "open"
            })
            contracts_count = len(contracts)
            last_page = int(contracts_count / self.items_per_page) + (
                contracts_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else contracts_count

            self.printer.header("Unpaid Invoices")
            self.print(contracts, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect Invoice: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            elif action == 's' or action == "select":
                contract_id = input("Select contract by ID: ").lower()
                if contract_id == 'q':
                    break
                contract = self.logic.get_contract_by_id(contract_id)
                if contract is None:
                    self.warning_msg = "contract not found"
                else:
                    self.print_invoice(contract_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out table of contract
    def print(self, contracts, start, end, current_page, last_page):
        if len(contracts) > 0:
            print(
                "|{:^4}|{:^40}|{:^25}|{:^15}|{:^27}|{:^15}|{:^15}|{:^15}|{:^20}|{:^15}|{:^15}|{:^10}|{:^10}|"
                .format("ID", "Customer", "Vehicle", "Employee", "Location",
                        "Date from", "Date to", "Contract Date",
                        "Contract status", "Pickup date", "Dropoff date",
                        "Total", "Paid"))
            print('-' * 240)
            for i in range(start, end):
                print(
                    "|{:^4}|{:^40}|{:^25}|{:^15}|{:^27}|{:^15}|{:^15}|{:^15}|{:^20}|{:^15}|{:^15}|{:^10}|{:^10}|"
                    .format(
                        contracts[i].id,
                        self.logic.get_customer_by_id(
                            contracts[i].customer_id).__str__(),
                        self.logic.get_vehicle_by_id(
                            contracts[i].vehicle_id).__str__(),
                        self.logic.get_employee_by_id(
                            contracts[i].employee_id).__str__(),
                        self.logic.get_location_by_id(
                            contracts[i].location_id).__str__(),
                        contracts[i].date_from, contracts[i].date_to,
                        contracts[i].contract_date,
                        contracts[i].contract_status, contracts[i].pickup_date,
                        contracts[i].dropoff_date, contracts[i].total,
                        contracts[i].paid))
            print("{:^240}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No contracts found"

    def print_invoice_overview(self, contracts, start, end, current_page,
                               last_page):
        if len(contracts) > 0:
            print("|{:^5}|{:^35}|{:^10}|{:^10}|".format(
                "ID", "Customer", "Total", "Paid"))
            print('-' * 65)
            for i in range(start, end):
                print("|{:^5}|{:^35}|{:^10}|{:^10}|".format(
                    contracts[i].id,
                    self.logic.get_customer_by_id(
                        contracts[i].customer_id).__str__(),
                    contracts[i].total, contracts[i].paid))
            print("{:^213}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No Invoices found"

    # Outputs warnings and success messages
    def notification(self):
        if not self.warning_msg == "":
            self.printer.print_warning(self.warning_msg)
            self.warning_msg = ""
        elif not self.success_msg == "":
            self.printer.print_success(self.success_msg)
            self.success_msg = ""
        else:
            self.printer.new_line()

    def create_branch_report(self, contracts):
        results = {}
        for contract in contracts:
            if contract.location_id not in results:
                results[contract.location_id] = []
            results[contract.location_id].append(int(contract.paid))
        updated_dict = {
            location: sum(amount)
            for location, amount in results.items()
        }
        return updated_dict

    def create_vehicletype_report(self, contracts):
        results = {}
        results2 = {}
        results3 = {}
        for contract in contracts:
            if contract.vehicle_id not in results:
                results[contract.vehicle_id] = []
            results[contract.vehicle_id].append(int(contract.paid))
        updated_dict = {
            vehicle: sum(amount)
            for vehicle, amount in results.items()
        }
        for key, value in updated_dict.items():
            if self.logic.get_vehicle_by_id(
                    key).vehicle_type_id not in results2:
                results2[self.logic.get_vehicle_by_id(
                    key).vehicle_type_id] = []
            results2[self.logic.get_vehicle_by_id(key).vehicle_type_id].append(
                value)
            updated_dict2 = {
                vt_id: sum(amount)
                for vt_id, amount in results2.items()
            }
        for key1, value1 in updated_dict2.items():
            if self.logic.get_vehicletype_by_id(key1).name not in results2:
                results3[self.logic.get_vehicletype_by_id(key1).name] = []
            results3[self.logic.get_vehicletype_by_id(key1).name].append(
                value1)
            updated_dict3 = {
                vt_id: sum(amount)
                for vt_id, amount in results3.items()
            }
        return updated_dict3

    def create_utilazation_report(self, vehicles):
        results = {}
        for vehicle in vehicles:
            if vehicle.location_id not in results:
                results[vehicle.location_id] = []
            results[vehicle.location_id].append(vehicle.vehicle_type_id)
        return results

    def print_utilazation_report(self, vehicles_dict):
        for key, value in vehicles_dict.items():
            my_dict = {
                self.logic.get_vehicletype_by_id(i).name: value.count(i)
                for i in value
            }
            print(self.logic.get_location_by_id(key).country)
            print("\n".join("\t{}: {}".format(k, v)
                            for k, v in my_dict.items()))
Exemplo n.º 7
0
class ContractUI:
    def __init__(self, employee_id, employee_role):

        self.items_per_page = 10
        self.employee_id = employee_id
        self.employee_role = employee_role

        self.logic = MainLogic()

        self.printer = PrinterUI()
        self.input = InputUI()

        self.employee_id = employee_id

        self.success_msg = ""
        self.warning_msg = ""

        self.menu()

    def create(self):
        counter = 0

        customer_id = ""
        vehicle_id = ""

        employee_id = self.employee_id
        location_id = ""
        location = ""
        date_from = ""
        date_to = ""

        contract_date = self.input.get_date()
        contract_status = "Open"
        pickup_date = ""
        dropoff_date = ""

        total = ""
        paid = 0

        customer_id_page = 1
        vehicle_id_page = 1
        location_id_page = 1
        while True:

            customer = self.logic.get_customer_by_id(customer_id)
            vehicle = self.logic.get_vehicle_by_id(vehicle_id)
            location = self.logic.get_location_by_id(location_id)

            if location is None:
                location = ""
            if customer is None:
                customer = ""
            if vehicle is None:
                vehicle = ""

            self.printer.header("Create contract")
            print(
                f"Customer:\t\t{customer}\nLocation:\t\t{location}\nDate from:\t\t{date_from}\nDate to:\t\t{date_to}\nVehicle:\t\t{vehicle}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            self.notification()
            next_input = True
            data = None
            try:
                if counter == 0:
                    while True:
                        print("Select customer:")
                        self.printer.print_options([
                            "Create new customer", "Select existing customer"
                        ])
                        self.printer.new_line()
                        action = input("Choose an option: ").lower()
                        if action == 'q':
                            return
                        if action == '1':
                            customer_id = str(
                                CustomerUI(show_menu=False).create().id)
                            break
                        if action == '2':
                            while True:
                                customers = self.logic.get_all_customers()
                                available_customers = [[
                                    customer.id, customer
                                ] for customer in customers]
                                customer_input = self.input.get_option(
                                    "customer",
                                    available_customers,
                                    current_page=customer_id_page,
                                    warning_msg=self.warning_msg)
                                if customer_input[0] == True:
                                    customer_id = customer_input[1]
                                    next_input = True
                                    break
                                else:
                                    next_input = False
                                    self.warning_msg = customer_input[1]
                                    customer_id_page = customer_input[2]
                            break
                elif counter == 1:
                    locations = self.logic.get_all_locations()
                    available_locations = [[location.id, location]
                                           for location in locations]
                    location_input = self.input.get_option(
                        "location",
                        available_locations,
                        current_page=location_id_page,
                        warning_msg=self.warning_msg)
                    if location_input[0] == True:
                        location_id = location_input[1]
                    else:
                        next_input = False
                        self.warning_msg = location_input[1]
                        location_id_page = location_input[2]
                elif counter == 2:
                    data = self.input.get_input("date from",
                                                ["required", "date"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        date_from = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 3:
                    data = self.input.get_input("date to",
                                                ["required", "date"],
                                                warning_msg=self.warning_msg)
                    if data[0]:
                        date_to = data[1]
                    else:
                        next_input = False
                        self.warning_msg = data[1]
                elif counter == 4:
                    all_vehicles = self.logic.filter_vehicles({
                        "location":
                        location_id,
                        "status":
                        "Available"
                    })
                    vehicles = [
                        v for v in all_vehicles
                        if self.logic.check_if_vehicle_is_rented(
                            v, date_from, date_to)
                    ]
                    available_vehicles = [[vehicle.id, vehicle]
                                          for vehicle in vehicles]
                    vehicle_input = self.input.get_option(
                        "vehicle",
                        available_vehicles,
                        current_page=vehicle_id_page,
                        warning_msg=self.warning_msg)
                    if vehicle_input[0] == True:
                        license_conformation = input(
                            "Does customer have license for this vehicle(\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                        )
                        if license_conformation == "y":
                            vehicle_id = vehicle_input[1]
                        elif license_conformation == "n":
                            self.printer.print_warning(
                                "Driver cannot register this vehicle, press any key to exit"
                            )
                            exit_input = input("Choose option: ")
                            if exit_input:
                                break
                        else:
                            next_input = False
                            self.warning_msg = vehicle_input[1]
                    else:
                        next_input = False
                        self.warning_msg = vehicle_input[1]
                        vehicle_id_page = vehicle_input[2]
                elif counter > 4:

                    self.logic.update_vehicle(vehicle_id,
                                              {"status": "Unavailable"})
                    vehicle = self.logic.get_vehicle_by_id(vehicle_id)

                    date_format = "%d/%m/%Y"

                    days = datetime.strptime(date_to,
                                             date_format) - datetime.strptime(
                                                 date_from, date_format)
                    total = (int(days.days) + 1) * int(
                        self.logic.get_vehicletype_by_id(
                            vehicle.vehicle_type_id).rate)

                    new_contract = Contract(customer_id, vehicle_id,
                                            employee_id, location_id,
                                            date_from, date_to, contract_date,
                                            contract_status, pickup_date,
                                            dropoff_date, total, paid)
                    confirmation = input(
                        "Are you sure you want to create this contract? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                    ).lower()
                    if confirmation == 'y':
                        self.logic.create_contract(new_contract)
                        return True
                    return False
                if next_input:
                    counter += 1
            except ValueError:
                break

    def menu_options(self):
        if self.employee_role.lower() == "admin":
            return {
                "Create a contract": self.create,
                "View contracts": self.view,
                "Customers": CustomerUI,
                "Deliver vehicle": self.pick_up,
                "Return vehicle": self.drop_off,
                "Pay contract": self.pay_contract
            }
        elif self.employee_role.lower() == "delivery":
            return {
                "View contracts": self.view,
                "Deliver vehicle": self.pick_up,
                "Return vehicle": self.drop_off
            }
        elif self.employee_role.lower() == "booking":
            return {
                "Create a contract": self.create,
                "View contracts": self.view
            }

    # Prints out contract's menu
    def menu(self):
        while True:
            menu_options = self.menu_options()
            self.printer.header("Contracts Menu")
            self.printer.print_menu_options(menu_options)
            self.printer.new_line(2)
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input("Choose an option: ").lower()
            if action == 'q':
                break
            try:
                list(menu_options.values())[int(action) - 1]()
            except:
                self.warning_msg = "Please select available option"

    def pick_up(self):
        contracts_page = 1
        while True:
            location = self.logic.get_employee_by_id(
                self.employee_id).location_id
            contracts = self.logic.filter_contracts({
                "location": location,
                "status": "open",
                "pickup": False
            })
            self.printer.header("Deliver vehicle")
            self.printer.print_fail("Press q to go back")
            self.notification()
            self.printer.new_line()
            available_contracts = [[
                contract.id,
                self.logic.get_customer_by_id(contract.customer_id)
            ] for contract in contracts]
            if len(available_contracts) > 0:
                while True:
                    data = self.input.get_option("customer",
                                                 available_contracts,
                                                 current_page=contracts_page,
                                                 warning_msg=self.warning_msg)
                    self.notification()
                    if data[0] == True:
                        contract_id = data[1]
                        break
                    else:
                        self.warning_msg = data[1]
                        contracts_page = data[2]

                while True:

                    self.printer.header("Deliver vehicle")

                    contract = self.logic.get_contract_by_id(contract_id)
                    customer = self.logic.get_customer_by_id(
                        contract.customer_id)
                    vehicle = self.logic.get_vehicle_by_id(contract.vehicle_id)
                    vehicletype = self.logic.get_vehicletype_by_id(
                        vehicle.vehicle_type_id)

                    print(
                        f"Name:\t\t\t\t{customer.name}\nSocial security number:\t\t{customer.ssn}\nPhone:\t\t\t\t{customer.phone}\nEmail:\t\t\t\t{customer.email}\n"
                    )
                    print(
                        f"Manufacturer:\t\t\t{vehicle.manufacturer}\nModel:\t\t\t\t{vehicle.model}\nVehicle type:\t\t\t{vehicletype.name}\nRate:\t\t\t\t{vehicletype.rate}\nManufacture year:\t\t{vehicle.man_year}\nColor:\t\t\t\t{vehicle.color}\nLicence needed:\t\t\t{vehicle.licence_type}\n"
                    )
                    print(
                        f"Delivery date:\t\t\t{contract.date_from}\nReturn date:\t\t\t{contract.date_to}\n"
                    )

                    self.printer.print_fail("Press q to go back")
                    self.notification()

                    action = input("(D)eliver vehicle: ").lower()
                    if action == 'q':
                        break
                    elif action == 'd' or action == "deliviery":
                        license_confirmation = input(
                            "Does customer have license for this vehicle(\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                        ).lower()
                        if license_confirmation == "y":
                            confirmation = input(
                                "Are you sure you want to deliver this vehicle? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                            ).lower()
                            if confirmation == 'y':
                                self.logic.contract_set_pickup(
                                    contract_id, self.input.get_date())
                                self.success_msg = "Vehicle has been delivered successfully"
                                break
                        elif license_confirmation == "n":
                            self.printer.print_warning(
                                "Driver cannot register this vehicle, press any key to exit"
                            )
                            exit_input = input("Choose option: ")
                            if exit_input:
                                break
                    else:
                        self.warning_msg = "Please select available option"
            else:
                print("No delivery scheduled for your location")
                self.printer.new_line()
                self.notification()
                action = input("Choose an option: ").lower()
                if action == 'q':
                    return
                else:
                    self.warning_msg = "Please select available option"

    def drop_off(self):
        contracts_page = 1
        while True:
            location = self.logic.get_employee_by_id(
                self.employee_id).location_id
            contracts = self.logic.filter_contracts({
                "location": location,
                "status": "open",
                "pickup": True,
                "dropoff": False
            })
            self.printer.header("Return vechicle")
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            available_contracts = [[
                contract.id,
                self.logic.get_customer_by_id(contract.customer_id)
            ] for contract in contracts]
            if len(available_contracts) > 0:
                while True:
                    data = self.input.get_option("customer",
                                                 available_contracts,
                                                 current_page=contracts_page,
                                                 warning_msg=self.warning_msg)
                    if data[0] == True:
                        contract_id = data[1]
                        break
                    else:
                        self.warning_msg = data[1]
                        contracts_page = data[2]

                while True:

                    self.printer.header("Return vechicle")

                    contract = self.logic.get_contract_by_id(contract_id)
                    customer = self.logic.get_customer_by_id(
                        contract.customer_id)
                    vehicle = self.logic.get_vehicle_by_id(contract.vehicle_id)
                    vehicletype = self.logic.get_vehicletype_by_id(
                        vehicle.vehicle_type_id)

                    print(
                        f"Name:\t\t\t\t{customer.name}\nSocial security number:\t\t{customer.ssn}\nPhone:\t\t\t\t{customer.phone}\nEmail:\t\t\t\t{customer.email}\n"
                    )
                    print(
                        f"Manufacturer:\t\t\t{vehicle.manufacturer}\nModel:\t\t\t\t{vehicle.model}\nVehicle type:\t\t\t{vehicletype.name}\nRate:\t\t\t\t{vehicletype.rate}\nManufacture year:\t\t{vehicle.man_year}\nColor:\t\t\t\t{vehicle.color}\nLicence needed:\t\t\t{vehicle.licence_type}\n"
                    )
                    print(
                        f"Delivery date:\t\t\t{contract.date_from}\nReturn date:\t\t\t{contract.date_to}\n"
                    )
                    print(
                        f"Amount paid:\t\t\t{contract.paid}\nTotal amount:\t\t\t{contract.total}\nAmount due:\t\t\t{contract.amount_due()}\n"
                    )

                    self.printer.print_fail("Press q to go back")
                    self.notification()

                    action = input("(R)eturn vechicle: ").lower()
                    if action == 'q':
                        break
                    elif action == 'r' or action == "return":
                        confirmation = input(
                            "Are you sure you want to return this vehicle? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                        ).lower()
                        if confirmation == 'y':
                            self.logic.contract_set_dropoff(
                                contract_id, self.input.get_date())
                            self.success_msg = "Vehicle has been returned successfully"
                            break
                    else:
                        self.warning_msg = "Please select available option"

            else:
                print("No return scheduled for your location")
                self.printer.new_line()
                self.notification()
                action = input("Choose an option: ").lower()
                if action == 'q':
                    return
                else:
                    self.warning_msg = "Please select available option"

    def pay_contract(self):
        contracts_page = 1
        while True:
            location = self.logic.get_employee_by_id(
                self.employee_id).location_id
            contracts = self.logic.filter_contracts({
                "location": location,
                "status": "open"
            })
            self.printer.header("Pay vechicle")
            self.printer.print_fail("Press q to go back")
            self.printer.new_line()
            available_contracts = [[
                contract.id,
                self.logic.get_customer_by_id(contract.customer_id)
            ] for contract in contracts]
            if len(available_contracts) > 0:
                while True:
                    data = self.input.get_option("contract",
                                                 available_contracts,
                                                 current_page=contracts_page,
                                                 warning_msg=self.warning_msg)
                    if data[0] == True:
                        contract_id = data[1]
                        break
                    else:
                        self.warning_msg = data[1]
                        contracts_page = data[2]

                while True:

                    self.printer.header("Pay contract")

                    contract = self.logic.get_contract_by_id(contract_id)
                    customer = self.logic.get_customer_by_id(
                        contract.customer_id)
                    vehicle = self.logic.get_vehicle_by_id(contract.vehicle_id)
                    vehicletype = self.logic.get_vehicletype_by_id(
                        vehicle.vehicle_type_id)

                    print(
                        f"Name:\t\t\t\t{customer.name}\nSocial security number:\t\t{customer.ssn}\nPhone:\t\t\t\t{customer.phone}\nEmail:\t\t\t\t{customer.email}\n"
                    )
                    print(
                        f"Manufacturer:\t\t\t{vehicle.manufacturer}\nModel:\t\t\t\t{vehicle.model}\nVehicle type:\t\t\t{vehicletype.name}\nRate:\t\t\t\t{vehicletype.rate}\nManufacture year:\t\t{vehicle.man_year}\nColor:\t\t\t\t{vehicle.color}\nLicence needed:\t\t\t{vehicle.licence_type}\n"
                    )
                    print(
                        f"Delivery date:\t\t\t{contract.date_from}\nReturn date:\t\t\t{contract.date_to}\n"
                    )
                    print(
                        f"Actual delivery date:\t\t\t{contract.pickup_date}\nActual return date:\t\t\t{contract.dropoff_date}\n"
                    )
                    print(
                        f"Amount paid:\t\t\t{contract.paid}\nTotal amount:\t\t\t{contract.total}\nAmount due:\t\t\t{contract.amount_due()}\n"
                    )

                    self.printer.print_fail("Press q to go back")
                    self.notification()

                    action = input(
                        "(C)lose contract / (P)ay partial: ").lower()

                    if action == 'q':
                        break
                    elif action == 'c' or action == "close":
                        amount = contract.amount_due()
                        confirmation = input(
                            "Are you sure you want to add {} to this contract? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                            .format(amount)).lower()
                        if confirmation == 'y':
                            self.logic.pay_to_contract(contract_id, amount)
                            break
                    elif action == 'p' or action == "pay":
                        amount = input(
                            "Enter amount between (1 - {}): ".format(
                                contract.amount_due()))
                        confirmation = input(
                            "Are you sure you want to add {} to this contract? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
                            .format(amount)).lower()
                        if confirmation == 'y':
                            self.logic.pay_to_contract(contract_id, amount)
                            break
                    else:
                        self.warning_msg = "Please select available option"

            else:
                print("No open contracts for your location")
                self.printer.new_line()
                self.notification()
                action = input("Choose an option: ").lower()
                if action == 'q':
                    return
                else:
                    self.warning_msg = "Please select available option"

    # Prints out all contract
    def view(self, created=False):
        current_page = 1
        while True:
            contracts = self.logic.get_all_contracts()
            contracts_count = len(contracts)
            last_page = int(contracts_count / self.items_per_page) + (
                contracts_count % self.items_per_page > 0)
            if current_page > last_page:
                current_page = last_page
            if created == True:
                current_page = last_page
                created = False
            start = (current_page - 1) * self.items_per_page
            end = start + 10 if not current_page == last_page else contracts_count

            self.printer.header("View contracts")
            self.print(contracts, start, end, current_page, last_page)
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()

            action = input(
                "(N)ext page / (P)revious page / (S)elect contract: ").lower()

            if action == 'q':
                break
            elif action == 'n' or action == "next":
                if current_page >= last_page:
                    current_page = last_page
                    self.warning_msg = "You are currenly on the last page"
                else:
                    current_page += 1
            elif action == 'p' or action == "previous":
                if current_page > 1:
                    current_page -= 1
                else:
                    current_page = 1
                    self.warning_msg = "You are currenly on the first page"
            elif action == 's' or action == "select":
                contract_id = input("Select contract by ID: ").lower()
                if contract_id == 'q':
                    break
                contract = self.logic.get_contract_by_id(contract_id)
                if contract is None:
                    self.warning_msg = "contract not found"
                else:
                    self.contract(contract_id)
            else:
                self.warning_msg = "Please select available option"

    # Prints out single contract
    def contract(self, contract_id):
        while True:
            contract = self.logic.get_contract_by_id(contract_id)
            customer = self.logic.get_customer_by_id(contract.customer_id)
            vehicle = self.logic.get_vehicle_by_id(contract.vehicle_id)
            vehicletype = self.logic.get_vehicletype_by_id(
                vehicle.vehicle_type_id)
            self.printer.header("View contract")

            print(
                f"Name:\t\t\t\t{customer.name}\nSocial security number:\t\t{customer.ssn}\nPhone:\t\t\t\t{customer.phone}\nEmail:\t\t\t\t{customer.email}\n"
            )
            print(
                f"Manufacturer:\t\t\t{vehicle.manufacturer}\nModel:\t\t\t\t{vehicle.model}\nVehicle type:\t\t\t{vehicletype.name}\nRate:\t\t\t\t{vehicletype.rate}\nManufacture year:\t\t{vehicle.man_year}\nColor:\t\t\t\t{vehicle.color}\nLicence needed:\t\t\t{vehicle.licence_type}\n"
            )
            print(
                f"Delivery date:\t\t\t{contract.date_from}\nReturn date:\t\t\t{contract.date_to}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")
            self.notification()
            action = input(
                "(E)dit / (I)nvalidate / (P)rint / (D)elete: ").lower()
            if action == 'q':
                break
            elif action == 'e' or action == 'edit':
                self.edit(contract_id)
            elif action == 'd' or action == 'delete':
                if self.delete(contract_id):
                    self.success_msg = "Contract has been deleted"
                    break
            elif action == 'i' or action == 'invalidate':
                if self.invalidate(contract_id):
                    self.success_msg = "Contract has been invalidated"
                    break
            elif action == 'p' or action == 'print':
                self.success_msg = "Contract has been printed"
            else:
                self.warning_msg = "Please select available option"

    # Prints out table of contract
    def print(self, contracts, start, end, current_page, last_page):
        if len(contracts) > 0:
            print(
                "|{:^4}|{:^40}|{:^27}|{:^27}|{:^15}|{:^15}|{:^15}|{:^20}|{:^15}|{:^15}|"
                .format("ID", "Customer", "Vehicle", "Location", "Date from",
                        "Date to", "Contract Date", "Contract status",
                        "Pickup date", "Dropoff date"))
            print('-' * 204)
            for i in range(start, end):
                print(
                    "|{:^4}|{:^40}|{:^27}|{:^27}|{:^15}|{:^15}|{:^15}|{:^20}|{:^15}|{:^15}|"
                    .format(
                        contracts[i].id,
                        self.logic.get_customer_by_id(
                            contracts[i].customer_id).__str__(),
                        self.logic.get_vehicle_by_id(
                            contracts[i].vehicle_id).__str__(),
                        self.logic.get_location_by_id(
                            contracts[i].location_id).__str__(),
                        contracts[i].date_from, contracts[i].date_to,
                        contracts[i].contract_date,
                        contracts[i].contract_status, contracts[i].pickup_date,
                        contracts[i].dropoff_date))
            print("{:^204}".format("Page {} of {}".format(
                current_page, last_page)))
            self.printer.new_line()
        else:
            self.warning_msg = "No contracts found"

    def edit(self, contract_id):
        customer_id_page = 1
        vehicle_id_page = 1
        location_id_page = 1
        role_page = 1
        while True:
            contract = self.logic.get_contract_by_id(contract_id)
            update = {}
            self.printer.header("Edit contract")
            print(
                f"ID:\t\t\t\t{contract_id}\nCustomer:\t\t\t{self.logic.get_customer_by_id(contract.customer_id)}\nVehicle:\t\t\t{self.logic.get_vehicle_by_id(contract.vehicle_id)}\nLocation:\t\t\t{self.logic.get_location_by_id(contract.location_id)}\nDate from:\t\t\t{contract.date_from}\nDate to:\t\t\t{contract.date_to}\nContract status:\t\t{contract.contract_status}\nPickup date:\t\t\t{contract.pickup_date}\nDropoff date:\t\t\t{contract.dropoff_date}\n"
            )
            self.printer.new_line()
            self.printer.print_fail("Press q to go back")

            self.printer.new_line()
            self.printer.print_options([
                'Edit customer', 'Edit vehicle', 'Edit location',
                'Edit date from', 'Edit date to', 'Edit contract status',
                'Edit pick up date', 'Edit drop off date'
            ])
            self.printer.new_line()
            self.notification()
            while True:
                action = input("Choose an option: ").lower()
                data = None
                try:
                    if action == "q":
                        return
                    elif action == "1":
                        while True:
                            customers = self.logic.get_all_customers()
                            available_customers = [[customer.id, customer]
                                                   for customer in customers]
                            data = self.input.get_option(
                                "customer",
                                available_customers,
                                current_page=customer_id_page,
                                warning_msg=self.warning_msg)
                            if data[0] == True:
                                update["customer_id"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                                customer_id_page = data[2]
                    elif action == "2":
                        while True:
                            vehicles = self.logic.get_all_vehicles()
                            available_vehicles = [[vehicle.id, vehicle]
                                                  for vehicle in vehicles]
                            data = self.input.get_option(
                                "vehicle",
                                available_vehicles,
                                current_page=vehicle_id_page,
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["vehicle_id"] = data[1]
                                date_format = "%d/%m/%Y"
                                days = datetime.strptime(
                                    contract.date_to,
                                    date_format) - datetime.strptime(
                                        contract.date_to, date_format)
                                total = int(days.days) * int(
                                    self.logic.get_vehicletype_by_id(
                                        data[1]).rate)
                                update["total"] = total
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "3":
                        while True:
                            locations = self.logic.get_all_locations()
                            available_locations = [[location.id, location]
                                                   for location in locations]
                            data = self.input.get_option(
                                "location",
                                available_locations,
                                current_page=location_id_page,
                                warning_msg=self.warning_msg)
                            if data[0] == True:
                                update["location_id"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                                location_id_page = data[2]
                    elif action == "4":
                        while True:
                            data = self.input.get_input(
                                "Date from", ["required", "date"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["date_from"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "5":
                        while True:
                            data = self.input.get_input(
                                "Date to", ["required", "date"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["date_to"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "6":
                        while True:
                            data = self.input.get_option(
                                "Contract status:",
                                ["Open", "Closed", "Invalid"],
                                current_page=role_page,
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["contract_status"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "7":
                        while True:
                            data = self.input.get_input(
                                "Pick up date", ["required", "date"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["pickup_date"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    elif action == "8":
                        while True:
                            data = self.input.get_input(
                                "Drop off date", ["required", "date"],
                                warning_msg=self.warning_msg)
                            if data[0]:
                                update["dropoff_date"] = data[1]
                                break
                            else:
                                self.printer.print_warning(data[1])
                    else:
                        self.warning_msg = "Please select available option"
                    if (len(update) > 0):
                        self.logic.update_contract(contract_id, update)
                        self.success_msg = "Contract has been modified"
                    break
                except ValueError:
                    break

    # Delete contract
    def delete(self, id):
        confirmation = input(
            "Are you sure you want to delete this contract? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
        ).lower()
        if confirmation == 'y':
            self.logic.delete_contract(id)
            return True
        return False

    def invalidate(self, contract_id):
        confirmation = input(
            "Are you sure you want to invalidate this contract? (\33[;32mY\33[;0m/\33[;31mN\33[;0m): "
        ).lower()
        if confirmation == 'y':
            self.logic.update_contract(contract_id,
                                       {"contract_status": "Invalid"})
            return True
        return False

    # Outputs warnings and success messages
    def notification(self):
        if not self.warning_msg == "":
            self.printer.print_warning(self.warning_msg)
            self.warning_msg = ""
        elif not self.success_msg == "":
            self.printer.print_success(self.success_msg)
            self.success_msg = ""
        else:
            self.printer.new_line()