diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 83a9488399e1b7f15a5e93c3e1af4590e2e51349..e4aa613f378f98d83e83042c39d177f8dca1bdc3 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]); } @@ -8,6 +14,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 @@ -17,7 +34,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"); } @@ -40,13 +73,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; } @@ -170,12 +203,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 = ` @@ -242,7 +269,7 @@ function createBillsOverviewTableCellInput(id, state, value, year) { if (!state) { is_readonly = `readonly`; } - text = ``; + text = ``; return text; } @@ -437,15 +464,15 @@ function createCustomerPreferenceTable(instance) { Affordable Downpayment - + Expected Payback - Months + Months Expected Net NOI DSCR - + @@ -501,15 +528,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); @@ -523,12 +550,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; } @@ -543,6 +573,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; @@ -625,11 +665,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; } @@ -646,7 +689,7 @@ function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { cell.innerHTML += `${rowCount}`; cell = row.insertCell(1); cell.innerHTML += ` - + `; cell = row.insertCell(2); cell.innerHTML += ` @@ -669,6 +712,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; @@ -768,9 +820,9 @@ function loadIncomeStatemenHeading() { heading.innerHTML = ` Year - - - + + + Next Year Average @@ -785,17 +837,17 @@ function loadIncomeStatemenBody() { body.innerHTML = ` Revenue - - - + + + Utility Expense - - - + + + @@ -849,9 +901,9 @@ function loadIncomeStatemenBody() { Non-Utility Operating Expense - - - + + + @@ -929,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); diff --git a/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html b/blocnote/apps/financialInputs/templates/financialInputs/headerForm.html index c5b3ccdbbe7d4f1084c037bbe21f54e2a30164d3..51a687a6529c72c918100ee0eeea59f961041121 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 }} +
+
diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index 67fc7bf1fba3dc67012e7d05e35dc77b566abf10..b909292d6b7fa60662cd5d1d2a0afe9e2234ed0a 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -333,16 +333,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)