@managesome/eposmatic-toolkit 0.4.73 → 0.4.75

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 (35) hide show
  1. package/esm/helpers/utils/halfhalf-setup-helpers.js +22 -4
  2. package/esm/helpers/utils/hr-helpers.js +0 -10
  3. package/esm/helpers/utils/setup-discount-helpers.js +79 -0
  4. package/esm/helpers/utils/specials-helpers.js +13 -1
  5. package/esm/schemas/models/tenant_hr_attendance_records.js +2 -2
  6. package/esm/schemas/models/tenant_hr_employees.js +0 -10
  7. package/esm/schemas/models/tenant_hr_shift_schedules.js +3 -38
  8. package/esm/schemas/models/tenant_hr_shifts.js +27 -13
  9. package/lib/helpers/utils/halfhalf-setup-helpers.js +22 -4
  10. package/lib/helpers/utils/hr-helpers.d.ts +0 -2
  11. package/lib/helpers/utils/hr-helpers.js +0 -10
  12. package/lib/helpers/utils/setup-discount-helpers.d.ts +29 -0
  13. package/lib/helpers/utils/setup-discount-helpers.js +82 -0
  14. package/lib/helpers/utils/specials-helpers.js +13 -1
  15. package/lib/schemas/models/tenant_hr_attendance_records.d.ts +3 -3
  16. package/lib/schemas/models/tenant_hr_attendance_records.js +2 -2
  17. package/lib/schemas/models/tenant_hr_employees.d.ts +0 -6
  18. package/lib/schemas/models/tenant_hr_employees.js +0 -10
  19. package/lib/schemas/models/tenant_hr_shift_schedules.d.ts +0 -19
  20. package/lib/schemas/models/tenant_hr_shift_schedules.js +3 -38
  21. package/lib/schemas/models/tenant_hr_shifts.d.ts +12 -30
  22. package/lib/schemas/models/tenant_hr_shifts.js +27 -13
  23. package/lib/schemas/types/tenant_hr_attendance_records.d.ts +2 -2
  24. package/lib/schemas/types/tenant_hr_employees.d.ts +1 -3
  25. package/lib/schemas/types/tenant_hr_shift_schedules.d.ts +2 -9
  26. package/lib/schemas/types/tenant_hr_shifts.d.ts +6 -6
  27. package/lib/tests/setup-quantity-discount-scaling.test.d.ts +1 -0
  28. package/lib/tests/setup-quantity-discount-scaling.test.js +274 -0
  29. package/lib/tests/tenant_hr_employees.test.d.ts +1 -0
  30. package/lib/tests/tenant_hr_employees.test.js +82 -0
  31. package/lib/tests/tenant_hr_shift_schedules.test.d.ts +1 -0
  32. package/lib/tests/tenant_hr_shift_schedules.test.js +61 -0
  33. package/lib/tests/tenant_hr_shifts.test.d.ts +1 -0
  34. package/lib/tests/tenant_hr_shifts.test.js +61 -0
  35. package/package.json +1 -1
@@ -127,16 +127,6 @@ exports.TenantHrEmployeeSchema = new mongoose_1.Schema({
127
127
  type: Number,
128
128
  default: null,
129
129
  },
130
- hr_working_days_per_month: {
131
- type: Number,
132
- required: true,
133
- default: 0,
134
- },
135
- hr_hours_per_working_day: {
136
- type: Number,
137
- required: true,
138
- default: 0,
139
- },
140
130
  hr_overtime_multiplier: {
141
131
  type: Number,
142
132
  required: true,
@@ -1,5 +1,4 @@
1
1
  import { Schema } from 'mongoose';
2
- import { HR_SHIFT_STATUS_ENUM, HR_SHIFT_TYPE_ENUM } from '../../constants';
3
2
  export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose").Model<any, any, any, any, any, any>, {}, {}, {}, {}, {
4
3
  timestamps: true;
5
4
  versionKey: false;
@@ -9,17 +8,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
9
8
  updatedAt: NativeDate;
10
9
  } & {
11
10
  _id: import("mongoose").Types.ObjectId;
12
- type: HR_SHIFT_TYPE_ENUM;
13
11
  createdAt: NativeDate;
14
12
  updatedAt: NativeDate;
15
- position: string;
16
- start_time: number;
17
- end_time: number;
18
13
  start_date: NativeDate;
19
14
  end_date: NativeDate;
20
15
  tenant_id: string;
21
- status: HR_SHIFT_STATUS_ENUM;
22
- day_indexes: string[];
23
16
  notes: string;
24
17
  employee_id: string;
25
18
  shift_id: string;
@@ -28,17 +21,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
28
21
  updatedAt: NativeDate;
29
22
  } & {
30
23
  _id: import("mongoose").Types.ObjectId;
31
- type: HR_SHIFT_TYPE_ENUM;
32
24
  createdAt: NativeDate;
33
25
  updatedAt: NativeDate;
34
- position: string;
35
- start_time: number;
36
- end_time: number;
37
26
  start_date: NativeDate;
38
27
  end_date: NativeDate;
39
28
  tenant_id: string;
40
- status: HR_SHIFT_STATUS_ENUM;
41
- day_indexes: string[];
42
29
  notes: string;
43
30
  employee_id: string;
44
31
  shift_id: string;
@@ -47,17 +34,11 @@ export declare const TenantHrShiftScheduleSchema: Schema<any, import("mongoose")
47
34
  updatedAt: NativeDate;
48
35
  } & {
49
36
  _id: import("mongoose").Types.ObjectId;
50
- type: HR_SHIFT_TYPE_ENUM;
51
37
  createdAt: NativeDate;
52
38
  updatedAt: NativeDate;
53
- position: string;
54
- start_time: number;
55
- end_time: number;
56
39
  start_date: NativeDate;
57
40
  end_date: NativeDate;
58
41
  tenant_id: string;
59
- status: HR_SHIFT_STATUS_ENUM;
60
- day_indexes: string[];
61
42
  notes: string;
62
43
  employee_id: string;
63
44
  shift_id: string;
@@ -2,7 +2,6 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TENANT_HR_SHIFT_SCHEDULES_COLLECTION_NAME = exports.TenantHrShiftScheduleSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
- const constants_1 = require("../../constants");
6
5
  exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
7
6
  _id: {
8
7
  type: mongoose_1.Schema.Types.ObjectId,
@@ -21,11 +20,10 @@ exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
21
20
  immutable: true,
22
21
  ref: 'tenant_hr_employees',
23
22
  },
24
- day_indexes: {
25
- type: [String],
26
- enum: constants_1.ALL_DAY_INDEX,
23
+ shift_id: {
24
+ type: String,
27
25
  required: true,
28
- default: [],
26
+ ref: 'tenant_hr_shifts',
29
27
  },
30
28
  start_date: {
31
29
  type: Date,
@@ -35,43 +33,10 @@ exports.TenantHrShiftScheduleSchema = new mongoose_1.Schema({
35
33
  type: Date,
36
34
  default: null,
37
35
  },
38
- start_time: {
39
- type: Number,
40
- required: true,
41
- min: 0,
42
- max: 86399,
43
- },
44
- end_time: {
45
- type: Number,
46
- required: true,
47
- min: 0,
48
- max: 86399,
49
- },
50
- position: {
51
- type: String,
52
- default: null,
53
- },
54
- type: {
55
- type: String,
56
- required: true,
57
- enum: constants_1.ALL_HR_SHIFT_TYPE_NAMES,
58
- default: constants_1.HR_SHIFT_TYPE_ENUM.REGULAR,
59
- },
60
- status: {
61
- type: String,
62
- required: true,
63
- enum: constants_1.ALL_HR_SHIFT_STATUS_NAMES,
64
- default: constants_1.HR_SHIFT_STATUS_ENUM.SCHEDULED,
65
- },
66
36
  notes: {
67
37
  type: String,
68
38
  default: null,
69
39
  },
70
- shift_id: {
71
- type: String,
72
- default: null,
73
- ref: 'tenant_hr_shifts',
74
- },
75
40
  createdAt: {
76
41
  type: mongoose_1.Schema.Types.Date,
77
42
  required: true,
@@ -15,17 +15,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
15
15
  end_time: number;
16
16
  tenant_id: string;
17
17
  is_active: boolean;
18
+ break_start_time: number;
19
+ break_end_time: number;
20
+ working_days: string[];
18
21
  grace_period_minutes: number;
19
- required_positions: import("mongoose").Types.DocumentArray<{
20
- count: number;
21
- position: string;
22
- }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
23
- count: number;
24
- position: string;
25
- }> & {
26
- count: number;
27
- position: string;
28
- }>;
22
+ overtime_start_time: number;
29
23
  }, import("mongoose").Document<unknown, {}, import("mongoose").FlatRecord<{
30
24
  createdAt: NativeDate;
31
25
  updatedAt: NativeDate;
@@ -38,17 +32,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
38
32
  end_time: number;
39
33
  tenant_id: string;
40
34
  is_active: boolean;
35
+ break_start_time: number;
36
+ break_end_time: number;
37
+ working_days: string[];
41
38
  grace_period_minutes: number;
42
- required_positions: import("mongoose").Types.DocumentArray<{
43
- count: number;
44
- position: string;
45
- }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
46
- count: number;
47
- position: string;
48
- }> & {
49
- count: number;
50
- position: string;
51
- }>;
39
+ overtime_start_time: number;
52
40
  }>> & import("mongoose").FlatRecord<{
53
41
  createdAt: NativeDate;
54
42
  updatedAt: NativeDate;
@@ -61,17 +49,11 @@ export declare const TenantHrShiftSchema: Schema<any, import("mongoose").Model<a
61
49
  end_time: number;
62
50
  tenant_id: string;
63
51
  is_active: boolean;
52
+ break_start_time: number;
53
+ break_end_time: number;
54
+ working_days: string[];
64
55
  grace_period_minutes: number;
65
- required_positions: import("mongoose").Types.DocumentArray<{
66
- count: number;
67
- position: string;
68
- }, import("mongoose").Types.Subdocument<import("mongoose").Types.ObjectId, any, {
69
- count: number;
70
- position: string;
71
- }> & {
72
- count: number;
73
- position: string;
74
- }>;
56
+ overtime_start_time: number;
75
57
  }> & Required<{
76
58
  _id: import("mongoose").Types.ObjectId;
77
59
  }> & {
@@ -2,16 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.TENANT_HR_SHIFTS_COLLECTION_NAME = exports.TenantHrShiftSchema = void 0;
4
4
  const mongoose_1 = require("mongoose");
5
- const hrRequiredPositionSchema = new mongoose_1.Schema({
6
- position: {
7
- type: String,
8
- required: true,
9
- },
10
- count: {
11
- type: Number,
12
- required: true,
13
- },
14
- }, { _id: false, minimize: false });
5
+ const constants_1 = require("../../constants");
15
6
  exports.TenantHrShiftSchema = new mongoose_1.Schema({
16
7
  _id: {
17
8
  type: mongoose_1.Schema.Types.ObjectId,
@@ -40,13 +31,36 @@ exports.TenantHrShiftSchema = new mongoose_1.Schema({
40
31
  min: 0,
41
32
  max: 86399,
42
33
  },
34
+ break_start_time: {
35
+ type: Number,
36
+ default: null,
37
+ min: 0,
38
+ max: 86399,
39
+ },
40
+ break_end_time: {
41
+ type: Number,
42
+ default: null,
43
+ min: 0,
44
+ max: 86399,
45
+ },
46
+ working_days: {
47
+ type: [String],
48
+ enum: constants_1.ALL_DAY_INDEX,
49
+ required: true,
50
+ validate: {
51
+ validator: (days) => Array.isArray(days) && days.length > 0,
52
+ message: 'working_days must contain at least one day',
53
+ },
54
+ },
43
55
  grace_period_minutes: {
44
56
  type: Number,
45
57
  default: null,
46
58
  },
47
- required_positions: {
48
- type: [hrRequiredPositionSchema],
49
- default: [],
59
+ overtime_start_time: {
60
+ type: Number,
61
+ default: null,
62
+ min: 0,
63
+ max: 86399,
50
64
  },
51
65
  is_active: {
52
66
  type: Boolean,
@@ -13,12 +13,12 @@ export interface ITenantHrAttendanceRecord {
13
13
  tenant_id: string;
14
14
  employee_id: string;
15
15
  attendance_date: string;
16
- schedule_id: string;
16
+ shift_id: string;
17
17
  clock_time: ITenantHrClockTime[];
18
18
  break_time: ITenantHrBreakTime[];
19
19
  total_break_time: number;
20
20
  total_worked_time: number;
21
21
  status: HR_ATTENDANCE_STATUS_ENUM;
22
22
  createdAt: Date;
23
- updatedAt: Date | null;
23
+ updatedAt: Date;
24
24
  }
@@ -32,11 +32,9 @@ export interface ITenantHrEmployee {
32
32
  pay_type: HR_PAY_TYPE_ENUM;
33
33
  salary_per_hour?: number | null;
34
34
  monthly_salary?: number | null;
35
- hr_working_days_per_month: number;
36
- hr_hours_per_working_day: number;
37
35
  hr_overtime_multiplier: number;
38
36
  leave_allowance?: Partial<Record<HR_LEAVE_TYPE_ENUM, number>>;
39
- docs: Record<HR_DOCUMENT_TYPE_ENUM, ITenantHrEmployeeDocument>;
37
+ docs: Partial<Record<HR_DOCUMENT_TYPE_ENUM, ITenantHrEmployeeDocument>>;
40
38
  notes?: string | null;
41
39
  createdAt: Date;
42
40
  updatedAt: Date;
@@ -1,18 +1,11 @@
1
- import { DAY_INDEX_ENUM, HR_SHIFT_STATUS_ENUM, HR_SHIFT_TYPE_ENUM } from '../../constants';
2
1
  export interface ITenantHrShiftSchedule {
3
2
  _id: string;
4
3
  tenant_id: string;
5
4
  employee_id: string;
6
- day_indexes: DAY_INDEX_ENUM[];
5
+ shift_id: string;
7
6
  start_date: Date;
8
7
  end_date?: Date | null;
9
- start_time: number;
10
- end_time: number;
11
- position?: string | null;
12
- type: HR_SHIFT_TYPE_ENUM;
13
- status: HR_SHIFT_STATUS_ENUM;
14
8
  notes?: string | null;
15
- shift_id?: string | null;
16
9
  createdAt: Date;
17
- updatedAt: Date | null;
10
+ updatedAt: Date;
18
11
  }
@@ -1,16 +1,16 @@
1
- export interface ITenantHrRequiredPosition {
2
- position: string;
3
- count: number;
4
- }
1
+ import { DAY_INDEX_ENUM } from '../../constants';
5
2
  export interface ITenantHrShift {
6
3
  _id: string;
7
4
  tenant_id: string;
8
5
  name: string;
9
6
  start_time: number;
10
7
  end_time: number;
8
+ break_start_time?: number | null;
9
+ break_end_time?: number | null;
10
+ working_days: DAY_INDEX_ENUM[];
11
11
  grace_period_minutes?: number | null;
12
- required_positions: ITenantHrRequiredPosition[];
12
+ overtime_start_time?: number | null;
13
13
  is_active: boolean;
14
14
  createdAt: Date;
15
- updatedAt: Date | null;
15
+ updatedAt: Date;
16
16
  }
@@ -0,0 +1,274 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const constants_1 = require("../constants");
4
+ const halfhalf_setup_helpers_1 = require("../helpers/utils/halfhalf-setup-helpers");
5
+ const specials_helpers_1 = require("../helpers/utils/specials-helpers");
6
+ // ============================================================================
7
+ // Fixed setup discounts must scale with quantity.
8
+ //
9
+ // `convertItemDiscountToOrderItemDiscount` stores `special_discount` as a
10
+ // PER-UNIT amount. The shared totals math subtracts a fixed discount once per
11
+ // line, so the setup converters must scale it to the selected quantity (the
12
+ // same convention the cart/classic drawer use in getItemQuantityChangeResults).
13
+ //
14
+ // These tests pin:
15
+ // - fixed discounts at quantity 1 / 2,
16
+ // - percentage discounts staying unscaled (applied to the line total),
17
+ // - edit scaling (stored line amount -> new quantity),
18
+ // - self-healing of legacy lines that kept the per-unit amount at qty > 1,
19
+ // - manual discount slots scaling from the previous quantity,
20
+ // - the same behavior in both half-half converters.
21
+ // ============================================================================
22
+ const PLATFORM = constants_1.PLATFORMS_ENUM.POS_WALK_IN;
23
+ // ---------------------------------------------------------------------------
24
+ // Fixtures
25
+ // ---------------------------------------------------------------------------
26
+ function makeSlotItem(itemId, price) {
27
+ return {
28
+ _id: `slot-${itemId}`,
29
+ item_id: itemId,
30
+ menu_id: 'menu-1',
31
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.ITEM,
32
+ name: `Item ${itemId}`,
33
+ price,
34
+ subtotal: price,
35
+ quantity: 1,
36
+ special_instructions: '',
37
+ item_discount_details: null,
38
+ tax_rate: 0,
39
+ modifiers: null,
40
+ _discount_amount: 0,
41
+ _gross_amount: 0,
42
+ _gst_amount: 0,
43
+ _net_amount: 0,
44
+ };
45
+ }
46
+ function makeWorkableSpecial({ price = 1000, discount = null, isPercentage = false, } = {}) {
47
+ return {
48
+ _id: 'special-1',
49
+ name: 'Deal',
50
+ description: '',
51
+ sold_out: [],
52
+ image_url: '',
53
+ category_id: 'combo-cat',
54
+ price: { BASE_PRICE: price },
55
+ discount_amount: discount == null ? null : { BASE_PRICE: discount },
56
+ is_discount_percentage: isPercentage,
57
+ display_price: null,
58
+ show_starting_from: false,
59
+ modifier_specials: [
60
+ {
61
+ _id: 'mod-1',
62
+ name: 'Group',
63
+ quantity: 1,
64
+ num_free_items: 0,
65
+ items: [],
66
+ exclusive_refs: [],
67
+ excluded_refs: [],
68
+ },
69
+ ],
70
+ };
71
+ }
72
+ function convertSpecial(quantity, options = {}, existingOrderItem) {
73
+ return (0, specials_helpers_1.convertSpecialItemToOrderItem)({
74
+ specialItem: makeWorkableSpecial(options),
75
+ modifierSpecials: [{ _id: 'mod-1', selectedItems: [makeSlotItem('slot-item', 0)] }],
76
+ quantity,
77
+ platform: PLATFORM,
78
+ existingOrderItem,
79
+ });
80
+ }
81
+ function makeExistingSpecialLine({ quantity, specialDiscount, specialDiscountId = 'special-1', loyaltyDiscount, }) {
82
+ const item_discount_details = { total_discount: 0 };
83
+ if (specialDiscount != null) {
84
+ item_discount_details.special_discount = specialDiscount;
85
+ item_discount_details.special_discount_id = specialDiscountId;
86
+ item_discount_details.special_discount_name = 'Special Discount';
87
+ item_discount_details.is_special_discount_percentage = false;
88
+ item_discount_details.total_discount += specialDiscount;
89
+ }
90
+ if (loyaltyDiscount != null) {
91
+ item_discount_details.loyalty_discount = loyaltyDiscount;
92
+ item_discount_details.loyalty_discount_id = 'loyalty-offer-1';
93
+ item_discount_details.loyalty_discount_name = 'Loyalty Discount';
94
+ item_discount_details.is_loyalty_discount_percentage = false;
95
+ item_discount_details.total_discount += loyaltyDiscount;
96
+ }
97
+ return {
98
+ ...makeSlotItem('slot-item', 0),
99
+ _id: 'existing-line',
100
+ item_id: 'special-1',
101
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.SPECIAL,
102
+ name: 'Deal',
103
+ price: 1000,
104
+ subtotal: 0,
105
+ quantity,
106
+ item_discount_details,
107
+ };
108
+ }
109
+ function makeWorkableHalfHalf({ discount = null, isPercentage = false, } = {}) {
110
+ return {
111
+ _id: 'halfhalf-1',
112
+ name: 'Half/Half',
113
+ description: '',
114
+ sold_out: [],
115
+ image_url: '',
116
+ choose_expensive_segment_price: false,
117
+ segments: [
118
+ { _id: 'seg-1', name: 'First Half', sort_id: 1 },
119
+ { _id: 'seg-2', name: 'Second Half', sort_id: 2 },
120
+ ],
121
+ category_id: 'pizza-cat',
122
+ excluded_refs: [],
123
+ exclusive_refs: [],
124
+ // Item-level price + two 500 segment options => 1100 per unit.
125
+ upsell_price: { BASE_PRICE: 100 },
126
+ discount_amount: discount == null ? null : { BASE_PRICE: discount },
127
+ is_discount_percentage: isPercentage,
128
+ items: [],
129
+ };
130
+ }
131
+ function makeHalfHalfSelections() {
132
+ return [makeSlotItem('half-a', 500), makeSlotItem('half-b', 500)];
133
+ }
134
+ function makeExistingHalfHalfLine({ quantity, specialDiscount, }) {
135
+ return {
136
+ ...makeSlotItem('half-a', 500),
137
+ _id: 'existing-halfhalf-line',
138
+ item_id: 'halfhalf-1',
139
+ item_type: constants_1.ORDER_ITEM_TYPE_ENUM.HALF_HALF,
140
+ name: 'Half/Half',
141
+ price: 100,
142
+ subtotal: 0,
143
+ quantity,
144
+ item_discount_details: {
145
+ special_discount: specialDiscount,
146
+ special_discount_id: 'halfhalf-1',
147
+ special_discount_name: 'Special Discount',
148
+ is_special_discount_percentage: false,
149
+ total_discount: specialDiscount,
150
+ },
151
+ };
152
+ }
153
+ // ---------------------------------------------------------------------------
154
+ // Specials
155
+ // ---------------------------------------------------------------------------
156
+ describe('convertSpecialItemToOrderItem: fixed discount scales with quantity', () => {
157
+ it('keeps quantity 1 unchanged', () => {
158
+ const orderItem = convertSpecial(1, { discount: 150 });
159
+ expect(orderItem.subtotal).toBe(850); // 1000 - 150
160
+ expect(orderItem.item_discount_details?.total_discount).toBe(150);
161
+ });
162
+ it('applies the discount once per unit at quantity 2', () => {
163
+ const orderItem = convertSpecial(2, { discount: 150 });
164
+ expect(orderItem.subtotal).toBe(1700); // 1000*2 - 150*2
165
+ expect(orderItem.item_discount_details?.total_discount).toBe(300);
166
+ });
167
+ it('does not scale percentage discounts (they apply to the line total)', () => {
168
+ const orderItem = convertSpecial(2, { discount: 10, isPercentage: true });
169
+ expect(orderItem.subtotal).toBe(1800); // 2000 - 10%
170
+ expect(orderItem.item_discount_details?.total_discount).toBe(200);
171
+ });
172
+ });
173
+ describe('convertSpecialItemToOrderItem: edit keeps the discount in sync', () => {
174
+ it('rebuilds the setup slot from the definition at the new quantity', () => {
175
+ const orderItem = convertSpecial(3, { discount: 150 }, makeExistingSpecialLine({ quantity: 2, specialDiscount: 300 }));
176
+ expect(orderItem.subtotal).toBe(2550); // 3000 - 150*3
177
+ expect(orderItem.item_discount_details?.total_discount).toBe(450);
178
+ expect(orderItem._id).toBe('existing-line');
179
+ });
180
+ it('heals legacy lines that stored the per-unit amount at quantity > 1', () => {
181
+ const orderItem = convertSpecial(2, { discount: 150 }, makeExistingSpecialLine({ quantity: 2, specialDiscount: 150 }));
182
+ expect(orderItem.subtotal).toBe(1700);
183
+ expect(orderItem.item_discount_details?.total_discount).toBe(300);
184
+ });
185
+ it('scales a manual discount slot from the previous quantity instead of rebuilding it', () => {
186
+ const orderItem = convertSpecial(3, { discount: 150 }, makeExistingSpecialLine({ quantity: 2, specialDiscount: 100, specialDiscountId: 'manual-discount' }));
187
+ expect(orderItem.subtotal).toBe(2850); // 3000 - (100 / 2 * 3)
188
+ expect(orderItem.item_discount_details?.special_discount_id).toBe('manual-discount');
189
+ expect(orderItem.item_discount_details?.total_discount).toBe(150);
190
+ });
191
+ it('rescales loyalty/voucher line amounts from the previous quantity', () => {
192
+ const orderItem = convertSpecial(3, { discount: 150 }, makeExistingSpecialLine({ quantity: 2, specialDiscount: 300, loyaltyDiscount: 200 }));
193
+ // Setup slot rebuilt at 3 units (450) + loyalty scaled 200/2*3 = 300.
194
+ expect(orderItem.item_discount_details?.special_discount).toBe(450);
195
+ expect(orderItem.item_discount_details?.loyalty_discount).toBe(300);
196
+ expect(orderItem.item_discount_details?.total_discount).toBe(750);
197
+ expect(orderItem.subtotal).toBe(2250); // 3000 - 750
198
+ });
199
+ it('applies a setup discount added after the line was created', () => {
200
+ const orderItem = convertSpecial(2, { discount: 150 }, makeExistingSpecialLine({ quantity: 2, loyaltyDiscount: 200 }));
201
+ expect(orderItem.item_discount_details?.special_discount_id).toBe('special-1');
202
+ expect(orderItem.item_discount_details?.special_discount).toBe(300);
203
+ expect(orderItem.item_discount_details?.loyalty_discount).toBe(200);
204
+ expect(orderItem.item_discount_details?.total_discount).toBe(500);
205
+ expect(orderItem.subtotal).toBe(1500); // 2000 - 500
206
+ });
207
+ it('clears a setup discount removed from the definition and keeps other slots', () => {
208
+ const orderItem = convertSpecial(2, {}, makeExistingSpecialLine({ quantity: 2, specialDiscount: 300, loyaltyDiscount: 200 }));
209
+ expect(orderItem.item_discount_details?.special_discount).toBeUndefined();
210
+ expect(orderItem.item_discount_details?.special_discount_id).toBeUndefined();
211
+ expect(orderItem.item_discount_details?.loyalty_discount).toBe(200);
212
+ expect(orderItem.item_discount_details?.total_discount).toBe(200);
213
+ expect(orderItem.subtotal).toBe(1800); // 2000 - 200
214
+ });
215
+ });
216
+ // ---------------------------------------------------------------------------
217
+ // Half-half
218
+ // ---------------------------------------------------------------------------
219
+ describe('convertHalfHalfToOrderItem: fixed discount scales with quantity', () => {
220
+ it('applies the discount once per unit at quantity 2', () => {
221
+ const orderItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToOrderItem)({
222
+ halfHalfItem: makeWorkableHalfHalf({ discount: 150 }),
223
+ selectedHalfHalfItems: makeHalfHalfSelections(),
224
+ quantity: 2,
225
+ platform: PLATFORM,
226
+ });
227
+ expect(orderItem.subtotal).toBe(1900); // (100 + 500 + 500) * 2 - 300
228
+ expect(orderItem.item_discount_details?.total_discount).toBe(300);
229
+ });
230
+ it('does not scale percentage discounts', () => {
231
+ const orderItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToOrderItem)({
232
+ halfHalfItem: makeWorkableHalfHalf({ discount: 10, isPercentage: true }),
233
+ selectedHalfHalfItems: makeHalfHalfSelections(),
234
+ quantity: 2,
235
+ platform: PLATFORM,
236
+ });
237
+ expect(orderItem.subtotal).toBe(1980); // 2200 - 10%
238
+ expect(orderItem.item_discount_details?.total_discount).toBe(220);
239
+ });
240
+ it('rebuilds the setup slot from the definition when editing', () => {
241
+ const orderItem = (0, halfhalf_setup_helpers_1.convertHalfHalfToOrderItem)({
242
+ halfHalfItem: makeWorkableHalfHalf({ discount: 150 }),
243
+ selectedHalfHalfItems: makeHalfHalfSelections(),
244
+ quantity: 3,
245
+ platform: PLATFORM,
246
+ existingOrderItem: makeExistingHalfHalfLine({ quantity: 2, specialDiscount: 150 }),
247
+ });
248
+ expect(orderItem.subtotal).toBe(2850); // 3300 - 450
249
+ expect(orderItem.item_discount_details?.total_discount).toBe(450);
250
+ expect(orderItem._id).toBe('existing-halfhalf-line');
251
+ });
252
+ });
253
+ describe('convertHalfHalfToOrderEngineItem: fixed discount scales with quantity', () => {
254
+ it('applies the discount once per unit at quantity 2', () => {
255
+ const engine = (0, halfhalf_setup_helpers_1.convertHalfHalfToOrderEngineItem)({
256
+ halfHalfItem: makeWorkableHalfHalf({ discount: 150 }),
257
+ selectedHalfHalfItems: makeHalfHalfSelections(),
258
+ quantity: 2,
259
+ platform: PLATFORM,
260
+ });
261
+ expect(engine.subtotal).toBe(1900);
262
+ expect(engine.item_discount_details?.total_discount).toBe(300);
263
+ });
264
+ it('does not scale percentage discounts', () => {
265
+ const engine = (0, halfhalf_setup_helpers_1.convertHalfHalfToOrderEngineItem)({
266
+ halfHalfItem: makeWorkableHalfHalf({ discount: 10, isPercentage: true }),
267
+ selectedHalfHalfItems: makeHalfHalfSelections(),
268
+ quantity: 2,
269
+ platform: PLATFORM,
270
+ });
271
+ expect(engine.subtotal).toBe(1980);
272
+ expect(engine.item_discount_details?.total_discount).toBe(220);
273
+ });
274
+ });
@@ -0,0 +1 @@
1
+ export {};