Example #1
0
def get_product_by_id(ProductId):
    try:
        row = Product.query.get(ProductId)
        result = object_as_dict(row)
        return get_success(result)
    except:
        return get_fail()
    return get_fail()
Example #2
0
def get_Bill_by_id(BillId):
    try:
        row = Bill.query.get(BillId)
        result = object_as_dict(row)
        return get_success(result)
    except:
        return get_fail()
    return get_fail()
Example #3
0
def search_by_name():
    try:
        page_size = request.args.get('page_size', 25, type=int)
        page_number = request.args.get('page_number', 1, type=int)
        ProductName = request.args.get('ProductName', type=str)
        row = Product.query.filter(Product.ProductName.contains(ProductName.strip())).\
            paginate(page=page_number, per_page=page_size).items
        result = [object_as_dict(x) for x in row]
        return get_success(result)
    except:
        return get_fail()
    return get_fail()
Example #4
0
def get_all_bill():
    page_size = request.args.get('page_size', 25, type=int)
    page_number = request.args.get('page_number', 1, type=int)

    try:
        max_length = len(Bill.query.order_by(Bill.BillId).all())
        if max_length - page_size * (page_number-1) < 1:
            result = []
        else:
            result = [object_as_dict(x) for x in Bill.query.order_by(Bill.BillId).
                paginate(page=page_number, per_page=page_size).items]
        return get_success(result)
    except:
        return get_fail()
    return get_fail()
Example #5
0
def statistic_by_month():
    try:
        page_size = request.args.get('page_size', 25, type=int)
        page_number = request.args.get('page_number', 1, type=int)

        month = int(request.args.get('month'))
        year = int(request.args.get("year"))
        amount_day_of_month = monthrange(year, month)[1]
        start_day = datetime.datetime.strptime(
            str(year) + "-" + str(month) + "-" + "1 " + "00:00:01",
            '%Y-%m-%d %H:%M:%S')

        revenues = []
        for i in range(amount_day_of_month):
            revenues.append(0)

        row_bill_detail = BillDetail.query.all()
        result_bill_detail = [object_as_dict(x) for x in row_bill_detail]
        row_bills = Bill.query.all()
        result_bills = [object_as_dict(x) for x in row_bills]
        for x in result_bill_detail:
            for y in result_bills:
                if x["BillId"] == y['BillId'] and 0 <= (
                        y['Datetime'].date() -
                        start_day.date()).days < amount_day_of_month:
                    if y["Type"] == 0:
                        revenues[y['Datetime'].day -
                                 1] -= x["Amount"] * x["Price"]
                    elif y["Type"] == 1:
                        revenues[y['Datetime'].day -
                                 1] += x["Amount"] * x["Price"]
        result = []
        for i in range(amount_day_of_month):
            result.append([str(i + 1), revenues[i]])
        return get_success(result)
    except:
        return get_fail()
    return get_fail()
Example #6
0
def get_all_product():
    day_in_week_str = [
        'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday',
        'Sunday'
    ]
    page_size = request.args.get('page_size', 25, type=int)
    page_number = request.args.get('page_number', 1, type=int)
    # try:
    max_length = len(Product.query.order_by(Product.ProductId).all())
    if max_length - page_size * (page_number - 1) < 1:
        result = []
    else:
        result = [
            object_as_dict(x)
            for x in Product.query.order_by(Product.ProductId).paginate(
                page=page_number, per_page=page_size).items
        ]
        for item in result:
            statistic = product_amount_sell_day(item)
            item['AmountBuyDay'] = statistic['amount_buy_day']
            item['AmountSellDay'] = statistic['amount_sell_day']
            item['AmountBuyWeek'] = statistic['amount_buy_week']
            item['AmountSellWeek'] = statistic['amount_sell_week']
            #   item['ProductInfor'] = [
            #   {
            #     'WeekDay': "Thứ 2",
            #     'Weather': "Nắng",
            #     'Temperature': "29",
            #     'NumberPurchased': 30,
            #     'NumberSold': 25
            #   },
            #   {
            #     'WeekDay': "Thứ 3",
            #     'Weather': "Mưa",
            #     'Temperature': "28",
            #     'NumberPurchased': 40,
            #     'NumberSold': 30
            #   },
            #   {
            #     'WeekDay': "Thứ 4",
            #     'Weather': "Nắng",
            #     'Temperature': "30",
            #     'NumberPurchased': 27,
            #     'NumberSold': 25
            #   },
            #   {
            #     'WeekDay': "Thứ 5",
            #     'Weather': "Mây",
            #     'Temperature': "27",
            #     'NumberPurchased': 46,
            #     'NumberSold': 37
            #   },
            #   {
            #     'WeekDay': "Thứ 6",
            #     'Weather': "Bão",
            #     'Temperature': "25",
            #     'NumberPurchased': 45,
            #     'NumberSold': 39
            #   },
            #   {
            #     'WeekDay': "Thứ 7",
            #     'Weather': "Mưa",
            #     'Temperature': "26",
            #     'NumberPurchased': 24,
            #     'NumberSold': 24
            #   },
            #   {
            #     'WeekDay': "Chủ nhật",
            #     'Weather': "Mưa",
            #     'Temperature': "29",
            #     'NumberPurchased': 35,
            #     'NumberSold': 29
            #   }
            # ]
            item['ProductInfor'] = product_statistic_one_week(item)
            for tmp in item['ProductInfor']:
                tmp['WeekDay'] = day_in_week_str[tmp['WeekDay']]
        return get_success(result)
    # except:
    #     return get_fail()
    return get_fail()