@appcorp/fusion-storybook 0.3.20 → 0.3.21
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/utils/fine.d.ts
DELETED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import { StudentFeeBE } from "../type";
|
|
2
|
-
export declare function calculateStudentFeeFine(fee: StudentFeeBE, dueDateLength: number, perDateRate: number, asOf?: Date): number;
|
|
3
|
-
export declare function calculateAccumulatedStudentFeeFines(fees: StudentFeeBE[], dueDateLength: number, perDateRate: number, asOf?: Date): number;
|
package/utils/fine.js
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
import { PAYMENT_STATUS } from "../type";
|
|
2
|
-
function sameCalendarMonth(a, b) {
|
|
3
|
-
return a.getFullYear() === b.getFullYear() && a.getMonth() === b.getMonth();
|
|
4
|
-
}
|
|
5
|
-
function daysBetween(start, end) {
|
|
6
|
-
return Math.round((end.getTime() - start.getTime()) / (1000 * 60 * 60 * 24));
|
|
7
|
-
}
|
|
8
|
-
export function calculateStudentFeeFine(fee, dueDateLength, perDateRate, asOf) {
|
|
9
|
-
if (fee.status === PAYMENT_STATUS.CANCELLED ||
|
|
10
|
-
fee.status === PAYMENT_STATUS.REFUNDED) {
|
|
11
|
-
return 0;
|
|
12
|
-
}
|
|
13
|
-
if (fee.fine != null && fee.fine > 0) {
|
|
14
|
-
return fee.fine;
|
|
15
|
-
}
|
|
16
|
-
if (perDateRate <= 0 || fee.amountDue <= 0) {
|
|
17
|
-
return 0;
|
|
18
|
-
}
|
|
19
|
-
const dueDate = new Date(fee.dueDate);
|
|
20
|
-
const paymentDate = fee.paidAt ? new Date(fee.paidAt) : (asOf !== null && asOf !== void 0 ? asOf : new Date());
|
|
21
|
-
const isSameMonth = sameCalendarMonth(dueDate, paymentDate);
|
|
22
|
-
let fineDays;
|
|
23
|
-
if (isSameMonth) {
|
|
24
|
-
const paymentDay = paymentDate.getDate();
|
|
25
|
-
fineDays = paymentDay - dueDateLength;
|
|
26
|
-
if (fineDays <= 0)
|
|
27
|
-
return 0;
|
|
28
|
-
}
|
|
29
|
-
else {
|
|
30
|
-
const startOfDueMonth = new Date(dueDate.getFullYear(), dueDate.getMonth(), 1);
|
|
31
|
-
const endOfPrePaymentMonth = new Date(paymentDate.getFullYear(), paymentDate.getMonth(), 0);
|
|
32
|
-
fineDays = daysBetween(startOfDueMonth, endOfPrePaymentMonth) + 1;
|
|
33
|
-
}
|
|
34
|
-
const ratio = fee.amount > 0 ? fee.amountDue / fee.amount : 0;
|
|
35
|
-
const fineAmount = fineDays * perDateRate * ratio;
|
|
36
|
-
return Math.round(fineAmount * 100) / 100;
|
|
37
|
-
}
|
|
38
|
-
export function calculateAccumulatedStudentFeeFines(fees, dueDateLength, perDateRate, asOf) {
|
|
39
|
-
return fees
|
|
40
|
-
.filter((f) => f.status === PAYMENT_STATUS.PENDING ||
|
|
41
|
-
f.status === PAYMENT_STATUS.PARTIAL ||
|
|
42
|
-
f.status === PAYMENT_STATUS.OVERDUE)
|
|
43
|
-
.reduce((sum, f) => {
|
|
44
|
-
return sum + calculateStudentFeeFine(f, dueDateLength, perDateRate, asOf);
|
|
45
|
-
}, 0);
|
|
46
|
-
}
|