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 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 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 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 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 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 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 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 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 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 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")
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")
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 delete(id): if request.method == "POST": Customer.objects(customer_id=id).delete() return render_template("executive.html", mes="data deleted successfully")