diff --git a/blocnote/apps/financialInputs/migrations/0001_initial.py b/blocnote/apps/financialInputs/migrations/0001_initial.py index 934afed6c8470922d73f813e67723908b2d77ff9..a5df4f736295e0b9109fdc549d5f50c77759e1c7 100644 --- a/blocnote/apps/financialInputs/migrations/0001_initial.py +++ b/blocnote/apps/financialInputs/migrations/0001_initial.py @@ -1,5 +1,5 @@ # -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-12 15:19 +# Generated by Django 1.10.6 on 2017-04-27 19:42 from __future__ import unicode_literals from django.db import migrations, models @@ -14,16 +14,75 @@ class Migration(migrations.Migration): ] operations = [ + migrations.CreateModel( + name='Bills', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('building_id', models.IntegerField()), + ('date_from', models.DateField()), + ('date_to', models.DateField()), + ('utility_type', models.CharField(max_length=11)), + ('usage', models.DecimalField(decimal_places=2, max_digits=10)), + ('charge', models.DecimalField(decimal_places=2, max_digits=10)), + ], + ), + migrations.CreateModel( + name='BillsOverview', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('building_id', models.IntegerField()), + ('year', models.DecimalField(decimal_places=0, max_digits=4)), + ('electricity', models.DecimalField(decimal_places=2, max_digits=10)), + ('electricity_is_user_input', models.BooleanField(default=False)), + ('water', models.DecimalField(decimal_places=2, max_digits=10)), + ('water_is_user_input', models.BooleanField(default=False)), + ('oil', models.DecimalField(decimal_places=2, max_digits=10)), + ('oil_is_user_input', models.BooleanField(default=False)), + ('gas', models.DecimalField(decimal_places=2, max_digits=10)), + ('gas_is_user_input', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='CashBalance', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('building_id', models.IntegerField()), + ('statement_date', models.DateField()), + ('is_from_balance_sheet', models.BooleanField(default=False)), + ('balance_amount', models.DecimalField(decimal_places=2, max_digits=10)), + ], + ), + migrations.CreateModel( + name='CustomerPreference', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('building_id', models.IntegerField()), + ('downpayment', models.DecimalField(decimal_places=2, max_digits=10)), + ('expected_payback', models.DecimalField(decimal_places=0, max_digits=3)), + ('expected_net_noi_dscr', models.DecimalField(decimal_places=2, max_digits=5)), + ], + ), + migrations.CreateModel( + name='EstimationAlgorithm', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('algorithm', models.CharField(max_length=16)), + ('building_id', models.IntegerField()), + ], + ), migrations.CreateModel( name='FinancingOverview', fields=[ ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), ('building_id', models.IntegerField()), - ('required_noi_dscr', models.DecimalField(decimal_places=2, max_digits=5)), - ('requrired_cash_dscr', models.DecimalField(decimal_places=2, max_digits=5)), + ('required_noi_dscr', models.DecimalField(decimal_places=2, default=0, max_digits=5)), + ('requrired_cash_dscr', models.DecimalField(decimal_places=2, default=0, max_digits=5)), + ('pro_forma_start_date', models.DateField()), + ('pro_forma_duration', models.DecimalField(decimal_places=0, max_digits=2)), + ('analysis_date', models.DateField()), ('anticipated_construction_start_date', models.DateField()), ('anticipated_commissioning_date', models.DateField()), - ('anticipated_construction_period', models.DecimalField(decimal_places=0, max_digits=2)), + ('anticipated_construction_period', models.DecimalField(decimal_places=0, max_digits=3)), ], ), migrations.CreateModel( @@ -33,9 +92,20 @@ class Migration(migrations.Migration): ('Name', models.CharField(max_length=200)), ], ), + migrations.CreateModel( + name='Liabilities', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('building_id', models.IntegerField()), + ('input_date', models.DateField()), + ('lender', models.CharField(max_length=150)), + ('monthly_service', models.DecimalField(decimal_places=2, max_digits=10)), + ('remaining_term', models.DecimalField(decimal_places=0, max_digits=3)), + ], + ), migrations.AddField( model_name='financingoverview', name='fund', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='financialInputs.Fund'), + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='financialInputs.Fund'), ), ] diff --git a/blocnote/apps/financialInputs/migrations/0002_auto_20170412_2043.py b/blocnote/apps/financialInputs/migrations/0002_auto_20170412_2043.py deleted file mode 100644 index bb6bee6ae8aae9983dd72ac6ec54d9b55b0d6c5a..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0002_auto_20170412_2043.py +++ /dev/null @@ -1,31 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-12 20:43 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0001_initial'), - ] - - operations = [ - migrations.AlterField( - model_name='financingoverview', - name='fund', - field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='financialInputs.Fund'), - ), - migrations.AlterField( - model_name='financingoverview', - name='required_noi_dscr', - field=models.DecimalField(decimal_places=2, default=0, max_digits=5), - ), - migrations.AlterField( - model_name='financingoverview', - name='requrired_cash_dscr', - field=models.DecimalField(decimal_places=2, default=0, max_digits=5), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0003_auto_20170412_2143.py b/blocnote/apps/financialInputs/migrations/0003_auto_20170412_2143.py deleted file mode 100644 index 29295423a4aae5474ae5b5b171f05fc9cf7ebc29..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0003_auto_20170412_2143.py +++ /dev/null @@ -1,21 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-12 21:43 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0002_auto_20170412_2043'), - ] - - operations = [ - migrations.AlterField( - model_name='financingoverview', - name='fund', - field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='financialInputs.Fund'), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0004_auto_20170412_2153.py b/blocnote/apps/financialInputs/migrations/0004_auto_20170412_2153.py deleted file mode 100644 index ca3454003527e023f27ee4850f5fc0fc35c44237..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0004_auto_20170412_2153.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-12 21:53 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0003_auto_20170412_2143'), - ] - - operations = [ - migrations.AlterField( - model_name='financingoverview', - name='anticipated_construction_period', - field=models.DecimalField(decimal_places=0, max_digits=4), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0005_auto_20170413_1530.py b/blocnote/apps/financialInputs/migrations/0005_auto_20170413_1530.py deleted file mode 100644 index 3086180e64810a89ca2dddfcf4620f742331c8b9..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0005_auto_20170413_1530.py +++ /dev/null @@ -1,33 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-13 15:30 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0004_auto_20170412_2153'), - ] - - operations = [ - migrations.AddField( - model_name='financingoverview', - name='analysis_date', - field=models.DateField(default='2017-01-01'), - preserve_default=False, - ), - migrations.AddField( - model_name='financingoverview', - name='pro_forma_duration', - field=models.DecimalField(decimal_places=0, default=2, max_digits=2), - preserve_default=False, - ), - migrations.AddField( - model_name='financingoverview', - name='pro_forma_start_date', - field=models.DateField(default='2017-01-01'), - preserve_default=False, - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0006_auto_20170413_1533.py b/blocnote/apps/financialInputs/migrations/0006_auto_20170413_1533.py deleted file mode 100644 index a10168597e492fc49dafc85978c7e816be95b0e4..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0006_auto_20170413_1533.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-13 15:33 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0005_auto_20170413_1530'), - ] - - operations = [ - migrations.AlterField( - model_name='financingoverview', - name='anticipated_construction_period', - field=models.DecimalField(decimal_places=0, max_digits=3), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0007_bills.py b/blocnote/apps/financialInputs/migrations/0007_bills.py deleted file mode 100644 index cf6002808452df06658696372ffd4dbe8fee51af..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0007_bills.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-17 15:04 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0006_auto_20170413_1533'), - ] - - operations = [ - migrations.CreateModel( - name='Bills', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('building_id', models.IntegerField()), - ('date_from', models.DateField()), - ('date_to', models.DateField()), - ('utility_type', models.CharField(max_length=11)), - ('usage', models.DecimalField(decimal_places=2, max_digits=6)), - ('charge', models.DecimalField(decimal_places=2, max_digits=10)), - ], - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0008_auto_20170417_2026.py b/blocnote/apps/financialInputs/migrations/0008_auto_20170417_2026.py deleted file mode 100644 index 3ecb611b8ef94452420c6e61c5a5611fda2608dc..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0008_auto_20170417_2026.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-17 20:26 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0007_bills'), - ] - - operations = [ - migrations.AlterField( - model_name='bills', - name='usage', - field=models.DecimalField(decimal_places=2, max_digits=10), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0009_billsoverview.py b/blocnote/apps/financialInputs/migrations/0009_billsoverview.py deleted file mode 100644 index 6f0b789ce5f777dfe621e5a07a64cabe604531fe..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0009_billsoverview.py +++ /dev/null @@ -1,24 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-17 23:20 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0008_auto_20170417_2026'), - ] - - operations = [ - migrations.CreateModel( - name='BillsOverview', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('building_id', models.IntegerField()), - ('year', models.DecimalField(decimal_places=0, max_digits=4)), - ('estimation_algorithm', models.CharField(choices=[('FR', 'Freshman'), ('SO', 'Sophomore'), ('JR', 'Junior'), ('SR', 'Senior')], max_length=100)), - ], - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0010_auto_20170417_2338.py b/blocnote/apps/financialInputs/migrations/0010_auto_20170417_2338.py deleted file mode 100644 index 5a4c4fd2850f30f2dcd8f59bd9f8ec9a01278fd5..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0010_auto_20170417_2338.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-17 23:38 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0009_billsoverview'), - ] - - operations = [ - migrations.AlterField( - model_name='billsoverview', - name='estimation_algorithm', - field=models.CharField(max_length=100), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0011_auto_20170418_0232.py b/blocnote/apps/financialInputs/migrations/0011_auto_20170418_0232.py deleted file mode 100644 index 8198ef55d1219d378f4dabb3d10a0da9892d922f..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0011_auto_20170418_0232.py +++ /dev/null @@ -1,59 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-18 02:32 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0010_auto_20170417_2338'), - ] - - operations = [ - migrations.AddField( - model_name='billsoverview', - name='electricity', - field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10), - preserve_default=False, - ), - migrations.AddField( - model_name='billsoverview', - name='electricity_is_user_input', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='billsoverview', - name='gas', - field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10), - preserve_default=False, - ), - migrations.AddField( - model_name='billsoverview', - name='gas_is_user_input', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='billsoverview', - name='oil', - field=models.DecimalField(decimal_places=2, default=0.0, max_digits=10), - preserve_default=False, - ), - migrations.AddField( - model_name='billsoverview', - name='oil_is_user_input', - field=models.BooleanField(default=False), - ), - migrations.AddField( - model_name='billsoverview', - name='water', - field=models.DecimalField(decimal_places=2, default=0, max_digits=10), - preserve_default=False, - ), - migrations.AddField( - model_name='billsoverview', - name='water_is_user_input', - field=models.BooleanField(default=False), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0012_customerpreference.py b/blocnote/apps/financialInputs/migrations/0012_customerpreference.py deleted file mode 100644 index 2b643cf26b5b284d6b6a1860f98f93a5f436a2bd..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0012_customerpreference.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-19 20:58 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0011_auto_20170418_0232'), - ] - - operations = [ - migrations.CreateModel( - name='CustomerPreference', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('building_id', models.IntegerField()), - ('downpayment', models.DecimalField(decimal_places=2, max_digits=10)), - ('expected_payback', models.DecimalField(decimal_places=0, max_digits=3)), - ('expected_net_noi_dscr', models.DecimalField(decimal_places=2, max_digits=5)), - ], - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0013_auto_20170424_2158.py b/blocnote/apps/financialInputs/migrations/0013_auto_20170424_2158.py deleted file mode 100644 index 781d3464cd0629f108aebe0392a0987857d9ae3b..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0013_auto_20170424_2158.py +++ /dev/null @@ -1,27 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-24 21:58 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0012_customerpreference'), - ] - - operations = [ - migrations.CreateModel( - name='EstimationAlgorithm', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('building_id', models.IntegerField()), - ('algorithm', models.CharField(max_length=100)), - ], - ), - migrations.RemoveField( - model_name='billsoverview', - name='estimation_algorithm', - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0013_cashbalance.py b/blocnote/apps/financialInputs/migrations/0013_cashbalance.py deleted file mode 100644 index 7fe295254e952dc6bd274b5b98bc2a3413ee6264..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0013_cashbalance.py +++ /dev/null @@ -1,25 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-20 15:12 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0012_customerpreference'), - ] - - operations = [ - migrations.CreateModel( - name='CashBalance', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('building_id', models.IntegerField()), - ('date', models.DateField()), - ('is_from_balance_sheet', models.BooleanField(default=False)), - ('balance_amount', models.DecimalField(decimal_places=2, max_digits=10)), - ], - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0014_auto_20170421_0004.py b/blocnote/apps/financialInputs/migrations/0014_auto_20170421_0004.py deleted file mode 100644 index b737b5103ca1ff7f846671e37e117bc98853cd10..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0014_auto_20170421_0004.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-21 00:04 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0013_cashbalance'), - ] - - operations = [ - migrations.RenameField( - model_name='cashbalance', - old_name='date', - new_name='start_date', - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0015_auto_20170424_2250.py b/blocnote/apps/financialInputs/migrations/0015_auto_20170424_2250.py deleted file mode 100644 index e350b035d62e87880c7bb1b48c93568b0297324e..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0015_auto_20170424_2250.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-24 22:50 -from __future__ import unicode_literals - -from django.db import migrations, models - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0013_auto_20170424_2158'), - ] - - operations = [ - migrations.AlterField( - model_name='estimationalgorithm', - name='algorithm', - field=models.CharField(max_length=16), - ), - ] diff --git a/blocnote/apps/financialInputs/migrations/0016_merge_20170427_1611.py b/blocnote/apps/financialInputs/migrations/0016_merge_20170427_1611.py deleted file mode 100644 index ef9d47626f40036ec9f5fc0bd2c2201867807423..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0016_merge_20170427_1611.py +++ /dev/null @@ -1,16 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-27 16:11 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0015_auto_20170424_2250'), - ('financialInputs', '0014_auto_20170421_0004'), - ] - - operations = [ - ] diff --git a/blocnote/apps/financialInputs/migrations/0017_auto_20170427_1900.py b/blocnote/apps/financialInputs/migrations/0017_auto_20170427_1900.py deleted file mode 100644 index a014e1d6c8c479d0b3dbf9e7f51f1755ea2105d3..0000000000000000000000000000000000000000 --- a/blocnote/apps/financialInputs/migrations/0017_auto_20170427_1900.py +++ /dev/null @@ -1,20 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.6 on 2017-04-27 19:00 -from __future__ import unicode_literals - -from django.db import migrations - - -class Migration(migrations.Migration): - - dependencies = [ - ('financialInputs', '0016_merge_20170427_1611'), - ] - - operations = [ - migrations.RenameField( - model_name='cashbalance', - old_name='start_date', - new_name='statement_date', - ), - ] diff --git a/blocnote/apps/financialInputs/models.py b/blocnote/apps/financialInputs/models.py index 8de7ff47b6acbb3515020345db0e29a10b9dc64a..16d26d4ee2250e637770260e315026548ee10067 100644 --- a/blocnote/apps/financialInputs/models.py +++ b/blocnote/apps/financialInputs/models.py @@ -73,6 +73,16 @@ class CustomerPreference(models.Model): expected_net_noi_dscr = models.DecimalField(max_digits=5, decimal_places=2) +class Liabilities(models.Model): + """Store Mortgage and Liability information for a building id.""" + + building_id = models.IntegerField() + input_date = models.DateField() + lender = models.CharField(max_length=150) + monthly_service = models.DecimalField(max_digits=10, decimal_places=2) + remaining_term = models.DecimalField(max_digits=3, decimal_places=0) + + class CashBalance(models.Model): """Store Balance amount information. diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 594149fdd0f94dad4e445cacc429d433af425cdd..7b871edaed4b178d398a50641e1af31cff3ed838 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -4,13 +4,8 @@ for (var utility_index in utilities) { } loadBillsOverview(); getCustomerPreferenceTable(); +getLiabilitiesTable(); getCashBalanceForm(); -/**nextCashBalanceRowID is used to uniquely identify the row of the cash balance table. This does NOT represent the - * actual row number. It represents the total number of rows added. This does NOT get decremented on deleting - * a row. This is so that each new row has a new number in its id so that information can be obtained and sent - * to backend. - */ -var nextCashBalanceRowID = 0; /** * Handle submition of the header form. Validate commissioning date is greater @@ -312,7 +307,7 @@ function createCalculateButton() { /**Create button to submit the projected and input data. */ function createSubmitButton() { text = ` -
+
`; @@ -430,29 +425,31 @@ function createCustomerPreferenceTable(instance) { var expectedPayback = instance['expected_payback']; var expectedNetNOIDSCR = instance['expected_net_noi_dscr'] } - var text = ` - - - - - - - - - - - - - - - - - - - - -
PreferenceValue
Affordable Downpayment
Expected PaybackMonths
Expected Net NOI DSCR
- ` + var text = ` + + + + + + + + + + + + + + + + + + + + + +
PreferenceValue
Affordable Downpayment
Expected PaybackMonths
Expected Net NOI DSCR
+ + `; customerPreferenceForm.innerHTML = text; } @@ -469,6 +466,112 @@ function getCustomerPreferenceTable() { }); } +/** + * Load the Mortgage and Liabilities table. + * This function loads the mortgage and liabilities table with the given inputList. If inputList is empty, it loads a + * row with empty inputs and 1/1/1980 date as default values. + */ +function loadLiabilitiesTable(inputList) { + table = document.querySelector('#liabilities-table'); + if (inputList.length === 0) { + addLiabilitiesRow('', '', '', 1, 1, 1980); + } + else { + inputList.map(function(record, index) { + record = inputList[index]; + lender = record['lender'] + service = record['monthly_service'] + term = record['remaining_term'] + date = record['input_date'].split('-'); + month = Number(date[1]); + day = Number(date[2]); + year = Number(date[0]); + addLiabilitiesRow(lender, service, term, month, day, year); + }); + } +} + +/**Add a new row to Mortgage and Liabilities table. */ +function addLiabilitiesRow(lender, service, term, month, day, year) { + table = document.querySelector('#liabilities-table tbody'); + var rowCount = table.rows.length; + var row = table.insertRow(rowCount); + var cell = row.insertCell(0); + cell.innerHTML = `Debt ${rowCount + 1}`; + cell = row.insertCell(1); + cell.innerHTML = ` + + `; + cell = row.insertCell(2); + cell.innerHTML = ` + + `; + cell = row.insertCell(3); + cell.innerHTML = ` + + `; + cell = row.insertCell(4); + cell.innerHTML = createDateComponent(month, day, year); + cell = row.insertCell(5); + cell.innerHTML = ` +
+ +
+ `; +} + +/**Delete a row from the Mortgage and Liabilities table. */ +function deleteLiabilitiesRow(rowIndex) { + table = document.querySelector('#liabilities-table'); + table.deleteRow(rowIndex); + var rowCount = table.rows.length; + for (var rowInd = 1; rowInd < rowCount; rowInd++) { + row = table.rows.item(rowInd).cells; + row.item(0).innerHTML = `Debt ${rowInd}`; + } + return false; +} + +/**HTTP PUT request with the user inputs for Mortgage and Liability. */ +function liabilitiesSubmitForm(form) { + table = document.querySelector('#liabilities-table'); + var rowCount = table.rows.length; + var result = []; + for (rowInd = 1; rowInd < rowCount; rowInd++) { + record = {}; + record['lender'] = table.rows[rowInd].cells[1].children[0].value; + record['monthly-service'] = table.rows[rowInd].cells[2].children[0].value; + record['remaining-term'] = table.rows[rowInd].cells[3].children[0].value; + record['date-month'] = table.rows[rowInd].cells[4].children[0].value; + record['date-day'] = table.rows[rowInd].cells[4].children[1].value; + record['date-year'] = table.rows[rowInd].cells[4].children[2].value; + result.push(record); + } + request('liabilities/', { + method: 'PUT', + credentials: 'same-origin', + body: JSON.stringify(result), + headers: new Headers({ + 'Content-Type': 'application/json', + 'X-CSRFToken': Cookies.get('csrftoken') + }) + }); + return false; +} + +/**HTTP GET request for any Mortgage and Liability data for the building id. */ +function getLiabilitiesTable() { + request(`liabilities/`, { + method: 'GET', + credentials: 'same-origin', + headers: { + 'Content-Type': 'application/json' + }, + }).then(res => { + loadLiabilitiesTable(res.payload.instance); + }); +} + /**Send HTTP GET request to obtain all cash balance records. */ function getCashBalanceForm() { request(`cash-balance/`, { @@ -513,7 +616,7 @@ function getCashBalanceCheckBox(isFromBalanceSheet) { } var text = ` `; return text; @@ -535,14 +638,14 @@ function deleteCashBalanceRow(row) { * balance sheet or not. */ function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { - table = document.querySelector('#cash-balance-table'); + table = document.querySelector('#cash-balance-table tbody'); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); cell.innerHTML += `${rowCount}`; cell = row.insertCell(1); cell.innerHTML += ` - + `; cell = row.insertCell(2); cell.innerHTML += ` @@ -554,7 +657,6 @@ function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { cell.innerHTML += ` `; - nextCashBalanceRowID += 1; return false; } @@ -588,13 +690,13 @@ function submitCashBalanceForm(form) { } /**Create the select date component.*/ -function createDateComponent(mon, day, yr) { +function createDateComponent(mon, day, yr, num) { months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; selectMonth = ``; selectDay = ``; selectYear = ``; var text = ` - `; for (var month = 0; month < 12; month++) { if (mon-1 === month){ @@ -610,7 +712,7 @@ function createDateComponent(mon, day, yr) { text += ` - `; for (var d=0; d<31; d++) { @@ -626,7 +728,7 @@ function createDateComponent(mon, day, yr) { } text += ` - `; for (var year=1980; year <= 2080; year++) { diff --git a/blocnote/apps/financialInputs/templates/financialInputs/bills.html b/blocnote/apps/financialInputs/templates/financialInputs/bills.html index b57366d474d7b0149e8f15da4fc23a46cc20d1d4..5af7c7961b932a07d5739f4ee3b51ebcc5ee3cae 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/bills.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/bills.html @@ -24,10 +24,10 @@
-
-
-
-
+
No Bills available
+
No Bills available
+
No Bills available
+
No Bills available
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/billsOverview.html b/blocnote/apps/financialInputs/templates/financialInputs/billsOverview.html index c0154420e77c83c51d854b9fb38fbe33d62ea1a7..a1e6de82bbf54cee31ddbe6129b0ea8325bd33e7 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/billsOverview.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/billsOverview.html @@ -1,5 +1,5 @@

Energy Bills Overview

-
+
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html index c6975d9052daa80faa1a39a19b64ea21281280c8..b3280081c8da99d15b7c6f480aa25823b40fee4b 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html @@ -1,10 +1,8 @@

Cash Balance -

+
-
- -
+ @@ -15,10 +13,10 @@ + +
Option
-
-
- -
-
+
+ +
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/index.html b/blocnote/apps/financialInputs/templates/financialInputs/index.html index 6a4a298da2bad4d967b762f3823b92a29109a9ec..25174a020214e199257dd30b9e56911c5bade034 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/index.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/index.html @@ -17,16 +17,29 @@
- {% include "financialInputs/bills.html" %} +
+ {% include "financialInputs/bills.html" %} +
+
+
+
+ {% include "financialInputs/billsOverview.html" %} +
- {% include "financialInputs/billsOverview.html" %} +
+ {% include "financialInputs/cashBalance.html" %} +
- {% include "financialInputs/cashBalance.html" %} +
+ {% include "financialInputs/liabilities.html" %} +
- {% include "financialInputs/customerPreference.html" %} +
+ {% include "financialInputs/customerPreference.html" %} +
{% endblock %} {% block scripts %} diff --git a/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html b/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html new file mode 100644 index 0000000000000000000000000000000000000000..48062446d88a4355f764d6b893ef366f10d9c03c --- /dev/null +++ b/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html @@ -0,0 +1,23 @@ +
+

Mortgage and Liabilities

+
+
+ + + + + + + + + + + + + + +
DebtLender NameMonthly ServiceRemaining TermsInput DateOption
+
+
+ +
diff --git a/blocnote/apps/financialInputs/urls.py b/blocnote/apps/financialInputs/urls.py index e84aa1cbd7823f01bd98b9802b5c198137efd3a3..0a0786b2d955a1ac33643c16746046b69f58b7ba 100644 --- a/blocnote/apps/financialInputs/urls.py +++ b/blocnote/apps/financialInputs/urls.py @@ -8,5 +8,6 @@ urlpatterns = [ url(r'^bills/$', views.BillsTable.as_view(), name='bills'), url(r'^bills-overview/$', views.BillsOverviewView.as_view(), name='bills_overview'), url(r'^customer-preference/$', views.CustomerPreferenceView.as_view(), name='customer_preference'), + url(r'^liabilities/$', views.LiabilitiesTable.as_view(), name='liabilities'), url(r'^cash-balance/$', views.CashBalanceView.as_view(), name='cash_balance'), ] diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index cb55f7bd60bf78dbfbf3a6da17ed03ae127739e5..ea50b691b20d80b64c65d24955c75edb6fec2956 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -8,7 +8,7 @@ from datetime import date from bpfin.utilbills.bill_backend_call import bill_prior_proj_rough_annual from bpfin.financials.cash_balance import cash_balance -from .models import FinancingOverview, Bills, BillsOverview, CustomerPreference, EstimationAlgorithm, CashBalance +from .models import FinancingOverview, Bills, BillsOverview, CustomerPreference, EstimationAlgorithm, Liabilities, CashBalance from .forms import BlocNoteHeaderForm @@ -230,7 +230,7 @@ class BillsTable(View): date_to_index = index elif heading == "Usage": usage_index = index - elif heading == "Total Charges": + elif "Total Charges" in heading: charge_index = index result = [] @@ -605,6 +605,66 @@ class CustomerPreferenceView(View): return JsonResponse({'instance': instance}) +class LiabilitiesTable(View): + """Store and load Mortgage and Liability information for a building id.""" + + model = Liabilities + + def get(self, request, building_id): + """HTTP GET request. + + Fetch Mortgage and Liability information from the database and return to the frontend. + + Args: + request: HTTP GET request. + building_id: id of the building. + + Returns: + JsonResponse: List of records. Each record is a dictionary with key as the attribute name and value + as the value. + """ + objs = self.model.objects.filter(building_id=building_id) + result = [] + if objs: + for obj in objs: + record = { + 'lender': obj.lender, + 'input_date': obj.input_date, + 'monthly_service': obj.monthly_service, + 'remaining_term': obj.remaining_term, + } + result.append(record) + return JsonResponse({'instance': result}) + + def put(self, request, building_id): + """HTTP PUT request. + + Receive Mortgage and Liabilities data from frontend and store in the database. Delete any existing records + before storing new data. + + Args: + request: HTTP PUT request. + building_id: id of the building. + + Returns: + JsonResponse: A status saying OK. + """ + put = json.loads(request.body.decode()) + self.model.objects.filter(building_id=building_id).delete() + for record in put: + year = int(record['date-year']) + month = int(record['date-month']) + day = int(record['date-day']) + self.model.objects.create( + building_id=building_id, + input_date=date(year, month, day), + lender=record['lender'], + monthly_service=float(record['monthly-service']), + remaining_term=float(record['remaining-term']), + ) + return JsonResponse({'status': 'OK'}) + + class CashBalanceView(View): """Display, store and use cash balance data.""" @@ -626,7 +686,7 @@ class CashBalanceView(View): instance['status'] = True for obj in objs: temp = {} - temp['date'] = obj.start_date + temp['date'] = obj.statement_date temp['is_from_balance_sheet'] = obj.is_from_balance_sheet temp['balance_amount'] = obj.balance_amount instance['result'].append(temp) @@ -679,7 +739,7 @@ class CashBalanceView(View): for record in record_list: self.model.objects.create( building_id=building_id, - start_date=date(record['year'], record['month'], record['day']), + statement_date=date(record['year'], record['month'], record['day']), is_from_balance_sheet=record['is_from_balance_sheet'], balance_amount=record['balance'], ) diff --git a/blocnote/urls.py b/blocnote/urls.py index 69e442f03e135dccb48451ab4c825baff226461f..2cefee10ee421cd9f7c9696bed9cda720ec0d2ce 100644 --- a/blocnote/urls.py +++ b/blocnote/urls.py @@ -18,6 +18,6 @@ from django.contrib import admin urlpatterns = [ url('', admin.site.urls), - url(r'^building/(?P[0-9]+)/financial-inputs/', include('blocnote.apps.financialInputs.urls')), + url(r'^buildings/(?P[0-9]+)/financial-inputs/', include('blocnote.apps.financialInputs.urls')), url(r'^admin/', admin.site.urls), ]