@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.
Files changed (38) hide show
  1. package/esm/constants/ENUMS.js +1 -0
  2. package/esm/constants/enums/accounting.js +80 -0
  3. package/esm/helpers/materialized-reports/materialized-discount-close-day-helpers.js +6 -0
  4. package/esm/helpers/materialized-reports/materialized-reports-selection-helpers.js +4 -6
  5. package/esm/schemas/models/index.js +2 -0
  6. package/esm/schemas/models/tenant_chart_of_accounts.js +80 -0
  7. package/esm/schemas/models/tenant_journal_entries.js +147 -0
  8. package/esm/schemas/types/index.js +2 -0
  9. package/esm/schemas/types/tenant_chart_of_accounts.js +1 -0
  10. package/esm/schemas/types/tenant_journal_entries.js +1 -0
  11. package/lib/constants/ENUMS.d.ts +1 -0
  12. package/lib/constants/ENUMS.js +1 -0
  13. package/lib/constants/enums/accounting.d.ts +62 -0
  14. package/lib/constants/enums/accounting.js +83 -0
  15. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.d.ts +7 -0
  16. package/lib/helpers/materialized-reports/materialized-discount-close-day-helpers.js +6 -0
  17. package/lib/helpers/materialized-reports/materialized-reports-selection-helpers.js +4 -6
  18. package/lib/helpers/order/payment-collection.d.ts +25 -0
  19. package/lib/helpers/order/payment-collection.js +51 -0
  20. package/lib/schemas/models/index.d.ts +2 -0
  21. package/lib/schemas/models/index.js +2 -0
  22. package/lib/schemas/models/tenant_chart_of_accounts.d.ts +66 -0
  23. package/lib/schemas/models/tenant_chart_of_accounts.js +83 -0
  24. package/lib/schemas/models/tenant_hr_documents.d.ts +3 -3
  25. package/lib/schemas/models/tenant_journal_entries.d.ts +132 -0
  26. package/lib/schemas/models/tenant_journal_entries.js +150 -0
  27. package/lib/schemas/types/index.d.ts +2 -0
  28. package/lib/schemas/types/index.js +2 -0
  29. package/lib/schemas/types/tenant_chart_of_accounts.d.ts +23 -0
  30. package/lib/schemas/types/tenant_chart_of_accounts.js +2 -0
  31. package/lib/schemas/types/tenant_journal_entries.d.ts +34 -0
  32. package/lib/schemas/types/tenant_journal_entries.js +2 -0
  33. package/lib/tests/materialized-reports/materialized-discount-close-day.test.js +16 -0
  34. package/lib/tests/materialized-reports/materialized-reports-selection-helpers.test.js +26 -18
  35. package/lib/tests/payment-collection-timestamps.test.d.ts +1 -0
  36. package/lib/tests/payment-collection-timestamps.test.js +71 -0
  37. package/lib/tests/reporting-contract.test.js +7 -0
  38. package/package.json +1 -1
@@ -480,6 +480,7 @@ describe('materialized discounts — close-day plan', () => {
480
480
  entries: compiled.entries,
481
481
  localDate: day,
482
482
  ...closeInputs(day, state),
483
+ existingEntriesComplete: true,
483
484
  reason: 'NEW_DAY',
484
485
  computedAt: AT,
485
486
  });
@@ -495,6 +496,21 @@ describe('materialized discounts — close-day plan', () => {
495
496
  entries: state.entries.filter((doc) => doc.scope_context !== 'localMonth'),
496
497
  };
497
498
  expect(monthRows(state)).toBe(0);
499
+ // Without an explicit acknowledgement that the period day set was fetched,
500
+ // the plan must refuse to guess.
501
+ {
502
+ const compiled = compileDay(c);
503
+ const unsafePlan = (0, materialized_discount_close_day_helpers_1.buildTenantDiscountCloseDayPlan)({
504
+ tenantId: TENANT,
505
+ reports: compiled.reports,
506
+ entries: compiled.entries,
507
+ localDate: c,
508
+ ...closeInputs(c, state),
509
+ reason: 'NEW_DAY',
510
+ computedAt: AT,
511
+ });
512
+ expect(unsafePlan).toBeNull();
513
+ }
498
514
  state = close(state, c);
499
515
  const dayRows = daysWithRows.reduce((sum, day) => {
500
516
  const doc = state.entries.find((entry) => entry.scope_context === 'localDate' && entry.scope_field === day);
@@ -107,30 +107,38 @@ describe('buildMaterializedReportScopeGroupsFromSelection', () => {
107
107
  },
108
108
  ]);
109
109
  });
110
- test('range-like window view compiles a CONTINUOUS span (boundary hours + compacted middle)', () => {
110
+ test('14-day range with 18:00–22:00 returns exactly 14 x 4 hour labels', () => {
111
+ const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
112
+ rangeStart: '2026-09-01',
113
+ rangeEnd: '2026-09-14',
114
+ timeStart: '18:00',
115
+ timeEnd: '22:00',
116
+ }));
117
+ expect(groups).toHaveLength(1);
118
+ expect(groups?.[0].scope_context).toBe('localHour');
119
+ expect(groups?.[0].scope_field).toHaveLength(56);
120
+ expect(groups?.[0].scope_field).toContain('2026-09-07 18');
121
+ expect(groups?.[0].scope_field).not.toContain('2026-09-07 12');
122
+ });
123
+ test('range-like window view repeats the SAME hours on every selected day', () => {
111
124
  const groups = (0, materialized_reports_selection_helpers_1.buildMaterializedReportScopeGroupsFromSelection)(selection({
112
125
  rangeStart: '2026-09-01',
113
126
  rangeEnd: '2026-09-03',
114
127
  timeStart: '18:00',
115
128
  timeEnd: '20:00',
116
129
  }));
117
- expect(groups).not.toBeNull();
118
- // The middle whole day folds into its localDate value…
119
- expect(groups).toContainEqual({
120
- scope_context: 'localDate',
121
- scope_field: ['2026-09-02'],
122
- });
123
- // …while the boundary days carry their exact hour labels: the start day
124
- // contributes its business-day tail (00–05) plus the hours from the window
125
- // start through 23; the end day contributes 06 through the hour before the
126
- // window end.
127
- const hourGroup = groups?.find((group) => group.scope_context === 'localHour');
128
- expect(hourGroup).toBeDefined();
129
- const asLabels = (day, hours) => hours.map((hour) => `${day} ${hour}`);
130
- expect(hourGroup?.scope_field).toEqual([
131
- ...asLabels('2026-09-01', ['00', '01', '02', '03', '04', '05']),
132
- ...asLabels('2026-09-01', ['18', '19', '20', '21', '22', '23']),
133
- ...asLabels('2026-09-03', ['06', '07', '08', '09', '10', '11', '12', '13', '14', '15', '16', '17', '18', '19']),
130
+ expect(groups).toEqual([
131
+ {
132
+ scope_context: 'localHour',
133
+ scope_field: [
134
+ '2026-09-01 18',
135
+ '2026-09-01 19',
136
+ '2026-09-02 18',
137
+ '2026-09-02 19',
138
+ '2026-09-03 18',
139
+ '2026-09-03 19',
140
+ ],
141
+ },
134
142
  ]);
135
143
  });
136
144
  test('an incomplete dedicated window falls back to the plain range read', () => {
@@ -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
+ });
@@ -35,6 +35,13 @@ describe('report contract capabilities', () => {
35
35
  expect((0, reporting_contract_1.getReportCapabilities)('NOT_A_REPORT')).toBeNull();
36
36
  });
37
37
  it('builds the shared live and historical paths', () => {
38
+ // The Overview page resolves BOTH modes through this builder — the admin
39
+ // slice never hardcodes `/reports/overview`.
40
+ expect((0, reporting_contract_1.buildReportPath)(reporting_contract_1.REPORT_KEY_ENUM.OVERVIEW, reporting_contract_1.REPORT_MODE_ENUM.LIVE)).toBe('/reports/overview/live');
41
+ expect((0, reporting_contract_1.buildReportPath)(reporting_contract_1.REPORT_KEY_ENUM.OVERVIEW, reporting_contract_1.REPORT_MODE_ENUM.HISTORICAL)).toBe('/reports/overview/historical');
42
+ expect((0, reporting_contract_1.buildReportPath)(reporting_contract_1.REPORT_KEY_ENUM.OVERVIEW, reporting_contract_1.REPORT_MODE_ENUM.HISTORICAL, {
43
+ details: true,
44
+ })).toBeNull();
38
45
  expect((0, reporting_contract_1.buildReportPath)(reporting_contract_1.REPORT_KEY_ENUM.SALES_COMPARISON, reporting_contract_1.REPORT_MODE_ENUM.LIVE)).toBe('/reports/sales-comparison/live');
39
46
  expect((0, reporting_contract_1.buildReportPath)(reporting_contract_1.REPORT_KEY_ENUM.SALES_COMPARISON, reporting_contract_1.REPORT_MODE_ENUM.HISTORICAL, {
40
47
  details: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@managesome/eposmatic-toolkit",
3
- "version": "0.4.17",
3
+ "version": "0.4.20",
4
4
  "description": "A Toolkit Library for Eposmatic",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",