diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js
index 5cc9ab2503ebf4452b915e75fe2ac490f1ca644f..51c74d7167d3ca8d3d8f0ec304ab21e9f0328f9a 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
diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/liabilities.js
index e2c7d8930332a04fc7594605a7b4a18bb47ae4ce..9138b68ce045648af1e1f1d002c901fa3cf91dbc 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();
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/index.html b/blocnote/apps/financialInputs/templates/financialInputs/index.html
index dfb6ab090a31aab7409ccf4f06b5f976a5611b3a..de8fe1b4a37f48094ce17679e5313786f6a29c99 100644
--- a/blocnote/apps/financialInputs/templates/financialInputs/index.html
+++ b/blocnote/apps/financialInputs/templates/financialInputs/index.html
@@ -59,4 +59,5 @@
+
{% endblock %}
diff --git a/blocnote/apps/financialInputs/urls.py b/blocnote/apps/financialInputs/urls.py
index 55e1e8dd4ca9c93b8ee90223404226c088c1751a..e3563f900e57e9829665a8c9abd9e2546370950f 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'),
diff --git a/blocnote/apps/financialInputs/views/liabilities.py b/blocnote/apps/financialInputs/views/liabilities.py
index 85c86d0fa5bd097a25ea082b5ac1928e577254a6..88b1c7064a709ffafa590dc553b8ec99351a11be 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():