Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose'; import { Document, Schema as MongooseSchema } from 'mongoose'; @Schema({ collection: 'salary_components', timestamps: true }) export class SalaryComponent extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) componentCode!: string; @Prop({ required: true }) componentName!: string; @Prop() shortName?: string; @Prop({ required: true, enum: [ 'earning', 'deduction', 'employer_contribution', 'reimbursement', 'benefit', 'tax', 'statutory_deduction', 'loan_recovery', 'advance_recovery', 'arrear', 'bonus', 'incentive', 'leave_encashment', 'overtime', 'custom', ], }) category!: string; @Prop({ required: true, enum: [ 'fixed', 'percentage', 'formula', 'attendance_based', 'working_day_based', 'hour_based', 'slab_based', 'quantity_based', 'manual_input', 'external_provider', ], }) calculationType!: string; @Prop() formula?: string; @Prop({ type: [MongooseSchema.Types.ObjectId], default: [] }) percentageOfComponentIds!: MongooseSchema.Types.ObjectId[]; @Prop({ default: false }) taxable!: boolean; @Prop({ default: 0 }) taxExemptLimit!: number; @Prop({ default: false }) statutory!: boolean; @Prop({ default: false }) employerComponent!: boolean; @Prop({ default: true }) employeeComponent!: boolean; @Prop({ default: false }) partOfGross!: boolean; @Prop({ default: false }) partOfCTC!: boolean; @Prop({ default: false }) partOfNetPay!: boolean; @Prop({ default: true }) visibleOnPayslip!: boolean; @Prop({ default: true }) recurring!: boolean; @Prop({ default: true }) proratable!: boolean; @Prop({ default: false }) arrearApplicable!: boolean; @Prop({ default: 'none', enum: ['none', 'prorate', 'full_deduct'] }) leaveImpact!: string; @Prop({ default: 'none', enum: ['none', 'prorate', 'full_deduct'] }) attendanceImpact!: string; @Prop({ default: 'nearest', enum: ['nearest', 'up', 'down', 'none'] }) roundingRule!: string; @Prop() minimumAmount?: number; @Prop() maximumAmount?: number; @Prop({ default: 0 }) priority!: number; @Prop() effectiveFrom?: Date; @Prop() effectiveTo?: Date; @Prop({ default: 'active', enum: ['active', 'archived', 'draft'] }) status!: string; @Prop({ default: 1 }) version!: number; } export const SalaryComponentSchema = SchemaFactory.createForClass(SalaryComponent); SalaryComponentSchema.index( { tenantId: 1, componentCode: 1 }, { unique: true }, ); SalaryComponentSchema.index({ tenantId: 1, category: 1, status: 1 }); @Schema({ collection: 'salary_component_versions', timestamps: true }) export class SalaryComponentVersion extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) componentId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) version!: number; @Prop({ type: MongooseSchema.Types.Mixed, required: true }) snapshot!: Record< string, unknown >; @Prop({ type: MongooseSchema.Types.ObjectId }) publishedBy?: MongooseSchema.Types.ObjectId; } export const SalaryComponentVersionSchema = SchemaFactory.createForClass( SalaryComponentVersion, ); SalaryComponentVersionSchema.index({ tenantId: 1, componentId: 1, version: -1, }); @Schema({ collection: 'salary_component_formulas', timestamps: true }) export class SalaryComponentFormula extends Document { @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) tenantId!: MongooseSchema.Types.ObjectId; @Prop({ type: MongooseSchema.Types.ObjectId, required: true }) componentId!: MongooseSchema.Types.ObjectId; @Prop({ required: true }) expression!: string; @Prop({ type: [String], default: [] }) variablesUsed!: string[]; @Prop({ type: [MongooseSchema.Types.ObjectId], default: [] }) componentDependencies!: MongooseSchema.Types.ObjectId[]; @Prop({ default: 1 }) version!: number; @Prop({ default: 'draft', enum: ['draft', 'published'] }) status!: string; } export const SalaryComponentFormulaSchema = SchemaFactory.createForClass( SalaryComponentFormula, ); // ──────────────────────────────────────────────────────────────── // 3. FORMULA ENGINE SCHEMAS // ──────────────────────────────────────────────────────────────── |