def index(): time_deposits = TimeDeposit.select().where( (TimeDeposit.terminal_date <= datetime.now()) & (TimeDeposit.deleted == False)).execute() for time_deposit in time_deposits: Account.update(account=Account.balance + (time_deposit.amount * time_deposit.interest) + time_deposit.amount).where( Account.account_number == time_deposit.account_number).execute() TimeDeposit.update(deleted=True).where( TimeDeposit.id == time_deposit.id).execute() accounts = Account.select().where( Account.user_id == session['user']['id']).execute() transactions = len( Transaction.select(Transaction).join( Account, on=(Transaction.account_number == Account.account_number)).join( User, on=(Account.user_id == User.id)).where( User.id == session['user']['id']).dicts()) return render_template('main/index.html', accounts=accounts, transactions=transactions)
def transfer(): accounts = Account.select().where( (Account.user_id == session['user']['id']) & (Account.type != 3)).execute() form = UserTransferForm(request.form) form.sender_account_number.choices = [ (account.account_number, "{} ({})".format(account.account_number, 'Savings' if account.type == 1 else 'ATM')) for account in accounts ] if form.validate_on_submit(): sender_account = Account.get( Account.account_number == form.sender_account_number.data) receiver_account = Account.get( Account.account_number == form.receiver_account_number.data) Account.update(balance=Account.balance - form.amount.data, updated_at=datetime.now()).where( Account.account_number == form.sender_account_number.data).execute() Account.update(balance=Account.balance + form.amount.data, updated_at=datetime.now()).where( Account.account_number == form.receiver_account_number.data).execute() Transaction.insert(account_number=form.sender_account_number.data, reference_number=form.receiver_account_number.data, amount=form.amount.data, type='FUND TRANSFER').execute() flash('Fund Transfer successful') return redirect(url_for('main.transfer')) return render_template('main/transfer.html', form=form)
def index(): accounts = Account.select(Account.id, Account.account_number, Account.balance, Account.deleted, Account.time_deposit, User.first_name, User.last_name).join(User, attr='user').execute() return render_template('account/index.html', accounts=accounts)
def inquiry(): form = InquiryForm(request.form) account = None if form.validate_on_submit(): account = Account.select( User.first_name, User.last_name, Account.balance, ).join(User, attr='user').where( (Account.account_number == form.account_number.data) ).get() return render_template('admin/inquiry.html', form=form, account=account)