@classytic/payroll 2.0.0 → 2.3.0

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.

Potentially problematic release.


This version of @classytic/payroll might be problematic. Click here for more details.

package/dist/index.d.ts CHANGED
@@ -1,21 +1,118 @@
1
- import payroll from './payroll.js';
2
- export { Payroll, PayrollBuilder, createPayrollInstance, getPayroll, resetPayroll } from './payroll.js';
3
- import { n as HRMConfig, D as DeepPartial, s as Department, t as EmploymentType, u as OrgRole, j as PayrollRecordDocument, v as HttpError, w as ErrorCode, x as PaymentFrequency, y as Allowance, z as Deduction, C as Compensation, F as CompensationBreakdownResult } from './types-BSYyX2KJ.js';
4
- export { A as AddAllowanceParams, c as AddDeductionParams, I as AllowanceType, Q as BankDetails, B as BulkPayrollResult, J as DeductionType, E as EmployeeDocument, G as EmployeeStatus, V as EmploymentHistoryEntry, m as ExportPayrollParams, N as HRMTransactionCategory, H as HireEmployeeParams, L as ListEmployeesParams, o as Logger, O as ObjectIdLike, q as OperationContext, Z as PayrollBreakdown, i as PayrollHistoryParams, P as PayrollInitConfig, r as PayrollInstance, Y as PayrollPeriod, X as PayrollStats, K as PayrollStatus, k as PayrollSummaryParams, l as PayrollSummaryResult, h as ProcessBulkPayrollParams, f as ProcessSalaryParams, g as ProcessSalaryResult, R as ReHireEmployeeParams, b as RemoveAllowanceParams, d as RemoveDeductionParams, S as SingleTenantConfig, T as TerminateEmployeeParams, M as TerminationReason, e as UpdateBankDetailsParams, U as UpdateEmploymentParams, a as UpdateSalaryParams, W as WorkSchedule } from './types-BSYyX2KJ.js';
5
- export { allowanceSchema, bankDetailsSchema, compensationSchema, deductionSchema, employmentFields, employmentHistorySchema, payrollStatsSchema, workScheduleSchema } from './schemas/index.js';
6
- import mongoose, { Model, Schema } from 'mongoose';
7
- import { AttendanceInput } from './core/index.js';
8
- export { Container, ContainerConfig, Err, ModelsContainer, Ok, Result, err, initializeContainer, isErr, isOk, map, mapErr, ok, unwrap, unwrapOr } from './core/index.js';
9
- export { E as EventBus, a as PayrollEventMap, P as PayrollPluginDefinition, d as PluginContext, b as PluginManager, c as createEventBus } from './plugin-D9mOr3_d.js';
10
- export { B as BatchPayrollFactory, C as CompensationService, a as EmployeeBuilder, E as EmployeeFactory, b as EmployeeService, P as PayrollFactory, c as PayrollService } from './index-CTjHlCzz.js';
11
- export { EmployeeQueryBuilder, PayrollQueryBuilder, QueryBuilder, addDays, addMonths, addYears, applyPercentage, calculateGross, calculateNet, calculateProRating, canReceiveSalary, compose, createValidator, diffInDays, diffInMonths, disableLogging, employee, enableLogging, endOfMonth, endOfYear, formatDateForDB, getCurrentPeriod, getLogger, getPayPeriod, getWorkingDaysInMonth, inRange, isActive, isDateInRange, isEmployed, isLoggingEnabled, isOnProbation, isTerminated, logger, max, min, oneOf, payroll, pipe, required, setLogger, startOfMonth, startOfYear, sum, sumAllowances, sumBy, sumDeductions, toObjectId } from './utils/index.js';
1
+ export { Payroll, PayrollBuilder, createPayrollInstance } from './payroll.js';
2
+ import { O as ObjectIdLike, aM as PayrollBreakdown, aF as LeaveType, aY as LeaveRequestStatus, aR as TaxType, aS as TaxStatus, z as HRMConfig, D as DeepPartial, I as Department, F as EmploymentType, aZ as OrgRole, aJ as LeaveInitConfig, a_ as HttpError, a$ as ErrorCode, aw as AttendanceInput, y as LeaveRequestDocument, v as TaxWithholdingDocument } from './types-BN3K_Uhr.js';
3
+ export { bm as AccrueLeaveOptions, j as AddAllowanceParams, l as AddDeductionParams, N as Allowance, bf as AllowanceType, A as AnyDocument, aP as AnyModel, V as BankDetails, bp as BulkPayrollProgress, B as BulkPayrollResult, X as Compensation, aO as CompensationBreakdownResult, b2 as DataRetentionConfig, Q as Deduction, bg as DeductionType, E as EmployeeDocument, bv as EmployeeHiredEvent, b7 as EmployeeIdMode, h as EmployeeIdentityMode, bo as EmployeeOperationParams, aK as EmployeeStatus, aW as EmployeeValidationResult, b5 as EmploymentConfig, bd as EmploymentHistoryEntry, bx as EventPayload, bu as EventPayloadBase, u as ExportPayrollParams, b1 as FilterQuery, G as GetPendingTaxParams, bi as HRMTransactionCategory, H as HireEmployeeParams, aH as LeaveBalance, bl as LeaveHistoryFilters, aI as LeaveSummaryResult, L as ListEmployeesParams, C as Logger, M as MarkTaxPaidParams, b0 as Nullable, g as OperationContext, aT as PayPeriodInfo, K as PaymentFrequency, aN as PaymentMethod, b3 as PayrollConfig, bc as PayrollCorrection, bz as PayrollEmployee, bt as PayrollEvent, r as PayrollHistoryParams, b as PayrollInitConfig, a as PayrollInstance, aL as PayrollPeriod, bq as PayrollPlugin, P as PayrollRecordDocument, bb as PayrollStats, aX as PayrollStatus, s as PayrollSummaryParams, t as PayrollSummaryResult, br as PluginFunction, bs as PluginType, q as ProcessBulkPayrollParams, o as ProcessSalaryParams, p as ProcessSalaryResult, by as QueryOptions, R as ReHireEmployeeParams, k as RemoveAllowanceParams, m as RemoveDeductionParams, bj as RequestLeaveInput, bn as ResetAnnualLeaveOptions, bk as ReviewLeaveRequestInput, ba as RoleMappingConfig, bh as SalaryBand, b9 as SalaryBandRange, b4 as SalaryConfig, bw as SalaryProcessedEvent, S as SingleTenantConfig, b8 as TaxBracket, aV as TaxCalculationResult, bB as TaxSummaryByType, w as TaxSummaryParams, x as TaxSummaryResult, T as TerminateEmployeeParams, Y as TerminationReason, n as UpdateBankDetailsParams, U as UpdateEmploymentParams, i as UpdateSalaryParams, be as UserReference, b6 as ValidationConfig, W as WebhookConfig, f as WebhookDelivery, ag as WebhookManager, bA as WithPayroll, J as WorkSchedule, aG as WorkingDaysOptions } from './types-BN3K_Uhr.js';
4
+ import { ITransaction, ITransactionCreateInput } from '@classytic/shared-types';
5
+ export { I as IdempotencyManager, a as IdempotentResult, g as generatePayrollIdempotencyKey } from './idempotency-Cw2CWicb.js';
6
+ export { allowanceSchema, applyEmployeeIndexes, applyLeaveRequestIndexes, applyPayrollRecordIndexes, applyTaxWithholdingIndexes, bankDetailsSchema, compensationSchema, createEmployeeSchema, createLeaveRequestSchema, createPayrollRecordSchema, createTaxWithholdingSchema, deductionSchema, employmentFields, employmentHistorySchema, leaveBalanceFields, leaveBalanceSchema, leaveRequestFields, leaveRequestIndexes, payrollStatsSchema, taxWithholdingFields, taxWithholdingIndexes, workScheduleSchema } from './schemas/index.js';
7
+ import mongoose__default, { Schema, Model } from 'mongoose';
8
+ export { C as CreateEmployeeParams, a as EmployeeBuilder, b as EmployeeData, E as EmployeeFactory, T as TerminationData, c as createEmployee } from './employee.factory-BlZqhiCk.js';
9
+ export { C as ContainerLike, a as DEFAULT_CARRY_OVER, D as DEFAULT_LEAVE_ALLOCATIONS, z as EmployeeIdType, A as EmployeeQueryFilter, R as ResolveOrganizationIdParams, S as SecureEmployeeLookupOptions, l as accrueLeaveToBalance, k as calculateCarryOver, c as calculateLeaveDays, f as calculateUnpaidLeaveDeduction, s as detectEmployeeIdType, n as employeeExistsSecure, m as findEmployeeSecure, o as findEmployeesSecure, y as formatEmployeeId, d as getAvailableDays, g as getLeaveBalance, b as getLeaveBalances, e as getLeaveSummary, j as getUnpaidLeaveDays, h as hasLeaveBalance, i as initializeLeaveBalances, x as isObjectIdEmployeeId, w as isStringEmployeeId, u as normalizeEmployeeId, p as proRateAllocation, r as requireOrganizationId, q as resolveOrganizationId, t as tryResolveOrganizationId, v as validateOrganizationId } from './employee-identity-DXhgOgXE.js';
10
+ export { AttendanceDeductionInput, AttendanceDeductionResult, ProRatingInput, ProRatingResult, ProcessedAllowance, ProcessedDeduction, SalaryCalculationInput, applyProRating, calculateAttendanceDeduction, calculateDailyRate, calculateHourlyRate, calculatePartialDayDeduction, calculateProRating, calculateSalaryBreakdown, calculateTotalAttendanceDeduction, shouldProRate } from './calculators/index.js';
11
+ export { AttendancePolicy, AttendancePolicyBuilder, AttendancePolicyDocument, AttendancePolicyModel, AttendancePolicySchema, AttendancePolicySchemaDefinition, CalculateShiftComplianceInput, ClockRoundingPolicy, ClockRoundingPolicyBuilder, ClockRoundingPolicySchema, ClockRoundingPolicySchemaDefinition, DEFAULT_ATTENDANCE_POLICY, EarlyDeparturePenaltyResult, EarlyDeparturePolicy, EarlyDeparturePolicySchema, EarlyDeparturePolicySchemaDefinition, EarlyOccurrence, HEALTHCARE_POLICY, HOSPITALITY_POLICY, LateArrivalPolicy, LateArrivalPolicySchema, LateArrivalPolicySchemaDefinition, LateOccurrence, LatePenaltyResult, LatePolicyBuilder, MANUFACTURING_POLICY, MaxPenaltiesPerPeriod, MaxPenaltiesSchema, MaxPenaltiesSchemaDefinition, NightShiftDifferential, NightShiftDifferentialSchema, NightShiftDifferentialSchemaDefinition, OFFICE_POLICY, OvertimeBonusResult, OvertimeMode, OvertimeOccurrence, OvertimePolicy, OvertimePolicyBuilder, OvertimePolicySchema, OvertimePolicySchemaDefinition, PenaltyMode, PenaltyOverride, PenaltyTier, PenaltyTierSchema, PenaltyTierSchemaDefinition, RETAIL_POLICY, ResetPeriod, RoundingMode, ShiftComplianceData, ShiftComplianceResult, ShiftDifferentialResult, TieredPenaltyBuilder, WeekendPremium, WeekendPremiumSchema, WeekendPremiumSchemaDefinition, calculateDailyOvertime, calculateFlatPenalty, calculateLatePenalty, calculateMonthlyOvertime, calculateNightShiftDifferential, calculateOvertimeBonus, calculatePerMinutePenalty, calculatePercentagePenalty, calculateShiftCompliance, calculateTieredPenalty, calculateWeekendPremium, calculateWeeklyOvertime, createClockRoundingPolicyBuilder, createLatePolicyBuilder, createOvertimePolicyBuilder, createPolicyFromPreset } from './shift-compliance/index.js';
12
12
 
13
13
  /**
14
- * @classytic/payroll - Enums
14
+ * Transaction Interface
15
+ * @classytic/payroll
16
+ *
17
+ * Payroll uses the unified transaction interface from @classytic/shared-types
18
+ * so revenue and payroll share a single cashflow event model.
19
+ */
20
+
21
+ /**
22
+ * Core transaction interface expected by payroll package
23
+ * Apps must provide a Transaction model with AT LEAST these fields
24
+ */
25
+ type IPayrollTransaction = ITransaction;
26
+ /**
27
+ * Transaction write input (what payroll package creates)
28
+ */
29
+ type IPayrollTransactionCreateInput = ITransactionCreateInput;
30
+ /**
31
+ * Type guard to check if object is a Transaction
32
+ */
33
+ declare function isPayrollTransaction(obj: unknown): obj is IPayrollTransaction;
34
+
35
+ /**
36
+ * @classytic/payroll - Transaction Factory
37
+ *
38
+ * Pure functions for building transaction objects aligned with @classytic/shared-types.
39
+ * Ensures consistency with revenue package for unified cashflow.
40
+ *
41
+ * @packageDocumentation
42
+ */
43
+
44
+ /**
45
+ * Input for creating a payroll transaction
46
+ */
47
+ interface CreatePayrollTransactionInput {
48
+ organizationId: ObjectIdLike;
49
+ employee: {
50
+ _id: ObjectIdLike;
51
+ userId?: ObjectIdLike | {
52
+ _id: ObjectIdLike;
53
+ name?: string;
54
+ } | null;
55
+ employeeId: string;
56
+ email?: string;
57
+ compensation: {
58
+ currency: string;
59
+ };
60
+ };
61
+ payrollRecord: {
62
+ _id: ObjectIdLike;
63
+ };
64
+ breakdown: PayrollBreakdown;
65
+ period: {
66
+ month: number;
67
+ year: number;
68
+ };
69
+ paymentDate: Date;
70
+ paymentMethod?: string;
71
+ processedBy?: ObjectIdLike;
72
+ idempotencyKey?: string;
73
+ jurisdiction?: string;
74
+ }
75
+ /**
76
+ * Input for creating a tax payment transaction
77
+ */
78
+ interface CreateTaxPaymentTransactionInput {
79
+ organizationId: ObjectIdLike;
80
+ totalAmount: number;
81
+ currency: string;
82
+ referenceNumber?: string;
83
+ notes?: string;
84
+ withholdingIds: ObjectIdLike[];
85
+ }
86
+ /**
87
+ * Create payroll transaction aligned with @classytic/shared-types
88
+ *
89
+ * This is the SINGLE SOURCE OF TRUTH for payroll transaction structure.
90
+ * Aligns with revenue package for unified cashflow.
15
91
  *
16
- * Type-safe enum definitions with const assertions
17
- * Single source of truth for all enum values
92
+ * @param input - Payroll transaction parameters
93
+ * @returns Transaction data ready for DB creation (ITransactionCreateInput)
94
+ *
95
+ * @pure This function has no side effects
18
96
  */
97
+ declare function createPayrollTransaction(input: CreatePayrollTransactionInput): ITransactionCreateInput;
98
+ /**
99
+ * Create tax payment transaction aligned with @classytic/shared-types
100
+ *
101
+ * For government tax payments (withholding remittance).
102
+ *
103
+ * @param input - Tax payment parameters
104
+ * @returns Transaction data ready for DB creation (ITransactionCreateInput)
105
+ *
106
+ * @pure This function has no side effects
107
+ */
108
+ declare function createTaxPaymentTransaction(input: CreateTaxPaymentTransactionInput): ITransactionCreateInput;
109
+ /**
110
+ * Transaction Factory class (for builder pattern if needed)
111
+ */
112
+ declare class TransactionFactory {
113
+ static createPayrollTransaction: typeof createPayrollTransaction;
114
+ static createTaxPaymentTransaction: typeof createTaxPaymentTransaction;
115
+ }
19
116
 
20
117
  declare const EMPLOYMENT_TYPE: {
21
118
  readonly FULL_TIME: "full_time";
@@ -83,13 +180,47 @@ declare const TERMINATION_REASON: {
83
180
  readonly MUTUAL_AGREEMENT: "mutual_agreement";
84
181
  readonly OTHER: "other";
85
182
  };
86
- declare const HRM_TRANSACTION_CATEGORIES: {
87
- readonly SALARY: "salary";
88
- readonly BONUS: "bonus";
89
- readonly COMMISSION: "commission";
90
- readonly OVERTIME: "overtime";
91
- readonly SEVERANCE: "severance";
183
+ declare const LEAVE_TYPE: {
184
+ readonly ANNUAL: "annual";
185
+ readonly SICK: "sick";
186
+ readonly UNPAID: "unpaid";
187
+ readonly MATERNITY: "maternity";
188
+ readonly PATERNITY: "paternity";
189
+ readonly BEREAVEMENT: "bereavement";
190
+ readonly COMPENSATORY: "compensatory";
191
+ readonly OTHER: "other";
192
+ };
193
+ declare function isValidLeaveType(value: string): value is LeaveType;
194
+ declare function isPaidLeaveType(type: LeaveType): boolean;
195
+ declare const LEAVE_REQUEST_STATUS: {
196
+ readonly PENDING: "pending";
197
+ readonly APPROVED: "approved";
198
+ readonly REJECTED: "rejected";
199
+ readonly CANCELLED: "cancelled";
92
200
  };
201
+ declare function isValidLeaveRequestStatus(value: string): value is LeaveRequestStatus;
202
+ declare function isPendingLeaveStatus(status: LeaveRequestStatus): boolean;
203
+ declare function isApprovedLeaveStatus(status: LeaveRequestStatus): boolean;
204
+ declare const TAX_TYPE: {
205
+ readonly INCOME_TAX: "income_tax";
206
+ readonly SOCIAL_SECURITY: "social_security";
207
+ readonly HEALTH_INSURANCE: "health_insurance";
208
+ readonly PENSION: "pension";
209
+ readonly EMPLOYMENT_INSURANCE: "employment_insurance";
210
+ readonly LOCAL_TAX: "local_tax";
211
+ readonly OTHER: "other";
212
+ };
213
+ declare const TAX_TYPE_VALUES: ("other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax")[];
214
+ declare function isValidTaxType(value: string): value is TaxType;
215
+ declare const TAX_STATUS: {
216
+ readonly PENDING: "pending";
217
+ readonly SUBMITTED: "submitted";
218
+ readonly PAID: "paid";
219
+ };
220
+ declare const TAX_STATUS_VALUES: ("pending" | "paid" | "submitted")[];
221
+ declare function isValidTaxStatus(value: string): value is TaxStatus;
222
+ declare function isPendingTaxStatus(status: TaxStatus): boolean;
223
+ declare function isPaidTaxStatus(status: TaxStatus): boolean;
93
224
 
94
225
  /**
95
226
  * @classytic/payroll - Configuration
@@ -99,10 +230,6 @@ declare const HRM_TRANSACTION_CATEGORIES: {
99
230
  */
100
231
 
101
232
  declare const HRM_CONFIG: HRMConfig;
102
- /**
103
- * Calculate tax based on annual income
104
- */
105
- declare function calculateTax(annualIncome: number, currency?: string): number;
106
233
  /**
107
234
  * Determine the appropriate organization role for an employee
108
235
  */
@@ -116,544 +243,6 @@ declare function determineOrgRole(employmentData: {
116
243
  */
117
244
  declare function mergeConfig(customConfig: Partial<HRMConfig> | DeepPartial<HRMConfig> | undefined): HRMConfig;
118
245
 
119
- /**
120
- * @classytic/payroll - PayrollRecord Model
121
- *
122
- * Mongoose schema for payroll records with TTL and auto-export
123
- */
124
-
125
- declare const payrollRecordSchema: mongoose.Schema<any, mongoose.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
126
- timestamps: true;
127
- }, {
128
- organizationId: mongoose.Types.ObjectId;
129
- userId: mongoose.Types.ObjectId;
130
- employeeId: mongoose.Types.ObjectId;
131
- period: {
132
- month: number;
133
- year: number;
134
- startDate: NativeDate;
135
- endDate: NativeDate;
136
- payDate?: NativeDate | null | undefined;
137
- };
138
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
139
- exported: boolean;
140
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
141
- breakdown: {
142
- baseAmount: number;
143
- allowances: mongoose.Types.DocumentArray<{
144
- type: string;
145
- amount: number;
146
- taxable: boolean;
147
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
148
- type: string;
149
- amount: number;
150
- taxable: boolean;
151
- }> & {
152
- type: string;
153
- amount: number;
154
- taxable: boolean;
155
- }>;
156
- deductions: mongoose.Types.DocumentArray<{
157
- type: string;
158
- amount: number;
159
- description?: string | null | undefined;
160
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
161
- type: string;
162
- amount: number;
163
- description?: string | null | undefined;
164
- }> & {
165
- type: string;
166
- amount: number;
167
- description?: string | null | undefined;
168
- }>;
169
- grossSalary: number;
170
- netSalary: number;
171
- taxableAmount: number;
172
- taxAmount: number;
173
- attendanceDeduction: number;
174
- proRatedAmount: number;
175
- workingDays?: number | null | undefined;
176
- actualDays?: number | null | undefined;
177
- };
178
- metadata: any;
179
- corrections: mongoose.Types.DocumentArray<{
180
- correctedAt: NativeDate;
181
- reason?: string | null | undefined;
182
- previousAmount?: number | null | undefined;
183
- newAmount?: number | null | undefined;
184
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
185
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
186
- correctedAt: NativeDate;
187
- reason?: string | null | undefined;
188
- previousAmount?: number | null | undefined;
189
- newAmount?: number | null | undefined;
190
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
191
- }> & {
192
- correctedAt: NativeDate;
193
- reason?: string | null | undefined;
194
- previousAmount?: number | null | undefined;
195
- newAmount?: number | null | undefined;
196
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
197
- }>;
198
- notes?: string | null | undefined;
199
- processedAt?: NativeDate | null | undefined;
200
- processedBy?: mongoose.Types.ObjectId | null | undefined;
201
- transactionId?: mongoose.Types.ObjectId | null | undefined;
202
- exportedAt?: NativeDate | null | undefined;
203
- paidAt?: NativeDate | null | undefined;
204
- } & mongoose.DefaultTimestampProps, mongoose.Document<unknown, {}, {
205
- organizationId: mongoose.Types.ObjectId;
206
- userId: mongoose.Types.ObjectId;
207
- employeeId: mongoose.Types.ObjectId;
208
- period: {
209
- month: number;
210
- year: number;
211
- startDate: NativeDate;
212
- endDate: NativeDate;
213
- payDate?: NativeDate | null | undefined;
214
- };
215
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
216
- exported: boolean;
217
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
218
- breakdown: {
219
- baseAmount: number;
220
- allowances: mongoose.Types.DocumentArray<{
221
- type: string;
222
- amount: number;
223
- taxable: boolean;
224
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
225
- type: string;
226
- amount: number;
227
- taxable: boolean;
228
- }> & {
229
- type: string;
230
- amount: number;
231
- taxable: boolean;
232
- }>;
233
- deductions: mongoose.Types.DocumentArray<{
234
- type: string;
235
- amount: number;
236
- description?: string | null | undefined;
237
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
238
- type: string;
239
- amount: number;
240
- description?: string | null | undefined;
241
- }> & {
242
- type: string;
243
- amount: number;
244
- description?: string | null | undefined;
245
- }>;
246
- grossSalary: number;
247
- netSalary: number;
248
- taxableAmount: number;
249
- taxAmount: number;
250
- attendanceDeduction: number;
251
- proRatedAmount: number;
252
- workingDays?: number | null | undefined;
253
- actualDays?: number | null | undefined;
254
- };
255
- metadata: any;
256
- corrections: mongoose.Types.DocumentArray<{
257
- correctedAt: NativeDate;
258
- reason?: string | null | undefined;
259
- previousAmount?: number | null | undefined;
260
- newAmount?: number | null | undefined;
261
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
262
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
263
- correctedAt: NativeDate;
264
- reason?: string | null | undefined;
265
- previousAmount?: number | null | undefined;
266
- newAmount?: number | null | undefined;
267
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
268
- }> & {
269
- correctedAt: NativeDate;
270
- reason?: string | null | undefined;
271
- previousAmount?: number | null | undefined;
272
- newAmount?: number | null | undefined;
273
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
274
- }>;
275
- notes?: string | null | undefined;
276
- processedAt?: NativeDate | null | undefined;
277
- processedBy?: mongoose.Types.ObjectId | null | undefined;
278
- transactionId?: mongoose.Types.ObjectId | null | undefined;
279
- exportedAt?: NativeDate | null | undefined;
280
- paidAt?: NativeDate | null | undefined;
281
- } & mongoose.DefaultTimestampProps, {
282
- id: string;
283
- }, mongoose.ResolveSchemaOptions<{
284
- timestamps: true;
285
- }>> & Omit<{
286
- organizationId: mongoose.Types.ObjectId;
287
- userId: mongoose.Types.ObjectId;
288
- employeeId: mongoose.Types.ObjectId;
289
- period: {
290
- month: number;
291
- year: number;
292
- startDate: NativeDate;
293
- endDate: NativeDate;
294
- payDate?: NativeDate | null | undefined;
295
- };
296
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
297
- exported: boolean;
298
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
299
- breakdown: {
300
- baseAmount: number;
301
- allowances: mongoose.Types.DocumentArray<{
302
- type: string;
303
- amount: number;
304
- taxable: boolean;
305
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
306
- type: string;
307
- amount: number;
308
- taxable: boolean;
309
- }> & {
310
- type: string;
311
- amount: number;
312
- taxable: boolean;
313
- }>;
314
- deductions: mongoose.Types.DocumentArray<{
315
- type: string;
316
- amount: number;
317
- description?: string | null | undefined;
318
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
319
- type: string;
320
- amount: number;
321
- description?: string | null | undefined;
322
- }> & {
323
- type: string;
324
- amount: number;
325
- description?: string | null | undefined;
326
- }>;
327
- grossSalary: number;
328
- netSalary: number;
329
- taxableAmount: number;
330
- taxAmount: number;
331
- attendanceDeduction: number;
332
- proRatedAmount: number;
333
- workingDays?: number | null | undefined;
334
- actualDays?: number | null | undefined;
335
- };
336
- metadata: any;
337
- corrections: mongoose.Types.DocumentArray<{
338
- correctedAt: NativeDate;
339
- reason?: string | null | undefined;
340
- previousAmount?: number | null | undefined;
341
- newAmount?: number | null | undefined;
342
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
343
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
344
- correctedAt: NativeDate;
345
- reason?: string | null | undefined;
346
- previousAmount?: number | null | undefined;
347
- newAmount?: number | null | undefined;
348
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
349
- }> & {
350
- correctedAt: NativeDate;
351
- reason?: string | null | undefined;
352
- previousAmount?: number | null | undefined;
353
- newAmount?: number | null | undefined;
354
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
355
- }>;
356
- notes?: string | null | undefined;
357
- processedAt?: NativeDate | null | undefined;
358
- processedBy?: mongoose.Types.ObjectId | null | undefined;
359
- transactionId?: mongoose.Types.ObjectId | null | undefined;
360
- exportedAt?: NativeDate | null | undefined;
361
- paidAt?: NativeDate | null | undefined;
362
- } & mongoose.DefaultTimestampProps & {
363
- _id: mongoose.Types.ObjectId;
364
- } & {
365
- __v: number;
366
- }, "id"> & {
367
- id: string;
368
- }, {
369
- [path: string]: mongoose.SchemaDefinitionProperty<undefined, any, any>;
370
- } | {
371
- [x: string]: mongoose.SchemaDefinitionProperty<any, any, mongoose.Document<unknown, {}, {
372
- organizationId: mongoose.Types.ObjectId;
373
- userId: mongoose.Types.ObjectId;
374
- employeeId: mongoose.Types.ObjectId;
375
- period: {
376
- month: number;
377
- year: number;
378
- startDate: NativeDate;
379
- endDate: NativeDate;
380
- payDate?: NativeDate | null | undefined;
381
- };
382
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
383
- exported: boolean;
384
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
385
- breakdown: {
386
- baseAmount: number;
387
- allowances: mongoose.Types.DocumentArray<{
388
- type: string;
389
- amount: number;
390
- taxable: boolean;
391
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
392
- type: string;
393
- amount: number;
394
- taxable: boolean;
395
- }> & {
396
- type: string;
397
- amount: number;
398
- taxable: boolean;
399
- }>;
400
- deductions: mongoose.Types.DocumentArray<{
401
- type: string;
402
- amount: number;
403
- description?: string | null | undefined;
404
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
405
- type: string;
406
- amount: number;
407
- description?: string | null | undefined;
408
- }> & {
409
- type: string;
410
- amount: number;
411
- description?: string | null | undefined;
412
- }>;
413
- grossSalary: number;
414
- netSalary: number;
415
- taxableAmount: number;
416
- taxAmount: number;
417
- attendanceDeduction: number;
418
- proRatedAmount: number;
419
- workingDays?: number | null | undefined;
420
- actualDays?: number | null | undefined;
421
- };
422
- metadata: any;
423
- corrections: mongoose.Types.DocumentArray<{
424
- correctedAt: NativeDate;
425
- reason?: string | null | undefined;
426
- previousAmount?: number | null | undefined;
427
- newAmount?: number | null | undefined;
428
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
429
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
430
- correctedAt: NativeDate;
431
- reason?: string | null | undefined;
432
- previousAmount?: number | null | undefined;
433
- newAmount?: number | null | undefined;
434
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
435
- }> & {
436
- correctedAt: NativeDate;
437
- reason?: string | null | undefined;
438
- previousAmount?: number | null | undefined;
439
- newAmount?: number | null | undefined;
440
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
441
- }>;
442
- notes?: string | null | undefined;
443
- processedAt?: NativeDate | null | undefined;
444
- processedBy?: mongoose.Types.ObjectId | null | undefined;
445
- transactionId?: mongoose.Types.ObjectId | null | undefined;
446
- exportedAt?: NativeDate | null | undefined;
447
- paidAt?: NativeDate | null | undefined;
448
- } & mongoose.DefaultTimestampProps, {
449
- id: string;
450
- }, mongoose.ResolveSchemaOptions<{
451
- timestamps: true;
452
- }>> & Omit<{
453
- organizationId: mongoose.Types.ObjectId;
454
- userId: mongoose.Types.ObjectId;
455
- employeeId: mongoose.Types.ObjectId;
456
- period: {
457
- month: number;
458
- year: number;
459
- startDate: NativeDate;
460
- endDate: NativeDate;
461
- payDate?: NativeDate | null | undefined;
462
- };
463
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
464
- exported: boolean;
465
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
466
- breakdown: {
467
- baseAmount: number;
468
- allowances: mongoose.Types.DocumentArray<{
469
- type: string;
470
- amount: number;
471
- taxable: boolean;
472
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
473
- type: string;
474
- amount: number;
475
- taxable: boolean;
476
- }> & {
477
- type: string;
478
- amount: number;
479
- taxable: boolean;
480
- }>;
481
- deductions: mongoose.Types.DocumentArray<{
482
- type: string;
483
- amount: number;
484
- description?: string | null | undefined;
485
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
486
- type: string;
487
- amount: number;
488
- description?: string | null | undefined;
489
- }> & {
490
- type: string;
491
- amount: number;
492
- description?: string | null | undefined;
493
- }>;
494
- grossSalary: number;
495
- netSalary: number;
496
- taxableAmount: number;
497
- taxAmount: number;
498
- attendanceDeduction: number;
499
- proRatedAmount: number;
500
- workingDays?: number | null | undefined;
501
- actualDays?: number | null | undefined;
502
- };
503
- metadata: any;
504
- corrections: mongoose.Types.DocumentArray<{
505
- correctedAt: NativeDate;
506
- reason?: string | null | undefined;
507
- previousAmount?: number | null | undefined;
508
- newAmount?: number | null | undefined;
509
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
510
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
511
- correctedAt: NativeDate;
512
- reason?: string | null | undefined;
513
- previousAmount?: number | null | undefined;
514
- newAmount?: number | null | undefined;
515
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
516
- }> & {
517
- correctedAt: NativeDate;
518
- reason?: string | null | undefined;
519
- previousAmount?: number | null | undefined;
520
- newAmount?: number | null | undefined;
521
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
522
- }>;
523
- notes?: string | null | undefined;
524
- processedAt?: NativeDate | null | undefined;
525
- processedBy?: mongoose.Types.ObjectId | null | undefined;
526
- transactionId?: mongoose.Types.ObjectId | null | undefined;
527
- exportedAt?: NativeDate | null | undefined;
528
- paidAt?: NativeDate | null | undefined;
529
- } & mongoose.DefaultTimestampProps & {
530
- _id: mongoose.Types.ObjectId;
531
- } & {
532
- __v: number;
533
- }, "id"> & {
534
- id: string;
535
- }> | undefined;
536
- }, {
537
- organizationId: mongoose.Types.ObjectId;
538
- userId: mongoose.Types.ObjectId;
539
- employeeId: mongoose.Types.ObjectId;
540
- period: {
541
- month: number;
542
- year: number;
543
- startDate: NativeDate;
544
- endDate: NativeDate;
545
- payDate?: NativeDate | null | undefined;
546
- };
547
- status: "pending" | "processing" | "paid" | "failed" | "cancelled";
548
- exported: boolean;
549
- paymentMethod: "bank" | "cash" | "check" | "mobile" | "bkash" | "nagad" | "rocket";
550
- breakdown: {
551
- baseAmount: number;
552
- allowances: mongoose.Types.DocumentArray<{
553
- type: string;
554
- amount: number;
555
- taxable: boolean;
556
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
557
- type: string;
558
- amount: number;
559
- taxable: boolean;
560
- }> & {
561
- type: string;
562
- amount: number;
563
- taxable: boolean;
564
- }>;
565
- deductions: mongoose.Types.DocumentArray<{
566
- type: string;
567
- amount: number;
568
- description?: string | null | undefined;
569
- }, mongoose.Types.Subdocument<mongoose.mongo.BSON.ObjectId, unknown, {
570
- type: string;
571
- amount: number;
572
- description?: string | null | undefined;
573
- }> & {
574
- type: string;
575
- amount: number;
576
- description?: string | null | undefined;
577
- }>;
578
- grossSalary: number;
579
- netSalary: number;
580
- taxableAmount: number;
581
- taxAmount: number;
582
- attendanceDeduction: number;
583
- proRatedAmount: number;
584
- workingDays?: number | null | undefined;
585
- actualDays?: number | null | undefined;
586
- };
587
- metadata: any;
588
- corrections: mongoose.Types.DocumentArray<{
589
- correctedAt: NativeDate;
590
- reason?: string | null | undefined;
591
- previousAmount?: number | null | undefined;
592
- newAmount?: number | null | undefined;
593
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
594
- } | {
595
- correctedAt: NativeDate;
596
- reason?: string | null | undefined;
597
- previousAmount?: number | null | undefined;
598
- newAmount?: number | null | undefined;
599
- correctedBy?: string | null | undefined;
600
- _id: string;
601
- }, mongoose.Types.Subdocument<string | mongoose.mongo.BSON.ObjectId, unknown, {
602
- correctedAt: NativeDate;
603
- reason?: string | null | undefined;
604
- previousAmount?: number | null | undefined;
605
- newAmount?: number | null | undefined;
606
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
607
- } | {
608
- correctedAt: NativeDate;
609
- reason?: string | null | undefined;
610
- previousAmount?: number | null | undefined;
611
- newAmount?: number | null | undefined;
612
- correctedBy?: string | null | undefined;
613
- _id: string;
614
- }> & ({
615
- correctedAt: NativeDate;
616
- reason?: string | null | undefined;
617
- previousAmount?: number | null | undefined;
618
- newAmount?: number | null | undefined;
619
- correctedBy?: mongoose.Types.ObjectId | null | undefined;
620
- } | {
621
- correctedAt: NativeDate;
622
- reason?: string | null | undefined;
623
- previousAmount?: number | null | undefined;
624
- newAmount?: number | null | undefined;
625
- correctedBy?: string | null | undefined;
626
- _id: string;
627
- })>;
628
- notes?: string | null | undefined;
629
- processedAt?: NativeDate | null | undefined;
630
- processedBy?: mongoose.Types.ObjectId | null | undefined;
631
- transactionId?: mongoose.Types.ObjectId | null | undefined;
632
- exportedAt?: NativeDate | null | undefined;
633
- paidAt?: NativeDate | null | undefined;
634
- createdAt: NativeDate;
635
- updatedAt: NativeDate;
636
- } & {
637
- _id: mongoose.Types.ObjectId;
638
- } & {
639
- __v: number;
640
- }>;
641
- interface PayrollRecordModel extends Model<PayrollRecordDocument> {
642
- findByPeriod(organizationId: mongoose.Types.ObjectId, month: number, year: number): ReturnType<Model<PayrollRecordDocument>['find']>;
643
- findByEmployee(employeeId: mongoose.Types.ObjectId, limit?: number): ReturnType<Model<PayrollRecordDocument>['find']>;
644
- getSummary(organizationId: mongoose.Types.ObjectId, month?: number, year?: number): Promise<{
645
- totalGross: number;
646
- totalNet: number;
647
- count: number;
648
- paidCount: number;
649
- }>;
650
- getExpiringSoon(organizationId: mongoose.Types.ObjectId, daysBeforeExpiry?: number): ReturnType<Model<PayrollRecordDocument>['find']>;
651
- }
652
- /**
653
- * Get or create PayrollRecord model
654
- */
655
- declare function getPayrollRecordModel(connection?: mongoose.Connection): PayrollRecordModel;
656
-
657
246
  /**
658
247
  * @classytic/payroll - Employee Plugin
659
248
  *
@@ -669,6 +258,14 @@ interface EmployeePluginOptions {
669
258
  statusField?: string;
670
259
  /** Enable auto salary calculation on save */
671
260
  autoCalculateSalary?: boolean;
261
+ /** Create indexes on schema (default: false) */
262
+ createIndexes?: boolean;
263
+ /** Enable leave management methods (default: false) */
264
+ enableLeave?: boolean;
265
+ /** Leave configuration */
266
+ leaveConfig?: LeaveInitConfig;
267
+ /** Field name for leave balances (default: 'leaveBalances') */
268
+ leaveBalancesField?: string;
672
269
  }
673
270
  /**
674
271
  * Mongoose plugin that adds HRM functionality to Employee schema
@@ -692,10 +289,24 @@ declare function employeePlugin(schema: Schema, options?: EmployeePluginOptions)
692
289
  declare class PayrollError extends Error implements HttpError {
693
290
  readonly code: ErrorCode;
694
291
  readonly status: number;
695
- readonly context?: Record<string, unknown>;
292
+ readonly context: Record<string, unknown>;
696
293
  readonly timestamp: Date;
697
- constructor(message: string, code?: ErrorCode, status?: number, context?: Record<string, unknown>);
294
+ /**
295
+ * Create a PayrollError.
296
+ *
297
+ * Supports BOTH constructor styles for backwards compatibility:
298
+ * - new PayrollError(message, code?, status?, context?)
299
+ * - new PayrollError(code, status, message, context?)
300
+ */
301
+ constructor(messageOrCode: string | ErrorCode, codeOrStatus?: ErrorCode | number, statusOrMessage?: number | string, context?: Record<string, unknown>);
302
+ /**
303
+ * Convert error to JSON for API responses (ClockIn-compatible shape)
304
+ */
698
305
  toJSON(): Record<string, unknown>;
306
+ /**
307
+ * Check if error is operational (expected) vs programmer error
308
+ */
309
+ isOperational(): boolean;
699
310
  }
700
311
  /**
701
312
  * Not initialized error
@@ -709,6 +320,12 @@ declare class NotInitializedError extends PayrollError {
709
320
  declare class EmployeeNotFoundError extends PayrollError {
710
321
  constructor(employeeId?: string, context?: Record<string, unknown>);
711
322
  }
323
+ /**
324
+ * Invalid employee error
325
+ */
326
+ declare class InvalidEmployeeError extends PayrollError {
327
+ constructor(message: string, context?: Record<string, unknown>);
328
+ }
712
329
  /**
713
330
  * Duplicate payroll error
714
331
  */
@@ -728,127 +345,45 @@ declare class ValidationError extends PayrollError {
728
345
  declare class EmployeeTerminatedError extends PayrollError {
729
346
  constructor(employeeId?: string, context?: Record<string, unknown>);
730
347
  }
348
+ /**
349
+ * Already processed error
350
+ */
351
+ declare class AlreadyProcessedError extends PayrollError {
352
+ constructor(message: string, context?: Record<string, unknown>);
353
+ }
731
354
  /**
732
355
  * Not eligible error
733
356
  */
734
357
  declare class NotEligibleError extends PayrollError {
735
358
  constructor(message: string, context?: Record<string, unknown>);
736
359
  }
737
-
738
360
  /**
739
- * @classytic/payroll - Compensation Factory
740
- *
741
- * Clean compensation structure creation
742
- * Presets for common compensation packages
361
+ * Create error from code
743
362
  */
744
-
745
- interface CreateCompensationParams {
746
- baseAmount: number;
747
- frequency?: PaymentFrequency;
748
- currency?: string;
749
- allowances?: Array<{
750
- type: Allowance['type'];
751
- value: number;
752
- isPercentage?: boolean;
753
- name?: string;
754
- taxable?: boolean;
755
- }>;
756
- deductions?: Array<{
757
- type: Deduction['type'];
758
- value: number;
759
- isPercentage?: boolean;
760
- name?: string;
761
- auto?: boolean;
762
- }>;
763
- effectiveFrom?: Date;
764
- }
765
- declare class CompensationFactory {
766
- /**
767
- * Create compensation object
768
- */
769
- static create(params: CreateCompensationParams): Compensation;
770
- /**
771
- * Create allowance
772
- */
773
- static createAllowance(params: {
774
- type: Allowance['type'];
775
- value: number;
776
- isPercentage?: boolean;
777
- name?: string;
778
- taxable?: boolean;
779
- }, baseAmount?: number): Allowance;
780
- /**
781
- * Create deduction
782
- */
783
- static createDeduction(params: {
784
- type: Deduction['type'];
785
- value: number;
786
- isPercentage?: boolean;
787
- name?: string;
788
- auto?: boolean;
789
- }, baseAmount?: number): Deduction;
790
- /**
791
- * Update base amount (immutable)
792
- */
793
- static updateBaseAmount(compensation: Compensation, newAmount: number, effectiveFrom?: Date): Compensation;
794
- /**
795
- * Add allowance (immutable)
796
- */
797
- static addAllowance(compensation: Compensation, allowance: Parameters<typeof this.createAllowance>[0]): Compensation;
798
- /**
799
- * Remove allowance (immutable)
800
- */
801
- static removeAllowance(compensation: Compensation, allowanceType: Allowance['type']): Compensation;
802
- /**
803
- * Add deduction (immutable)
804
- */
805
- static addDeduction(compensation: Compensation, deduction: Parameters<typeof this.createDeduction>[0]): Compensation;
806
- /**
807
- * Remove deduction (immutable)
808
- */
809
- static removeDeduction(compensation: Compensation, deductionType: Deduction['type']): Compensation;
810
- /**
811
- * Calculate compensation breakdown
812
- */
813
- static calculateBreakdown(compensation: Compensation): CompensationBreakdownResult;
814
- /**
815
- * Apply salary increment (immutable)
816
- */
817
- static applyIncrement(compensation: Compensation, params: {
818
- percentage?: number;
819
- amount?: number;
820
- effectiveFrom?: Date;
821
- }): Compensation;
822
- }
823
- declare class CompensationBuilder {
824
- private data;
825
- /**
826
- * Set base amount
827
- */
828
- withBase(amount: number, frequency?: PaymentFrequency, currency?: string): this;
829
- /**
830
- * Add allowance
831
- */
832
- addAllowance(type: Allowance['type'], value: number, isPercentage?: boolean, name?: string): this;
833
- /**
834
- * Add deduction
835
- */
836
- addDeduction(type: Deduction['type'], value: number, isPercentage?: boolean, name?: string): this;
837
- /**
838
- * Set effective date
839
- */
840
- effectiveFrom(date: Date): this;
841
- /**
842
- * Build compensation
843
- */
844
- build(): Compensation;
845
- }
363
+ declare function createError(code: ErrorCode, message: string, context?: Record<string, unknown>): PayrollError;
364
+ /**
365
+ * Check if error is PayrollError
366
+ */
367
+ declare function isPayrollError(error: unknown): error is PayrollError;
368
+ /**
369
+ * Extract error info for logging
370
+ */
371
+ declare function extractErrorInfo(error: unknown): {
372
+ code: string;
373
+ status: number;
374
+ message: string;
375
+ context?: Record<string, unknown>;
376
+ };
377
+ /**
378
+ * Convert unknown error to PayrollError
379
+ */
380
+ declare function toPayrollError(error: unknown): PayrollError;
846
381
 
847
382
  /**
848
383
  * @classytic/payroll - Attendance Integration
849
384
  *
850
385
  * Native integration with @classytic/clockin.
851
- * ClockIn is a peer dependency - attendance is core to payroll.
386
+ * ClockIn is an optional peer dependency for attendance-based deductions.
852
387
  */
853
388
 
854
389
  /**
@@ -869,9 +404,9 @@ declare class CompensationBuilder {
869
404
  * await payroll.processSalary({ employeeId, month: 3, year: 2024, attendance });
870
405
  * ```
871
406
  */
872
- declare function getAttendance(AttendanceModel: Model<any>, params: {
873
- organizationId: any;
874
- employeeId: any;
407
+ declare function getAttendance(AttendanceModel: Model<unknown>, params: {
408
+ organizationId: ObjectIdLike;
409
+ employeeId: ObjectIdLike;
875
410
  month: number;
876
411
  year: number;
877
412
  expectedDays: number;
@@ -895,9 +430,9 @@ declare function getAttendance(AttendanceModel: Model<any>, params: {
895
430
  * const emp1Attendance = attendanceMap.get(emp1._id.toString());
896
431
  * ```
897
432
  */
898
- declare function batchGetAttendance(AttendanceModel: Model<any>, params: {
899
- organizationId: any;
900
- employeeIds: any[];
433
+ declare function batchGetAttendance(AttendanceModel: Model<unknown>, params: {
434
+ organizationId: ObjectIdLike;
435
+ employeeIds: ObjectIdLike[];
901
436
  month: number;
902
437
  year: number;
903
438
  expectedDays: number;
@@ -956,12 +491,412 @@ declare function getHolidays(HolidayModel: Model<any>, params: {
956
491
  }): Promise<Date[]>;
957
492
 
958
493
  /**
959
- * @classytic/payroll
494
+ * @classytic/payroll - LeaveRequest Model
495
+ *
496
+ * Mongoose schema for leave requests with TTL support
497
+ */
498
+
499
+ declare const leaveRequestSchema: mongoose__default.Schema<any, mongoose__default.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
500
+ timestamps: true;
501
+ }, {
502
+ employeeId: mongoose__default.Types.ObjectId;
503
+ status: "pending" | "cancelled" | "approved" | "rejected";
504
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
505
+ metadata: any;
506
+ startDate: NativeDate;
507
+ endDate: NativeDate;
508
+ days: number;
509
+ halfDay: boolean;
510
+ attachments: string[];
511
+ reason?: string | null | undefined;
512
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
513
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
514
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
515
+ reviewedAt?: NativeDate | null | undefined;
516
+ reviewNotes?: string | null | undefined;
517
+ } & mongoose__default.DefaultTimestampProps, mongoose__default.Document<unknown, {}, {
518
+ employeeId: mongoose__default.Types.ObjectId;
519
+ status: "pending" | "cancelled" | "approved" | "rejected";
520
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
521
+ metadata: any;
522
+ startDate: NativeDate;
523
+ endDate: NativeDate;
524
+ days: number;
525
+ halfDay: boolean;
526
+ attachments: string[];
527
+ reason?: string | null | undefined;
528
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
529
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
530
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
531
+ reviewedAt?: NativeDate | null | undefined;
532
+ reviewNotes?: string | null | undefined;
533
+ } & mongoose__default.DefaultTimestampProps, {
534
+ id: string;
535
+ }, mongoose__default.ResolveSchemaOptions<{
536
+ timestamps: true;
537
+ }>> & Omit<{
538
+ employeeId: mongoose__default.Types.ObjectId;
539
+ status: "pending" | "cancelled" | "approved" | "rejected";
540
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
541
+ metadata: any;
542
+ startDate: NativeDate;
543
+ endDate: NativeDate;
544
+ days: number;
545
+ halfDay: boolean;
546
+ attachments: string[];
547
+ reason?: string | null | undefined;
548
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
549
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
550
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
551
+ reviewedAt?: NativeDate | null | undefined;
552
+ reviewNotes?: string | null | undefined;
553
+ } & mongoose__default.DefaultTimestampProps & {
554
+ _id: mongoose__default.Types.ObjectId;
555
+ } & {
556
+ __v: number;
557
+ }, "id"> & {
558
+ id: string;
559
+ }, {
560
+ [path: string]: mongoose__default.SchemaDefinitionProperty<undefined, any, any>;
561
+ } | {
562
+ [x: string]: mongoose__default.SchemaDefinitionProperty<any, any, mongoose__default.Document<unknown, {}, {
563
+ employeeId: mongoose__default.Types.ObjectId;
564
+ status: "pending" | "cancelled" | "approved" | "rejected";
565
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
566
+ metadata: any;
567
+ startDate: NativeDate;
568
+ endDate: NativeDate;
569
+ days: number;
570
+ halfDay: boolean;
571
+ attachments: string[];
572
+ reason?: string | null | undefined;
573
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
574
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
575
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
576
+ reviewedAt?: NativeDate | null | undefined;
577
+ reviewNotes?: string | null | undefined;
578
+ } & mongoose__default.DefaultTimestampProps, {
579
+ id: string;
580
+ }, mongoose__default.ResolveSchemaOptions<{
581
+ timestamps: true;
582
+ }>> & Omit<{
583
+ employeeId: mongoose__default.Types.ObjectId;
584
+ status: "pending" | "cancelled" | "approved" | "rejected";
585
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
586
+ metadata: any;
587
+ startDate: NativeDate;
588
+ endDate: NativeDate;
589
+ days: number;
590
+ halfDay: boolean;
591
+ attachments: string[];
592
+ reason?: string | null | undefined;
593
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
594
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
595
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
596
+ reviewedAt?: NativeDate | null | undefined;
597
+ reviewNotes?: string | null | undefined;
598
+ } & mongoose__default.DefaultTimestampProps & {
599
+ _id: mongoose__default.Types.ObjectId;
600
+ } & {
601
+ __v: number;
602
+ }, "id"> & {
603
+ id: string;
604
+ }> | undefined;
605
+ }, {
606
+ employeeId: mongoose__default.Types.ObjectId;
607
+ status: "pending" | "cancelled" | "approved" | "rejected";
608
+ type: "other" | "annual" | "sick" | "unpaid" | "maternity" | "paternity" | "bereavement" | "compensatory";
609
+ metadata: any;
610
+ startDate: NativeDate;
611
+ endDate: NativeDate;
612
+ days: number;
613
+ halfDay: boolean;
614
+ attachments: string[];
615
+ reason?: string | null | undefined;
616
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
617
+ organizationId?: mongoose__default.Types.ObjectId | null | undefined;
618
+ reviewedBy?: mongoose__default.Types.ObjectId | null | undefined;
619
+ reviewedAt?: NativeDate | null | undefined;
620
+ reviewNotes?: string | null | undefined;
621
+ createdAt: NativeDate;
622
+ updatedAt: NativeDate;
623
+ } & {
624
+ _id: mongoose__default.Types.ObjectId;
625
+ } & {
626
+ __v: number;
627
+ }>;
628
+ interface LeaveRequestModel extends Model<LeaveRequestDocument> {
629
+ findByEmployee(employeeId: mongoose__default.Types.ObjectId, options?: {
630
+ status?: LeaveRequestStatus;
631
+ year?: number;
632
+ limit?: number;
633
+ }): ReturnType<Model<LeaveRequestDocument>['find']>;
634
+ findPendingByOrganization(organizationId?: mongoose__default.Types.ObjectId): ReturnType<Model<LeaveRequestDocument>['find']>;
635
+ findByPeriod(organizationId: mongoose__default.Types.ObjectId | undefined, startDate: Date, endDate: Date, options?: {
636
+ status?: LeaveRequestStatus;
637
+ type?: LeaveType;
638
+ }): ReturnType<Model<LeaveRequestDocument>['find']>;
639
+ getLeaveStats(employeeId: mongoose__default.Types.ObjectId, year: number): Promise<Array<{
640
+ _id: LeaveType;
641
+ totalDays: number;
642
+ count: number;
643
+ }>>;
644
+ getOrganizationSummary(organizationId: mongoose__default.Types.ObjectId | undefined, year: number): Promise<Array<{
645
+ _id: {
646
+ status: LeaveRequestStatus;
647
+ type: LeaveType;
648
+ };
649
+ totalDays: number;
650
+ count: number;
651
+ }>>;
652
+ findOverlapping(employeeId: mongoose__default.Types.ObjectId, startDate: Date, endDate: Date, excludeRequestId?: mongoose__default.Types.ObjectId): ReturnType<Model<LeaveRequestDocument>['find']>;
653
+ hasOverlap(employeeId: mongoose__default.Types.ObjectId, startDate: Date, endDate: Date, excludeRequestId?: mongoose__default.Types.ObjectId): Promise<boolean>;
654
+ }
655
+ /**
656
+ * Get or create LeaveRequest model
960
657
  *
961
- * Enterprise-grade HRM and Payroll Management for MongoDB/Mongoose
962
- * Clean, pluggable, multi-tenant architecture
658
+ * @example
659
+ * const LeaveRequest = getLeaveRequestModel();
963
660
  *
964
- * @packageDocumentation
661
+ * // With custom connection
662
+ * const LeaveRequest = getLeaveRequestModel(customConnection);
663
+ */
664
+ declare function getLeaveRequestModel(connection?: mongoose__default.Connection): LeaveRequestModel;
665
+
666
+ /**
667
+ * @classytic/payroll - TaxWithholding Model
668
+ *
669
+ * Mongoose schema for tax withholding tracking with aggregation support
670
+ */
671
+
672
+ declare const taxWithholdingSchema: mongoose__default.Schema<any, mongoose__default.Model<any, any, any, any, any, any, any>, {}, {}, {}, {}, {
673
+ timestamps: true;
674
+ }, {
675
+ employeeId: mongoose__default.Types.ObjectId;
676
+ amount: number;
677
+ status: "pending" | "paid" | "submitted";
678
+ organizationId: mongoose__default.Types.ObjectId;
679
+ currency: string;
680
+ payrollRecordId: mongoose__default.Types.ObjectId;
681
+ metadata: any;
682
+ transactionId: mongoose__default.Types.ObjectId;
683
+ taxableAmount: number;
684
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
685
+ taxRate: number;
686
+ period?: {
687
+ month: number;
688
+ year: number;
689
+ startDate: NativeDate;
690
+ endDate: NativeDate;
691
+ payDate: NativeDate;
692
+ } | null | undefined;
693
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
694
+ referenceNumber?: string | null | undefined;
695
+ notes?: string | null | undefined;
696
+ paidAt?: NativeDate | null | undefined;
697
+ submittedAt?: NativeDate | null | undefined;
698
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
699
+ } & mongoose__default.DefaultTimestampProps, mongoose__default.Document<unknown, {}, {
700
+ employeeId: mongoose__default.Types.ObjectId;
701
+ amount: number;
702
+ status: "pending" | "paid" | "submitted";
703
+ organizationId: mongoose__default.Types.ObjectId;
704
+ currency: string;
705
+ payrollRecordId: mongoose__default.Types.ObjectId;
706
+ metadata: any;
707
+ transactionId: mongoose__default.Types.ObjectId;
708
+ taxableAmount: number;
709
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
710
+ taxRate: number;
711
+ period?: {
712
+ month: number;
713
+ year: number;
714
+ startDate: NativeDate;
715
+ endDate: NativeDate;
716
+ payDate: NativeDate;
717
+ } | null | undefined;
718
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
719
+ referenceNumber?: string | null | undefined;
720
+ notes?: string | null | undefined;
721
+ paidAt?: NativeDate | null | undefined;
722
+ submittedAt?: NativeDate | null | undefined;
723
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
724
+ } & mongoose__default.DefaultTimestampProps, {
725
+ id: string;
726
+ }, mongoose__default.ResolveSchemaOptions<{
727
+ timestamps: true;
728
+ }>> & Omit<{
729
+ employeeId: mongoose__default.Types.ObjectId;
730
+ amount: number;
731
+ status: "pending" | "paid" | "submitted";
732
+ organizationId: mongoose__default.Types.ObjectId;
733
+ currency: string;
734
+ payrollRecordId: mongoose__default.Types.ObjectId;
735
+ metadata: any;
736
+ transactionId: mongoose__default.Types.ObjectId;
737
+ taxableAmount: number;
738
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
739
+ taxRate: number;
740
+ period?: {
741
+ month: number;
742
+ year: number;
743
+ startDate: NativeDate;
744
+ endDate: NativeDate;
745
+ payDate: NativeDate;
746
+ } | null | undefined;
747
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
748
+ referenceNumber?: string | null | undefined;
749
+ notes?: string | null | undefined;
750
+ paidAt?: NativeDate | null | undefined;
751
+ submittedAt?: NativeDate | null | undefined;
752
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
753
+ } & mongoose__default.DefaultTimestampProps & {
754
+ _id: mongoose__default.Types.ObjectId;
755
+ } & {
756
+ __v: number;
757
+ }, "id"> & {
758
+ id: string;
759
+ }, {
760
+ [path: string]: mongoose__default.SchemaDefinitionProperty<undefined, any, any>;
761
+ } | {
762
+ [x: string]: mongoose__default.SchemaDefinitionProperty<any, any, mongoose__default.Document<unknown, {}, {
763
+ employeeId: mongoose__default.Types.ObjectId;
764
+ amount: number;
765
+ status: "pending" | "paid" | "submitted";
766
+ organizationId: mongoose__default.Types.ObjectId;
767
+ currency: string;
768
+ payrollRecordId: mongoose__default.Types.ObjectId;
769
+ metadata: any;
770
+ transactionId: mongoose__default.Types.ObjectId;
771
+ taxableAmount: number;
772
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
773
+ taxRate: number;
774
+ period?: {
775
+ month: number;
776
+ year: number;
777
+ startDate: NativeDate;
778
+ endDate: NativeDate;
779
+ payDate: NativeDate;
780
+ } | null | undefined;
781
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
782
+ referenceNumber?: string | null | undefined;
783
+ notes?: string | null | undefined;
784
+ paidAt?: NativeDate | null | undefined;
785
+ submittedAt?: NativeDate | null | undefined;
786
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
787
+ } & mongoose__default.DefaultTimestampProps, {
788
+ id: string;
789
+ }, mongoose__default.ResolveSchemaOptions<{
790
+ timestamps: true;
791
+ }>> & Omit<{
792
+ employeeId: mongoose__default.Types.ObjectId;
793
+ amount: number;
794
+ status: "pending" | "paid" | "submitted";
795
+ organizationId: mongoose__default.Types.ObjectId;
796
+ currency: string;
797
+ payrollRecordId: mongoose__default.Types.ObjectId;
798
+ metadata: any;
799
+ transactionId: mongoose__default.Types.ObjectId;
800
+ taxableAmount: number;
801
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
802
+ taxRate: number;
803
+ period?: {
804
+ month: number;
805
+ year: number;
806
+ startDate: NativeDate;
807
+ endDate: NativeDate;
808
+ payDate: NativeDate;
809
+ } | null | undefined;
810
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
811
+ referenceNumber?: string | null | undefined;
812
+ notes?: string | null | undefined;
813
+ paidAt?: NativeDate | null | undefined;
814
+ submittedAt?: NativeDate | null | undefined;
815
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
816
+ } & mongoose__default.DefaultTimestampProps & {
817
+ _id: mongoose__default.Types.ObjectId;
818
+ } & {
819
+ __v: number;
820
+ }, "id"> & {
821
+ id: string;
822
+ }> | undefined;
823
+ }, {
824
+ employeeId: mongoose__default.Types.ObjectId;
825
+ amount: number;
826
+ status: "pending" | "paid" | "submitted";
827
+ organizationId: mongoose__default.Types.ObjectId;
828
+ currency: string;
829
+ payrollRecordId: mongoose__default.Types.ObjectId;
830
+ metadata: any;
831
+ transactionId: mongoose__default.Types.ObjectId;
832
+ taxableAmount: number;
833
+ taxType: "other" | "income_tax" | "social_security" | "health_insurance" | "pension" | "employment_insurance" | "local_tax";
834
+ taxRate: number;
835
+ period?: {
836
+ month: number;
837
+ year: number;
838
+ startDate: NativeDate;
839
+ endDate: NativeDate;
840
+ payDate: NativeDate;
841
+ } | null | undefined;
842
+ userId?: mongoose__default.Types.ObjectId | null | undefined;
843
+ referenceNumber?: string | null | undefined;
844
+ notes?: string | null | undefined;
845
+ paidAt?: NativeDate | null | undefined;
846
+ submittedAt?: NativeDate | null | undefined;
847
+ governmentTransactionId?: mongoose__default.Types.ObjectId | null | undefined;
848
+ createdAt: NativeDate;
849
+ updatedAt: NativeDate;
850
+ } & {
851
+ _id: mongoose__default.Types.ObjectId;
852
+ } & {
853
+ __v: number;
854
+ }>;
855
+ interface TaxWithholdingModel extends Model<TaxWithholdingDocument> {
856
+ findByPeriod(organizationId: mongoose__default.Types.ObjectId, month: number, year: number): ReturnType<Model<TaxWithholdingDocument>['find']>;
857
+ findByEmployee(employeeId: mongoose__default.Types.ObjectId, options?: {
858
+ year?: number;
859
+ taxType?: TaxType;
860
+ status?: TaxStatus;
861
+ limit?: number;
862
+ }): ReturnType<Model<TaxWithholdingDocument>['find']>;
863
+ findPending(organizationId: mongoose__default.Types.ObjectId, options?: {
864
+ fromMonth?: number;
865
+ fromYear?: number;
866
+ toMonth?: number;
867
+ toYear?: number;
868
+ taxType?: TaxType;
869
+ }): ReturnType<Model<TaxWithholdingDocument>['find']>;
870
+ getSummaryByType(organizationId: mongoose__default.Types.ObjectId, fromPeriod: {
871
+ month: number;
872
+ year: number;
873
+ }, toPeriod: {
874
+ month: number;
875
+ year: number;
876
+ }): Promise<Array<{
877
+ taxType: TaxType;
878
+ totalAmount: number;
879
+ count: number;
880
+ withholdingIds: mongoose__default.Types.ObjectId[];
881
+ }>>;
882
+ getByPayrollRecord(payrollRecordId: mongoose__default.Types.ObjectId): ReturnType<Model<TaxWithholdingDocument>['find']>;
883
+ getTotalByOrganization(organizationId: mongoose__default.Types.ObjectId, options?: {
884
+ status?: TaxStatus;
885
+ year?: number;
886
+ }): Promise<{
887
+ totalAmount: number;
888
+ count: number;
889
+ }>;
890
+ }
891
+ /**
892
+ * Get or create TaxWithholding model
893
+ *
894
+ * @example
895
+ * const TaxWithholding = getTaxWithholdingModel();
896
+ *
897
+ * // With custom connection
898
+ * const TaxWithholding = getTaxWithholdingModel(customConnection);
965
899
  */
900
+ declare function getTaxWithholdingModel(connection?: mongoose__default.Connection): TaxWithholdingModel;
966
901
 
967
- export { ALLOWANCE_TYPE, Allowance, Compensation, CompensationBuilder, CompensationFactory, DEDUCTION_TYPE, DEPARTMENT, Deduction, DeepPartial, Department, DuplicatePayrollError, EMPLOYEE_STATUS, EMPLOYMENT_TYPE, EmployeeNotFoundError, type EmployeePluginOptions, EmployeeTerminatedError, EmploymentType, HRMConfig, HRM_CONFIG, HRM_TRANSACTION_CATEGORIES, type Holiday, NotEligibleError, NotInitializedError, PAYMENT_FREQUENCY, PAYROLL_STATUS, PaymentFrequency, PayrollError, PayrollRecordDocument, type PayrollRecordModel, TERMINATION_REASON, ValidationError, batchGetAttendance, calculateTax, createHolidaySchema, payroll as default, determineOrgRole, employeePlugin, getAttendance, getHolidays, getPayrollRecordModel, mergeConfig, payroll as payrollInstance, payrollRecordSchema };
902
+ export { ALLOWANCE_TYPE, AlreadyProcessedError, type CreatePayrollTransactionInput, type CreateTaxPaymentTransactionInput, DEDUCTION_TYPE, DEPARTMENT, DeepPartial, Department, DuplicatePayrollError, EMPLOYEE_STATUS, EMPLOYMENT_TYPE, EmployeeNotFoundError, type EmployeePluginOptions, EmployeeTerminatedError, EmploymentType, ErrorCode, HRMConfig, HRM_CONFIG, type Holiday, HttpError, type IPayrollTransaction, type IPayrollTransactionCreateInput, InvalidEmployeeError, LEAVE_REQUEST_STATUS, LEAVE_TYPE, LeaveInitConfig, LeaveRequestDocument, type LeaveRequestModel, LeaveRequestStatus, LeaveType, NotEligibleError, NotInitializedError, ObjectIdLike, OrgRole, PAYMENT_FREQUENCY, PAYROLL_STATUS, PayrollBreakdown, PayrollError, TAX_STATUS, TAX_STATUS_VALUES, TAX_TYPE, TAX_TYPE_VALUES, TERMINATION_REASON, TaxStatus, TaxType, TaxWithholdingDocument, type TaxWithholdingModel, TransactionFactory, ValidationError, batchGetAttendance, createError, createHolidaySchema, createPayrollTransaction, createTaxPaymentTransaction, determineOrgRole, employeePlugin, extractErrorInfo, getAttendance, getHolidays, getLeaveRequestModel, getTaxWithholdingModel, isApprovedLeaveStatus, isPaidLeaveType, isPaidTaxStatus, isPayrollError, isPayrollTransaction, isPendingLeaveStatus, isPendingTaxStatus, isValidLeaveRequestStatus, isValidLeaveType, isValidTaxStatus, isValidTaxType, leaveRequestSchema, mergeConfig, taxWithholdingSchema, toPayrollError };