@@ -3,9 +3,12 @@ import { TRANSACTION_TYPES, TransactionType } from "../types/payment";
3
3
import { Permit } from "../types/permit" ;
4
4
import { isValidTransaction } from "./payment" ;
5
5
import { Nullable } from "../../../common/types/common" ;
6
- import { PERMIT_STATES , daysLeftBeforeExpiry , getPermitState } from "./permitState" ;
6
+ import { PERMIT_STATES , getPermitState } from "./permitState" ;
7
7
import { PERMIT_TYPES , PermitType } from "../types/PermitType" ;
8
- import { getDurationIntervalDays , maxDurationForPermitType } from "./dateSelection" ;
8
+ import {
9
+ getDurationIntervalDays ,
10
+ maxDurationForPermitType ,
11
+ } from "./dateSelection" ;
9
12
import {
10
13
applyWhenNotNullable ,
11
14
getDefaultRequiredVal ,
@@ -17,19 +20,27 @@ import {
17
20
* @param duration Number of days for duration of permit
18
21
* @returns Fee to be paid for the permit duration
19
22
*/
20
- export const calculateFeeByDuration = ( permitType : PermitType , duration : number ) => {
23
+ export const calculateFeeByDuration = (
24
+ permitType : PermitType ,
25
+ duration : number ,
26
+ ) => {
21
27
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 ;
27
36
28
37
const intervalDays = getDurationIntervalDays ( permitType ) ;
29
38
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
+
33
44
switch ( permitType ) {
34
45
// Add more conditions for other permit types if needed
35
46
case PERMIT_TYPES . STOS :
@@ -61,9 +72,11 @@ export const feeSummaryDisplayText = (
61
72
( numericStr ) => Number ( numericStr ) . toFixed ( 2 ) ,
62
73
feeSummary ,
63
74
) ;
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
+
67
80
const fee = getDefaultRequiredVal ( "0.00" , feeFromSummary , feeFromDuration ) ;
68
81
const numericFee = Number ( fee ) ;
69
82
return numericFee >= 0 ? `$${ fee } ` : `-$${ ( numericFee * - 1 ) . toFixed ( 2 ) } ` ;
@@ -114,7 +127,10 @@ export const calculateAmountToRefund = (
114
127
const netPaid = calculateNetAmount ( permitHistory ) ;
115
128
if ( isZeroAmount ( netPaid ) ) return 0 ; // If total paid is $0 (eg. no-fee permits), then refund nothing
116
129
117
- const feeForCurrDuration = calculateFeeByDuration ( currPermitType , currDuration ) ;
130
+ const feeForCurrDuration = calculateFeeByDuration (
131
+ currPermitType ,
132
+ currDuration ,
133
+ ) ;
118
134
return netPaid - feeForCurrDuration ;
119
135
} ;
120
136
@@ -142,13 +158,8 @@ export const calculateAmountForVoid = (
142
158
return 0 ;
143
159
}
144
160
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
147
163
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 ;
154
165
} ;
0 commit comments