def setUp(self):
        context = {}
        context['TransactionRepository'] = None  # FakeTransactionRepository
        context['InstrumentRepository'] = FakeInstrumentRepository()
        self.context = context

        self.transactions = [
            Transaction(1, 1, 1, 'BUY', 50, 116, datetime(2017, 1, 1)),
            Transaction(2, 1, 1, 'BUY', 50, 120, datetime(2017, 1, 15)),
            Transaction(3, 1, 1, 'SELL', 80, 128, datetime(2017, 2, 1)),
            Transaction(4, 2, 1, 'BUY', 50, 800, datetime(2017, 2, 1)),
            Transaction(5, 2, 1, 'BUY', 10, 810, datetime(2017, 2, 7))
        ]
示例#2
0
def withdraw_amount():
    if session.get('userId') and session.get('roleId')=="2222":
        account=Account.objects(ws_acct_id=request.form["acct_id"]).first()
        # return account["ws_acct_type"]
        if not request.form["withdraw_amount"].isnumeric():
            flash("Please enter only digits","danger")
            return render_template('view_withdraw.html',account=account)
        withdraw_amount=int(request.form["withdraw_amount"])
        if(account["ws_acct_balance"]<int(withdraw_amount)):
            flash("You dont have enough balance to withdraw given amount","danger")
            return render_template('view_withdraw.html',account=account)
        else:
            account.ws_acct_balance=account.ws_acct_balance-withdraw_amount
            ws_cust_id=account.ws_cust_id
            ws_acct_id=account.ws_acct_id
            ws_transaction_id=generate_Transaction_Id()
            ws_description='withdraw'
            ws_amount=withdraw_amount
            x = datetime.now()
            d=x.strftime("%x")
            y = datetime.now()
            t=y.strftime("%X")
            dt = d + " " + t 
            ws_trxn_date=datetime.strptime(dt,'%m/%d/%y %H:%M:%S')
            Transaction(ws_cust_id=ws_cust_id,ws_acct_id=ws_acct_id,ws_transaction_id=ws_transaction_id,ws_description=ws_description,ws_amount=ws_amount,ws_trxn_date=ws_trxn_date).save()
            account.save()
            flash("Amount withdrawn successfully","success")
            return redirect('/view_single/'+request.form["acct_id"])
        # return render_template('single_account_details.html',account = account)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
示例#3
0
def add_value():
    req_data = request.get_json()

    cardNumber = req_data['cardNumber']
    amount = req_data['amount']
    amount_in_decimal = Decimal(amount.replace(',', '.'))
    card = Card.query.filter_by(number=cardNumber).first()

    error = None
    status = None

    if card is not None:
        student_id = card.owner_id
        card_owner = User.query.filter_by(id=student_id).first()
        if card_owner is None:
            status = 'Declined'
            error = 'Card not associated to any user'
        else:
            card_owner.balance = card_owner.balance + amount_in_decimal
            redeem_txn = Transaction(card_num=card.number,
                                     type='EARN',
                                     amount=amount_in_decimal,
                                     status='APPROVED')
            db.session.add(redeem_txn)
            db.session.commit()
            status = 'Approved'
    else:
        error = 'Card not found'
        status = 'Declined'

    return jsonify(status=status, error=error)
示例#4
0
def transferMoney(amount, cust_id, from_acc, to_acc):
    fromAccount = Account.query.filter_by(cust_id=cust_id,
                                          acc_type=from_acc).first()
    print(fromAccount)
    toAccount = Account.query.filter_by(cust_id=cust_id,
                                        acc_type=to_acc).first()
    print(toAccount)
    if fromAccount == None or toAccount == None:
        return "Failure"
    else:
        if fromAccount.acc_balance - amount < 0:
            return "Failure"
        else:
            num_transactions = len(Transaction.query.all())
            fromAccount.acc_balance -= amount
            toAccount.acc_balance += amount
            db.session.commit()
            transaction = Transaction(transaction_id=num_transactions + 1,
                                      transaction_amount=amount,
                                      from_acc=from_acc,
                                      to_acc=to_acc,
                                      action="Transfer",
                                      cust_id=fromAccount.cust_id)
            db.session.add(transaction)
            db.session.commit()
            return "Success"
示例#5
0
def view_account_statement_date():
    if session.get('userId') and session.get('roleId')=="2222":
        acct_id=request.form.get('ws_acct_id')
        start_date=request.form.get('start_date')
        start_date=datetime.strptime(start_date,'%Y-%m-%d')
        start_date1=dateutil.parser.parse(str(start_date)).date()
        end_date=request.form.get('end_date')
        end_date=datetime.strptime(end_date,'%Y-%m-%d')
        end_date1=dateutil.parser.parse(str(end_date)).date()

        print(start_date)
        print('from form')
        print(type(start_date))
        print(end_date)
        print('from form')
        print(type(end_date))
        
        data=[]
        Transactions=Transaction.objects(ws_acct_id=acct_id)
        for x in Transactions:
            print(x.ws_trxn_date)
            print(type(x.ws_trxn_date))
            if(x.ws_trxn_date >= start_date1 and x.ws_trxn_date <= end_date1):
                print('in')
                data.append(x)
        return render_template('view_account_statement.html',Transactions=data,ws_acct_id=acct_id,start_date=start_date1,end_date=end_date1)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")   
示例#6
0
文件: routes.py 项目: vrushang98/RBMS
def deposit_amount():
    if session.get('userId') and session.get('roleId') == "2222":
        print("inside acct delete", request.form["acct_id"])
        account = Account.objects(ws_acct_id=request.form["acct_id"]).first()

        if not request.form["deposit_amount"].isnumeric():
            flash("Please enter only digits", "danger")
            return render_template('view_deposit.html', account=account)
        print(type(request.form["deposit_amount"]))
        deposit_amount = int(request.form["deposit_amount"])
        account.ws_acct_balance = account.ws_acct_balance + deposit_amount
        ws_cust_id = account.ws_cust_id
        ws_acct_id = account.ws_acct_id
        ws_transaction_id = generate_Transaction_Id()
        ws_description = 'Deposit'
        ws_amount = deposit_amount
        x = datetime.now()
        d = x.strftime("%x")
        y = datetime.now()
        t = y.strftime("%X")
        dt = d + " " + t
        ws_trxn_date = datetime.strptime(dt, '%m/%d/%y %H:%M:%S')
        Transaction(ws_cust_id=ws_cust_id,
                    ws_acct_id=ws_acct_id,
                    ws_transaction_id=ws_transaction_id,
                    ws_description=ws_description,
                    ws_amount=ws_amount,
                    ws_trxn_date=ws_trxn_date).save()
        account.save()
        flash("Amount deposited successfully", "success")
        return redirect('/view_single/' + request.form["acct_id"])

    else:
        flash("Sorry You are not authorised to access this page", "danger")
        return redirect("/")
示例#7
0
def generate_Transaction_Id():
    st="50"
    num2=random.randint(1000000,9999999)
    transaction_id=int(st+str(num2))
    transaction=Transaction.objects(ws_transaction_id=transaction_id).first()
    if transaction:
        generate_Transaction_Id()
    return str(transaction_id)
    async def process_transaction(self, transaction: Transaction,
                                  bot: Bot) -> Transaction:
        document = await Billing.get_document(transaction=transaction)
        user = document.user
        if not transaction.processed_at:
            transaction.processed_at = datetime.datetime.now()
            try:
                document.status = BaseDocument.Status.Processed
                await Billing._change_user_balance(user=user,
                                                   amount=transaction.amount,
                                                   tr_type=transaction.tr_type)
                # make blockcypher payment
                if transaction.tr_type == Transaction.Types.credit:
                    try:
                        btc_worker = BlockcypherWorker(config=self.config)
                        tr_hash = await btc_worker.send_money(
                            to_address=transaction.address_to,
                            amount=await
                            get_satoshis_from_btc(btc_count=transaction.amount
                                                  ))
                        transaction.tr_hash = tr_hash
                        await objects.update(transaction)
                        link = 'https://live.blockcypher.com/btc/tx/{tr_hash}'.format(
                            tr_hash=tr_hash)
                        text = 'User <b>{user}</b> withdraw <code>{amount}</code> <b>BTC</b>\n{link}'.format(
                            user=user, amount=transaction.amount, link=link)
                        await bot.send_message(chat_id=await get_root_user(),
                                               text=text,
                                               parse_mode='HTML',
                                               disable_web_page_preview=True)
                    except Exception as send_money_error:
                        print_tb(send_money_error)

            except NotEnoughFunds as nef:
                print_tb(nef)
                raise NotEnoughFunds
            except Exception as e:
                print_tb(e)
                raise TrxProcessFailed(message=e)
        else:
            raise TrxProcessFailed(message='Transaction was already processed')
        await objects.update(user)
        await objects.update(transaction)
        await objects.update(document)
        return transaction
示例#9
0
 def setUp(self):
     db.create_all()
     test_account = Accounts(account_name="Barclays",cust_name="Rexx", balance=2000 )
     test_transaction = Transaction(transaction="Initial Balance", transaction_amount="2000", accounts=test_account )
     db.session.add(test_account)
     db.session.add(test_transaction)
     db.session.commit()
     app.config['TESTING'] = True
     app.config['WTF_CSRF_ENABLED'] = False
示例#10
0
def view_account_statement_number():
    if session.get('userId') and session.get('roleId')=="2222":
        acct_id=request.form.get('ws_acct_id')
        number= request.form.get('number_of_Transactions')
        Transactions=Transaction.objects(ws_acct_id=acct_id)
        tra=Transactions.order_by('-ws_trxn_date').limit(int(number))
        return render_template('view_account_statement.html',Transactions=tra,ws_acct_id=acct_id,records=number)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
示例#11
0
def new_transaction():
    form = TransactionForm()
    if form.validate_on_submit():
        transaction = Transaction(content=form.content.data,
                                  amount_paid=form.amount_paid.data,
                                  amount_received=form.amount_received.data,
                                  creator=current_user)
        db.session.add(transaction)
        db.session.commit()
        flash('Your transaction has been added', 'success')
        return redirect(
            url_for('users.user_transactions', username=current_user.username))
    return render_template('new_transaction.html',
                           title="New Transaction",
                           form=form,
                           legend="New Transaction")
示例#12
0
def depositMoney(depositAmount, acc_no=None, cust_id=None, acc_type='S'):
    account = searchAccount(acc_no=acc_no, cust_id=cust_id, acc_type=acc_type)
    if account != None:
        account.acc_balance += depositAmount
        db.session.commit()
        num_transactions = len(Transaction.query.all())
        transaction = Transaction(transaction_id=num_transactions + 1,
                                  transaction_amount=depositAmount,
                                  from_acc=acc_type,
                                  to_acc=acc_type,
                                  action="Deposit",
                                  cust_id=account.cust_id)
        db.session.add(transaction)
        db.session.commit()
        return "Success"
    else:
        return "Failure"
示例#13
0
def addAccount():
    form = HomeForm()
    if request.method == "POST":
        if form.validate_on_submit():
            new_account = Accounts(account_name=form.account.data,
                                   cust_name=form.customer.data,
                                   balance=form.balance.data)
            new_transaction = Transaction(transaction="Initial Balance",
                                          transaction_amount=form.balance.data,
                                          accounts=new_account)
            db.session.add(new_account)
            db.session.add(new_transaction)
            db.session.commit()
            return redirect(url_for("customer_home"))
    return render_template("add_account.html",
                           title="Add a new Account",
                           form=form)
示例#14
0
def deposit(account_id):
    form = TransactionForm()
    account = Accounts.query.filter_by(id=account_id).first()

    if request.method == "POST":
        if form.validate_on_submit():
            deposit = Transaction(
                transaction="Deposit : " + form.transaction.data,
                transaction_amount=form.transaction_amount.data,
                accounts=account)
            db.session.add(deposit)
            account.balance = account.balance + form.transaction_amount.data
            db.session.commit()
            return redirect(url_for("customer_home"))
    return render_template("deposit.html",
                           form=form,
                           title="Add Deposit",
                           account=account)
示例#15
0
def withdrawMoney(withdrawAmount, acc_no=None, cust_id=None, acc_type='S'):
    account = searchAccount(acc_no=acc_no, cust_id=cust_id, acc_type=acc_type)
    if account != None:
        if account.acc_balance - withdrawAmount < 1000:
            return "Failure"
        else:
            account.acc_balance -= withdrawAmount
            db.session.commit()
            num_transactions = len(Transaction.query.all())
            transaction = Transaction(transaction_id=num_transactions + 1,
                                      transaction_amount=withdrawAmount,
                                      from_acc=acc_type,
                                      to_acc=acc_type,
                                      action="Withdraw",
                                      cust_id=account.cust_id)
            db.session.add(transaction)
            db.session.commit()
            return "Success"
    else:
        return "Failure"
示例#16
0
def transaction():
    if not session.get('username'):
        return redirect(url_for("login"))
    transaction_type = request.form.get("transaction_type")
    currency_symbol = request.form.get("currency_symbol")
    currency_value = request.form.get("USD")
    amount = request.form.get("amount")

    user_id = session['user_id']

    if transaction_type:
        value = float(currency_value) * float(amount)
        transaction_id = Transaction.objects.count()
        transaction_id += 1
        Transaction(transaction_id=transaction_id,
                    user_id=user_id,
                    transaction_type=transaction_type,
                    currency_symbol=currency_symbol,
                    amount=amount,
                    value=value,
                    date=datetime.now).save()
        flash(f"Transaction added succesfully", category="success")

    transactions = list(
        Transaction.objects.aggregate(*[{
            '$match': {
                'user_id': session["user_id"]
            }
        }, {
            '$sort': {
                'date': 1
            }
        }]))

    return render_template("transaction.html",
                           transactions=transactions,
                           filterValue="all",
                           transaction=True)
示例#17
0
 def setUp(self):
     print("--------------------------NEXT-TEST----------------------------------------------")
     chrome_options = Options()
     chrome_options.binary_location = "/usr/bin/chromium-browser"
     chrome_options.add_argument("--headless")
     #chrome_options.add_argument('--no-sandbox')
     #chrome_options.add_argument('--disable-dev-shm-usage')
     self.driver = webdriver.Chrome(
         executable_path="/home/o_orekoya/chromedriver", 
         chrome_options=chrome_options
         )
     self.driver.get("http://localhost:5000")
     
     db.session.commit()
     db.drop_all()
     db.create_all()
     
     test_account = Accounts(account_name="Barclays",cust_name="Rexx", balance=2000 )
     test_transaction = Transaction(transaction="Buy grapes", transaction_amount="20", accounts=test_account )
     
     db.session.add(test_account)
     db.session.add(test_transaction)
     db.session.commit()
示例#18
0
def transfer_amount():
    if session.get('userId') and session.get('roleId')=="2222":
        form = TransferForm()
        print(form.ws_source_id.data)
        # if form.validate_on_submit():
        #     print("validate")    
        # else:
        #     print(" not validate")    
        if request.method=="POST":
            
            if form.ws_source_id.data==form.ws_target_id.data:
                flash("Source Account and Target account cannot be same","danger")
                return redirect('/account_search')
            else:
                cust_id=form.ws_cust_id.data
                print("cust_id",form.ws_cust_id.data)
                source_id=form.ws_source_id.data
                target_id=form.ws_target_id.data
                transfer_amount=form.ws_transfer_amount.data
                source_account=Account.objects(ws_acct_id=source_id).first()
                old_source=source_account.ws_acct_balance
                if source_account.ws_acct_balance<transfer_amount:
                    flash("Sorry you dont have enough balance in source account to transfer","danger")
                    accounts=Account.objects(ws_cust_id=cust_id).all()
                    acct_id = []
                    # accounts[0]['ws_acct_type']
                    for account in accounts:
                        acct_id.append((account.ws_acct_id,str(account.ws_acct_id)))
                    print(acct_id)
                    form.ws_cust_id.data=cust_id
                    form.ws_source_id.choices = acct_id
                    # form.ws_source_type.data=accounts[0]['ws_acct_type']
                    
                    form.ws_target_id.choices = acct_id
                    # form.ws_target_type.data=accounts[0]['ws_acct_type']
                    return render_template("view_transfer.html",form=form)
                else:
                    
                    source_account.ws_acct_balance=source_account.ws_acct_balance-transfer_amount
                    new_source=source_account.ws_acct_balance
                    source_account.save()
                    

                    target_account=Account.objects(ws_acct_id=target_id).first()
                    old_target=target_account.ws_acct_balance
                    target_account.ws_acct_balance=target_account.ws_acct_balance+transfer_amount
                    new_target=target_account.ws_acct_balance
                    target_account.save()
                    x = datetime.now()
                    d=x.strftime("%x")
                    y = datetime.now()
                    t=y.strftime("%X")
                    dt = d + " " + t 
                    ws_trxn_date=datetime.strptime(dt,'%m/%d/%y %H:%M:%S')
                    Transaction(ws_cust_id=source_account.ws_cust_id,ws_acct_id=source_id,ws_transaction_id=generate_Transaction_Id(),ws_description="Transfer",ws_amount=transfer_amount,ws_trxn_date=ws_trxn_date).save()

                    flash("Transfer made successfully","success")
                    return redirect(url_for("transfer_details",source_id=source_id,target_id=target_id,old_source=old_source,new_source=new_source,old_target=old_target,new_target=new_target))
                
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
示例#19
0
 def test_get_transactions_by_account_id(self):
     self.assertTrue(Transaction.get_transactions(1))