diff --git a/frontend/src/features/permits/components/feeSummary/FeeSummary.tsx b/frontend/src/features/permits/components/feeSummary/FeeSummary.tsx index 9c105d3e1..27ecfd7f8 100644 --- a/frontend/src/features/permits/components/feeSummary/FeeSummary.tsx +++ b/frontend/src/features/permits/components/feeSummary/FeeSummary.tsx @@ -1,6 +1,6 @@ import { Nullable } from "../../../../common/types/common"; import { feeSummaryDisplayText } from "../../helpers/feeSummary"; -import { permitTypeDisplayText } from "../../types/PermitType"; +import { PermitType, permitTypeDisplayText } from "../../types/PermitType"; import "./FeeSummary.scss"; export const FeeSummary = ({ @@ -9,12 +9,12 @@ export const FeeSummary = ({ permitDuration, hideDescriptions, }: { - permitType?: Nullable; + permitType?: Nullable; feeSummary?: Nullable; permitDuration?: number; hideDescriptions?: boolean; }) => { - const feeDisplayText = feeSummaryDisplayText(feeSummary, permitDuration); + const feeDisplayText = feeSummaryDisplayText(feeSummary, permitDuration, permitType); return (
diff --git a/frontend/src/features/permits/helpers/feeSummary.ts b/frontend/src/features/permits/helpers/feeSummary.ts index e521b0a68..68d56f78f 100644 --- a/frontend/src/features/permits/helpers/feeSummary.ts +++ b/frontend/src/features/permits/helpers/feeSummary.ts @@ -4,6 +4,7 @@ import { Permit } from "../types/permit"; import { isValidTransaction } from "./payment"; import { Nullable } from "../../../common/types/common"; import { PERMIT_STATES, getPermitState } from "./permitState"; +import { PERMIT_TYPES, PermitType } from "../types/PermitType"; import { applyWhenNotNullable, @@ -12,10 +13,16 @@ import { /** * Calculates the fee for a permit only by its duration. + * @param permitType Type of permit * @param duration Number of days for duration of permit * @returns Fee to be paid for the permit duration */ -export const calculateFeeByDuration = (duration: number) => { +export const calculateFeeByDuration = (permitType: PermitType, duration: number) => { + if (permitType === PERMIT_TYPES.TROW) { + // Only for TROW + return duration > 360 ? 1200 : Math.floor(duration / 30) * 100; + } + // Add more conditions for other permit types if needed // 1 Year === 365 days, but the fee for one year is only $360 return duration > 360 ? 360 : duration; }; @@ -24,20 +31,21 @@ export const calculateFeeByDuration = (duration: number) => { * Gets full display text for fee summary. * @param feeSummary fee summary field for a permit (if exists) * @param duration duration field for a permit (if exists) + * @param permitType type of permit (if exists) * @returns display text for the fee summary (currency amount to 2 decimal places) */ export const feeSummaryDisplayText = ( feeSummary?: Nullable, duration?: Nullable, + permitType?: Nullable, ) => { const feeFromSummary = applyWhenNotNullable( (numericStr) => Number(numericStr).toFixed(2), feeSummary, ); - const feeFromDuration = applyWhenNotNullable( - (num) => calculateFeeByDuration(num).toFixed(2), - duration, - ); + const feeFromDuration = duration && permitType ? + calculateFeeByDuration(permitType, duration).toFixed(2) : null; + const fee = getDefaultRequiredVal("0.00", feeFromSummary, feeFromDuration); const numericFee = Number(fee); return numericFee >= 0 ? `$${fee}` : `-$${(numericFee * -1).toFixed(2)}`; @@ -77,14 +85,16 @@ export const calculateNetAmount = (permitHistory: PermitHistory[]) => { * Calculates the amount that needs to be refunded (or paid if amount is negative) for a permit given a new duration period. * @param permitHistory List of history objects that make up the history of a permit and its transactions * @param currDuration Current (updated) duration of the permit + * @param currPermitType Permit type of current permit to refund * @returns Amount that needs to be refunded, or if negative then the amount that still needs to be paid */ export const calculateAmountToRefund = ( permitHistory: PermitHistory[], currDuration: number, + currPermitType: PermitType, ) => { const netPaid = calculateNetAmount(permitHistory); - const feeForCurrDuration = calculateFeeByDuration(currDuration); + const feeForCurrDuration = calculateFeeByDuration(currPermitType, currDuration); return netPaid - feeForCurrDuration; }; diff --git a/frontend/src/features/permits/helpers/getDefaultApplicationFormData.ts b/frontend/src/features/permits/helpers/getDefaultApplicationFormData.ts index e805af9b8..2b2407c36 100644 --- a/frontend/src/features/permits/helpers/getDefaultApplicationFormData.ts +++ b/frontend/src/features/permits/helpers/getDefaultApplicationFormData.ts @@ -182,6 +182,11 @@ export const getDefaultValues = ( applicationData?.permitData?.expiryDate, ); + const defaultPermitType = getDefaultRequiredVal( + permitType, + applicationData?.permitType, + ); + return { originalPermitId: getDefaultRequiredVal( "", @@ -194,10 +199,7 @@ export const getDefaultValues = ( ), permitId: getDefaultRequiredVal("", applicationData?.permitId), permitNumber: getDefaultRequiredVal("", applicationData?.permitNumber), - permitType: getDefaultRequiredVal( - permitType, - applicationData?.permitType, - ), + permitType: defaultPermitType, permitStatus: getDefaultRequiredVal( PERMIT_STATUSES.IN_PROGRESS, applicationData?.permitStatus, @@ -242,7 +244,7 @@ export const getDefaultValues = ( vehicleDetails: getDefaultVehicleDetails( applicationData?.permitData?.vehicleDetails, ), - feeSummary: `${calculateFeeByDuration(durationOrDefault)}`, + feeSummary: `${calculateFeeByDuration(defaultPermitType, durationOrDefault)}`, }, }; }; diff --git a/frontend/src/features/permits/pages/Amend/components/AmendPermitFinish.tsx b/frontend/src/features/permits/pages/Amend/components/AmendPermitFinish.tsx index debac2847..e3d0f8b0f 100644 --- a/frontend/src/features/permits/pages/Amend/components/AmendPermitFinish.tsx +++ b/frontend/src/features/permits/pages/Amend/components/AmendPermitFinish.tsx @@ -13,6 +13,7 @@ import { isValidTransaction } from "../../../helpers/payment"; import { hasPermitsActionFailed } from "../../../helpers/permitState"; import { ERROR_ROUTES } from "../../../../../routes/constants"; import { getDefaultRequiredVal } from "../../../../../common/helpers/util"; +import { DEFAULT_PERMIT_TYPE } from "../../../types/PermitType"; export const AmendPermitFinish = () => { const navigate = useNavigate(); @@ -39,6 +40,11 @@ export const AmendPermitFinish = () => { 0, amendmentApplication?.permitData?.permitDuration, ), + getDefaultRequiredVal( + DEFAULT_PERMIT_TYPE, + amendmentApplication?.permitType, + permit?.permitType, + ), ); const { mutation: startTransactionMutation, transaction } = diff --git a/frontend/src/features/permits/pages/Amend/components/AmendPermitReview.tsx b/frontend/src/features/permits/pages/Amend/components/AmendPermitReview.tsx index f8b8bd862..ae7fe270c 100644 --- a/frontend/src/features/permits/pages/Amend/components/AmendPermitReview.tsx +++ b/frontend/src/features/permits/pages/Amend/components/AmendPermitReview.tsx @@ -13,6 +13,7 @@ import { isValidTransaction } from "../../../helpers/payment"; import { getDatetimes } from "./helpers/getDatetimes"; import { useModifyAmendmentApplication } from "../../../hooks/hooks"; import { ERROR_ROUTES } from "../../../../../routes/constants"; +import { DEFAULT_PERMIT_TYPE } from "../../../types/PermitType"; import { applyWhenNotNullable, getDefaultRequiredVal, @@ -102,6 +103,11 @@ export const AmendPermitReview = () => { 0, amendmentApplication?.permitData?.permitDuration, ), + getDefaultRequiredVal( + DEFAULT_PERMIT_TYPE, + amendmentApplication?.permitType, + permit?.permitType, + ), ); return ( diff --git a/frontend/src/features/permits/pages/Application/components/form/PermitDetails.tsx b/frontend/src/features/permits/pages/Application/components/form/PermitDetails.tsx index 4b5d38bef..e9ddb4f3c 100644 --- a/frontend/src/features/permits/pages/Application/components/form/PermitDetails.tsx +++ b/frontend/src/features/permits/pages/Application/components/form/PermitDetails.tsx @@ -79,8 +79,8 @@ export const PermitDetails = ({ // this needs useEffect as this form field update process is manual, and needs to happen whenever startDate and duration changes // also, the form field component is accepting a dayJS object setValue("permitData.expiryDate", dayjs(expiryDate)); - setValue("permitData.feeSummary", `${calculateFeeByDuration(duration)}`); - }, [startDate, duration]); + setValue("permitData.feeSummary", `${calculateFeeByDuration(permitType, duration)}`); + }, [startDate, duration, permitType]); return ( diff --git a/frontend/src/features/permits/pages/Application/components/review/PermitReview.tsx b/frontend/src/features/permits/pages/Application/components/review/PermitReview.tsx index 1c04f5dd9..8aae70bc5 100644 --- a/frontend/src/features/permits/pages/Application/components/review/PermitReview.tsx +++ b/frontend/src/features/permits/pages/Application/components/review/PermitReview.tsx @@ -12,7 +12,7 @@ import { ReviewFeeSummary } from "./ReviewFeeSummary"; import { ReviewActions } from "./ReviewActions"; import { CompanyProfile } from "../../../../../manageProfile/types/manageProfile"; import { VehicleSubType } from "../../../../../manageVehicles/types/Vehicle"; -import { PermitType } from "../../../../types/PermitType"; +import { DEFAULT_PERMIT_TYPE, PermitType } from "../../../../types/PermitType"; import { calculateFeeByDuration } from "../../../../helpers/feeSummary"; import { getDefaultRequiredVal } from "../../../../../../common/helpers/util"; import { Nullable } from "../../../../../../common/types/common"; @@ -56,6 +56,7 @@ export const PermitReview = (props: PermitReviewProps) => { const feeSummary = props.calculatedFee ? props.calculatedFee : `${calculateFeeByDuration( + getDefaultRequiredVal(DEFAULT_PERMIT_TYPE, props.permitType), getDefaultRequiredVal(0, props.permitDuration), )}`; diff --git a/frontend/src/features/permits/pages/Application/tests/ApplicationReview.test.tsx b/frontend/src/features/permits/pages/Application/tests/ApplicationReview.test.tsx index 85bb11c80..1766b8ffe 100644 --- a/frontend/src/features/permits/pages/Application/tests/ApplicationReview.test.tsx +++ b/frontend/src/features/permits/pages/Application/tests/ApplicationReview.test.tsx @@ -413,6 +413,7 @@ describe("Review and Confirm Application Details", () => { permitData: { ...defaultApplicationData.permitData, feeSummary: `${calculateFeeByDuration( + defaultApplicationData.permitType, defaultApplicationData.permitData.permitDuration, )}`, }, diff --git a/frontend/src/features/permits/pages/Refund/RefundPage.tsx b/frontend/src/features/permits/pages/Refund/RefundPage.tsx index 56d71a959..cb1dd91bb 100644 --- a/frontend/src/features/permits/pages/Refund/RefundPage.tsx +++ b/frontend/src/features/permits/pages/Refund/RefundPage.tsx @@ -14,7 +14,7 @@ import { } from "@mui/material"; import "./RefundPage.scss"; -import { permitTypeDisplayText } from "../../types/PermitType"; +import { PermitType, permitTypeDisplayText } from "../../types/PermitType"; import { RefundFormData } from "./types/RefundFormData"; import { requiredMessage } from "../../../../common/helpers/validationMessages"; import { getErrorMessage } from "../../../../common/components/form/CustomFormComponents"; @@ -90,7 +90,7 @@ export const RefundPage = ({ fax?: Nullable; reason?: Nullable; permitNumber?: Nullable; - permitType?: Nullable; + permitType?: Nullable; permitAction: PermitAction; amountToRefund: number; onFinish: (refundData: RefundFormData) => void; diff --git a/vehicles/src/common/constants/permit.constant.ts b/vehicles/src/common/constants/permit.constant.ts index 633627f88..3b8bfe925 100644 --- a/vehicles/src/common/constants/permit.constant.ts +++ b/vehicles/src/common/constants/permit.constant.ts @@ -3,6 +3,6 @@ export const TROS_PRICE_PER_TERM = 30; export const TROS_MIN_VALID_DURATION = TROS_TERM; export const TROS_MAX_VALID_DURATION = 366; export const TROW_TERM = 30; -export const TROW_PRICE_PER_TERM = 30; +export const TROW_PRICE_PER_TERM = 100; export const TROW_MIN_VALID_DURATION = TROS_TERM; export const TROW_MAX_VALID_DURATION = 366; diff --git a/vehicles/src/common/helper/permit-fee.helper.ts b/vehicles/src/common/helper/permit-fee.helper.ts index 1fdc0de11..38da2783f 100644 --- a/vehicles/src/common/helper/permit-fee.helper.ts +++ b/vehicles/src/common/helper/permit-fee.helper.ts @@ -10,6 +10,8 @@ import { TROS_TERM, TROW_MAX_VALID_DURATION, TROW_MIN_VALID_DURATION, + TROW_PRICE_PER_TERM, + TROW_TERM, } from '../constants/permit.constant'; import { differenceBetween } from './date-time.helper'; import * as dayjs from 'dayjs'; @@ -81,8 +83,8 @@ export const permitFee = (application: Permit, oldAmount: number): number => { duration = 360; return currentPermitFee( duration, - TROS_PRICE_PER_TERM, - TROS_TERM, + TROW_PRICE_PER_TERM, + TROW_TERM, oldAmount, ); }