Skip to main content

Fines Configuration

Overview

This documentation outlines the Fines Configuration module, for managing late fees in the payx settings tab. It helps administrators to configure fines based on criteria, schedule them, and efficiently track and manage student fees.

Feature Description

  • Fine Configuration:

    • Fines can be created for specific batches, courses, quotas, years, and fee types in the PayX Setting tab.
    • Fines can either be fixed amounts or percentages of the total amount for the specific fee type.
    • Fines can be scheduled for a specific due date.
    • Admins can edit the fee amount and delete fines in the Fines Config tab.
  • Academic Fee Tracking:

    • Late fees applied to students can be viewed in the Academic Fee tab.
    • After late fees are applied to a student, admins can edit or delete fees for that specific student in the Academic Fees tab by searching for the student.
  • Late Fee Condition: The late fee is applied only when the due fee percentage criteria is not met for that student or students who fail to pay their fees before the due date if schedule fine due is enabled.

Process Flow

Development Steps

  • Backend:

    • Create a new module or update an existing one to manage fines configuration. This module should include functionalities for adding, editing, and deleting fines, as well as viewing the scheduled fines.
    • Design and implement a database schema that accommodates tenant and institution-specific data.
    • Calculate the late fee only if the due percentage for a student exceeds a predefined threshold.
      • Find admissions which are applicable to late fee by calculating with due percentage for that feeType.
      • Calculate the amount based on the respective type, whether percentage or fixed.
      • Apply the fine to those admissions and their respective fee types (create a ledger with isFine true).
      • Update the status of the fine to "applied" (set to true).
  • Frontend:

    • Create user interfaces for administrators to configure fines based on batches, courses, quotas, years, and fee types.
    • Integrate the late fee tracking mechanism with the Academic Fee tab. Ensure that late fees are appropriately displayed for students who have incurred them.
    • Implement the functionality to edit and delete fees for individual students in the Academic Fee tab.

Schema Changes

src/payments/domain/schemas/fee-fine.schema.ts
import { Course, Quota } from "@campxdev/server-shared";
import { Prop, Schema, SchemaFactory } from "@nestjs/mongoose";
import { HydratedDocument, Schema as MongooseSchema } from "mongoose";
import { getSetDefaultBoolFn, parseDecimal } from "src/utils/util-functions";
import { FeeType } from "./fee-type.schema";

export const FeeFineCName = "fee_fines";
export type FeeFineDocument = HydratedDocument<FeeFine>;

@Schema({
collection: FeeFineCName,
timestamps: true,
toJSON: { getters: true },
toObject: { getters: true },
})
export class FeeFine {
@Prop({ required: true })
id: string;

@Prop()
uniqueId: number;

@Prop({ required: true, type: MongooseSchema.Types.ObjectId })
tenantId: string;

@Prop({ required: true })
institutionId: string;

@Prop({ required: true })
courseId: string;

@Prop({ required: true })
batch: string;

@Prop({ required: true })
year: number;

@Prop({ required: true })
feeTypeId: string;

@Prop({ required: true })
quotaId: string;

@Prop({ required: true })
fineType: string;

@Prop({ default: false, set: getSetDefaultBoolFn(false) })
lateralEntry: boolean;

@Prop({ default: false, set: getSetDefaultBoolFn(false) })
hasScholarship: boolean;

@Prop({ default: false, set: getSetDefaultBoolFn(false) })
schedule: boolean;

@Prop()
dueDate: Date;

@Prop({
required: true,
type: MongooseSchema.Types.Decimal128,
get: parseDecimal,
})
duePercentage: number;

@Prop({ required: true })
calType: string;

@Prop({
required: true,
type: MongooseSchema.Types.Decimal128,
get: parseDecimal,
})
amount: number;

@Prop({ default: false, set: getSetDefaultBoolFn(false) })
applied: boolean;

@Prop({ type: MongooseSchema.Types.ObjectId })
createdById: string;

@Prop({ type: MongooseSchema.Types.ObjectId })
updatedById: string;

@Prop()
updatedAt: Date;

@Prop()
createdAt: Date;

feeType: FeeType;

course: Course;

quota: Quota;
}

export const FeeFineSchema = SchemaFactory.createForClass(FeeFine);
FeeFineSchema.index({ id: -1 }, { unique: true });
FeeFineSchema.index({ feeTypeId: 1 });

FeeFineSchema.index({
tenantId: 1,
applied: 1,
dueDate: 1,
schedule: 1,
});

FeeFineSchema.index({
tenantId: 1,
institutionId: 1,
courseId: 1,
batch: 1,
year: 1,
feeTypeId: 1,
applied: 1,
createdAt: 1,
});

export const FeeFineCalType = {
percentage: "percentage",
fixed: "fixed",
};

export const FeeAmountCheckOperation = {
greaterThan: "greaterThan",
lessThan: "lessThan",
greaterThanOrEqual: "greaterThanOrEqual",
lessThanOrEqual: "lessThanOrEqual",
equal: "equal",
notEqual: "notEqual",
};

export const FeeFineType = {
afterDueDate: "afterDueDate",
};

Functions with Individual Test Cases

  • createFeeFine

    • Test Cases:
      • Ensure course,quota,feeTypes are present.
      • Check if the fee fine is present and if the scheduled due date is available.
      • If previous ledgers are present, ensure they are paid or exist; otherwise, update the late fee.
  • updateFeeFine

    • Test Cases:
      • Check if the fee fine is present and if the scheduled due date is available.
      • Apply fines to students when fines are updated.
  • deleteFeeFine

    • Test Cases:
      • Check if the fee fine is present.
      • Delete the fee fine ledgers for students if the fine has not been paid when the fine is deleted.

Conclusion

The Fines Configuration module, with the added feature of applying late fees based on the due percentage for each student, offers a robust solution for managing late payments.

References