-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreturn_.py
215 lines (150 loc) · 6.89 KB
/
return_.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import random
import datetime
from bill import *
def invalid_message():
print("\nIvalid input")
print("\nPlese select the value as per the provied options\n")
def display_Return():
file = open("file.txt","r")
print("--------------------------------------------------------------")
print("\tID \tCustome Name \tCustome Brand Price($) Quantity")
print("--------------------------------------------------------------")
counterID = 0
for line in file:
counterID = counterID + 1
print("\t", counterID, "\t" + line.replace(",","\t"))
print("----------------------------------------------------------")
file.close()
def dictionary_Return():
file = open("file.txt", "r")
counterID = 0
dictionaryCostume = {}
for line in file:
counterID = counterID + 1
line = line.replace("\n","")
line = line.split(',')
dictionaryCostume[counterID] = line
#print(dictionaryCostume)
return dictionaryCostume
file.close()
def valid_costume_ID():
continueLoop=True
while continueLoop==True:
try:
validCostumeID = int(input("Enter the ID of costume you want to return: "))
break
except:
print("Invalid option!!")
while validCostumeID <= 0 or validCostumeID > len(dictionary_Return()):
valid2=int(input("\nPlease provide a valid costume ID :"))
return validCostumeID
def quantity_costume(stockQuantity):
continueLoop=True
while continueLoop==True:
try:
quantityOfCostume = int(input("\nEnter the quantity of costume: "))
break
except:
print("Invalid option!!")
while quantityOfCostume <=0 :
if quantityOfCostume <= 0:
valid_quantity()
quantityOfCostume = int(input("Enter the quantity: "))
return quantityOfCostume
def stock_costume(dictionary):
file = open("file.txt","w")
for i in dictionary.values():
line = str(i[0] + "," + str(i[1]) + "," + str(i[2]) + "," + str(i[3]))
file.write(line)
file.write("\n")
file.close()
def bill():
print()
print("====================================================")
print(" Bill Details ")
print("====================================================")
print("Name of Customer: ", name)
print("Date and time of return: ", todaysDate)
print("Items returned are: ",", ".join(ReturnCostumeNameArray))
print("Total fine: $",finecharged)
print("----------------------------------------------------")
print()
print("+++++++++++++++++++++++++++++++++++++++++++++++++")
print("| Return Detail Bill has been generated. |")
print("+++++++++++++++++++++++++++++++++++++++++++++++++")
print()
num=str(random.randint(999999999,9999999999))
bill = open("Return_"+name+"_"+num+".txt","w")
bill.write("===============================================\n")
bill.write(" Invoice \n")
bill.write("===============================================\n")
bill.write(" Name of Customer: " + str(name))
bill.write("\n Date and time of return: " +str(todaysDate))
bill.write("\n Items returned are: " + ", ".join(ReturnCostumeNameArray))
bill.write("\nTotal fine: $"+str(finecharged))
bill.write("\n===============================================")
bill.close()
while True:
display_Return()
dictionary_Return()
dictionaryCostume = dictionary_Return()
#print(dictionaryCostume)
ReturnCostumeID = valid_costume_ID()
ReturnCostumeNameArray = []
if int(dictionaryCostume[ReturnCostumeID][3]) > 0:
quantityOfCostume = quantity_costume(int(dictionaryCostume[ReturnCostumeID][3]))
dictionaryCostume[ReturnCostumeID][3] = int(dictionaryCostume[ReturnCostumeID][3]) + quantityOfCostume
print(dictionaryCostume)
finecharged=0
continueLoop=True
while continueLoop==True:
try:
day = int(input("\n For how many days have you rented the costume? "))
break
except:
print("Please enter the day in number.")
if day <=7:
days_of_fine= 0
elif day >7:
days_of_fine= day - 7
finecharged += (days_of_fine*10)
print("The total fine charged is: $",finecharged)
name = input("Enter the name of customer: ")
todaysDate = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
ReturnCostumeNameArray.append(dictionaryCostume[ReturnCostumeID][0])
stock_costume(dictionaryCostume)
print("===================================================")
print("Do you wannt to return any other costumes??")
continueReturn = input("Please enter 'y' if another costume has been Returned else provide any other value: ").lower()
while True:
if continueReturn == "y":
print()
display_Return()
dictionaryCostume = dictionary_Return()
ReturnCostumeID = valid_costume_ID()
if int(dictionaryCostume[ReturnCostumeID][3]) > 0:
quantityOfCostume = quantity_costume(int(dictionaryCostume[ReturnCostumeID][3]))
dictionaryCostume[ReturnCostumeID][3] = int(dictionaryCostume[ReturnCostumeID][3]) + quantityOfCostume
print(dictionaryCostume)
finecharged=0
continueLoop=True
while continueLoop==True:
try:
day = int(input("\n For how many days have you rented the costume? "))
break
except:
print("Please enter the day in number.")
if day <=7:
days_of_fine= 0
elif day >7:
days_of_fine= day - 7
finecharged += (days_of_fine*10)
print("The total fine charged is: $",finecharged)
ReturnCostumeNameArray.append(dictionaryCostume[ReturnCostumeID][0])
stock_costume(dictionaryCostume)
print("==================================================")
print("Have the costumer returned another costume as well??")
continueReturn = input("Please enter 'y' if another costume has been Returned else provide any other value: ").lower()
else:
bill()
break