예제 #1
0
def insertSellsFood(sellsFood):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    if sellsFoodRepo.duplicate_entry(sellsFood.getFoodname(),
                                     sellsFood.getBarname()):
        raise Error("Duplicate Entry")
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    return sellsFoodRepo.insertSellsFood(sellsFood)
예제 #2
0
def updateSellsFood(sellsFood, oldFood, oldBar):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    if sellsFoodRepo.duplicate_entry(
            sellsFood.getFoodname(), sellsFood.getBarname()) and (
                not oldFood == sellsFood.getFoodname()
                or not oldBar == sellsFood.getBarname()):
        raise Error("Duplicate Entry")
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    return sellsFoodRepo.updateSellsFood(sellsFood, oldFood, oldBar)
예제 #3
0
def insertTransactions(transactions):
    if int(transactions.getQuantity()) <= 0:
        raise Error("Invalid Quantity")

    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBillArray(transactions.getBillId())
    if len(bill) == 0:
        raise Error(
            "No bill has been created for this transaction. Please insert a bill and try again."
        )
    bill = bill[0]

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    if transactionsRepo.duplicate_entry(transactions.getBillId(),
                                        transactions.getItem()):
        raise Error(
            "item is already a transactions for the current bill please use update to change amount of the item"
        )

    if transactions.getType() == "food":
        barFoodRepo = BarFoodRepo.BarFoodRepo()
        if not barFoodRepo.barFood_exists(transactions.getItem()):
            raise Error("Food does not exist")

        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        if not sellsFoodRepo.bar_sells_food(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the food")

        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        price = sellsFoodRepo.get_price(bill.getBar(), transactions.getItem())

    if transactions.getType() == "beer":

        beerRepo = BeerRepo.BeerRepo()
        if not beerRepo.beer_exists(transactions.getItem()):
            raise Error("Beer does not exist")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        if not sellsBeerRepo.bar_sells_beer(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the beer")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        price = sellsBeerRepo.get_price(bill.getBar(), transactions.getItem())

        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventoryForToday(bill.getBar(),
                                                     transactions.getItem(),
                                                     bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #see if can update inventory
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #see if violates pattern
        results[0].setEndQuantity(
            int(results[0].getEndQuantity()) - int(transactions.getQuantity()))
        if int(results[0].getEndQuantity()) < 0:
            raise Error("Violates Pattern 4: not enough inventory")
        for r in range(1, len(results)):
            results[r].setStartQuantity(int(results[r - 1].getEndQuantity()))
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) -
                int(transactions.getQuantity()))
            if int(results[r].getEndQuantity()) < 0:
                raise Error("Violates Pattern 4: not enough inventory")

        #doesn't violate pattern 4
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())

        #update inventory
        results[0].setEndQuantity(
            int(results[0].getEndQuantity()) - int(transactions.getQuantity()))
        inventoryService.updateInventory(results[0], results[0].getDate(),
                                         results[0].getBar(),
                                         results[0].getBeer())
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) -
                int(transactions.getQuantity()))
            inventoryService.updateInventory(results[r], results[r].getDate(),
                                             results[r].getBar(),
                                             results[r].getBeer())

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    transactionsRepo.insertTransactions(transactions)

    #update bills
    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBill(transactions.getBillId())
    items_price = float(transactions.getPrice())
    bill.setItemsPrice(items_price + float(bill.getItemsPrice()))
    bill.setTaxPrice(round(float(bill.getItemsPrice()) * 0.07, 2))
    bill.setTotalPrice(
        float(bill.getItemsPrice()) + float(bill.getTaxPrice()) +
        float(bill.getTip()))
    billsService.updateBills(bill, bill.getBillId())

    return "success"
예제 #4
0
def updateTransactions(transactions, oldBillId, oldItem):
    if int(transactions.getQuantity()) <= 0:
        raise Error("Invalid Quantity")

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    if transactionsRepo.duplicate_entry(
            transactions.getBillId(), transactions.getItem()) and (
                not transactions.getBillId() == oldBillId
                or not transactions.getItem() == oldItem):
        raise Error("Duplicate Entry")

    billsRepo = BillsRepo.BillsRepo()
    bill = billsRepo.getBillArray(transactions.getBillId())
    if len(bill) == 0:
        raise Error(
            "No bill has been created for this transaction. Please insert a bill and try again."
        )
    bill = bill[0]

    transactionsRepo = TransactionsRepo.TransactionsRepo()
    trans = transactionsRepo.get_transaction(oldBillId, oldItem)
    if len(trans) == 0:
        raise Error("no transcation found")
    trans = trans[0]

    if transactions.getType() == "food":
        barFoodRepo = BarFoodRepo.BarFoodRepo()
        if not barFoodRepo.barFood_exists(transactions.getItem()):
            raise Error("Food does not exist")
        sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
        if not sellsFoodRepo.bar_sells_food(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the food")

    if transactions.getType() == "beer":
        beerRepo = BeerRepo.BeerRepo()
        if not beerRepo.beer_exists(transactions.getItem()):
            raise Error("Beer does not exist")

        sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        if not sellsBeerRepo.bar_sells_beer(bill.getBar(),
                                            transactions.getItem()):
            raise Error("Bar doesn't sell the beer")

        # sellsBeerRepo = SellsBeerRepo.SellsBeerRepo()
        # price = sellsBeerRepo.get_price(transactions.getBar(), transactions.getItem())
        # if not price*int(transactions.getQuantity()) == transactions.getPrice():
        # 	raise Error("Incorrect price")

        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())
        if len(results) == 0:
            raise Error("no inventory found for the bar")

        #number of the beer trying to sell
        # transactionsRepo = TransactionsRepo.TransactionsRepo()
        # quantity = transactionsRepo.get_quantity(transactions.getBillId(), transactions.getItem())

        quantity = int(transactions.getQuantity()) - int(trans.getQuantity())

        #see if violates pattern
        results[0].setEndQuantity(int(results[0].getEndQuantity()) - quantity)
        if int(results[0].getEndQuantity()) < 0:
            raise Error("Violates Pattern 4: not enough inventory")
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) - quantity)
            if int(results[r].getEndQuantity()) < 0:
                raise Error("Violates Pattern 4: not enough inventory")

        #doesn't violate pattern 4
        inventoryRepo = InventoryRepo.InventoryRepo()
        #gets all inventory from date and after for a bar and beer
        results = inventoryRepo.getInventory(bill.getBar(),
                                             transactions.getItem(),
                                             bill.getDate())

        #number of the beer trying to sell
        # transactionsRepo = TransactionsRepo.TransactionsRepo()
        # quantity = transactionsRepo.get_quantity(transactions.getBillId(), transactions.getItem())

        #update inventory
        results[0].setEndQuantity(int(results[0].getEndQuantity()) - quantity)
        inventoryService.updateInventory(results[0], results[0].getDate(),
                                         results[0].getBar(),
                                         results[0].getBeer())
        for r in range(1, len(results)):
            results[r].setStartQuantity(results[r - 1].getEndQuantity())
            results[r].setEndQuantity(
                int(results[r].getEndQuantity()) - quantity)
            inventoryService.updateInventory(results[r], results[r].getDate(),
                                             results[r].getBar(),
                                             results[r].getBeer())

    #update transaction
    transactionsRepo = TransactionsRepo.TransactionsRepo()
    transactionsRepo.updateTransactions(transactions, oldBillId, oldItem)

    #remove all item price from bill
    bill.setItemsPrice(float(bill.getItemsPrice()) - float(trans.getPrice()))

    #update bills
    items_price = float(bill.getItemsPrice())
    bill.setItemsPrice(items_price + float(transactions.getPrice()))
    bill.setTaxPrice(round(float(bill.getItemsPrice()) * 0.07, 2))
    bill.setTotalPrice(
        float(bill.getItemsPrice()) + float(bill.getTaxPrice()) +
        float(bill.getTip()))
    billsService.updateBills(bill, bill.getBillId())

    return "success"
예제 #5
0
def deleteSellsFood(sellsFood):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    return sellsFoodRepo.deleteSellsFood(sellsFood)
예제 #6
0
def getAllSellsFood():
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    results = sellsFoodRepo.getAllSellsFood()
    return jsonify([e.toJson() for e in results])
예제 #7
0
def getAllFoodAndPrices(bar):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    results = sellsFoodRepo.getAllFoodAndPrices(bar)
    return jsonify([e.toJson() for e in results])
예제 #8
0
def get_bars_for_foods(food):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    results = sellsFoodRepo.get_bars_for_foods(food)
    return jsonify([e.toJson() for e in results])
예제 #9
0
def get_price(bar, food):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    results = sellsFoodRepo.get_price(bar, food)
    return jsonify(str(results))
예제 #10
0
def get_price_for_quantity(bar, food, quantity):
    sellsFoodRepo = SellsFoodRepo.SellsFoodRepo()
    results = sellsFoodRepo.get_price_for_quantity(bar, food, quantity)
    return jsonify(str(results))