def withdraw(aid=False): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': amount = request.form['amount'] previous_amount = request.form['ws_acct_balance'] ws_acct_id = request.form['ws_acct_id'] ws_acct_balance = int(previous_amount) - int(amount) if ws_acct_balance <= 0: flash("Withdraw not allowed, please choose smaller amount", "danger") url = '/withdraw/' + ws_acct_id return redirect(url) Account.objects(ws_acct_id=ws_acct_id).update_one( ws_acct_balance=ws_acct_balance, ws_message='WITHDRAW', ws_acct_lasttrdate=datetime.now()) transactions = Transactions( ws_tnsc_id=get_random_alphaNumeric_string(8), ws_acct_id=ws_acct_id, ws_desc='Withdraw', ws_amt=amount, ws_trxn_date=datetime.now()) transactions.save() flash("Amount withdrawn successfully", "success") url = '/accounts/' + ws_acct_id return redirect(url) if aid: account = Account.objects(ws_acct_id=aid).first() return render_template("account_operations/withdraw_money.html", account=account, info=True) return render_template("account_operations/withdraw_money.html", info=False)
def deposit(aid=False): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': amount = request.form['amount'] previous_amount = request.form['ws_acct_balance'] ws_acct_id = request.form['ws_acct_id'] ws_acct_balance = int(previous_amount) + int(amount) Account.objects(ws_acct_id=ws_acct_id).update_one( ws_acct_balance=ws_acct_balance, ws_message='DEPOSIT', ws_acct_lasttrdate=datetime.now()) transactions = Transactions( ws_tnsc_id=get_random_alphaNumeric_string(8), ws_acct_id=ws_acct_id, ws_desc='Deposit', ws_amt=amount, ws_trxn_date=datetime.now()) transactions.save() url = '/accounts/' + ws_acct_id flash("Amount deposited successfully", "success") return redirect(url) if aid: account = Account.objects(ws_acct_id=aid).first() return render_template("account_operations/deposit.html", account=account, info=True) return render_template("account_operations/deposit.html", info=False)
def transfer(): if request.method == 'POST': SA = request.form.get('SA') TA = request.form.get('TA') amount = request.form.get('amount') amount = int(amount) if SA: if TA: SA_user = Accounts.query.filter( and_(Accounts.accountid == SA, Accounts.status == 'Active')).first() if SA_user: TA_user = Accounts.query.filter( and_(Accounts.accountid == TA, Accounts.status == 'Active')).first() if TA_user: SA_balance = SA_user.balance if SA_balance >= amount: new_SA_balance = SA_balance - amount SA_user.balance = new_SA_balance tt = Transactions(accountid=SA, customerid=SA_user.accountid, amount=amount, msg='transfered-to ' + str(TA), date=datetime.datetime.now()) db.session.add(tt) TA_balance = TA_user.balance new_TA_balance = TA_balance + amount TA_user.balance = new_TA_balance tt = Transactions(accountid=TA, customerid=TA_user.customerid, amount=amount, msg='received from ' + str(SA), date=datetime.datetime.now()) db.session.add(tt) db.session.commit() flash('Transaction successful') return render_template( 'display2.html', SA=SA, TA=TA, SA_balance=SA_balance, TA_balance=TA_balance, new_SA_balance=new_SA_balance, new_TA_balance=new_TA_balance) else: flash('Insufficent balance') else: flash('Target Account not Found/ Inactive') else: flash('Source Account not found/ Inactive ') else: flash('please enter Target account') else: flash('please enter Source account') return render_template('transfer.html')
def withdraw(): if request.method == 'POST': accountid = request.form.get('accountid') amount = request.form.get('amount') amount = int(amount) if accountid: a_user = Accounts.query.filter( and_(Accounts.accountid == accountid, Accounts.status == 'Active')).first() if a_user: balance = a_user.balance if (balance >= amount): new_balance = balance - amount a_user.balance = new_balance tt = Transactions(accountid=accountid, customerid=a_user.customerid, amount=amount, msg='debit', date=datetime.datetime.now()) db.session.add(tt) db.session.commit() flash('Transaction successful') return render_template('display1.html', account=a_user) else: flash('Insufficient balance') else: flash('Account Id Invalid or inactive account !') return render_template('withdraw.html')
def deposit(): if request.method == 'POST': accountid = request.form.get('accountid') amount = request.form.get('amount') if accountid: a_user = Accounts.query.filter( and_(Accounts.accountid == accountid, Accounts.status == 'Active')).first() if a_user: balance = a_user.balance new_balance = balance + int(amount) a_user.balance = new_balance tt = Transactions(customerid=a_user.customerid, accountid=accountid, amount=amount, msg='credit', date=datetime.datetime.now()) db.session.add(tt) db.session.commit() flash('Transaction successful') return render_template('display1.html', account=a_user) else: flash('Account ID invalid/ Inactive Account') return render_template('deposit.html')
def transfer(): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': print(request.form, flush=True) sr_acct_id = request.form['sr_acct_id'] tr_acct_id = request.form['tr_acct_id'] if sr_acct_id == tr_acct_id: flash("Source and Target cannot be same !", "danger") return redirect('/transfer') amount = int(request.form['amount']) account1 = Account.objects(ws_acct_id=sr_acct_id).first() account2 = Account.objects(ws_acct_id=tr_acct_id).first() if account1 and account2: if account1.ws_acct_balance >= amount: sr_acct_balance = account1.ws_acct_balance - amount tr_acct_balance = account2.ws_acct_balance + amount Account.objects(ws_acct_id=sr_acct_id).update_one( ws_acct_balance=sr_acct_balance, ws_message='TRANSFER', ws_acct_lasttrdate=datetime.now()) Account.objects(ws_acct_id=tr_acct_id).update_one( ws_acct_balance=tr_acct_balance, ws_message='TRANSFER', ws_acct_lasttrdate=datetime.now()) transactions1 = Transactions( ws_tnsc_id=get_random_alphaNumeric_string(8), ws_acct_id=sr_acct_id, ws_desc='Transfer from here', ws_amt=amount, ws_trxn_date=datetime.now(), ws_src_typ=account1.ws_acct_type, ws_tgt_typ=account2.ws_acct_type) transactions1.save() transactions2 = Transactions( ws_tnsc_id=get_random_alphaNumeric_string(8), ws_acct_id=tr_acct_id, ws_desc='Transfer to here', ws_amt=amount, ws_trxn_date=datetime.now(), ws_src_typ=account1.ws_acct_type, ws_tgt_typ=account2.ws_acct_type) transactions2.save() flash("Amount transfer completed successfully !", "success") return redirect('/transfer') else: flash("Transfer not allowed, please choose smaller amount !", "danger") return redirect('/transfer') else: if account1: flash("Destination Account Doest exists !", "danger") return redirect('/transfer') else: flash("Source Account Doest exists !", "danger") return redirect('/transfer') return render_template("account_operations/transfer_money.html")
def create_account(): if not session.get('user_id'): return redirect(url_for('login')) if request.method == 'POST': ws_cust_id = request.form['ws_cust_id'] ws_acct_id = get_random_alphaNumeric_string(9) ws_acct_type = request.form['ws_acct_type'] ws_acct_balance = int(request.form['ws_acct_balance']) if ws_acct_balance <= 0: flash("Account creation Failed due to negative amount!", "danger") return redirect(url_for('create_account')) ws_acct_crdate = datetime.now() ws_acct_lasttrdate = datetime.now() ws_acct_duration = 0 ws_status = 'CREATED' account = Account.objects(ws_cust_id=ws_cust_id, ws_acct_type=ws_acct_type) if account: flash( "Current User already have this type of account please try other", "danger") return redirect(url_for('create_account')) account = Account(ws_cust_id=ws_cust_id, ws_acct_id=ws_acct_id, ws_acct_type=ws_acct_type, ws_acct_balance=ws_acct_balance, ws_acct_crdate=ws_acct_crdate, ws_message='CREATED', ws_acct_lasttrdate=ws_acct_lasttrdate, ws_acct_duration=ws_acct_duration, ws_status=ws_status) account.save() transactions = Transactions( ws_tnsc_id=get_random_alphaNumeric_string(8), ws_acct_id=ws_acct_id, ws_desc='Deposit', ws_amt=ws_acct_balance, ws_trxn_date=datetime.now()) transactions.save() flash("Account creation initiated successfully!", "success") return redirect('/accounts/' + ws_acct_id) return render_template("account_management/create_account.html")
def account_statement(): if request.method == 'POST': ws_acct_id = request.form['ws_acct_id'] transactions = Transactions.objects(ws_acct_id=ws_acct_id) n = request.form['limit'] if n: n = int(request.form['limit']) transactions = Transactions.objects(ws_acct_id=ws_acct_id).limit(n) if request.form['from_date'] and request.form['to_date']: start = request.form['from_date'] end = request.form['to_date'] if n: n = int(request.form['limit']) transactions = Transactions.objects( (Q(ws_trxn_date__lte=end) & Q(ws_trxn_date__gte=start)) & Q(ws_acct_id=ws_acct_id)).limit(n) transactions = Transactions.objects((Q(ws_trxn_date__lte=end) & Q(ws_trxn_date__gte=start)) & Q(ws_acct_id=ws_acct_id)) return render_template("account_operations/account_statement.html", transactions=transactions, ws_acct_id=ws_acct_id) return render_template("account_operations/account_statement.html")
def incoming_transaction(): form = IncomingTransactionForm() if form.validate_on_submit(): transactionData = Transactions( date_posted=datetime.now(), TransactionOwner=current_user, transaction_type="Incoming", amount=form.incoming_transaction_amount.data) db.session.add(transactionData) db.session.commit() return redirect(url_for('home')) else: print(form.errors) return render_template('incomingTransaction.html', title='New Incoming', form=form)
def createaccount(): if request.method == 'POST': customerid = request.form.get('customerid') accountid = request.form.get('accountid') accounttype = request.form.get('accounttype') depositamount = request.form.get('depositamount') accountstatus = 'Active' message = 'Account created sucessfully' lastupdated = datetime.datetime.now() customer = Customerstatus.query.filter_by( customerid=customerid).first() if customer: if customer.status == 'Active': account = Accounts(customerid=customerid, accountid=accountid, accounttype=accounttype, balance=depositamount, status=accountstatus, message=message, lastupdated=lastupdated) transaction = Transactions(customerid=customer.customerid, accountid=accountid, amount=depositamount, msg="Debit", date=lastupdated) try: db.session.add(account) db.session.add(transaction) db.session.commit() flash('Account Added Sucessfully') return redirect(url_for('home')) except: flash('Constrains Failed') return redirect(url_for('home')) else: flash('Customer Deactivated') return redirect(url_for('Home')) else: flash('Invalid Customerid / Account Inactive') return redirect(url_for('createaccount')) else: return render_template('createaccount.html')