@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.
- package/README.md +168 -489
- package/dist/core/index.d.ts +480 -0
- package/dist/core/index.js +971 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index-CTjHlCzz.d.ts +721 -0
- package/dist/index.d.ts +967 -0
- package/dist/index.js +4352 -0
- package/dist/index.js.map +1 -0
- package/dist/payroll.d.ts +233 -0
- package/dist/payroll.js +2103 -0
- package/dist/payroll.js.map +1 -0
- package/dist/plugin-D9mOr3_d.d.ts +333 -0
- package/dist/schemas/index.d.ts +2869 -0
- package/dist/schemas/index.js +440 -0
- package/dist/schemas/index.js.map +1 -0
- package/dist/services/index.d.ts +3 -0
- package/dist/services/index.js +1696 -0
- package/dist/services/index.js.map +1 -0
- package/dist/types-BSYyX2KJ.d.ts +671 -0
- package/dist/utils/index.d.ts +873 -0
- package/dist/utils/index.js +1046 -0
- package/dist/utils/index.js.map +1 -0
- package/package.json +54 -37
- package/dist/types/config.d.ts +0 -162
- package/dist/types/core/compensation.manager.d.ts +0 -54
- package/dist/types/core/employment.manager.d.ts +0 -49
- package/dist/types/core/payroll.manager.d.ts +0 -60
- package/dist/types/enums.d.ts +0 -117
- package/dist/types/factories/compensation.factory.d.ts +0 -196
- package/dist/types/factories/employee.factory.d.ts +0 -149
- package/dist/types/factories/payroll.factory.d.ts +0 -319
- package/dist/types/hrm.orchestrator.d.ts +0 -47
- package/dist/types/index.d.ts +0 -20
- package/dist/types/init.d.ts +0 -30
- package/dist/types/models/payroll-record.model.d.ts +0 -3
- package/dist/types/plugins/employee.plugin.d.ts +0 -2
- package/dist/types/schemas/employment.schema.d.ts +0 -959
- package/dist/types/services/compensation.service.d.ts +0 -94
- package/dist/types/services/employee.service.d.ts +0 -28
- package/dist/types/services/payroll.service.d.ts +0 -30
- package/dist/types/utils/calculation.utils.d.ts +0 -26
- package/dist/types/utils/date.utils.d.ts +0 -35
- package/dist/types/utils/logger.d.ts +0 -12
- package/dist/types/utils/query-builders.d.ts +0 -83
- package/dist/types/utils/validation.utils.d.ts +0 -33
- package/payroll.d.ts +0 -241
- package/src/config.js +0 -177
- package/src/core/compensation.manager.js +0 -242
- package/src/core/employment.manager.js +0 -224
- package/src/core/payroll.manager.js +0 -499
- package/src/enums.js +0 -141
- package/src/factories/compensation.factory.js +0 -198
- package/src/factories/employee.factory.js +0 -173
- package/src/factories/payroll.factory.js +0 -413
- package/src/hrm.orchestrator.js +0 -139
- package/src/index.js +0 -172
- package/src/init.js +0 -62
- package/src/models/payroll-record.model.js +0 -126
- package/src/plugins/employee.plugin.js +0 -164
- package/src/schemas/employment.schema.js +0 -126
- package/src/services/compensation.service.js +0 -231
- package/src/services/employee.service.js +0 -162
- package/src/services/payroll.service.js +0 -213
- package/src/utils/calculation.utils.js +0 -91
- package/src/utils/date.utils.js +0 -120
- package/src/utils/logger.js +0 -36
- package/src/utils/query-builders.js +0 -185
- package/src/utils/validation.utils.js +0 -122
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Compensation Factory - Clean Compensation Structure Creation
|
|
3
|
-
* Beautiful, testable compensation management
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { calculateGross, calculateNet } from '../utils/calculation.utils.js';
|
|
7
|
-
|
|
8
|
-
export class CompensationFactory {
|
|
9
|
-
static create({
|
|
10
|
-
baseAmount,
|
|
11
|
-
frequency = 'monthly',
|
|
12
|
-
currency = 'BDT',
|
|
13
|
-
allowances = [],
|
|
14
|
-
deductions = [],
|
|
15
|
-
effectiveFrom = new Date(),
|
|
16
|
-
}) {
|
|
17
|
-
return {
|
|
18
|
-
baseAmount,
|
|
19
|
-
frequency,
|
|
20
|
-
currency,
|
|
21
|
-
allowances: allowances.map(this.createAllowance),
|
|
22
|
-
deductions: deductions.map(this.createDeduction),
|
|
23
|
-
effectiveFrom,
|
|
24
|
-
lastUpdated: new Date(),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
static createAllowance({ type, name, value, isPercentage = false }) {
|
|
29
|
-
return {
|
|
30
|
-
type,
|
|
31
|
-
name: name || type,
|
|
32
|
-
value,
|
|
33
|
-
isPercentage,
|
|
34
|
-
};
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
static createDeduction({ type, name, value, isPercentage = false }) {
|
|
38
|
-
return {
|
|
39
|
-
type,
|
|
40
|
-
name: name || type,
|
|
41
|
-
value,
|
|
42
|
-
isPercentage,
|
|
43
|
-
};
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
static updateBaseAmount(compensation, newAmount, effectiveFrom = new Date()) {
|
|
47
|
-
return {
|
|
48
|
-
...compensation,
|
|
49
|
-
baseAmount: newAmount,
|
|
50
|
-
lastUpdated: effectiveFrom,
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
static addAllowance(compensation, allowance) {
|
|
55
|
-
return {
|
|
56
|
-
...compensation,
|
|
57
|
-
allowances: [...compensation.allowances, this.createAllowance(allowance)],
|
|
58
|
-
lastUpdated: new Date(),
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
static removeAllowance(compensation, allowanceType) {
|
|
63
|
-
return {
|
|
64
|
-
...compensation,
|
|
65
|
-
allowances: compensation.allowances.filter((a) => a.type !== allowanceType),
|
|
66
|
-
lastUpdated: new Date(),
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
static addDeduction(compensation, deduction) {
|
|
71
|
-
return {
|
|
72
|
-
...compensation,
|
|
73
|
-
deductions: [...compensation.deductions, this.createDeduction(deduction)],
|
|
74
|
-
lastUpdated: new Date(),
|
|
75
|
-
};
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
static removeDeduction(compensation, deductionType) {
|
|
79
|
-
return {
|
|
80
|
-
...compensation,
|
|
81
|
-
deductions: compensation.deductions.filter((d) => d.type !== deductionType),
|
|
82
|
-
lastUpdated: new Date(),
|
|
83
|
-
};
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
static calculateBreakdown(compensation) {
|
|
87
|
-
const { baseAmount, allowances, deductions } = compensation;
|
|
88
|
-
|
|
89
|
-
const calculatedAllowances = allowances.map((a) => ({
|
|
90
|
-
...a,
|
|
91
|
-
amount: a.isPercentage ? (baseAmount * a.value) / 100 : a.value,
|
|
92
|
-
}));
|
|
93
|
-
|
|
94
|
-
const calculatedDeductions = deductions.map((d) => ({
|
|
95
|
-
...d,
|
|
96
|
-
amount: d.isPercentage ? (baseAmount * d.value) / 100 : d.value,
|
|
97
|
-
}));
|
|
98
|
-
|
|
99
|
-
const gross = calculateGross(baseAmount, calculatedAllowances);
|
|
100
|
-
const net = calculateNet(gross, calculatedDeductions);
|
|
101
|
-
|
|
102
|
-
return {
|
|
103
|
-
baseAmount,
|
|
104
|
-
allowances: calculatedAllowances,
|
|
105
|
-
deductions: calculatedDeductions,
|
|
106
|
-
grossAmount: gross,
|
|
107
|
-
netAmount: net,
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
static applyIncrement(compensation, { percentage, amount, effectiveFrom = new Date() }) {
|
|
112
|
-
const newBaseAmount = amount
|
|
113
|
-
? compensation.baseAmount + amount
|
|
114
|
-
: compensation.baseAmount * (1 + percentage / 100);
|
|
115
|
-
|
|
116
|
-
return this.updateBaseAmount(compensation, Math.round(newBaseAmount), effectiveFrom);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export class CompensationBuilder {
|
|
121
|
-
constructor() {
|
|
122
|
-
this.data = {
|
|
123
|
-
allowances: [],
|
|
124
|
-
deductions: [],
|
|
125
|
-
frequency: 'monthly',
|
|
126
|
-
currency: 'BDT',
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
withBase(amount, frequency = 'monthly', currency = 'BDT') {
|
|
131
|
-
this.data.baseAmount = amount;
|
|
132
|
-
this.data.frequency = frequency;
|
|
133
|
-
this.data.currency = currency;
|
|
134
|
-
return this;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
addAllowance(type, value, isPercentage = false, name = null) {
|
|
138
|
-
this.data.allowances.push({ type, value, isPercentage, name });
|
|
139
|
-
return this;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
addDeduction(type, value, isPercentage = false, name = null) {
|
|
143
|
-
this.data.deductions.push({ type, value, isPercentage, name });
|
|
144
|
-
return this;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
effectiveFrom(date) {
|
|
148
|
-
this.data.effectiveFrom = date;
|
|
149
|
-
return this;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
build() {
|
|
153
|
-
return CompensationFactory.create(this.data);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
export const createCompensation = () => new CompensationBuilder();
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Standard Compensation Presets
|
|
161
|
-
*/
|
|
162
|
-
export const CompensationPresets = {
|
|
163
|
-
basic(baseAmount) {
|
|
164
|
-
return createCompensation().withBase(baseAmount).build();
|
|
165
|
-
},
|
|
166
|
-
|
|
167
|
-
withHouseRent(baseAmount, rentPercentage = 50) {
|
|
168
|
-
return createCompensation()
|
|
169
|
-
.withBase(baseAmount)
|
|
170
|
-
.addAllowance('house_rent', rentPercentage, true, 'House Rent')
|
|
171
|
-
.build();
|
|
172
|
-
},
|
|
173
|
-
|
|
174
|
-
withMedical(baseAmount, medicalPercentage = 10) {
|
|
175
|
-
return createCompensation()
|
|
176
|
-
.withBase(baseAmount)
|
|
177
|
-
.addAllowance('medical', medicalPercentage, true, 'Medical Allowance')
|
|
178
|
-
.build();
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
standard(baseAmount) {
|
|
182
|
-
return createCompensation()
|
|
183
|
-
.withBase(baseAmount)
|
|
184
|
-
.addAllowance('house_rent', 50, true, 'House Rent')
|
|
185
|
-
.addAllowance('medical', 10, true, 'Medical Allowance')
|
|
186
|
-
.addAllowance('transport', 5, true, 'Transport Allowance')
|
|
187
|
-
.build();
|
|
188
|
-
},
|
|
189
|
-
|
|
190
|
-
withProvidentFund(baseAmount, pfPercentage = 10) {
|
|
191
|
-
return createCompensation()
|
|
192
|
-
.withBase(baseAmount)
|
|
193
|
-
.addAllowance('house_rent', 50, true, 'House Rent')
|
|
194
|
-
.addAllowance('medical', 10, true, 'Medical Allowance')
|
|
195
|
-
.addDeduction('provident_fund', pfPercentage, true, 'Provident Fund')
|
|
196
|
-
.build();
|
|
197
|
-
},
|
|
198
|
-
};
|
|
@@ -1,173 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Employee Factory - Clean Object Creation
|
|
3
|
-
* Beautiful, testable, immutable object creation
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { calculateProbationEnd } from '../utils/date.utils.js';
|
|
7
|
-
|
|
8
|
-
export class EmployeeFactory {
|
|
9
|
-
static create({
|
|
10
|
-
userId,
|
|
11
|
-
organizationId,
|
|
12
|
-
employment = {},
|
|
13
|
-
compensation = {},
|
|
14
|
-
bankDetails = {},
|
|
15
|
-
}) {
|
|
16
|
-
const hireDate = employment.hireDate || new Date();
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
userId,
|
|
20
|
-
organizationId,
|
|
21
|
-
employeeId: employment.employeeId,
|
|
22
|
-
employmentType: employment.type || 'full_time',
|
|
23
|
-
status: 'active',
|
|
24
|
-
department: employment.department,
|
|
25
|
-
position: employment.position,
|
|
26
|
-
hireDate,
|
|
27
|
-
probationEndDate: calculateProbationEnd(hireDate, employment.probationMonths),
|
|
28
|
-
compensation: this.createCompensation(compensation),
|
|
29
|
-
workSchedule: employment.workSchedule || this.defaultWorkSchedule(),
|
|
30
|
-
bankDetails: bankDetails || {},
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
static createCompensation({
|
|
35
|
-
baseAmount,
|
|
36
|
-
frequency = 'monthly',
|
|
37
|
-
currency = 'BDT',
|
|
38
|
-
allowances = [],
|
|
39
|
-
deductions = [],
|
|
40
|
-
}) {
|
|
41
|
-
return {
|
|
42
|
-
baseAmount,
|
|
43
|
-
frequency,
|
|
44
|
-
currency,
|
|
45
|
-
allowances: allowances.map(this.createAllowance),
|
|
46
|
-
deductions: deductions.map(this.createDeduction),
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
static createAllowance({ type, name, amount, isPercentage = false }) {
|
|
51
|
-
return {
|
|
52
|
-
type,
|
|
53
|
-
name: name || type,
|
|
54
|
-
amount,
|
|
55
|
-
isPercentage,
|
|
56
|
-
};
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
static createDeduction({ type, name, amount, isPercentage = false }) {
|
|
60
|
-
return {
|
|
61
|
-
type,
|
|
62
|
-
name: name || type,
|
|
63
|
-
amount,
|
|
64
|
-
isPercentage,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
static defaultWorkSchedule() {
|
|
69
|
-
return {
|
|
70
|
-
hoursPerWeek: 40,
|
|
71
|
-
daysPerWeek: 5,
|
|
72
|
-
workDays: ['monday', 'tuesday', 'wednesday', 'thursday', 'friday'],
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
static createTermination({ reason, date = new Date(), notes, context = {} }) {
|
|
77
|
-
return {
|
|
78
|
-
terminatedAt: date,
|
|
79
|
-
terminationReason: reason,
|
|
80
|
-
terminationNotes: notes,
|
|
81
|
-
terminatedBy: {
|
|
82
|
-
userId: context.userId,
|
|
83
|
-
name: context.userName,
|
|
84
|
-
role: context.userRole,
|
|
85
|
-
},
|
|
86
|
-
};
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export class EmployeeBuilder {
|
|
91
|
-
constructor() {
|
|
92
|
-
this.data = {};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
forUser(userId) {
|
|
96
|
-
this.data.userId = userId;
|
|
97
|
-
return this;
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
inOrganization(organizationId) {
|
|
101
|
-
this.data.organizationId = organizationId;
|
|
102
|
-
return this;
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
withEmployeeId(employeeId) {
|
|
106
|
-
this.data.employment = { ...this.data.employment, employeeId };
|
|
107
|
-
return this;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
asDepartment(department) {
|
|
111
|
-
this.data.employment = { ...this.data.employment, department };
|
|
112
|
-
return this;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
asPosition(position) {
|
|
116
|
-
this.data.employment = { ...this.data.employment, position };
|
|
117
|
-
return this;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
withEmploymentType(type) {
|
|
121
|
-
this.data.employment = { ...this.data.employment, type };
|
|
122
|
-
return this;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
hiredOn(date) {
|
|
126
|
-
this.data.employment = { ...this.data.employment, hireDate: date };
|
|
127
|
-
return this;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
withProbation(months) {
|
|
131
|
-
this.data.employment = { ...this.data.employment, probationMonths: months };
|
|
132
|
-
return this;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
withBaseSalary(amount, frequency = 'monthly', currency = 'BDT') {
|
|
136
|
-
this.data.compensation = {
|
|
137
|
-
...this.data.compensation,
|
|
138
|
-
baseAmount: amount,
|
|
139
|
-
frequency,
|
|
140
|
-
currency,
|
|
141
|
-
};
|
|
142
|
-
return this;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
addAllowance(type, amount, name) {
|
|
146
|
-
const allowances = this.data.compensation?.allowances || [];
|
|
147
|
-
this.data.compensation = {
|
|
148
|
-
...this.data.compensation,
|
|
149
|
-
allowances: [...allowances, { type, amount, name }],
|
|
150
|
-
};
|
|
151
|
-
return this;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
addDeduction(type, amount, name) {
|
|
155
|
-
const deductions = this.data.compensation?.deductions || [];
|
|
156
|
-
this.data.compensation = {
|
|
157
|
-
...this.data.compensation,
|
|
158
|
-
deductions: [...deductions, { type, amount, name }],
|
|
159
|
-
};
|
|
160
|
-
return this;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
withBankDetails(bankDetails) {
|
|
164
|
-
this.data.bankDetails = bankDetails;
|
|
165
|
-
return this;
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
build() {
|
|
169
|
-
return EmployeeFactory.create(this.data);
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
export const createEmployee = () => new EmployeeBuilder();
|