def transfer(): data = request.json payer = get_user() if payer.is_organisation == True: return jsonify({ 'error': True, 'message': 'Organisations Cannot Donate, Please Create a Personal Account' }), 403 payer_bank = BankAccount.get(BankAccount.user == payer) user = User.get(uid=data["receiver_uid"]) receiver_bank = BankAccount.get(user=user) transaction = Transaction( payer_bank=payer_bank, receiver_bank=receiver_bank, amount=data["amount"], post_ident=Post.get(Post.uid == data["post_uid"])) transaction.save() payer_bank.balance = payer_bank.balance - data["amount"] receiver_bank.balance = receiver_bank.balance + data["amount"] payer_bank.save() receiver_bank.save() if payer.is_organisation: label = "income" trans = Transaction.select().where( Transaction.receiver_bank == receiver_bank) else: label = "expenses" trans = Transaction.select().where( Transaction.payer_bank == payer_bank) result = {} result["balance"] = payer_bank.balance trans_dicts = [] for t in trans: trans_dicts.append(t.to_dict) result[label] = trans_dicts return jsonify({"message": "Transaction Success", "payload": result})
def fund(): data = request.json user = get_user() bank_acc = BankAccount.get(BankAccount.user == user) bank_acc.balance += data["amount"] bank_acc.save() return jsonify({"message": "Funds Added. Go Pay Those Puppers!"})
def new_account(): form = BankAccountForm() if form.validate_on_submit(): account = BankAccount(account_name=form.account_name.data, account_currency=form.account_currency.data, cash_amount=float(form.start_amount.data)) db.session.add(account) db.session.commit() t = Thread(target=raise_saving_accounts, args=(account.id,)) t.start() return redirect(url_for('profile')) return render_template('new_bank_account.html', form=form)
def register(): data = request.json password = data.pop("password") """ try: customer_id, account_id = create_account({ "title" : data["title"], "name" : data["name"], "last_name" : "", "dob" : data["dob"], "nationality" : data["nationality"], "email" : data["email"] }) except: pass # return jsonify({"message" : "EEEEEEE"}), 503 """ try: user = User(**data) except: return jsonify({'error':True, 'message': 'bad request'}), 400 user.set_password(password) user.save() starting_balance = 200 if (data['is_organisation']): starting_balance = 0 bank_acc = BankAccount(user=user, balance=starting_balance) bank_acc.save() sesh = Session.create(user=user) sesh.save() session['session_token'] = sesh.token return {'error': False, 'message':'User successfully created!', 'data': user.to_dict}, 201
def get_bankaccts(): # SELECT: # SELECT * FROM BankAccount NATURAL JOIN Bank NATURAL Branch; bankaccts = BankAccount.query.all() if len(bankaccts) == 0: # POPULATE # INSERT INTO BankAccount VALUES # (123756789122421,"Bank of the Philippine Islands", "BPI UP Town Center"), # (341256989113453,"Bank of the Philippine Islands", "BPI Loyola-Katipunan"), # (563412089153456,"Banco de Oro", "BDO Katipunan"), # (783456389121450,"Metrobank", "Metrobank Katipunan"), # (903456189125451,"Metrobank", "Metrobank Blue Ridge"); acctNos = [123756789122421,341256989113453,563412089153456,783456389121450,903456189125451] bankNames = [ "Bank of the Philippine Islands", "Bank of the Philippine Islands", "Banco de Oro", "Metrobank", "Metrobank" ] branchNames = [ "BPI UP Town Center", "BPI Loyola-Katipunan", "BDO Katipunan", "Metrobank Katipunan", "Metrobank Blue Ridge" ] for i in range(0, len(acctNos)): bankacct = BankAccount( bankAcctNo=acctNos[i], bankName=bankNames[i], bankBranchName=branchNames[i] ) db.session.add(bankacct) db.session.commit() return get_bankaccts() else: return_data = [] for bankacct in bankaccts: return_data.append({ "bankAcctNo": str(bankacct.bankAcctNo), "bankName": bankacct.bankName, "bankMainAddress": bankacct.bank.bankMainAddress, "bankBranchName": bankacct.bankBranchName, "bankBranchAddress": bankacct.branch.bankBranchAddress }) return jsonify(return_data)
def create_bankacct(): # INSERT: # INSERT INTO BankAccount VALUES (<BankAcctNo>, <bankName>, <bankBranchName>); post_data = request.get_json() bankAcctNo = post_data.get('bankAcctNo') bankName = post_data.get('bankName') bankBranchName = post_data.get('bankBranchName') bank = Bank.query.get(bankName) branch = Branch.query.get(bankBranchName) bankacct = BankAccount( bankAcctNo=bankAcctNo, bankName=bankName, bankBranchName=bankBranchName ) db.session.add(bankacct) bank.bankAccounts.append(bankacct) branch.bankAccounts.append(bankacct) db.session.commit() return jsonify({'msg': "SUCCESS"})
def get_data(): user = get_user() bank_acc = BankAccount.get(BankAccount.user == user) if user.is_organisation: label = "income" trans = Transaction.select().where( Transaction.receiver_bank == bank_acc) else: label = "expenses" trans = Transaction.select().where(Transaction.payer_bank == bank_acc) result = {} result["balance"] = bank_acc.balance trans_dicts = [] for t in trans: trans_dicts.append(t.to_dict) result[label] = trans_dicts return jsonify(result)