cloud-ide-model-schema
Version:
Pachage for schema management of Cloud IDEsys LMS
376 lines (375 loc) • 12.8 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CAdmissionFeeSnapshot = void 0;
var mongoose_1 = require("mongoose");
/**
* Admission Fee Snapshot Schema
*
* Purpose: Store complete fee structure snapshot at the time of admission confirmation/conversion
* This ensures that changes to fee structure definitions don't affect already applied fees
*
* BUSINESS LOGIC:
* 1. Stores complete fee structure with all items, amounts, discounts, scholarships
* 2. Linked to admission_id at confirmation stage
* 3. Updated with student_id at conversion stage
* 4. Used for viewing fee status instead of actual fee structure tables
* 5. Supports different school scenarios (apply at confirmation or conversion)
*/
/* SCHEMA START */
var admission_fee_snapshot = new mongoose_1.Schema({
adfsn_snapshot_number: {
type: String,
required: true,
unique: true,
maxlength: 50,
trim: true,
comment: "Unique snapshot number (auto-generated, e.g., SNAP2026-001)"
},
adfsn_admission_id_admap: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "admission_application_main",
required: true,
comment: "Reference to admission application"
},
adfsn_student_id: {
type: String,
maxlength: 50,
trim: true,
default: null,
comment: "Student ID (updated at conversion stage, null until conversion)"
},
adfsn_user_id_auth: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "auth_user_mst",
default: null,
comment: "Reference to user account (updated at conversion stage)"
},
adfsn_entity_id_syen: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_system_entity",
required: true,
comment: "Entity for which fees are applicable"
},
adfsn_academic_year_id_acayr: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "aca_academic_year",
required: true,
comment: "Academic year for which fees are applicable"
},
adfsn_class_program_id_acacpm: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "aca_class_program_master",
required: true,
comment: "Class/Program for which fees are applicable"
},
adfsn_class_program_term_id_acapt: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "aca_class_program_term",
default: null,
comment: "Program term (if applicable)"
},
adfsn_class_program_branch_id_acabrn: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "aca_class_prg_branch",
default: null,
comment: "Specialization/Branch (if applicable)"
},
adfsn_section_id_acapts: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "aca_prg_trm_section",
default: null,
comment: "Section (if applicable)"
},
adfsn_fee_structure_id_feest: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "fee_structures",
default: null,
comment: "Original fee structure ID (for reference, snapshot is independent)"
},
adfsn_snapshot_date: {
type: Date,
required: true,
default: Date.now,
comment: "Date when snapshot was created (confirmation or conversion date)"
},
adfsn_applied_at_stage: {
type: String,
required: true,
enum: ['CONFIRMATION', 'CONVERSION'],
comment: "Stage at which fees were applied (confirmation or student conversion)"
},
adfsn_fee_items: [{
// Store complete fee item details (snapshot of fee_structure_item at time of application)
feesi_original_item_id: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "fee_structure_items",
default: null,
comment: "Original fee structure item ID (for reference)"
},
feesi_category_id_sygms: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_general_master",
required: true,
comment: "Fee category"
},
feesi_category_name: {
type: String,
maxlength: 200,
trim: true,
comment: "Fee category name (snapshot)"
},
feesi_item_code: {
type: String,
maxlength: 50,
trim: true,
comment: "Fee item code"
},
feesi_item_name: {
type: String,
required: true,
maxlength: 200,
trim: true,
comment: "Fee item name"
},
feesi_description: {
type: String,
maxlength: 500,
trim: true,
comment: "Fee item description"
},
feesi_original_amount: {
type: Number,
required: true,
min: 0,
comment: "Original fee amount (before discounts/scholarships)"
},
feesi_applied_amount: {
type: Number,
required: true,
min: 0,
comment: "Amount applied (may differ from original if editable)"
},
feesi_discount_type: {
type: String,
enum: ['PERCENTAGE', 'FIXED_AMOUNT', null],
default: null,
comment: "Discount type if applicable"
},
feesi_discount_value: {
type: Number,
default: 0,
min: 0,
comment: "Discount value (percentage or fixed amount)"
},
feesi_discount_amount: {
type: Number,
required: true,
default: 0,
min: 0,
comment: "Calculated discount amount"
},
feesi_discount_reason_id_sygms: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_general_master",
default: null,
comment: "Discount reason (if applicable)"
},
feesi_scholarship_type_id_sygms: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_general_master",
default: null,
comment: "Scholarship type (if applicable)"
},
feesi_scholarship_category: {
type: String,
enum: ['FULL', 'PARTIAL', null],
default: null,
comment: "Scholarship category"
},
feesi_scholarship_percentage: {
type: Number,
default: null,
min: 0,
max: 100,
comment: "Scholarship percentage (if partial)"
},
feesi_scholarship_amount: {
type: Number,
required: true,
default: 0,
min: 0,
comment: "Scholarship amount"
},
feesi_final_amount: {
type: Number,
required: true,
min: 0,
comment: "Final amount after discounts and scholarships"
},
feesi_tax_applicable: {
type: Boolean,
default: false,
comment: "Is tax applicable"
},
feesi_tax_percentage: {
type: Number,
default: 0,
min: 0,
max: 100,
comment: "Tax percentage"
},
feesi_tax_amount: {
type: Number,
default: 0,
min: 0,
comment: "Tax amount"
},
feesi_total_amount: {
type: Number,
required: true,
min: 0,
comment: "Total amount including tax"
},
feesi_is_mandatory: {
type: Boolean,
default: true,
comment: "Is this fee mandatory"
},
feesi_is_refundable: {
type: Boolean,
default: false,
comment: "Is this fee refundable"
},
feesi_is_installment_allowed: {
type: Boolean,
default: false,
comment: "Allow installments"
},
feesi_installment_count: {
type: Number,
default: 1,
min: 1,
comment: "Number of installments"
},
feesi_due_date_offset_days: {
type: Number,
default: 0,
comment: "Due date offset in days"
},
feesi_collection_start_offset_days: {
type: Number,
default: 0,
comment: "Collection start offset"
},
feesi_collection_end_offset_days: {
type: Number,
default: 30,
comment: "Collection end offset"
},
feesi_display_order: {
type: Number,
default: 0,
comment: "Display order"
},
feesi_notes: {
type: String,
maxlength: 500,
trim: true,
comment: "Additional notes for this fee item"
}
}],
adfsn_total_original_amount: {
type: Number,
required: true,
min: 0,
comment: "Total original amount (sum of all fee items before discounts)"
},
adfsn_total_discount_amount: {
type: Number,
required: true,
default: 0,
min: 0,
comment: "Total discount amount"
},
adfsn_total_scholarship_amount: {
type: Number,
required: true,
default: 0,
min: 0,
comment: "Total scholarship amount"
},
adfsn_total_tax_amount: {
type: Number,
required: true,
default: 0,
min: 0,
comment: "Total tax amount"
},
adfsn_total_final_amount: {
type: Number,
required: true,
min: 0,
comment: "Total final amount (after all adjustments)"
},
adfsn_currency_id_sycr: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "core_currency",
default: null,
comment: "Currency for fees"
},
adfsn_currency_code: {
type: String,
maxlength: 10,
trim: true,
default: 'USD',
comment: "Currency code (snapshot)"
},
adfsn_notes: {
type: String,
maxlength: 1000,
trim: true,
comment: "Additional notes about this fee snapshot"
},
adfsn_created_by_user: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "auth_user_mst",
comment: "User who created this snapshot"
},
adfsn_modified_by_user: {
type: mongoose_1.default.Schema.Types.ObjectId,
ref: "auth_user_mst",
comment: "User who last modified this snapshot"
},
adfsn_isactive: {
type: Boolean,
default: true,
comment: "Active status"
},
adfsn_created_date: {
type: Date,
default: Date.now,
comment: "Creation timestamp"
},
adfsn_modified_date: {
type: Date,
default: Date.now,
comment: "Last modification timestamp"
}
}, {
collection: 'admission_fee_snapshot',
timestamps: false // Using custom timestamp fields
});
// Indexes for performance
admission_fee_snapshot.index({ adfsn_admission_id_admap: 1 });
admission_fee_snapshot.index({ adfsn_student_id: 1 });
admission_fee_snapshot.index({ adfsn_user_id_auth: 1 });
admission_fee_snapshot.index({ adfsn_entity_id_syen: 1 });
admission_fee_snapshot.index({ adfsn_academic_year_id_acayr: 1 });
admission_fee_snapshot.index({ adfsn_class_program_id_acacpm: 1 });
admission_fee_snapshot.index({ adfsn_snapshot_date: 1 });
admission_fee_snapshot.index({ adfsn_applied_at_stage: 1 });
// Compound index for efficient lookups
admission_fee_snapshot.index({ adfsn_admission_id_admap: 1, adfsn_isactive: 1 });
admission_fee_snapshot.index({ adfsn_student_id: 1, adfsn_isactive: 1 });
var CAdmissionFeeSnapshot = mongoose_1.default.model("admission_fee_snapshot", admission_fee_snapshot);
exports.CAdmissionFeeSnapshot = CAdmissionFeeSnapshot;