예제 #1
0
def trasferAccount(idx=None):

    if not (session.get('login') and session.get('login') == 'Cashier/Teller'):
        flash("Please Login as Cashier/Teller To Perform This Operation",
              'danger')
        return redirect(url_for('login'))

    if idx == None:
        return redirect(url_for('view_all_customers'))
    form = TransferWithin()
    if form.validate_on_submit():
        AccountStatus.objects(acc_cust_id=form.cust_id.data).update(
            acc_message="Money Tranfer within accounts",
            acc_last_update=datetime.now())
        source = AccountStatus.objects.filter(acc_cust_id=form.cust_id.data,
                                              acc_type=form.source.data)
        target = AccountStatus.objects.filter(acc_cust_id=form.cust_id.data,
                                              acc_type=form.target.data)
        trasfer = form.transfer_amount.data
        s_acc = source.first()['acc_deposit'] - trasfer
        t_acc = target.first()['acc_deposit'] + trasfer
        source.update(acc_deposit=s_acc)
        target.update(acc_deposit=t_acc)

        flash("Transfer successfull", "success")
        return redirect(url_for('view_all_customers'))

    cust = CustomerStatus.objects(customer_id=idx).first()
    if not cust:
        flash(f"No Customer of id {idx} Found", "danger")
        return redirect(url_for('view_all_customers'))
    return render_template('trasferAccount.html', c=cust, form=form)
예제 #2
0
def depositWithdrawAccount():

    if not (session.get('login') and session.get('login') == 'Cashier/Teller'):
        flash("Please Login as Cashier/Teller To Perform This Operation",
              'danger')
        return redirect(url_for('index'))

    acc_id = request.form.get("acc_id")
    deposit = request.form.get("DorW") == "Deposit"
    value = request.form.get("Value")

    acc = AccountStatus.objects(acc_id=acc_id).first()
    if not acc:
        flash("Account not found")
        return redirect(url_for('viewAllAccounts'))

    if not value:
        return render_template('depositWithdrawAccount.html',
                               acc=acc,
                               deposit=deposit)
    else:
        if value.isdigit() and int(value) > 0:

            total = acc.acc_deposit
            if deposit:
                total += int(value)
                AccountStatus.objects(acc_id=acc_id).update(
                    acc_deposit=total,
                    acc_message=f"Successfully Deposited {int(value)}",
                    acc_last_update=datetime.now())

                flash(
                    f"Successfull Transaction to account id {acc_id} Added {int(value)} Total Amount Avalible is {total}",
                    "success")
            else:
                total -= int(value)
                if total >= 0:
                    AccountStatus.objects(acc_id=acc_id).update(
                        acc_deposit=total,
                        acc_message=f"Successfully Withdraw {int(value)}",
                        acc_last_update=datetime.now())

                    flash(
                        f"Successfull Transaction to account id {acc_id} Removed {int(value)} Total Amount Avalible is {total}",
                        "success")
                else:
                    flash(
                        "Transaction Failed current Balance is less than Withdraw requested",
                        "danger")
            return redirect(url_for('viewAllAccounts'))
        else:
            flash("Amount cant be negative", "danger")
            return redirect(url_for('viewAllAccounts'))
예제 #3
0
def deleteCustomer():

    if not (session.get('login')
            and session.get('login') == 'Account Executive'):
        flash("Please Login as Account Executive To Perform This Operation",
              'danger')
        return redirect(url_for('indix'))

    cust_id = request.form.get("customer_id")
    cust = CustomerStatus.objects(customer_id=cust_id).first()
    AccountStatus.objects(acc_cust_id=cust_id).update(acc_status="Inactive")
    if cust:
        cust.delete()
        flash("Customer Successfully deleted", "danger")
    else:
        flash("Costomer already deleted", "danger")
    return redirect(url_for('view_all_customers'))
예제 #4
0
def viewAllAccounts(idx=None):

    if not session.get('login'):
        return redirect(url_for('login'))

    if idx == None:
        acc = AccountStatus.objects.all()
    else:
        acc = AccountStatus.objects(acc_cust_id=idx)
    return render_template('viewAllAccounts.html',
                           acc=acc,
                           viewAllAccounts=True,
                           idx=idx)
예제 #5
0
def deleteAccount():

    if not (session.get('login')
            and session.get('login') == 'Account Executive'):
        flash("Please Login as Account Executive To Perform This Operation",
              'danger')
        return redirect(url_for('index'))

    acc_id = request.form.get("acc_id")
    acc = AccountStatus.objects(acc_id=acc_id).first()
    if acc:
        acc.delete()
        flash("Account Successfully deleted", "danger")
    else:
        flash("Account already deleted", "danger")
    return redirect(url_for('viewAllAccounts'))
예제 #6
0
def createAccount():

    if not (session.get('login')
            and session.get('login') == 'Account Executive'):
        flash("Please Login as Account Executive To Perform This Operation",
              'danger')
        return redirect(url_for('index'))

    form = CreateAccount()
    cust_id = False
    if request.method == "GET" and request.args.get("customer_id"):
        cust_id = request.args.get("customer_id")

    if form.validate_on_submit():

        acc_id = 0
        if AccountStatus.objects.count() != 0:
            acc_id = AccountStatus.objects.order_by(
                '-acc_id').first()['acc_id']
        acc_id += 1
        data = {
            "acc_id": acc_id,
            "acc_cust_id": form.acc_cust_id.data,
            "acc_type": form.acc_type.data,
            "acc_deposit": form.acc_deposit.data,
            "acc_status": "Active",
            "acc_message": "Account Creation Successfull",
            "acc_last_update": datetime.now()
        }
        AccountStatus(**data).save()

        flash('Account Created Successfully', 'success')
        # return redirect(url_for('view_all_customers'))
        return redirect(url_for('viewAllAccounts'))

    return render_template('createAccount.html',
                           form=form,
                           createAccount=True,
                           cust_id=cust_id)
예제 #7
0
def searchAccount():

    if not session.get('login'):
        return redirect(url_for('login'))

    cust_id = request.form.get("customer_id")
    acc_id = request.form.get("account_id")
    if cust_id:
        flash("Accounts of Customer ID " + str(cust_id), 'success')
        return redirect(f'/viewAllAccounts/{cust_id}')
    if acc_id:
        acc = AccountStatus.objects(acc_id=acc_id).first()
        if acc:
            flash("Account of ID " + str(acc_id), 'success')
            return render_template('viewAllAccounts.html',
                                   acc=[acc],
                                   viewAllAccounts=True,
                                   idx=False,
                                   single=True)

    flash("No Account found", "danger")
    return redirect(url_for('view_all_customers'))
예제 #8
0
def update_status_account(acc_id, status):
    if (acc_id):
        if status == 'created':
            acc = Account.query.filter_by(ws_acc_id=acc_id).first()
            if acc:
                account_status = AccountStatus(ws_acc_id=acc.ws_acc_id,
                                               ws_cust_id=acc.ws_cust_id,
                                               ws_acct_type=acc.ws_acct_type,
                                               status='Created',
                                               message='Completed')
                account_status.last_updated = datetime.now()
                db.session.add(account_status)
                db.session.commit()

        else:
            account_status = AccountStatus.query.filter_by(
                ws_acc_id=acc_id).first()
            if account_status:
                account_status.status = 'Deleted'
                account_status.message = 'Completed'
                account_status.last_updated = datetime.now()
                db.session.commit()