Exemple #1
0
def update_status_customer(ws_ssn1, status):
    customer = Customer.query.filter_by(ws_ssn=ws_ssn1).first()
    if customer:
        ws_ssn = customer.ws_ssn
        ws_cust_id = customer.ws_cust_id

        if status == 'created':
            cust_status = CustomerStatus(ws_ssn=ws_ssn,
                                         ws_cust_id=ws_cust_id,
                                         status='Created',
                                         message='Completed')
            cust_status.last_updated = datetime.now()
            db.session.add(cust_status)
            db.session.commit()
            db.session.flush()
        elif status == 'updated':
            cust_status = CustomerStatus.query.filter_by(ws_ssn=ws_ssn).first()
            if cust_status:
                cust_status.status = 'Updated'
                cust_status.message = 'Completed'
                cust_status.last_updated = datetime.now()
                db.session.commit()
    else:
        cust_status = CustomerStatus.query.filter_by(ws_ssn=ws_ssn1).first()
        if cust_status:
            cust_status.status = 'Deleted'
            cust_status.message = 'Completed'
            cust_status.last_updated = datetime.now()
            db.session.commit()
Exemple #2
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)
Exemple #3
0
def searchCustomer():

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

    cust_id = request.form.get("customer_id")
    ssn_id = request.form.get("ssn_id")
    if cust_id:
        cust = CustomerStatus.objects(customer_id=cust_id).first()
        if cust:
            flash("Customer of ID " + str(cust_id), 'success')
            return render_template('viewAllCustomers.html',
                                   cust=[cust],
                                   view_all_customers=True)
    if ssn_id:
        cust = CustomerStatus.objects(ssn_id=ssn_id).first()
        if cust:
            flash("Customer of SSN " + str(ssn_id), 'success')
            return render_template('viewAllCustomers.html',
                                   cust=[cust],
                                   view_all_customers=True)
    flash("No customer found", "danger")
    return redirect(url_for('view_all_customers'))
Exemple #4
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'))
Exemple #5
0
def createCustomer():

    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 = CreateCustomer()
    if form.validate_on_submit():

        customer_id = 0
        if CustomerStatus.objects.count() != 0:
            customer_id = CustomerStatus.objects.order_by(
                '-customer_id').first()['customer_id']
        customer_id += 1

        data = {
            "customer_id": customer_id,
            "ssn_id": form.cust_ssn.data,
            "customer_name": form.cust_name.data,
            "cust_age": form.cust_age.data,
            "state": form.cust_state.data,
            "customer_address": form.cust_address.data,
            "status": "Active",
            "message": "Customer Creation Successfull",
            "last_update": datetime.now()
        }
        CustomerStatus(**data).save()

        flash('Coustomer Created Successfully', 'success')
        return redirect(url_for('view_all_customers'))

    return render_template('createCustomer.html',
                           form=form,
                           create_customer=True)
Exemple #6
0
def customerViewEdit(idx=None):
    # return redirect(url_for('index'))

    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'))

    if idx == None:
        return redirect(url_for('view_all_customers'))

    form = UpdateCustomer()
    if form.validate_on_submit():
        message = ""
        if form.cust_name.data:
            CustomerStatus.objects(customer_id=form.cust_id.data).update(
                customer_name=form.cust_name.data)
            message += "Name, "
        if form.cust_age.data:
            CustomerStatus.objects(customer_id=form.cust_id.data).update(
                cust_age=form.cust_age.data)
            message += "Age, "
        if form.cust_address.data:
            CustomerStatus.objects(customer_id=form.cust_id.data).update(
                customer_address=form.cust_address.data)
            message += "Address, "
        if message == "":
            message = "Nothing, "

        else:
            CustomerStatus.objects(customer_id=form.cust_id.data).update(
                message="Customer Updated Successfully")
            CustomerStatus.objects(customer_id=form.cust_id.data).update(
                last_update=datetime.now())
        flash(message + "Updated", "danger")
        return redirect(url_for('view_all_customers'))
        #   CustomerStatus.objects(customer_id=form.cust_id.data).update(title='Example Post')
        # CustomerStatus.objects(customer_id=form.cust_id.data).update(title='Example Post')

    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('customerViewEdit.html',
                           form=form,
                           create_customer=True,
                           c=cust)
Exemple #7
0
 def validate_acc_cust_id(form, field):
     if not CustomerStatus.objects(customer_id=field.data).first():
         raise ValidationError("customer of this ID does not exists")
Exemple #8
0
 def validate_cust_ssn(form, field):
     if len(str(field.data)) != 9:
         raise ValidationError("SSN number must be of 9 digits")
     elif CustomerStatus.objects(ssn_id=field.data).first():
         raise ValidationError("SSN number Already exists")