Ejemplo n.º 1
0
def withdraw(aid=False):
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        amount = request.form['amount']
        previous_amount = request.form['ws_acct_balance']
        ws_acct_id = request.form['ws_acct_id']
        ws_acct_balance = int(previous_amount) - int(amount)
        if ws_acct_balance <= 0:
            flash("Withdraw not allowed, please choose smaller amount",
                  "danger")
            url = '/withdraw/' + ws_acct_id
            return redirect(url)
        Account.objects(ws_acct_id=ws_acct_id).update_one(
            ws_acct_balance=ws_acct_balance,
            ws_message='WITHDRAW',
            ws_acct_lasttrdate=datetime.now())
        transactions = Transactions(
            ws_tnsc_id=get_random_alphaNumeric_string(8),
            ws_acct_id=ws_acct_id,
            ws_desc='Withdraw',
            ws_amt=amount,
            ws_trxn_date=datetime.now())
        transactions.save()
        flash("Amount withdrawn successfully", "success")
        url = '/accounts/' + ws_acct_id
        return redirect(url)
    if aid:
        account = Account.objects(ws_acct_id=aid).first()
        return render_template("account_operations/withdraw_money.html",
                               account=account,
                               info=True)
    return render_template("account_operations/withdraw_money.html",
                           info=False)
Ejemplo n.º 2
0
def deposit(aid=False):
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        amount = request.form['amount']
        previous_amount = request.form['ws_acct_balance']
        ws_acct_id = request.form['ws_acct_id']
        ws_acct_balance = int(previous_amount) + int(amount)
        Account.objects(ws_acct_id=ws_acct_id).update_one(
            ws_acct_balance=ws_acct_balance,
            ws_message='DEPOSIT',
            ws_acct_lasttrdate=datetime.now())
        transactions = Transactions(
            ws_tnsc_id=get_random_alphaNumeric_string(8),
            ws_acct_id=ws_acct_id,
            ws_desc='Deposit',
            ws_amt=amount,
            ws_trxn_date=datetime.now())
        transactions.save()
        url = '/accounts/' + ws_acct_id
        flash("Amount deposited successfully", "success")
        return redirect(url)
    if aid:
        account = Account.objects(ws_acct_id=aid).first()
        return render_template("account_operations/deposit.html",
                               account=account,
                               info=True)
    return render_template("account_operations/deposit.html", info=False)
Ejemplo n.º 3
0
def account_search():
    if session.get('userId') and session.get('roleId')=="2222":
        form = Account_Search_Form()
        if(request.method=='POST'):
            ws_acc_id=form.ws_acc_id.data
            print(ws_acc_id)
            ws_cust_id=form.ws_cust_id.data
            if ws_acc_id != None :
                account=Account.objects(ws_acct_id=ws_acc_id).first()
                if account:
                    return render_template('single_account_details.html',account = account)
                else:
                    flash("Invalid Account Id","danger")
            elif ws_cust_id != None :
                print("cust id")
                account=Account.objects(ws_cust_id=ws_cust_id)
                if account:
                    return render_template('account_details.html',account = account)
                else:
                    flash("Invalid Customer Id","danger")
            
            else :
                flash('Enter one of the ID','danger')    
        return render_template('Account_search.html',form=form)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 4
0
def create_account():
    if request.method == "POST":
        customer_id = request.form["customerId"]
        check_cusid = Customer.objects(customer_id=customer_id).first()
        account_id = str(
            int(Account.objects.order_by('-customer_id').first().account_id) +
            2)
        account_type = request.form["account_type"]
        check_type = Account.objects(customer_id=customer_id,
                                     account_type=account_type).first()
        deposit_amount = request.form["depositAmount"]
        if (not check_cusid):
            message = "Customer Id doesnot Exist"
        elif (check_type):
            message = "Customer already has account of specific type"
            account = Account.objects(customer_id=customer_id,
                                      account_type=account_type).first()
            account.account_status = message
            account.save()

        else:
            message = "Account Created Successfully"
            account = Account(customer_id=customer_id,
                              account_id=account_id,
                              account_type=account_type,
                              deposit_amount=deposit_amount,
                              account_status=message).save()
        return render_template("create_account.html", message=message)
    return render_template("create_account.html")
Ejemplo n.º 5
0
def account_status():
    count = Account.objects().count()
    if count == 0:
        flash("Currently No Accounts Created Untill Now", "danger")
        return redirect(url_for(index))
    accounts = Account.objects()
    return render_template("status_detail/account_status.html",
                           accounts=accounts)
Ejemplo n.º 6
0
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("/")
Ejemplo n.º 7
0
def account_delete_search():
    if session.get('userId') and session.get('roleId')=="1111":
        if request.method=="POST":
            form = Account_Delete_Form()
            accounts = Account.objects(ws_cust_id=request.form["cust_id"]).all()
            acc_id = []
            if accounts:
            
                acct_type=accounts[0]['ws_acct_type']
                # accounts[0]['ws_acct_type']

                for account in accounts:
                    acc_id.append((account.ws_acct_id,account.ws_acct_id))
                
                form.ws_acct_id.choices = acc_id
                form.ws_acct_type.data=acct_type
                return render_template('account_delete.html',form=form, accounts =accounts,acc_id=acc_id)
                #form.ws_acct_type.default = form.ws_acc_id.data 
        
            else:
                flash("Invalid Customer Id","danger")
        return render_template("account_delete_search.html")
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 8
0
def account_delete():
    if session.get('userId') and session.get('roleId')=="1111":
        form = Account_Delete_Form()   
        if request.method =='POST' :
            acct_id = form.ws_acct_id.data
            delete_account= Account.objects(ws_acct_id=acct_id).first()
            delete_account_status=Account_Status.objects(ws_acct_id=acct_id).first()
            x = datetime.now()
            d=x.strftime("%x")
            y = datetime.now()
            t=y.strftime("%X")
            dt = d + " " + t 
            if delete_account_status:
                delete_account_status.ws_acct_status='inactive'
                delete_account_status.ws_message='account deleted'
                delete_account_status.ws_acct_lastUdate=datetime.strptime(dt,'%m/%d/%y %H:%M:%S') 
                delete_account_status.save()
            else:
                print(delete_account.ws_cust_id)
                account_status=Account_Status(ws_cust_id=delete_account.ws_cust_id,ws_acct_type=delete_account.ws_acct_type,ws_acct_id=acct_id,ws_acct_status='inactive',ws_message='account deleted',ws_acct_lastUdate=datetime.strptime(dt,'%m/%d/%y %H:%M:%S'))
                account_status.save()
            delete_account.delete()
            flash('your Account is deleted', 'success')
            return render_template('layout.html')
        return render_template('account_delete.html',form=form, accounts =accounts,acc_id=acc_id)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 9
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("/")
Ejemplo n.º 10
0
def accounts(aid):
    print(aid, flush=True)
    if aid:
        accounts = Account.objects(ws_acct_id=aid)
    else:
        return redirect(url_for(index))
    return render_template("account_operations/accounts.html",
                           accounts=accounts)
Ejemplo n.º 11
0
def generate_Account_Id():
    st="30"
    num2=random.randint(1000000,9999999)
    acct_id=int(st+str(num2))
    account=Account.objects(ws_acct_id=acct_id).first()
    if account:
        generate_Account_Id()
    return str(acct_id)
Ejemplo n.º 12
0
def withdraw():
    if session.get('userId') and session.get('roleId')=="2222":
        account=Account.objects(ws_acct_id=request.form["acct_id"]).first()

        return render_template('view_withdraw.html',account=account)
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 13
0
def view_single(id):
    if session.get('userId') and session.get('roleId')=="2222":
        
        account=Account.objects(ws_acct_id=id).first()
        return render_template('single_account_details.html',account = account)
        
    else:
        flash("Sorry You are not authorised to access this page","danger")
        return redirect("/")
Ejemplo n.º 14
0
def index():
    c_count = UserStore.objects(role='CASHIER').count()
    e_count = UserStore.objects(role='EXECUTIVE').count()
    customer_count = Customer.objects().count()
    account_count = Account.objects().count()
    return render_template("home.html",
                           c_count=c_count,
                           e_count=e_count,
                           customer_count=customer_count,
                           account_count=account_count)
Ejemplo n.º 15
0
def search_delete_account():
    if request.method == "POST":
        account_id = request.form["accountid"]

        customer_id = request.form["customerid"]
        check_id = Account.objects(account_id=account_id).first()

        check_cusid = Account.objects(customer_id=customer_id).all()

        if check_id or check_cusid:
            if not check_cusid and not check_id:
                return render_template("search_account.html")
            elif not check_cusid:
                return render_template("delete_account.html", form=check_id)
            else:

                return render_template("delete_account.html",
                                       form_list=check_cusid)
    return render_template("search_account.html")
Ejemplo n.º 16
0
def transfer():
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        print(request.form, flush=True)
        sr_acct_id = request.form['sr_acct_id']
        tr_acct_id = request.form['tr_acct_id']
        if sr_acct_id == tr_acct_id:
            flash("Source and Target cannot be  same !", "danger")
            return redirect('/transfer')
        amount = int(request.form['amount'])
        account1 = Account.objects(ws_acct_id=sr_acct_id).first()
        account2 = Account.objects(ws_acct_id=tr_acct_id).first()
        if account1 and account2:
            if account1.ws_acct_balance >= amount:
                sr_acct_balance = account1.ws_acct_balance - amount
                tr_acct_balance = account2.ws_acct_balance + amount
                Account.objects(ws_acct_id=sr_acct_id).update_one(
                    ws_acct_balance=sr_acct_balance,
                    ws_message='TRANSFER',
                    ws_acct_lasttrdate=datetime.now())
                Account.objects(ws_acct_id=tr_acct_id).update_one(
                    ws_acct_balance=tr_acct_balance,
                    ws_message='TRANSFER',
                    ws_acct_lasttrdate=datetime.now())
                transactions1 = Transactions(
                    ws_tnsc_id=get_random_alphaNumeric_string(8),
                    ws_acct_id=sr_acct_id,
                    ws_desc='Transfer from here',
                    ws_amt=amount,
                    ws_trxn_date=datetime.now(),
                    ws_src_typ=account1.ws_acct_type,
                    ws_tgt_typ=account2.ws_acct_type)
                transactions1.save()
                transactions2 = Transactions(
                    ws_tnsc_id=get_random_alphaNumeric_string(8),
                    ws_acct_id=tr_acct_id,
                    ws_desc='Transfer to here',
                    ws_amt=amount,
                    ws_trxn_date=datetime.now(),
                    ws_src_typ=account1.ws_acct_type,
                    ws_tgt_typ=account2.ws_acct_type)
                transactions2.save()
                flash("Amount transfer completed successfully !", "success")
                return redirect('/transfer')
            else:
                flash("Transfer not allowed, please choose smaller amount !",
                      "danger")
                return redirect('/transfer')
        else:
            if account1:
                flash("Destination Account Doest exists !", "danger")
                return redirect('/transfer')
            else:
                flash("Source Account Doest exists !", "danger")
                return redirect('/transfer')
    return render_template("account_operations/transfer_money.html")
Ejemplo n.º 17
0
def delete_account2():
    if request.method == "POST":
        account_id = request.form["accountid"]
        account_type = request.form["accounttype"]
        account = Account.objects(account_id=account_id,
                                  account_type=account_type).delete()
        if account == 0:
            return render_template(
                "delete_account.html",
                message="AccountId is and Account type is not matching")
        else:
            return render_template("executive.html",
                                   mes="data deleted successfully")

    return render_template("delete_account.html")
Ejemplo n.º 18
0
def delete_account():
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        ws_acct_id = request.form['ws_acct_id']
        ws_acct_type = request.form['ws_acct_type']
        account = Account.objects(
            ws_acct_id=ws_acct_id,
            ws_acct_type=ws_acct_type).update_one(ws_status='DELETED')
        if account == 0:
            flash("No Account  Available with Given Information !", "danger")
        else:
            flash("Account deletion initiated successfully", "success")
        return redirect(url_for('delete_account'))
    return render_template("account_management/delete_account.html")
Ejemplo n.º 19
0
def account_search():
    if request.method == 'POST':
        ws_cust_id = request.form['cid']
        ws_acct_id = request.form['aid']
        if ws_acct_id:
            account = Account.objects(ws_acct_id=ws_acct_id).first()
            if account:
                url = 'accounts/' + ws_acct_id
                return redirect(url)
            else:
                flash("No account exists with given Account Id !", "danger")
        elif ws_cust_id:
            account = Account.objects(ws_cust_id=ws_cust_id).first()
            if account:
                ws_acct_id = account.ws_acct_id
                url = 'accounts/' + ws_acct_id
                return redirect(url)
            else:
                flash("No account exists with given Account Id !", "danger")
        else:
            flash(
                "Search possible only by filling either  Account Id or Customer ID !",
                "danger")
    return render_template("status_detail/account_search.html")
Ejemplo n.º 20
0
def create_account():
    if not session.get('user_id'):
        return redirect(url_for('login'))
    if request.method == 'POST':
        ws_cust_id = request.form['ws_cust_id']
        ws_acct_id = get_random_alphaNumeric_string(9)
        ws_acct_type = request.form['ws_acct_type']
        ws_acct_balance = int(request.form['ws_acct_balance'])
        if ws_acct_balance <= 0:
            flash("Account creation Failed due to negative amount!", "danger")
            return redirect(url_for('create_account'))
        ws_acct_crdate = datetime.now()
        ws_acct_lasttrdate = datetime.now()
        ws_acct_duration = 0
        ws_status = 'CREATED'
        account = Account.objects(ws_cust_id=ws_cust_id,
                                  ws_acct_type=ws_acct_type)
        if account:
            flash(
                "Current User already have this type of account please try other",
                "danger")
            return redirect(url_for('create_account'))
        account = Account(ws_cust_id=ws_cust_id,
                          ws_acct_id=ws_acct_id,
                          ws_acct_type=ws_acct_type,
                          ws_acct_balance=ws_acct_balance,
                          ws_acct_crdate=ws_acct_crdate,
                          ws_message='CREATED',
                          ws_acct_lasttrdate=ws_acct_lasttrdate,
                          ws_acct_duration=ws_acct_duration,
                          ws_status=ws_status)
        account.save()
        transactions = Transactions(
            ws_tnsc_id=get_random_alphaNumeric_string(8),
            ws_acct_id=ws_acct_id,
            ws_desc='Deposit',
            ws_amt=ws_acct_balance,
            ws_trxn_date=datetime.now())
        transactions.save()
        flash("Account creation initiated successfully!", "success")
        return redirect('/accounts/' + ws_acct_id)
    return render_template("account_management/create_account.html")
Ejemplo n.º 21
0
def view_transfer():
    if session.get('userId') and session.get('roleId') == "2222":
        form = TransferForm()
        accounts = Account.objects(ws_cust_id=request.form["cust_id"]).all()
        acct_id = []

        for account in accounts:
            acct_id.append((account.ws_acct_id, str(account.ws_acct_id)))
        print(acct_id)
        form.ws_cust_id.data = request.form["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:
        flash("Sorry You are not authorised to access this page", "danger")
        return redirect("/")
Ejemplo n.º 22
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("/")
Ejemplo n.º 23
0
def delete_account(id):
    if request.method == "POST":
        Account.objects(account_id=id).delete()
        return render_template("executive.html",
                               mes="data deleted successfully")
Ejemplo n.º 24
0
def get_acct_type():
    if session["userId"]:
        print("inside acct delete")
        account=Account.objects(ws_acct_id=request.form["acct_id"]).first()
        return account["ws_acct_type"]
Ejemplo n.º 25
0
def getaccounts(aid):
    accounts = Account.objects(ws_acct_id=aid).first()
    return Response(json.dumps(accounts), mimetype="application/json")
Ejemplo n.º 26
0
def deleteaccount(aid):
    Account.objects(ws_acct_id=aid).update_one(ws_status='DELETED')
    flash("Account Deleted successfully !", "success")
    return redirect(url_for('index'))