def deleteCustomer(): if request.method == "POST": flag = 0 input_type = request.form['input_type'] id = request.form['id'] if (input_type == 'cust_id'): result = customer_table.read_customer(f"cust_id={id}") if (len(result) > 0): flag = 1 for row in result: #flash("Customer Found",category="success") return render_template('delete_customer.html', search=False, data=row, activate_customer_mgmt=True) elif (input_type == 'ssn_id'): result = customer_table.read_customer(f"ssnid={id}") if (len(result) > 0): flag = 1 for row in result: #flash("Customer Found",category="success") return render_template('delete_customer.html', search=False, data=row, activate_customer_mgmt=True) if (flag == 0): flash(f'Customer not found with {input_type} = {id} ', 'warning') return render_template('delete_customer.html', search=True, activate_customer_mgmt=True) return render_template('delete_customer.html', search=True, activate_customer_mgmt=True)
def createCustomer(): if request.method == 'POST': #create customer and return accordingly ssnid = int(request.form['cust_ssid']) name = request.form['cust_name'] age = request.form['cust_age'] address = request.form['cust_address'] state = request.form['cust_state'] city = request.form['cust_city'] result = customer_table.read_customer(f"ssnid={ssnid}") if (len(result) > 0): flash(f"Customer with ssnid = {ssnid} already exists!", category="warning") return redirect(url_for('createCustomer')) result = customer_table.getLastRow() prev_cust_id = None for row in result: prev_cust_id = row[0] if prev_cust_id != None: cust_id = int(prev_cust_id) + 1 else: cust_id = 100000001 customer_table.insert_customer( f"{int(cust_id)},{int(ssnid)},'{name}','{age}','{address}','{state}','{city}','Active','{str(datetime.now().strftime('%Y/%m/%d, %H:%M:%S'))}','Customer creation initiated successfully' " ) flash('Customer created successfully', 'success') return render_template('create_customer.html', activate_customer_mgmt=True) return render_template('create_customer.html', activate_customer_mgmt=True)
def createAccount(): if request.method == 'POST': if ('cust_id' in request.form and 'account_type' in request.form and 'deposit_amt' in request.form): cust_id = int(request.form['cust_id']) account_type = request.form['account_type'] deposit_amt = int(float(request.form['deposit_amt'])) result = accounts_table.read_accounts( f"cust_id={cust_id} and acc_type='{account_type}'") if (len(result) > 0): flash( f"A {account_type} account with cust_id = {cust_id} already exists!", category="warning") return redirect(url_for('createAccount')) result = customer_table.read_customer(f"cust_id={cust_id}") if len(result) > 0: #if customer found for row in result: rec = accounts_table.getLastRow() prev_acc_id = None for r in rec: prev_acc_id = r[0] if prev_acc_id != None: acc_id = int(prev_acc_id) + 1 else: acc_id = 300000001 ans = accounts_table.insert_accounts( f"{acc_id},{cust_id},'{account_type}',{deposit_amt},'Account creation initiated successfully', '{str(datetime.now().strftime('%Y/%m/%d, %H:%M:%S'))}','active' " ) if ans: # if deposit success prev_trans_id = None transIDs = transactions_table.getLastRow() for t in transIDs: prev_trans_id = t[1] if prev_trans_id == None: trans_id = 500000001 else: trans_id = prev_trans_id + 1 transactions_table.insert_transactions( f"{acc_id},{trans_id},'Deposit','{date.today()}',{deposit_amt} " ) flash('Account creation initiated successfully', 'success') return redirect(url_for('createAccount')) else: flash('An unknown error occured', 'warning') return redirect(url_for('createAccount')) else: flash(f'Customer with id = {cust_id} not found! ', 'warning') return redirect(url_for('createAccount')) return render_template('create_account.html', activate_account_mgmt=True)
def customerSearch(): if request.method == "POST": if ('input_type' in request.form and 'id' in request.form): input_type = request.form['input_type'] id = int(request.form['id']) #search for customer data with id and input_type...write a funtion to pull data from db using input_Type and id if (input_type == 'cust_id'): result = customer_table.read_customer(f"cust_id={id}") if (len(result) > 0): for row in result: if (id == row[0]): #flash(f"Customer found!",category="success") return render_template('customer_search.html', search=False, data=row, activate_search=True) else: flash(f"Customer with {input_type} = {id} not found!", category='warning') return render_template('customer_search.html', search=True, activate_search=True) elif (input_type == 'ssn_id'): result = customer_table.read_customer(f"ssnid={id}") if (len(result) > 0): for row in result: if (id == row[1]): #flash(f"Customer found!",category="success") return render_template('customer_search.html', search=False, data=row, activate_search=True) else: flash(f"Customer with {input_type} = {id} not found!", category='warning') return render_template('customer_search.html', search=True, activate_search=True) return render_template('customer_search.html', search=True, activate_search=True)
def viewCustomer(): if request.method == 'POST': custid = int(request.form['custid']) ssnid = int(request.form['ssnid']) result = customer_table.read_customer(f"ssnid={ssnid}") if (len(result) > 0): flag = 1 for row in result: #flash("Customer Found",category="success") return render_template('view_customer.html', datatable=True, activate_status_details=True, data=row)
def customerStatus(): customers = customer_table.read_customer() return render_template('customer_status.html', datatable=True, activate_status_details=True, data=customers)