@classytic/payroll 1.0.2 → 2.0.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.

Files changed (68) hide show
  1. package/README.md +168 -489
  2. package/dist/core/index.d.ts +480 -0
  3. package/dist/core/index.js +971 -0
  4. package/dist/core/index.js.map +1 -0
  5. package/dist/index-CTjHlCzz.d.ts +721 -0
  6. package/dist/index.d.ts +967 -0
  7. package/dist/index.js +4352 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/payroll.d.ts +233 -0
  10. package/dist/payroll.js +2103 -0
  11. package/dist/payroll.js.map +1 -0
  12. package/dist/plugin-D9mOr3_d.d.ts +333 -0
  13. package/dist/schemas/index.d.ts +2869 -0
  14. package/dist/schemas/index.js +440 -0
  15. package/dist/schemas/index.js.map +1 -0
  16. package/dist/services/index.d.ts +3 -0
  17. package/dist/services/index.js +1696 -0
  18. package/dist/services/index.js.map +1 -0
  19. package/dist/types-BSYyX2KJ.d.ts +671 -0
  20. package/dist/utils/index.d.ts +873 -0
  21. package/dist/utils/index.js +1046 -0
  22. package/dist/utils/index.js.map +1 -0
  23. package/package.json +54 -37
  24. package/dist/types/config.d.ts +0 -162
  25. package/dist/types/core/compensation.manager.d.ts +0 -54
  26. package/dist/types/core/employment.manager.d.ts +0 -49
  27. package/dist/types/core/payroll.manager.d.ts +0 -60
  28. package/dist/types/enums.d.ts +0 -117
  29. package/dist/types/factories/compensation.factory.d.ts +0 -196
  30. package/dist/types/factories/employee.factory.d.ts +0 -149
  31. package/dist/types/factories/payroll.factory.d.ts +0 -319
  32. package/dist/types/hrm.orchestrator.d.ts +0 -47
  33. package/dist/types/index.d.ts +0 -20
  34. package/dist/types/init.d.ts +0 -30
  35. package/dist/types/models/payroll-record.model.d.ts +0 -3
  36. package/dist/types/plugins/employee.plugin.d.ts +0 -2
  37. package/dist/types/schemas/employment.schema.d.ts +0 -959
  38. package/dist/types/services/compensation.service.d.ts +0 -94
  39. package/dist/types/services/employee.service.d.ts +0 -28
  40. package/dist/types/services/payroll.service.d.ts +0 -30
  41. package/dist/types/utils/calculation.utils.d.ts +0 -26
  42. package/dist/types/utils/date.utils.d.ts +0 -35
  43. package/dist/types/utils/logger.d.ts +0 -12
  44. package/dist/types/utils/query-builders.d.ts +0 -83
  45. package/dist/types/utils/validation.utils.d.ts +0 -33
  46. package/payroll.d.ts +0 -241
  47. package/src/config.js +0 -177
  48. package/src/core/compensation.manager.js +0 -242
  49. package/src/core/employment.manager.js +0 -224
  50. package/src/core/payroll.manager.js +0 -499
  51. package/src/enums.js +0 -141
  52. package/src/factories/compensation.factory.js +0 -198
  53. package/src/factories/employee.factory.js +0 -173
  54. package/src/factories/payroll.factory.js +0 -413
  55. package/src/hrm.orchestrator.js +0 -139
  56. package/src/index.js +0 -172
  57. package/src/init.js +0 -62
  58. package/src/models/payroll-record.model.js +0 -126
  59. package/src/plugins/employee.plugin.js +0 -164
  60. package/src/schemas/employment.schema.js +0 -126
  61. package/src/services/compensation.service.js +0 -231
  62. package/src/services/employee.service.js +0 -162
  63. package/src/services/payroll.service.js +0 -213
  64. package/src/utils/calculation.utils.js +0 -91
  65. package/src/utils/date.utils.js +0 -120
  66. package/src/utils/logger.js +0 -36
  67. package/src/utils/query-builders.js +0 -185
  68. package/src/utils/validation.utils.js +0 -122
@@ -0,0 +1,233 @@
1
+ import { ClientSession, Model } from 'mongoose';
2
+ import { P as PayrollInitConfig, H as HireEmployeeParams, E as EmployeeDocument, U as UpdateEmploymentParams, T as TerminateEmployeeParams, R as ReHireEmployeeParams, O as ObjectIdLike, L as ListEmployeesParams, a as UpdateSalaryParams, A as AddAllowanceParams, b as RemoveAllowanceParams, c as AddDeductionParams, d as RemoveDeductionParams, e as UpdateBankDetailsParams, f as ProcessSalaryParams, g as ProcessSalaryResult, h as ProcessBulkPayrollParams, B as BulkPayrollResult, i as PayrollHistoryParams, j as PayrollRecordDocument, k as PayrollSummaryParams, l as PayrollSummaryResult, m as ExportPayrollParams, D as DeepPartial, n as HRMConfig, S as SingleTenantConfig, o as Logger } from './types-BSYyX2KJ.js';
3
+ import { P as PayrollPluginDefinition, a as PayrollEventMap } from './plugin-D9mOr3_d.js';
4
+
5
+ /**
6
+ * @classytic/payroll - Main Payroll Class
7
+ *
8
+ * Clean, Stripe-like API for payroll management
9
+ * Builder pattern for configuration
10
+ */
11
+
12
+ declare class Payroll {
13
+ private _container;
14
+ private _events;
15
+ private _plugins;
16
+ private _initialized;
17
+ constructor();
18
+ /**
19
+ * Initialize Payroll with models and configuration
20
+ */
21
+ initialize(config: PayrollInitConfig): this;
22
+ /**
23
+ * Check if initialized
24
+ */
25
+ isInitialized(): boolean;
26
+ /**
27
+ * Ensure initialized
28
+ */
29
+ private ensureInitialized;
30
+ /**
31
+ * Get models
32
+ */
33
+ private get models();
34
+ /**
35
+ * Get config
36
+ */
37
+ private get config();
38
+ /**
39
+ * Register a plugin
40
+ */
41
+ use(plugin: PayrollPluginDefinition): Promise<this>;
42
+ /**
43
+ * Subscribe to events
44
+ */
45
+ on<K extends keyof PayrollEventMap>(event: K, handler: (payload: PayrollEventMap[K]) => void | Promise<void>): () => void;
46
+ /**
47
+ * Hire a new employee
48
+ */
49
+ hire(params: HireEmployeeParams): Promise<EmployeeDocument>;
50
+ /**
51
+ * Update employment details
52
+ * NOTE: Status changes to 'terminated' must use terminate() method
53
+ */
54
+ updateEmployment(params: UpdateEmploymentParams): Promise<EmployeeDocument>;
55
+ /**
56
+ * Terminate employee
57
+ */
58
+ terminate(params: TerminateEmployeeParams): Promise<EmployeeDocument>;
59
+ /**
60
+ * Re-hire terminated employee
61
+ */
62
+ reHire(params: ReHireEmployeeParams): Promise<EmployeeDocument>;
63
+ /**
64
+ * Get employee by ID
65
+ */
66
+ getEmployee(params: {
67
+ employeeId: ObjectIdLike;
68
+ populateUser?: boolean;
69
+ session?: ClientSession;
70
+ }): Promise<EmployeeDocument>;
71
+ /**
72
+ * List employees
73
+ */
74
+ listEmployees(params: ListEmployeesParams): Promise<{
75
+ docs: EmployeeDocument[];
76
+ totalDocs: number;
77
+ page: number;
78
+ limit: number;
79
+ }>;
80
+ /**
81
+ * Update employee salary
82
+ */
83
+ updateSalary(params: UpdateSalaryParams): Promise<EmployeeDocument>;
84
+ /**
85
+ * Add allowance to employee
86
+ */
87
+ addAllowance(params: AddAllowanceParams): Promise<EmployeeDocument>;
88
+ /**
89
+ * Remove allowance from employee
90
+ */
91
+ removeAllowance(params: RemoveAllowanceParams): Promise<EmployeeDocument>;
92
+ /**
93
+ * Add deduction to employee
94
+ */
95
+ addDeduction(params: AddDeductionParams): Promise<EmployeeDocument>;
96
+ /**
97
+ * Remove deduction from employee
98
+ */
99
+ removeDeduction(params: RemoveDeductionParams): Promise<EmployeeDocument>;
100
+ /**
101
+ * Update bank details
102
+ */
103
+ updateBankDetails(params: UpdateBankDetailsParams): Promise<EmployeeDocument>;
104
+ /**
105
+ * Process salary for single employee
106
+ *
107
+ * ATOMICITY: This method creates its own transaction if none provided.
108
+ * All database operations (PayrollRecord, Transaction, Employee stats)
109
+ * are atomic - either all succeed or all fail.
110
+ */
111
+ processSalary(params: ProcessSalaryParams): Promise<ProcessSalaryResult>;
112
+ /**
113
+ * Process bulk payroll
114
+ *
115
+ * ATOMICITY STRATEGY: Each employee is processed in its own transaction.
116
+ * This allows partial success - some employees can succeed while others fail.
117
+ * Failed employees don't affect successful ones.
118
+ */
119
+ processBulkPayroll(params: ProcessBulkPayrollParams): Promise<BulkPayrollResult>;
120
+ /**
121
+ * Get payroll history
122
+ */
123
+ payrollHistory(params: PayrollHistoryParams): Promise<PayrollRecordDocument[]>;
124
+ /**
125
+ * Get payroll summary
126
+ */
127
+ payrollSummary(params: PayrollSummaryParams): Promise<PayrollSummaryResult>;
128
+ /**
129
+ * Export payroll data
130
+ */
131
+ exportPayroll(params: ExportPayrollParams): Promise<PayrollRecordDocument[]>;
132
+ /**
133
+ * Calculate salary breakdown with proper handling for:
134
+ * - Effective dates on allowances/deductions
135
+ * - Pro-rating for mid-period hires AND terminations
136
+ * - Tax calculation
137
+ * - Working days vs calendar days for attendance
138
+ */
139
+ private calculateSalaryBreakdown;
140
+ /**
141
+ * Advanced pro-rating calculation that handles:
142
+ * - Mid-period hires
143
+ * - Mid-period terminations
144
+ * - Working days (not calendar days)
145
+ */
146
+ private calculateProRatingAdvanced;
147
+ /**
148
+ * Calculate attendance deduction using working days (not calendar days)
149
+ */
150
+ private calculateAttendanceDeduction;
151
+ private updatePayrollStats;
152
+ /**
153
+ * Create a new Payroll instance
154
+ */
155
+ static create(): Payroll;
156
+ }
157
+ interface ModelsConfig {
158
+ EmployeeModel: Model<any>;
159
+ PayrollRecordModel: Model<any>;
160
+ TransactionModel: Model<any>;
161
+ AttendanceModel?: Model<any> | null;
162
+ }
163
+ interface PayrollBuilderOptions {
164
+ models?: ModelsConfig;
165
+ config?: DeepPartial<HRMConfig>;
166
+ singleTenant?: SingleTenantConfig | null;
167
+ logger?: Logger;
168
+ }
169
+ declare class PayrollBuilder {
170
+ private _models;
171
+ private _config;
172
+ private _singleTenant;
173
+ private _logger;
174
+ /**
175
+ * Set models
176
+ */
177
+ withModels(models: ModelsConfig): this;
178
+ /**
179
+ * Set config overrides
180
+ */
181
+ withConfig(config: DeepPartial<HRMConfig>): this;
182
+ /**
183
+ * Enable single-tenant mode
184
+ *
185
+ * Use this when building a single-organization HRM (no organizationId needed)
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * const payroll = createPayrollInstance()
190
+ * .withModels({ EmployeeModel, PayrollRecordModel, TransactionModel })
191
+ * .withSingleTenant({ organizationId: 'my-company' })
192
+ * .build();
193
+ * ```
194
+ */
195
+ withSingleTenant(config: SingleTenantConfig): this;
196
+ /**
197
+ * Enable single-tenant mode (shorthand)
198
+ *
199
+ * Alias for withSingleTenant() - consistent with @classytic/clockin API
200
+ *
201
+ * @example
202
+ * ```typescript
203
+ * const payroll = createPayrollInstance()
204
+ * .withModels({ ... })
205
+ * .forSingleTenant() // ← No organizationId needed!
206
+ * .build();
207
+ * ```
208
+ */
209
+ forSingleTenant(config?: SingleTenantConfig): this;
210
+ /**
211
+ * Set custom logger
212
+ */
213
+ withLogger(logger: Logger): this;
214
+ /**
215
+ * Build and initialize Payroll instance
216
+ */
217
+ build(): Payroll;
218
+ }
219
+ /**
220
+ * Create a new Payroll builder
221
+ */
222
+ declare function createPayrollInstance(): PayrollBuilder;
223
+ /**
224
+ * Get or create singleton Payroll instance
225
+ */
226
+ declare function getPayroll(): Payroll;
227
+ /**
228
+ * Reset singleton (for testing)
229
+ */
230
+ declare function resetPayroll(): void;
231
+ declare const payroll: Payroll;
232
+
233
+ export { type ModelsConfig, Payroll, PayrollBuilder, type PayrollBuilderOptions, createPayrollInstance, payroll as default, getPayroll, payroll, resetPayroll };