Skip to content

Commit

Permalink
Show History of orders
Browse files Browse the repository at this point in the history
  • Loading branch information
miladbarooni committed Jan 23, 2020
2 parents 7ad9519 + bc27945 commit c6df867
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions snapFood.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ def addAddress(self, x, y, user_id, city_id, street = "", alley = "", plaque = "
self._mydb.commit()
return address_id

def deletAddress(self, address_id):
self._mycursor.execute("DELETE FROM ADDRESS WHERE addressid = \'{}\';".format(address_id))
self._mydb.commit()

def searchShopByLocation(self, address_id, radius):
self._mycursor.execute("SELECT * FROM LOCATION WHERE ADDRESSaddressid = \'{}\';".format(address_id))
data = self._mycursor.fetchall()
Expand Down Expand Up @@ -163,8 +167,13 @@ def finalizeCart(self, user_id, address_id, discount_code = None): #NOT CHECKED
invoic_id = self._mycursor.lastrowid
total_price = 0
for food in foods:
<<<<<<< HEAD
self._mycursor.execute("INSERT INTO FOOD_INVOIC(FOODfoodid, INVOICinvoiceid) VALUES (\'{}\', \'{}\');"
=======
self._mycursor.execute("INSERT INTO FOOD_INVOIC (FOODfoodid, INVOICinvoiceid) VALUES (\'{}\', \'{}\');"
>>>>>>> bc279458a0ea8c7cacef0b0095a7b4fbacce9647
.format(food[0], invoic_id))
self._mycursor.execute("DELETE FROM CART WHERE USERuserid = \'{}\' AND FOODfoodid = \'{}\';".format(user_id,food[0]))
self._mycursor.execute("SELECT `minimum-bill-value`, price FROM SHOP JOIN FOOD ON shopid = SHOPshopid AND foodid = \'{}\'"
.format(food[0]))
data = self._mycursor.fetchall()
Expand All @@ -177,7 +186,7 @@ def finalizeCart(self, user_id, address_id, discount_code = None): #NOT CHECKED
self._mycursor.execute("SELECT balance FROM WALLET WHERE walletid = \'{}\'".format(wallet_id))
balance = int(self._mycursor.fetchall()[0][0])
self._mycursor.execute("UPDATE WALLET SET balance = \'{}\' WHERE walletid = \'{}\';".format(balance - total_price, wallet_id))
self._mycursor.execute("UPDATE INVOIC SET `total-price` = \'{}\' WHERE invoicid = \'{}\';".format(total_price, invoic_id))
self._mycursor.execute("UPDATE INVOIC SET `total-price` = \'{}\' WHERE invoiceid = \'{}\';".format(total_price, invoic_id))
self._mydb.commit()
return invoic_id

Expand All @@ -192,13 +201,13 @@ def showBuyHistory(self, user_id): #NOT CHECKED
JOIN STATUS ON STATUSstatusid = statusid)
JOIN ADDRESS ON ADDRESSaddressid = addressid)
JOIN WALLET ON WALLETwalletid = walletid)
JOIN USER ON WALLET.walletid = USER.WALLETwalletid WHERE USER.userid = \'{}\'""".format(user_id))
JOIN USER ON WALLET.walletid = USER.WALLETwalletid WHERE USER.userid = \'{}\' AND STATUS.name = \'Completed\'".format(user_id))
return self._mycursor.fetchall()
def addComment(self, invoic_id, rate, text = None): #NOT CHECKED
self._mycursor.execute("INSERT INTO COMMENT(rate, text) VALUES (\'{}\', \'{}\');".format(rate, text))
comment_id = self._mycursor.lastrowid
self._mycursor.execute("UPDATE INVOIC SET COMMENTcommentid = \'{}\' WHERE invoiceid = \'{}\';".format(comment_id,invoic_id))
self._mycursor.execute("UPDATE INVOIC SET COMMENTcommentid = \'{}\' WHERE invoiceid = \'{}\';""".format(comment_id,invoic_id))
self._mydb.commit()
return comment_id

Expand Down Expand Up @@ -325,9 +334,16 @@ def addDiscountCodeForUser(self, user_id, code, percent=50):
self._mydb.commit()
return discount_id

<<<<<<< HEAD
=======
def temp(self):
return
#self._mycursor.execute("ALTER TABLE `FOOD_INVOIC` ADD `food-invoicid` int(11)")
#self._mycursor.execute("ALTER TABLE `FOOD_INVOIC` DROP PRIMARY KEY, ADD PRIMARY KEY (`food-invoicid`);")
#self._mycursor.execute("ALTER TABLE `FOOD_INVOIC` MODIFY `food-invoicid` int(11) NOT NULL AUTO_INCREMENT;")
#self._mycursor.execute("ALTER TABLE FOOD_INVOIC ADD CONSTRAINT `is in` FOREIGN KEY (FOODfoodid) REFERENCES FOOD (foodid);")
#self._mycursor.execute("ALTER TABLE FOOD_INVOIC ADD CONSTRAINT `is in` FOREIGN KEY (INVOICinvoiceid) REFERENCES INVOIC (invoiceid);")

>>>>>>> bc279458a0ea8c7cacef0b0095a7b4fbacce9647
def close(self):
self._mydb.close()

db = SnapFoodDB()
print(db.addDiscountCodeForUser(4, "opening"))
db.close()

0 comments on commit c6df867

Please sign in to comment.