All files / src/domains/hr/payroll/calendars/schemas payroll-calendar.schema.ts

0% Statements 0/58
0% Branches 0/68
100% Functions 0/0
0% Lines 0/48

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                                                                                                                                                                                                   
import { Prop, Schema, SchemaFactory } from '@nestjs/mongoose';
import { Document, Schema as MongooseSchema } from 'mongoose';
 
@Schema({ collection: 'payroll_calendars', timestamps: true })
export class PayrollCalendar extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) calendarName!: string;
  @Prop({
    required: true,
    enum: ['monthly', 'weekly', 'biweekly', 'semi_monthly', 'daily', 'custom'],
  })
  frequency!: string;
  @Prop() description?: string;
  @Prop({ default: true }) isActive!: boolean;
}
export const PayrollCalendarSchema =
  SchemaFactory.createForClass(PayrollCalendar);
 
@Schema({ collection: 'payroll_periods', timestamps: true })
export class PayrollPeriod extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  calendarId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) periodName!: string;
  @Prop({ required: true }) startDate!: Date;
  @Prop({ required: true }) endDate!: Date;
  @Prop({
    default: 'draft',
    enum: ['draft', 'open', 'processing', 'closed', 'locked'],
  })
  status!: string;
  @Prop({ default: 0 }) workingDays!: number;
}
export const PayrollPeriodSchema = SchemaFactory.createForClass(PayrollPeriod);
PayrollPeriodSchema.index({
  tenantId: 1,
  calendarId: 1,
  startDate: 1,
  endDate: 1,
});
PayrollPeriodSchema.index({ tenantId: 1, status: 1 });
 
@Schema({ collection: 'payroll_groups', timestamps: true })
export class PayrollGroup extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true, index: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ required: true }) groupName!: string;
  @Prop({ required: true }) groupCode!: string;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  calendarId!: MongooseSchema.Types.ObjectId;
  @Prop() description?: string;
  @Prop({ default: true }) isActive!: boolean;
}
export const PayrollGroupSchema = SchemaFactory.createForClass(PayrollGroup);
PayrollGroupSchema.index({ tenantId: 1, groupCode: 1 }, { unique: true });
 
@Schema({ collection: 'payroll_group_assignments', timestamps: true })
export class PayrollGroupAssignment extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  groupId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  branchId?: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  departmentId?: MongooseSchema.Types.ObjectId;
  @Prop() grade?: string;
  @Prop() employmentType?: string;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  employeeId?: MongooseSchema.Types.ObjectId;
  @Prop({ default: 0 }) priority!: number;
}
export const PayrollGroupAssignmentSchema = SchemaFactory.createForClass(
  PayrollGroupAssignment,
);
PayrollGroupAssignmentSchema.index({ tenantId: 1, groupId: 1 });
 
@Schema({ collection: 'payroll_cutoff_configurations', timestamps: true })
export class PayrollCutoffConfiguration extends Document {
  @Prop({ type: MongooseSchema.Types.ObjectId, required: true })
  tenantId!: MongooseSchema.Types.ObjectId;
  @Prop({ type: MongooseSchema.Types.ObjectId })
  groupId?: MongooseSchema.Types.ObjectId;
  @Prop({ default: 25 }) attendanceCutoffDay!: number;
  @Prop({ default: 25 }) leaveCutoffDay!: number;
  @Prop({ default: 28 }) inputCutoffDay!: number;
  @Prop({ default: 1 }) paymentDay!: number;
}
export const PayrollCutoffConfigurationSchema = SchemaFactory.createForClass(
  PayrollCutoffConfiguration,
);
 
// ────────────────────────────────────────────────────────────────
// 7. PAYROLL INPUTS
// ────────────────────────────────────────────────────────────────