diff --git a/src/leases/components/leaseSections/rent/BasicInfo.tsx b/src/leases/components/leaseSections/rent/BasicInfo.tsx index bf44e0d7..3ed24512 100644 --- a/src/leases/components/leaseSections/rent/BasicInfo.tsx +++ b/src/leases/components/leaseSections/rent/BasicInfo.tsx @@ -6,11 +6,11 @@ import FormText from "@/components/form/FormText"; import FormTextTitle from "@/components/form/FormTextTitle"; import { LeaseRentDueDatesFieldPaths, LeaseRentDueDatesFieldTitles, LeaseRentsFieldPaths, LeaseRentsFieldTitles, RentCycles, RentTypes, RentDueDateTypes, LeaseFieldPaths } from "@/leases/enums"; import { formatDueDates, formatSeasonalDate, sortDueDates } from "@/leases/helpers"; +import { showOverrideReceivableTypeField } from "@/leases/helpers"; import { getUiDataLeaseKey } from "@/uiData/helpers"; import { formatDate, formatNumber, getFieldOptions, getLabelOfOption, isEmptyValue, isFieldAllowedToRead } from "@/util/helpers"; import { getAttributes as getLeaseAttributes } from "@/leases/selectors"; import type { Attributes } from "types"; -import { getReceivableTypes } from "@/leaseCreateCharge/selectors"; type SeasonalDatesProps = { leaseAttributes: Attributes; rent: Record; @@ -36,17 +36,19 @@ const SeasonalDates = ({ type Props = { leaseAttributes: Attributes; - receivableTypes?: Array | null | undefined; - receivableTypeOptions?: Array | null | undefined; rent: Record; rentType: string | null | undefined; }; +type PropsWithServiceUnitId = Props & { + serviceUnitId: number; +} + const BasicInfoIndexOrManual = ({ leaseAttributes, - receivableTypeOptions, - rent -}: Props) => { + rent, + serviceUnitId, +}: PropsWithServiceUnitId) => { const areOldInfoVisible = () => { return !isEmptyValue(rent.elementary_index) || !isEmptyValue(rent.index_rounding) || !isEmptyValue(rent.x_value) || !isEmptyValue(rent.y_value) || !isEmptyValue(rent.y_value_start) || !isEmptyValue(rent.equalization_start_date) || !isEmptyValue(rent.equalization_end_date); }; @@ -55,6 +57,7 @@ const BasicInfoIndexOrManual = ({ const cycleOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.CYCLE); const indexTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.INDEX_TYPE); const dueDatesTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.DUE_DATES_TYPE); + const receivableTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE); const oldValuesVisible = areOldInfoVisible(); return @@ -191,17 +194,18 @@ const BasicInfoIndexOrManual = ({ - + { showOverrideReceivableTypeField(serviceUnitId) && {LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE} - {getLabelOfOption(receivableTypeOptions, rent?.override_receivable_type) || '-'} + {getLabelOfOption(receivableTypeOptions, rent.override_receivable_type) || '-'} - + + } {oldValuesVisible && @@ -335,12 +339,13 @@ const BasicInfoOneTime = ({ const BasicInfoFixed = ({ leaseAttributes, - receivableTypeOptions, - rent -}: Props) => { + rent, + serviceUnitId, +}: PropsWithServiceUnitId) => { const dueDatesTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.DUE_DATES_TYPE); const typeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.TYPE); - + const receivableTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE); + return @@ -433,16 +438,19 @@ const BasicInfoFixed = ({ + + { showOverrideReceivableTypeField(serviceUnitId) && {LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE} - {getLabelOfOption(receivableTypeOptions, rent?.override_receivable_type) || '-'} + {getLabelOfOption(receivableTypeOptions, rent.override_receivable_type) || '-'} + } ; }; @@ -498,18 +506,18 @@ const BasicInfoFree = ({ ; }; + const BasicInfo = ({ leaseAttributes, - receivableTypes, rent, - rentType -}: Props) => { - const receivableTypeOptions = receivableTypes?.map((rt) => ({ value: rt.id, label: rt.name })) || []; + rentType, + serviceUnitId, +}: PropsWithServiceUnitId) => { return {!rentType && Vuokralajia ei ole valittu} - {(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && } - {rentType === RentTypes.ONE_TIME && } - {rentType === RentTypes.FIXED && } + {(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && } + {rentType === RentTypes.ONE_TIME && } + {rentType === RentTypes.FIXED && } {rentType === RentTypes.FREE && } ; }; @@ -517,6 +525,5 @@ const BasicInfo = ({ export default connect(state => { return { leaseAttributes: getLeaseAttributes(state), - receivableTypes: getReceivableTypes(state) }; -})(BasicInfo); \ No newline at end of file +})(BasicInfo); diff --git a/src/leases/components/leaseSections/rent/BasicInfoEdit.tsx b/src/leases/components/leaseSections/rent/BasicInfoEdit.tsx index 6f3f3425..496c93c1 100644 --- a/src/leases/components/leaseSections/rent/BasicInfoEdit.tsx +++ b/src/leases/components/leaseSections/rent/BasicInfoEdit.tsx @@ -15,10 +15,11 @@ import { rentCustomDateOptions } from "@/leases/constants"; import { FieldTypes, FormNames } from "@/enums"; import { DueDatesPositions, FixedDueDates, LeaseRentDueDatesFieldPaths, LeaseRentDueDatesFieldTitles, LeaseRentsFieldPaths, LeaseRentsFieldTitles, RentCycles, RentTypes, RentDueDateTypes } from "@/leases/enums"; import { UsersPermissions } from "@/usersPermissions/enums"; -import { formatDueDates, formatSeasonalDate } from "@/leases/helpers"; +import { formatDueDates, formatSeasonalDate, showOverrideReceivableTypeField } from "@/leases/helpers"; import { getUiDataLeaseKey } from "@/uiData/helpers"; import { getFieldAttributes, hasPermissions, isFieldAllowedToEdit, isFieldAllowedToRead, isFieldRequired } from "@/util/helpers"; import { getAttributes as getLeaseAttributes, getCurrentLease } from "@/leases/selectors"; +import { getReceivableTypes } from "@/leaseCreateCharge/selectors"; import { getLeaseTypeList } from "@/leaseType/selectors"; import { getUsersPermissions } from "@/usersPermissions/selectors"; import { PlotSearchFieldPaths } from "@/plotSearch/enums"; @@ -182,7 +183,7 @@ type BasicInfoEmptyProps = { const BasicInfoEmpty = ({ isSaveClicked, - leaseAttributes + leaseAttributes, }: BasicInfoEmptyProps) => { return @@ -203,6 +204,8 @@ type BasicInfoIndexOrManualProps = { rentType: string; isSaveClicked: boolean; leaseAttributes: Attributes; + receivableTypeOptions: Array>; + serviceUnitId: number; usersPermissions: UsersPermissionsType; yearlyDueDates: Array; }; @@ -215,6 +218,8 @@ const BasicInfoIndexOrManual = ({ rentType, isSaveClicked, leaseAttributes, + receivableTypeOptions, + serviceUnitId, usersPermissions, yearlyDueDates }: BasicInfoIndexOrManualProps) => { @@ -324,17 +329,23 @@ const BasicInfoIndexOrManual = ({ + + { showOverrideReceivableTypeField(serviceUnitId) && + } ; }; @@ -348,7 +359,7 @@ type BasicInfoOneTimeProps = { const BasicInfoOneTime = ({ isSaveClicked, - leaseAttributes + leaseAttributes, }: BasicInfoOneTimeProps) => { return @@ -381,7 +392,6 @@ const BasicInfoOneTime = ({ - @@ -391,17 +401,7 @@ const BasicInfoOneTime = ({ - - - - - - - + ; }; @@ -411,6 +411,8 @@ type BasicInfoFixedProps = { field: string; isSaveClicked: boolean; leaseAttributes: Attributes; + receivableTypeOptions: Array>; + serviceUnitId: number; usersPermissions: UsersPermissionsType; yearlyDueDates: Array; }; @@ -421,6 +423,8 @@ const BasicInfoFixed = ({ field, isSaveClicked, leaseAttributes, + receivableTypeOptions, + serviceUnitId, usersPermissions, yearlyDueDates }: BasicInfoFixedProps) => { @@ -496,18 +500,23 @@ const BasicInfoFixed = ({ + + { showOverrideReceivableTypeField(serviceUnitId) && - + } ; }; @@ -557,6 +566,24 @@ const BasicInfoFree = ({ ; }; +/** + * Get receivable type options for override receivable type select. + * ReceivableTypes must be fetched separately from API, because receivabletype + * choices from leaseAttributes are not filtered by service unit. + * + * @param receivableTypes Receivable types filtered by lease's service unit + * @returns Array Receivabletype options for select element + */ +export const getOverrideReceivableTypeOptions = (receivableTypes: Array>) => { + const options = receivableTypes.map((rt) => ({ + label: rt.name, + value: rt.id + })); + const sortedOptions = options.sort((a, b) => a.label.localeCompare(b.label)); + const emptyItem = { label: "", value: "" }; + return [emptyItem, ...sortedOptions]; +} + type Props = { change: (...args: Array) => any; currentLease: Lease; @@ -568,6 +595,7 @@ type Props = { isSaveClicked: boolean; leaseAttributes: Attributes; leaseTypes: LeaseTypeList; + receivableTypes: Array>; rentType: string | null | undefined; usersPermissions: UsersPermissionsType; }; @@ -582,6 +610,7 @@ const BasicInfoEdit = ({ isSaveClicked, leaseAttributes, leaseTypes, + receivableTypes, rentType, usersPermissions }: Props) => { @@ -591,13 +620,13 @@ const BasicInfoEdit = ({ if (!dueDatesPerYear || !leaseType || dueDatesType !== RentDueDateTypes.FIXED) return []; return FixedDueDates[rentType === RentTypes.FIXED ? DueDatesPositions.START_OF_MONTH : leaseType.due_dates_position][dueDatesPerYear]; }; - const yearlyDueDates = getYearlyDueDates(); + const receivableTypeOptions=getOverrideReceivableTypeOptions(receivableTypes); return {!rentType && } - {(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && } + {(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && } {rentType === RentTypes.ONE_TIME && } - {rentType === RentTypes.FIXED && } + {rentType === RentTypes.FIXED && } {rentType === RentTypes.FREE && } ; }; @@ -617,8 +646,9 @@ export default connect((state, props: BasicInfoEditProps) => { dueDates: selector(state, `${props.field}.due_dates`), leaseAttributes: getLeaseAttributes(state), leaseTypes: getLeaseTypeList(state), + receivableTypes: getReceivableTypes(state), usersPermissions: getUsersPermissions(state) }; }, { change -})(BasicInfoEdit); \ No newline at end of file +})(BasicInfoEdit); diff --git a/src/leases/components/leaseSections/rent/RentItem.tsx b/src/leases/components/leaseSections/rent/RentItem.tsx index 00b09fe7..ca497ef9 100644 --- a/src/leases/components/leaseSections/rent/RentItem.tsx +++ b/src/leases/components/leaseSections/rent/RentItem.tsx @@ -32,6 +32,7 @@ type Props = { rents: Array>; rentAdjustmentsCollapseState: boolean; rentCollapseState: boolean; + serviceUnitId: number; }; const RentItem = ({ @@ -45,7 +46,8 @@ const RentItem = ({ rent, rents, rentAdjustmentsCollapseState, - rentCollapseState + rentCollapseState, + serviceUnitId, }: Props) => { const handleCollapseToggle = (key: string, val: boolean) => { receiveCollapseStates({ @@ -108,7 +110,7 @@ const RentItem = ({ } headerTitle={ {getLabelOfOption(typeOptions, rentType) || '-'} } onToggle={handleRentCollapseToggle}> - + {(rentTypeIsIndex || rentTypeIsIndex2022 || rentTypeIsManual) && @@ -162,4 +164,4 @@ export default connect((state, props) => { }; }, { receiveCollapseStates -})(RentItem); \ No newline at end of file +})(RentItem); diff --git a/src/leases/components/leaseSections/rent/Rents.tsx b/src/leases/components/leaseSections/rent/Rents.tsx index 1a1a0d78..19e83b29 100644 --- a/src/leases/components/leaseSections/rent/Rents.tsx +++ b/src/leases/components/leaseSections/rent/Rents.tsx @@ -67,14 +67,14 @@ const Rents = ({ <> {!rents || !rents.length && Ei vuokria} {rents && !!rents.length && rents.map(rent => { - return ; + return ; })} {!!rentsArchived.length &&

Arkisto

} - {!!rentsArchived.length && rentsArchived.map(rent => )} + {!!rentsArchived.length && rentsArchived.map(rent => )}
@@ -110,4 +110,4 @@ const mapStateToProps = (state: RootState) => { }; }; -export default flowRight(connect(mapStateToProps), withRouter)(Rents) as React.ComponentType; \ No newline at end of file +export default flowRight(connect(mapStateToProps), withRouter)(Rents) as React.ComponentType; diff --git a/src/leases/enums.ts b/src/leases/enums.ts index e77dd082..fe951ef3 100644 --- a/src/leases/enums.ts +++ b/src/leases/enums.ts @@ -907,7 +907,7 @@ export const LeaseRentsFieldTitles = { Y_VALUE: 'Y-luku', Y_VALUE_START: 'Y-luku alkaen', YEARLY_DUE_DATES: 'Eräpäivät (pv.kk)', - OVERRIDE_RECEIVABLE_TYPE: 'Korvaava saamislaji' + OVERRIDE_RECEIVABLE_TYPE: 'Korvaava saamislaji laskuille' }; /** @@ -1594,4 +1594,4 @@ export const calculatorTypeOptions = [{ }, { value: 'device cabinet', label: 'Laitekaappi' -}]; \ No newline at end of file +}]; diff --git a/src/leases/helpers.ts b/src/leases/helpers.ts index 1be20b7d..bc6cb19e 100644 --- a/src/leases/helpers.ts +++ b/src/leases/helpers.ts @@ -10,6 +10,7 @@ import { FormNames, TableSortOrder } from "@/enums"; import { CollateralTypes, ConstructabilityType, DecisionTypeKinds, LeaseState, LeaseTenantRentSharesFieldPaths, LeaseStatus, RecipientOptions, RelationTypes, RentAdjustmentAmountTypes, RentCycles, RentDueDateTypes, RentTypes, SubventionTypes, TenantContactType } from "./enums"; import { CalculatorTypes } from "@/leases/enums"; import { LeaseAreaAttachmentTypes } from "@/leaseAreaAttachment/enums"; +import { ServiceUnitIds } from "@/serviceUnits/enums"; import { getContactFullName, getContentContact } from "@/contacts/helpers"; import { getContentLessor } from "@/lessor/helpers"; import { getContentPropertyIdentifiers } from "@/rentbasis/helpers"; @@ -1641,7 +1642,7 @@ export const getContentRents = (lease: Record): Array): string => { /** * Sort due dates by month and day - * @param {Array} dueDates + * @param {Array} dueDates * @returns {Array} Sorted array of due date objects with day and month properties. */ export const sortDueDates = (dueDates: Array): Array => { @@ -2931,7 +2932,7 @@ export const restructureLease = (lease: Record): Record, b: Record { + return leaseServiceUnitId !== ServiceUnitIds.MAKE; +}