def update_customer(cid): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': ws_name = request.form['ws_name'] ws_adrs1 = request.form['ws_adrs1'] if request.form['ws_adrs2']: ws_adrs2 = request.form['ws_adrs2'] else: ws_adrs2 = 'NULL' ws_city = request.form['ws_city'] ws_state = request.form['ws_state'] ws_age = request.form['ws_age'] ws_status = 'UPDATED' ws_message = request.form['ws_message'] ws_cust_update = datetime.now() Customer.objects(ws_cust_id=cid).update_one( ws_name=ws_name, ws_adrs1=ws_adrs1, ws_adrs2=ws_adrs2, ws_city=ws_city, ws_state=ws_state, ws_cust_update=ws_cust_update, ws_age=ws_age, ws_status=ws_status, ws_message=ws_message) flash("Customer update initiated successfully !", "success") url = '/customers/' + cid return redirect(url) customer = Customer.objects(ws_cust_id=cid).first() return render_template("customer_management/update_customer.html", customer=customer)
def delete_customer(cid): if not session.get('user_id'): return redirect(url_for('login')) Customer.objects(ws_cust_id=cid).update_one(ws_status='DELETED') flash("Customer with ID- " + cid + " deletion initiated successfully !", "success") return redirect(url_for('index'))
def create_customer(): form = CustomerForm() if form.validate_on_submit(): ssn_id = form.customerId.data name = form.customer_name.data age = form.age.data address = form.address.data state = form.state.data if state is not None: customer = Customer(customerId=ssn_id, customer_name=name, age=age, address=address, state=state) customer.save() flash("CUSTOMER CREATED SUCCESSFULLY", "success") return redirect(url_for('create_customer')) else: flash("Sorry, Something went wrong", "danger") return render_template("create_customer.html", title="Create Customer", customer_management=True, form=form, states=states_list)
def delete_customer(id): if session.get('userId') and session.get('roleId')=="1111": print("delete id",id) delete_customer=Customer.objects(ws_ssn_id=id).first() if not delete_customer: delete_customer=Customer.objects(ws_cust_id=id).first() if not delete_customer: flash("Invalid ID","danger") return redirect("/delete_search") if(request.method=='POST'): delete_customer_status=Customer_Status.objects(ws_ssn_id=id).first() delete_customer_status.ws_status='inactive' delete_customer_status.ws_message='customer deleted' x = datetime.now() d=x.strftime("%x") y = datetime.now() t=y.strftime("%X") dt = d + " " + t delete_customer_status.ws_cust_lastUdate=datetime.strptime(dt,'%m/%d/%y %H:%M:%S') delete_customer_status.save() delete_customer.delete() flash('your details are deleted', 'success') return redirect(url_for('index')) return render_template('delete_customer.html',delete_customer=delete_customer) else: flash("Sorry You are not authorised to access this page","danger") return redirect("/")
def register_customer(): if request.method == "POST": ssn_id = request.form["ssnid"] check = Customer.objects(ssn_id=ssn_id).first() customer_id = str( int(Customer.objects.order_by('-customer_id').first().customer_id) + 2) customer_name = request.form["customerName"] age = request.form["age"] address = request.form["address"] state = request.form["state"] city = request.form["city"] if (check): message = "Ssn Id Already Exist" else: message = "Customer Created Successfully" customer = Customer(ssn_id=ssn_id, customer_id=customer_id, customer_name=customer_name, age=age, address=address, state=state, city=city, customer_status=message).save() return render_template("register_customer.html", message=message) return render_template("register_customer.html")
def create_account(): if request.method == "POST": customer_id = request.form["customerId"] check_cusid = Customer.objects(customer_id=customer_id).first() account_id = str( int(Account.objects.order_by('-customer_id').first().account_id) + 2) account_type = request.form["account_type"] check_type = Account.objects(customer_id=customer_id, account_type=account_type).first() deposit_amount = request.form["depositAmount"] if (not check_cusid): message = "Customer Id doesnot Exist" elif (check_type): message = "Customer already has account of specific type" account = Account.objects(customer_id=customer_id, account_type=account_type).first() account.account_status = message account.save() else: message = "Account Created Successfully" account = Account(customer_id=customer_id, account_id=account_id, account_type=account_type, deposit_amount=deposit_amount, account_status=message).save() return render_template("create_account.html", message=message) return render_template("create_account.html")
def create_user_and_sample_Items(name, phone_num): customer = Customer(name, phone_num) cookie = Item(name + "_Cookie", 1.50) muffin = Item(name + "_Muffin", 2.00, "Carby stuff") latte = Item(name + "_Latte", 4.35, "Steamed milk over expresso") mocha = Item(name + "_Mocha", 5.00, "Steamed milk over expresso and chocolate syrup") session.add(customer) session.add(cookie) session.add(muffin) session.add(latte) session.add(mocha) session.commit() result = {"customer": customer} item_names = ['cookie', 'muffin', 'latte', 'mocha'] for name in item_names: item = session.query(Item).\ filter(func.lower(Item.name).like('%' + name + '%')).\ filter(func.lower(Item.name).like('%' + customer_name + '%')).\ scalar() result[name] = item return result
def search_update(): if request.method == "POST": ssn_id = request.form["ssnId"] customer_id = request.form["customerId"] check_ssn = Customer.objects(ssn_id=ssn_id).first() check_cusid = Customer.objects(customer_id=customer_id).first() print(check_cusid) print(check_ssn) if check_ssn or check_cusid: if check_cusid == None and check_ssn == None: return render_template("search_customer.html") elif check_cusid == None: return render_template("update_customer.html", form=check_ssn) else: return render_template("update_customer.html", form=check_cusid) return render_template("search_customer.html")
def generate_Cutomer_Id(): st="10" num2=random.randint(1000000,9999999) cust_id=int(st+str(num2)) customer=Customer.objects(ws_cust_id=cust_id).first() if customer: generate_Cutomer_Id() return str(cust_id)
def update(id): if request.method == "POST": customer = Customer.objects(customer_id=id).first() customer.customer_name = request.form["newcustomername"] customer.address = request.form["newaddress"] customer.age = request.form["newage"] customer.save() return render_template("executive.html", mes="data updated successfully")
def index(): c_count = UserStore.objects(role='CASHIER').count() e_count = UserStore.objects(role='EXECUTIVE').count() customer_count = Customer.objects().count() account_count = Account.objects().count() return render_template("home.html", c_count=c_count, e_count=e_count, customer_count=customer_count, account_count=account_count)
def customer_search(): if request.method == 'POST': ws_cust_id = request.form['cid'] ws_ssn = request.form['ssn'] if ws_cust_id: customer = Customer.objects(ws_cust_id=ws_cust_id).first() if customer: url = 'customers/' + ws_cust_id return redirect(url) else: flash("No Customer exists with given Customer Id !", "danger") elif ws_ssn: customer = Customer.objects(ws_ssn=ws_ssn).first() if customer: ws_cust_id = customer.ws_cust_id url = 'customers/' + ws_cust_id return redirect(url) else: flash("No Customer exists with given SSN !", "danger") else: flash("Fill Either Customer ID OR SSN ID to search", "danger") return render_template("status_detail/customer_search.html")
def create_customer(): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': ws_ssn = request.form['ws_ssn'] if len(str(ws_ssn)) != 9: flash("SSN length need to be 9 digits", "danger") return redirect(url_for('create_customer')) customer = Customer.objects(ws_ssn=ws_ssn).first() if customer: flash("SSN Alreday exists with another Customer", "danger") return redirect(url_for('create_customer')) ws_cust_id = '99899' + get_random_alphaNumeric_string(4) ws_name = request.form['ws_name'] ws_adrs1 = request.form['ws_adrs1'] if request.form['ws_adrs2']: ws_adrs2 = request.form['ws_adrs2'] else: ws_adrs2 = 'NULL' ws_city = request.form['ws_city'] ws_state = request.form['ws_state'] ws_age = request.form['ws_age'] ws_message = 'JUST CREATED' ws_status = 'CREATED' ws_cust_update = datetime.now() customer = Customer(ws_ssn=ws_ssn, ws_cust_id=ws_cust_id, ws_name=ws_name, ws_adrs1=ws_adrs1, ws_adrs2=ws_adrs2, ws_city=ws_city, ws_state=ws_state, ws_age=ws_age, ws_status=ws_status, ws_cust_update=ws_cust_update) customer.save() flash("Customer creation initiated successfully !", "success") return redirect('/customers/' + ws_cust_id) return render_template("customer_management/create_customer.html")
def checkin(): if request.method == 'POST': data_entered = Customer(fn=request.form['firstname'], ln=request.form['lastname'], vInfo=request.form['vInfo'], dur=request.form['duration']) try: db.session.add(data_entered) db.session.commit() db.session.close() except: db.session.rollback() return render_template('parking.html') return render_template('checkin.html',)
def customers(cid): if not session.get('user_id'): return redirect(url_for('login')) if cid: customers = Customer.objects(ws_cust_id=cid) if customers: return render_template("customer_management/customers.html", customers=customers) else: flash("User with ID " + cid + " Doesn't exists", "danger") return redirect(url_for(index)) else: flash("URL Doesn't exists", "danger") return redirect(url_for(index))
def create_customer(): if session.get('userId') and session.get('roleId')=="1111": form = Create_Customer_Form() if(request.method=='POST'): if(form.validate_on_submit()): ssn_id=form.ssn_id.data customer_name=form.customer_name.data age=form.age.data address=form.address.data cust_id=generate_Cutomer_Id() status='Active' x = datetime.now() d=x.strftime("%x") y = datetime.now() t=y.strftime("%X") dt = d + " " + t print("##############"+dt+"##############") last_updated =datetime.strptime(dt,'%m/%d/%y %H:%M:%S') message='customer created successfully' if not ssn_id.isnumeric(): flash('Invalid SSN ID', 'danger') return redirect(url_for('create_customer')) # state=form.state.data # city=form.city.data # ssn_id = request.form.get('ssn_id') # user = Create_customer.objects(ssn_id=ssn_id).first() # customer_name = request.form.get('customer_name') # age = request.form.get('age') # address = request.form.get('address') # state = request.form.get('state') # city = request.form.get('city') Customer(ws_ssn_id=ssn_id,ws_cust_id=cust_id,ws_name=customer_name,ws_age=age,ws_address=address).save() Customer_Status(ws_ssn_id=ssn_id,ws_cust_id=cust_id,ws_status=status,ws_message=message,ws_cust_lastUdate=last_updated).save() # if user: # flash('ssn_id should be unique', 'danger') # return redirect(url_for('create_customer')) flash('Thank for submmtimg your details.we will get back to you soon', 'success') return redirect(url_for('create_customer')) return render_template('create_customer.html',form=form) else: flash("Sorry You are not authorised to access this page","danger") return redirect("/")
def create_customer(): if session.get('ROLE') != "acc_exec": flash("Action Not Allowed", category="danger") return redirect('main.home') else: form = CustomerDetailsForm() form.choice.data = 'C' form.cust_id.data = Customer.generate_cust_id() if form.validate_on_submit(): customer = Customer(ssn=form.ssn_id.data, cust_id=form.cust_id.data, cust_name=form.cust_name.data, cust_address=form.address.data, cust_contact=form.contact.data, cust_age=form.cust_age.data, cust_state=form.state.data, cust_city=form.city.data) db.session.add(customer) db.session.commit() flash("Customer Successfully Created!!!", category="success") return redirect(url_for('main.home')) return render_template("customers/create_customer.html", form=form, title="Create Customer")
def register(): if current_user.is_authenticated: return redirect(url_for('home')) form = RegistrationForm() if form.validate_on_submit(): hash_pw = bcrypt.generate_password_hash(form.password.data) user = Customer(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=hash_pw) db.session.add(user) db.session.commit() return redirect(url_for('login')) return render_template('register.html', title='Register', form=form)
def delete_customer_data(): if session.get('userId') and session.get('roleId')=="1111": print("delete id",request.form.get('ssn_id')) delete_customer=Customer.objects(ws_ssn_id=request.form.get('ssn_id')).first() print(delete_customer) if(request.method=='POST'): delete_customer.delete() flash('your details are deleted', 'success') return redirect(url_for('index')) return render_template('delete_customer.html',delete_customer=delete_customer) else: flash("Sorry You are not authorised to access this page","danger") return redirect("/")
def setUp(self): """ Will be called before every test """ # ensure there is no data in the test database when the test starts db.session.commit() db.drop_all() db.create_all() # create test admin user hashed_pw = bcrypt.generate_password_hash('admin2016') admin = Customer(first_name="admin", last_name="admin", email="*****@*****.**", password=hashed_pw) # create test non-admin user hashed_pw_2 = bcrypt.generate_password_hash('test2016') employee = Customer(first_name="test", last_name="user", email="*****@*****.**", password=hashed_pw_2) # save users to database db.session.add(admin) db.session.add(employee) db.session.commit()
def create_account(): if not session.get('username'): return redirect(url_for('login')) form = AccountForm() customer_Id = form.customerId.data account_type = form.account_type.data deposit = form.deposit.data customer = Customer() if customer_Id: classess = list( Customer.objects.aggregate(*[{ '$lookup': { 'from': 'account', 'localField': 'customerId', 'foreignField': 'customerId', 'as': 'r1' } }, { '$match': { 'customerId': customer_Id } }])) print(classess) if classess: acc = Account(customerId=customer_Id, account_type=account_type, deposit=deposit) acc.save() flash("Account created", 'success') return redirect(url_for('create_account')) else: flash("account not found") return render_template("create_account.html", title="Create Account", account_management=True, form=form)
def validate_ssn_id(self, ssn_id): print("insdie valid") user = Customer.objects(ws_ssn_id=ssn_id.data).first() if user: raise ValidationError("SSN Id already exists")
def validate_ws_cust_id(self, ws_cust_id): print("insdie valid") account = Customer.objects(ws_cust_id=ws_cust_id.data).first() if not account: raise ValidationError("Customer id does not exist")
#Here we will write all of our routes from application import app, db from application.models import User, Customer, Account from flask import render_template, request, Response, flash, redirect from application.forms import LoginForm while (Customer.objects.all().count() == 0): Customer(ssn_id="111222333444", customer_id="900000000", customer_name="Subhankar Majumder", age="23", address="Sodepur", state="West Bengal", city="Kolkata", customer_status="Demo Customer created Successfully").save() Account(customer_id="900000000", account_id="101011000", account_type="Current Account", deposit_amount="1000", account_status="Demo Account created Successfully").save() @app.route("/", methods=['POST', 'GET']) @app.route("/login", methods=['POST', 'GET']) def login(): form = LoginForm() if form.validate_on_submit(): id = form.user_id.data password = form.password.data user = User.objects(user_id=id).first() if user and password == user.password and user.work == "executive":
def delete(id): if request.method == "POST": Customer.objects(customer_id=id).delete() return render_template("executive.html", mes="data deleted successfully")
except IOError: parent_directory = os.path.dirname(pathname) if not os.path.isdir(parent_directory): os.system('mkdir -p {0}'.format(parent_directory)) os.system('head -c 24 /dev/urandom > {0}'.format(pathname)) omnibus = Flask(__name__) omnibus.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///sql.db" omnibus.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = True omnibus.register_blueprint(views) keymaker(omnibus) customer = Customer() # customer.setup(omnibus) @omnibus.before_request def before_request(): g.customer = None if 'customer_id' in session: # FIXME TO BE CONTINUED... print(session['customer_id']) g.customer = customer.get_customer(session['customer_id']) # Front page @omnibus.route('/', methods=['GET']) def front():
def update_customer(id): print(id) if session.get('userId') and session.get('roleId')=="1111": update_customer=Customer.objects(ws_ssn_id=id).first() form=Update_Customer_Form() print(update_customer) if update_customer: form.ssn_id.data = update_customer.ws_ssn_id form.cust_id.data = update_customer.ws_cust_id form.old_customer_name.data =update_customer.ws_name form.old_age.data = update_customer.ws_age form.old_address.data = update_customer.ws_address customer_name=form.new_customer_name.data age=form.new_age.data address=form.new_address.data else: update_customer=Customer.objects(ws_cust_id=id).first() if update_customer: form.ssn_id.data = update_customer.ws_ssn_id form.cust_id.data = update_customer.ws_cust_id form.old_customer_name.data =update_customer.ws_name form.old_age.data = update_customer.ws_age form.old_address.data = update_customer.ws_address customer_name=form.new_customer_name.data age=form.new_age.data address=form.new_address.data else: flash("Invalid ID","danger") return redirect("/update_search") if(request.method=='POST'): if (form.validate_on_submit()): customer_name=form.new_customer_name.data age=form.new_age.data address=form.new_address.data print(customer_name) print(age) print(address) new_customer=Customer.objects(ws_ssn_id=form.ssn_id.data).first() new_customer.ws_name=customer_name new_customer.ws_age=age new_customer.ws_address=address update_customer_status=Customer_Status.objects(ws_ssn_id=form.ssn_id.data).first() x = datetime.now() d=x.strftime("%x") y = datetime.now() t=y.strftime("%X") dt = d + " " + t if update_customer_status: update_customer_status.ws_message='customer update completed' update_customer_status.ws_cust_lastUdate=datetime.strptime(dt,'%m/%d/%y %H:%M:%S') update_customer_status.save() else: Customer_Status(ws_ssn_id=form.ssn_id.data,ws_cust_id=new_customer.ws_cust_id,ws_message='customer update completed',ws_status="Active",ws_cust_lastUdate=datetime.strptime(dt,'%m/%d/%y %H:%M:%S')).save() new_customer.save() flash('your details are updated', 'success') return redirect(url_for('index')) # update_customer=Customer.objects(ws_ssn_id=id).first() return render_template('update_customer1.html',update_customer=update_customer,form=form) else: flash("Sorry You are not authorised to access this page","danger") return redirect("/")
def getcustomer(cid): customers = Customer.objects(ws_cust_id=cid) return Response(json.dumps(customers), mimetype="application/json")
"Jaipur", "Gangtok", "Chennai", "Hyderabad", "Agartala", "Dehradun", "Lucknow", "Kolkata", ] ssnNo = rd.randint(77777777, 99999999) custID = rd.randint(33333333, 99999999) for i in range(25): rdsc = rd.randint(0, 28) cust = Customer(ssn=ssnNo + 1, cust_id=custID + 1, cust_name=names[rd.randint(0, 39)], cust_address=addr[rd.randint(0, 9)], cust_contact=rd.randint(8888888888, 9999999999), cust_age=rd.randint(10, 80), cust_state=state[rdsc], cust_city=city[rdsc]) print(cust) ssnNo += 1 custID += 1 db.session.add(cust) db.session.commit() customers = Customer.query.all() for customer in customers: print(customer)