コード例 #1
0
ファイル: views.py プロジェクト: svpmtrust/chitmanager
def record_customer_payment(request):
    payment_amount = int(request.POST['payment_amount'])
    payments_for = {}
    for s in Subscriptions.objects.filter(member_id=request.POST['customer_id']):
        k = 'payment_for_'+str(s.id)
        if k in request.POST and request.POST[k]:
            payments_for[s.id] = int(request.POST[k])
    if sum(payments_for.values()) != payment_amount:
        return HttpResponse('Sum of amounts is not adding up')
    
    j = Journal()
    j.entry_date = request.POST['payment_date']
    j.comments = 'No Comments'
    j.entry_type = j.PAYMENT
    j.member_id = request.POST['customer_id']
    j.save()
        
    # Create due amounts after subtracting dividends
    for s_id, p_amount in payments_for.iteritems():
        
        print s_id, p_amount
        
        j1 = JournalItem()
        j1.txn = j
        j1.debit = 0
        j1.credit = p_amount
        j1.subscription_id = s_id
        j1.save()
    
    # Redirect back to the page 
    return HttpResponseRedirect('/customers/grouplist?id='+request.POST['customer_id'])
コード例 #2
0
ファイル: views.py プロジェクト: vikky789s/chitmanager
def daily_collection(request):
    if (request.method == 'GET'):
        return get_daily_collection(request)
    if (request.method != 'POST'):
        return HttpResponse('Request must be either GET or POST', status=500)

    c_list = Customer.objects.all().order_by('name')
    for c in c_list:
        cust_payment = request.POST.get('customer_collection_%s' % c.id)
        cust_payment = int(cust_payment) if cust_payment else 0
        if cust_payment:
            print("Payment for ", c.name, " is ", cust_payment)
            print("Finding subscriptions with due amounts")
            dues = (JournalItem.objects.filter(subscription__member_id=c.id).
                    values('subscription_id').annotate(
                        Sum('debit'),
                        Sum('credit')).order_by('subscription__id'))

            # Get any previous credits
            pc_id = Subscriptions.objects.get(member_id=c.id, group_id=1).id
            a = JournalItem.objects.filter(subscription_id=pc_id).aggregate(
                Sum('debit'), Sum('credit'))
            credit_amount = int(a['credit__sum'] if a['credit__sum'] else 0)
            debit_amount = int(a['debit__sum'] if a['debit__sum'] else 0)
            old_credit = credit_amount - debit_amount

            # Create journal entry
            j = Journal()
            j.entry_date = request.POST['collection_date']
            j.amount = cust_payment
            j.entry_type = j.PAYMENT
            j.member = c
            j.save()
            # If there any old credit, add it to the current amount
            available_amount = old_credit + cust_payment
            for s in dues:
                s_id = s['subscription_id']
                due = s['debit__sum'] - s['credit__sum']
                if due <= 0:
                    continue

                j1 = JournalItem()
                j1.subscription_id = s_id
                j1.txn = j
                j1.debit = 0
                j1.credit = min(due, available_amount)
                j1.save()
                available_amount -= j1.credit
                if available_amount == 0:
                    break
            if available_amount != old_credit:
                j1 = JournalItem()
                j1.txn = j
                j1.credit = cust_payment
                j1.subscription_id = pc_id
                j1.debit = 0
                if old_credit < available_amount:
                    j1.credit = available_amount - old_credit
                else:
                    j1.debit = old_credit - available_amount
                j1.save()

    return HttpResponseRedirect('/customers/list')
コード例 #3
0
ファイル: views.py プロジェクト: vikky789s/chitmanager
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'])
コード例 #4
0
ファイル: views.py プロジェクト: svpmtrust/chitmanager
def daily_collection(request):
    if(request.method=='GET'):
        return get_daily_collection(request)
    
    if(request.method != 'POST'):
        return HttpResponse('Request must be either GET or POST', status=500)

    c_list = Customer.objects.all().order_by('name')
    for c in c_list:
        cust_payment = request.POST.get('customer_collection_%s' % c.id)
        cust_payment = int(cust_payment) if cust_payment else 0
        if cust_payment:
            print "Payment for ", c.name, " is ", cust_payment
            print "Finding subscriptions with due amounts"
            dues = (JournalItem.objects
                               .filter(subscription__member_id=c.id)
                               .values('subscription_id')
                               .annotate(Sum('debit'),Sum('credit'))
                               .order_by('subscription__id'))
            
            # Get any previous credits
            pc_id = Subscriptions.objects.get(member_id=c.id, group_id=1).id
            a = JournalItem.objects.filter(subscription_id=pc_id).aggregate(Sum('debit'),Sum('credit'))
            credit_amount = int(a['credit__sum'] if a['credit__sum'] else 0)
            debit_amount = int(a['debit__sum'] if a['debit__sum'] else 0)
            old_credit = credit_amount - debit_amount

            # Create journal entry
            j = Journal()
            j.entry_date = request.POST['collection_date']
            j.amount = cust_payment
            j.entry_type = j.PAYMENT
            j.member = c
            j.save()
            
            # If there any old credit, add it to the current amount
            available_amount = old_credit + cust_payment

            print "\n"
            print "Total available amount == ", available_amount
            print "\n"

            for s in dues:
                s_id = s['subscription_id']
                due = s['debit__sum'] - s['credit__sum']
                if due <= 0:
                    continue
                
                j1 = JournalItem()
                j1.subscription_id = s_id
                j1.txn = j
                j1.debit = 0
                j1.credit = min(due, available_amount)
                j1.save()
                available_amount -= j1.credit
                if available_amount == 0:
                    break
            
            if available_amount != old_credit:
                j1 = JournalItem()
                j1.txn = j
                j1.credit = 0
                j1.subscription_id = pc_id
                j1.debit = 0
                if old_credit < available_amount:
                    j1.credit = available_amount - old_credit
                else:
                    j1.debit = old_credit - available_amount
                j1.save()

    return HttpResponseRedirect('/customers/list')
コード例 #5
0
ファイル: views.py プロジェクト: svpmtrust/chitmanager
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']) 
コード例 #6
0
def daily_collection(request):
    c_list = Customer.objects.all().order_by('name')
    for c in c_list:
        cust_payment = request.POST.get('customer_collection_%s' % c.id)
        cust_payment = int(cust_payment) if cust_payment else 0
        if cust_payment:
            print "Payment for ", c.name, " is ", cust_payment
            print "Finding subscriptions with due amounts"
            dues = (JournalItem.objects
                               .filter(subscription__member_id=c.id)
                               .values('subscription_id')
                               .annotate(Sum('debit'),Sum('credit'))
                               .order_by('subscription__id'))
            
            # Get any previous credits
            pc_id = Subscriptions.objects.get(member_id=c.id, group_id=1).id
            a = JournalItem.objects.filter(subscription_id=pc_id).aggregate(Sum('debit'),Sum('credit'))
            credit_amount = int(a['credit__sum'] if a['credit__sum'] else 0)
            debit_amount = int(a['debit__sum'] if a['debit__sum'] else 0)
            old_credit = credit_amount - debit_amount

            # Create journal entry
            j = Journal()
            j.entry_date = request.POST['collection_date']
            j.amount = cust_payment
            j.entry_type = j.PAYMENT
            j.save()
            
            # If there any old credit, add it to the current amount
            if old_credit != 0:
                j1 = JournalItem()
                j1.txn = j
                j1.subscription_id = pc_id
                cust_payment += old_credit

                if(old_credit>0):
                    j1.debit, j1.credit = old_credit, 0
                    j1.credit = 0
                else:
                    # We don't expect this case.  But if the customer
                    # Owe us something for what ever reason, we reduce it
                    # from the amount
                    j1.debit, j1.credit = 0, -old_credit
                j1.save()
            
            for s in dues:
                s_id = s['subscription_id']
                due = s['debit__sum'] - s['credit__sum']
                if due == 0:
                    continue
                
                j1 = JournalItem()
                j1.subscription_id = s_id
                j1.txn = j
                j1.debit = 0
                j1.credit = min(due, cust_payment)
                j1.save()
                cust_payment -= j1.credit
                if cust_payment == 0:
                    break
            else:
                j1 = JournalItem()
                j1.txn = j
                j1.credit = cust_payment
                j1.subscription_id = pc_id
                j1.debit = 0
                j1.save()

    return HttpResponseRedirect('/customers/list')
コード例 #7
0
ファイル: views.py プロジェクト: urmyfrnz/chitmanager
def daily_collection(request):
    c_list = Customer.objects.all().order_by('name')
    for c in c_list:
        cust_payment = request.POST.get('customer_collection_%s' % c.id)
        cust_payment = int(cust_payment) if cust_payment else 0
        if cust_payment:
            print "Payment for ", c.name, " is ", cust_payment
            print "Finding subscriptions with due amounts"
            dues = (JournalItem.objects.filter(subscription__member_id=c.id).
                    values('subscription_id').annotate(
                        Sum('debit'),
                        Sum('credit')).order_by('subscription__id'))

            # Get any previous credits
            pc_id = Subscriptions.objects.get(member_id=c.id, group_id=1).id
            a = JournalItem.objects.filter(subscription_id=pc_id).aggregate(
                Sum('debit'), Sum('credit'))
            credit_amount = int(a['credit__sum'] if a['credit__sum'] else 0)
            debit_amount = int(a['debit__sum'] if a['debit__sum'] else 0)
            old_credit = credit_amount - debit_amount

            # Create journal entry
            j = Journal()
            j.entry_date = request.POST['collection_date']
            j.amount = cust_payment
            j.entry_type = j.PAYMENT
            j.save()

            # If there any old credit, add it to the current amount
            if old_credit != 0:
                j1 = JournalItem()
                j1.txn = j
                j1.subscription_id = pc_id
                cust_payment += old_credit

                if (old_credit > 0):
                    j1.debit, j1.credit = old_credit, 0
                    j1.credit = 0
                else:
                    # We don't expect this case.  But if the customer
                    # Owe us something for what ever reason, we reduce it
                    # from the amount
                    j1.debit, j1.credit = 0, -old_credit
                j1.save()

            for s in dues:
                s_id = s['subscription_id']
                due = s['debit__sum'] - s['credit__sum']
                if due == 0:
                    continue

                j1 = JournalItem()
                j1.subscription_id = s_id
                j1.txn = j
                j1.debit = 0
                j1.credit = min(due, cust_payment)
                j1.save()
                cust_payment -= j1.credit
                if cust_payment == 0:
                    break
            else:
                j1 = JournalItem()
                j1.txn = j
                j1.credit = cust_payment
                j1.subscription_id = pc_id
                j1.debit = 0
                j1.save()

    return HttpResponseRedirect('/customers/list')