@managesome/eposmatic-toolkit 0.4.17 → 0.4.20
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.js +1 -0
- package/esm/constants/enums/accounting.js +80 -0
- package/esm/helpers/materialized-reports/materialized-discount-close-day-helpers.js +6 -0
- package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +4 -6
- package/esm/schemas/models/index.js +2 -0
- package/esm/schemas/models/tenant_chart_of_accounts.js +80 -0
- package/esm/schemas/models/tenant_journal_entries.js +147 -0
- package/esm/schemas/types/index.js +2 -0
- package/esm/schemas/types/tenant_chart_of_accounts.js +1 -0
- package/esm/schemas/types/tenant_journal_entries.js +1 -0
- package/lib/constants/ENUMS.d.ts +1 -0
- package/lib/constants/ENUMS.js +1 -0
- package/lib/constants/enums/accounting.d.ts +62 -0
- package/lib/constants/enums/accounting.js +83 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +7 -0
- package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +6 -0
- package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +4 -6
- package/lib/helpers/order/payment-collection.d.ts +25 -0
- package/lib/helpers/order/payment-collection.js +51 -0
- package/lib/schemas/models/index.d.ts +2 -0
- package/lib/schemas/models/index.js +2 -0
- package/lib/schemas/models/tenant_chart_of_accounts.d.ts +66 -0
- package/lib/schemas/models/tenant_chart_of_accounts.js +83 -0
- package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
- package/lib/schemas/models/tenant_journal_entries.d.ts +132 -0
- package/lib/schemas/models/tenant_journal_entries.js +150 -0
- package/lib/schemas/types/index.d.ts +2 -0
- package/lib/schemas/types/index.js +2 -0
- package/lib/schemas/types/tenant_chart_of_accounts.d.ts +23 -0
- package/lib/schemas/types/tenant_chart_of_accounts.js +2 -0
- package/lib/schemas/types/tenant_journal_entries.d.ts +34 -0
- package/lib/schemas/types/tenant_journal_entries.js +2 -0
- package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +16 -0
- package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.js +26 -18
- package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
- package/lib/tests/payment-collection-timestamps.test.js +71 -0
- package/lib/tests/reporting-contract.test.js +7 -0
- package/package.json +1 -1
|
@@ -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
|
+
}
|
|
@@ -67,6 +67,7 @@ export * from './tenant_cash_drawer_sessions';
|
|
|
67
67
|
export * from './tenant_cash_drawers';
|
|
68
68
|
export * from './tenant_cash_in_hand_transactions';
|
|
69
69
|
export * from './tenant_cash_in_out';
|
|
70
|
+
export * from './tenant_chart_of_accounts';
|
|
70
71
|
export * from './tenant_clients';
|
|
71
72
|
export * from './tenant_day_sessions';
|
|
72
73
|
export * from './tenant_hr_attendance_records';
|
|
@@ -87,6 +88,7 @@ export * from './tenant_inventory_department_transactions';
|
|
|
87
88
|
export * from './tenant_inventory_department_utilities';
|
|
88
89
|
export * from './tenant_inventory_departments';
|
|
89
90
|
export * from './tenant_inventory_entries';
|
|
91
|
+
export * from './tenant_journal_entries';
|
|
90
92
|
export * from './tenant_metadata';
|
|
91
93
|
export * from './tenant_order_item_instructions';
|
|
92
94
|
export * from './tenant_purchase_order_vendor_returns';
|
|
@@ -83,6 +83,7 @@ __exportStar(require("./tenant_cash_drawer_sessions"), exports);
|
|
|
83
83
|
__exportStar(require("./tenant_cash_drawers"), exports);
|
|
84
84
|
__exportStar(require("./tenant_cash_in_hand_transactions"), exports);
|
|
85
85
|
__exportStar(require("./tenant_cash_in_out"), exports);
|
|
86
|
+
__exportStar(require("./tenant_chart_of_accounts"), exports);
|
|
86
87
|
__exportStar(require("./tenant_clients"), exports);
|
|
87
88
|
__exportStar(require("./tenant_day_sessions"), exports);
|
|
88
89
|
__exportStar(require("./tenant_hr_attendance_records"), exports);
|
|
@@ -103,6 +104,7 @@ __exportStar(require("./tenant_inventory_department_transactions"), exports);
|
|
|
103
104
|
__exportStar(require("./tenant_inventory_department_utilities"), exports);
|
|
104
105
|
__exportStar(require("./tenant_inventory_departments"), exports);
|
|
105
106
|
__exportStar(require("./tenant_inventory_entries"), exports);
|
|
107
|
+
__exportStar(require("./tenant_journal_entries"), exports);
|
|
106
108
|
__exportStar(require("./tenant_metadata"), exports);
|
|
107
109
|
__exportStar(require("./tenant_order_item_instructions"), exports);
|
|
108
110
|
__exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { ACCOUNT_TYPE_ENUM } from '../../constants';
|
|
3
|
+
export declare const TenantChartOfAccountsSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
4
|
+
timestamps: true;
|
|
5
|
+
versionKey: false;
|
|
6
|
+
minimize: false;
|
|
7
|
+
}, {
|
|
8
|
+
createdAt: NativeDate;
|
|
9
|
+
updatedAt: NativeDate;
|
|
10
|
+
} & {
|
|
11
|
+
_id: import("mongoose").Types.ObjectId;
|
|
12
|
+
type: ACCOUNT_TYPE_ENUM;
|
|
13
|
+
name: string;
|
|
14
|
+
sort_id: number;
|
|
15
|
+
description: string;
|
|
16
|
+
tenant_id: string;
|
|
17
|
+
increases_on: import("../../constants").ACCOUNT_NORMAL_BALANCE_ENUM;
|
|
18
|
+
is_system: boolean;
|
|
19
|
+
is_archived: boolean;
|
|
20
|
+
code?: string | null | undefined;
|
|
21
|
+
parent_id?: import("mongoose").Types.ObjectId | null | undefined;
|
|
22
|
+
account_number?: string | null | undefined;
|
|
23
|
+
bank_name?: string | null | undefined;
|
|
24
|
+
bank_identifier_code?: string | null | undefined;
|
|
25
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
26
|
+
createdAt: NativeDate;
|
|
27
|
+
updatedAt: NativeDate;
|
|
28
|
+
} & {
|
|
29
|
+
_id: import("mongoose").Types.ObjectId;
|
|
30
|
+
type: ACCOUNT_TYPE_ENUM;
|
|
31
|
+
name: string;
|
|
32
|
+
sort_id: number;
|
|
33
|
+
description: string;
|
|
34
|
+
tenant_id: string;
|
|
35
|
+
increases_on: import("../../constants").ACCOUNT_NORMAL_BALANCE_ENUM;
|
|
36
|
+
is_system: boolean;
|
|
37
|
+
is_archived: boolean;
|
|
38
|
+
code?: string | null | undefined;
|
|
39
|
+
parent_id?: import("mongoose").Types.ObjectId | null | undefined;
|
|
40
|
+
account_number?: string | null | undefined;
|
|
41
|
+
bank_name?: string | null | undefined;
|
|
42
|
+
bank_identifier_code?: string | null | undefined;
|
|
43
|
+
}>> & import("mongoose").FlatRecord<{
|
|
44
|
+
createdAt: NativeDate;
|
|
45
|
+
updatedAt: NativeDate;
|
|
46
|
+
} & {
|
|
47
|
+
_id: import("mongoose").Types.ObjectId;
|
|
48
|
+
type: ACCOUNT_TYPE_ENUM;
|
|
49
|
+
name: string;
|
|
50
|
+
sort_id: number;
|
|
51
|
+
description: string;
|
|
52
|
+
tenant_id: string;
|
|
53
|
+
increases_on: import("../../constants").ACCOUNT_NORMAL_BALANCE_ENUM;
|
|
54
|
+
is_system: boolean;
|
|
55
|
+
is_archived: boolean;
|
|
56
|
+
code?: string | null | undefined;
|
|
57
|
+
parent_id?: import("mongoose").Types.ObjectId | null | undefined;
|
|
58
|
+
account_number?: string | null | undefined;
|
|
59
|
+
bank_name?: string | null | undefined;
|
|
60
|
+
bank_identifier_code?: string | null | undefined;
|
|
61
|
+
}> & Required<{
|
|
62
|
+
_id: import("mongoose").Types.ObjectId;
|
|
63
|
+
}> & {
|
|
64
|
+
__v: number;
|
|
65
|
+
}>;
|
|
66
|
+
export declare const TENANT_CHART_OF_ACCOUNTS_COLLECTION_NAME = "tenant_chart_of_accounts";
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_CHART_OF_ACCOUNTS_COLLECTION_NAME = exports.TenantChartOfAccountsSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
exports.TenantChartOfAccountsSchema = new mongoose_1.Schema({
|
|
7
|
+
_id: {
|
|
8
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
9
|
+
required: true,
|
|
10
|
+
immutable: true,
|
|
11
|
+
},
|
|
12
|
+
tenant_id: {
|
|
13
|
+
type: String,
|
|
14
|
+
required: true,
|
|
15
|
+
immutable: true,
|
|
16
|
+
ref: 'tenants',
|
|
17
|
+
},
|
|
18
|
+
code: {
|
|
19
|
+
type: String,
|
|
20
|
+
trim: true,
|
|
21
|
+
uppercase: true,
|
|
22
|
+
match: /^[A-Z0-9][A-Z0-9-_]{0,23}$/,
|
|
23
|
+
},
|
|
24
|
+
name: {
|
|
25
|
+
type: String,
|
|
26
|
+
required: true,
|
|
27
|
+
trim: true,
|
|
28
|
+
maxlength: 120,
|
|
29
|
+
},
|
|
30
|
+
type: {
|
|
31
|
+
type: String,
|
|
32
|
+
required: true,
|
|
33
|
+
enum: constants_1.ALL_ACCOUNT_TYPES,
|
|
34
|
+
},
|
|
35
|
+
increases_on: {
|
|
36
|
+
type: String,
|
|
37
|
+
required: true,
|
|
38
|
+
enum: constants_1.ALL_ACCOUNT_NORMAL_BALANCES,
|
|
39
|
+
default() {
|
|
40
|
+
return constants_1.ACCOUNT_TYPE_NORMAL_BALANCE[this.type];
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
parent_id: {
|
|
44
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
45
|
+
ref: 'tenant_chart_of_accounts',
|
|
46
|
+
},
|
|
47
|
+
is_system: {
|
|
48
|
+
type: Boolean,
|
|
49
|
+
default: false,
|
|
50
|
+
},
|
|
51
|
+
is_archived: {
|
|
52
|
+
type: Boolean,
|
|
53
|
+
default: false,
|
|
54
|
+
},
|
|
55
|
+
description: {
|
|
56
|
+
type: String,
|
|
57
|
+
trim: true,
|
|
58
|
+
maxlength: 300,
|
|
59
|
+
default: '',
|
|
60
|
+
},
|
|
61
|
+
sort_id: {
|
|
62
|
+
type: Number,
|
|
63
|
+
required: true,
|
|
64
|
+
min: 0,
|
|
65
|
+
},
|
|
66
|
+
account_number: {
|
|
67
|
+
type: String,
|
|
68
|
+
trim: true,
|
|
69
|
+
},
|
|
70
|
+
bank_name: {
|
|
71
|
+
type: String,
|
|
72
|
+
trim: true,
|
|
73
|
+
},
|
|
74
|
+
bank_identifier_code: {
|
|
75
|
+
type: String,
|
|
76
|
+
trim: true,
|
|
77
|
+
},
|
|
78
|
+
}, {
|
|
79
|
+
timestamps: true,
|
|
80
|
+
versionKey: false,
|
|
81
|
+
minimize: false,
|
|
82
|
+
});
|
|
83
|
+
exports.TENANT_CHART_OF_ACCOUNTS_COLLECTION_NAME = 'tenant_chart_of_accounts';
|
|
@@ -14,13 +14,13 @@ export declare const TenantHrDocumentSchema: Schema<any, import("mongoose").Mode
|
|
|
14
14
|
description: string;
|
|
15
15
|
tenant_id: string;
|
|
16
16
|
employee_id: string;
|
|
17
|
+
is_archived: boolean;
|
|
17
18
|
document_type: HR_DOCUMENT_TYPE_ENUM;
|
|
18
19
|
document_name: string;
|
|
19
20
|
file_url: string;
|
|
20
21
|
file_size: number;
|
|
21
22
|
file_type: string;
|
|
22
23
|
is_confidential: boolean;
|
|
23
|
-
is_archived: boolean;
|
|
24
24
|
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
25
25
|
createdAt: NativeDate;
|
|
26
26
|
updatedAt: NativeDate;
|
|
@@ -31,13 +31,13 @@ export declare const TenantHrDocumentSchema: Schema<any, import("mongoose").Mode
|
|
|
31
31
|
description: string;
|
|
32
32
|
tenant_id: string;
|
|
33
33
|
employee_id: string;
|
|
34
|
+
is_archived: boolean;
|
|
34
35
|
document_type: HR_DOCUMENT_TYPE_ENUM;
|
|
35
36
|
document_name: string;
|
|
36
37
|
file_url: string;
|
|
37
38
|
file_size: number;
|
|
38
39
|
file_type: string;
|
|
39
40
|
is_confidential: boolean;
|
|
40
|
-
is_archived: boolean;
|
|
41
41
|
}>> & import("mongoose").FlatRecord<{
|
|
42
42
|
createdAt: NativeDate;
|
|
43
43
|
updatedAt: NativeDate;
|
|
@@ -48,13 +48,13 @@ export declare const TenantHrDocumentSchema: Schema<any, import("mongoose").Mode
|
|
|
48
48
|
description: string;
|
|
49
49
|
tenant_id: string;
|
|
50
50
|
employee_id: string;
|
|
51
|
+
is_archived: boolean;
|
|
51
52
|
document_type: HR_DOCUMENT_TYPE_ENUM;
|
|
52
53
|
document_name: string;
|
|
53
54
|
file_url: string;
|
|
54
55
|
file_size: number;
|
|
55
56
|
file_type: string;
|
|
56
57
|
is_confidential: boolean;
|
|
57
|
-
is_archived: boolean;
|
|
58
58
|
}> & Required<{
|
|
59
59
|
_id: import("mongoose").Types.ObjectId;
|
|
60
60
|
}> & {
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import { Schema } from 'mongoose';
|
|
2
|
+
import { JOURNAL_ENTRY_STATUS_ENUM } from '../../constants';
|
|
3
|
+
export declare const TenantJournalEntriesSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
|
|
4
|
+
timestamps: true;
|
|
5
|
+
versionKey: false;
|
|
6
|
+
minimize: false;
|
|
7
|
+
}, {
|
|
8
|
+
createdAt: NativeDate;
|
|
9
|
+
updatedAt: NativeDate;
|
|
10
|
+
} & {
|
|
11
|
+
_id: import("mongoose").Types.ObjectId;
|
|
12
|
+
description: string;
|
|
13
|
+
tenant_id: string;
|
|
14
|
+
status: JOURNAL_ENTRY_STATUS_ENUM;
|
|
15
|
+
source_type: import("../../constants").JOURNAL_ENTRY_SOURCE_ENUM;
|
|
16
|
+
entry_number: string;
|
|
17
|
+
reference: string;
|
|
18
|
+
lines: import("mongoose").Types.DocumentArray<{
|
|
19
|
+
line_no: number;
|
|
20
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
21
|
+
account_code: string;
|
|
22
|
+
debit: number;
|
|
23
|
+
credit: number;
|
|
24
|
+
memo: string;
|
|
25
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
26
|
+
line_no: number;
|
|
27
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
28
|
+
account_code: string;
|
|
29
|
+
debit: number;
|
|
30
|
+
credit: number;
|
|
31
|
+
memo: string;
|
|
32
|
+
}> & {
|
|
33
|
+
line_no: number;
|
|
34
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
35
|
+
account_code: string;
|
|
36
|
+
debit: number;
|
|
37
|
+
credit: number;
|
|
38
|
+
memo: string;
|
|
39
|
+
}>;
|
|
40
|
+
total_debit: number;
|
|
41
|
+
total_credit: number;
|
|
42
|
+
voided_at: NativeDate;
|
|
43
|
+
void_reason?: string | null | undefined;
|
|
44
|
+
created_by?: string | null | undefined;
|
|
45
|
+
source_id?: string | null | undefined;
|
|
46
|
+
voided_by?: string | null | undefined;
|
|
47
|
+
}, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
|
|
48
|
+
createdAt: NativeDate;
|
|
49
|
+
updatedAt: NativeDate;
|
|
50
|
+
} & {
|
|
51
|
+
_id: import("mongoose").Types.ObjectId;
|
|
52
|
+
description: string;
|
|
53
|
+
tenant_id: string;
|
|
54
|
+
status: JOURNAL_ENTRY_STATUS_ENUM;
|
|
55
|
+
source_type: import("../../constants").JOURNAL_ENTRY_SOURCE_ENUM;
|
|
56
|
+
entry_number: string;
|
|
57
|
+
reference: string;
|
|
58
|
+
lines: import("mongoose").Types.DocumentArray<{
|
|
59
|
+
line_no: number;
|
|
60
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
61
|
+
account_code: string;
|
|
62
|
+
debit: number;
|
|
63
|
+
credit: number;
|
|
64
|
+
memo: string;
|
|
65
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
66
|
+
line_no: number;
|
|
67
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
68
|
+
account_code: string;
|
|
69
|
+
debit: number;
|
|
70
|
+
credit: number;
|
|
71
|
+
memo: string;
|
|
72
|
+
}> & {
|
|
73
|
+
line_no: number;
|
|
74
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
75
|
+
account_code: string;
|
|
76
|
+
debit: number;
|
|
77
|
+
credit: number;
|
|
78
|
+
memo: string;
|
|
79
|
+
}>;
|
|
80
|
+
total_debit: number;
|
|
81
|
+
total_credit: number;
|
|
82
|
+
voided_at: NativeDate;
|
|
83
|
+
void_reason?: string | null | undefined;
|
|
84
|
+
created_by?: string | null | undefined;
|
|
85
|
+
source_id?: string | null | undefined;
|
|
86
|
+
voided_by?: string | null | undefined;
|
|
87
|
+
}>> & import("mongoose").FlatRecord<{
|
|
88
|
+
createdAt: NativeDate;
|
|
89
|
+
updatedAt: NativeDate;
|
|
90
|
+
} & {
|
|
91
|
+
_id: import("mongoose").Types.ObjectId;
|
|
92
|
+
description: string;
|
|
93
|
+
tenant_id: string;
|
|
94
|
+
status: JOURNAL_ENTRY_STATUS_ENUM;
|
|
95
|
+
source_type: import("../../constants").JOURNAL_ENTRY_SOURCE_ENUM;
|
|
96
|
+
entry_number: string;
|
|
97
|
+
reference: string;
|
|
98
|
+
lines: import("mongoose").Types.DocumentArray<{
|
|
99
|
+
line_no: number;
|
|
100
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
101
|
+
account_code: string;
|
|
102
|
+
debit: number;
|
|
103
|
+
credit: number;
|
|
104
|
+
memo: string;
|
|
105
|
+
}, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
|
|
106
|
+
line_no: number;
|
|
107
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
108
|
+
account_code: string;
|
|
109
|
+
debit: number;
|
|
110
|
+
credit: number;
|
|
111
|
+
memo: string;
|
|
112
|
+
}> & {
|
|
113
|
+
line_no: number;
|
|
114
|
+
account_id: import("mongoose").Types.ObjectId;
|
|
115
|
+
account_code: string;
|
|
116
|
+
debit: number;
|
|
117
|
+
credit: number;
|
|
118
|
+
memo: string;
|
|
119
|
+
}>;
|
|
120
|
+
total_debit: number;
|
|
121
|
+
total_credit: number;
|
|
122
|
+
voided_at: NativeDate;
|
|
123
|
+
void_reason?: string | null | undefined;
|
|
124
|
+
created_by?: string | null | undefined;
|
|
125
|
+
source_id?: string | null | undefined;
|
|
126
|
+
voided_by?: string | null | undefined;
|
|
127
|
+
}> & Required<{
|
|
128
|
+
_id: import("mongoose").Types.ObjectId;
|
|
129
|
+
}> & {
|
|
130
|
+
__v: number;
|
|
131
|
+
}>;
|
|
132
|
+
export declare const TENANT_JOURNAL_ENTRIES_COLLECTION_NAME = "tenant_journal_entries";
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TENANT_JOURNAL_ENTRIES_COLLECTION_NAME = exports.TenantJournalEntriesSchema = void 0;
|
|
4
|
+
const mongoose_1 = require("mongoose");
|
|
5
|
+
const constants_1 = require("../../constants");
|
|
6
|
+
const TenantJournalEntryLineSchema = new mongoose_1.Schema({
|
|
7
|
+
line_no: {
|
|
8
|
+
type: Number,
|
|
9
|
+
required: true,
|
|
10
|
+
min: 1,
|
|
11
|
+
},
|
|
12
|
+
account_id: {
|
|
13
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
14
|
+
required: true,
|
|
15
|
+
ref: 'tenant_chart_of_accounts',
|
|
16
|
+
},
|
|
17
|
+
account_code: {
|
|
18
|
+
type: String,
|
|
19
|
+
required: true,
|
|
20
|
+
},
|
|
21
|
+
debit: {
|
|
22
|
+
type: Number,
|
|
23
|
+
required: true,
|
|
24
|
+
min: 0,
|
|
25
|
+
validate: {
|
|
26
|
+
validator: (value) => Number.isInteger(value),
|
|
27
|
+
message: 'debit must be an integer (minor units)',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
credit: {
|
|
31
|
+
type: Number,
|
|
32
|
+
required: true,
|
|
33
|
+
min: 0,
|
|
34
|
+
validate: {
|
|
35
|
+
validator: (value) => Number.isInteger(value),
|
|
36
|
+
message: 'credit must be an integer (minor units)',
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
memo: {
|
|
40
|
+
type: String,
|
|
41
|
+
trim: true,
|
|
42
|
+
maxlength: 500,
|
|
43
|
+
default: '',
|
|
44
|
+
},
|
|
45
|
+
}, { _id: true });
|
|
46
|
+
TenantJournalEntryLineSchema.pre('validate', function (next) {
|
|
47
|
+
const line = this;
|
|
48
|
+
if (line.debit > 0 === line.credit > 0) {
|
|
49
|
+
return next(new Error('Each journal line must have exactly one side greater than zero'));
|
|
50
|
+
}
|
|
51
|
+
next();
|
|
52
|
+
});
|
|
53
|
+
exports.TenantJournalEntriesSchema = new mongoose_1.Schema({
|
|
54
|
+
_id: {
|
|
55
|
+
type: mongoose_1.Schema.Types.ObjectId,
|
|
56
|
+
required: true,
|
|
57
|
+
immutable: true,
|
|
58
|
+
},
|
|
59
|
+
tenant_id: {
|
|
60
|
+
type: String,
|
|
61
|
+
required: true,
|
|
62
|
+
immutable: true,
|
|
63
|
+
ref: 'tenants',
|
|
64
|
+
},
|
|
65
|
+
entry_number: {
|
|
66
|
+
type: String,
|
|
67
|
+
required: true,
|
|
68
|
+
immutable: true,
|
|
69
|
+
},
|
|
70
|
+
description: {
|
|
71
|
+
type: String,
|
|
72
|
+
required: true,
|
|
73
|
+
trim: true,
|
|
74
|
+
maxlength: 300,
|
|
75
|
+
},
|
|
76
|
+
reference: {
|
|
77
|
+
type: String,
|
|
78
|
+
trim: true,
|
|
79
|
+
maxlength: 120,
|
|
80
|
+
default: '',
|
|
81
|
+
},
|
|
82
|
+
source_type: {
|
|
83
|
+
type: String,
|
|
84
|
+
required: true,
|
|
85
|
+
enum: constants_1.ALL_JOURNAL_ENTRY_SOURCES,
|
|
86
|
+
},
|
|
87
|
+
source_id: {
|
|
88
|
+
type: String,
|
|
89
|
+
},
|
|
90
|
+
lines: {
|
|
91
|
+
type: [TenantJournalEntryLineSchema],
|
|
92
|
+
required: true,
|
|
93
|
+
validate: [
|
|
94
|
+
{
|
|
95
|
+
validator: (lines) => lines.length >= 2,
|
|
96
|
+
message: 'A journal entry needs at least two lines',
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
validator: (lines) => {
|
|
100
|
+
const totalDebit = lines.reduce((total, line) => total + line.debit, 0);
|
|
101
|
+
const totalCredit = lines.reduce((total, line) => total + line.credit, 0);
|
|
102
|
+
return totalDebit > 0 && totalDebit === totalCredit;
|
|
103
|
+
},
|
|
104
|
+
message: 'Debits must equal credits and be greater than zero',
|
|
105
|
+
},
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
total_debit: {
|
|
109
|
+
type: Number,
|
|
110
|
+
required: true,
|
|
111
|
+
min: 1,
|
|
112
|
+
validate: {
|
|
113
|
+
validator: (value) => Number.isInteger(value),
|
|
114
|
+
message: 'total_debit must be an integer (minor units)',
|
|
115
|
+
},
|
|
116
|
+
},
|
|
117
|
+
total_credit: {
|
|
118
|
+
type: Number,
|
|
119
|
+
required: true,
|
|
120
|
+
min: 1,
|
|
121
|
+
validate: {
|
|
122
|
+
validator: (value) => Number.isInteger(value),
|
|
123
|
+
message: 'total_credit must be an integer (minor units)',
|
|
124
|
+
},
|
|
125
|
+
},
|
|
126
|
+
status: {
|
|
127
|
+
type: String,
|
|
128
|
+
required: true,
|
|
129
|
+
enum: constants_1.ALL_JOURNAL_ENTRY_STATUSES,
|
|
130
|
+
default: constants_1.JOURNAL_ENTRY_STATUS_ENUM.POSTED,
|
|
131
|
+
},
|
|
132
|
+
voided_at: {
|
|
133
|
+
type: mongoose_1.Schema.Types.Date,
|
|
134
|
+
default: null,
|
|
135
|
+
},
|
|
136
|
+
voided_by: {
|
|
137
|
+
type: String,
|
|
138
|
+
},
|
|
139
|
+
void_reason: {
|
|
140
|
+
type: String,
|
|
141
|
+
},
|
|
142
|
+
created_by: {
|
|
143
|
+
type: String,
|
|
144
|
+
},
|
|
145
|
+
}, {
|
|
146
|
+
timestamps: true,
|
|
147
|
+
versionKey: false,
|
|
148
|
+
minimize: false,
|
|
149
|
+
});
|
|
150
|
+
exports.TENANT_JOURNAL_ENTRIES_COLLECTION_NAME = 'tenant_journal_entries';
|
|
@@ -65,6 +65,7 @@ export * from './tenant_cash_drawer_sessions';
|
|
|
65
65
|
export * from './tenant_cash_drawers';
|
|
66
66
|
export * from './tenant_cash_in_hand_transactions';
|
|
67
67
|
export * from './tenant_cash_in_out';
|
|
68
|
+
export * from './tenant_chart_of_accounts';
|
|
68
69
|
export * from './tenant_clients';
|
|
69
70
|
export * from './tenant_day_sessions';
|
|
70
71
|
export * from './tenant_hr_attendance_records';
|
|
@@ -82,6 +83,7 @@ export * from './tenant_hr_shifts';
|
|
|
82
83
|
export * from './tenant_instore_shift_sessions';
|
|
83
84
|
export * from './tenant_instore_shifts';
|
|
84
85
|
export * from './tenant_inventory_entries';
|
|
86
|
+
export * from './tenant_journal_entries';
|
|
85
87
|
export * from './tenant_metadata';
|
|
86
88
|
export * from './tenant_order_item_instructions';
|
|
87
89
|
export * from './tenant_purchase_order_vendor_returns';
|
|
@@ -81,6 +81,7 @@ __exportStar(require("./tenant_cash_drawer_sessions"), exports);
|
|
|
81
81
|
__exportStar(require("./tenant_cash_drawers"), exports);
|
|
82
82
|
__exportStar(require("./tenant_cash_in_hand_transactions"), exports);
|
|
83
83
|
__exportStar(require("./tenant_cash_in_out"), exports);
|
|
84
|
+
__exportStar(require("./tenant_chart_of_accounts"), exports);
|
|
84
85
|
__exportStar(require("./tenant_clients"), exports);
|
|
85
86
|
__exportStar(require("./tenant_day_sessions"), exports);
|
|
86
87
|
__exportStar(require("./tenant_hr_attendance_records"), exports);
|
|
@@ -98,6 +99,7 @@ __exportStar(require("./tenant_hr_shifts"), exports);
|
|
|
98
99
|
__exportStar(require("./tenant_instore_shift_sessions"), exports);
|
|
99
100
|
__exportStar(require("./tenant_instore_shifts"), exports);
|
|
100
101
|
__exportStar(require("./tenant_inventory_entries"), exports);
|
|
102
|
+
__exportStar(require("./tenant_journal_entries"), exports);
|
|
101
103
|
__exportStar(require("./tenant_metadata"), exports);
|
|
102
104
|
__exportStar(require("./tenant_order_item_instructions"), exports);
|
|
103
105
|
__exportStar(require("./tenant_purchase_order_vendor_returns"), exports);
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { ACCOUNT_NORMAL_BALANCE_ENUM, ACCOUNT_TYPE_ENUM } from '../../constants';
|
|
2
|
+
export interface ITenantChartOfAccount {
|
|
3
|
+
_id: string;
|
|
4
|
+
tenant_id: string;
|
|
5
|
+
/** Uppercase, unique per tenant. 4-digit convention; users may type their own. */
|
|
6
|
+
code?: string | null;
|
|
7
|
+
name: string;
|
|
8
|
+
type: ACCOUNT_TYPE_ENUM;
|
|
9
|
+
/** The side this account increases on — derived from `type` on create, never accepted from clients. */
|
|
10
|
+
increases_on: ACCOUNT_NORMAL_BALANCE_ENUM;
|
|
11
|
+
parent_id?: string | null;
|
|
12
|
+
/** Seeded from the template — type is locked, and the account can only be archived. */
|
|
13
|
+
is_system: boolean;
|
|
14
|
+
is_archived: boolean;
|
|
15
|
+
description: string;
|
|
16
|
+
sort_id: number;
|
|
17
|
+
/** Banking block only: cash (100x), bank (101x), clearing (102x), credit cards (207x). */
|
|
18
|
+
account_number?: string | null;
|
|
19
|
+
bank_name?: string | null;
|
|
20
|
+
bank_identifier_code?: string | null;
|
|
21
|
+
createdAt: Date;
|
|
22
|
+
updatedAt: Date;
|
|
23
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { JOURNAL_ENTRY_SOURCE_ENUM, JOURNAL_ENTRY_STATUS_ENUM } from '../../constants';
|
|
2
|
+
export interface IJournalEntryLine {
|
|
3
|
+
_id: string;
|
|
4
|
+
/** 1-based display order. */
|
|
5
|
+
line_no: number;
|
|
6
|
+
account_id: string;
|
|
7
|
+
/** Snapshot so a renamed or archived account still reads correctly on old entries. */
|
|
8
|
+
account_code: string;
|
|
9
|
+
/** Integer minor units; exactly one side is greater than zero. */
|
|
10
|
+
debit: number;
|
|
11
|
+
credit: number;
|
|
12
|
+
memo: string;
|
|
13
|
+
}
|
|
14
|
+
export interface ITenantJournalEntry {
|
|
15
|
+
_id: string;
|
|
16
|
+
tenant_id: string;
|
|
17
|
+
entry_number: string;
|
|
18
|
+
description: string;
|
|
19
|
+
/** Shift number, invoice no, settlement ref — whatever the entry refers to. */
|
|
20
|
+
reference: string;
|
|
21
|
+
source_type: JOURNAL_ENTRY_SOURCE_ENUM;
|
|
22
|
+
/** Source document id — the shift id for a consolidated SHIFT_CLOSE entry. */
|
|
23
|
+
source_id?: string | null;
|
|
24
|
+
lines: IJournalEntryLine[];
|
|
25
|
+
total_debit: number;
|
|
26
|
+
total_credit: number;
|
|
27
|
+
status: JOURNAL_ENTRY_STATUS_ENUM;
|
|
28
|
+
voided_at: Date | null;
|
|
29
|
+
voided_by?: string | null;
|
|
30
|
+
void_reason?: string | null;
|
|
31
|
+
created_by?: string | null;
|
|
32
|
+
createdAt: Date;
|
|
33
|
+
updatedAt: Date;
|
|
34
|
+
}
|