Beispiel #1
0
def set_reservations(room_id):
    if request.method == 'GET':
        room = Room.query.filter_by(id=room_id).first()

        if room is None:
            return jsonify({'message': 'ERROR'})

        reservations_dict = []
        for i in room.reservations:
            reservations_dict.append(i.to_dict())
        return jsonify(reservations_dict)

    elif request.method == 'PUT':
        room = Room.query.filter_by(id=room_id).first()

        if room is None:
            return jsonify({'message': 'ERROR'})

        new_reservation = request.get_json()
        new_reservation = new_reservation['reservation']

        d_from = datetime.strptime(new_reservation['date_from'], "%Y-%m-%d")
        if new_reservation['date_to'] is None:
            d_to = None
        else:
            d_to = datetime.strptime(new_reservation['date_to'], "%Y-%m-%d")

        renter_public_id = new_reservation['public_user_id']
        renter = User.query.filter_by(public_id=renter_public_id).first()

        room.reservations.append(
            Reservation(d_from, d_to, Status.rented, renter.id))

        db.session.commit()
        return jsonify({'message': 'SUCCESS'})
Beispiel #2
0
 def make_reservation(self, location_id, start, end):
     reservation = Reservation(db=self.__db, customer_id=self.current_customer_id,
                               location_id=location_id, start=start, end=end)
     if reservation.inserted:
         return self.__db.get_last_insert_id()
     else:
         return False
Beispiel #3
0
def get_random_data():
    rooms_number = 100
    rooms = []

    for i in range(rooms_number):
        room = Room(random.choice(list(RoomTypes)), random.randint(1, 5),
                    random.randint(1, 5), random.randint(1, 10),
                    bool(random.getrandbits(1)), "desc",
                    bool(random.getrandbits(1)), bool(random.getrandbits(1)),
                    bool(random.getrandbits(1)), bool(random.getrandbits(1)),
                    bool(random.getrandbits(1)), bool(random.getrandbits(1)),
                    bool(random.getrandbits(1)), bool(random.getrandbits(1)),
                    bool(random.getrandbits(1)), bool(random.getrandbits(1)),
                    37.9754983 + random.uniform(-1, 1),
                    23.7356671 + random.uniform(-1, 1), "address", "info",
                    random.randint(1, 5), random.randint(23, 300),
                    random.uniform(10, 70), random_sentence(3),
                    random.randint(6, 20), random.randint(1, 3), 7)

        for y in range(10):
            room.images.append(
                Image('https://picsum.photos/id/' + str(i * 10 + y) +
                      '/400/400'))
            room.reviews.append(
                Review(random.uniform(1, 5), random_sentence(3),
                       random_sentence(10), 4))

            start_date = datetime.now()

            for x in range(10):
                next_date = start_date + timedelta(days=random.randint(2, 30))

            room.reservations.append(
                Reservation(start_date, next_date, Status.rented))

            start_date = next_date + timedelta(days=random.randint(20, 40))

            next_date = None
            room.reservations.append(
                Reservation(start_date, next_date, Status.not_available))

            db.session.add(room)

            db.session.commit()
Beispiel #4
0
    def update(self, simulation_date):
        """
        Method to update an application
        :param simulation_date: Integer
        :return None if application is finished
        """
        if self._terminated :
            return
        self._dag.update(simulation_date)

        #Making reservation
        ready_tasks = self._dag.get_ready_tasks()
        for i in range(0, len(ready_tasks)):
            ready_task = ready_tasks[i]
            reservation = Reservation(ready_task.resource, ready_task.criticality, ready_task)
            ready_task.status = TaskStatus.SCHEDULED
            self._resource_manager.reserve(self, reservation)
Beispiel #5
0
def unavailable_dates(room_id):
    if request.method == 'GET':
        room = Room.query.filter_by(id=room_id).first()

        if room is None:
            return jsonify({'message': 'ERROR'})

        reservations_dict = []
        for i in room.reservations:
            if i.status == Status.not_available:
                reservations_dict.append(i.to_dict())
        return jsonify(reservations_dict)
    elif request.method == 'POST':
        room = Room.query.filter_by(id=room_id).first()

        new_reservations = request.get_json()
        print(new_reservations)
        new_reservations = new_reservations['new_reservations']

        reservations = new_reservations['reservations']
        renter_public_id = new_reservations['public_user_id']
        renter = User.query.filter_by(public_id=renter_public_id).first()

        if room is None:
            return jsonify({'message': 'ERROR'})

        for r in room.reservations:
            db.session.delete(r)
        for a in reservations:
            d_from = datetime.strptime(a['date_from'], "%Y-%m-%d")
            if a['date_to'] is None:
                d_to = None
            else:
                d_to = datetime.strptime(a['date_to'], "%Y-%m-%d")

            room.reservations.append(
                Reservation(d_from, d_to, Status.not_available, renter.id))

        db.session.commit()
        return jsonify({'message': 'SUCCESS'})
Beispiel #6
0
    def reservations_menu(
        self, current_employee
    ):  #THIS IS READY APPLY THIS TO YOUR UI MIGHT NEED TO CHANGE CURRENT_EMPLOYEE
        action = ""
        options = ["1", "2", "3", "4", "5"]
        print("=== RESERVATIONS ===\n")
        while action not in options:
            print("AVAILABLE OPTIONS:")
            print(
                "1. Make reservation\n2. Lookup reservation\n3. Edit reservation\n4. Cancel reservation\n5. Go back"
            )
            action = input("Enter: ")
            print("")

            if action == "1":
                customer_drivers_license = input("Drivers license number: ")
                body_type = input("Body type: ")
                from_date = input("From: ")
                to_date = input("To: ")

                if self.__res_services.check_dates(body_type, from_date,
                                                   to_date) > 0:
                    body_amount = self.__res_services.check_dates(
                        body_type, from_date, to_date)
                    print("There are {} {}'s available for the dates selected".
                          format(body_amount, body_type))
                else:
                    print("There are no {}'s available for the dates selected".
                          format(body_type))
                insurance = input("Insurance?(Y/N): ").lower()
                if insurance == "y":
                    cost = self.__res_services.calc_res_cost(insurance)
                else:
                    cost = self.__res_services.calc_res_cost()
                CC = input("Enter Credit Card number: ")
                payment_method = input(
                    "Payment method (Cash/Credit): ").lower()
                if payment_method == "cash":
                    payment_method == "Cash"
                elif payment_method == "credit":
                    payment_method == "Credit"
                else:
                    print("Invalid input")
                    self.reservations_menu(current_employee)

                employee = current_employee
                res_num = self.__res_services.get_res_num()
                new_reservation = Reservation(res_num,
                                              customer_drivers_license,
                                              from_date, to_date, cost, CC,
                                              payment_method, employee)
                self.__res_services.make_res(new_reservation)
                print("")
                self.reservations_menu(current_employee)

            elif action == "2":
                #Search Reservations
                res_num = input("Enter reservation number: ")
                self.__res_services.search_res(res_num)
                self.reservations_menu(current_employee)

                #1,customer_license_num,CC_number,from_date,to_date,insurance(Y/N),body,employee

            elif action == "3":  #Edit res
                edit_action = ""
                edit_options = ["1", "2", "3", "4", "5", "6", "7"]
                res_num = input("Enter reservation number: ")
                print("\nWhat would you like to change?\n")
                print(
                    "1. License number\n2. Credit Card\n3. From Date\n4. To Date\n5. Insurance\n6. Body\n7. Finish"
                )  #
                while edit_action not in edit_options:
                    edit_action = input("Enter: ")
                    if edit_action == "1":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "2":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "3":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "4":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "5":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "6":
                        change = input("Enter new info: ")
                        self.__res_services.edit_res(res_num, edit_action,
                                                     change)
                    elif edit_action == "7":
                        self.reservations_menu(current_employee)
                    self.reservations_menu(current_employee)

            elif action == "4":
                #cancel reservation
                res_num = input("Enter reservation number: ")
                self.__res_services.cancel_res(res_num)
                self.reservations_menu(current_employee)

            elif action == "5":
                #Go back to main menu
                self.main_menu(current_employee)

            else:
                print("INPUT INVALID\n")
                self.reservations_menu(current_employee)
Beispiel #7
0
 def update_reservation_end(self, reservation_id, new_end):
     reservation = Reservation(db=self.__db, reservation_id=reservation_id)
     reservation.update_end(new_end)