Beispiel #1
0
def club_detail(request, club = None):

    club = get_object_or_404(Club, Slug = club)

    if request.method == 'POST':
        form = ManagerForm(request.POST)

        if form.is_valid() and check_manager_status(request, club):
            remove = form.cleaned_data['Remove']
            user = form.cleaned_data['User']
            if remove:
                club.Managers.remove(user)
                messages.success(request, '%s was removed as a manager for  %s.' % (user.username, club.Name))
            else:
                club.Managers.add(user)
                messages.success(request, '%s was added as a manager for  %s.' % (user.username, club.Name))
            return HttpResponseRedirect(club.get_absolute_url())


    else:
        form = ManagerForm()

    info_dict = {
        'club':club,
        'template_name':'Dojo/Club_object_detail.html',
        'manager_form':form

    }

    return render_to_response('Dojo/Club_object_detail.html', info_dict,
                              context_instance = RequestContext(request))
Beispiel #2
0
def manager_edit(request, id):
    manager = get_object_or_404(Manager, pk=id)
    if request.POST:
        form = ManagerForm(request.POST, instance=manager)
        if form.is_valid():
            obj = form.save()
            messages.success(request, _(u'%s manager changed successfully' % obj))
            return redirect('meotec:settings')
    else:
        form = ManagerForm(instance=manager)
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Manager Edit'),
        'form': form,
    })
Beispiel #3
0
def manager_add(request):
    if request.POST:
        print 0
        form = ManagerForm(request.POST)
        if form.is_valid():
            obj = form.save()
            messages.success(request, _(u'%s manager is added' % obj))
            return redirect('meotec:settings')
    else:
        form = ManagerForm()
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Manager Add'),
        'form': form,
    })
Beispiel #4
0
def manager_add(request):
    if request.POST:
        print 0
        form = ManagerForm(request.POST)
        if form.is_valid():
            obj = form.save()
            messages.success(request, _(u'%s manager is added' % obj))
            return redirect('meotec:settings')
    else:
        form = ManagerForm()
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Manager Add'),
        'form': form,
    })
Beispiel #5
0
def manager_edit(request, id):
    manager = get_object_or_404(Manager, pk=id)
    if request.POST:
        form = ManagerForm(request.POST, instance=manager)
        if form.is_valid():
            obj = form.save()
            messages.success(request,
                             _(u'%s manager changed successfully' % obj))
            return redirect('meotec:settings')
    else:
        form = ManagerForm(instance=manager)
    return direct_to_template(request, 'meotec/simple_form.html', {
        'title': _('Manager Edit'),
        'form': form,
    })
Beispiel #6
0
def login_success_employee():
    context = dict()
    # load basic information
    cursor = conn.execute('select * from employee where employid = \'' +
                          current_user.id + '\'')
    context['id'] = current_user.id

    for result in cursor:
        context['employname'] = result['employname'].strip()
        context['employpos'] = result['employpos'].strip()
    cursor.close()

    # load customer part
    # cart = []
    cashierform = CashierForm()
    context['cashierform'] = cashierform
    cashiergoodform = CashierGoodForm()
    context['cashiergoodform'] = cashiergoodform
    context['cart'] = cart
    print(context.keys())
    if cashierform.validate_on_submit():
        context['cur_cust_id'] = cashierform.customerid.data
        if cashierform.submit.data == True:
            cart.clear()
            cursor = conn.execute('select * from customer where cid = \'' +
                                  cashierform.customerid.data + '\'')
            for result in cursor:
                # context['cur_cust_id'] = cashierform.customerid.data
                context['cur_cust_name'] = result['cname'].strip()
            cursor.close()
            if 'cur_cust_name' in context.keys(
            ) and context['cur_cust_name'] != None:
                messagefound = 'Found customer: ' + cashierform.customerid.data + '. Now working on ' + context[
                    'cur_cust_name'] + '.'
                context['messagefound'] = messagefound
                return render_template('login-success-employee.html',
                                       **context)
            else:
                messagefound = 'Customer not found. Please try again'
                context['messagefound'] = messagefound

        elif cashierform.clear.data == True:
            context['cur_cust_id'] = None
            context['cur_cust_name'] = None
            cashierform.customerid.data = ''
            messagefound = 'Cleared!'
            context['messagefound'] = messagefound
            return render_template('login-success-employee.html', **context)

        elif cashierform.submit1.data == True:
            print(context['cur_cust_id'])
            print(context.keys())
            # print(context['cart'])
            cursor = conn.execute('select * from goods where goodbatch = \'' +
                                  cashiergoodform.goodid.data +
                                  '\' and storage > ' +
                                  cashierform.quantity.data)
            gprice = None
            i = 0
            for result in cursor:
                temp_goodname = ''
                temp_manufactor = ''
                gprice = result['gprice']
                cursor1 = conn.execute(
                    'select * from supplierapprovedBy where invoiceid = \'' +
                    result['invoiceid'] + '\'')
                for result1 in cursor1:
                    temp_goodname = result1['goodname']
                    temp_manufactor = result1['suppliername']
                cursor1.close()
                cart.append((temp_goodname, temp_manufactor,
                             cashierform.quantity.data, gprice))
                i = i + 1
            context['cart'] = cart
            if i == 0:
                check_message = "Item does not exist or out of stock"
            else:
                check_message = "Successfully added to cart"
            context['check_message'] = check_message
            return render_template('login-success-employee.html',
                                   **context.copy())

        elif cashierform.checkout.data == True:
            cursor = conn.execute(
                'select billid from bill where billdate = (select max(billdate) from bill)'
            )
            temp_billid = ''
            for result in cursor:
                temp_billid = result['billid']
            cursor.close()
            new_billid = int(temp_billid) + 1
            new_billid = str(new_billid).zfill(10)
            nowdate = date.today().strftime('%Y-%m-%d')
            discount = 1
            # retrieve membership level
            cursor = conn.execute(
                'select mlvl from membership where cid = \'' +
                context['cur_cust_id'] + '\'')
            mlvl = ''
            for result in cursor:
                mlvl = result['mlvl'].strip()
            if mlvl == 'silver':
                discount = 0.95
            elif mlbl == 'gold':
                discount = 0.9

            for row in cart:
                payment = int(row[2]) * float(row[3]) * discount
                billpmnt = 'cash'
                # update bill
                execution = 'insert into bill values (\'' + new_billid + '\', \'' + nowdate + '\',' + str(
                    payment
                ) + ', + ' + str(row[2]) + ', \'' + context[
                    'cur_cust_id'] + '\', \'' + current_user.id + '\', \'' + cashiergoodform.goodid.data + '\', \'' + billpmnt + '\')'
                print(execution)
                cursor = conn.execute(execution)
                cursor.close()
                # update storage
                execution = 'update goods set storage = storage - ' + row[
                    2] + ' where goodbatch = \'' + cashiergoodform.goodid.data + '\''
                cursor = conn.execute(execution)
                cursor.close()
                # update balance in membership
                execution = 'update membership set mbalance = mbalance + ' + str(
                    payment) + 'where cid = \'' + context['cur_cust_id'] + '\''
                cursor = conn.execute(execution)
                cursor.close()
            cart.clear()
            submit_message = "You purchased a total of $" + str(
                payment / discount) + "and paid with a discount of " + str(
                    discount) + ". Paid in total of " + str(payment) + '.'
            context['submit_message'] = submit_message

    # manager form: fire employee and release
    managerform = ManagerForm()
    context['managerform'] = managerform
    worker_list = []
    cursor = conn.execute(
        'select * from employee where employpos = \'cashier\' or employpos = \'tallyman\''
    )
    for result in cursor:
        managerform.workers.choices.append(
            (result['employid'], result['employname']))
    cursor.close()
    supplement = dict()
    cursor = conn.execute(
        'select * from supplierapprovedBy where managerid = \'' +
        current_user.id + '\'')
    for result in cursor:
        managerform.suppliers.choices.append(
            (result['invoiceid'],
             result['goodname'] + 'from ' + result['suppliername']))
        if result['suppliername'] not in supplement:
            supplement[result['suppliername']] = [result['goodname']]
        else:
            supplement[result['suppliername']].append(result['goodname'])
    cursor.close()
    if managerform.check.data == True:
        print(managerform.suppliers.data)
        context['invoiceid'] = managerform.suppliers.data
    if managerform.fire.data == True:
        value = dict(managerform.workers.choices).get(managerform.workers.data)
        cursor = conn.execute('delete from employee where employname = \'' +
                              value + '\'')
        cursor.close()
        managerform.workers.choices = []
        cursor = conn.execute(
            'select * from employee where employpos = \'cashier\' or employpos = \'tallyman\''
        )
        for result in cursor:
            managerform.workers.choices.append(
                (result['employid'], result['employname']))
        cursor.close()
    if managerform.release.data == True:
        dict1 = dict(managerform.suppliers.choices)
        key_list = list(dict1.keys())
        val_list = list(dict1.values())
        print(managerform.suppliers.data)
        cursor = conn.execute(
            'delete from supplierapprovedBy where invoiceid = \'' +
            managerform.suppliers.data + '\'')
        cursor.close()
        managerform.suppliers.choices = []
        cursor = conn.execute(
            'select * from supplierapprovedBy where managerid = \'' +
            current_user.id + '\'')
        for result in cursor:
            managerform.suppliers.choices.append(
                (result['invoiceid'],
                 result['goodname'] + 'from ' + result['suppliername']))
        cursor.close()
        # print(dict1)

    # insert new supplier
    managerform1 = ManagerForm1()
    context['managerform1'] = managerform1
    if managerform1.validate_on_submit():
        pass

    # insert new employee
    managerform2 = ManagerForm2()
    context['managerform2'] = managerform2
    if managerform2.validate_on_submit():
        cursor = conn.execute('select max(employid) from employee')
        cur_employid = 0
        for result in cursor:
            cur_employid = int(result['max'])
        new_employid = str(cur_employid + 1).zfill(6)
        execution = 'insert into employee values(\'' + new_employid + '\',\'' + managerform2.employname.data + '\', \'' + managerform2.identity.data + '\', \'' + managerform2.password.data + '\')'
        cursor = conn.execute(execution)
        managerform2.employname.data = ''
        cursor.close()

    # add to cart part
    # if cashiergoodform.validate_on_submit():
    #     print(cart)
    #     print("here")
    #     cursor = conn.execute('select * from goods where goodbatch = \'' + cashiergoodform.goodid.data + '\' and storage > ' + cashiergoodform.quantity.data)
    #     for result in cursor:
    #         temp_goodname = ''
    #         temp_manufactor = ''
    #         cursor1 = conn.execute('select * from supplierapprovedBy where invoiceid = \'' + result['invoiceid'] + '\'')
    #         for result1 in cursor1:
    #             temp_goodname = result1['goodname']
    #             temp_manufactor = result1['suppliername']
    #         cursor1.close()
    #         cart.append(('dsa'))
    #     return render_template('login-success-employee.html', **context)

    execution = 'select sum(storage), suppliername, supplieremail, goodname from supplierapprovedby join goods on goods.invoiceid = supplierapprovedBy.invoiceid group by suppliername, supplieremail, goodname, tallyid having tallyid = \'' + current_user.id + '\''
    cursor = conn.execute(execution)
    tallyman_item = []
    context['tallyman_item'] = tallyman_item
    for result in cursor:
        tallyman_item.append((result['goodname'], result['suppliername'],
                              result['sum'], result['supplieremail']))
    context['tallyman_item'] = tallyman_item

    return render_template('login-success-employee.html', **context)