From f71de1f85b07899ea80206f3b20083c8d3596fcd Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Wed, 23 May 2018 18:40:49 +0530 Subject: [PATCH 01/11] requirements changed --- requirements.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From c38354c828e764b58a7bc507afe6130034781e27 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 11:36:04 +0530 Subject: [PATCH 02/11] sample first commit --- src/.env | 1 + src/.env | 1 + .../migrations/0002_auto_20180523_0654.py | 20 ++ src/chit_main_app/migrations/0003_loan.py | 26 +++ .../migrations/0004_auto_20180529_0621.py | 25 +++ .../migrations/0005_auto_20180529_1028.py | 20 ++ .../migrations/0006_auto_20180604_0806.py | 33 +++ src/chit_main_app/models.py | 16 +- src/chit_main_app/static/style.css | 22 +- .../templates/customers/grouplist.html | 197 +++++++++++------- .../templates/customers/list.html | 17 +- .../customers/loan_registration.html | 31 +++ .../templates/registration/logged_out.html | 2 +- .../templates/registration/login.html | 6 +- src/chit_main_app/templates/site_layout.html | 21 +- src/chit_main_app/templatetags/myfilter.py | 8 +- src/chit_main_app/views.py | 162 ++++++++++---- src/chits/settings.py | 4 +- src/chits/urls.py | 11 +- 19 files changed, 478 insertions(+), 145 deletions(-) create mode 100644 src/.env create mode 100644 src/.env create mode 100644 src/chit_main_app/migrations/0002_auto_20180523_0654.py create mode 100644 src/chit_main_app/migrations/0003_loan.py create mode 100644 src/chit_main_app/migrations/0004_auto_20180529_0621.py create mode 100644 src/chit_main_app/migrations/0005_auto_20180529_1028.py create mode 100644 src/chit_main_app/migrations/0006_auto_20180604_0806.py create mode 100644 src/chit_main_app/templates/customers/loan_registration.html diff --git a/src/.env b/src/.env new file mode 100644 index 0000000..16ef7e8 --- /dev/null +++ b/src/.env @@ -0,0 +1 @@ +export SQLITE=True diff --git a/src/.env b/src/.env new file mode 100644 index 0000000..16ef7e8 --- /dev/null +++ b/src/.env @@ -0,0 +1 @@ +export SQLITE=True diff --git a/src/chit_main_app/migrations/0002_auto_20180523_0654.py b/src/chit_main_app/migrations/0002_auto_20180523_0654.py new file mode 100644 index 0000000..c985a60 --- /dev/null +++ b/src/chit_main_app/migrations/0002_auto_20180523_0654.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-23 06:54 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0001_initial'), + ] + + operations = [ + migrations.AlterField( + model_name='journal', + name='entry_type', + field=models.CharField(choices=[('A', 'Auction'), ('P', 'Payment'), ('D', 'Disbursement')], max_length=10), + ), + ] diff --git a/src/chit_main_app/migrations/0003_loan.py b/src/chit_main_app/migrations/0003_loan.py new file mode 100644 index 0000000..74908f7 --- /dev/null +++ b/src/chit_main_app/migrations/0003_loan.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-29 05:15 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0002_auto_20180523_0654'), + ] + + operations = [ + 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()), + ('cid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Customer')), + ], + ), + ] diff --git a/src/chit_main_app/migrations/0004_auto_20180529_0621.py b/src/chit_main_app/migrations/0004_auto_20180529_0621.py new file mode 100644 index 0000000..5f10c49 --- /dev/null +++ b/src/chit_main_app/migrations/0004_auto_20180529_0621.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-29 06:21 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0003_loan'), + ] + + operations = [ + migrations.RenameField( + model_name='loan', + old_name='cid', + new_name='ccid', + ), + migrations.AddField( + model_name='loan', + name='loan_name', + field=models.CharField(max_length=30, null=True), + ), + ] diff --git a/src/chit_main_app/migrations/0005_auto_20180529_1028.py b/src/chit_main_app/migrations/0005_auto_20180529_1028.py new file mode 100644 index 0000000..628ffba --- /dev/null +++ b/src/chit_main_app/migrations/0005_auto_20180529_1028.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-05-29 10:28 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0004_auto_20180529_0621'), + ] + + operations = [ + migrations.RenameField( + model_name='loan', + old_name='ccid', + new_name='identity', + ), + ] diff --git a/src/chit_main_app/migrations/0006_auto_20180604_0806.py b/src/chit_main_app/migrations/0006_auto_20180604_0806.py new file mode 100644 index 0000000..baa5c55 --- /dev/null +++ b/src/chit_main_app/migrations/0006_auto_20180604_0806.py @@ -0,0 +1,33 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-06-04 08:06 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0005_auto_20180529_1028'), + ] + + operations = [ + migrations.CreateModel( + name='loan_history', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('last_payment_date', models.DateField()), + ], + ), + migrations.AddField( + model_name='loan', + name='accumulated_interest', + field=models.IntegerField(default=0), + ), + migrations.AddField( + model_name='loan_history', + name='key', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Loan'), + ), + ] diff --git a/src/chit_main_app/models.py b/src/chit_main_app/models.py index 79facde..246d561 100644 --- a/src/chit_main_app/models.py +++ b/src/chit_main_app/models.py @@ -1,5 +1,7 @@ from django.db import models from django.contrib.auth.models import User +from datetime import date + # Create your models here . class Group(models.Model): @@ -22,7 +24,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 +45,15 @@ 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_name = models.CharField(max_length=30,null=True) + accumulated_interest = models.IntegerField(default=0) + +class loan_history(models.Model): + key = models.ForeignKey(Loan, null = True) + last_payment_date = models.DateField() 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..efa4034 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 silly %} +
+ {% csrf_token %} + + + + + + + + + + + + {% for loan in silly %} + + + + + + + + + + {% 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/list.html b/src/chit_main_app/templates/customers/list.html index ce4d261..09dde85 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,7 @@ } }) $('#total_collection').val(total) - + }) $('#datepicker').change(function(){ $.get('/customers/daily_collection',{date:$('#datepicker').val()}).done(function(data){ @@ -38,7 +46,7 @@

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

{% csrf_token %} @@ -67,7 +75,8 @@ {% else %} {% endif %} - + - + - + From ce11698c77cc6c603e3edd2d1929585c0762b59d Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:36:16 +0530 Subject: [PATCH 08/11] deleting even the loan history on deleting a particular loan --- src/chit_main_app/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chit_main_app/models.py b/src/chit_main_app/models.py index 246d561..67907c4 100644 --- a/src/chit_main_app/models.py +++ b/src/chit_main_app/models.py @@ -55,5 +55,5 @@ class Loan(models.Model): accumulated_interest = models.IntegerField(default=0) class loan_history(models.Model): - key = models.ForeignKey(Loan, null = True) + key = models.ForeignKey(Loan, null = True,on_delete = models.CASCADE) last_payment_date = models.DateField() From 754d3fc23b65bb7a2d42d03fd7f419c7219b3894 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:56:03 +0530 Subject: [PATCH 09/11] variable name changes and cascade delete of loan history --- .../migrations/0007_auto_20180605_0712.py | 21 +++++++++++++++++++ .../templates/customers/grouplist.html | 4 ++-- src/chit_main_app/views.py | 3 +-- 3 files changed, 24 insertions(+), 4 deletions(-) create mode 100644 src/chit_main_app/migrations/0007_auto_20180605_0712.py diff --git a/src/chit_main_app/migrations/0007_auto_20180605_0712.py b/src/chit_main_app/migrations/0007_auto_20180605_0712.py new file mode 100644 index 0000000..039b4ff --- /dev/null +++ b/src/chit_main_app/migrations/0007_auto_20180605_0712.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11 on 2018-06-05 07:12 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('chit_main_app', '0006_auto_20180604_0806'), + ] + + operations = [ + migrations.AlterField( + model_name='loan_history', + name='key', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Loan'), + ), + ] diff --git a/src/chit_main_app/templates/customers/grouplist.html b/src/chit_main_app/templates/customers/grouplist.html index efa4034..b09e3f4 100644 --- a/src/chit_main_app/templates/customers/grouplist.html +++ b/src/chit_main_app/templates/customers/grouplist.html @@ -150,7 +150,7 @@ {% endif %}
- {% if silly %} + {% if customer_loan %}
{% csrf_token %} @@ -165,7 +165,7 @@
- {% for loan in silly %} + {% for loan in customer_loan %}
  {{ customer.name }}{{ customer.name }} + {{ customer.mobile_number }} @@ -90,5 +99,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..0550629 --- /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..ef03c25 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,loan_history 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,26 +72,30 @@ 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') +######################################################################### + #silly = Loan.objects.filter(identity = request.GET['id']) +######################################################################### context = { 'group_list': group_list, 'due_amounts': due_amounts, - 'auctions_left': auctions_left + 'auctions_left': auctions_left, + # 'silly': silly } return HttpResponse(template.render(context)) @@ -114,7 +118,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,7 +132,7 @@ 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() @@ -139,13 +143,13 @@ def new_customer(request): 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 +159,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 +171,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 +193,14 @@ 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 +217,43 @@ 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} 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'] + silly = Loan.objects.filter(identity=request.GET['id']) + for l in silly : + if l.approved_date.year == datetime.today().strftime("%Y"): + if l.approved_date.month == datetime.today().strftime("%m"): + l.accumulated_interest = 0 + else: + 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 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())), + 'silly': silly } template = loader.get_template('customers/grouplist.html') + return HttpResponse(template.render(context)) - + @login_required def subscriptionnew(request): if request.method == 'GET': @@ -255,7 +268,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 +279,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 +296,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 +324,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 +334,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 +354,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 +370,23 @@ 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': + loo = Loan() + loo.loan_amount = request.POST['loanAmount'] + loo.interest = request.POST['ROI'] + loo.approved_date = request.POST['DOS'] + loo.loan_name = request.POST['loanName'] + loo.identity = Customer.objects.get(id=request.GET['cid']) + loo.save() + return HttpResponseRedirect('/customers/grouplist?id='+request.GET['cid']) @login_required def record_customer_payment(request): @@ -370,36 +398,69 @@ 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): + 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]: + if int(request.POST[k]) >= (l.accumulated_interest+l.loan_amount): + l.accumulated_interest = 0 + l.loan_amount = 0 + l.save() + else: + if int(request.POST[k]) < l.accumulated_interest : + l.accumulated_interest = l.accumulated_interest - int(request.POST[k]) + l.save() + h = loan_history(key = l) + h.last_payment_date = request.POST['loan_payment_date'] + h.save() + else: + l.loan_amount = l.loan_amount + l.accumulated_interest - int(request.POST[k]) + l.accumulated_interest = 0 + l.save() + from pprint import pprint + pprint(request.POST) + h = loan_history(key= l) + h.last_payment_date = request.POST['loan_payment_date'] + h.save() + return HttpResponseRedirect('/customers/grouplist?id='+request.POST['customer_id']) +@login_required def new_mobile_number(request): m = Customer.objects.get(id=request.GET['id']) m.mobile_number = request.GET['new_number'] 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 +481,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 +518,7 @@ 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 +527,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 +549,7 @@ 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 +557,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 +567,7 @@ 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..668d0e1 100644 --- a/src/chits/settings.py +++ b/src/chits/settings.py @@ -84,7 +84,7 @@ if os.environ.get('SQLITE','False') == 'True': DATABASES['default'] = { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, '..', 'chit_data.sqlite3'), + 'NAME': os.path.join(BASE_DIR, 'chit_data.sqlite3'), } if 'DATABASE_URL' in os.environ: @@ -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..494c7ea 100644 --- a/src/chits/urls.py +++ b/src/chits/urls.py @@ -9,7 +9,7 @@ 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 +17,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), From 8b68a47b43a3c53011d15dd20a6fe8181e599e87 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:06:08 +0530 Subject: [PATCH 03/11] removed .env file --- src/.env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/.env diff --git a/src/.env b/src/.env deleted file mode 100644 index 16ef7e8..0000000 --- a/src/.env +++ /dev/null @@ -1 +0,0 @@ -export SQLITE=True From 6393e11b3dd46f1dd346a93ac2370b4decec7da9 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:07:54 +0530 Subject: [PATCH 04/11] Removed .env second file --- src/.env | 1 - 1 file changed, 1 deletion(-) delete mode 100644 src/.env diff --git a/src/.env b/src/.env deleted file mode 100644 index 16ef7e8..0000000 --- a/src/.env +++ /dev/null @@ -1 +0,0 @@ -export SQLITE=True From f9c5ccbbd3d89beedc520ff557375476c76c483b Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:16:24 +0530 Subject: [PATCH 05/11] reverted to old code --- src/chits/settings.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/chits/settings.py b/src/chits/settings.py index 668d0e1..5c1761e 100644 --- a/src/chits/settings.py +++ b/src/chits/settings.py @@ -84,7 +84,7 @@ if os.environ.get('SQLITE','False') == 'True': DATABASES['default'] = { 'ENGINE': 'django.db.backends.sqlite3', - 'NAME': os.path.join(BASE_DIR, 'chit_data.sqlite3'), + 'NAME': os.path.join(BASE_DIR, '..', 'chit_data.sqlite3'), } if 'DATABASE_URL' in os.environ: From 1dfbae4ea1e576fb08d25c1308a716edb27bcf96 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:25:37 +0530 Subject: [PATCH 06/11] Removing unnecessary lines / comments --- src/chit_main_app/views.py | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/src/chit_main_app/views.py b/src/chit_main_app/views.py index ef03c25..d66d028 100644 --- a/src/chit_main_app/views.py +++ b/src/chit_main_app/views.py @@ -88,9 +88,6 @@ def group_list(request): auctions_left[g.id] = g.total_months - auctions_done.get(g.id, 0) template = loader.get_template('groups/list.html') -######################################################################### - #silly = Loan.objects.filter(identity = request.GET['id']) -######################################################################### context = { 'group_list': group_list, 'due_amounts': due_amounts, @@ -236,8 +233,8 @@ def customersgroups(request): 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'] - silly = Loan.objects.filter(identity=request.GET['id']) - for l in silly : + customer_loan = Loan.objects.filter(identity=request.GET['id']) + for l in customer_loan : if l.approved_date.year == datetime.today().strftime("%Y"): if l.approved_date.month == datetime.today().strftime("%m"): l.accumulated_interest = 0 @@ -248,7 +245,7 @@ def customersgroups(request): 'customer_details':customer_details, 'due_amounts': due_amounts, 'total_due': sum(iter(due_amounts.values())), - 'silly': silly + 'customer_loan': customer_loan } template = loader.get_template('customers/grouplist.html') @@ -379,13 +376,13 @@ def new_loan(request): template = loader.get_template('customers/loan_registration.html') return HttpResponse(template.render({})) elif request.method == 'POST': - loo = Loan() - loo.loan_amount = request.POST['loanAmount'] - loo.interest = request.POST['ROI'] - loo.approved_date = request.POST['DOS'] - loo.loan_name = request.POST['loanName'] - loo.identity = Customer.objects.get(id=request.GET['cid']) - loo.save() + 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.save() return HttpResponseRedirect('/customers/grouplist?id='+request.GET['cid']) @login_required From aecb8e18a00c8b1d34359c0fc747fba4e59894c2 Mon Sep 17 00:00:00 2001 From: NARAYANA SHANMUKHA VENKAT Date: Tue, 5 Jun 2018 12:26:53 +0530 Subject: [PATCH 07/11] changing variable names as per requirements --- src/chit_main_app/templates/customers/loan_registration.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/chit_main_app/templates/customers/loan_registration.html b/src/chit_main_app/templates/customers/loan_registration.html index 0550629..78c7ef7 100644 --- a/src/chit_main_app/templates/customers/loan_registration.html +++ b/src/chit_main_app/templates/customers/loan_registration.html @@ -15,11 +15,11 @@
Rate of Interest :
Date of Sanction:
Due Payment
diff --git a/src/chit_main_app/views.py b/src/chit_main_app/views.py index d66d028..3f629e9 100644 --- a/src/chit_main_app/views.py +++ b/src/chit_main_app/views.py @@ -91,8 +91,7 @@ def group_list(request): context = { 'group_list': group_list, 'due_amounts': due_amounts, - 'auctions_left': auctions_left, - # 'silly': silly + 'auctions_left': auctions_left } return HttpResponse(template.render(context)) From 62b58af206ef15a9e42251e9d2bb1392f3491b17 Mon Sep 17 00:00:00 2001 From: yukesh Date: Fri, 15 Jun 2018 00:36:41 +0530 Subject: [PATCH 10/11] loan transaction history --- src/chit_main_app/migrations/0001_initial.py | 26 +++++- .../migrations/0002_auto_20180523_0654.py | 20 ----- src/chit_main_app/migrations/0003_loan.py | 26 ------ .../migrations/0004_auto_20180529_0621.py | 25 ------ .../migrations/0005_auto_20180529_1028.py | 20 ----- .../migrations/0006_auto_20180604_0806.py | 33 -------- .../migrations/0007_auto_20180605_0712.py | 21 ----- src/chit_main_app/models.py | 8 +- .../templates/customers/history.html | 30 ++++++- .../templates/customers/list.html | 5 ++ src/chit_main_app/views.py | 83 ++++++++++++------- src/chits/settings.py | 6 +- src/chits/urls.py | 3 +- 13 files changed, 122 insertions(+), 184 deletions(-) delete mode 100644 src/chit_main_app/migrations/0002_auto_20180523_0654.py delete mode 100644 src/chit_main_app/migrations/0003_loan.py delete mode 100644 src/chit_main_app/migrations/0004_auto_20180529_0621.py delete mode 100644 src/chit_main_app/migrations/0005_auto_20180529_1028.py delete mode 100644 src/chit_main_app/migrations/0006_auto_20180604_0806.py delete mode 100644 src/chit_main_app/migrations/0007_auto_20180605_0712.py 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/migrations/0002_auto_20180523_0654.py b/src/chit_main_app/migrations/0002_auto_20180523_0654.py deleted file mode 100644 index c985a60..0000000 --- a/src/chit_main_app/migrations/0002_auto_20180523_0654.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-23 06:54 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='journal', - name='entry_type', - field=models.CharField(choices=[('A', 'Auction'), ('P', 'Payment'), ('D', 'Disbursement')], max_length=10), - ), - ] diff --git a/src/chit_main_app/migrations/0003_loan.py b/src/chit_main_app/migrations/0003_loan.py deleted file mode 100644 index 74908f7..0000000 --- a/src/chit_main_app/migrations/0003_loan.py +++ /dev/null @@ -1,26 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-29 05:15 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0002_auto_20180523_0654'), - ] - - operations = [ - 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()), - ('cid', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Customer')), - ], - ), - ] diff --git a/src/chit_main_app/migrations/0004_auto_20180529_0621.py b/src/chit_main_app/migrations/0004_auto_20180529_0621.py deleted file mode 100644 index 5f10c49..0000000 --- a/src/chit_main_app/migrations/0004_auto_20180529_0621.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-29 06:21 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0003_loan'), - ] - - operations = [ - migrations.RenameField( - model_name='loan', - old_name='cid', - new_name='ccid', - ), - migrations.AddField( - model_name='loan', - name='loan_name', - field=models.CharField(max_length=30, null=True), - ), - ] diff --git a/src/chit_main_app/migrations/0005_auto_20180529_1028.py b/src/chit_main_app/migrations/0005_auto_20180529_1028.py deleted file mode 100644 index 628ffba..0000000 --- a/src/chit_main_app/migrations/0005_auto_20180529_1028.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-05-29 10:28 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0004_auto_20180529_0621'), - ] - - operations = [ - migrations.RenameField( - model_name='loan', - old_name='ccid', - new_name='identity', - ), - ] diff --git a/src/chit_main_app/migrations/0006_auto_20180604_0806.py b/src/chit_main_app/migrations/0006_auto_20180604_0806.py deleted file mode 100644 index baa5c55..0000000 --- a/src/chit_main_app/migrations/0006_auto_20180604_0806.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-04 08:06 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0005_auto_20180529_1028'), - ] - - operations = [ - migrations.CreateModel( - name='loan_history', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('last_payment_date', models.DateField()), - ], - ), - migrations.AddField( - model_name='loan', - name='accumulated_interest', - field=models.IntegerField(default=0), - ), - migrations.AddField( - model_name='loan_history', - name='key', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Loan'), - ), - ] diff --git a/src/chit_main_app/migrations/0007_auto_20180605_0712.py b/src/chit_main_app/migrations/0007_auto_20180605_0712.py deleted file mode 100644 index 039b4ff..0000000 --- a/src/chit_main_app/migrations/0007_auto_20180605_0712.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.11 on 2018-06-05 07:12 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('chit_main_app', '0006_auto_20180604_0806'), - ] - - operations = [ - migrations.AlterField( - model_name='loan_history', - name='key', - field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.CASCADE, to='chit_main_app.Loan'), - ), - ] diff --git a/src/chit_main_app/models.py b/src/chit_main_app/models.py index 67907c4..4c86332 100644 --- a/src/chit_main_app/models.py +++ b/src/chit_main_app/models.py @@ -1,7 +1,6 @@ from django.db import models from django.contrib.auth.models import User -from datetime import date - +from datetime import date, datetime # Create your models here . class Group(models.Model): @@ -51,9 +50,12 @@ class Loan(models.Model): 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 loan_history(models.Model): +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/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 09dde85..7319034 100644 --- a/src/chit_main_app/templates/customers/list.html +++ b/src/chit_main_app/templates/customers/list.html @@ -42,6 +42,11 @@ for(id in data){ $("#current-amount-"+id).html(data[id]) } }) }) + $('#datepicker').change(function(){ + $.get('/customers/daily_collection',{date:$('#datepicker').val()}).done(function(data){ + for(id in data){ $("#current-amount-"+id).html(data[id]) } + }) + }) }); diff --git a/src/chit_main_app/views.py b/src/chit_main_app/views.py index 3f629e9..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, Loan,loan_history +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 @@ -134,6 +134,7 @@ def new_customer(request): 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']) @@ -196,7 +197,6 @@ def customershistory(request): "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 @@ -219,8 +219,15 @@ def customershistory(request): "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)) @@ -234,11 +241,16 @@ def customersgroups(request): 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 : - if l.approved_date.year == datetime.today().strftime("%Y"): - if l.approved_date.month == datetime.today().strftime("%m"): - l.accumulated_interest = 0 - else: - 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 + #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, @@ -381,6 +393,7 @@ def new_loan(request): 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']) @@ -419,30 +432,47 @@ def record_customer_payment(request): @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() - else: - if int(request.POST[k]) < l.accumulated_interest : - l.accumulated_interest = l.accumulated_interest - int(request.POST[k]) - l.save() - h = loan_history(key = l) - h.last_payment_date = request.POST['loan_payment_date'] - h.save() - else: - l.loan_amount = l.loan_amount + l.accumulated_interest - int(request.POST[k]) - l.accumulated_interest = 0 - l.save() - from pprint import pprint - pprint(request.POST) - h = loan_history(key= l) - h.last_payment_date = request.POST['loan_payment_date'] - h.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 def new_mobile_number(request): m = Customer.objects.get(id=request.GET['id']) @@ -514,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) @@ -545,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: @@ -563,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 5c1761e..269d3d2 100644 --- a/src/chits/settings.py +++ b/src/chits/settings.py @@ -72,10 +72,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - #'NAME':'chitmanager', - 'NAME': 'heroku_e18935074c20bff', + 'NAME':'chitmanager', + #'NAME': 'heroku_e18935074c20bff', 'USER': 'root', - 'PASSWORD':'', + 'PASSWORD':'vikky', 'HOST': '', 'PORT': '', } diff --git a/src/chits/urls.py b/src/chits/urls.py index 494c7ea..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,7 +16,7 @@ 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'^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), From 84ae338febd559efeded0b14ed66be5549ab7a81 Mon Sep 17 00:00:00 2001 From: yukesh Date: Fri, 15 Jun 2018 09:56:13 +0530 Subject: [PATCH 11/11] settings file changed to earlierstage --- src/chits/settings.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/chits/settings.py b/src/chits/settings.py index 269d3d2..5633488 100644 --- a/src/chits/settings.py +++ b/src/chits/settings.py @@ -72,10 +72,10 @@ DATABASES = { 'default': { 'ENGINE': 'django.db.backends.mysql', - 'NAME':'chitmanager', - #'NAME': 'heroku_e18935074c20bff', + #'NAME':'chitmanager', + 'NAME': 'heroku_e18935074c20bff', 'USER': 'root', - 'PASSWORD':'vikky', + 'PASSWORD':'karthik', 'HOST': '', 'PORT': '', }