Skip to content

Commit 4d05079

Browse files
authored
ORV2-3211 - BVT: Void not refunding the total value (#1740)
Co-authored-by: GlenAOT <[email protected]>
1 parent aa12d4e commit 4d05079

File tree

1 file changed

+34
-23
lines changed

1 file changed

+34
-23
lines changed

frontend/src/features/permits/helpers/feeSummary.ts

Lines changed: 34 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { TRANSACTION_TYPES, TransactionType } from "../types/payment";
33
import { Permit } from "../types/permit";
44
import { isValidTransaction } from "./payment";
55
import { Nullable } from "../../../common/types/common";
6-
import { PERMIT_STATES, daysLeftBeforeExpiry, getPermitState } from "./permitState";
6+
import { PERMIT_STATES, getPermitState } from "./permitState";
77
import { PERMIT_TYPES, PermitType } from "../types/PermitType";
8-
import { getDurationIntervalDays, maxDurationForPermitType } from "./dateSelection";
8+
import {
9+
getDurationIntervalDays,
10+
maxDurationForPermitType,
11+
} from "./dateSelection";
912
import {
1013
applyWhenNotNullable,
1114
getDefaultRequiredVal,
@@ -17,19 +20,27 @@ import {
1720
* @param duration Number of days for duration of permit
1821
* @returns Fee to be paid for the permit duration
1922
*/
20-
export const calculateFeeByDuration = (permitType: PermitType, duration: number) => {
23+
export const calculateFeeByDuration = (
24+
permitType: PermitType,
25+
duration: number,
26+
) => {
2127
const maxAllowableDuration = maxDurationForPermitType(permitType);
22-
23-
// Make sure that duration is between 0 and max allowable duration (for given permit type)
24-
const safeDuration = duration < 0
25-
? 0
26-
: (duration > maxAllowableDuration) ? maxAllowableDuration : duration;
28+
29+
// Make sure that duration is between 0 and max allowable duration (for given permit type)
30+
const safeDuration =
31+
duration < 0
32+
? 0
33+
: duration > maxAllowableDuration
34+
? maxAllowableDuration
35+
: duration;
2736

2837
const intervalDays = getDurationIntervalDays(permitType);
2938

30-
const intervalPeriodsToPay = safeDuration > 360
31-
? Math.ceil(360 / intervalDays) : Math.ceil(safeDuration / intervalDays);
32-
39+
const intervalPeriodsToPay =
40+
safeDuration > 360
41+
? Math.ceil(360 / intervalDays)
42+
: Math.ceil(safeDuration / intervalDays);
43+
3344
switch (permitType) {
3445
// Add more conditions for other permit types if needed
3546
case PERMIT_TYPES.STOS:
@@ -61,9 +72,11 @@ export const feeSummaryDisplayText = (
6172
(numericStr) => Number(numericStr).toFixed(2),
6273
feeSummary,
6374
);
64-
const feeFromDuration = duration && permitType ?
65-
calculateFeeByDuration(permitType, duration).toFixed(2) : null;
66-
75+
const feeFromDuration =
76+
duration && permitType
77+
? calculateFeeByDuration(permitType, duration).toFixed(2)
78+
: null;
79+
6780
const fee = getDefaultRequiredVal("0.00", feeFromSummary, feeFromDuration);
6881
const numericFee = Number(fee);
6982
return numericFee >= 0 ? `$${fee}` : `-$${(numericFee * -1).toFixed(2)}`;
@@ -114,7 +127,10 @@ export const calculateAmountToRefund = (
114127
const netPaid = calculateNetAmount(permitHistory);
115128
if (isZeroAmount(netPaid)) return 0; // If total paid is $0 (eg. no-fee permits), then refund nothing
116129

117-
const feeForCurrDuration = calculateFeeByDuration(currPermitType, currDuration);
130+
const feeForCurrDuration = calculateFeeByDuration(
131+
currPermitType,
132+
currDuration,
133+
);
118134
return netPaid - feeForCurrDuration;
119135
};
120136

@@ -142,13 +158,8 @@ export const calculateAmountForVoid = (
142158
return 0;
143159
}
144160

145-
const netAmountPaid = calculateNetAmount(transactionHistory);
146-
if (isZeroAmount(netAmountPaid)) return 0; // If existing net paid is $0 (eg. no-fee permits), then refund nothing
161+
const netPaid = calculateNetAmount(transactionHistory);
162+
if (isZeroAmount(netPaid)) return 0; // If existing net paid is $0 (eg. no-fee permits), then refund nothing
147163

148-
const daysLeft = daysLeftBeforeExpiry(permit);
149-
const intervalDays = getDurationIntervalDays(permit.permitType);
150-
return calculateFeeByDuration(
151-
permit.permitType,
152-
Math.floor(daysLeft / intervalDays) * intervalDays,
153-
);
164+
return netPaid;
154165
};

0 commit comments

Comments
 (0)