@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
@@ -1,319 +0,0 @@
1
- /**
2
- * @typedef {Object} AllowanceInput
3
- * @property {string} type - Type of allowance
4
- * @property {string} [name] - Display name for the allowance
5
- * @property {number} value - Allowance value (amount or percentage)
6
- * @property {boolean} [isPercentage=false] - Whether value is a percentage
7
- */
8
- /**
9
- * @typedef {Object} DeductionInput
10
- * @property {string} type - Type of deduction
11
- * @property {string} [name] - Display name for the deduction
12
- * @property {number} value - Deduction value (amount or percentage)
13
- * @property {boolean} [isPercentage=false] - Whether value is a percentage
14
- */
15
- /**
16
- * @typedef {Object} PeriodInput
17
- * @property {number} [month] - Month (1-12)
18
- * @property {number} [year] - Year
19
- */
20
- /**
21
- * @typedef {Object} PayrollMetadata
22
- * @property {string} [currency='BDT'] - Currency code
23
- * @property {string} [paymentMethod] - Payment method
24
- * @property {string} [notes] - Additional notes
25
- */
26
- /**
27
- * @typedef {Object} PayrollRecord
28
- * @property {string} employeeId - Employee identifier
29
- * @property {string} organizationId - Organization identifier
30
- * @property {Object} period - Pay period information
31
- * @property {Object} breakdown - Salary breakdown
32
- * @property {number} breakdown.baseAmount - Base salary amount
33
- * @property {Array} breakdown.allowances - Calculated allowances
34
- * @property {Array} breakdown.deductions - Calculated deductions
35
- * @property {number} breakdown.grossSalary - Gross salary
36
- * @property {number} breakdown.netSalary - Net salary after deductions
37
- * @property {string} status - Payroll status ('pending', 'processed', 'paid')
38
- * @property {Date|null} processedAt - When payroll was processed
39
- * @property {Date|null} paidAt - When payment was made
40
- * @property {PayrollMetadata} metadata - Additional metadata
41
- */
42
- export class PayrollFactory {
43
- /**
44
- * Create a new payroll record
45
- *
46
- * @param {Object} params - Payroll parameters
47
- * @param {string} params.employeeId - Employee ID
48
- * @param {string} params.organizationId - Organization ID
49
- * @param {number} params.baseAmount - Base salary amount
50
- * @param {AllowanceInput[]} [params.allowances=[]] - Allowances array
51
- * @param {DeductionInput[]} [params.deductions=[]] - Deductions array
52
- * @param {PeriodInput} [params.period={}] - Pay period
53
- * @param {PayrollMetadata} [params.metadata={}] - Additional metadata
54
- * @returns {PayrollRecord} Payroll record object
55
- */
56
- static create({ employeeId, organizationId, baseAmount, allowances, deductions, period, metadata, }: {
57
- employeeId: string;
58
- organizationId: string;
59
- baseAmount: number;
60
- allowances?: AllowanceInput[];
61
- deductions?: DeductionInput[];
62
- period?: PeriodInput;
63
- metadata?: PayrollMetadata;
64
- }): PayrollRecord;
65
- /**
66
- * Create a pay period object
67
- *
68
- * @param {PeriodInput} [params={}] - Period parameters
69
- * @param {number} [params.month] - Month (defaults to current month)
70
- * @param {number} [params.year] - Year (defaults to current year)
71
- * @returns {Object} Pay period object with startDate, endDate, etc.
72
- */
73
- static createPeriod({ month, year }?: PeriodInput): any;
74
- /**
75
- * Calculate allowances from base amount and allowance inputs
76
- *
77
- * @param {number} baseAmount - Base salary amount
78
- * @param {AllowanceInput[]} allowances - Array of allowances
79
- * @returns {Array} Calculated allowances with amounts
80
- */
81
- static calculateAllowances(baseAmount: number, allowances: AllowanceInput[]): any[];
82
- /**
83
- * Calculate deductions from base amount and deduction inputs
84
- *
85
- * @param {number} baseAmount - Base salary amount
86
- * @param {DeductionInput[]} deductions - Array of deductions
87
- * @returns {Array} Calculated deductions with amounts
88
- */
89
- static calculateDeductions(baseAmount: number, deductions: DeductionInput[]): any[];
90
- /**
91
- * Create a bonus object
92
- *
93
- * @param {Object} params - Bonus parameters
94
- * @param {string} params.type - Bonus type
95
- * @param {number} params.amount - Bonus amount
96
- * @param {string} params.reason - Reason for bonus
97
- * @param {string} params.approvedBy - User who approved the bonus
98
- * @returns {Object} Bonus object
99
- */
100
- static createBonus({ type, amount, reason, approvedBy }: {
101
- type: string;
102
- amount: number;
103
- reason: string;
104
- approvedBy: string;
105
- }): any;
106
- /**
107
- * Create a deduction object
108
- *
109
- * @param {Object} params - Deduction parameters
110
- * @param {string} params.type - Deduction type
111
- * @param {number} params.amount - Deduction amount
112
- * @param {string} params.reason - Reason for deduction
113
- * @param {string} params.appliedBy - User who applied the deduction
114
- * @returns {Object} Deduction object
115
- */
116
- static createDeduction({ type, amount, reason, appliedBy }: {
117
- type: string;
118
- amount: number;
119
- reason: string;
120
- appliedBy: string;
121
- }): any;
122
- /**
123
- * Mark a payroll record as paid (immutable - returns new object)
124
- *
125
- * @param {PayrollRecord} payroll - Payroll record to mark as paid
126
- * @param {Object} [params={}] - Payment details
127
- * @param {Date} [params.paidAt] - Payment date (defaults to now)
128
- * @param {string} [params.transactionId] - Transaction ID
129
- * @param {string} [params.paymentMethod] - Payment method
130
- * @returns {PayrollRecord} New payroll record marked as paid
131
- */
132
- static markAsPaid(payroll: PayrollRecord, { paidAt, transactionId, paymentMethod }?: {
133
- paidAt?: Date;
134
- transactionId?: string;
135
- paymentMethod?: string;
136
- }): PayrollRecord;
137
- /**
138
- * Mark a payroll record as processed (immutable - returns new object)
139
- *
140
- * @param {PayrollRecord} payroll - Payroll record to mark as processed
141
- * @param {Object} [params={}] - Processing details
142
- * @param {Date} [params.processedAt] - Processing date (defaults to now)
143
- * @returns {PayrollRecord} New payroll record marked as processed
144
- */
145
- static markAsProcessed(payroll: PayrollRecord, { processedAt }?: {
146
- processedAt?: Date;
147
- }): PayrollRecord;
148
- }
149
- /**
150
- * PayrollBuilder - Fluent builder pattern for creating payroll records
151
- *
152
- * @example
153
- * const payroll = createPayroll()
154
- * .forEmployee('emp-123')
155
- * .inOrganization('org-456')
156
- * .withBaseAmount(50000)
157
- * .addAllowance('housing', 10000)
158
- * .addDeduction('tax', 15, true)
159
- * .build();
160
- */
161
- export class PayrollBuilder {
162
- data: {
163
- allowances: any[];
164
- deductions: any[];
165
- period: {};
166
- metadata: {};
167
- };
168
- forEmployee(employeeId: any): this;
169
- inOrganization(organizationId: any): this;
170
- withBaseAmount(amount: any): this;
171
- forPeriod(month: any, year: any): this;
172
- addAllowance(type: any, value: any, isPercentage?: boolean, name?: any): this;
173
- addDeduction(type: any, value: any, isPercentage?: boolean, name?: any): this;
174
- addBonus(amount: any, reason: any, approvedBy: any): this;
175
- withCurrency(currency: any): this;
176
- withPaymentMethod(method: any): this;
177
- withNotes(notes: any): this;
178
- build(): PayrollRecord;
179
- }
180
- export function createPayroll(): PayrollBuilder;
181
- /**
182
- * BatchPayrollFactory - Process payroll for multiple employees at once
183
- *
184
- * @example
185
- * const payrolls = BatchPayrollFactory.createBatch(employees, {
186
- * month: 1,
187
- * year: 2025,
188
- * organizationId: 'org-123'
189
- * });
190
- */
191
- export class BatchPayrollFactory {
192
- /**
193
- * Create payroll records for multiple employees
194
- *
195
- * @param {Array} employees - Array of employee objects
196
- * @param {Object} params - Batch parameters
197
- * @param {number} params.month - Month for payroll
198
- * @param {number} params.year - Year for payroll
199
- * @param {string} params.organizationId - Organization ID
200
- * @returns {PayrollRecord[]} Array of payroll records
201
- */
202
- static createBatch(employees: any[], { month, year, organizationId }: {
203
- month: number;
204
- year: number;
205
- organizationId: string;
206
- }): PayrollRecord[];
207
- /**
208
- * Calculate total payroll amounts across multiple records
209
- *
210
- * @param {PayrollRecord[]} payrolls - Array of payroll records
211
- * @returns {Object} Totals summary
212
- * @returns {number} return.count - Total number of payrolls
213
- * @returns {number} return.totalGross - Sum of gross salaries
214
- * @returns {number} return.totalNet - Sum of net salaries
215
- * @returns {number} return.totalAllowances - Sum of all allowances
216
- * @returns {number} return.totalDeductions - Sum of all deductions
217
- */
218
- static calculateTotalPayroll(payrolls: PayrollRecord[]): any;
219
- }
220
- export type AllowanceInput = {
221
- /**
222
- * - Type of allowance
223
- */
224
- type: string;
225
- /**
226
- * - Display name for the allowance
227
- */
228
- name?: string;
229
- /**
230
- * - Allowance value (amount or percentage)
231
- */
232
- value: number;
233
- /**
234
- * - Whether value is a percentage
235
- */
236
- isPercentage?: boolean;
237
- };
238
- export type DeductionInput = {
239
- /**
240
- * - Type of deduction
241
- */
242
- type: string;
243
- /**
244
- * - Display name for the deduction
245
- */
246
- name?: string;
247
- /**
248
- * - Deduction value (amount or percentage)
249
- */
250
- value: number;
251
- /**
252
- * - Whether value is a percentage
253
- */
254
- isPercentage?: boolean;
255
- };
256
- export type PeriodInput = {
257
- /**
258
- * - Month (1-12)
259
- */
260
- month?: number;
261
- /**
262
- * - Year
263
- */
264
- year?: number;
265
- };
266
- export type PayrollMetadata = {
267
- /**
268
- * - Currency code
269
- */
270
- currency?: string;
271
- /**
272
- * - Payment method
273
- */
274
- paymentMethod?: string;
275
- /**
276
- * - Additional notes
277
- */
278
- notes?: string;
279
- };
280
- export type PayrollRecord = {
281
- /**
282
- * - Employee identifier
283
- */
284
- employeeId: string;
285
- /**
286
- * - Organization identifier
287
- */
288
- organizationId: string;
289
- /**
290
- * - Pay period information
291
- */
292
- period: any;
293
- /**
294
- * - Salary breakdown
295
- */
296
- breakdown: {
297
- baseAmount: number;
298
- allowances: any[];
299
- deductions: any[];
300
- grossSalary: number;
301
- netSalary: number;
302
- };
303
- /**
304
- * - Payroll status ('pending', 'processed', 'paid')
305
- */
306
- status: string;
307
- /**
308
- * - When payroll was processed
309
- */
310
- processedAt: Date | null;
311
- /**
312
- * - When payment was made
313
- */
314
- paidAt: Date | null;
315
- /**
316
- * - Additional metadata
317
- */
318
- metadata: PayrollMetadata;
319
- };
@@ -1,47 +0,0 @@
1
- export const hrmOrchestrator: HRMOrchestrator;
2
- export const hrm: HRMOrchestrator;
3
- export default hrm;
4
- declare class HRMOrchestrator {
5
- _models: {
6
- EmployeeModel: any;
7
- PayrollRecordModel: any;
8
- TransactionModel: any;
9
- AttendanceModel: any;
10
- };
11
- _initialized: boolean;
12
- configure({ EmployeeModel, PayrollRecordModel, TransactionModel, AttendanceModel }: {
13
- EmployeeModel: any;
14
- PayrollRecordModel: any;
15
- TransactionModel: any;
16
- AttendanceModel?: any;
17
- }): void;
18
- _ensureInitialized(): void;
19
- isInitialized(): boolean;
20
- hire(params: any): Promise<any>;
21
- updateEmployment(params: any): Promise<any>;
22
- terminate(params: any): Promise<any>;
23
- reHire(params: any): Promise<any>;
24
- listEmployees(params: any): Promise<any>;
25
- getEmployee(params: any): Promise<any>;
26
- updateSalary(params: any): Promise<any>;
27
- addAllowance(params: any): Promise<any>;
28
- removeAllowance(params: any): Promise<any>;
29
- addDeduction(params: any): Promise<any>;
30
- removeDeduction(params: any): Promise<any>;
31
- updateBankDetails(params: any): Promise<any>;
32
- processSalary(params: any): Promise<{
33
- payrollRecord: any;
34
- transaction: any;
35
- employee: any;
36
- }>;
37
- processBulkPayroll(params: any): Promise<{
38
- successful: any[];
39
- failed: any[];
40
- total: any;
41
- }>;
42
- payrollHistory(params: any): Promise<any>;
43
- payrollSummary(params: any): Promise<any>;
44
- exportPayroll(params: any): Promise<any>;
45
- getEmployeeModel(): any;
46
- getPayrollRecordModel(): any;
47
- }
@@ -1,20 +0,0 @@
1
- export { setLogger } from "./utils/logger.js";
2
- export { employeePlugin } from "./plugins/employee.plugin.js";
3
- export { default as PayrollRecord } from "./models/payroll-record.model.js";
4
- export default hrmDefault;
5
- import { hrm as hrmDefault } from './hrm.orchestrator.js';
6
- export { initializeHRM, isInitialized } from "./init.js";
7
- export { EMPLOYMENT_TYPE, EMPLOYMENT_TYPE_VALUES, EMPLOYEE_STATUS, EMPLOYEE_STATUS_VALUES, DEPARTMENT, DEPARTMENT_VALUES, PAYMENT_FREQUENCY, PAYMENT_FREQUENCY_VALUES, PAYMENT_METHOD, PAYMENT_METHOD_VALUES, ALLOWANCE_TYPE, ALLOWANCE_TYPE_VALUES, DEDUCTION_TYPE, DEDUCTION_TYPE_VALUES, PAYROLL_STATUS, PAYROLL_STATUS_VALUES, TERMINATION_REASON, TERMINATION_REASON_VALUES, HRM_TRANSACTION_CATEGORIES, HRM_CATEGORY_VALUES, isHRMManagedCategory } from "./enums.js";
8
- export { HRM_CONFIG, SALARY_BANDS, TAX_BRACKETS, ORG_ROLES, ORG_ROLE_KEYS, ROLE_MAPPING, calculateTax, getSalaryBand, determineOrgRole } from "./config.js";
9
- export { employmentFields, allowanceSchema, deductionSchema, compensationSchema, workScheduleSchema, bankDetailsSchema, employmentHistorySchema, payrollStatsSchema } from "./schemas/employment.schema.js";
10
- export { hrm, hrmOrchestrator } from "./hrm.orchestrator.js";
11
- export { addDays, addMonths, diffInDays, diffInMonths, startOfMonth, endOfMonth, startOfYear, endOfYear, isWeekday, isWeekend, getPayPeriod, getCurrentPeriod, calculateProbationEnd, formatDateForDB, parseDBDate } from "./utils/date.utils.js";
12
- export { sum, sumBy, sumAllowances, sumDeductions, calculateGross, calculateNet, applyPercentage, calculatePercentage, createAllowanceCalculator, createDeductionCalculator, calculateTotalCompensation, pipe, compose } from "./utils/calculation.utils.js";
13
- export { isActive, isOnLeave, isSuspended, isTerminated, isEmployed, canReceiveSalary, hasCompensation, required, minValue, maxValue, isInRange, isPositive, isValidStatus, isValidEmploymentType, compose as composeValidators } from "./utils/validation.utils.js";
14
- export { QueryBuilder, EmployeeQueryBuilder, PayrollQueryBuilder, employee, payroll, toObjectId } from "./utils/query-builders.js";
15
- export { EmployeeFactory, EmployeeBuilder, createEmployee } from "./factories/employee.factory.js";
16
- export { PayrollFactory, PayrollBuilder, BatchPayrollFactory, createPayroll } from "./factories/payroll.factory.js";
17
- export { CompensationFactory, CompensationBuilder, CompensationPresets, createCompensation } from "./factories/compensation.factory.js";
18
- export { EmployeeService, createEmployeeService } from "./services/employee.service.js";
19
- export { PayrollService, createPayrollService } from "./services/payroll.service.js";
20
- export { CompensationService, createCompensationService } from "./services/compensation.service.js";
@@ -1,30 +0,0 @@
1
- /**
2
- * Initialize HRM/Payroll framework
3
- *
4
- * @param {Object} options - Initialization options
5
- * @param {Model} options.EmployeeModel - Employee model (required)
6
- * @param {Model} options.PayrollRecordModel - Payroll record model (required)
7
- * @param {Model} options.TransactionModel - Transaction model (required)
8
- * @param {Model} options.AttendanceModel - Optional attendance model for integration
9
- * @param {Object} options.logger - Optional custom logger
10
- *
11
- * @example Multi-Tenant (default)
12
- * initializeHRM({
13
- * EmployeeModel,
14
- * PayrollRecordModel,
15
- * TransactionModel
16
- * });
17
- *
18
- * @example Single-Tenant
19
- * // For single-tenant apps, add organizationId with default value in your Employee schema:
20
- * // organizationId: { type: ObjectId, required: true, default: () => FIXED_ORG_ID }
21
- */
22
- export function initializeHRM({ EmployeeModel, PayrollRecordModel, TransactionModel, AttendanceModel, logger: customLogger }: {
23
- EmployeeModel: Model;
24
- PayrollRecordModel: Model;
25
- TransactionModel: Model;
26
- AttendanceModel: Model;
27
- logger: any;
28
- }): void;
29
- export function isInitialized(): boolean;
30
- export default initializeHRM;
@@ -1,3 +0,0 @@
1
- export default PayrollRecord;
2
- declare const PayrollRecord: mongoose.Model<any, {}, {}, {}, any, any, any>;
3
- import mongoose from 'mongoose';
@@ -1,2 +0,0 @@
1
- export function employeePlugin(schema: any, options?: {}): void;
2
- export default employeePlugin;