diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js index 2b2d615b3870f68ad10ad915e9b3170329c73a01..93cde755148673699b887caf2fc58cbc7013325d 100644 --- a/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js +++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/app.js @@ -532,25 +532,22 @@ function getCustomerPreferenceTable() { function loadLiabilitiesTable(inputList) { table = document.querySelector('#liabilities-table'); if (inputList.length === 0) { - addLiabilitiesRow('', '', '', 1, 1, 1980); + 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'].split('-'); - month = Number(date[1]); - day = Number(date[2]); - year = Number(date[0]); - addLiabilitiesRow(lender, service, term, month, day, year); + 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, month, day, year) { +function addLiabilitiesRow(lender, service, term, date) { table = document.querySelector('#liabilities-table tbody'); var rowCount = table.rows.length; var row = table.insertRow(rowCount); @@ -569,7 +566,9 @@ function addLiabilitiesRow(lender, service, term, month, day, year) { `; cell = row.insertCell(4); - cell.innerHTML = createDateComponent(month, day, year); + cell.innerHTML = ` + + `; cell = row.insertCell(5); cell.innerHTML = `
@@ -603,18 +602,18 @@ 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), + 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(date, todaysDate)) { - alert('Invalid date'); + if (!validateDate(dateDict, todaysDate)) { + alert('Input Date cannot be in the future'); 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; + record['input_date'] = date; result.push(record); } request('liabilities/', { @@ -661,16 +660,13 @@ function loadCashBalanceTable(instance) { if (instance.status) { for (var record=0; record < instance.result.length; record++) { balanceAmount = Number(instance.result[record].balance_amount); - date = instance.result[record].date.split('-'); - month = Number(date[1]); - day = Number(date[2]); - year = Number(date[0]); + date = instance.result[record].date; isFromBalanceSheet = instance.result[record]['is_from_balance_sheet'] - addCashBalanceRow(balanceAmount, month, day, year, isFromBalanceSheet); + addCashBalanceRow(balanceAmount, date, isFromBalanceSheet); } } else { - addCashBalanceRow(0, 1, 1, 1980, false); + addCashBalanceRow(0, '', false); } } @@ -710,24 +706,24 @@ function deleteCashBalanceRow(row) { * Add a row to the cash balance table. Take balance amount, date and boolean that represents if a record is from * balance sheet or not. */ -function addCashBalanceRow(balance, month, day, year, isFromBalanceSheet) { +function addCashBalanceRow(balance, date, isFromBalanceSheet) { table = document.querySelector('#cash-balance-table tbody'); var rowCount = table.rows.length; var row = table.insertRow(rowCount); var cell = row.insertCell(0); - cell.innerHTML += `${rowCount + 1}`; + cell.innerHTML = `${rowCount + 1}`; cell = row.insertCell(1); - cell.innerHTML += ` + cell.innerHTML = ` `; cell = row.insertCell(2); - cell.innerHTML += ` - ${createDateComponent(month, day, year)} + cell.innerHTML = ` + `; cell = row.insertCell(3); - cell.innerHTML += getCashBalanceCheckBox(isFromBalanceSheet); + cell.innerHTML = getCashBalanceCheckBox(isFromBalanceSheet); cell = row.insertCell(4) - cell.innerHTML += ` + cell.innerHTML = ` `; return false; @@ -741,21 +737,24 @@ 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), + date = table.rows[rowIndex].cells[2].children[0].value; + dateSplit = date.split('-'); + dateDict = { + 'day': Number(dateSplit[2]), + 'month': Number(dateSplit[1]), + 'year': Number(dateSplit[0]), } - if (!validateDate(date, todaysDate)) { - alert('Invalid date'); + if (!validateDate(dateDict, todaysDate)) { + alert('Statement Date cannot be in the future'); 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; + record['statement-date'] = date; checkBox = table.rows[rowIndex].querySelectorAll('input[type="checkbox"]:checked'); if (checkBox.length > 0) { - record['is-from-balance-sheet'] = 'on'; + record['is-from-balance-sheet'] = true; + } + else { + record['is-from-balance-sheet'] = false; } myResult.push(record); } @@ -771,66 +770,6 @@ function submitCashBalanceForm(form) { return false; } -/**Create the select date component.*/ -function createDateComponent(mon, day, yr, num) { - months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December']; - selectMonth = ``; - selectDay = ``; - selectYear = ``; - var text = ` - - - - `; - - return text; -} - /** * Load income statement table. The column heading are displayed first along with the table body. The growth rate * drop down box is displayed as well. diff --git a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html index b3280081c8da99d15b7c6f480aa25823b40fee4b..0a3dd92df7e25e4b415eb5b6a02e2cf1602d5d19 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/cashBalance.html @@ -8,7 +8,7 @@ # Balance Amount - Date + Statement Date Balance Sheet Option @@ -17,6 +17,6 @@ -
+
diff --git a/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html b/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html index 48062446d88a4355f764d6b893ef366f10d9c03c..5b0b087984be836d7fbfbca05f698bf08f6be2cf 100644 --- a/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html +++ b/blocnote/apps/financialInputs/templates/financialInputs/liabilities.html @@ -19,5 +19,5 @@
- +
diff --git a/blocnote/apps/financialInputs/views.py b/blocnote/apps/financialInputs/views.py index e7102f5059edf4fabca70189cce7377ca51fc9e9..9c0ffa93387f82273b1daf17c11c76f30684560a 100644 --- a/blocnote/apps/financialInputs/views.py +++ b/blocnote/apps/financialInputs/views.py @@ -658,12 +658,9 @@ class LiabilitiesTable(View): put = json.loads(request.body.decode()) self.model.objects.filter(building_id=building_id).delete() for record in put: - year = int(record['date-year']) - month = int(record['date-month']) - day = int(record['date-day']) self.model.objects.create( building_id=building_id, - input_date=date(year, month, day), + input_date=record['input_date'], lender=record['lender'], monthly_service=float(record['monthly-service']), remaining_term=float(record['remaining-term']), @@ -700,31 +697,6 @@ class CashBalanceView(View): instance['status'] = False return JsonResponse({'instance': instance}) - def get_record_list(self, put): - """Retrieve records from PUT request. - - Retrieve all cash balance records from PUT request and return a list of records which is a dictionary here. - - Args: - put: Decoded put request body which is a dictionary. - - Returns: - result: List of dictionaries which are the cash balance records. - """ - record_list = [] - for row in put: - record = {} - if 'is-from-balance-sheet' in row: - record['is_from_balance_sheet'] = True - else: - record['is_from_balance_sheet'] = False - record['balance'] = row['balance'] - record['month'] = int(row['date-month']) - record['day'] = int(row['date-day']) - record['year'] = int(row['date-year']) - record_list.append(record) - return record_list - def put(self, request, building_id): """Handle HTTP PUT request. @@ -738,15 +710,14 @@ class CashBalanceView(View): JsonResponse: An instance with OK. """ put = json.loads(request.body.decode()) - record_list = self.get_record_list(put) self.model.objects.filter( building_id=building_id, ).delete() - for record in record_list: + for record in put: self.model.objects.create( building_id=building_id, - statement_date=date(record['year'], record['month'], record['day']), - is_from_balance_sheet=record['is_from_balance_sheet'], + statement_date=record['statement-date'], + is_from_balance_sheet=record['is-from-balance-sheet'], balance_amount=record['balance'], ) return JsonResponse({'instance': 'OK'})