def wdashboard(): if request.method == "POST": user_id = request.form['userid'] em_or_num = str( pybase64.b64encode( (request.form['em_or_num'].lower()).encode("utf-8")), "utf-8") manager_name = request.form['manager_name'] mname = str( pybase64.b64encode( (request.form['manager_name'].lower()).encode("utf-8")), "utf-8") passwd = str( pybase64.b64encode((request.form['password']).encode("utf-8")), "utf-8") cur = getdbcur() sql = "select managerName from warehouse where (id = %s AND (email = %s OR phoneNumber = %s ) AND managerName=%s AND password= %s ) " cur.execute(sql, (user_id, em_or_num, em_or_num, mname, passwd)) sqlres = cur.rowcount mname = cur.fetchone() if sqlres == 1: session['user_id'] = user_id session['user_name'] = manager_name wareid = session['user_id'] sql = 'select * from warehousenotification where warehouseId = "' + wareid + '" ' cur = getdbcur() cur.execute(sql) n = cur.rowcount if n > 0: session['notifcount'] = n return render_template('warehouse_dashboard.html') else: flash("Incorrect credentials!") return redirect(url_for('warehouse_login')) return redirect(url_for('warehouse_login'))
def addmember(): cur =getdbcur() app = current_app._get_current_object() if request.method == 'POST': if 'user_id' in session: name = request.form['name'] position = request.form['position'] msg = request.form['msg'].replace('\r\n','<br>') img = request.files['memberimg'] path=os.path.basename(img.filename) file_ext=os.path.splitext(path)[1][1:] imgfilename=str(uuid.uuid4())+'.'+file_ext memberimg = secure_filename(imgfilename) addquery ='insert into team values (%s,%s,%s,%s) ' cur.execute(addquery,(name,position,msg,memberimg)) n = cur.rowcount if n == 1: img.save(os.path.join(app.config['UPLOAD_FOLDER'],memberimg)) flash('Member Added Successully !') return redirect(url_for('add_member')) flash('There is error while adding Member !') return redirect(url_for('add_member')) flash('You must Login first to add Team Member !') return redirect(url_for('warehouse_login')) #Tempo put this until Admin Dash is created return render_template('add_teammember.html')
def reqware(): if 'outlet_id' in session: outletId = session['outlet_id'] warehouseId = session['nearest_warehouse_id'] if request.method == 'POST': fullkey = uuid.uuid4() requestId = fullkey.time name = request.form['pname'] quantity = request.form['quantity'] description = request.files['description'] if description: path = os.path.basename(description.filename) file_ext = os.path.splitext(path)[1][1:] imgfilename = str(uuid.uuid4()) + '.' + file_ext descriptionname = secure_filename(imgfilename) app = current_app._get_current_object() description.save( os.path.join(app.config['UPLOAD_FOLDER'], descriptionname)) else: flash('Order is not placed..Please upload the description!') return redirect(url_for('nearest_warehouses')) sql = 'insert into warehousenotification(requestId,warehouseId,outletId,productName,description,quantity) values(%s,%s,%s,%s,%s,%s) ' cur = getdbcur() cur.execute(sql, (requestId, warehouseId, outletId, name, descriptionname, quantity)) n = cur.rowcount if n == 1: flash( 'Commodity request send to warehouse wait for response !') return redirect(url_for('nearest_warehouses')) flash('There is an error while placing Order..!') return redirect(url_for('nearest_warehouses')) flash('You must login first to view This page!') return redirect(url_for('outlet_login'))
def respass(): if request.method == 'POST': user_id = request.form['id'] verifcode = request.form['verifcode'] passwd = str( pybase64.b64encode((request.form['pass']).encode("utf-8")), "utf-8") if (verifcode == None): flash("please fill out the verification code") return redirect(url_for('reset_password')) cur = getdbcur() idquery = 'select managerName from warehouse where id= "' + user_id + '" AND passwordResetCode = "' + verifcode + '" ' cur.execute(idquery) m = cur.rowcount if m == 1: resquery = ' update warehouse set password = %s where (id = %s AND passwordResetCode = %s) ' cur.execute(resquery, (passwd, user_id, verifcode)) n = cur.rowcount if n == 1: delquery = ' update warehouse set passwordResetCode = %s where id = %s ' cur.execute(delquery, (uuid.uuid4().hex, user_id)) flash('Your password is Changed ..You can now Login!') return redirect(url_for('warehouse_login')) else: return render_template( 'reset_password.html', samepassmsg= "You password is same as previous One..login from below") else: return render_template( 'reset_password.html', rmsg= "Either unique Id or verification code is incorrect.. please try again!" ) return render_template('reset_password.html')
def wareforget(): if request.method == 'POST': user_id = request.form['id'] em = request.form['email'] email = str(pybase64.b64encode((em).encode("utf-8")), "utf-8") randcode = randint(100000, 999999) #Generating 6 digit random int sql = ' update warehouse set passwordResetcode = %s where (id = %s AND email = %s) ' cur = getdbcur() cur.execute(sql, (randcode, user_id, email)) n = cur.rowcount if n == 1: #getting mail app with app app = current_app._get_current_object() mail = Mail(app) subject = "verification code for account" msg = Message(subject, sender='*****@*****.**', recipients=[str(em)]) msg.body = "Your verification code for change password is " + str( randcode) mail.send(msg) flash('Check your verification code in your email') return redirect(url_for('reset_password')) else: return render_template( 'forgot_password.html', fmsg="Either unique Id or email is incorrect..try again!") return render_template('forgot_password.html')
def countbar(warehouseid): sql = 'SELECT commodityType , commodityUnits FROM producer where warehouseid = %s' cur = getdbcur() cur.execute(sql, warehouseid) n = cur.rowcount cbar = [0, 0, 0, 0, 0, 0, 0, 0] if n >= 1: data = cur.fetchall() cd = [list(i) for i in data] for i in range(0, len(cd)): for j in range(0, len(cd[i])): cd[i][j] = str(pybase64.b64decode(cd[i][j]), "utf-8") td = list(list(i) for i in cd) for i in td: if i[0] == 'black Pepper': cbar[0] = cbar[0] + int(i[1]) elif i[0] == 'turmeric': cbar[1] = cbar[1] + int(i[1]) elif i[0] == 'cinnamon': cbar[2] = cbar[2] + int(i[1]) elif i[0] == 'red chilly': cbar[3] = cbar[3] + int(i[1]) elif i[0] == 'mustard': cbar[4] = cbar[4] + int(i[1]) elif i[0] == 'clove': cbar[5] = cbar[5] + int(i[1]) elif i[0] == 'cumin': cbar[6] = cbar[6] + int(i[1]) elif i[0] == 'chick Pea': cbar[7] = cbar[7] + int(i[1]) else: continue return cbar
def clientreview(): if 'user_id' in session: app = current_app._get_current_object() id = session['user_id'] checksql = "select name from testimonial where clientId='"+id+"' " cur =getdbcur() cur.execute(checksql) m = cur.rowcount if m == 0: if request.method == 'POST': name = request.form['name'] review = request.form['review'].replace('\r\n','<br>') rating = request.form['rating'] img = request.files['img'] path=os.path.basename(img.filename) file_ext=os.path.splitext(path)[1][1:] imgfilename=str(uuid.uuid4())+'.'+file_ext clientimg = secure_filename(imgfilename) addquery ='insert into testimonial values (%s,%s,%s,%s,%s) ' cur.execute(addquery,(id,name,clientimg,rating,review)) n = cur.rowcount if n == 1: img.save(os.path.join(app.config['UPLOAD_FOLDER'],clientimg)) flash('Review added Successfully..Thankyou for using Our services!') return render_template('client_review.html') flash('There is error while adding review Please!') return redirect(url_for('add_member')) return render_template('client_review.html') flash('You have already give your review..!') return render_template('client_review.html') flash('You must Login first to give your review !') return redirect(url_for('warehouse_login'))
def searchproducer(): if 'user_id' in session: warehouseid = str(session['user_id']) cbar = countbar(warehouseid) if request.method == 'POST': si = str( pybase64.b64encode( (request.form['searchinp'].lower()).encode("utf-8")), "utf-8") searchquery = "select * from producer where (name like '%" + si + "%' OR commodityType like '%" + si + "%' ) and warehouseid = '" + warehouseid + "' " cur = getdbcur() cur.execute(searchquery) n = cur.rowcount if n >= 1: data = cur.fetchall() cd = [list(i) for i in data] for i in range(0, len(cd)): for j in range(1, len(cd[i]) - 1): cd[i][j] = str(pybase64.b64decode(cd[i][j]), "utf-8") td = tuple(tuple(i) for i in cd) return render_template('producers.html', pdata=td, pmsg="Search Results!", cbar=cbar) else: return render_template( 'producers.html', pmsg="No results for search..try different key!", cbar=cbar) else: return render_template('producers.html', pmsg="Enter something to search!", cbar=cbar) flash('You must login first to view Producers!') return redirect(url_for('warehouse_login'))
def homedata(): cur = getdbcur() outletcur = getoutletcur() sql = 'select * from team' cur.execute(sql) teamdata = cur.fetchall() sql = 'select * from flex' cur.execute(sql) flexdata = cur.fetchall() session['flex_data'] = flexdata sql = 'select * from testimonial' cur.execute(sql) reviewdata = cur.fetchall() ##Getting Blogs from the blogdb ## blogdata = getthreeblogs() ###########geeting total users (oulets,producer,warehouses)## totalbar = [] sql = 'select * from producer' cur.execute(sql) totalproducer = cur.rowcount totalbar.append(totalproducer) sql = 'select * from warehouse' cur.execute(sql) totalwarehouse = cur.rowcount totalbar.append(totalwarehouse) sql = 'select * from outlet' outletcur.execute(sql) totaloutlet = outletcur.rowcount totalbar.append(totaloutlet) totalbar.append(sum(totalbar)) session['totalbar'] = totalbar ######################################## return render_template('index.html',teamdata = teamdata,reviewdata = reviewdata,blogdata=blogdata)
def changepass(): if 'user_id' in session: usid = session['user_id'] if request.method == 'POST': oldpass = str( pybase64.b64encode( (request.form['oldPassword']).encode("utf-8")), "utf-8") newpass = str( pybase64.b64encode( (request.form['newPassword']).encode("utf-8")), "utf-8") cpass = str( pybase64.b64encode( (request.form['confirmPassword']).encode("utf-8")), "utf-8") if (newpass != cpass): return render_template( 'change_password.html', passmsg="new password and confirm password doesn't match.." ) cur = getdbcur() cpasssql = "update warehouse set password='******' where id = '" + usid + "' " cur.execute(cpasssql) n = cur.rowcount if n == 1: flash("password changed successfully !") session.pop('user_id', None) session.pop('user_name', None) return redirect(url_for('warehouse_login')) return render_template( 'change_password.html', passmsg="New password is same as Confirm password") return render_template('change_password.html') flash('Direct access to this page is Not allowed ..Login First!') return redirect(url_for('warehouse_login'))
def reject_order(): if 'user_id' in session: if request.method == 'POST': requestid = request.form['requestid'] sql = 'select outletId,productName from warehousenotification where requestId=%s' cur = getdbcur() cur.execute(sql, (requestid)) n = cur.rowcount if n == 1: data = cur.fetchone() outletId = str(data[0]) productName = str(data[1]) print(productName) warehouseId = session['user_id'] fullkey = uuid.uuid4() responseId = fullkey.time result = request.form['reason'] sql = 'insert into outletnotification values (%s,%s,%s,%s,%s,%s)' cur = getoutletcur() cur.execute(sql, (responseId, requestid, outletId, warehouseId, result, productName)) n = cur.rowcount if n == 1: sql = 'delete from warehousenotification where requestId=%s' cur = getdbcur() cur.execute(sql, (requestid)) n = cur.rowcount if n == 1: flash( 'Your order accept answer is send to the outlet manager' ) return redirect(url_for('warehouse_notification')) flash( 'There is some error in sending the response to the outlet manager' ) return redirect(url_for('warehouse_notification')) flash( 'There is some error in sending the response to the outlet manager' ) return redirect(url_for('warehouse_notification')) flash( 'there is some server error for processing your response. Try again Later !!' ) return redirect(url_for('warehouse_notification')) return redirect(url_for('warehouse_notification')) flash('You are not logged in...') return redirect(url_for('warehouse_login'))
def addproducer(): if 'user_id' in session: warehouseid = str(session['user_id']) cbar = countbar(warehouseid) if request.method == 'POST': fullkey = uuid.uuid4() uid = fullkey.time name = str( pybase64.b64encode( (request.form['name'].lower()).encode("utf-8")), "utf-8") phoneNumber = str( pybase64.b64encode( (request.form['phoneNumber'].lower()).encode("utf-8")), "utf-8") email = str( pybase64.b64encode( (request.form['email'].lower()).encode("utf-8")), "utf-8") gender = str( pybase64.b64encode( (request.form['gender'].lower()).encode("utf-8")), "utf-8") age = str( pybase64.b64encode( (request.form['age'].lower()).encode("utf-8")), "utf-8") address = str( pybase64.b64encode( (request.form['address'].lower()).encode("utf-8")), "utf-8") commodityType = str( pybase64.b64encode( (request.form['commodityType'].lower()).encode("utf-8")), "utf-8") commodityUnits = str( pybase64.b64encode( (request.form['commodityUnits'].lower()).encode("utf-8")), "utf-8") aadharNumber = str( pybase64.b64encode( (request.form['aadharNumber'].lower()).encode("utf-8")), "utf-8") addquery = 'insert into producer values(%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s)' cur = getdbcur() cur.execute( addquery, (uid, name, age, gender, phoneNumber, email, address, commodityType, commodityUnits, aadharNumber, warehouseid)) n = cur.rowcount if (n == 1): flash(' New Producer details added!') return redirect(url_for('producer')) else: return render_template( 'producers.html', pmsg='Adding new producer details failed!', cbar=cbar) return render_template('producers.html', cbar=cbar) flash('Direct access to this page is Not allowed !') return redirect(url_for('warehouse_login'))
def changeproducer(): if 'user_id' in session: if request.method == 'POST': id = request.form['id'] name = str( pybase64.b64encode( (request.form['name'].lower()).encode("utf-8")), "utf-8") email = str( pybase64.b64encode( (request.form['email'].lower()).encode("utf-8")), "utf-8") number = str( pybase64.b64encode( (request.form['phoneNumber'].lower()).encode("utf-8")), "utf-8") gender = str( pybase64.b64encode( (request.form['gender'].lower()).encode("utf-8")), "utf-8") age = str( pybase64.b64encode( (request.form['age'].lower()).encode("utf-8")), "utf-8") address = str( pybase64.b64encode( (request.form['address'].lower()).encode("utf-8")), "utf-8") commoditytype = str( pybase64.b64encode( (request.form['commodityType'].lower()).encode("utf-8")), "utf-8") commodityunits = str( pybase64.b64encode( (request.form['commodityUnits'].lower()).encode("utf-8")), "utf-8") aadharNumber = str( pybase64.b64encode( (request.form['aadharNumber'].lower()).encode("utf-8")), "utf-8") editquery = 'update producer set name =%s,emailId=%s,contactNumber=%s,commodityType=%s,commodityUnits=%s, age=%s, gender=%s, address=%s,aadharNumber=%s where unique_key=%s ' cur = getdbcur() cur.execute(editquery, (name, email, number, commoditytype, commodityunits, age, gender, address, aadharNumber, id)) n = cur.rowcount if n == 1: flash('producers Details changed Successfully !') return redirect(url_for('producer')) else: flash('Nothing will be changed in producers details !') return redirect(url_for('producer')) return redirect(url_for('producer')) flash( 'Direct access to this page is Not Alloed Login first To view this page!' ) return redirect(url_for('warehouse_login'))
def getnearestwarehouse(id): sql = 'select latitude,longitude,id from warehouse ' cur = getdbcur() cur.execute(sql) waredata = cur.fetchall() sql = 'select latitude,longitude from outlet where id = %s ' cur = getoutletcur() cur.execute(sql, id) outdata = cur.fetchone() mind = 9999999999999 warehouseid = 0 for i in waredata: distance = geodesic((i[0], i[1]), outdata) if distance < mind: mind = distance warehouseid = i[2] return warehouseid
def warenotif(): if 'user_id' in session: if 'notifcount' in session: session.pop('notifcount', None) wareid = session['user_id'] sql = 'select * from warehousenotification where warehouseId = "' + wareid + '" ' cur = getdbcur() cur.execute(sql) n = cur.rowcount if n >= 1: notifdata = cur.fetchall() return render_template('warehouse_notification.html', notifdata=notifdata) flash('There is no new order!!') return render_template('warehouse_notification.html') flash('You are not logged in...') return redirect(url_for('warehouse_login'))
def deleteproducer(): if 'user_id' in session: if request.method == 'POST': id = request.form['id'] delquery = 'delete from producer where unique_key="' + id + '" ' cur = getdbcur() cur.execute(delquery) n = cur.rowcount if n == 1: flash('producers Details deleted Successfully !') return redirect(url_for('producer')) else: flash('There is error in deleting producers details !') return redirect(url_for('producer')) return redirect(url_for('producer')) flash( 'Direct access to this page is Not Alloed Login first To view this page!' ) return redirect(url_for('warehouse_login'))
def producerhome(): if 'user_id' in session: warehouseid = str(session['user_id']) cbar = countbar(warehouseid) sql = 'select * from producer where warehouseid = %s' cur = getdbcur() cur.execute(sql, warehouseid) n = cur.rowcount if n >= 1: data = cur.fetchall() cd = [list(i) for i in data] for i in range(0, len(cd)): for j in range(1, len(cd[i]) - 1): cd[i][j] = str(pybase64.b64decode(cd[i][j]), "utf-8") td = tuple(tuple(i) for i in cd) return render_template('producers.html', pdata=td, cbar=cbar) else: return render_template( 'producers.html', pmsg="currently there is NO Producer information !", cbar=cbar) flash('You must login first to view Producers!') return redirect(url_for('warehouse_login'))
def addflex(): cur =getdbcur() app = current_app._get_current_object() if request.method == 'POST': imageno = int(request.form['imageno']) heading = request.form['heading'] body = request.form['body'] img = request.files['fleximg'] path=os.path.basename(img.filename) file_ext=os.path.splitext(path)[1][1:] imgfilename=str(uuid.uuid4())+'.'+file_ext fleximg = secure_filename(imgfilename) addquery = "update flex SET heading = %s , body = %s , image = %s WHERE id = %s" cur.execute(addquery,(heading,body,fleximg,imageno)) n = cur.rowcount if n == 1: img.save(os.path.join(app.config['UPLOAD_FOLDER'],fleximg)) flash('Image Added Successully !') return redirect(url_for('add_flex')) flash('There is error while adding image !') return redirect(url_for('add_flex')) #flash('You must Login first to add image !') #return redirect(url_for('warehouse_login')) #Tempo put this until Admin Dash is created return render_template('flex.html')
def wreg(): if request.method == 'POST': fullkey = uuid.uuid4() uid = fullkey.time em = request.form['email'] passwd = request.form['password'] cpasswd = request.form['confirmpassword'] longitude = request.form['longitude'] latitude = request.form['latitude'] if (not latitude or not longitude): flash('You denied the location access !!') return redirect(url_for('warehouse_register')) if (passwd != cpasswd): #flash msg flash('Password and Confirm Password does not match') return redirect(url_for('warehouse_register')) print(request.form['longitude']) print(request.form['latitude']) wname = str( pybase64.b64encode( (request.form['warehouseName'].lower()).encode("utf-8")), "utf-8") mname = str( pybase64.b64encode( (request.form['managerName'].lower()).encode("utf-8")), "utf-8") email = str( pybase64.b64encode( (request.form['email'].lower()).encode("utf-8")), "utf-8") compno = str( pybase64.b64encode( (request.form['companyNumber'].lower()).encode("utf-8")), "utf-8") pno = str( pybase64.b64encode( (request.form['phoneNumber'].lower()).encode("utf-8")), "utf-8") address = str( pybase64.b64encode( (request.form['address'].lower()).encode("utf-8")), "utf-8") password = str( pybase64.b64encode((request.form['password']).encode("utf-8")), "utf-8") cur = getdbcur() checkusersql = "select * from warehouse where (email = %s OR phoneNumber = %s )" cur.execute(checkusersql, (email, pno)) checkusercount = cur.rowcount if checkusercount == 0: insertusersql = 'insert into warehouse(id,warehouseName,managerName,companyNumber,phoneNumber,email,address,password,longitude,latitude) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ' cur.execute(insertusersql, (uid, wname, mname, compno, pno, email, address, password, longitude, latitude)) insertcount = cur.rowcount if insertcount >= 1: #getting mail app with app app = current_app._get_current_object() mail = Mail(app) subject = "Your registration successful !" msg = Message(subject, sender='*****@*****.**', recipients=[str(em)]) msg.body = "Hey ! you are registered with us. \n Your unique id to access the dashboard is " + str( uid) + "\n Save this key for your future reference !!" mail.send(msg) flash('You have succesfully register, You can now login!') return redirect(url_for('warehouse_login')) else: return render_template('warehouseregister.html', failuremsg="There is error!") else: return render_template( 'warehouseregister.html', failuremsg= "User is already registered with same Email or Phone Number!") return render_template('warehouseregister.html')
def wareprofile(): if 'user_id' in session: id = session['user_id'] cur = getdbcur() if request.method == 'POST': wareimg = request.files['wareimg'] if wareimg: checkphoto = "select warehouseImage from warehouse where id='" + id + "'" cur.execute(checkphoto) n = cur.rowcount if n == 1: prevphoto = cur.fetchone() photo = prevphoto[0] if photo != None: os.remove("./static/photos/" + photo) path = os.path.basename(wareimg.filename) file_ext = os.path.splitext(path)[1][1:] imgfilename = str(uuid.uuid4()) + '.' + file_ext wimgname = secure_filename(imgfilename) app = current_app._get_current_object() wareimg.save( os.path.join(app.config['UPLOAD_FOLDER'], wimgname)) warename = str( pybase64.b64encode( (request.form['warename'].lower()).encode("utf-8")), "utf-8") manname = str( pybase64.b64encode( (request.form['manname'].lower()).encode("utf-8")), "utf-8") manemail = str( pybase64.b64encode( (request.form['manemail'].lower()).encode("utf-8")), "utf-8") compno = str( pybase64.b64encode( (request.form['compno'].lower()).encode("utf-8")), "utf-8") manno = str( pybase64.b64encode( (request.form['manno'].lower()).encode("utf-8")), "utf-8") wareaddress = str( pybase64.b64encode( (request.form['wareaddress'].lower()).encode("utf-8")), "utf-8") isonum = request.form['isonum'] editprofsql = ' update warehouse set warehouseName = %s, managerName = %s, companyNumber = %s, phoneNumber = %s, email = %s, address = %s, warehouseImage = %s, isoNumber = %s where id = %s ' viewprofsql = 'select * from warehouse where id ="' + id + '" ' try: cur.execute(editprofsql, (warename, manname, compno, manno, manemail, wareaddress, wimgname, isonum, id)) except: editprofsql = ' update warehouse set warehouseName = %s, managerName = %s, companyNumber = %s, phoneNumber = %s, email = %s, address = %s, isoNumber = %s where id = %s ' cur.execute(editprofsql, (warename, manname, compno, manno, manemail, wareaddress, isonum, id)) n = cur.rowcount cur.execute(viewprofsql) m = cur.rowcount if m == 1: data = cur.fetchall() cd = [list(i) for i in data] for i in range(0, len(cd)): for j in range(1, len(cd[i]) - 5): cd[i][j] = str(pybase64.b64decode(cd[i][j]), "utf-8") td = tuple(tuple(i) for i in cd) return render_template('warehouse_profile.html', profmsg="Profile Updated !", pdata=td) return render_template( 'warehouse_profile.html', profmsg="There is error while changing data !", pdata=td) viewprofsql = 'select * from warehouse where id ="' + id + '" ' cur.execute(viewprofsql) n = cur.rowcount if n == 1: data = cur.fetchall() cd = [list(i) for i in data] for i in range(0, len(cd)): for j in range(1, len(cd[i]) - 5): cd[i][j] = str(pybase64.b64decode(cd[i][j]), "utf-8") td = tuple(tuple(i) for i in cd) return render_template('warehouse_profile.html', pdata=td) return render_template( 'warehouse_profile.html', profmsg="There is error in displaying profile msg") flash('Direct access to this page is Not allowed ..Login First!') return redirect(url_for('warehouse_login'))