diff --git a/requirements.txt b/requirements.txt index 42aa23d..396f555 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ -django +django==1.11 mysql-python gunicorn dj_static \ No newline at end of file diff --git a/src/chit_main_app/migrations/0001_initial.py b/src/chit_main_app/migrations/0001_initial.py index e97b16d..2c0cf39 100644 --- a/src/chit_main_app/migrations/0001_initial.py +++ b/src/chit_main_app/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.11.13 on 2018-05-20 04:04 +# Generated by Django 1.11 on 2018-06-14 09:46 from __future__ import unicode_literals from django.conf import settings @@ -44,7 +44,7 @@ class Migration(migrations.Migration): ('amount', models.IntegerField(null=True)), ('entry_date', models.DateField()), ('comment', models.CharField(max_length=1000)), - ('entry_type', models.CharField(choices=[(b'A', b'Auction'), (b'P', b'Payment'), (b'D', b'Disbursement')], max_length=10)), + ('entry_type', models.CharField(choices=[('A', 'Auction'), ('P', 'Payment'), ('D', 'Disbursement')], max_length=10)), ('member', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Customer')), ], ), @@ -56,6 +56,28 @@ class Migration(migrations.Migration): ('credit', models.IntegerField()), ], ), + migrations.CreateModel( + name='Loan', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('loan_amount', models.IntegerField()), + ('interest', models.IntegerField()), + ('approved_date', models.DateField()), + ('loan_lastpayment_date', models.DateField()), + ('loan_name', models.CharField(max_length=30, null=True)), + ('accumulated_interest', models.IntegerField(default=0)), + ('identity', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Customer')), + ], + ), + migrations.CreateModel( + name='LoanHistory', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('last_payment_date', models.DateField()), + ('payment_amount', models.IntegerField(default=0)), + ('key', models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Loan')), + ], + ), migrations.CreateModel( name='Subscriptions', fields=[ diff --git a/src/chit_main_app/models.py b/src/chit_main_app/models.py index 79facde..4c86332 100644 --- a/src/chit_main_app/models.py +++ b/src/chit_main_app/models.py @@ -1,5 +1,6 @@ from django.db import models from django.contrib.auth.models import User +from datetime import date, datetime # Create your models here . class Group(models.Model): @@ -22,7 +23,7 @@ class Subscriptions(models.Model): auction_amount = models.IntegerField(null=True) auction_date = models.DateField(null=True) auction_number = models.IntegerField(null=True) - + class Journal(models.Model): member = models.ForeignKey(Customer, null=True) amount = models.IntegerField(null=True) @@ -43,3 +44,18 @@ class JournalItem(models.Model): subscription = models.ForeignKey(Subscriptions) debit = models.IntegerField() credit = models.IntegerField() + +class Loan(models.Model): + identity = models.ForeignKey(Customer) + loan_amount = models.IntegerField() + interest = models.IntegerField() + approved_date = models.DateField() + loan_lastpayment_date = models.DateField() + loan_name = models.CharField(max_length=30,null=True) + accumulated_interest = models.IntegerField(default=0) + +class LoanHistory(models.Model): + key = models.ForeignKey(Loan, null = True,on_delete = models.CASCADE) + last_payment_date = models.DateField() + payment_amount = models.IntegerField(default=0) + diff --git a/src/chit_main_app/static/style.css b/src/chit_main_app/static/style.css index 3d2d261..217cea1 100644 --- a/src/chit_main_app/static/style.css +++ b/src/chit_main_app/static/style.css @@ -35,13 +35,13 @@ width: 100% } .menu { - border: 1px lightblue solid; + border: 1px lightblue solid; padding-top: 1pt; padding-bottom: 1pt; padding-left: 10pt; padding-right: 10pt; background: lightgray; - text-decoration: none; + text-decoration: none; } .action_icon { width: 12pt; @@ -49,7 +49,7 @@ } .label { color: gray; - text-align: right; + text-align: right; } button, submit { font-size: 12pt; @@ -61,7 +61,7 @@ span.warning { } .payment-amount { - font-size: 12pt; + font-size: 12pt; } .total-amount, .extraCredits { @@ -94,3 +94,17 @@ tr:nth-child(even) { tr:nth-child(odd) { background-color: #ffffff; } + + +.form-container { + width: 100%; + margin: auto; +} +.groups-form { + width: 48%; + float: left; +} +.loans-form { + width: 48%; + float: right; +} diff --git a/src/chit_main_app/templates/customers/grouplist.html b/src/chit_main_app/templates/customers/grouplist.html index 24fdedd..b09e3f4 100644 --- a/src/chit_main_app/templates/customers/grouplist.html +++ b/src/chit_main_app/templates/customers/grouplist.html @@ -1,11 +1,13 @@ {% extends "site_layout.html" %} {% load myfilter %} -{% block title %}{{customer_details.name}} details{% endblock %} +{% block title %}{{customer_details.name}} details{% endblock %} {% block page_heading %} Details of {{customer_details.name}} {% endblock %} {% block content %} + +

-{% if group_list %} -

-{% csrf_token %} - - - - - - - - -
Payment Date: -
- - - - - - - - - - {% for subscription in group_list %} - - - - - - - - - {% endfor %} - - - - - -
 Group NamesSubscriptionAuction AmountDuePayment
- {% if subscription.group.started %} -   - {% else %} - - - - {% endif %} - {{subscription.group.name}}{{subscription.id}}{{subscription.auction_amount|default:"-"}}{{due_amounts|get_item:subscription.id}} -
Total: {{total_due}}
-
-
+
+ {% if group_list %} +
+
+ {% csrf_token %} + + + + + +
+ + + + + + + + + + {% for subscription in group_list %} + + + + + + + + + {% endfor %} + + + + + +
 Group NamesSubscriptionAuction AmountDuePayment
+ {% if subscription.group.started %} +   + {% else %} + + + + {% endif %} + {{subscription.group.name}}{{subscription.id}}{{subscription.auction_amount|default:"-"}}{{due_amounts|get_item:subscription.id}} +
Total: {{total_due}}
+
+
+

payment date:

+
+
+
{% else %} Not in any groups yet {% endif %} +
+
+ {% if customer_loan %} +
+ {% csrf_token %} + + + + + + + + + + + + {% for loan in customer_loan %} + + + + + + + + + + {% endfor %} +
 Loan NamePrincipal AmountRate of
Interest +
Accumulated
Interest
DuePayment
+ + + + {{loan.loan_name}}{{loan.loan_amount}}{{loan.interest}}{{loan.accumulated_interest}}{{loan.accumulated_interest|add_loan:loan.loan_amount }} +
+
+
+

payment date:

+
+
+
+
+ {% else %} + Not in any loans yet + {% endif %} +
+
{% endblock %} diff --git a/src/chit_main_app/templates/customers/history.html b/src/chit_main_app/templates/customers/history.html index d7cf5dd..a110d4e 100644 --- a/src/chit_main_app/templates/customers/history.html +++ b/src/chit_main_app/templates/customers/history.html @@ -25,11 +25,15 @@ }); -Name: {{customer_details.name}}
Mobile: {{customer_details.mobile_number}}

+ + +

+
+ {% if journal %} {{ 0|counter_reset:'ALL' }} @@ -77,5 +81,29 @@ {% else %} No activity found {% endif %} +
+ + +
+ {% if loan_transactions %} + + + + + + + {% for lh_item in loan_transactions %} + + + + + + {% endfor %} +
Loan NamePayment AmountPayment Date
{{ lh_item.loan_name }} {{ lh_item.payment_amount }} {{ lh_item.last_payment_date }}
+ {% else %} + No activity found + {% endif %} +
+
{% endblock %} diff --git a/src/chit_main_app/templates/customers/list.html b/src/chit_main_app/templates/customers/list.html index ce4d261..7319034 100644 --- a/src/chit_main_app/templates/customers/list.html +++ b/src/chit_main_app/templates/customers/list.html @@ -17,6 +17,14 @@ return false } +function change_name(id) { + new_name = prompt('Enter new name: ') + if (new_name) { + window.location = '/customers/name?id='+id+'&new_name='+new_name + } + return false +} + $(function() { $('.payment-amount').change(function() { var total = 0 @@ -27,7 +35,12 @@ } }) $('#total_collection').val(total) - + + }) + $('#datepicker').change(function(){ + $.get('/customers/daily_collection',{date:$('#datepicker').val()}).done(function(data){ + for(id in data){ $("#current-amount-"+id).html(data[id]) } + }) }) $('#datepicker').change(function(){ $.get('/customers/daily_collection',{date:$('#datepicker').val()}).done(function(data){ @@ -38,7 +51,7 @@

-{% if customer_list %} +{% if customer_list %}

{% csrf_token %} @@ -67,7 +80,8 @@ {% else %} {% endif %} - +
  {{ customer.name }}{{ customer.name }} + {{ customer.mobile_number }} @@ -90,5 +104,5 @@ {% else %}

No Customers are available.

-{% endif %} +{% endif %} {% endblock %} diff --git a/src/chit_main_app/templates/customers/loan_registration.html b/src/chit_main_app/templates/customers/loan_registration.html new file mode 100644 index 0000000..78c7ef7 --- /dev/null +++ b/src/chit_main_app/templates/customers/loan_registration.html @@ -0,0 +1,31 @@ +{% extends "site_layout.html" %} +{% block title %}New Loan{% endblock %} +{% block page_heading %}Loan Registration Form{% endblock %} +{% block content %} +
+ {% csrf_token %} + + + + + + + + + + + + + + + + + + + + + +
Name of the Loan :
Loan amount :
Rate of Interest :
Date of Sanction:
+ +
+{% endblock %} diff --git a/src/chit_main_app/templates/registration/logged_out.html b/src/chit_main_app/templates/registration/logged_out.html index 1e17f3d..eef0bda 100644 --- a/src/chit_main_app/templates/registration/logged_out.html +++ b/src/chit_main_app/templates/registration/logged_out.html @@ -1 +1 @@ -You are logged out. Head to login again. +You are logged out! \ No newline at end of file diff --git a/src/chit_main_app/templates/registration/login.html b/src/chit_main_app/templates/registration/login.html index 95c215a..7c9da34 100644 --- a/src/chit_main_app/templates/registration/login.html +++ b/src/chit_main_app/templates/registration/login.html @@ -1,5 +1,5 @@

Admin + style="color: black; padding-top: 100; padding-left: 550; font-size: 25; font-family: sans-serif;">Admin Login

@@ -12,7 +12,7 @@ {% endif %} -
+
{% csrf_token %} @@ -33,4 +33,4 @@
-
\ No newline at end of file + diff --git a/src/chit_main_app/templates/site_layout.html b/src/chit_main_app/templates/site_layout.html index 070e5e3..8b61dfe 100644 --- a/src/chit_main_app/templates/site_layout.html +++ b/src/chit_main_app/templates/site_layout.html @@ -10,17 +10,18 @@ -
Apsara Chits
- - - - - - - -
 GroupsCustomers Hello, {{ user.username }}  Logout 
+
+
Apsara Chits
+ + + + + + + +
 GroupsCustomers Hello, {{ user.username }}  Logout 
- +

{% block page_heading %} page_heading is missing{% endblock %}

{% block content %}Your content goes here{% endblock %} diff --git a/src/chit_main_app/templatetags/myfilter.py b/src/chit_main_app/templatetags/myfilter.py index e399c7c..7e618ce 100644 --- a/src/chit_main_app/templatetags/myfilter.py +++ b/src/chit_main_app/templatetags/myfilter.py @@ -16,7 +16,7 @@ def get_item(dictionary, key): def counter_subtract(value, counter_name): counters[counter_name] -= int(value) return counters[counter_name] - + @register.filter def counter_add(value, counter_name): counters[counter_name] += int(value) @@ -26,7 +26,7 @@ def counter_add(value, counter_name): def counter_subtract_only(value, counter_name): counters[counter_name] -= int(value) return '' - + @register.filter def counter_add_only(value, counter_name): counters[counter_name] += int(value) @@ -40,3 +40,7 @@ def counter_reset(value, counter_name): @register.filter def counter_recall(value, counter_name): return counters[counter_name] + +@register.filter +def add_loan(a,b): + return a + b diff --git a/src/chit_main_app/views.py b/src/chit_main_app/views.py index d8c2900..c1e5a95 100644 --- a/src/chit_main_app/views.py +++ b/src/chit_main_app/views.py @@ -1,6 +1,6 @@ from django.shortcuts import HttpResponse from django.template import loader -from chit_main_app.models import Group,Customer, Subscriptions, Journal,JournalItem +from chit_main_app.models import Group,Customer, Subscriptions, Journal,JournalItem, Loan,LoanHistory from django.http.response import HttpResponseRedirect from django.contrib.auth.models import User from django.contrib.auth.decorators import login_required @@ -54,7 +54,7 @@ def new_group(request): context = { 'group_details': group_details } - return HttpResponse(template.render(context)) + return HttpResponse(template.render(context)) elif request.method == 'POST': if 'id' in request.POST: group = Group.objects.get(id=request.POST['id']) @@ -72,21 +72,21 @@ def new_group(request): @login_required def group_list(request): group_list = Group.objects.all() - + due_amounts = {} dues = JournalItem.objects.all().values('subscription__group_id').annotate(Sum('debit'),Sum('credit')) for x in dues: due_amounts[x['subscription__group_id']] = x['debit__sum'] - x['credit__sum'] - + auctions_done = {} auctions_left = {} auction_count = Subscriptions.objects.all().values('group_id').annotate(Count('auction_amount')) for x in auction_count: auctions_done[x['group_id']] = x['auction_amount__count'] - + for g in group_list: auctions_left[g.id] = g.total_months - auctions_done.get(g.id, 0) - + template = loader.get_template('groups/list.html') context = { 'group_list': group_list, @@ -114,7 +114,7 @@ def group_members(request): 'due_amounts': due_amounts, 'total_due_amount': sum(due_amounts.values()) } - return HttpResponse(template.render(context)) + return HttpResponse(template.render(context)) except Subscriptions.DoesNotExist: return HttpResponse("No members exist in this group.") @@ -128,24 +128,25 @@ def delete_group(request): def new_customer(request): if request.method == 'GET': template = loader.get_template('customers/new.html') - return HttpResponse(template.render({})) + 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") @login_required @@ -155,7 +156,7 @@ def customer_list(request): dues = JournalItem.objects.all().values('subscription__member_id').annotate(Sum('debit'),Sum('credit')) for x in dues: due_amounts[x['subscription__member_id']] = x['debit__sum'] - x['credit__sum'] - + template = loader.get_template('customers/list.html') context = { 'customer_list': customer_list, @@ -167,7 +168,7 @@ def customer_list(request): def delete_customer(request): group = Customer.objects.get(id=request.GET["id"]) group.delete() - return HttpResponseRedirect("/groups/list") + return HttpResponseRedirect("/customers/list") @login_required def delete_auction(request): @@ -189,14 +190,13 @@ def customershistory(request): for j_item in ji_list: if prvious_txn == None or j_item.txn.id != prvious_txn.id: previous_data = { - "type": "journal", + "type": "journal", "comment": "Auction: " + j_item.subscription.group.name if j_item.txn.entry_type=='A' else "Payment", "item": j_item.txn, "balance": the_balance, "credit": j_item.txn.amount if j_item.txn.amount else "" } j.append(previous_data) - previous_data["balance"] -= j_item.credit - j_item.debit the_balance -= j_item.credit - j_item.debit credit = None @@ -213,34 +213,55 @@ def customershistory(request): credit = j_item.credit j.append({ - "type":"journal_item", + "type":"journal_item", "balance": subscription_balances[j_item.subscription_id], "credit": credit or "", "debit": debit or "", "item": j_item}) prvious_txn = j_item.txn - c = {'journal': j, 'customer_details': customer_details} + loan_list = Loan.objects.filter(identity_id=request.GET['id']) + loan_transactions = [] + for l_item in loan_list: + loan_history_list = LoanHistory.objects.filter(key_id=l_item.id).order_by('last_payment_date') + for lh_item in loan_history_list: + setattr(lh_item, 'loan_name', l_item.loan_name) + loan_transactions.append(lh_item) + c = {'journal': j, 'customer_details': customer_details, 'loan_transactions': loan_transactions} template = loader.get_template('customers/history.html') return HttpResponse(template.render(c)) @login_required -def customersgroups(request): +def customersgroups(request): group_list = Subscriptions.objects.filter(member_id=request.GET['id']) customer_details = Customer.objects.get(id=request.GET['id']) due_amounts = {} dues = JournalItem.objects.filter(subscription__member_id=request.GET['id']).values('subscription_id').annotate(Sum('debit'),Sum('credit')) for x in dues: due_amounts[x['subscription_id']] = x['debit__sum'] - x['credit__sum'] + customer_loan = Loan.objects.filter(identity=request.GET['id']) + for l in customer_loan : + #l.accumulated_interest = l.accumulated_interest + (l.loan_amount*((int(datetime.today().strftime("%Y"))-int(l.approved_date.year) )*12 - int(l.approved_date.month) + int(datetime.today().strftime("%m")))*l.interest)/100 + if l.loan_lastpayment_date.year <= int(datetime.today().strftime("%Y")): + no_of_years = int(datetime.today().strftime("%Y"))-int(l.loan_lastpayment_date.year) + no_of_months = l.loan_lastpayment_date.month - int(datetime.today().strftime("%m")) + if l.loan_lastpayment_date.month <= int(datetime.today().strftime("%m")): + total_months = abs(no_of_years*12) + abs(no_of_months) + else: + total_months = abs(no_of_years*12) - abs(no_of_months) + l.accumulated_interest = l.accumulated_interest + int(l.loan_amount * total_months * ((int(l.interest)/12)/100)) + context = { 'group_list':group_list, 'customer_details':customer_details, 'due_amounts': due_amounts, - 'total_due': sum(due_amounts.itervalues()) + 'total_due': sum(iter(due_amounts.values())), + 'customer_loan': customer_loan } template = loader.get_template('customers/grouplist.html') + return HttpResponse(template.render(context)) - + @login_required def subscriptionnew(request): if request.method == 'GET': @@ -255,7 +276,7 @@ def subscriptionnew(request): 'group': group } return HttpResponse(template.render(context)) - + else: customer = Customer.objects.get(id=request.GET['cid']) customer_list = Customer.objects.all() @@ -266,7 +287,7 @@ def subscriptionnew(request): 'group_list':group_list, 'customer': customer } - return HttpResponse(template.render(context)) + 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') @@ -283,7 +304,7 @@ def subscriptionnew(request): else: return HttpResponse("We don't know your origin") -@login_required +@login_required def subscriptionslist(request): subscription_list = Subscriptions.objects.all() template = loader.get_template('subscriptions/list.html') @@ -311,7 +332,7 @@ def new_auction(request): 'subscriptions_list':subscriptions_list, 'group':group, 'auction_month':auction_month, - 'under_subscribed': under_subscribed + 'under_subscribed': under_subscribed } return HttpResponse(template.render(context)) elif request.method == 'POST': @@ -321,12 +342,12 @@ def new_auction(request): 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 @@ -341,14 +362,14 @@ def new_auction(request): 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() @@ -357,8 +378,24 @@ def new_auction(request): j1.credit = 0 j1.subscription_id = s1.id j1.save() - - return HttpResponseRedirect('/groups/members?id='+ request.POST['group_id']) + + return HttpResponseRedirect('/groups/members?id='+ request.POST['group_id']) + +@login_required +def new_loan(request): + if request.method == 'GET': + template = loader.get_template('customers/loan_registration.html') + return HttpResponse(template.render({})) + elif request.method == 'POST': + l = Loan() + l.loan_amount = request.POST['loanAmount'] + l.interest = request.POST['rateofinterest'] + l.approved_date = request.POST['dateofsanction'] + l.loan_name = request.POST['loanName'] + l.identity = Customer.objects.get(id=request.GET['cid']) + l.loan_lastpayment_date = l.approved_date + l.save() + return HttpResponseRedirect('/customers/grouplist?id='+request.GET['cid']) @login_required def record_customer_payment(request): @@ -370,27 +407,70 @@ def record_customer_payment(request): 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 - + for s_id, p_amount in iter(payments_for.items()): + + 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 + + # Redirect back to the page + return HttpResponseRedirect('/customers/grouplist?id='+request.POST['customer_id']) + +@login_required +def record_customer_loan_payment(request): + payments_for = {} + for l in Loan.objects.filter(identity_id = request.POST['customer_id']): + k = 'payment_for_' + str(l.id) + if k in request.POST and request.POST[k]: + payments_for[l.id] = int(request.POST[k]) + payment_date = datetime.strptime(request.POST['loan_payment_date'], '%Y-%m-%d').date() + if int(l.loan_lastpayment_date.year) <= int(payment_date.year): + no_of_years = int(payment_date.strftime("%Y"))-int(l.loan_lastpayment_date.year) + no_of_months = l.loan_lastpayment_date.month - int(payment_date.strftime("%m")) + if l.loan_lastpayment_date.month <= int(payment_date.strftime("%m")) : + total_months = no_of_years*12 + abs(no_of_months) + else : + total_months = no_of_years*12 - abs(no_of_months) + l.accumulated_interest = l.accumulated_interest + int(l.loan_amount * total_months * ((int(l.interest)/12)/100)) + + if int(request.POST[k]) >= (l.accumulated_interest+l.loan_amount): + l.accumulated_interest = 0 + l.loan_amount = 0 + l.loan_lastpayment_date = request.POST['loan_payment_date'] + l.save() + + elif int(request.POST[k]) >= (l.accumulated_interest): + l.loan_amount = l.loan_amount - (int(request.POST[k]) - l.accumulated_interest) + l.accumulated_interest = 0 + l.loan_lastpayment_date = request.POST['loan_payment_date'] + l.save() + + elif int(request.POST[k]) < l.accumulated_interest : + l.accumulated_interest = l.accumulated_interest - int(request.POST[k]) + l.loan_amount = l.loan_amount + l.loan_lastpayment_date = request.POST['loan_payment_date'] + l.save() + + from pprint import pprint + pprint(request.POST) + h = LoanHistory(key = l) + h.last_payment_date = request.POST['loan_payment_date'] + h.payment_amount = int(request.POST[k]) + h.save() return HttpResponseRedirect('/customers/grouplist?id='+request.POST['customer_id']) @login_required @@ -400,6 +480,13 @@ def new_mobile_number(request): m.save() return HttpResponseRedirect('/customers/list') +@login_required +def new_name(request): + m = Customer.objects.get(id=request.GET['id']) + m.name = request.GET['new_name'] + m.save() + return HttpResponseRedirect('/customers/list') + @login_required def new_auction_date(request): a = Subscriptions.objects.get(id=request.GET['id']) @@ -420,6 +507,17 @@ def remove_subscription(request): else: return HttpResponseRedirect('/groups/members?id=%s' % m.group_id) + +@login_required +def remove_loan(request): + m = Loan.objects.get(id=request.GET['id']) + if m: + m.delete() + else: + return HttpResponse('Invalid subscription') + return HttpResponseRedirect('/customers/list') + + @login_required def subscription_activity(request): j = JournalItem.objects.filter(subscription_id=request.GET['subscription_id']).order_by('txn__entry_date') @@ -446,7 +544,6 @@ def change_subscription(request): 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) @@ -455,14 +552,14 @@ def daily_collection(request): 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" + 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')) @@ -477,7 +574,6 @@ def daily_collection(request): 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: @@ -485,7 +581,7 @@ def daily_collection(request): due = s['debit__sum'] - s['credit__sum'] if due <= 0: continue - + j1 = JournalItem() j1.subscription_id = s_id j1.txn = j @@ -495,7 +591,6 @@ def daily_collection(request): available_amount -= j1.credit if available_amount == 0: break - if available_amount != old_credit: j1 = JournalItem() j1.txn = j diff --git a/src/chits/settings.py b/src/chits/settings.py index 2e92eb7..5633488 100644 --- a/src/chits/settings.py +++ b/src/chits/settings.py @@ -75,7 +75,7 @@ #'NAME':'chitmanager', 'NAME': 'heroku_e18935074c20bff', 'USER': 'root', - 'PASSWORD':'', + 'PASSWORD':'karthik', 'HOST': '', 'PORT': '', } @@ -106,7 +106,7 @@ if url.scheme == 'mysql': DATABASES['default']['ENGINE'] = 'django.db.backends.mysql' except Exception: - print 'Unexpected error:', sys.exc_info() + print('Unexpected error:', sys.exc_info()) # Internationalization # https://docs.djangoproject.com/en/1.6/topics/i18n/ diff --git a/src/chits/urls.py b/src/chits/urls.py index e57ebcb..aa582ab 100644 --- a/src/chits/urls.py +++ b/src/chits/urls.py @@ -9,7 +9,6 @@ url(r'^login/$', auth_views.login), url(r'^home/$', chit_main_app.views.homepage), url(r'^logout/$', auth_views.logout, name='logout'), - # Group operations url(r'^groups/new$', chit_main_app.views.new_group), url(r'^groups/list$', chit_main_app.views.group_list), @@ -17,18 +16,23 @@ url(r'^groups/members$', chit_main_app.views.group_members), url(r'^groups/auction$', chit_main_app.views.new_auction), url(r'^groups/remove_subscription$', chit_main_app.views.remove_subscription), + url(r'^cutomers/grouplist...../remove_loan$', chit_main_app.views.remove_loan), url(r'^groups/change_subscription$', chit_main_app.views.change_subscription), url(r'^groups/auction_date$', chit_main_app.views.new_auction_date), - + # Customer Operations url(r'^customers/new$', chit_main_app.views.new_customer), + url(r'^customers/remove_loan$', chit_main_app.views.remove_loan), url(r'^customers/list$', chit_main_app.views.customer_list), url(r'^customers/delete$', chit_main_app.views.delete_customer), url(r'^customers/grouplist$', chit_main_app.views.customersgroups), - url(r'^customers/history$', chit_main_app.views.customershistory), + url(r'^customers/history$', chit_main_app.views.customershistory), url(r'^customers/subscription$', chit_main_app.views.subscriptionnew), url(r'^customers/record_payment$', chit_main_app.views.record_customer_payment), + url(r'^customers/record_loan_payment$', chit_main_app.views.record_customer_loan_payment), + url(r'^customers/loan_registration$', chit_main_app.views.new_loan), url(r'^customers/mobile_number$', chit_main_app.views.new_mobile_number), + url(r'^customers/name$', chit_main_app.views.new_name), url(r'^customers/group_activity$', chit_main_app.views.subscription_activity), url(r'^customers/daily_collection$', chit_main_app.views.daily_collection), url(r'^customers/delete_payment$', chit_main_app.views.delete_payment),