Skip to content

Commit

Permalink
check subvention values when updating full_amount
Browse files Browse the repository at this point in the history
  • Loading branch information
NC-jsAhonen committed Sep 5, 2023
1 parent 5833acf commit 55fb224
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
17 changes: 15 additions & 2 deletions src/leases/components/leaseSections/rent/RentAdjustmentEdit.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
calculateRentAdjustmentSubventionPercentCumulative,
getDecisionById,
hasSubventionDataChanged,
hasSubventionValues,
} from '$src/leases/helpers';
import {getUiDataLeaseKey} from '$src/uiData/helpers';
import {
Expand Down Expand Up @@ -265,9 +266,21 @@ class RentAdjustmentsEdit extends PureComponent<Props> {

componentDidUpdate(prevProps: Props) {
if (this.props && hasSubventionDataChanged(prevProps, this.props)) {
const {change, field} = this.props;
const {
change,
field,
fullAmount,
managementSubventions,
temporarySubventions
} = this.props;

let newFullAmount = fullAmount

if (hasSubventionValues(managementSubventions, temporarySubventions)) {
newFullAmount = this.calculateTotalSubventionPercent()
}

change(formName, `${field}.full_amount`, formatNumber(this.calculateTotalSubventionPercent())); // TODO
change(formName, `${field}.full_amount`, formatNumber(newFullAmount)); // TODO
}
}

Expand Down
13 changes: 13 additions & 0 deletions src/leases/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -1531,6 +1531,19 @@ export const calculateSubventionDiscountTotal = (initialYearRent: number, manage
return Number(initialYearRent);
};

/**
* Check if subventions have values for calculation
* @param {number} initialYearRent
* @param {Object[]} managementSubventions
* @param {number} currentAmountPerArea
* @return {number}
*/
export const hasSubventionValues = (managementSubventions: ?Array<Object>, temporarySubventions: ?Array<Object>): boolean => {
let msWithValues = managementSubventions.filter((subvention) => !!subvention.subvention_amount)
let tsWithValues = temporarySubventions.filter((subvention) => !!subvention.subvention_percent)
return !!(msWithValues.length || tsWithValues.length)
};

/**
* Calculate basis of rent subvention percent
* @param {number} initialYearRent
Expand Down

0 comments on commit 55fb224

Please sign in to comment.