`;
estimateModelForm += estimationDropDownBox();
estimateModelForm += createCalculateButton();
estimateModelForm += `
@@ -421,7 +444,7 @@ function createBillsOverviewRows(data) {
function createCalculateButton() {
text = `
-
+
`;
return text;
@@ -431,7 +454,7 @@ function createCalculateButton() {
function createSubmitButton() {
text = `
-
+
`;
return text;
@@ -482,7 +505,7 @@ function billsOverviewFormCalculate(data) {
})
}).then(res => {
if (res.payload.instance['err']) {
- alert(res.payload.instance['msg']);
+ alert(res.payload.instance['err']);
return false;
}
table = document.querySelector('#Energy-Bills-Overview')
@@ -494,12 +517,23 @@ function billsOverviewFormCalculate(data) {
return false;
}
+// Watch bills overview table to display/erase error/success messages.
+var billsOverview = document.querySelector('#Energy-Bills-Overview');
+billsOverview.onchange = function() {
+ document.querySelector('#bills-overview-warning-message').innerHTML = '';
+}
+
function billsOverviewFormSubmit(form) {
const formData = new FormData(form);
const result = {};
for (const [key, value] of formData.entries()) {
result[key] = value;
}
+ // Check the estimation model. Since only rough estimation is implemented, allow only that.
+ if (!(document.querySelector('#estimation-model').value === 'Rough Estimation')) {
+ alert('Please recalculate the projection with rough estimation and try to save again');
+ return false;
+ }
request(`bills-overview/`, {
method: 'POST',
credentials: 'same-origin',
@@ -508,10 +542,42 @@ function billsOverviewFormSubmit(form) {
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken')
})
+ }).then(res => {
+ // Display error/success message.
+ var message = '';
+ if (!res.payload.err) {
+ message = 'Saved';
+ }
+ else {
+ message = res.payload.err;
+ }
+ document.querySelector('#bills-overview-warning-message').innerHTML = `
+
${message}
+ `;
+ // Update the total once manual inputs are saved.
+ var totalCharge = []
+ var billsOverviewTable = document.querySelector('#table-bills-overview tbody');
+ var columnLength = billsOverviewTable.rows[0].cells.length - 2;
+ for (var cellIndex = 2; cellIndex < columnLength; cellIndex++) {
+ val = 0;
+ for(var rowIndex = 0; rowIndex < 4; rowIndex++) {
+ val += Number(billsOverviewTable.rows[rowIndex].cells[cellIndex].children[0].value);
+ }
+ totalCharge.push(val);
+ }
+ for (var cellIndex = 2; cellIndex < columnLength; cellIndex++) {
+ billsOverviewTable.rows[4].cells[cellIndex].innerHTML = totalCharge[cellIndex - 2];
+ }
});
return false;
}
+// Watch customer preference to display/erase error/success mesaages.
+var customerPreference = document.querySelector('#Customer-Preference');
+customerPreference.onchange = function() {
+ document.querySelector('#customer-preference-warning-message').innerHTML = '';
+}
+
/**
* Handle customer preference form submit. Make a HTTP PUT request.
*/
@@ -530,6 +596,12 @@ function customerPreferenceForm(form) {
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken')
})
+ }).then(res => {
+ if (!res.payload.err) {
+ document.querySelector('#customer-preference-warning-message').innerHTML = `
+
Saved
+ `;
+ }
});
return false;
}
@@ -543,7 +615,7 @@ function createCustomerPreferenceTable(instance) {
var expectedPayback = 999;
var expectedNetNOIDSCR = 1.15
- if (instance.status) {
+ if (instance) {
var downpayment = instance['downpayment'];
var expectedPayback = instance['expected_payback'];
var expectedNetNOIDSCR = instance['expected_net_noi_dscr']
@@ -559,15 +631,15 @@ function createCustomerPreferenceTable(instance) {
| Affordable Downpayment |
- |
+ |
| Expected Payback |
- Months |
+ Months |
| Expected Net NOI DSCR |
- |
+ |
@@ -632,7 +704,7 @@ function addLiabilitiesRow(lender, service, term, date) {
`;
cell = row.insertCell(4);
cell.innerHTML = `
-
+
`;
cell = row.insertCell(5);
cell.innerHTML = `
@@ -657,6 +729,11 @@ function deleteLiabilitiesRow(rowIndex) {
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');
@@ -689,6 +766,12 @@ function liabilitiesSubmitForm(form) {
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken')
})
+ }).then(res => {
+ if (!res.payload.err) {
+ document.querySelector('#liabilities-warning-message').innerHTML = `
+
Saved!
+ `;
+ }
});
return false;
}
@@ -722,7 +805,7 @@ function getCashBalanceForm() {
/**Load cash balance table with initial values. Takes response from GET request to construct the table. */
function loadCashBalanceTable(instance) {
table = document.querySelector('#cash-balance-table');
- if (instance.status) {
+ if (instance) {
for (var record=0; record < instance.result.length; record++) {
balanceAmount = Number(instance.result[record].balance_amount);
date = instance.result[record].date;
@@ -731,7 +814,7 @@ function loadCashBalanceTable(instance) {
}
}
else {
- addCashBalanceRow(0, '', false);
+ addCashBalanceRow('', '', false);
}
}
@@ -758,6 +841,11 @@ function deleteCashBalanceRow(row) {
var result = confirm('ARE YOU SURE YOU WANT TO DELETE THIS ROW?');
if (result) {
table = document.querySelector('#cash-balance-table');
+ var rowCount = table.rows.length;
+ if (rowCount === 2) {
+ alert('YOU MUST HAVE ATLEAST ONE CASH BALANCE ENTRY!');
+ return false;
+ }
table.deleteRow(row);
for (rowInd = 1; rowInd < table.rows.length; rowInd++) {
row = table.rows.item(rowInd).cells;
@@ -779,11 +867,11 @@ function addCashBalanceRow(balance, date, isFromBalanceSheet) {
cell.innerHTML = `${rowCount + 1}`;
cell = row.insertCell(1);
cell.innerHTML = `
-
+
`;
cell = row.insertCell(2);
cell.innerHTML = `
-
+
`;
cell = row.insertCell(3);
cell.innerHTML = getCashBalanceCheckBox(isFromBalanceSheet);
@@ -794,6 +882,12 @@ function addCashBalanceRow(balance, date, isFromBalanceSheet) {
return false;
}
+// Watch cash balance to display/erase error/success messages.
+var cashBalanceForm = document.querySelector('#cash-balance-form');
+cashBalanceForm.onchange = function() {
+ document.querySelector('#cash-balance-warning-message').innerHTML = '';
+}
+
/**Make PUT request with data from the cash balance table. */
function submitCashBalanceForm(form) {
var myResult = [];
@@ -810,7 +904,9 @@ function submitCashBalanceForm(form) {
'year': Number(dateSplit[0]),
}
if (!validateDate(dateDict, todaysDate)) {
- alert('Statement Date cannot be in the future');
+ document.querySelector('#cash-balance-warning-message').innerHTML = `
+
Statement date cannot be in the future!
+ `;
return false;
}
record['statement-date'] = date;
@@ -831,6 +927,12 @@ function submitCashBalanceForm(form) {
'Content-Type': 'application/json',
'X-CSRFToken': Cookies.get('csrftoken')
})
+ }).then(res => {
+ if (!res.payload.err) {
+ document.querySelector('#cash-balance-warning-message').innerHTML = `
+
Saved
+ `;
+ }
});
return false;
}
@@ -853,9 +955,9 @@ function loadIncomeStatemenHeading() {
heading.innerHTML = `
| Year |
- |
- |
- |
+ |
+ |
+ |
Next Year |
Average |
@@ -870,17 +972,17 @@ function loadIncomeStatemenBody() {
body.innerHTML = `
| Revenue |
- |
- |
- |
+ |
+ |
+ |
|
|
| Utility Expense |
- |
- |
- |
+ |
+ |
+ |
|
|
@@ -934,9 +1036,9 @@ function loadIncomeStatemenBody() {
| Non-Utility Operating Expense |
- |
- |
- |
+ |
+ |
+ |
|
|
@@ -976,7 +1078,7 @@ function loadIncomeStatementDropdownBox(cagr) {
var text = ``;
text += `
Please select Growth Rate
-
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html
index 0a3dd92df7e25e4b415eb5b6a02e2cf1602d5d19..e383f8b9ac5721bb0a5246a25db06d6d59e5aed9 100644
--- a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html
+++ b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html
@@ -2,7 +2,11 @@
Cash Balance
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/customerPreference.html b/blocnote/apps/financialInputs/templates/financialInputs/customerPreference.html
index ec52556d2192ba158afadf777a1482e381300846..c4188f40774be0558c320623349321393de7180f 100644
--- a/blocnote/apps/financialInputs/templates/financialInputs/customerPreference.html
+++ b/blocnote/apps/financialInputs/templates/financialInputs/customerPreference.html
@@ -3,4 +3,6 @@
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/incomeStatement.html b/blocnote/apps/financialInputs/templates/financialInputs/incomeStatement.html
index f1ce56c4d34af8a8def9b171f847819e387f9bdf..5b2d0c056ceae5100155965700ebacaa5a11c419 100644
--- a/blocnote/apps/financialInputs/templates/financialInputs/incomeStatement.html
+++ b/blocnote/apps/financialInputs/templates/financialInputs/incomeStatement.html
@@ -2,11 +2,13 @@