From 91226404bbcb9526b4398785a6d73cfb64d5e75e Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 3 May 2017 14:09:33 -0400 Subject: [PATCH 1/5] Remove unused function startoverviewform. Create constant variable todaysDate to hold today's date as a dictionary. Update validateDate to become generic and compare any 2 dates. Validate date in cash balance and liability tables to ensure that it is not a future date. Modify all decimal inputs to take in only decimals and not alphabets and other characters. --- .../static/financialInputs/scripts/app.js | 79 +++++++++++++------ 1 file changed, 57 insertions(+), 22 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 7b871ed..7230db9 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -1,4 +1,10 @@ -utilities = ['electricity', 'gas', 'oil', 'water']; +const utilities = ['electricity', 'gas', 'oil', 'water']; +var today = new Date(); +const todaysDate = { + 'day': today.getDate(), + 'month': today.getMonth()+1, + 'year': today.getFullYear(), +} for (var utility_index in utilities) { loadInitialBillsTable(utilities[utility_index]); } @@ -16,7 +22,23 @@ getCashBalanceForm(); */ function billProjectionDatesForm(form) { const formData = new FormData(form); - var validDate = validateDate(formData); + var anticipatedConstructionStartYear = formData.get('anticipated_construction_start_date_year'); + var anticipatedConstructionStartMonth = formData.get('anticipated_construction_start_date_month'); + var anticipatedConstructionStartDay = formData.get('anticipated_construction_start_date_day'); + var anticipatedCommissioningStartYear = formData.get('anticipated_commissioning_date_year'); + var anticipatedCommissioningStartMonth = formData.get('anticipated_commissioning_date_month'); + var anticipatedCommissioningStartDay = formData.get('anticipated_commissioning_date_day'); + var anticipatedConstructionStarDate = { + 'day': anticipatedConstructionStartDay, + 'month': anticipatedConstructionStartMonth, + 'year': anticipatedConstructionStartYear, + } + var anticipatedCommissioningDate = { + 'day': anticipatedCommissioningStartDay, + 'month': anticipatedCommissioningStartMonth, + 'year': anticipatedCommissioningStartYear, + } + var validDate = validateDate(anticipatedConstructionStarDate, anticipatedCommissioningDate); if (!validDate) { alert("Anticipated Commissioning date has to be after Anticipated Construction start date"); } @@ -39,13 +61,13 @@ function billProjectionDatesForm(form) { } /** Validate that commissioning date is after the construction start date. */ -function validateDate(data) { - 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'); - var endDateYear = data.get('anticipated_commissioning_date_year'); - var endDateMonth = data.get('anticipated_commissioning_date_month'); - var endDateDay = data.get('anticipated_commissioning_date_day'); +function validateDate(startDate, endDate) { + var startDateYear = startDate.year; + var startDateMonth = startDate.month; + var startDateDay = startDate.day; + var endDateYear = endDate.year + var endDateMonth = endDate.month; + var endDateDay = endDate.day; if (endDateYear < startDateYear) { return false; } @@ -169,12 +191,6 @@ function createEstimateModelForm() { return estimateModelForm; } -/** Create form tag Energy Bills Overview */ -function startBillsOverviewForm() { - var text = `
`; - return text; -} - /** Create dropdown box to select estimation algorithm */ function estimationDropDownBox() { var text = ` @@ -241,7 +257,7 @@ function createBillsOverviewTableCellInput(id, state, value, year) { if (!state) { is_readonly = `readonly`; } - text = ``; + text = ``; return text; } @@ -436,15 +452,15 @@ function createCustomerPreferenceTable(instance) { Affordable Downpayment - + Expected Payback - Months + Months Expected Net NOI DSCR - + @@ -504,11 +520,11 @@ function addLiabilitiesRow(lender, service, term, month, day, year) { `; cell = row.insertCell(2); cell.innerHTML = ` - + `; cell = row.insertCell(3); cell.innerHTML = ` - + `; cell = row.insertCell(4); cell.innerHTML = createDateComponent(month, day, year); @@ -542,6 +558,16 @@ function liabilitiesSubmitForm(form) { 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 = { + 'day': Number(table.rows[rowInd].cells[4].children[1].value), + 'month': Number(table.rows[rowInd].cells[4].children[0].value), + 'year': Number(table.rows[rowInd].cells[4].children[2].value), + } + if (!validateDate(date, todaysDate)) { + console.log('Invalid date'); + alert('Invalid date'); + return false; + } 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; @@ -645,7 +671,7 @@ function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { cell.innerHTML += `${rowCount}`; cell = row.insertCell(1); cell.innerHTML += ` - + `; cell = row.insertCell(2); cell.innerHTML += ` @@ -668,6 +694,15 @@ function submitCashBalanceForm(form) { for (rowIndex = 1; rowIndex < rowCount; rowIndex++) { record = {}; record['balance'] = table.rows[rowIndex].cells[1].children[0].value; + date = { + 'day': Number(table.rows[rowIndex].cells[2].children[1].value), + 'month': Number(table.rows[rowIndex].cells[2].children[0].value), + 'year': Number(table.rows[rowIndex].cells[2].children[2].value), + } + if (!validateDate(date, todaysDate)) { + alert('Invalid date'); + return false; + } record['date-month'] = table.rows[rowIndex].cells[2].children[0].value; record['date-day'] = table.rows[rowIndex].cells[2].children[1].value; record['date-year'] = table.rows[rowIndex].cells[2].children[2].value; -- GitLab From c02b18d7ec129747fe61d4d6c4546308e365de37 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 3 May 2017 15:08:49 -0400 Subject: [PATCH 2/5] Update input fields to be required fields and prevent submitting empty fields. --- .../static/financialInputs/scripts/app.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 7230db9..dc6544a 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -452,15 +452,15 @@ function createCustomerPreferenceTable(instance) { Affordable Downpayment - + Expected Payback - Months + Months Expected Net NOI DSCR - + @@ -516,15 +516,15 @@ function addLiabilitiesRow(lender, service, term, month, day, year) { 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); @@ -671,7 +671,7 @@ function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { cell.innerHTML += `${rowCount}`; cell = row.insertCell(1); cell.innerHTML += ` - + `; cell = row.insertCell(2); cell.innerHTML += ` -- GitLab From 58c152d3bffbb1cd5a7ce8183598c1a1ce1e3d65 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 3 May 2017 15:39:45 -0400 Subject: [PATCH 3/5] Add warning message when about to change fund. Confirm if user wants to delete a row before deleting a row. --- .../static/financialInputs/scripts/app.js | 39 +++++++++++++------ .../templates/financialInputs/headerForm.html | 2 + 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index dc6544a..0108d6c 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -13,6 +13,17 @@ getCustomerPreferenceTable(); getLiabilitiesTable(); getCashBalanceForm(); +var fund = document.querySelector('#id_fund'); +fund.onmouseenter = function() { + var errorDiv = document.querySelector('#show-error'); + errorDiv.innerHTML = `Changing fund will affect loan options`; +} + +fund.onmouseleave = function() { + var errorDiv = document.querySelector('#show-error'); + errorDiv.innerHTML = ""; +} + /** * Handle submition of the header form. Validate commissioning date is greater * than construction start date. Create result dictionary containing the form @@ -538,12 +549,15 @@ function addLiabilitiesRow(lender, service, term, month, day, year) { /**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}`; + 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; } @@ -650,11 +664,14 @@ function getCashBalanceCheckBox(isFromBalanceSheet) { /**Delete a given row in the cash balance table. Takes in the row index as argument. */ function deleteCashBalanceRow(row) { - table = document.querySelector('#cash-balance-table'); - table.deleteRow(row); - for (rowInd = 1; rowInd < table.rows.length; rowInd++) { - row = table.rows.item(rowInd).cells; - row.item(0).innerHTML = rowInd; + var result = confirm('ARE YOU SURE YOU WANT TO DELETE THIS ROW?'); + if (result) { + table = document.querySelector('#cash-balance-table'); + table.deleteRow(row); + for (rowInd = 1; rowInd < table.rows.length; rowInd++) { + row = table.rows.item(rowInd).cells; + row.item(0).innerHTML = rowInd; + } } return false; } diff --git a/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html b/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html index c5b3ccd..51a687a 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html @@ -26,6 +26,8 @@
Select Fund: {{ form.fund }} +
+
-- GitLab From 0f803a1afb64828b31091305a0efa8f2fcb753a8 Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 3 May 2017 16:40:22 -0400 Subject: [PATCH 4/5] Fix UI for when you change proforma duration to less than what it was, don't show extra columns. --- blocnote/apps/financialInputs/views.py | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index ea50b69..3b54047 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -332,16 +332,21 @@ def get_total_charge(utility_type, analysis_date, building_id): building_id=building_id, ) if objs: - for obj in objs: - store_year = str(obj.year) - if utility_type == 'electricity': - annual_bill[store_year] = obj.electricity - elif utility_type == 'gas': - annual_bill[store_year] = obj.gas - elif utility_type == 'oil': - annual_bill[store_year] = obj.oil - elif utility_type == 'water': - annual_bill[store_year] = obj.water + for index in range(analysis_date['proforma_duration']): + if index < len(objs): + obj = objs[index] + store_year = str(obj.year) + if utility_type == 'electricity': + annual_bill[store_year] = obj.electricity + elif utility_type == 'gas': + annual_bill[store_year] = obj.gas + elif utility_type == 'oil': + annual_bill[store_year] = obj.oil + elif utility_type == 'water': + annual_bill[store_year] = obj.water + else: + store_year = str(int(store_year) + 1) + annual_bill[store_year] = 0 else: for year in range(analysis_date['proforma_duration']): store_year = str(analysis_date['proforma_start'].year + year) -- GitLab From a0ab1ba06eadcd2f5abc7eac09d7b2a439d361bb Mon Sep 17 00:00:00 2001 From: Adarsh Murthy Date: Wed, 3 May 2017 17:46:12 -0400 Subject: [PATCH 5/5] Update input fields of income statement to take in only decimal numbers. --- .../static/financialInputs/scripts/app.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 2c8e481..e4aa613 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -820,9 +820,9 @@ function loadIncomeStatemenHeading() { heading.innerHTML = ` Year - - - + + + Next Year Average @@ -837,17 +837,17 @@ function loadIncomeStatemenBody() { body.innerHTML = ` Revenue - - - + + + Utility Expense - - - + + + @@ -901,9 +901,9 @@ function loadIncomeStatemenBody() { Non-Utility Operating Expense - - - + + + @@ -981,19 +981,19 @@ function getIncomeStatementTable() { for (var index in recordList) { cellIndex = Number(index)+1; heading.rows[0].cells[cellIndex].innerHTML = ` - + `; var revenue = recordList[index].revenue; var utilityExpense = recordList[index].utility_expense; var nonUtilityExpense = recordList[index].non_utility_operating_expense; var revenueInput = ` - + `; var utilityExpenseInput = ` - + `; var nonUtilityExpenseInput = ` - + `; updateIncomeStatementTable(REVENUE_ROW, cellIndex, revenueInput); updateIncomeStatementTable(UTILITY_EXPENSE_ROW, cellIndex, utilityExpenseInput); -- GitLab