def get_status(): query = "SELECT produce_image, produce_name, order_date, delivery_status,\ order_quantity, order_price, delivery_address, order_id \ FROM orders INNER JOIN produce \ ON orders.produce_id = produce.produce_id \ WHERE orders.delivery_agency_id = (SELECT agency_id \ FROM delivery_agent WHERE delivery_agent_id = %s)\ ORDER BY order_date" params = (session['id'], ) try: connection = connect() cur = connection.cursor() cur.execute(query, params) delivery_details = cur.fetchall() except mysql.connector.Error as err: print(err) delivery_details = [] flash("Could not retrieve past delivery details") finally: cur.close() connection.close() addresses = [delivery[6] for delivery in delivery_details] addresses = set(addresses) items, subtotal, items_len = cart_items() return render_template('delivery.html', subtotal=subtotal, items=items, delivery_details=delivery_details, addresses=addresses)
def get_profile(): user_details = get_details() items, subtotal, items_len = cart_items() return (render_template('profile.html', user_details=user_details, items=items, subtotal=subtotal))
def set_status(order_id, delivery_status): items, subtotal, items_len = cart_items() if (not order_id): flash("Could not retrieve order") return redirect(url_for('delivery')) if delivery_status == 'Pending': query = "UPDATE orders SET delivery_status = 'Shipping',\ pickup_time = NOW() WHERE order_id = %s " elif delivery_status == 'Shipping': query = "UPDATE orders SET delivery_status = 'Delivered',\ drop_time = NOW() WHERE order_id = %s " try: connection = connect() cur = connection.cursor() params = (order_id, ) cur.execute(query, params) connection.commit() except mysql.connector.Error as err: print(err) flash("Could not update status. Try again later") finally: cur.close() connection.close() return redirect(url_for('delivery'))
def orhistory(bid): query = "SELECT order_id, order_quantity, order_date, order_price, delivery_status, payment_method, delivery_address, med_id, med_role, order_total, buyer_id\ FROM orders\ WHERE buyer_id= %s" connection = connect() cur = connection.cursor() try: params = (str(bid), ) cur.execute(query, params) items = cur.fetchall() print(items) ite, subtotal, len_items = cart_items() # image = ("static/images/d1.jpg","static/images/d7.jpg","static/images/d2.jpg","static/images/d21.jpg","static/images/d23.jpg","static/images/img16.jpg","static/images/img17.jpg","static/images/img21.jpg","static/images/img15.jpg") except mysql.connector.Error as err: print(err) return [] finally: cur.close() connection.close() return render_template("orderhistory.html", items=items, subtotal=subtotal, len_items=len_items, buid=bid)
def get_update_page(): user_details = get_details() items, subtotal, items_len = cart_items() return render_template('password.html', user_details=user_details, items=items, subtotal=subtotal)
def checkout_page(): categories = get_categories() items, subtotal, items_len = cart_items() query = "SELECT DISTINCT buyer_address FROM address WHERE buyer_id = %s" try: connection = connect() cur = connection.cursor() params = (session['id'], ) cur.execute(query, params) buyer_address = cur.fetchall() except mysql.connector.Error as err: print(err) finally: cur.close() connection.close() query = "SELECT user_address FROM user WHERE user_id = %s" try: connection = connect() cur = connection.cursor() params = (session['id'], ) cur.execute(query, params) user_address = cur.fetchone() except mysql.connector.Error as err: print(err) finally: cur.close() connection.close() return render_template('checkout.html', categories=categories, buyer_address=buyer_address, items=items, subtotal=subtotal, items_len=items_len, user_address=user_address)
def normal_checkout(): items, subtotal, items_len = cart_items() normalc = session['cdis'] specialc = session['pdis'] buid = buyid() return render_template("checkout.html", items=items, subtotal=subtotal, items_len=items_len, normalc=normalc, specialc=specialc, buid=buid)
def coupon(): items, subtotal, items_len = cart_items() buid = buyid() couponcode = request.form.get('coupo', None) if session['type'] == 'customer': if couponcode == 'SOMAIYA15': flash("Coupon applied successfully!!", category="success") coupon = subtotal * 0.15 session['cdis'] = coupon dis = 0.00 val = 1 return render_template("cart.html", items=items, val=val, subtotal=subtotal, items_len=items_len, coupon=coupon, dis=dis, buid=buid) else: flash("Coupon Invalid!!", category="danger") coupon = 0.00 dis = 0.00 val = 1 return render_template("cart.html", items=items, val=val, subtotal=subtotal, items_len=items_len, coupon=coupon, dis=dis, buid=buid) else: flash( "Coupon Discount is only for Normal Customers and not for Pharmacy Store Owners!!", category="danger") coupon = 0.00 dis = subtotal * 0.25 session['pdis'] = dis val = 200 return render_template("cart.html", items=items, val=val, subtotal=subtotal, items_len=items_len, coupon=coupon, dis=dis, buid=buid)
def cart(): items, subtotal, items_len = cart_items() buid = buyid() coupon = 0.00 if session['type'] == 'powner': dis = subtotal * 0.25 session['pdis'] = dis val = 200 else: dis = 0.00 val = 1 return render_template("cart.html", items=items, val=val, subtotal=subtotal, items_len=items_len, coupon=coupon, dis=dis, buid=buid)
def product_detail(pur): query = "SELECT med_name,med_brandname,med_purpose,med_price,med_role,dosage_form,med_id\ FROM medicine\ WHERE med_purpose = %s" try: connection = connect() cur = connection.cursor() params = (pur, ) cur.execute(query, params) items = cur.fetchall() ite, subtotal, items_len = cart_items() buid=buyid() # image = ("static/images/d1.jpg","static/images/d7.jpg","static/images/d2.jpg","static/images/d21.jpg","static/images/d23.jpg","static/images/img16.jpg","static/images/img17.jpg","static/images/img21.jpg","static/images/img15.jpg") except mysql.connector.Error as err: print(err) return [] finally: cur.close() connection.close() return render_template("product.html", items=items, subtotal=subtotal, items_len=items_len, buid=buid)
def single_product(pid, rol): query = "SELECT med_name,med_brandname,med_purpose,med_price,med_role,dosage_form,med_quantity,med_id,med_expiry\ FROM medicine\ WHERE med_id= %s and med_role = %s" connection = connect() cur = connection.cursor() try: params = ( str(pid), str(rol), ) cur.execute(query, params) items = cur.fetchone() ite, subtotal, items_len = cart_items() buid = buyid() query = "SELECT med_name,med_brandname,med_purpose,med_price,med_role,med_id\ FROM medicine\ WHERE med_purpose = %s and med_role = %s LIMIT 3" param = ( str(items[2]), str(items[4]), ) cur.execute(query, param) rel = cur.fetchall() # image = ("static/images/d1.jpg","static/images/d7.jpg","static/images/d2.jpg","static/images/d21.jpg","static/images/d23.jpg","static/images/img16.jpg","static/images/img17.jpg","static/images/img21.jpg","static/images/img15.jpg") except mysql.connector.Error as err: print(err) return [] finally: cur.close() connection.close() return render_template("single-product.html", items=items, subtotal=subtotal, items_len=items_len, rel=rel, buid=buid)
def query_search(): ite, subtotal, items_len = cart_items() se = request.form.get('searc', None) typ = request.form.get('type', None) buid=buyid() if typ: query = "SELECT med_name,med_brandname,med_purpose,med_price,med_role,dosage_form,med_id,med_quantity\ FROM medicine\ WHERE med_name LIKE %s and med_role=%s\ OR med_name LIKE %s and med_role=%s\ OR med_name LIKE %s and med_role=%s\ OR med_name LIKE %s and med_role=%s" params = (se+"%", typ, "%"+se, typ, "%"+se+"%", typ, se, typ, ) else: query = "SELECT med_name,med_brandname,med_purpose,med_price,med_role,dosage_form,med_id,med_quantity\ FROM medicine\ WHERE med_name LIKE %s \ OR med_name LIKE %s \ OR med_name LIKE %s \ OR med_name = %s " params = (se+"%", "%"+se, "%"+se+"%", se, ) connection = connect() cur = connection.cursor() try: cur.execute(query, params) items = cur.fetchall() print(query) if len(items)==0: flash("No results found related to your search!!", category="warning") return redirect(url_for('mhome')) # image = ("static/images/d1.jpg","static/images/d7.jpg","static/images/d2.jpg","static/images/d21.jpg","static/images/d23.jpg","static/images/img16.jpg","static/images/img17.jpg","static/images/img21.jpg","static/images/img15.jpg") except mysql.connector.Error as err: print(err) return render_template('search.html', items=ite, subtotal=subtotal, items_len=items_len, buid=buid) finally: connection.commit() cur.close() connection.close() return render_template('search.html', items=items, subtotal=subtotal, items_len=items_len, buid=buid)
def get_history(): query = "SELECT produce_image, produce_name, produce_quantity,\ produce_date, produce_price, produce_category\ FROM produce \ WHERE produce.farmer_id = %s ORDER BY produce_date" params = (session['id'],) try: connection = connect() cur = connection.cursor() cur.execute(query, params) produce_details = cur.fetchall() except mysql.connector.Error as err: print(err) produce_details = [] flash("Could not retrieve past Produce details") finally: cur.close() connection.close() items, subtotal, items_len = cart_items() categories = get_categories() return render_template('producehistory.html', subtotal=subtotal, items=items, produce_details=produce_details, categories=categories)
def checkout_details(): connection = connect() cur = connection.cursor() address = (str(request.form.get('address', None)) + ", " + str(request.form.get('city', None)) + ", " + str(request.form.get('postcode', None)) + ", " + str(request.form.get('zone_id', None))) try: query = "INSERT into address(buyer_id, buyer_address)\ VALUES (%s, %s)" buid = buyid() params = ( session['user'], address, ) cur.execute(query, params) items, subtotal, item_len = cart_items() sum = 0.00 for item in items: sum = sum + round(item[1] * item[9] * 1.2, 2) sum = sum + 60 - session['cdis'] - session['pdis'] orders = [] for item in items: orders.append(( item[9], round(item[1] * item[9] * 1.2, 2), 'Pending', request.form.get('payment_method', None), address, item[4], item[7], sum, )) values = [] for order in orders: params = (session['user'], order[0], order[1], order[2], order[3], order[4], order[5], order[6], order[7]) values.append(params) query = "INSERT into orders(buyer_id, order_quantity,\ order_date, order_price,\ delivery_status, payment_method, delivery_address,\ med_id, med_role, order_total)\ VALUES (%s, %s, NOW() , %s, %s, %s, %s, %s, %s, %s)" cur.executemany(query, values) values = [] for item in items: params = ( item[9], item[4], item[7], ) values.append(params) query = "UPDATE medicine SET med_quantity = med_quantity - %s\ WHERE med_id = %s and med_role=%s" cur.executemany(query, values) values = [] for item in items: params = (item[0], ) values.append(params) query = "DELETE FROM cart_items WHERE buyer_user = %s " params = (str(buid), ) cur.execute(query, params) connection.commit() except mysql.connector.Error as err: print(err) flash("Could not place your order. Try again later.", category="warning") connection.rollback() return redirect(url_for('checkout')) finally: cur.close() connection.close() session['cdis'] = 0.00 flash("Order has been placed successfully!!", category="success") return redirect(url_for('mhome'))
def category_page(category): quantity_list = request.args.getlist('quantity') price_list = request.args.getlist('price') if(len(price_list)): s = "0" else: s = "1" for price in price_list: if(price == '100'): s += " OR produce_price < 100" if(price == '500'): s += " OR produce_price > 100 AND produce_price <= 500" if(price == '1000'): s += " OR produce_price > 500 AND produce_price <= 1000" if(price == '10000'): s += " OR produce_price > 1000" if(len(quantity_list)): q = "0" else: q = "1" for quantity in quantity_list: if(quantity == '100'): q += " OR produce_quantity < 100" if(quantity == '200'): q += " OR produce_quantity > 100 AND produce_quantity <= 200" if(quantity == '500'): q += " OR produce_quantity > 200 AND produce_quantity <= 500" if(quantity == '10000'): q += " OR produce_quantity > 500" sort = request.args.get("sort", "produce_name ASC") page = request.args.get('page', 1) categories = get_categories() latest = get_latest_items() if(session.get('email', False)): items, subtotal, items_len = cart_items() else: items, subtotal, items_len = [], 0, 0 query = "SELECT produce_image, produce_name, produce_price, produce_id,\ produce_quantity FROM produce WHERE \ produce_category = %s AND produce_quantity != 0\ AND (" + s + ") AND (" + q + ")" + " ORDER BY \ " + sort try: connection = connect() cur = connection.cursor() params = (category,) cur.execute(query, params) category = cur.fetchall() except mysql.connector.Error as err: print(err) finally: cur.close() connection.close() return render_template('category.html', items=items, subtotal=subtotal, categories=categories, latestitems=latest, category=category, total=len(category), page=page)
def checkout_func(): try: connection = connect() cur = connection.cursor() if (request.form.get('payment_address') == 'existing_address'): address = request.form.get('address') elif (request.form.get('payment_address') == 'new_address'): address = (request.form.get('address_new', None) + ", " + request.form.get('city', None) + ", " + request.form.get('postcode', None) + ", " + request.form.get('state', None)) query = "INSERT into address (buyer_id, address_id, buyer_address)\ VALUES (%s, UUID(), %s)" params = ( session['id'], address, ) cur.execute(query, params) items, subtotal, item_len = cart_items() orders = [] for item in items: orders.append(( item[2], round(item[1] * item[2] * 1.2, 2), item[8], 'Pending', request.form.get('payment_method', None), address, item[5], )) values = [] for order in orders: params = ( session['id'], order[0], order[1], order[2], order[3], order[4], order[5], order[6], ) values.append(params) query = "INSERT into orders(buyer_id, order_id, order_quantity,\ order_date, order_price, delivery_agency_id,\ delivery_status, payment_method, delivery_address,\ produce_id)\ VALUES (%s, UUID(), %s, NOW() , %s, %s, %s, %s, %s, %s)" cur.executemany(query, values) values = [] for item in items: params = ( item[2], item[5], ) values.append(params) query = "UPDATE produce SET produce_quantity = produce_quantity - %s\ WHERE produce_id = %s" cur.executemany(query, values) values = [] for item in items: params = (item[0], ) values.append(params) query = "DELETE FROM cart_items WHERE item_id = %s" cur.executemany(query, values) connection.commit() flash("Order added successfully") except mysql.connector.Error as err: print(err) flash("Could not place your order. Try again later.") connection.rollback() return redirect(url_for('checkout')) finally: cur.close() connection.close() return redirect(url_for('index'))