Ejemplo n.º 1
0
    def unregisterSelf(self):
        confirm = UserInterface.displayConfirm(
            "Please confirm",
            "This action will remove your account. Are you sure?")
        if confirm == 'y':
            if self.store.getCustomer(self.loginDetail).getBalance() > 0:
                c2 = UserInterface.displayConfirm(
                    "Balance remaining",
                    "You still have balance remaining. Are you sure you want to unregister?"
                )
                if c2 == 'y':
                    self.store.removeCustomer(self.loginDetail)
                    self.loginDetail = None
                    UserInterface.writeLine(
                        "Your account has been logged out and unregisted. Thanks for shopping with us!"
                    )
                    return
            else:
                self.store.removeCustomer(self.loginDetail)
                self.loginDetail = None
                UserInterface.writeLine(
                    "Your account has been logged out and unregisted. Thanks for shopping with us!"
                )
                return

        UserInterface.writeLine("Cancelled.")
Ejemplo n.º 2
0
 def viewProductByBatch(self, productId):
     product = self.store.getProduct(productId)
     batches = product.getBatches()
     tuples = [("BatchId", "Price, Quantity, Expiry Date")]
     batchIds = []
     for batch in batches:
         batchId = batch.getBatchID()
         batchIds.append(batchId)
         theRest = str(batch.getActualPrice()) + " " + str(
             batch.getQuantity()) + " " + str(batch.getExpiryDate())
         tuples.append((batchId, theRest))
     UserInterface.displayList("Batch details: ", tuples, "", False)
     confirm = UserInterface.displayConfirm("Edit batch ",
                                            "Do you wish to edit Batch?")
     if confirm.lower() == 'y' and len(batchIds) > 0:
         while True:
             batchId = UserInterface.displayForm(
                 "Batch Id",
                 [("Please input the batchID you would like to edit.",
                   "number")])[0]
             #print(batchIds)
             if batchId in batchIds:
                 self.editBatch(productId, batchId)
                 break
             else:
                 UserInterface.writeLine("Batch Id incorrect. Try again.")
     else:  # ML added else condition so user doesn't get stuck when no batch exists.
         UserInterface.writeLine("No batches to edit.")
Ejemplo n.º 3
0
 def removeCustomer(self):
     idlist = self.viewAllCustomerID()
     validInput = False
     while not validInput:
         customerId = input("Please input customer id, x to quit")
         if customerId in idlist:
             if self.store.getCustomer(customerId).getBalance() > 0:
                 hasconfirmed = False
                 while not hasconfirmed:
                     confirm = UserInterface.displayConfirm(
                         "The customer still has some balance, are you sure? ",
                         "y or n ")
                     if confirm.lower() == 'y':
                         self.store.removeCustomer(customerId)
                         UserInterface.writeLine("Customer removed.")
                         validInput = True
                         hasconfirmed = True
                     elif confirm.lower() == 'n':
                         UserInterface.writeLine("Cancelled.")
                         hasconfirmed = True
                         validInput = True
                     else:
                         UserInterface.writeLine("Invalid input.")
             else:
                 self.store.removeCustomer(customerId)
                 UserInterface.writeLine("Customer removed.")
                 validInput = True
         elif customerId.upper() == "X":
             validInput = True
         else:
             pass
Ejemplo n.º 4
0
 def modifyShoppingCart(self):
     while True:
         choice = UserInterface.displayConfirm("Continue? ", "")
         if choice.upper().strip() == 'Y':
             idPrice = UserInterface.displayForm(
                 "Please input the product ", [("id", "nstring"),
                                               ("price", "money")])
             sc = self.store.getCustomer(self.loginDetail).getShoppingCart()
             # print(idPrice[0])
             acStock = sc.getListByIdPrice(idPrice[0], float(idPrice[1]))
             print(type(idPrice[0]))
             if acStock is not None:
                 newQuan = UserInterface.displayForm(
                     "New quantity", [("", "money")])[0]
                 print(type(newQuan), float(newQuan))
                 if float(newQuan) == 0.0:
                     sc.deleteFromShoppingCart(idPrice[0],
                                               float(idPrice[1]))
                     UserInterface.writeLine(
                         "Item deleted from shopping Cart. :\'(")
                 else:
                     acStock[2] = float(newQuan)
                 break
             else:
                 UserInterface.writeLine(
                     "Try again. Id and price does not match.")
         else:
             break
Ejemplo n.º 5
0
    def checkOut(self):
        currentCustomer = self.store.getCustomer(self.loginDetail)
        shoppingCart = currentCustomer.getShoppingCart()
        totalPrice = shoppingCart.getTotalPrice()
        formattedSC = []
        formattedSC.append(('Index', 'product name, real price, quantity'))
        for line in shoppingCart.getProductsInCart():
            pname = self.store.getProduct(line[0]).getName()
            newLine = pname + "," + str(line[1]) + "," + str(line[2])
            formattedSC.append((line[0], newLine))
        UserInterface.displayList("Current Shopping Cart", formattedSC, '',
                                  False)

        insufficientP = []
        for eachProduct in shoppingCart.getProductsInCart():
            if not self.checkStock(eachProduct[2], eachProduct[0],
                                   eachProduct[1]):
                insufficientP.append(eachProduct)
        if len(
                insufficientP
        ) > 0:  # insufficient stock, return to shopping cart or whatever
            return insufficientP

        confirmMSG = UserInterface.displayConfirm(
            "You are about to check out. ", "Are you sure?")
        if confirmMSG == 'y' or confirmMSG == 'Y':
            if self.store.getCustomer(
                    self.loginDetail).getBalance() < totalPrice:
                UserInterface.writeLine(
                    'You do not have sufficient balance. Please go to manage account and top up.'
                )
                return None
            currentCustomer.subtractBalance(totalPrice)

            for eachProduct in shoppingCart.getProductsInCart():
                self.store.getProduct(eachProduct[0]).deductStock(
                    eachProduct[1], eachProduct[2])

            shoppingCartCopy = shoppingCart.getProductsInCart()[:]
            newOrder = self.store.addOrder(self.loginDetail, shoppingCartCopy,
                                           totalPrice)
            #translate order into list of tuples(name, everthing else)

            orderId = newOrder.getOrderId()  # str
            newShoppingCart = newOrder.getShoppingCart()
            listOfTuples = []
            for productInCart in newShoppingCart.getProductsInCart():
                name = productInCart[0]
                rest = str(productInCart[1]) + " " + str(productInCart[2])
                newTuple = (name, rest)
                listOfTuples.append(newTuple)
            UserInterface.writeLine(orderId)

            UserInterface.displayList("The new order details: ", listOfTuples,
                                      "", False)
            UserInterface.writeLine("The total price is: " +
                                    str(newShoppingCart.getTotalPrice()))
            currentCustomer.getShoppingCart().setProductsInCart([])
        else:
            pass
Ejemplo n.º 6
0
    def addToCart(self, productId, priceGroup):
        toAdd = UserInterface.displayConfirm(
            "", "Do you wish to add this Product into shopping cart?")
        if toAdd in ['y', 'Y']:
            # check input, add to cart

            acPrice, pQuantity = None, None
            UserInterface.writeLine(
                "input the price you want. enter 9999 to quit.")
            acPrice = UserInterface.displayForm("select price:",
                                                [('', 'money')])[0]
            acPrice = float(acPrice)
            while acPrice not in priceGroup and acPrice != 9999:
                acPrice = UserInterface.displayForm(
                    "price not found. select price:", [('', 'money')])[0]
                acPrice = float(acPrice)
            if acPrice != 9999:
                pQuantity = UserInterface.displayForm("input quantity:",
                                                      [('', 'number')])[0]
                pQuantity = float(pQuantity)
                while pQuantity > priceGroup[acPrice] and pQuantity != 9999:
                    UserInterface.writeLine(
                        "quantity larger than stock. input new or 9999 to quit"
                    )
                    pQuantity = UserInterface.displayForm(
                        "input new:", [('', 'number')])[0]
                    pQuantity = float(pQuantity)
            if acPrice != 9999 and pQuantity != 9999:
                UserInterface.writeLine("selected price: " + str(acPrice) +
                                        " Quantity: " + str(pQuantity))
                confirmed = UserInterface.displayConfirm(
                    "", "confirm to add to shopping cart.")
                if confirmed == 'y':
                    sc = self.store.getCustomer(
                        self.loginDetail).getShoppingCart()
                    sc.addToShoppingCart(productId, acPrice, pQuantity)
                else:
                    pass
Ejemplo n.º 7
0
 def editBatchPrice(self, productId, batchId):
     currentPrice = self.store.getProduct(productId).getBatch(
         batchId).getActualPrice()
     UserInterface.writeLine("The current quantity is " + str(currentPrice))
     results = UserInterface.displayForm("Please enter the new price",
                                         [('Price', 'money')])  #input
     newPrice = float(results[0])
     confirmMsg = UserInterface.displayConfirm(
         "Your new price is " + results[0], "Are you sure?")
     if confirmMsg == 'y' or confirmMsg == 'Y':
         self.store.getProduct(productId).getBatch(batchId).setActualPrice(
             newPrice)
         UserInterface.writeLine("The new price is: " + str(newPrice))
     else:
         UserInterface.writeLine("The action is abandoned.")
Ejemplo n.º 8
0
 def editBatchQuantity(self, productId, batchId):
     currentQuantity = self.store.getProduct(productId).getBatch(
         batchId).getQuantity()
     UserInterface.writeLine("The current quantity is " +
                             str(currentQuantity))
     results = UserInterface.displayForm("Please enter the new quantity",
                                         [('Quantity', 'number')])  #input
     newQuantity = float(results[0])
     confirmMsg = UserInterface.displayConfirm(
         "Your new quantity is " + results[0], "Are you sure?")
     if confirmMsg == 'y' or confirmMsg == 'Y':
         self.store.getProduct(productId).getBatch(batchId).setQuantity(
             newQuantity)
         UserInterface.writeLine("The new quantity is: " + str(newQuantity))
     else:
         UserInterface.writeLine("The action is abandoned.")
Ejemplo n.º 9
0
 def viewShoppingCart(self):
     shoppingCart = self.store.getCustomer(
         self.loginDetail).getShoppingCart().getProductsInCart()
     listToBeDisplayed = []
     for listhaha in shoppingCart:
         pName = self.store.getProduct(listhaha[0]).getName()
         theRest = [pName]
         theRest.extend(listhaha[1:])
         listToBeDisplayed.append((listhaha[0], theRest))
     UserInterface.displayList("Products in Shopping Cart",
                               listToBeDisplayed, "", False)
     if len(listToBeDisplayed) == 0:
         UserInterface.writeLine('no product yet')
     else:
         while True:
             co = UserInterface.displayList(
                 'Next action: ', [],
                 'A to check out. B to modify shopping cart Q to quit')
             if co.upper().strip() == 'A':
                 insufficientProduct = self.checkOut()
                 if insufficientProduct != None:
                     for plist in insufficientProduct:
                         proid = plist[0]
                         pro = self.store.getProduct(proid)
                         proName = pro.getName()
                         print("Available stock: ", proName,
                               [plist[1],
                                pro.calculateStock(plist[1])])
                         print("In shopping cart: ", proName, plist[1:])
                     co = UserInterface.displayConfirm(
                         'Do you wish to modify shopping cart?', '')
                     if co in ['y', 'Y']:
                         self.modifyShoppingCart()
                 break
             elif co.upper().strip() == 'B':
                 self.modifyShoppingCart()
                 break
             elif co.upper().strip() == 'Q':
                 break
             else:
                 UserInterface.writeLine(
                     "Incorrect menu option, try again.")
Ejemplo n.º 10
0
 def viewExpiringProducts(self):
     products = self.store.getProducts()
     paired = []
     expIds = []
     for p in products:
         for b in p.getExpiringBatches():
             paired.append(("Name: {}, Product ID: {}, Batch ID: {}".format(
                 p.getName(), p.getId(),
                 b.getBatchID()), "Expiring: {}".format(b.getExpiryDate())))
             if p.getId() not in expIds:
                 expIds.append(p.getId())
     if len(paired) > 0:
         UserInterface.displayList("Expiring product batches", paired, "",
                                   False)
         toDiscount = UserInterface.displayConfirm(
             "Do you wish to discount these products and delete expired batches? ",
             "")
         if toDiscount in ['y', 'Y']:
             for pid in expIds:
                 self.store.getProduct(pid).updateDiscount()
                 self.store.getProduct(pid).deleteExpiredProducts()
     else:
         UserInterface.writeLine(
             "Good news! There are no expiring products")