Example #1
0
def new_customer(request):
    if request.method == 'GET':
        template = loader.get_template('customers/new.html')
        return HttpResponse(template.render({}))
    elif request.method == 'POST':
        username = request.POST['username']
        user = User()
        user.username = username
        user.set_password(username + request.POST['mobile'])
        user.last_login = datetime.utcnow()
        user.save()
        member_name = request.POST['name'][0].upper(
        ) + request.POST['name'][1:]
        member = Customer(name=member_name,
                          mobile_number=request.POST['mobile'])
        member.user = user
        member.save()

        s = Subscriptions()
        s.member_id = member.id
        s.group_id = 1
        s.comment = 'Auto added to personal credits group'
        s.save()

        return HttpResponseRedirect("/customers/list")
Example #2
0
def subscriptionnew(request):
    if request.method == 'GET':
        if 'gid' in request.GET:
            group = Group.objects.get(id=request.GET['gid'])
            customer_list = Customer.objects.all().order_by('name')
            group_list = Group.objects.all()
            template = loader.get_template('customers/subscription.html')
            context = RequestContext(
                request, {
                    'customer_list': customer_list,
                    'group_list': group_list,
                    'group': group
                })
            return HttpResponse(template.render(context))

        else:
            customer = Customer.objects.get(id=request.GET['cid'])
            customer_list = Customer.objects.all()
            group_list = Group.objects.all()
            template = loader.get_template('customers/subscription.html')
            context = RequestContext(
                request, {
                    'customer_list': customer_list,
                    'group_list': group_list,
                    'customer': customer
                })
        return HttpResponse(template.render(context))
    elif request.method == 'POST':
        customer_list = request.POST.getlist('to_customer_list')
        group_list = request.POST.getlist('to_group_list')
        for c, g in itertools.product(customer_list, group_list):
            subscription = Subscriptions()
            subscription.group_id = g
            subscription.member_id = c
            subscription.comments = request.POST['comments']
            subscription.save()
        if 'group_id' in request.POST:
            return HttpResponseRedirect('/groups/members?id=' +
                                        request.POST['group_id'])
        elif 'customer_id' in request.POST:
            return HttpResponseRedirect('/customers/grouplist?id=' +
                                        request.POST['customer_id'])
        else:
            return HttpResponse("We don't know your origin")
Example #3
0
def subscriptionnew(request):
    if request.method == 'GET':
        if 'gid' in request.GET:
            group = Group.objects.get(id=request.GET['gid'])
            customer_list = Customer.objects.all().order_by('name')
            group_list = Group.objects.all()
            template = loader.get_template('customers/subscription.html')
            context = {
                'customer_list': customer_list,
                'group_list':group_list,
                'group': group
            }
            return HttpResponse(template.render(context))
                      
        else:
            customer = Customer.objects.get(id=request.GET['cid'])
            customer_list = Customer.objects.all()
            group_list = Group.objects.all()
            template = loader.get_template('customers/subscription.html')
            context = {
                'customer_list': customer_list,
                'group_list':group_list,
                'customer': customer
            }
        return HttpResponse(template.render(context)) 
    elif request.method == 'POST':
        customer_list = request.POST.getlist('to_customer_list')
        group_list = request.POST.getlist('to_group_list')
        for c,g in itertools.product(customer_list, group_list):
            subscription = Subscriptions()
            subscription.group_id = g
            subscription.member_id = c
            subscription.comments = request.POST['comments']
            subscription.save()
        if 'group_id' in request.POST:
            return HttpResponseRedirect('/groups/members?id=' + request.POST['group_id'])
        elif 'customer_id' in request.POST:
            return HttpResponseRedirect('/customers/grouplist?id=' + request.POST['customer_id'])
        else:
            return HttpResponse("We don't know your origin")
Example #4
0
def new_customer(request):
    if request.method == 'GET':
        template = loader.get_template('customers/new.html')
        return HttpResponse(template.render({}))    
    elif request.method == 'POST':
        username = request.POST['username']
        user = User()
        user.username = username
        user.set_password(username + request.POST['mobile'])
        user.last_login = datetime.utcnow()
        user.save()
        member_name = request.POST['name'][0].upper()+request.POST['name'][1:]
        member = Customer(name=member_name, mobile_number=request.POST['mobile'])
        member.user = user
        member.save()
        
        s = Subscriptions()
        s.member_id = member.id
        s.group_id = 1
        s.comment = 'Auto added to personal credits group'
        s.save()
        
        return HttpResponseRedirect("/customers/list")
Example #5
0
def new_auction(request):
    if request.method == 'GET':
        group = Group.objects.get(id=request.GET['id'])
        subscriptions_list = Subscriptions.objects.filter(
            group_id=request.GET['id'])
        subscription_count = Subscriptions.objects.filter(
            group_id=request.GET['id']).count()
        if subscription_count > group.total_months:
            return HttpResponse("Group Over subscribed")
        elif subscription_count < group.total_months:
            under_subscribed = True
        else:
            under_subscribed = False
        auction_month = sum(0 if s.auction_amount is None else 1
                            for s in subscriptions_list) + 1
        subscriptions_list = filter(lambda s: s.auction_amount is None,
                                    subscriptions_list)
        template = loader.get_template('groups/auction.html')
        context = {
            'subscriptions_list': subscriptions_list,
            'group': group,
            'auction_month': auction_month,
            'under_subscribed': under_subscribed
        }
        return HttpResponse(template.render(context))
    elif request.method == 'POST':
        # Mark the subscription for the auction
        s = Subscriptions.objects.get(id=request.POST['auctionmember'])
        s.auction_amount = float(request.POST['amount'])
        s.auction_date = request.POST['date']
        s.auction_number = request.POST['month']
        s.save()

        g = s.group
        if not g.started:
            g.started = True
            g.save()

        # Add missing subscriptions
        subscription_count = Subscriptions.objects.filter(
            group_id=g.id).count()
        missing_subscriptions = g.total_months - subscription_count
        if missing_subscriptions > 0:
            for i in range(missing_subscriptions):
                s1 = Subscriptions()
                s1.member_id = 1
                s1.group_id = g.id
                s1.comments = 'Automatically subscribed'
                s1.save()

        monthly_due = g.amount / g.total_months
        dividend = (s.auction_amount -
                    (g.amount * g.commision) / 100) / g.total_months
        due_amount = monthly_due - dividend

        # Create main journal Entries
        j = Journal()
        j.entry_date = s.auction_date
        j.comments = 'No Comments'
        j.entry_type = j.AUCTION
        j.save()

        # Create due amounts after subtracting dividends
        for s1 in Subscriptions.objects.filter(group_id=s.group_id):
            j1 = JournalItem()
            j1.txn = j
            j1.debit = due_amount
            j1.credit = 0
            j1.subscription_id = s1.id
            j1.save()

        return HttpResponseRedirect('/groups/members?id=' +
                                    request.POST['group_id'])
Example #6
0
def new_auction(request):
    if request.method == 'GET':
        group = Group.objects.get(id=request.GET['id'])
        subscriptions_list = Subscriptions.objects.filter(group_id=request.GET['id'])
        subscription_count = Subscriptions.objects.filter(group_id=request.GET['id']).count()
        if subscription_count > group.total_months:
            return HttpResponse("Group Over subscribed")
        elif subscription_count < group.total_months:
            under_subscribed = True
        else:
            under_subscribed = False
        auction_month = sum(0 if s.auction_amount is None else 1 for s in subscriptions_list)+1
        subscriptions_list = filter(lambda s:s.auction_amount is None, subscriptions_list)
        template = loader.get_template('groups/auction.html')
        context = {
            'subscriptions_list':subscriptions_list,
            'group':group,
            'auction_month':auction_month,
            'under_subscribed': under_subscribed 
        }
        return HttpResponse(template.render(context))
    elif request.method == 'POST':
        # Mark the subscription for the auction
        s = Subscriptions.objects.get(id=request.POST['auctionmember'])
        s.auction_amount = float(request.POST['amount'])
        s.auction_date = request.POST['date']
        s.auction_number = request.POST['month']
        s.save()
        
        g = s.group
        if not g.started:
            g.started = True
            g.save()
        
        # Add missing subscriptions
        subscription_count = Subscriptions.objects.filter(group_id=g.id).count()
        missing_subscriptions = g.total_months - subscription_count
        if missing_subscriptions > 0:
            for i in range(missing_subscriptions):
                s1 = Subscriptions()
                s1.member_id = 1
                s1.group_id = g.id
                s1.comments = 'Automatically subscribed'
                s1.save()

        monthly_due = g.amount / g.total_months
        dividend = (s.auction_amount - (g.amount * g.commision)/100) / g.total_months
        due_amount = monthly_due - dividend
        
        # Create main journal Entries
        j = Journal()
        j.entry_date = s.auction_date
        j.comments = 'No Comments'
        j.entry_type = j.AUCTION
        j.save()
        
        # Create due amounts after subtracting dividends
        for s1 in Subscriptions.objects.filter(group_id=s.group_id):
            j1 = JournalItem()
            j1.txn = j
            j1.debit = due_amount
            j1.credit = 0
            j1.subscription_id = s1.id
            j1.save()
        
        return HttpResponseRedirect('/groups/members?id='+ request.POST['group_id'])