Exemplo n.º 1
0
def customer_care_order_detail(order_id):
    form = ReasonForm()
    order = Order.read_order(id=int(order_id))
    cart_items_sum = Cart.customer_order_items_total(order.id)
    courier_districts = Courier.read_courier_districts()
    order_return_form = OrderReturnsForm()
    order_return_form.order_ref.data = order.id

    order_products = []
    order_return_form.order_products.choices = order_products
    timezone = pytz.timezone("Africa/Kampala")
    _date = timezone.localize(order.pre_order_time)
    order_date = _date.astimezone(timezone).strftime("%a %b %d %H:%M:%S %Z %Y")
    for item in order.cart:
        order_products.append(
            (item.product_id,
             f"{item.product_name},{item.quantity} @{item.unit_price}"))

    if request.method == "POST":
        Order.customer_care_register_order_sales(data=request.json,
                                                 order=order)
        return jsonify()

    return render_template('orders/order/order_detail.html',
                           order_date=order_date,
                           order=order,
                           cart_items_sum=cart_items_sum,
                           districts=courier_districts,
                           form=form,
                           order_return_form=order_return_form)
Exemplo n.º 2
0
def dashboard():
    product_sales_today = Sales.read_sales_sum(
        Sales.amount,
        Sales.sales_day == DateUtil().current_date.day,
        Sales.sales_month == DateUtil().current_date.month,
        Sales.sales_year == DateUtil().current_date.year,
    )

    commission_sales_today = Sales.read_sales_sum(
        Sales.commision_amount,
        Sales.sales_day == DateUtil().current_date.day,
        Sales.sales_month == DateUtil().current_date.month,
        Sales.sales_year == DateUtil().current_date.year,
    )
    customer_count = Customer.read_customer_count()
    vendors_count = Resturant.read_restaurants_count()
    products_count = Products.read_products_count()
    orders_count = Order.read_orders_count()
    total_revenue = Sales.read_sales_sum(Sales.amount)

    context = dict(product_sales_today=product_sales_today,
                   commission_sales_today=commission_sales_today,
                   total_revenue=total_revenue,
                   shipping_sales_today=0,
                   standard_shipping_sales_td=0,
                   pickup_station_sales_td=0,
                   vendors_count=vendors_count,
                   customer_count=customer_count,
                   products_count=products_count,
                   orders_count=orders_count)

    return render_template('dashboard.html', **context)
Exemplo n.º 3
0
def account_settings():
    account_settings_form = AccountSettingsForm()
    password_change_form = ChangePasswordForm()
    user = StaffAccounts.read_user(id=current_user.id)
    current_tab = request.args.get("tab", "personal")
    if request.method == "GET":
        account_settings_form = AccountSettingsForm(obj=current_user)

    if account_settings_form.validate_on_submit():
        user.update_employee_details(
            email=account_settings_form.email.data.strip(),
            name=account_settings_form.name.data.strip(),
            contact=account_settings_form.contact.data.strip(),
            address=account_settings_form.address.data.strip())
        flash("Updated your details successfully", "success")
        return redirect(url_for(".account_settings"))

    elif password_change_form.validate_on_submit():
        if user.verify_password(password_change_form.current_password.data):
            user.hash_password(password_change_form.new_password.data)
            session.commit()
            flash(
                "Password changed successfully, please try to log in with new password",
                "success")
            return redirect(
                url_for(".account_settings", current_tab="password"))
        else:
            flash("Current password is incorrect", "danger")
            return redirect(
                url_for(".account_settings", current_tab="password"))

    context = dict(account_settings_form=account_settings_form,
                   password_change_form=password_change_form,
                   current_tab=current_tab)
    return render_template("customer_care_account_settings.html", **context)
Exemplo n.º 4
0
def custcare_shops(shop_state):
    if shop_state == "all":
        restuarants = Resturant.read_all_rests()

    return render_template('restaurants/customer_care_restaurants.html',
                           restuarants=restuarants,
                           shop_state=shop_state)
Exemplo n.º 5
0
def all_orders():
    state = request.args.get("state", "need_preparing_orders")

    if state == "need_preparing_orders":
        page = "Need Preparing Orders"
        orders = Order.read_all_orders_filter(
            and_(Order.is_prepared == False, Order.is_terminated == False))
    elif state == "pre_orders":
        page = "Pre Orders"
        orders = Order.read_all_orders_filter(
            and_(Order.is_prepared == False, Order.is_terminated == False,
                 Order.pre_order == True))
    elif state == "prepared_orders":
        page = "Prepared Orders"
        orders = Order.read_all_orders_filter(Order.is_prepared == True)

    elif state == "received_orders":
        page = "Recieved Orders"
        orders = Order.read_all_orders_filter(Order.customer_received == True)

    elif state == "need_transporting":
        page = "Need Transporting"
        orders = Order.read_all_orders_filter(Order.customer_received == False,
                                              Order.is_prepared == True,
                                              Order.is_terminated == False)

    return render_template('orders/all_orders_base_1.html',
                           orders=orders,
                           page=page,
                           state=state)
Exemplo n.º 6
0
def courier_details(courier_id):
    courier = Courier.read_courier(id=courier_id)
    orders = Order.read_all_orders_delivery_details_filter(
        DeliveryDetails.courier_id == courier_id)
    return render_template('courier_detail.html',
                           courier=courier,
                           orders=orders,
                           order_count=len(orders))
Exemplo n.º 7
0
def send_email(title, recipients, template, context):
    try:
        with app.app_context():
            message = Message(
                subject=title,
                recipients=recipients,
                html=render_template(template, **context)
            )
            mail.send(message)
    
    except Exception as e:
        logger.warning(f"Sending email error: {e}")
Exemplo n.º 8
0
def customer_care_orders():
    page = int(request.args.get("page", 1))
    orders = Order.read_all_orders()
    pagination = Paginate(orders, page, 8)
    next_url = url_for(
        ".customer_care_orders",
        page=pagination.next_page) if pagination.has_next else None
    prev_url = url_for(
        ".customer_care_orders",
        page=pagination.previous_page) if pagination.has_previous else None
    return render_template('orders/orders.html',
                           orders=orders,
                           next_url=next_url,
                           prev_url=prev_url,
                           pagination=pagination,
                           current_page=page)
Exemplo n.º 9
0
def add_product():
    form = AddProductForm()
    brands = Brand.read_all_bandss_filter_by("brand_id", "name")
    if request.method == "GET":
        form.restaurant.choices = Resturant.read_all_restaurants_filter_by(
            "id", "business_name")
        form.brand.choices = brands
        form.sub_cat.choices = SubCategory.read_all_subcategories_filter_by(
            "sub_category_id", "name")
        form.price.data = 0
        form.buying_price.data = 0
        form.selling_price.data = 0
        form.served_with.data = "none"
        form.commission_fee.data = 0.0
        form.headsup.data = "clickEat"

    if form.validate_on_submit():
        try:
            product_picture = save_picture(form.product_picture.data, None,
                                           "static/product_images", 500, 500)
            price = form.price.data
            rest_id = form.restaurant.data
            brand_name = [
                brand for brand in brands if brand[0] == form.brand.data
            ][0][1]
            if (Products()(name=form.name.data,
                           product_picture=product_picture,
                           description=form.description.data,
                           price=form.price.data,
                           resturant_id=form.restaurant.data,
                           brand=brand_name,
                           sub_category_id=form.sub_cat.data,
                           buying_price=form.buying_price.data,
                           selling_price=form.selling_price.data,
                           served_with=form.served_with.data,
                           commission_fee=form.commission_fee.data,
                           headsup=form.headsup.data)):
                flash("Product added successfully", "success")
                return redirect(url_for("customer_care.add_product"))

        except Exception as e:
            print("Error while trying to save product: ", e)
            session.rollback()
            flash("Error while trying to save product", "danger")

    return render_template('restaurants/restaurant/product/add_product.html',
                           form=form)
Exemplo n.º 10
0
def customer_care_login():
    form = LoginForm()

    if form.validate_on_submit():
        user = StaffAccounts.read_user(username=form.username.data)

        if not user:
            user = StaffAccounts.read_user(email=form.username.data)

        if user and user.verify_password(form.password.data):
            login_user(user)
            _session["account_type"] = "Employee"
            return redirect(url_for(".dashboard"))
        else:
            flash("User name or Password is incorrect", "danger")
            return redirect(url_for(".customer_care_login"))

    return render_template("customer_care_login.html", form=form)
Exemplo n.º 11
0
def shop_detail(shop_id, state):
    restuarant = Resturant.read_restaurant(id=shop_id)
    if state == "all_products":
        products = restuarant.read_all_rest_products

    elif state == "approved":
        products = restuarant.read_all_approved_products

    elif state == "not_approved":
        products = restuarant.read_all_non_approved_products

    elif state == "suspended":
        products = restuarant.read_all_suspended_products

    return render_template('restaurants/restaurant/restuarant_details.html',
                           restuarant=restuarant,
                           shop_id=shop_id,
                           products=products,
                           state=state)
Exemplo n.º 12
0
def rest_product_detail(product_id):
    product = Products.read_product(product_id)
    top_selling_status = TopSellingProducts.read_top_most_selling_product(
        product_id)
    comments = Comments.product_comments(product_id)
    product_rating = Rate.read_product_rate(product_id)
    restuarant = Resturant.read_restaurant(id=product.resturant_id)
    form = ProductsVerificationForm()
    promotional_price_form = SetPromotionForm()
    suspend_form = SuspendProductForm()
    suspend_form.product_id.data = product_id

    if request.method == "GET":
        form = ProductsVerificationForm(obj=product)
        form.sub_category.choices = SubCategory.read_all_subcategories_filter_by(
            "sub_category_id",
            "name",
            category_id=product.sub_category.category_id)

    # form.category.choices = Category.read_all_categories_by_attr("category_id","name")

    if form.validate_on_submit():
        if form.product_picture.data:
            try:
                product_pic = save_picture(form.product_picture.data,
                                           product.product_picture,
                                           "static/product_images", 500, 500)
                # product.sub_category_id = form.sub_category.data
                product.name = form.name.data
                product.product_picture = product_pic
                product.price = form.price.data
                product.description = form.description.data
                product.product = form.price.data
                product.buying_price = form.buying_price.data
                product.selling_price = form.selling_price.data
                product.served_with = form.served_with.data
                product.commission_fee = form.commission_fee.data
                product.headsup = form.headsup.data
                product.free_delivery = form.free_delivery.data
                session.commit()
                flash("Product updated successfully", "success")
                return redirect(
                    url_for("customer_care.rest_product_detail",
                            product_id=product_id))
            except Exception as e:
                print("Customer care updating product error:", e)
                session.rollback()
                flash("Internal server error failed to update product.",
                      "danger")
        else:
            try:
                # product.sub_category_id = form.sub_category.data
                product.name = form.name.data
                product.price = form.price.data
                product.description = form.description.data
                product.product = form.price.data
                product.buying_price = form.buying_price.data
                product.selling_price = form.selling_price.data
                product.served_with = form.served_with.data
                product.commission_fee = form.commission_fee.data
                product.headsup = form.headsup.data
                product.free_delivery = form.free_delivery.data
                session.commit()
                flash("Product updated successfully", "success")
            except Exception as e:
                print("Customer care updating product error:", e)
                session.rollback()
                flash("Internal server error failed to update product.",
                      "danger")
        return redirect(
            url_for("customer_care.rest_product_detail",
                    product_id=product_id))

    return render_template(
        'restaurants/restaurant/product/product_details.html',
        shop=restuarant,
        product=product,
        product_rating=product_rating,
        comments=comments,
        form=form,
        promo_form=promotional_price_form,
        suspend_form=suspend_form,
        top_selling_status=top_selling_status)
Exemplo n.º 13
0
def couriers():
    couriers = Courier.read_couriers()
    return render_template('courier.html', couriers=couriers)
Exemplo n.º 14
0
def cancelled_orders():
    orders_terminated = Order.read_all_orders_filter(
        Order.is_terminated == True)
    return render_template('orders/cancelled_orders.html',
                           orders_terminated=orders_terminated)