Пример #1
0
def deposite(acc_id):
    form = DepositeForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            amt = form.amt.data
            account = Account.query.filter_by(ws_acc_id=acc_id).first()
            x = int(account.ws_acct_balance)
            account.ws_acct_balance = x + int(amt)
            db.session.commit()
            flash("Amount deposited successfully", "success")

            transaction = Transaction(ws_acc_id=account.ws_acc_id,
                                      ws_cust_id=account.ws_cust_id,
                                      ws_amt=amt,
                                      ws_acct_type=account.ws_acct_type,
                                      ws_src_typ=None,
                                      ws_tgt_typ=None,
                                      cr_or_db='Credit')
            transaction.ws_trxn_date = datetime.now()
            transaction.description = '' + str(amt) + ' credited in ' + str(
                account.ws_acc_id) + ' account'
            db.session.add(transaction)
            db.session.commit()

            return render_template("deposite.html",
                                   account=account,
                                   old_balance=x,
                                   get_accounts=True)

    return render_template("deposite.html",
                           title='Deposite Amount',
                           form=form,
                           get_accounts=True)
Пример #2
0
def withdraw(acc_id):
    form = WithdrawForm()
    if request.method == 'POST':
        if form.validate_on_submit:
            amt = form.amt.data
            account = Account.query.filter_by(ws_acc_id=acc_id).first()
            x = int(account.ws_acct_balance)
            if (x < int(amt)):
                flash("Your Balance is not sufficient to withdraw !", "danger")
            else:
                account.ws_acct_balance = x - int(amt)
                db.session.commit()
                flash("Amount withdrawed successfully .", "success")

                transaction = Transaction(ws_acc_id=account.ws_acc_id,
                                          ws_cust_id=account.ws_cust_id,
                                          ws_amt=amt,
                                          ws_acct_type=account.ws_acct_type,
                                          ws_src_typ=None,
                                          ws_tgt_typ=None,
                                          cr_or_db='Debit')
                transaction.ws_trxn_date = datetime.now()
                transaction.description = '' + str(
                    amt) + ' debited from ' + str(
                        account.ws_acc_id) + ' account'
                db.session.add(transaction)
                db.session.commit()

                return render_template("withdraw.html",
                                       account=account,
                                       old_balance=x,
                                       get_accounts=True)

    return render_template("withdraw.html", title='Withdraw Amount', form=form)
Пример #3
0
    def post(self):
        trans = Transaction(id=self.request.get("trans_code"))
        trans.trans_code = self.request.get("trans_code")

        sender = User.get_by_id(self.request.get("sender_code"))
        trans.sender = sender.key.urlsafe()
        
        receiver = User.get_by_id(self.request.get("receiver_code"))
        trans.receiver = receiver.key.urlsafe()

        trans.description = self.request.get("description")
        logging.critical(self.request.get("eda"))
        date = datetime.datetime.strptime(self.request.get("eda"), '%m/%d/%Y')
        logging.critical(date)
        trans.eda = date
        p_code = ""
        r_code = ""
        while True:
            p_code = parser_code()
            parcel = P.get_by_id(p_code)    
            if not parcel:
                break;

        while True:
            r_code = receiver_code()
            receiver = R.get_by_id(r_code)
            if not receiver:
                break;

        logging.critical(p_code)
        logging.critical(r_code)

        trans.parser_code = hash_code(p_code, "PARSER")
        trans.receiver_code = hash_code(r_code, "RECEIVER")

        trans.put()

        """ save transaction for PARSEL code """
        p = P(id=p_code)
        p.codes = p_code
        p.trans_key = trans.key.urlsafe()
        p.put()
        """ ---------------------------------- """

        """ save transaction for RECEIVER code """
        r = R(id=r_code)
        r.codes = r_code
        r.trans_key = trans.key.urlsafe()
        r.put()
        """ ---------------------------------- """

        self.redirect(self.uri_for('www-login', success="Added!."))
Пример #4
0
def dummy_transaction(request):
    transaction = Transaction()
    transaction.user_id = 0
    transaction.bank_id = 0
    transaction.category_id = 0
    transaction.description = 'test'
    transaction.amount = 1337.37
    transaction.date = datetime.now()

    def teardown():
        pass # db_session.delete(transaction)  # transaction not even added to db at first

    request.addfinalizer(teardown)
    return transaction
Пример #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)