Beispiel #1
0
def trans(user_id, node_id):

    URL = baseURL + '/users'
    response = requests.get(URL, headers=headers).json()
    users = response['users']

    form = TransferForm()
    legal_names = [(user['_id'], user['legal_names'][0]) for user in users]

    form.to.choices = legal_names
    # form.sender.choices = [(node_id,node_id)]

    if form.validate_on_submit():
        POSTURL = baseURL + '/users/' + user_id + '/nodes/' + node_id + '/trans'
        to = {'type': form.network.data, 'id': str(form.to.data)}
        amount = {'amount': form.amount.data, 'currency': form.currency.data}
        extra = {'ip': ip_address}
        headers["Content-Type"] = "application/json"
        resp = requests.post(POSTURL,
                             headers=headers,
                             json={
                                 'to': to,
                                 'amount': amount,
                                 'extra': extra
                             }).json()

        return redirect(url_for('users'))

    URL = baseURL + '/users/' + user_id + '/nodes/' + node_id + '/trans'
    resp = requests.get(URL, headers=headers).json()
    trans = resp['trans']

    return render_template('trans.html', form=form, trans=trans)
Beispiel #2
0
def edit_transfer(transfer_id):
    transfer = Transfer.query.get(transfer_id)
    edit_form = TransferForm(paidfrom=transfer.paidfrom,
                             paidto=transfer.paidto,
                             amount=transfer.amount,
                             frequency=transfer.frequency,
                             nextduedate=transfer.nextduedate)
    if edit_form.validate_on_submit():
        transfer.paidfrom = edit_form.paidfrom.data,
        transfer.paidto = edit_form.paidto.data,
        transfer.amount = edit_form.amount.data,
        transfer.frequency = edit_form.frequency.data,
        transfer.nextduedate = edit_form.nextduedate.data
        db.session.commit()
        return redirect(url_for("view_transfers"))
    return render_template("add-transfer.html", form=edit_form)
def transfer(puppy_id):
    if 'username' not in login_session:
        flash ("Please login for more complete access to our puppies.")
        return redirect ('/puppies')
    puppy = session.query(Puppy).filter(Puppy.id==puppy_id).one()
    if login_session['admin'] < 2 and puppy.user_id != login_session['user_id']:
        flash ("You do not have the authority to access that page.")
        return redirect ('/puppies')
    form = TransferForm()
    shelters = session.query(Shelter).filter(Shelter.occupancy<Shelter.capacity\
        , Shelter.id != puppy.shelter_id).all()
    if form.validate_on_submit():
        session.query(Puppy).filter(Puppy.id==puppy_id).update({'shelter_id' :\
            form.newShelter.data})
        session.commit()
        flash("You successfully transferred your puppy.")
        return redirect(url_for('shelters'))
    else:
        return render_template ('transfer.html', form=form, puppy=puppy,\
            shelters=shelters)
Beispiel #4
0
def add_transfer():
    form = TransferForm()
    banks = Bank.query.filter_by(bmID=current_user.bmID)
    form.accountfrom.choices = [(bank.bankID,
                                 bank.bankname + " - " + bank.accounttype)
                                for bank in banks]
    form.accountto.choices = [(bank.bankID,
                               bank.bankname + " - " + bank.accounttype)
                              for bank in banks]
    if form.validate_on_submit():
        new_transfer = Transfer(bmID=current_user.bmID,
                                accountfrom=form.accountfrom.data,
                                accountto=form.accountto.data,
                                amount=form.amount.data,
                                frequency=form.frequency.data,
                                nextduedate=form.nextduedate.data)
        db.session.add(new_transfer)
        db.session.commit()
        return redirect(url_for('view_transfers'))
    return render_template("add-transfer.html", form=form)
Beispiel #5
0
def transfer():
    form = TransferForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            src_acc_id = form.src_acc_id.data
            tar_acc_id = form.tar_acc_id.data
            amount = form.amount.data

            src_acc = Account.query.filter_by(ws_acc_id=src_acc_id).first()
            tar_acc = Account.query.filter_by(ws_acc_id=tar_acc_id).first()

            if src_acc and tar_acc:
                x = int(src_acc.ws_acct_balance)
                y = int(tar_acc.ws_acct_balance)
                z = int(amount)
                if x < z:
                    flash("Transfer not allowed, please choose smaller amount",
                          "danger")
                else:
                    src_acc.ws_acct_balance = x - z
                    src_acc.acct_lasttrdate = datetime.now()
                    tar_acc.ws_acct_balance = y + z
                    tar_acc.acct_lasttrdate = datetime.now()
                    db.session.commit()
                    flash("Amount transfer completed successfully", "success")

                    #for sourse account
                    transaction = Transaction(
                        ws_acc_id=src_acc.ws_acc_id,
                        ws_cust_id=src_acc.ws_cust_id,
                        ws_amt=amount,
                        ws_acct_type=src_acc.ws_acct_type,
                        ws_src_typ=src_acc.ws_acct_type,
                        ws_tgt_typ=tar_acc.ws_acct_type,
                        cr_or_db='Debit')
                    transaction.ws_trxn_date = datetime.now()
                    transaction.ws_src_typ = src_acc.ws_acct_type
                    transaction.ws_tgt_typ = tar_acc.ws_acct_type
                    transaction.description = '' + amount + ' transfered from ' + str(
                        src_acc.ws_acc_id) + ' to ' + str(tar_acc.ws_acc_id)
                    db.session.add(transaction)
                    db.session.commit()
                    #for destination
                    transaction = Transaction(
                        ws_acc_id=tar_acc.ws_acc_id,
                        ws_cust_id=tar_acc.ws_cust_id,
                        ws_amt=amount,
                        ws_acct_type=tar_acc.ws_acct_type,
                        ws_src_typ=src_acc.ws_acct_type,
                        ws_tgt_typ=tar_acc.ws_acct_type,
                        cr_or_db='Credit')
                    transaction.ws_trxn_date = datetime.now()
                    transaction.ws_src_typ = src_acc.ws_acct_type
                    transaction.ws_tgt_typ = tar_acc.ws_acct_type
                    transaction.description = '' + amount + ' transfered from ' + str(
                        src_acc.ws_acc_id) + ' to ' + str(tar_acc.ws_acc_id)
                    db.session.add(transaction)
                    db.session.commit()

                    return render_template('transfer.html',
                                           src_acc=src_acc,
                                           tar_acc=tar_acc,
                                           title='Transfer',
                                           x=x,
                                           y=y,
                                           get_accounts=True)
            elif not src_acc:
                flash("Source account not found !", "danger")
            elif not tar_acc:
                flash("Target account not found !", "danger")
            else:
                flash("Something went wrong ....", 'danger')

    return render_template("transfer.html",
                           form=form,
                           title="Transfer",
                           get_accounts=True)
Beispiel #6
0
def bankTransfer():

    db = get_db()
    user_id = g.user
    balance = round(g.balance, 2)
    form = TransferForm()

    if form.validate_on_submit():
        recipient = form.recipient.data
        amount = form.amount.data
        db = get_db()
        receiving = db.execute(
            ''' SELECT * FROM users
                            WHERE user_id = ?;''', (recipient, )).fetchone()
        sender = db.execute(
            ''' SELECT * FROM users
                            WHERE user_id = ?;''',
            (user_id, )).fetchone()["balance"]

        if receiving is None:
            form.recipient.errors.append("Person does not exist!")

        elif receiving is not None:
            if recipient != user_id:
                receiver = receiving["balance"]
                receiver_name = str(receiving["user_id"])

                if balance >= amount:
                    #Enough in account
                    if amount > 0:
                        currentTransaction = datetime.datetime.now()
                        db.execute(
                            '''UPDATE users
                                    SET balance = ?
                                    WHERE user_id = ?;''',
                            (sender - float(amount), user_id))
                        db.commit()
                        db.execute(
                            '''UPDATE users
                                    SET balance = ?
                                    WHERE user_id = ?;''',
                            (receiver + float(amount), recipient))
                        db.commit()
                        db.execute(
                            '''INSERT INTO transactions(sender, receiver, amount, time_of_transaction)
                                    VALUES(?, ?, ?, ?);''',
                            (user_id, receiver_name, float(amount),
                             currentTransaction))
                        db.commit()
                        form.recipient.errors.append(
                            "Sent Waluigi Dollars successfully.")
                        eventLogger(user_id, "sent Waluigi Dollars to someone")
                        currentBal = db.execute(
                            ''' SELECT * FROM users
                                WHERE user_id = ?;''',
                            (user_id, )).fetchone()["balance"]
                        session["balance"] = currentBal
                    else:
                        form.recipient.errors.append("Nice try...")

                else:
                    form.recipient.errors.append(
                        "Bank said no! Go get a job, loser!")
                    eventLogger(user_id, "failed to send Waluigi Dollars")
            else:
                form.recipient.errors.append("Can't send money to yourself...")
                eventLogger(user_id, "tried to send themselves money")

    if "transactionList" not in session:
        session["transactionList"] = {}

    users = {}
    amount_received = {}
    amount_sent = {}
    time = {}
    db = get_db()
    transactions = db.execute(
        '''SELECT * FROM transactions WHERE sender = ? or receiver = ?;''', (
            user_id,
            user_id,
        )).fetchall()
    session["balance"] = round(session["balance"], 2)
    return render_template("bank.html",
                           form=form,
                           balance=session["balance"],
                           transactions=transactions)