-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsql.py
More file actions
executable file
·180 lines (143 loc) · 4.8 KB
/
sql.py
File metadata and controls
executable file
·180 lines (143 loc) · 4.8 KB
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
#!/usr/bin/python3
from datetime import date
import sqlite3
conn = sqlite3.connect('hotel.db', check_same_thread=False)
cursor = conn.cursor()
def getRoom(heads, inDate, outDate, category):
inD = date(*map(int, inDate.split('-')))
outD = date(*map(int, outDate.split('-')))
days=(outD-inD).days
sql = "select roomNo from Rooms where category="+str(category)
cursor.execute(sql)
roomNo=cursor.fetchall()
r=-1
for rn in roomNo:
sql="select checkindate,checkoutdate from booked where roomno="+str(rn[0])
cursor.execute(sql)
ddd=cursor.fetchall()
if(len(ddd)==0):
r=rn[0]
break
if(r==-1):
for i in range(0,len(ddd)):
if( outDate<str(ddd[i][0]) ):
if( inDate>str(ddd[i-1][1]) ):
r=rn[0]
break
if(r==-1):
r=None
cursor.execute("""SELECT basePrice,pricePerHead,pricePerDay
FROM Price WHERE category="""+str(category)
)
x=cursor.fetchone()
bsp=x[0]
pph=x[1]
ppd=x[2]
total=int(bsp)+int(pph)*int(heads)+int(ppd)*int(days)
final={
"roomno" : r,
"amount" : total
}
#conn.close()
return(final)
def bookRoom(cID,name,phNo,email,heads,inDate,outDate,category,roomNo,amount):
sql="SELECT datetime('now')"
cursor.execute(sql)
x=cursor.fetchone()
datenow=x[0]
rr=getRoom(heads, inDate, outDate, category)
if rr==None:
return False
sql="select count(*) from customers where cId='"+str(cID)+"'"
cursor.execute(sql)
x=cursor.fetchone()
if(x[0]==0):
sql="INSERT INTO customers(cid,name,email,phno) VALUES(?,?,?,?)"
cursor.execute(sql,(cID,name,email,phNo,))
sql="INSERT INTO Bills(amount,generationdate) VALUES(?,?)"
cursor.execute(sql,(amount,datenow))
sql="SELECT count(*) from Bills"
cursor.execute(sql)
x=cursor.fetchone()
inv=x[0]
sql="INSERT INTO Booked(cid,roomNo,heads,checkindate,checkoutdate,invoiceid) VALUES(?,?,?,?,?,?)"
cursor.execute(sql,(cID,roomNo,heads,inDate,outDate,inv))
conn.commit()
#conn.close()
def checkStatus(cID,inDate):
final=False
sql="select count(*) from booked where cid='"+str(cID)+"'"+"and checkindate='"+str(inDate)+"'"
cursor.execute(sql)
y=cursor.fetchone()
if(y[0]!=0):
sql="select * from booked where cid='"+str(cID)+"'"+"and checkindate='"+str(inDate)+"'"
cursor.execute(sql)
y=cursor.fetchall()
y=y[0]
sql="select * from customers where cid='"+str(cID)+"'"
cursor.execute(sql)
x=cursor.fetchone()
final={
"name" : x[1],
"email" : x[2],
"phoneno" : x[3],
"checkin" : y[3],
"checkout" : y[4],
"roomno" : y[1]
}
return(final)
def generateBill(cID,inDate):
sql="select count(*) from booked where cid='"+str(cID)+"'"+"AND checkindate='"+str(inDate)+"'"
cursor.execute(sql)
x=cursor.fetchone()
final=False
if(x[0]!=0):
sql="select * from booked where cid='"+str(cID)+"'"+"AND checkindate='"+str(inDate)+"'"
cursor.execute(sql)
x=cursor.fetchall()
x=x[0]
inv=x[5]
sql="select * from bills where invoiceid='"+str(inv)+"'"
cursor.execute(sql)
y=cursor.fetchone()
sql="select * from customers where cid='"+str(cID)+"'"
cursor.execute(sql)
z=cursor.fetchone()
final={
"name" : z[1],
"phoneno" : z[3],
"email" : z[2],
"checkin" : x[3],
"checkout" : x[4],
"amount" : y[1],
"invoiceid" : y[0]
}
#conn.close()
return(final)
def cancelBooking(inID):
sql="SELECT count(*) FROM Bills WHERE invoiceID='"+str(inID)+"'"
cursor.execute(sql)
x=cursor.fetchone()
if(x[0]==0):
return(False)
sql="DELETE FROM Booked WHERE invoiceID='"+str(inID)+"'"
cursor.execute(sql)
sql="DELETE FROM Bills WHERE invoiceID='"+str(inID)+"'"
cursor.execute(sql)
conn.commit()
return True
# getRoom(2,"2018-11-15","2018-11-17",1)
# getRoom(2,"2018-11-15","2018-11-17",2)
# getRoom(2,"2018-11-15","2018-11-17",3)
# bookRoom("c1","n1",7894561230,"a@b.c",2,"2018-11-15","2018-11-17",1,501,2600)
# bookRoom("c2","n2",7894561230,"a@b.c",2,"2018-11-15","2018-11-17",2,301,1900)
# bookRoom("c3","n3",7894561230,"a@b.c",2,"2018-11-15","2018-11-17",3,101,1500)
# bookRoom("c4","n4",7894561230,"a@b.c",2,"2018-11-18","2018-11-24",1,505,4600)
# generateBill("c1","2018-11-15")
# checkStatus("c2","2018-11-15")
# checkStatus("c3","2018-11-15")
# checkStatus("c4","2018-11-18")
# generateBill("c1","2018-11-15")
# generateBill("c2","2018-11-15")
# generateBill("c3","2018-11-15")
# generateBill("c4","2018-11-18")