Hotelrezeption/client_test.py

210 lines
6.9 KiB
Python

import math
#----------------CLASS---KEY------------------------------------------
class Key:
how_many_keys = 0
# Initialisation of keys
def __init__(self, keynumber):
self.number = keynumber
self.possessor = "Reception"
#where are the keys
def status_key(self, keynumber=None):
return self.number, self.possessor
def hand_out_key(self, keynumber, Guest):
self.possessor = Guest
def get_back_key(self, keynumber):
self.possessor = "Reception"
# Generates all the keys, two for each room
# results in keynumbers: 11, 12, 21, 22, 31, 32, 41, 42
key_list = []
for i in range(11, 42, 10):
a = "key_" + str(i) + " = Key(" + str(i) + ")"
exec(a)
a2 = "key_list.append(key_" + str(i) + ")"
exec(a2)
b = "key_" + str(i+1) + " = Key(" + str(i+1) + ")"
exec(b)
b2 = "key_list.append(key_" + str(i+1) + ")"
exec(b2)
#----------------CLASS---CLIENT------------------------------------------
class Client():
months = ['Januar', 'Februar','März','April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']
all_clients=[]
clients = 0
def __init__(self, name: str, surname: str, client_num: int, room: str, period, key_num: int, bookings, status: bool):
self.name = name
self.surname = surname
self.client_num = client_num
self.room = None
self.period = period
self.key_num = 0
self.bookings = 0
self.status = False
# Automatic status adjustment
if len(self.bookings) >= 4:
self.status = True
Client.clients += 1
def check_in(self, room, key_num):
room_list[reference.index(room)].occupy(surname, self.period)
num_ = "key_" + str(key_num) + ".hand_out_key(" + str(key_num) + "," + "'" + str(surname) + "')"
try:
exec(num_)
self.key_num = key_num
except:
("Schlüssel mit Daten nicht gefunden.")
def change_room(self, surname, new_room, key_num = 0): # Room add period
room_list[reference.index(self.room)].free()
room_list[reference.index(new_room)].occupy(surname, self.period)
num_ = "key_" + str(key_num) + ".hand_out_key(" + str(key_num) + "," + "'" + str(surname) + "')"
try:
exec(num_)
self.key_num = key_num
except:
("Schlüssel mit Daten nicht gefunden.")
def name_change(self, name, surname):
self.name = name
self.surname = surname
# Length of stay as print
def period_print(self):
stay_period = []
num_string = ""
for i in self.period:
if i.isnumeric():
num_string += i
if i == ",":
stay_period.append(num_string)
num_string = ""
stay_period.append(num_string)
print(stay_period)
stay_period = tuple(stay_period)
# Same month
if stay_period[1] == stay_period[3]:
days = int(stay_period[0]) - int(stay_period[2])
month_num = int(stay_period[1]) + 1
month_print = Client.months[month_num]
print("Der Kunde bleibt", abs(days), "Tage.")
print("Vom", stay_period[0], "bis", stay_period[2], month_print)
# Across months
if stay_period[1] != stay_period[3]:
# Stay period more than 1 month
if int(stay_period[3]) - int(stay_period[1]) > 1:
days = 28 - int(stay_period[0]) + int(stay_period[2]) + \
((int(stay_period[3]) - int(stay_period[1])-1) * 28)
# Stay period
else:
days = 28 - int(stay_period[0]) + int(stay_period[2])
month_num_1 = int(stay_period[1]) - 1
month_num_2 = int(stay_period[3]) - 1
month_print_1 = Client.months[month_num_1]
month_print_2 = Client.months[month_num_2]
print("Der Kunde bleibt", abs(days), "Tage.")
print("Vom", stay_period[0], month_print_1, "bis", stay_period[2], month_print_2)
# Client information
def info(self, action = None):
dic_ = {"Name" : self.name,
"Nachname" : self.surname,
"Kundennummer" : self.client_num,
"Zimmer" : self.room,
"Aufenthaltsdauer": self.period,
"Schlüsselnummer" : self.key_num,
"Buchungen" : self.bookings,
"VIP-Status" : self.status
}
if action != None:
# If asked client information is stay period
if action == "Aufenthaltsdauer":
client_num = self.client_num
stay = str(client_num)+ ".period_print()"
exec(stay)
# If asked client information is different
if action != "Aufenthaltsdauer":
for i in dic_:
if i == action:
print(action, "ist", dic_[i])
else:
for i in dic_:
print(i.ljust(16), ": ", dic_[i])
w43 = Client("David", "Gebert", "w43", "Suite", "01,02,03,03", 22, (51,61,77), False)
w43.period_print()
#----------------CLASS--ROOM------------------------------------------
''' Implementierung der Klasse Zimmer '''
class Room:
def __init__(self, room_number, guest=None, period=None):
self.number = room_number
self.occupied = False
self.resident = None
self.period = None
# Room gets occupied by a client
def occupy(self, guest, period):
self.occupied = True
self.resident = guest
self.period = period
# Room is no longer occupied
def free(self):
self.occupied = False
self.resident = None
self.period = None
# room information
def info(self, action = None):
dic_ = {"Nummer" : self.number,
"Gast" : self.resident,
}
if action != None:
if action == "Nummer":
print("Das Zimmer" + str(self) + "hat die Nummer" + dic_["Nummer"]
if action == "Gast":
if dic_["Gast"] != None:
print("Das Zimmer" + str(self) + "ist gerade vom Gast" + dic_["Gast"] + "belegt")
else:
print("Das Zimmer" + str(self) + "ist im Moment nicht belegt.")
else:
for i in dic_:
print(i.ljust(16), ": ", dic_[i])
# Generates all the rooms
# nr.10-"Single", nr.20-"Double", nr.30-"Suite", nr.40-"Panorama-Suite"
reference = ["Single", "Double", "Suite", "Panorama-Suite"]
room_types = [["Single", 10], ["Double", 20], ["Suite", 30], ["Panorama-Suite", 40]]
room_list = []
for i in room_types:
tmp = '''i[0] = Room(i[1])
room_list.append(i[0])'''
exec(tmp)
print(room_list)