diff --git a/.gitignore b/.gitignore index 32b1e5a16a36f3d59c0566fb584e5e9f6c6a9f23..171d7787629356c3ebf8817d272bbf6961df57e6 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ node_modules # misc .idea .vscode/ +static/ diff --git a/blocnote/apps/financialInputs/migrations/0012_customerpreference.py b/blocnote/apps/financialInputs/migrations/0012_customerpreference.py new file mode 100644 index 0000000000000000000000000000000000000000..2b643cf26b5b284d6b6a1860f98f93a5f436a2bd --- /dev/null +++ b/blocnote/apps/financialInputs/migrations/0012_customerpreference.py @@ -0,0 +1,25 @@ +# -*- 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/models.py b/blocnote/apps/financialInputs/models.py index b10647c3055533d0d0f66255ec4a9bd5b48c8e83..139bfb31abb126c3861ab4384d7e22ef8a989137 100644 --- a/blocnote/apps/financialInputs/models.py +++ b/blocnote/apps/financialInputs/models.py @@ -56,3 +56,12 @@ class BillsOverview(models.Model): oil_is_user_input = models.BooleanField(default=False) gas = models.DecimalField(max_digits=10, decimal_places=2) gas_is_user_input = models.BooleanField(default=False) + + +class CustomerPreference(models.Model): + """Store customer preferences on payment.""" + + building_id = models.IntegerField() + downpayment = models.DecimalField(max_digits=10, decimal_places=2) + expected_payback = models.DecimalField(max_digits=3, decimal_places=0) + expected_net_noi_dscr = models.DecimalField(max_digits=5, decimal_places=2) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 9f076c4b68a695e03d3bd55c485ab0ec93ead38e..cfc018772ee7c48ae402e85cb6aec8d297d382e2 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -3,15 +3,16 @@ for (var utility_index in utilities) { loadInitialBillsTable(utilities[utility_index]); } loadBillsOverview(); +getCustomerPreferenceTable(); +/** + * Handle submition of the header form. Validate commissioning date is greater + * than construction start date. Create result dictionary containing the form + * data and convert into JSON to send to the backend. Upon success, load the + * Bills overview table as the Pro Forma year changes the start year of the + * Bills overview table. + */ function billProjectionDatesForm(form) { - /* - * Handle submition of the header form. Validate commissioning date is greater - * than construction start date. Create result dictionary containing the form - * data and convert into JSON to send to the backend. Upon success, load the - * Bills overview table as the Pro Forma year changes the start year of the - * Bills overview table. - */ const formData = new FormData(form); var validDate = validateDate(formData); if (!validDate) { @@ -23,7 +24,7 @@ function billProjectionDatesForm(form) { result[key] = value; } request('finance-overview/', { - method: 'put', + method: 'PUT', credentials: 'same-origin', body: JSON.stringify(result), headers: new Headers({ @@ -37,8 +38,8 @@ function billProjectionDatesForm(form) { return false; } +/** Validate that commissioning date is after the construction start date. */ function validateDate(data) { - /* Validate that commissioning date is after the construction start date. */ var startDateYear = data.get('anticipated_construction_start_date_year'); var startDateMonth = data.get('anticipated_construction_start_date_month'); var startDateDay = data.get('anticipated_construction_start_date_day'); @@ -61,16 +62,16 @@ function validateDate(data) { return true; } +/** + * Load initial bills table given a utility. Send GET request to obtain + * bill information and call updateTable function to update the bills table + * with the data obtained from backend. + */ function loadInitialBillsTable(utility) { - /* - * Load initial bills table given a utility. Send GET request to obtain - * bill information and call updateTable function to update the bills table - * with the data obtained from backend. - */ const table = document.querySelector('#'+utility); request(`bills/?utility_type=${utility}`, { - method: 'get', + method: 'GET', credentials: 'same-origin', headers: { 'Content-Type': 'application/json' @@ -83,17 +84,17 @@ function loadInitialBillsTable(utility) { }) } - +/** + * Update the Bills table with the data. Function queries to get the table + * component and then updates the component with the text. + */ function updateTable(utility, text) { - /* Update the Bills table with the data. Function queries to get the table - * component and then updates the component with the text. - */ table = document.querySelector('#'+utility); table.innerHTML = text; } +/** Generate html text for a given utility and bills data from backend. */ function getText(result, utility) { - /* Generate html text for a given utility and bills data from backend. */ var text = `