diff --git a/blocnote/apps/financialInputs/static/financialInputs/scripts/proformaInputs.js b/blocnote/apps/financialInputs/static/financialInputs/scripts/proformaInputs.js
index dbdc284c87df042b39c4ef369c1cd34a2759c942..c389eea4bd1e7c586d69bddb72b971cb6705f216 100644
--- a/blocnote/apps/financialInputs/static/financialInputs/scripts/proformaInputs.js
+++ b/blocnote/apps/financialInputs/static/financialInputs/scripts/proformaInputs.js
@@ -94,69 +94,78 @@ getBillProjectionDatesForm();
* @returns : False so that page does not reload.
*/
function billProjectionDatesForm(form) {
- const formData = new FormData(form);
- const result = {};
- formData.forEach((value, field) => {
- result[field] = value;
- });
- const constructionStartDate = new Date(result.anticipated_construction_start_date);
- const constructionCommissioningDate = new Date(result.anticipated_commissioning_date);
- // Make sure construction commision date is afer construction start date.
- if (constructionStartDate > constructionCommissioningDate) {
- document.querySelector('#pro-forma-form-save-msg').innerHTML = `
-
- Anticipated Commissioning date has to be after Anticipated Construction start date
-
- `;
- return false;
- }
- request('finance-overview/', {
- method: 'PUT',
+ request(`loan-options/?loans=all-loans`, {
+ method: 'GET',
credentials: 'same-origin',
- body: JSON.stringify(result),
- headers: new Headers({
- 'Content-Type': 'application/json',
- 'X-CSRFToken': Cookies.get('csrftoken'),
- }),
- }).then((res) => {
- const displayMessage = document.querySelector('#pro-forma-form-save-msg');
- if (!res.err) {
- // Display response message. Add that loan options changed if fund was changed. Reset
- // didFundChange to false.
- let responseMessage = 'Saved. ';
- if (didFundChange) {
- responseMessage += 'Loan Options table is reloaded.';
- }
- displayMessage.innerHTML = `${responseMessage}`;
- /**
- * delete-loan-options request to the backend to delete loan options for this building id if
- * previosly stored. This ensures that the loan options table is up to date with the latest
- * fund. Clear the loan options table and reload with new fund's default loan options.
- */
- if (didFundChange) {
- didFundChange = false;
- request('loan-options/?loans=delete-loan-options', {
- method: 'GET',
- credentials: 'same-origin',
- headers: {
- 'Content-Type': 'application/json',
- },
- }).then(() => {
- const tableBody = document.querySelector('#loan-options-table tbody');
- tableBody.innerHTML = '';
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ }).then(res => {
+ let isFirstTime = !res.payload.load;
+ const formData = new FormData(form);
+ const result = {};
+ formData.forEach((value, field) => {
+ result[field] = value;
+ });
+ const constructionStartDate = new Date(result.anticipated_construction_start_date);
+ const constructionCommissioningDate = new Date(result.anticipated_commissioning_date);
+ // Make sure construction commision date is afer construction start date.
+ if (constructionStartDate > constructionCommissioningDate) {
+ document.querySelector('#pro-forma-form-save-msg').innerHTML = `
+
+ Anticipated Commissioning date has to be after Anticipated Construction start date
+
+ `;
+ return false;
+ }
+ request('finance-overview/', {
+ method: 'PUT',
+ credentials: 'same-origin',
+ body: JSON.stringify(result),
+ headers: new Headers({
+ 'Content-Type': 'application/json',
+ 'X-CSRFToken': Cookies.get('csrftoken'),
+ }),
+ }).then((res) => {
+ const displayMessage = document.querySelector('#pro-forma-form-save-msg');
+ if (!res.err) {
+ // Display response message. Add that loan options changed if fund was changed. Reset
+ // didFundChange to false.
+ let responseMessage = 'Saved. ';
+ if (didFundChange) {
+ responseMessage += 'Loan Options table is reloaded.';
+ }
+ displayMessage.innerHTML = `${responseMessage}`;
+ /**
+ * delete-loan-options request to the backend to delete loan options for this building id if
+ * previosly stored. This ensures that the loan options table is up to date with the latest
+ * fund. Clear the loan options table and reload with new fund's default loan options.
+ */
+ if (didFundChange || isFirstTime) {
+ didFundChange = false;
+ request('loan-options/?loans=delete-loan-options', {
+ method: 'GET',
+ credentials: 'same-origin',
+ headers: {
+ 'Content-Type': 'application/json',
+ },
+ }).then(() => {
+ const tableBody = document.querySelector('#loan-options-table tbody');
+ tableBody.innerHTML = '';
+ });
+ getLoanOptionsTable();
+ }
+ } else {
+ res.err.responseBody.then((error) => {
+ // Display error message.
+ Object.keys(error).forEach((key) => {
+ document.querySelector(`#${key}-error`).innerHTML = `
+ ${error[key][0]}
+ `;
+ });
});
- getLoanOptionsTable();
}
- } else {
- res.err.responseBody.then((error) => {
- // Display error message.
- Object.keys(error).forEach((key) => {
- document.querySelector(`#${key}-error`).innerHTML = `
- ${error[key][0]}
- `;
- });
- });
- }
+ });
});
return false;
}