Beispiel #1
0
def delete_reservation(config, client_id):
    """
    Undo reserve-dates command.

    Usage:\n
    hotel delete-reservation client_id\n

    Arguments:\n
    client_id is type INT\n

    Description:\n
    This commmand removes reservation in rooms/reservations/{best_room}.csv for client_id, state = 3\n
    Removes and rejoins old interverl in rooms/interval/{best_rom}.csv\n
    Updates client_list.csv with new informtion

    """
    helpers.handle_session()

    if client_id in config.client_list.index:

        if config.client_list.loc[client_id, "state"] == 2:
            hotel_path = helpers.get_hotel_path()
            full_path = os.path.join(config.cwd_path, hotel_path)

            res_start = config.client_list.loc[client_id, "start"]
            res_end = config.client_list.loc[client_id, "end"]
            room_number = config.client_list.loc[client_id, "reserved_room"]

            helpers.remove_reservation_client_list(config.client_list,
                                                   client_id)
            helpers.overwrite_client_list(config.client_list, full_path)

            helpers.remove_reservations(config.reservations, res_start)
            helpers.overwrite_reservations(config.reservations,
                                           config.cwd_path, hotel_path,
                                           room_number)

            helpers.remove_intervals(config.intervals, res_start, res_end,
                                     room_number)
            helpers.overwrite_intervals(config.intervals, config.cwd_path,
                                        hotel_path, room_number)

            click.echo("The reservation has been deleted.")

        else:
            click.echo(
                f"The client ID {client_id} does not have a reservation.")
    else:
        click.echo(
            f"The client ID {client_id} does not exist. Please use a valid client ID"
        )
Beispiel #2
0
def check_in(config, client_id):
    """
    Update client list after check-in.

    Usage:\n
    hotel check-in client_id\n

    Arguments:\n
    client_id is type INT\n

    Description:\n
    This commmand pops reservation from reservation in rooms/reservations/{best_room}.csv\n
    Popped reservation is updated in client_list.csv\n
    State = 1

    """
    helpers.handle_session()

    if client_id in config.client_list.index:

        if config.client_list.loc[client_id, "state"] == 2:

            hotel_path = helpers.get_hotel_path()
            full_path = os.path.join(config.cwd_path, hotel_path)

            res_start = config.client_list.loc[client_id, "start"]
            room_number = config.client_list.loc[client_id, "reserved_room"]

            helpers.checkin_client_list(config.client_list, client_id)
            helpers.overwrite_client_list(config.client_list, full_path)

            helpers.pop_reservation(config.reservations, res_start,
                                    room_number)
            helpers.overwrite_reservations(config.reservations,
                                           config.cwd_path, hotel_path,
                                           room_number)
            click.echo("You are now checked in!")
        else:
            click.echo(
                f"The client ID {client_id} does not have a reservation. Please first make a reservation"
            )
    else:
        click.echo(
            f"The client ID {client_id} does not exist. Please use a valid client ID"
        )
Beispiel #3
0
def register(config, name, email):
    """
    Add new client information to the DB.

    Usage:\n
    hotel register name email\n

    Arguments:\n
    name is type STRING\n
    email is type STRING\n

    Description:\n
    This commmand adds new clients to the DB, starting state = 3\n
    Client_supp.csv saves new client info, assigns a client ID\n
    Client_list.csv uses client ID to track relevent informtion

    """
    helpers.handle_session()

    id_list = helpers.unique_client(config.client_supp, name, email)

    if id_list.empty:
        hotel_path = helpers.get_hotel_path()
        full_path = os.path.join(config.cwd_path, hotel_path)

        config.client_supp = helpers.add_client_supp(config.client_supp, name,
                                                     email)
        helpers.overwrite_client_supp(config.client_supp, full_path)

        config.client_list = helpers.add_client_list(config.client_list, 3,
                                                     None, None, -1, None,
                                                     False, -1)
        helpers.overwrite_client_list(config.client_list, full_path)

        click.echo("Registration successful!")

    else:
        click.echo(
            f"The a client already exists with name: {name} and email: {email}"
        )
Beispiel #4
0
def check_out(config, client_id, paid):
    """
    Update client list after check-out.

    Usage:\n
    hotel check-out client_id paid\n

    Arguments:\n
    client_id is type INT\n
    paid is stype BOOL\n

    Description:\n
    This commmand updates client_list.csv with new informtion, state = 3
    """
    helpers.handle_session()

    if client_id in config.client_list.index:

        if config.client_list.loc[client_id, "state"] == 1:

            hotel_path = helpers.get_hotel_path()
            full_path = os.path.join(config.cwd_path, hotel_path)

            helpers.checkout_client_list(config.client_list, client_id, paid)
            helpers.overwrite_client_list(config.client_list, full_path)

            click.echo("You are now checked out!")

        else:
            click.echo(
                f"The client ID {client_id} is not currently checked-in. Please first ensure client is checked-in"
            )
    else:
        click.echo(
            f"The client ID {client_id} does not exist. Please use a valid client ID"
        )
Beispiel #5
0
def reserve_dates(config, client_id, room_type, start, end):
    """
    Find ideal rooms based on criteria given.

    Usage:\n
    hotel reserve-dates client_id room_type start_date end_date\n

    Arguments:\n
    client_id is type INT\n
    room_type is type INT\n
    start_date is format %Y-%m-%d\n
    end_date is format %Y-%m-%d\n

    Description:\n
    This commmand returns a list of rooms that match the criteria given\n
    Rooms are ordered by the minimal disruption of free intervals\n
    Creates new reservation in rooms/reservations/{best_room}.csv\n
    Splits and adds new interverl in rooms/interval/{best_rom}.csv\n
    Updates client_list.csv with new informtion, reserved state = 2

    """
    helpers.handle_session()

    if client_id in config.client_list.index:

        if config.client_list.loc[client_id, "state"] == 3:

            hotel_path = helpers.get_hotel_path()
            full_path = os.path.join(config.cwd_path, hotel_path)

            room_matching_type = helpers.get_room_of_type(
                config.hotel, room_type)
            df_intervals = config.intervals[room_matching_type].dropna(
                axis=0, how="all")

            available_rooms = helpers.get_room_number_optimized(
                df_intervals, start, end)
            delta = end - start

            if available_rooms.empty:
                click.echo("Sorry! There are no rooms available!")
            else:
                best_room = available_rooms["room"][0]

                payment = helpers.get_payment(config.hotel, best_room)
                payment_due = delta.days * payment
                paid = False

                helpers.add_reservation_client_list(
                    config.client_list,
                    client_id,
                    2,
                    start,
                    end,
                    best_room,
                    payment_due,
                    paid,
                )
                helpers.overwrite_client_list(config.client_list, full_path)

                helpers.add_reservations(config.reservations, best_room,
                                         client_id, start)
                helpers.overwrite_reservations(config.reservations,
                                               config.cwd_path, hotel_path,
                                               best_room)

                helpers.add_intervals(config.intervals, best_room, start, end,
                                      hotel_path)
                helpers.overwrite_intervals(config.intervals, config.cwd_path,
                                            hotel_path, best_room)

                click.echo("Reservation successful!")
        else:
            click.echo(
                f"The client ID {client_id} is currently unable to accept a new reservation. Please verify the current client state"
            )
    else:
        click.echo(
            f"The client ID {client_id} does not exist. Please use a valid client ID"
        )