Skip to content

Commit

Permalink
Add use_rent_override_receivable_type to service units
Browse files Browse the repository at this point in the history
  • Loading branch information
juho-kettunen-nc committed Nov 20, 2024
1 parent a3280fe commit fb1f3f3
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 78 deletions.
26 changes: 13 additions & 13 deletions src/leases/components/leaseSections/rent/BasicInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 type { ServiceUnit } from "@/serviceUnits/types";
type SeasonalDatesProps = {
leaseAttributes: Attributes;
rent: Record<string, any>;
Expand Down Expand Up @@ -40,15 +40,15 @@ type Props = {
rentType: string | null | undefined;
};

type PropsWithServiceUnitId = Props & {
serviceUnitId: number;
type PropsWithServiceUnit = Props & {
serviceUnit: ServiceUnit;
}

const BasicInfoIndexOrManual = ({
leaseAttributes,
rent,
serviceUnitId,
}: PropsWithServiceUnitId) => {
serviceUnit,
}: PropsWithServiceUnit) => {
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);
};
Expand Down Expand Up @@ -177,7 +177,7 @@ const BasicInfoIndexOrManual = ({
</Row>}

<Row>
{ showOverrideReceivableTypeField(serviceUnitId) &&
{ serviceUnit.use_rent_override_receivable_type &&
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Column small={12} medium={4} large={4}>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
Expand Down Expand Up @@ -340,8 +340,8 @@ const BasicInfoOneTime = ({
const BasicInfoFixed = ({
leaseAttributes,
rent,
serviceUnitId,
}: PropsWithServiceUnitId) => {
serviceUnit,
}: PropsWithServiceUnit) => {
const dueDatesTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.DUE_DATES_TYPE);
const typeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.TYPE);
const receivableTypeOptions = getFieldOptions(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE);
Expand Down Expand Up @@ -421,7 +421,7 @@ const BasicInfoFixed = ({
</Row>

<Row>
{ showOverrideReceivableTypeField(serviceUnitId) &&
{ serviceUnit.use_rent_override_receivable_type &&
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Column small={12} medium={4} large={4}>
<FormTextTitle uiDataKey={getUiDataLeaseKey(LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
Expand Down Expand Up @@ -511,13 +511,13 @@ const BasicInfo = ({
leaseAttributes,
rent,
rentType,
serviceUnitId,
}: PropsWithServiceUnitId) => {
serviceUnit,
}: PropsWithServiceUnit) => {
return <Fragment>
{!rentType && <FormText>Vuokralajia ei ole valittu</FormText>}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} serviceUnitId={serviceUnitId}/>}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} serviceUnit={serviceUnit}/>}
{rentType === RentTypes.ONE_TIME && <BasicInfoOneTime leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} serviceUnitId={serviceUnitId} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} serviceUnit={serviceUnit} />}
{rentType === RentTypes.FREE && <BasicInfoFree leaseAttributes={leaseAttributes} rent={rent} rentType={rentType} />}
</Fragment>;
};
Expand Down
24 changes: 12 additions & 12 deletions src/leases/components/leaseSections/rent/BasicInfoEdit.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ 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 { isServiceUnitAkvOrKuva } from "@/serviceUnits/enums";
import { formatDueDates, formatSeasonalDate, showOverrideReceivableTypeField } from "@/leases/helpers";
import { formatDueDates, formatSeasonalDate } 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";
Expand All @@ -27,6 +26,7 @@ import { PlotSearchFieldPaths } from "@/plotSearch/enums";
import type { Attributes } from "types";
import type { DueDate, Lease } from "@/leases/types";
import type { LeaseTypeList } from "@/leaseType/types";
import type { ServiceUnit } from "@/serviceUnits/types";
import type { UsersPermissions as UsersPermissionsType } from "@/usersPermissions/types";
const formName = FormNames.LEASE_RENTS;
const selector = formValueSelector(formName);
Expand Down Expand Up @@ -206,7 +206,7 @@ type BasicInfoIndexOrManualProps = {
isSaveClicked: boolean;
leaseAttributes: Attributes;
receivableTypeOptions: Array<Record<string, any>>;
leaseServiceUnitId: number;
serviceUnit: ServiceUnit;
usersPermissions: UsersPermissionsType;
yearlyDueDates: Array<DueDate>;
};
Expand All @@ -220,7 +220,7 @@ const BasicInfoIndexOrManual = ({
isSaveClicked,
leaseAttributes,
receivableTypeOptions,
leaseServiceUnitId,
serviceUnit,
usersPermissions,
yearlyDueDates
}: BasicInfoIndexOrManualProps) => {
Expand Down Expand Up @@ -314,7 +314,7 @@ const BasicInfoIndexOrManual = ({
</Row>}

<Row>
{ showOverrideReceivableTypeField(leaseServiceUnitId) &&
{ serviceUnit.use_rent_override_receivable_type &&
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Column small={12} medium={6} large={4}>
<FormField
Expand All @@ -324,7 +324,7 @@ const BasicInfoIndexOrManual = ({
overrideValues={{
label: LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE,
options: receivableTypeOptions,
required: isServiceUnitAkvOrKuva(leaseServiceUnitId),
required: true,
}}
/>
</Column>
Expand Down Expand Up @@ -413,7 +413,7 @@ type BasicInfoFixedProps = {
isSaveClicked: boolean;
leaseAttributes: Attributes;
receivableTypeOptions: Array<Record<string, any>>;
leaseServiceUnitId: number;
serviceUnit: ServiceUnit;
usersPermissions: UsersPermissionsType;
yearlyDueDates: Array<DueDate>;
};
Expand All @@ -425,7 +425,7 @@ const BasicInfoFixed = ({
isSaveClicked,
leaseAttributes,
receivableTypeOptions,
leaseServiceUnitId,
serviceUnit,
usersPermissions,
yearlyDueDates
}: BasicInfoFixedProps) => {
Expand Down Expand Up @@ -485,7 +485,7 @@ const BasicInfoFixed = ({
</Row>

<Row>
{ showOverrideReceivableTypeField(leaseServiceUnitId) &&
{ serviceUnit.use_rent_override_receivable_type &&
<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.OVERRIDE_RECEIVABLE_TYPE)}>
<Column small={12} medium={6} large={4}>
<FormField
Expand All @@ -495,7 +495,7 @@ const BasicInfoFixed = ({
overrideValues={{
label: LeaseRentsFieldTitles.OVERRIDE_RECEIVABLE_TYPE,
options: receivableTypeOptions,
required: isServiceUnitAkvOrKuva(leaseServiceUnitId),
required: true,
}}
/>
</Column>
Expand Down Expand Up @@ -625,9 +625,9 @@ const BasicInfoEdit = ({
const receivableTypeOptions=getOverrideReceivableTypeOptions(receivableTypes);
return <Fragment>
{!rentType && <BasicInfoEmpty isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} />}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual cycle={cycle} dueDates={dueDates} dueDatesType={dueDatesType} field={field} rentType={rentType} isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} usersPermissions={usersPermissions} yearlyDueDates={yearlyDueDates} receivableTypeOptions={receivableTypeOptions} leaseServiceUnitId={currentLease.service_unit.id} />}
{(rentType === RentTypes.INDEX || rentType === RentTypes.INDEX2022 || rentType === RentTypes.MANUAL) && <BasicInfoIndexOrManual cycle={cycle} dueDates={dueDates} dueDatesType={dueDatesType} field={field} rentType={rentType} isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} usersPermissions={usersPermissions} yearlyDueDates={yearlyDueDates} receivableTypeOptions={receivableTypeOptions} serviceUnit={currentLease.service_unit} />}
{rentType === RentTypes.ONE_TIME && <BasicInfoOneTime dueDates={dueDates} dueDatesType={dueDatesType} isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} usersPermissions={usersPermissions} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed dueDates={dueDates} dueDatesType={dueDatesType} field={field} isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} usersPermissions={usersPermissions} yearlyDueDates={yearlyDueDates} receivableTypeOptions={receivableTypeOptions} leaseServiceUnitId={currentLease.service_unit.id} />}
{rentType === RentTypes.FIXED && <BasicInfoFixed dueDates={dueDates} dueDatesType={dueDatesType} field={field} isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} usersPermissions={usersPermissions} yearlyDueDates={yearlyDueDates} receivableTypeOptions={receivableTypeOptions} serviceUnit={currentLease.service_unit} />}
{rentType === RentTypes.FREE && <BasicInfoFree isSaveClicked={isSaveClicked} leaseAttributes={leaseAttributes} />}
</Fragment>;
};
Expand Down
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 @@ -19,6 +19,8 @@ import { getUiDataLeaseKey } from "@/uiData/helpers";
import { formatDateRange, getFieldOptions, getLabelOfOption, isActive, isArchived, isFieldAllowedToRead } from "@/util/helpers";
import { getAttributes as getLeaseAttributes, getCollapseStateByKey } from "@/leases/selectors";
import type { Attributes } from "types";
import type { ServiceUnit } from "@/serviceUnits/types";

const formName = FormNames.LEASE_RENTS;
type Props = {
contractRentsCollapseState: boolean;
Expand All @@ -32,7 +34,7 @@ type Props = {
rents: Array<Record<string, any>>;
rentAdjustmentsCollapseState: boolean;
rentCollapseState: boolean;
serviceUnitId: number;
serviceUnit: ServiceUnit;
};

const RentItem = ({
Expand All @@ -47,7 +49,7 @@ const RentItem = ({
rents,
rentAdjustmentsCollapseState,
rentCollapseState,
serviceUnitId,
serviceUnit,
}: Props) => {
const handleCollapseToggle = (key: string, val: boolean) => {
receiveCollapseStates({
Expand Down Expand Up @@ -110,7 +112,7 @@ const RentItem = ({
</Column>} headerTitle={<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentsFieldPaths.TYPE)}>
{getLabelOfOption(typeOptions, rentType) || '-'}
</Authorization>} onToggle={handleRentCollapseToggle}>
<BasicInfo rent={rent} rentType={rentType} serviceUnitId={serviceUnitId} />
<BasicInfo rent={rent} rentType={rentType} serviceUnit={serviceUnit} />

<Authorization allow={isFieldAllowedToRead(leaseAttributes, LeaseRentFixedInitialYearRentsFieldPaths.FIXED_INITIAL_YEAR_RENTS)}>
{(rentTypeIsIndex || rentTypeIsIndex2022 || rentTypeIsManual) && <Collapse className='collapse__secondary' defaultOpen={fixedInitialYearRentsCollapseState !== undefined ? fixedInitialYearRentsCollapseState : true} headerTitle={`${LeaseRentFixedInitialYearRentsFieldTitles.FIXED_INITIAL_YEAR_RENTS} (${fixedInitialYearRents.length})`} onToggle={handleFixedInitialYearRentsCollapseToggle} uiDataKey={getUiDataLeaseKey(LeaseRentFixedInitialYearRentsFieldPaths.FIXED_INITIAL_YEAR_RENTS)}>
Expand Down
4 changes: 2 additions & 2 deletions src/leases/components/leaseSections/rent/Rents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,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} serviceUnitId={currentLease.service_unit.id} />;
return <RentItem key={rent.id} rent={rent} rents={rents} serviceUnit={currentLease.service_unit} />;
})}

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

Expand Down
12 changes: 0 additions & 12 deletions src/leases/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ 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, isServiceUnitAkvOrKuva } from "@/serviceUnits/enums";
import { getContactFullName, getContentContact } from "@/contacts/helpers";
import { getContentLessor } from "@/lessor/helpers";
import { getContentPropertyIdentifiers } from "@/rentbasis/helpers";
Expand Down Expand Up @@ -2952,14 +2951,3 @@ export const sortRelatedHistoryItems = (a: Record<string, any>, b: Record<string
return 0;
}
};

/**
* The feature for override_receivable_type is only for AKV and KuVa leases.
* MaKe users don't want the field visible, to avoid clutter and confusion.
*
* @param leaseServiceUnitId ID of the lease's service unit
* @returns boolean Whether the field should be visible
*/
export const showOverrideReceivableTypeField = (leaseServiceUnitId: number): boolean => {
return isServiceUnitAkvOrKuva(leaseServiceUnitId);
}
33 changes: 0 additions & 33 deletions src/serviceUnits/enums.ts

This file was deleted.

6 changes: 3 additions & 3 deletions src/serviceUnits/types.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import type { Action } from "@/types";
export type ServiceUnit = { id: number, name: string };
export type ServiceUnits = Array<Record<string, any>>;
export type ServiceUnit = { id: number, name: string, use_rent_override_receivable_type: boolean };
export type ServiceUnits = Array<ServiceUnit>;
export type ServiceUnitState = {
isFetching: boolean;
serviceUnits: ServiceUnits;
};
export type FetchServiceUnitsAction = Action<string, void>;
export type ReceiveServiceUnitsAction = Action<string, ServiceUnits>;
export type ServiceUnitsNotFoundAction = Action<string, void>;
export type ServiceUnitsNotFoundAction = Action<string, void>;

0 comments on commit fb1f3f3

Please sign in to comment.