From b350b03603070ed451968c176461fa43f44d5d01 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 08:56:37 -0400 Subject: [PATCH 1/5] Change route in urls for liabilities to go to the new liabilities. --- blocnote/apps/financialInputs/urls.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocnote/apps/financialInputs/urls.py b/blocnote/apps/financialInputs/urls.py index 55e1e8d..e3563f9 100644 --- a/blocnote/apps/financialInputs/urls.py +++ b/blocnote/apps/financialInputs/urls.py @@ -3,7 +3,7 @@ from django.conf.urls import url from . import old_views from .views import ( - proforma_input, customer_preference, cash_balance + proforma_input, customer_preference, cash_balance, liabilities, ) app_name = 'financial-inputs' @@ -13,7 +13,7 @@ urlpatterns = [ url(r'^bills/$', old_views.BillsTable.as_view(), name='bills'), url(r'^bills-overview/$', old_views.BillsOverviewView.as_view(), name='bills_overview'), url(r'^customer-preference/$', customer_preference.CustomerPreferenceView.as_view(), name='customer_preference'), - url(r'^liabilities/$', old_views.LiabilitiesTable.as_view(), name='liabilities'), + url(r'^liabilities/$', liabilities.LiabilitiesTable.as_view(), name='liabilities'), url(r'^cash-balance/$', cash_balance.CashBalanceView.as_view(), name='cash_balance'), url(r'^income-statement/$', old_views.IncomeStatementTable.as_view(), name='income_statement'), url(r'^loan-options/$', old_views.LoanOptionsTable.as_view(), name='loan_options'), -- GitLab From 3e91278ef3f88d625844d5a7daaf0bed415d20f1 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 09:01:09 -0400 Subject: [PATCH 2/5] Fix variable naming. --- .../static/financialInputs/scripts/liabilities.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js index e2c7d89..9138b68 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js @@ -77,8 +77,8 @@ function liabilitiesSubmitForm(form) { for (let rowIndex = 1; rowIndex < rowCount; rowIndex++) { let record = {}; record['lender'] = table.rows[rowIndex].cells[1].children[0].value; - record['monthly-service'] = table.rows[rowIndex].cells[2].children[0].value; - record['remaining-term'] = table.rows[rowIndex].cells[3].children[0].value; + record['monthly_service'] = table.rows[rowIndex].cells[2].children[0].value; + record['remaining_term'] = table.rows[rowIndex].cells[3].children[0].value; let date = table.rows[rowIndex].cells[4].children[0].value; const liabilitiesDate = new Date(date); const todaysDate = new Date(); -- GitLab From 9ef8d04a6df5fac85914fd3a08ab55c3c94d0dea Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 09:13:03 -0400 Subject: [PATCH 3/5] Remove liabilities code from appjs. --- .../static/financialInputs/scripts/app.js | 128 ------------------ 1 file changed, 128 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 5cc9ab2..51c74d7 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -11,7 +11,6 @@ for (var utility_index in utilities) { loadBillsOverview(); getIncomeStatementTable(); -getLiabilitiesTable(); getLoanOptionsTable(); /** Validate that commissioning date is after the construction start date. */ @@ -416,133 +415,6 @@ function billsOverviewFormSubmit(form) { return false; } -/** - * 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('', '', '', ''); - } - else { - inputList.map(function(record, index) { - record = inputList[index]; - lender = record['lender']; - service = record['monthly_service']; - term = record['remaining_term']; - date = record['input_date']; - addLiabilitiesRow(lender, service, term, date); - }); - } -} - -/**Add a new row to Mortgage and Liabilities table. */ -function addLiabilitiesRow(lender, service, term, date) { - 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 = ` - - `; - cell = row.insertCell(5); - cell.innerHTML = ` -
- -
- `; -} - -/**Delete a row from the Mortgage and Liabilities table. */ -function deleteLiabilitiesRow(rowIndex) { - var result = confirm("ARE YOU SURE YOU WANT TO DELETE THIS ROW?"); - if (result) { - 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; -} - -var liabilitiesForm = document.querySelector('#Liabilities'); -liabilitiesForm.onchange = function() { - document.querySelector('#liabilities-warning-message').innerHTML = ''; -} - -/**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; - date = table.rows[rowInd].cells[4].children[0].value; - dateSplit = date.split('-'); - dateDict = { - 'day': Number(dateSplit[2]), - 'month': Number(dateSplit[1]), - 'year': Number(dateSplit[0]), - } - if (!validateDate(dateDict, todaysDate)) { - alert('Input Date cannot be in the future'); - return false; - } - record['input_date'] = date; - 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') - }) - }).then(res => { - if (!res.payload.err) { - document.querySelector('#liabilities-warning-message').innerHTML = ` - Saved! - `; - } - }); - 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); - }); -} /** * Load income statement table. The column heading are displayed first along with the table body. The growth rate -- GitLab From f06f11ddd5acf969b7aa7b8356268540638d49d7 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 09:13:25 -0400 Subject: [PATCH 4/5] Add liabilities js to index. --- .../apps/financialInputs/templates/financialInputs/index.html | 1 + 1 file changed, 1 insertion(+) diff --git a/blocnote/apps/financialInputs/templates/financialInputs/index.html b/blocnote/apps/financialInputs/templates/financialInputs/index.html index dfb6ab0..de8fe1b 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/index.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/index.html @@ -59,4 +59,5 @@ + {% endblock %} -- GitLab From 6ac7b1f8f340514f0ee4a5d6a0b457ce76858c57 Mon Sep 17 00:00:00 2001 From: Adarsh Date: Thu, 29 Jun 2017 09:13:52 -0400 Subject: [PATCH 5/5] Modify put to store all th eliabilites and not just the latest. --- blocnote/apps/financialInputs/views/liabilities.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py index 85c86d0..88b1c70 100644 --- a/blocnote/apps/financialInputs/views/liabilities.py +++ b/blocnote/apps/financialInputs/views/liabilities.py @@ -52,14 +52,12 @@ class LiabilitiesTable(View): JsonResponse: A status saying OK. """ put = json.loads(request.body.decode()) + Liabilities.objects.filter(building_id=building_id).delete() for record in put: record['building_id'] = building_id form = LiabilitiesForm(record) if form.is_valid(): - self.model.objects.update_or_create( - building_id=building_id, - defaults=record, - ) + self.model.objects.create(**record) else: error_dict = {} for field, error in form.errors.items(): -- GitLab