Skip to content

Commit

Permalink
Move receivable type override to ContractRents
Browse files Browse the repository at this point in the history
Project steering group wants the field under contract rents instead of basic info, after all.
  • Loading branch information
juho-kettunen-nc committed Nov 7, 2024
1 parent 5d5812a commit d24b60c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 63 deletions.
52 changes: 6 additions & 46 deletions src/leases/components/leaseSections/rent/BasicInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@ import { Row, Column } from "react-foundation";
import Authorization from "@/components/authorization/Authorization";
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 { LeaseRentDueDatesFieldPaths, LeaseRentDueDatesFieldTitles, LeaseRentsFieldPaths, LeaseRentsFieldTitles, RentCycles, RentTypes, RentDueDateTypes } from "@/leases/enums";
import { formatDueDates, formatSeasonalDate, sortDueDates } 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<string, any>;
Expand All @@ -36,15 +35,12 @@ const SeasonalDates = ({

type Props = {
leaseAttributes: Attributes;
receivableTypes?: Array<any> | null | undefined;
receivableTypeOptions?: Array<any> | null | undefined;
rent: Record<string, any>;
rentType: string | null | undefined;
};

const BasicInfoIndexOrManual = ({
leaseAttributes,
receivableTypeOptions,
rent
}: Props) => {
const areOldInfoVisible = () => {
Expand Down Expand Up @@ -192,17 +188,6 @@ const BasicInfoIndexOrManual = ({
</Column>
</Row>

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Row>
<Column>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
{LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE}
</FormTextTitle>
<FormText>{getLabelOfOption(receivableTypeOptions, rent?.override_receivable_type) || '-'}</FormText>
</Column>
</Row>
</Authorization>

{oldValuesVisible && <Row>
<Column small={12} medium={4} large={2}>
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.ELEMENTARY_INDEX) || isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.INDEX_ROUNDING)}>
Expand Down Expand Up @@ -272,7 +257,6 @@ const BasicInfoIndexOrManual = ({

const BasicInfoOneTime = ({
leaseAttributes,
receivableTypeOptions,
rent
}: Props) => {
const typeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.TYPE);
Expand Down Expand Up @@ -331,27 +315,16 @@ const BasicInfoOneTime = ({
</Row>
</Authorization>

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Row>
<Column>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
{LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE}
</FormTextTitle>
<FormText>{getLabelOfOption(receivableTypeOptions, rent?.override_receivable_type) || '-'}</FormText>
</Column>
</Row>
</Authorization>
</Fragment>;
};

const BasicInfoFixed = ({
leaseAttributes,
receivableTypeOptions,
rent
}: Props) => {
const dueDatesTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.DUE_DATES_TYPE);
const typeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.TYPE);

return <Fragment>
<Row>
<Column small={6} medium={4} large={2}>
Expand Down Expand Up @@ -444,16 +417,6 @@ const BasicInfoFixed = ({
</Authorization>
</Column>
</Row>
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Row>
<Column>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
{LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE}
</FormTextTitle>
<FormText>{getLabelOfOption(receivableTypeOptions, rent?.override_receivable_type) || '-'}</FormText>
</Column>
</Row>
</Authorization>
</Fragment>;
};

Expand Down Expand Up @@ -511,23 +474,20 @@ const BasicInfoFree = ({

const BasicInfo = ({
leaseAttributes,
receivableTypes,
rent,
rentType
}: Props) => {
const receivableTypeOptions = receivableTypes?.map((rt) => ({ value: rt.id, label: rt.name })) || [];
return <Fragment>
{!rentType && <FormText>Vuokralajia ei ole valittu</FormText>}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual leaseAttributes={leaseAttributes} receivableTypeOptions={receivableTypeOptions} rent={rent} rentType={rentType} />}
{rentType === RentTypes.ONE_TIME && <BasicInfoOneTime leaseAttributes={leaseAttributes} receivableTypeOptions={receivableTypeOptions} rent={rent} rentType={rentType} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed leaseAttributes={leaseAttributes} receivableTypeOptions={receivableTypeOptions} rent={rent} rentType={rentType} />}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
{rentType === RentTypes.ONE_TIME && <BasicInfoOneTime leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
{rentType === RentTypes.FREE && <BasicInfoFree leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
</Fragment>;
};

export default connect(state => {
return {
leaseAttributes: getLeaseAttributes(state),
receivableTypes: getReceivableTypes(state)
};
})(BasicInfo);
})(BasicInfo);
33 changes: 27 additions & 6 deletions src/leases/components/leaseSections/rent/ContractRents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@ import BoxItemContainer from "@/components/content/BoxItemContainer";
import FormText from "@/components/form/FormText";
import FormTextTitle from "@/components/form/FormTextTitle";
import { LeaseRentContractRentsFieldPaths, LeaseRentContractRentsFieldTitles, RentTypes } from "@/leases/enums";
import { ServiceUnitIds } from "@/serviceUnits/enums";
import { getUiDataLeaseKey } from "@/uiData/helpers";
import { formatDate, formatNumber, getFieldOptions, getLabelOfOption, isEmptyValue, isFieldAllowedToRead } from "@/util/helpers";
import { getAttributes as getLeaseAttributes } from "@/leases/selectors";
import { withWindowResize } from "@/components/resize/WindowResizeHandler";
import { getReceivableTypes } from "@/leaseCreateCharge/selectors";
import type { Attributes } from "types";
type Props = {
contractRents: Array<Record<string, any>>;
largeScreen: boolean;
leaseAttributes: Attributes;
receivableTypes: Array<Record<string,any>>;
rentType: string;
overrideReceivableTypeId: number;
serviceUnitId: number;
};
type State = {
amountPeriodOptions: Array<Record<string, any>>;
baseAmountPeriodOptions: Array<Record<string, any>>;
intendedUseOptions: Array<Record<string, any>>;
indexOptions: Array<Record<string, any>>;
leaseAttributes: Attributes;
receivableTypeOptions: Array<Record<string, any>>;
};

class ContractRents extends PureComponent<Props, State> {
Expand All @@ -34,7 +40,8 @@ class ContractRents extends PureComponent<Props, State> {
baseAmountPeriodOptions: [],
intendedUseOptions: [],
indexOptions: [],
leaseAttributes: null
leaseAttributes: null,
receivableTypeOptions: [],
};

static getDerivedStateFromProps(props: Props, state: State) {
Expand All @@ -46,6 +53,7 @@ class ContractRents extends PureComponent<Props, State> {
newState.baseAmountPeriodOptions = getFieldOptions(props.leaseAttributes, LeaseRentContractRentsFieldPaths.BASE_AMOUNT_PERIOD);
newState.intendedUseOptions = getFieldOptions(props.leaseAttributes, LeaseRentContractRentsFieldPaths.INTENDED_USE);
newState.indexOptions = getFieldOptions(props.leaseAttributes, LeaseRentContractRentsFieldPaths.INDEX);
newState.receivableTypeOptions = getFieldOptions(props.leaseAttributes, LeaseRentContractRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE);
}

return newState;
Expand All @@ -56,15 +64,17 @@ class ContractRents extends PureComponent<Props, State> {
contractRents,
largeScreen,
leaseAttributes,
rentType
rentType,
overrideReceivableTypeId,
serviceUnitId
} = this.props;
const {
amountPeriodOptions,
baseAmountPeriodOptions,
intendedUseOptions,
indexOptions
indexOptions,
receivableTypeOptions
} = this.state;

const getAmountUiDataKey = () => {
if (rentType === RentTypes.FIXED) {
return getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.AMOUNT_FIXED_RENT);
Expand Down Expand Up @@ -121,6 +131,16 @@ class ContractRents extends PureComponent<Props, State> {
</>
</Authorization>
</Column>
{(serviceUnitId !== ServiceUnitIds.MAKE) && <Column small={6} medium={4} large={3}>
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
{LeaseRentContractRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE || '-'}
</FormTextTitle>
<FormText>{getLabelOfOption(receivableTypeOptions, overrideReceivableTypeId) || '-'}</FormText>
</>
</Authorization>
</Column>}
{rentType === RentTypes.INDEX2022 && <Column small={6} medium={4} large={2}>
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.INDEX)}>
<>
Expand Down Expand Up @@ -200,6 +220,7 @@ class ContractRents extends PureComponent<Props, State> {

export default flowRight(withWindowResize, connect(state => {
return {
leaseAttributes: getLeaseAttributes(state)
leaseAttributes: getLeaseAttributes(state),
receivableTypes: getReceivableTypes(state)
};
}))(ContractRents);
}))(ContractRents);
8 changes: 5 additions & 3 deletions src/leases/components/leaseSections/rent/RentItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ type Props = {
rents: Array<Record<string, any>>;
rentAdjustmentsCollapseState: boolean;
rentCollapseState: boolean;
serviceUnitId: number;
};

const RentItem = ({
Expand All @@ -45,7 +46,8 @@ const RentItem = ({
rent,
rents,
rentAdjustmentsCollapseState,
rentCollapseState
rentCollapseState,
serviceUnitId
}: Props) => {
const handleCollapseToggle = (key: string, val: boolean) => {
receiveCollapseStates({
Expand Down Expand Up @@ -118,7 +120,7 @@ const RentItem = ({

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
{(rentTypeIsIndex || rentTypeIsIndex2022 || rentTypeIsFixed || rentTypeIsManual) && <Collapse className='collapse__secondary' defaultOpen={contractRentsCollapseState !== undefined ? contractRentsCollapseState : true} headerTitle={`${LeaseRentContractRentsFieldTitles.CONTRACT_RENTS} (${contractRents.length})`} onToggle={handleContractRentsCollapseToggle} uiDataKey={getUiDataLeaseKey(LeaseRentContractRentsFieldPaths.CONTRACT_RENTS)}>
<ContractRents contractRents={contractRents} rentType={rentType} />
<ContractRents contractRents={contractRents} rentType={rentType} overrideReceivableTypeId={rent.override_receivable_type} serviceUnitId={serviceUnitId} />
</Collapse>}
</Authorization>

Expand Down Expand Up @@ -162,4 +164,4 @@ export default connect((state, props) => {
};
}, {
receiveCollapseStates
})(RentItem);
})(RentItem);
7 changes: 4 additions & 3 deletions src/leases/components/leaseSections/rent/Rents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ const Rents = ({
const rents = rentsAll.filter(rent => !isArchived(rent));
const rentsArchived = rentsAll.filter(rent => isArchived(rent));
const warnings = getRentWarnings(rents);
const serviceUnitId = currentLease.service_unit.id;
return <Fragment>
<Title uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.RENTS)}>
{LeaseRentsFieldTitles.RENTS}
Expand Down Expand Up @@ -67,14 +68,14 @@ const Rents = ({
<>
{!rents || !rents.length && <FormText className='no-margin'>Ei vuokria</FormText>}
{rents && !!rents.length && rents.map(rent => {
return <RentItem key={rent.id} rent={rent} rents={rents} />;
return <RentItem key={rent.id} rent={rent} rents={rents} serviceUnitId={serviceUnitId} />;
})}

{!!rentsArchived.length && <h3 style={{
marginTop: 10,
marginBottom: 5
}}>Arkisto</h3>}
{!!rentsArchived.length && rentsArchived.map(rent => <RentItem key={rent.id} rent={rent} rents={rents} />)}
{!!rentsArchived.length && rentsArchived.map(rent => <RentItem key={rent.id} rent={rent} rents={rents} serviceUnitId={serviceUnitId} />)}
</>
</Authorization>

Expand Down Expand Up @@ -110,4 +111,4 @@ const mapStateToProps = (state: RootState) => {
};
};

export default flowRight(connect(mapStateToProps), withRouter)(Rents) as React.ComponentType<any>;
export default flowRight(connect(mapStateToProps), withRouter)(Rents) as React.ComponentType<any>;
11 changes: 6 additions & 5 deletions src/leases/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -872,7 +872,6 @@ export const LeaseRentsFieldPaths = {
Y_VALUE: 'rents.child.children.y_value',
YEARLY_DUE_DATES: 'rents.child.children.yearly_due_dates',
Y_VALUE_START: 'rents.child.children.y_value_start',
OVERRIDE_RECEIVABLE_TYPE: 'rents.child.children.override_receivable_type'
};

/**
Expand Down Expand Up @@ -907,7 +906,6 @@ 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'
};

/**
Expand Down Expand Up @@ -974,7 +972,9 @@ export const LeaseRentContractRentsFieldPaths = {
END_DATE: 'rents.child.children.contract_rents.child.children.end_date',
INDEX: 'rents.child.children.contract_rents.child.children.index',
INTENDED_USE: 'rents.child.children.contract_rents.child.children.intended_use',
START_DATE: 'rents.child.children.contract_rents.child.children.start_date'
START_DATE: 'rents.child.children.contract_rents.child.children.start_date',
// OVERRIDE_RECEIVABLE_TYPE: 'rents.child.children.contract_rents.child.children.override_receivable_type' // TODO use this after moving property to model ContractRents instead of Rent
OVERRIDE_RECEIVABLE_TYPE: 'rents.child.children.override_receivable_type'
};

/**
Expand All @@ -994,7 +994,8 @@ export const LeaseRentContractRentsFieldTitles = {
END_DATE: 'Loppupvm',
INDEX: 'Indeksi',
INTENDED_USE: 'Käyttötarkoitus',
START_DATE: 'Alkupvm'
START_DATE: 'Alkupvm',
OVERRIDE_RECEIVABLE_TYPE: 'Automaattisten laskujen saamislaji'
};

/**
Expand Down Expand Up @@ -1594,4 +1595,4 @@ export const calculatorTypeOptions = [{
}, {
value: 'device cabinet',
label: 'Laitekaappi'
}];
}];

0 comments on commit d24b60c

Please sign in to comment.