@managesome/eposmatic-toolkit 0.4.19 → 0.4.21
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/esm/constants/enums/hr.js +6 -0
- package/esm/schemas/models/tenant_hr_attendance_records.js +33 -19
- package/lib/constants/enums/hr.d.ts +5 -0
- package/lib/constants/enums/hr.js +7 -1
- package/lib/helpers/order/payment-collection.d.ts +25 -0
- package/lib/helpers/order/payment-collection.js +51 -0
- package/lib/schemas/models/tenant_hr_attendance_records.d.ts +48 -18
- package/lib/schemas/models/tenant_hr_attendance_records.js +32 -18
- package/lib/schemas/types/tenant_hr_attendance_records.d.ts +10 -7
- package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
- package/lib/tests/payment-collection-timestamps.test.js +71 -0
- package/package.json +1 -1
|
@@ -24,6 +24,12 @@ export var HR_CHECK_IN_METHOD_ENUM;
|
|
|
24
24
|
HR_CHECK_IN_METHOD_ENUM["QR"] = "QR";
|
|
25
25
|
})(HR_CHECK_IN_METHOD_ENUM || (HR_CHECK_IN_METHOD_ENUM = {}));
|
|
26
26
|
export const ALL_HR_CHECK_IN_METHOD_NAMES = Object.values(HR_CHECK_IN_METHOD_ENUM);
|
|
27
|
+
export var HR_CLOCK_TIME_TYPE_ENUM;
|
|
28
|
+
(function (HR_CLOCK_TIME_TYPE_ENUM) {
|
|
29
|
+
HR_CLOCK_TIME_TYPE_ENUM["CHECK_IN"] = "CHECK_IN";
|
|
30
|
+
HR_CLOCK_TIME_TYPE_ENUM["CHECK_OUT"] = "CHECK_OUT";
|
|
31
|
+
})(HR_CLOCK_TIME_TYPE_ENUM || (HR_CLOCK_TIME_TYPE_ENUM = {}));
|
|
32
|
+
export const ALL_HR_CLOCK_TIME_TYPE_NAMES = Object.values(HR_CLOCK_TIME_TYPE_ENUM);
|
|
27
33
|
export var HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM;
|
|
28
34
|
(function (HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM) {
|
|
29
35
|
HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM["FINGERPRINT"] = "FINGERPRINT";
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
import { Schema } from 'mongoose';
|
|
2
|
-
import { ALL_HR_ATTENDANCE_STATUS_NAMES, ALL_HR_CHECK_IN_METHOD_NAMES, HR_ATTENDANCE_STATUS_ENUM, } from '../../constants';
|
|
2
|
+
import { ALL_HR_ATTENDANCE_STATUS_NAMES, ALL_HR_CHECK_IN_METHOD_NAMES, ALL_HR_CLOCK_TIME_TYPE_NAMES, HR_ATTENDANCE_STATUS_ENUM, } from '../../constants';
|
|
3
3
|
const hrBreakTimeSchema = new Schema({
|
|
4
4
|
start_time: {
|
|
5
5
|
type: Number,
|
|
6
6
|
required: true,
|
|
7
|
+
min: 0,
|
|
8
|
+
max: 86399,
|
|
7
9
|
},
|
|
8
10
|
end_time: {
|
|
9
11
|
type: Number,
|
|
10
12
|
default: null,
|
|
13
|
+
min: 0,
|
|
14
|
+
max: 86399,
|
|
15
|
+
},
|
|
16
|
+
}, { _id: false, minimize: false });
|
|
17
|
+
const hrClockTimeSchema = new Schema({
|
|
18
|
+
type: {
|
|
19
|
+
type: String,
|
|
20
|
+
required: true,
|
|
21
|
+
enum: ALL_HR_CLOCK_TIME_TYPE_NAMES,
|
|
22
|
+
},
|
|
23
|
+
time: {
|
|
24
|
+
type: Number,
|
|
25
|
+
required: true,
|
|
26
|
+
min: 0,
|
|
27
|
+
},
|
|
28
|
+
method: {
|
|
29
|
+
type: String,
|
|
30
|
+
enum: ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
31
|
+
default: null,
|
|
11
32
|
},
|
|
12
33
|
}, { _id: false, minimize: false });
|
|
13
34
|
export const TenantHrAttendanceRecordSchema = new Schema({
|
|
@@ -28,23 +49,24 @@ export const TenantHrAttendanceRecordSchema = new Schema({
|
|
|
28
49
|
immutable: true,
|
|
29
50
|
ref: 'tenant_hr_employees',
|
|
30
51
|
},
|
|
31
|
-
|
|
32
|
-
type:
|
|
33
|
-
|
|
52
|
+
attendance_date: {
|
|
53
|
+
type: String,
|
|
54
|
+
required: true,
|
|
55
|
+
match: /^\d{4}-\d{2}-\d{2}$/,
|
|
34
56
|
},
|
|
35
|
-
|
|
36
|
-
type:
|
|
37
|
-
default:
|
|
57
|
+
clock_time: {
|
|
58
|
+
type: [hrClockTimeSchema],
|
|
59
|
+
default: [],
|
|
38
60
|
},
|
|
39
61
|
break_time: {
|
|
40
62
|
type: [hrBreakTimeSchema],
|
|
41
63
|
default: [],
|
|
42
64
|
},
|
|
43
|
-
|
|
65
|
+
total_break_time: {
|
|
44
66
|
type: Number,
|
|
45
67
|
default: 0,
|
|
46
68
|
},
|
|
47
|
-
|
|
69
|
+
total_worked_time: {
|
|
48
70
|
type: Number,
|
|
49
71
|
default: 0,
|
|
50
72
|
},
|
|
@@ -54,16 +76,6 @@ export const TenantHrAttendanceRecordSchema = new Schema({
|
|
|
54
76
|
enum: ALL_HR_ATTENDANCE_STATUS_NAMES,
|
|
55
77
|
default: HR_ATTENDANCE_STATUS_ENUM.PRESENT,
|
|
56
78
|
},
|
|
57
|
-
check_in_method: {
|
|
58
|
-
type: String,
|
|
59
|
-
enum: ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
60
|
-
default: null,
|
|
61
|
-
},
|
|
62
|
-
check_out_method: {
|
|
63
|
-
type: String,
|
|
64
|
-
enum: ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
65
|
-
default: null,
|
|
66
|
-
},
|
|
67
79
|
notes: {
|
|
68
80
|
type: String,
|
|
69
81
|
default: null,
|
|
@@ -84,4 +96,6 @@ export const TenantHrAttendanceRecordSchema = new Schema({
|
|
|
84
96
|
versionKey: false,
|
|
85
97
|
minimize: false,
|
|
86
98
|
});
|
|
99
|
+
TenantHrAttendanceRecordSchema.index({ tenant_id: 1, employee_id: 1, attendance_date: 1 }, { unique: true });
|
|
100
|
+
TenantHrAttendanceRecordSchema.index({ tenant_id: 1, attendance_date: 1 });
|
|
87
101
|
export const TENANT_HR_ATTENDANCE_RECORDS_COLLECTION_NAME = 'tenant_hr_attendance_records';
|
|
@@ -20,6 +20,11 @@ export declare enum HR_CHECK_IN_METHOD_ENUM {
|
|
|
20
20
|
QR = "QR"
|
|
21
21
|
}
|
|
22
22
|
export declare const ALL_HR_CHECK_IN_METHOD_NAMES: HR_CHECK_IN_METHOD_ENUM[];
|
|
23
|
+
export declare enum HR_CLOCK_TIME_TYPE_ENUM {
|
|
24
|
+
CHECK_IN = "CHECK_IN",
|
|
25
|
+
CHECK_OUT = "CHECK_OUT"
|
|
26
|
+
}
|
|
27
|
+
export declare const ALL_HR_CLOCK_TIME_TYPE_NAMES: HR_CLOCK_TIME_TYPE_ENUM[];
|
|
23
28
|
export declare enum HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM {
|
|
24
29
|
FINGERPRINT = "FINGERPRINT",
|
|
25
30
|
FACE = "FACE"
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
// Auto-split from constants/ENUMS.ts — see ENUMS.ts barrel for exports.
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.ALL_HR_REVIEW_TYPE_NAMES = exports.HR_REVIEW_TYPE_ENUM = exports.DEFAULT_HR_LEAVE_ALLOWANCE = exports.ALL_HR_LEAVE_STATUS_NAMES = exports.HR_LEAVE_STATUS_ENUM = exports.ALL_HR_LEAVE_TYPE_NAMES = exports.HR_LEAVE_TYPE_ENUM = exports.ALL_HR_POLICY_STATUS_NAMES = exports.HR_POLICY_STATUS_ENUM = exports.ALL_HR_DOCUMENT_STATUS_NAMES = exports.HR_DOCUMENT_STATUS_ENUM = exports.ALL_HR_DOCUMENT_TYPE_NAMES = exports.HR_DOCUMENT_TYPE_ENUM = exports.ALL_HR_PAYMENT_METHOD_NAMES = exports.HR_PAYMENT_METHOD_ENUM = exports.ALL_HR_PAYROLL_STATUS_NAMES = exports.HR_PAYROLL_STATUS_ENUM = exports.ALL_HR_PAY_TYPE_NAMES = exports.HR_PAY_TYPE_ENUM = exports.ALL_HR_EMPLOYEE_DOCUMENT_TYPES = exports.HR_EMPLOYEE_DOCUMENT_TYPE_ENUM = exports.ALL_HR_SHIFT_STATUS_NAMES = exports.HR_SHIFT_STATUS_ENUM = exports.ALL_HR_SHIFT_TYPE_NAMES = exports.HR_SHIFT_TYPE_ENUM = exports.ALL_HR_BIOMETRIC_ENROLLMENT_TYPE_NAMES = exports.HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM = exports.ALL_HR_CHECK_IN_METHOD_NAMES = exports.HR_CHECK_IN_METHOD_ENUM = exports.ALL_HR_ATTENDANCE_STATUS_NAMES = exports.HR_ATTENDANCE_STATUS_ENUM = exports.ALL_HR_EMPLOYMENT_STATUS_NAMES = exports.HR_EMPLOYMENT_STATUS_ENUM = void 0;
|
|
4
|
+
exports.ALL_HR_REVIEW_TYPE_NAMES = exports.HR_REVIEW_TYPE_ENUM = exports.DEFAULT_HR_LEAVE_ALLOWANCE = exports.ALL_HR_LEAVE_STATUS_NAMES = exports.HR_LEAVE_STATUS_ENUM = exports.ALL_HR_LEAVE_TYPE_NAMES = exports.HR_LEAVE_TYPE_ENUM = exports.ALL_HR_POLICY_STATUS_NAMES = exports.HR_POLICY_STATUS_ENUM = exports.ALL_HR_DOCUMENT_STATUS_NAMES = exports.HR_DOCUMENT_STATUS_ENUM = exports.ALL_HR_DOCUMENT_TYPE_NAMES = exports.HR_DOCUMENT_TYPE_ENUM = exports.ALL_HR_PAYMENT_METHOD_NAMES = exports.HR_PAYMENT_METHOD_ENUM = exports.ALL_HR_PAYROLL_STATUS_NAMES = exports.HR_PAYROLL_STATUS_ENUM = exports.ALL_HR_PAY_TYPE_NAMES = exports.HR_PAY_TYPE_ENUM = exports.ALL_HR_EMPLOYEE_DOCUMENT_TYPES = exports.HR_EMPLOYEE_DOCUMENT_TYPE_ENUM = exports.ALL_HR_SHIFT_STATUS_NAMES = exports.HR_SHIFT_STATUS_ENUM = exports.ALL_HR_SHIFT_TYPE_NAMES = exports.HR_SHIFT_TYPE_ENUM = exports.ALL_HR_BIOMETRIC_ENROLLMENT_TYPE_NAMES = exports.HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM = exports.ALL_HR_CLOCK_TIME_TYPE_NAMES = exports.HR_CLOCK_TIME_TYPE_ENUM = exports.ALL_HR_CHECK_IN_METHOD_NAMES = exports.HR_CHECK_IN_METHOD_ENUM = exports.ALL_HR_ATTENDANCE_STATUS_NAMES = exports.HR_ATTENDANCE_STATUS_ENUM = exports.ALL_HR_EMPLOYMENT_STATUS_NAMES = exports.HR_EMPLOYMENT_STATUS_ENUM = void 0;
|
|
5
5
|
var HR_EMPLOYMENT_STATUS_ENUM;
|
|
6
6
|
(function (HR_EMPLOYMENT_STATUS_ENUM) {
|
|
7
7
|
HR_EMPLOYMENT_STATUS_ENUM["ACTIVE"] = "ACTIVE";
|
|
@@ -27,6 +27,12 @@ var HR_CHECK_IN_METHOD_ENUM;
|
|
|
27
27
|
HR_CHECK_IN_METHOD_ENUM["QR"] = "QR";
|
|
28
28
|
})(HR_CHECK_IN_METHOD_ENUM || (exports.HR_CHECK_IN_METHOD_ENUM = HR_CHECK_IN_METHOD_ENUM = {}));
|
|
29
29
|
exports.ALL_HR_CHECK_IN_METHOD_NAMES = Object.values(HR_CHECK_IN_METHOD_ENUM);
|
|
30
|
+
var HR_CLOCK_TIME_TYPE_ENUM;
|
|
31
|
+
(function (HR_CLOCK_TIME_TYPE_ENUM) {
|
|
32
|
+
HR_CLOCK_TIME_TYPE_ENUM["CHECK_IN"] = "CHECK_IN";
|
|
33
|
+
HR_CLOCK_TIME_TYPE_ENUM["CHECK_OUT"] = "CHECK_OUT";
|
|
34
|
+
})(HR_CLOCK_TIME_TYPE_ENUM || (exports.HR_CLOCK_TIME_TYPE_ENUM = HR_CLOCK_TIME_TYPE_ENUM = {}));
|
|
35
|
+
exports.ALL_HR_CLOCK_TIME_TYPE_NAMES = Object.values(HR_CLOCK_TIME_TYPE_ENUM);
|
|
30
36
|
var HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM;
|
|
31
37
|
(function (HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM) {
|
|
32
38
|
HR_BIOMETRIC_ENROLLMENT_TYPE_ENUM["FINGERPRINT"] = "FINGERPRINT";
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { IOrderPayment } from '../../schemas/types/orders';
|
|
2
|
+
/**
|
|
3
|
+
* Server-owned `collected_at` stamping for order payments.
|
|
4
|
+
*
|
|
5
|
+
* A payment line is the unit a credit bill lives on: the sale is issued on the
|
|
6
|
+
* punch day, and money may arrive later (full or partial). `order_settled_at`
|
|
7
|
+
* only moves on FULL settlement, so it cannot anchor a partial collection.
|
|
8
|
+
* This helper records the LAST collection moment on the payment itself,
|
|
9
|
+
* derived by comparing `amount_paid` with the stored previous version.
|
|
10
|
+
*
|
|
11
|
+
* Rules:
|
|
12
|
+
* - never trust the incoming `collected_at` (clients may send anything);
|
|
13
|
+
* - a NEW payment line with money in (`amount_paid > 0`) gets `now`;
|
|
14
|
+
* - an EXISTING line whose `amount_paid` increased gets `now`;
|
|
15
|
+
* - unchanged / decreased / zero-amount lines keep the stored timestamp
|
|
16
|
+
* (`null` when unknown — legacy rows are not backfilled here).
|
|
17
|
+
*
|
|
18
|
+
* Pure and never throws. `previousPayments` must be the SERVER copy of the
|
|
19
|
+
* order's payments before the write (pass none on create).
|
|
20
|
+
*/
|
|
21
|
+
export interface IStampPaymentCollectionTimestampsOptions {
|
|
22
|
+
/** Override for the collection instant (tests / offline replays). */
|
|
23
|
+
now?: Date | string | null;
|
|
24
|
+
}
|
|
25
|
+
export declare function stampPaymentCollectionTimestamps(payments: IOrderPayment[] | null | undefined, previousPayments?: IOrderPayment[] | null | undefined, options?: IStampPaymentCollectionTimestampsOptions): IOrderPayment[];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stampPaymentCollectionTimestamps = stampPaymentCollectionTimestamps;
|
|
4
|
+
const constants_1 = require("../../constants");
|
|
5
|
+
const toValidDate = (value) => {
|
|
6
|
+
if (value == null)
|
|
7
|
+
return null;
|
|
8
|
+
const date = value instanceof Date ? value : new Date(value);
|
|
9
|
+
return Number.isNaN(date.getTime()) ? null : date;
|
|
10
|
+
};
|
|
11
|
+
/** Stable identity across a merge: subdoc `_id` first, then `payment_id`. */
|
|
12
|
+
const identityOf = (payment) => {
|
|
13
|
+
if (payment._id != null && String(payment._id).trim() !== '') {
|
|
14
|
+
return `id:${String(payment._id)}`;
|
|
15
|
+
}
|
|
16
|
+
if (typeof payment.payment_id === 'string' && payment.payment_id.trim() !== '') {
|
|
17
|
+
return `payment:${payment.payment_id}`;
|
|
18
|
+
}
|
|
19
|
+
return null;
|
|
20
|
+
};
|
|
21
|
+
function stampPaymentCollectionTimestamps(payments, previousPayments = null, options = {}) {
|
|
22
|
+
if (!Array.isArray(payments))
|
|
23
|
+
return [];
|
|
24
|
+
const now = toValidDate(options.now) ?? new Date();
|
|
25
|
+
const previousByIdentity = new Map();
|
|
26
|
+
for (const previous of Array.isArray(previousPayments) ? previousPayments : []) {
|
|
27
|
+
if (previous == null)
|
|
28
|
+
continue;
|
|
29
|
+
const identity = identityOf(previous);
|
|
30
|
+
if (identity != null)
|
|
31
|
+
previousByIdentity.set(identity, previous);
|
|
32
|
+
}
|
|
33
|
+
return payments.map((payment) => {
|
|
34
|
+
if (payment == null)
|
|
35
|
+
return payment;
|
|
36
|
+
const identity = identityOf(payment);
|
|
37
|
+
const previous = identity != null ? previousByIdentity.get(identity) : undefined;
|
|
38
|
+
const previousCollectedAt = toValidDate(previous?.collected_at);
|
|
39
|
+
const amountPaid = Number(payment.amount_paid ?? 0);
|
|
40
|
+
const previousAmountPaid = Number(previous?.amount_paid ?? 0);
|
|
41
|
+
const isFailed = payment.payment_status === constants_1.PAYMENT_STATUS_ENUM.FAILED;
|
|
42
|
+
const isNewCollection = !isFailed &&
|
|
43
|
+
Number.isFinite(amountPaid) &&
|
|
44
|
+
amountPaid > 0 &&
|
|
45
|
+
(previous == null || amountPaid > previousAmountPaid);
|
|
46
|
+
return {
|
|
47
|
+
...payment,
|
|
48
|
+
collected_at: isNewCollection ? now : previousCollectedAt,
|
|
49
|
+
};
|
|
50
|
+
});
|
|
51
|
+
}
|
|
@@ -25,12 +25,22 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
25
25
|
start_time: number;
|
|
26
26
|
end_time: number;
|
|
27
27
|
}>;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
28
|
+
attendance_date: string;
|
|
29
|
+
clock_time: import("mongoose").Types.DocumentArray<{
|
|
30
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
31
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
32
|
+
time: number;
|
|
33
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
34
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
35
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
36
|
+
time: number;
|
|
37
|
+
}> & {
|
|
38
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
39
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
40
|
+
time: number;
|
|
41
|
+
}>;
|
|
42
|
+
total_break_time: number;
|
|
43
|
+
total_worked_time: number;
|
|
34
44
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
35
45
|
createdAt: NativeDate;
|
|
36
46
|
updatedAt: NativeDate;
|
|
@@ -52,12 +62,22 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
52
62
|
start_time: number;
|
|
53
63
|
end_time: number;
|
|
54
64
|
}>;
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
65
|
+
attendance_date: string;
|
|
66
|
+
clock_time: import("mongoose").Types.DocumentArray<{
|
|
67
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
68
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
69
|
+
time: number;
|
|
70
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
71
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
72
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
73
|
+
time: number;
|
|
74
|
+
}> & {
|
|
75
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
76
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
77
|
+
time: number;
|
|
78
|
+
}>;
|
|
79
|
+
total_break_time: number;
|
|
80
|
+
total_worked_time: number;
|
|
61
81
|
}>> & import("mongoose").FlatRecord<{
|
|
62
82
|
createdAt: NativeDate;
|
|
63
83
|
updatedAt: NativeDate;
|
|
@@ -79,12 +99,22 @@ export declare const TenantHrAttendanceRecordSchema: Schema<any, import("mongoos
|
|
|
79
99
|
start_time: number;
|
|
80
100
|
end_time: number;
|
|
81
101
|
}>;
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
102
|
+
attendance_date: string;
|
|
103
|
+
clock_time: import("mongoose").Types.DocumentArray<{
|
|
104
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
105
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
106
|
+
time: number;
|
|
107
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
108
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
109
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
110
|
+
time: number;
|
|
111
|
+
}> & {
|
|
112
|
+
type: import("../../constants").HR_CLOCK_TIME_TYPE_ENUM;
|
|
113
|
+
method: import("../../constants").HR_CHECK_IN_METHOD_ENUM;
|
|
114
|
+
time: number;
|
|
115
|
+
}>;
|
|
116
|
+
total_break_time: number;
|
|
117
|
+
total_worked_time: number;
|
|
88
118
|
}> & Required<{
|
|
89
119
|
_id: import("mongoose").Types.ObjectId;
|
|
90
120
|
}> & {
|
|
@@ -7,10 +7,31 @@ const hrBreakTimeSchema = new mongoose_1.Schema({
|
|
|
7
7
|
start_time: {
|
|
8
8
|
type: Number,
|
|
9
9
|
required: true,
|
|
10
|
+
min: 0,
|
|
11
|
+
max: 86399,
|
|
10
12
|
},
|
|
11
13
|
end_time: {
|
|
12
14
|
type: Number,
|
|
13
15
|
default: null,
|
|
16
|
+
min: 0,
|
|
17
|
+
max: 86399,
|
|
18
|
+
},
|
|
19
|
+
}, { _id: false, minimize: false });
|
|
20
|
+
const hrClockTimeSchema = new mongoose_1.Schema({
|
|
21
|
+
type: {
|
|
22
|
+
type: String,
|
|
23
|
+
required: true,
|
|
24
|
+
enum: constants_1.ALL_HR_CLOCK_TIME_TYPE_NAMES,
|
|
25
|
+
},
|
|
26
|
+
time: {
|
|
27
|
+
type: Number,
|
|
28
|
+
required: true,
|
|
29
|
+
min: 0,
|
|
30
|
+
},
|
|
31
|
+
method: {
|
|
32
|
+
type: String,
|
|
33
|
+
enum: constants_1.ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
34
|
+
default: null,
|
|
14
35
|
},
|
|
15
36
|
}, { _id: false, minimize: false });
|
|
16
37
|
exports.TenantHrAttendanceRecordSchema = new mongoose_1.Schema({
|
|
@@ -31,23 +52,24 @@ exports.TenantHrAttendanceRecordSchema = new mongoose_1.Schema({
|
|
|
31
52
|
immutable: true,
|
|
32
53
|
ref: 'tenant_hr_employees',
|
|
33
54
|
},
|
|
34
|
-
|
|
35
|
-
type:
|
|
36
|
-
|
|
55
|
+
attendance_date: {
|
|
56
|
+
type: String,
|
|
57
|
+
required: true,
|
|
58
|
+
match: /^\d{4}-\d{2}-\d{2}$/,
|
|
37
59
|
},
|
|
38
|
-
|
|
39
|
-
type:
|
|
40
|
-
default:
|
|
60
|
+
clock_time: {
|
|
61
|
+
type: [hrClockTimeSchema],
|
|
62
|
+
default: [],
|
|
41
63
|
},
|
|
42
64
|
break_time: {
|
|
43
65
|
type: [hrBreakTimeSchema],
|
|
44
66
|
default: [],
|
|
45
67
|
},
|
|
46
|
-
|
|
68
|
+
total_break_time: {
|
|
47
69
|
type: Number,
|
|
48
70
|
default: 0,
|
|
49
71
|
},
|
|
50
|
-
|
|
72
|
+
total_worked_time: {
|
|
51
73
|
type: Number,
|
|
52
74
|
default: 0,
|
|
53
75
|
},
|
|
@@ -57,16 +79,6 @@ exports.TenantHrAttendanceRecordSchema = new mongoose_1.Schema({
|
|
|
57
79
|
enum: constants_1.ALL_HR_ATTENDANCE_STATUS_NAMES,
|
|
58
80
|
default: constants_1.HR_ATTENDANCE_STATUS_ENUM.PRESENT,
|
|
59
81
|
},
|
|
60
|
-
check_in_method: {
|
|
61
|
-
type: String,
|
|
62
|
-
enum: constants_1.ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
63
|
-
default: null,
|
|
64
|
-
},
|
|
65
|
-
check_out_method: {
|
|
66
|
-
type: String,
|
|
67
|
-
enum: constants_1.ALL_HR_CHECK_IN_METHOD_NAMES,
|
|
68
|
-
default: null,
|
|
69
|
-
},
|
|
70
82
|
notes: {
|
|
71
83
|
type: String,
|
|
72
84
|
default: null,
|
|
@@ -87,4 +99,6 @@ exports.TenantHrAttendanceRecordSchema = new mongoose_1.Schema({
|
|
|
87
99
|
versionKey: false,
|
|
88
100
|
minimize: false,
|
|
89
101
|
});
|
|
102
|
+
exports.TenantHrAttendanceRecordSchema.index({ tenant_id: 1, employee_id: 1, attendance_date: 1 }, { unique: true });
|
|
103
|
+
exports.TenantHrAttendanceRecordSchema.index({ tenant_id: 1, attendance_date: 1 });
|
|
90
104
|
exports.TENANT_HR_ATTENDANCE_RECORDS_COLLECTION_NAME = 'tenant_hr_attendance_records';
|
|
@@ -1,20 +1,23 @@
|
|
|
1
|
-
import { HR_ATTENDANCE_STATUS_ENUM, HR_CHECK_IN_METHOD_ENUM } from '../../constants';
|
|
1
|
+
import { HR_ATTENDANCE_STATUS_ENUM, HR_CHECK_IN_METHOD_ENUM, HR_CLOCK_TIME_TYPE_ENUM } from '../../constants';
|
|
2
2
|
export interface ITenantHrBreakTime {
|
|
3
3
|
start_time: number;
|
|
4
4
|
end_time?: number | null;
|
|
5
5
|
}
|
|
6
|
+
export interface ITenantHrClockTime {
|
|
7
|
+
type: HR_CLOCK_TIME_TYPE_ENUM;
|
|
8
|
+
time: number;
|
|
9
|
+
method: HR_CHECK_IN_METHOD_ENUM | null;
|
|
10
|
+
}
|
|
6
11
|
export interface ITenantHrAttendanceRecord {
|
|
7
12
|
_id: string;
|
|
8
13
|
tenant_id: string;
|
|
9
14
|
employee_id: string;
|
|
10
|
-
|
|
11
|
-
|
|
15
|
+
attendance_date: string;
|
|
16
|
+
clock_time: ITenantHrClockTime[];
|
|
12
17
|
break_time: ITenantHrBreakTime[];
|
|
13
|
-
|
|
14
|
-
|
|
18
|
+
total_break_time: number;
|
|
19
|
+
total_worked_time: number;
|
|
15
20
|
status: HR_ATTENDANCE_STATUS_ENUM;
|
|
16
|
-
check_in_method: HR_CHECK_IN_METHOD_ENUM | null;
|
|
17
|
-
check_out_method: HR_CHECK_IN_METHOD_ENUM | null;
|
|
18
21
|
notes?: string | null;
|
|
19
22
|
createdAt: Date;
|
|
20
23
|
updatedAt: Date | null;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const constants_1 = require("../constants");
|
|
4
|
+
const payment_collection_1 = require("../helpers/order/payment-collection");
|
|
5
|
+
const NOW = new Date('2026-10-20T14:00:00.000Z');
|
|
6
|
+
const EARLIER = new Date('2026-10-19T10:00:00.000Z');
|
|
7
|
+
const payment = (over = {}) => ({
|
|
8
|
+
_id: '5f0000000000000000000001',
|
|
9
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.CASH,
|
|
10
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.SETTLED,
|
|
11
|
+
card_details: null,
|
|
12
|
+
amount_paid: 1000,
|
|
13
|
+
amount_due: 1000,
|
|
14
|
+
amount_refunded: 0,
|
|
15
|
+
payment_id: 'pay-1',
|
|
16
|
+
...over,
|
|
17
|
+
});
|
|
18
|
+
describe('stampPaymentCollectionTimestamps', () => {
|
|
19
|
+
it('stamps new collected money and leaves unpaid PAY_LATER empty', () => {
|
|
20
|
+
const [paid, credit] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([
|
|
21
|
+
payment(),
|
|
22
|
+
payment({
|
|
23
|
+
_id: '5f0000000000000000000002',
|
|
24
|
+
payment_id: 'pay-2',
|
|
25
|
+
payment_type: constants_1.PAYMENT_TYPE_ENUM.PAY_LATER,
|
|
26
|
+
payment_status: constants_1.PAYMENT_STATUS_ENUM.PENDING,
|
|
27
|
+
amount_paid: 0,
|
|
28
|
+
amount_due: 5000,
|
|
29
|
+
}),
|
|
30
|
+
], null, { now: NOW });
|
|
31
|
+
expect(paid.collected_at).toBe(NOW);
|
|
32
|
+
expect(credit.collected_at).toBeNull();
|
|
33
|
+
});
|
|
34
|
+
it('ignores a client-supplied collected_at on create', () => {
|
|
35
|
+
const [paid] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: EARLIER })], null, { now: NOW });
|
|
36
|
+
expect(paid.collected_at).toBe(NOW);
|
|
37
|
+
});
|
|
38
|
+
it('preserves the stored timestamp when amount_paid did not increase', () => {
|
|
39
|
+
const previous = payment({ collected_at: EARLIER });
|
|
40
|
+
const [unchanged] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ collected_at: null })], [previous], { now: NOW });
|
|
41
|
+
expect(unchanged.collected_at).toBe(EARLIER);
|
|
42
|
+
});
|
|
43
|
+
it('stamps the latest collection when a partial amount is collected', () => {
|
|
44
|
+
const previous = payment({ amount_paid: 400, collected_at: EARLIER });
|
|
45
|
+
const [partial] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 700 })], [previous], { now: NOW });
|
|
46
|
+
expect(partial.collected_at).toBe(NOW);
|
|
47
|
+
});
|
|
48
|
+
it('does not rewrite the timestamp on a refund / amount decrease', () => {
|
|
49
|
+
const previous = payment({ amount_paid: 1000, collected_at: EARLIER });
|
|
50
|
+
const [refunded] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ amount_paid: 0, amount_refunded: 1000, payment_status: constants_1.PAYMENT_STATUS_ENUM.REFUNDED })], [previous], { now: NOW });
|
|
51
|
+
expect(refunded.collected_at).toBe(EARLIER);
|
|
52
|
+
});
|
|
53
|
+
it('matches legacy rows by _id when payment_id is null', () => {
|
|
54
|
+
const previous = payment({ payment_id: null, collected_at: EARLIER });
|
|
55
|
+
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: null, amount_paid: 1200 })], [previous], { now: NOW });
|
|
56
|
+
expect(updated.collected_at).toBe(NOW);
|
|
57
|
+
});
|
|
58
|
+
it('preserves the stamp when the server reassigns payment_id but _id is stable', () => {
|
|
59
|
+
const previous = payment({ payment_id: 'pay-old', collected_at: EARLIER });
|
|
60
|
+
const [updated] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_id: 'pay-new' })], [previous], { now: NOW });
|
|
61
|
+
expect(updated.collected_at).toBe(EARLIER);
|
|
62
|
+
});
|
|
63
|
+
it('does not stamp a failed payment', () => {
|
|
64
|
+
const [failed] = (0, payment_collection_1.stampPaymentCollectionTimestamps)([payment({ payment_status: constants_1.PAYMENT_STATUS_ENUM.FAILED })], null, { now: NOW });
|
|
65
|
+
expect(failed.collected_at).toBeNull();
|
|
66
|
+
});
|
|
67
|
+
it('returns an empty array for empty / invalid input', () => {
|
|
68
|
+
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(null)).toEqual([]);
|
|
69
|
+
expect((0, payment_collection_1.stampPaymentCollectionTimestamps)(undefined)).toEqual([]);
|
|
70
|
+
});
|
|
71
|
+
});
|