@darkpos/pricing 1.0.133 → 1.0.134

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.
@@ -904,8 +904,8 @@
904
904
  "kitchen": "open",
905
905
  "delivery": "none",
906
906
  "detailed": true,
907
- "fullyPaid": false,
908
- "fullyPicked": true,
907
+ "paid": false,
908
+ "picked": true,
909
909
  "invoice": "partial"
910
910
  },
911
911
  "attributes": [],
@@ -559,45 +559,45 @@ describe('Order actions', () => {
559
559
  expect(itemBalance).toEqual(1.25);
560
560
 
561
561
  // paying with a paymenttype that doesn match the payment modifiers
562
- const fullyPaidOrderWithCredit = pricingService.order.calculate(testOrder, {
562
+ const paidOrderWithCredit = pricingService.order.calculate(testOrder, {
563
563
  paymentType: 'credit',
564
564
  amountToPay: 1.25,
565
565
  lockPaymentModifiers: true,
566
566
  });
567
- fullyPaidOrderWithCredit.items[0].totalPaid += 1.25;
568
- fullyPaidOrderWithCredit.totalPaid += 1.25;
567
+ paidOrderWithCredit.items[0].totalPaid += 1.25;
568
+ paidOrderWithCredit.totalPaid += 1.25;
569
569
 
570
570
  const orderBalanceWithCredit = pricingService.order.getOrdersBalance({
571
- orders: [fullyPaidOrderWithCredit],
571
+ orders: [paidOrderWithCredit],
572
572
  });
573
573
  const itemBalanceWithCredit = pricingService.item.getItemsBalance({
574
- items: fullyPaidOrderWithCredit.items,
574
+ items: paidOrderWithCredit.items,
575
575
  });
576
576
 
577
- expect(fullyPaidOrderWithCredit).toHaveProperty('total', 11.59);
578
- expect(fullyPaidOrderWithCredit).toHaveProperty('subTotal', 13.5);
579
- expect(fullyPaidOrderWithCredit).toHaveProperty('subTotals', {
577
+ expect(paidOrderWithCredit).toHaveProperty('total', 11.59);
578
+ expect(paidOrderWithCredit).toHaveProperty('subTotal', 13.5);
579
+ expect(paidOrderWithCredit).toHaveProperty('subTotals', {
580
580
  discount: -2.585,
581
581
  fee: 0.675,
582
582
  });
583
583
 
584
- expect(fullyPaidOrderWithCredit.items[0].modifiers).toHaveLength(3);
584
+ expect(paidOrderWithCredit.items[0].modifiers).toHaveLength(3);
585
585
 
586
- expect(fullyPaidOrderWithCredit.items[0].modifiers[0]._computed).toEqual(
586
+ expect(paidOrderWithCredit.items[0].modifiers[0]._computed).toEqual(
587
587
  expect.objectContaining({
588
588
  amount: 0,
589
589
  description: 'CASH 20% DISCOUNT',
590
590
  })
591
591
  );
592
592
 
593
- expect(fullyPaidOrderWithCredit.items[0].modifiers[1]._computed).toEqual(
593
+ expect(paidOrderWithCredit.items[0].modifiers[1]._computed).toEqual(
594
594
  expect.objectContaining({
595
595
  amount: 0.675,
596
596
  description: '5% FEE ($0.68)',
597
597
  })
598
598
  );
599
599
 
600
- expect(fullyPaidOrderWithCredit.items[0].modifiers[2]._computed).toEqual(
600
+ expect(paidOrderWithCredit.items[0].modifiers[2]._computed).toEqual(
601
601
  expect.objectContaining({
602
602
  amount: -2.585,
603
603
  description: '$2.59 discount (-$2.59)',
@@ -608,52 +608,52 @@ describe('Order actions', () => {
608
608
  expect(itemBalanceWithCredit).toEqual(0);
609
609
 
610
610
  // paying with a paymenttype that doesn match the payment modifiers
611
- const fullyPaidOrderWithCash = pricingService.order.calculate(testOrder, {
611
+ const paidOrderWithCash = pricingService.order.calculate(testOrder, {
612
612
  paymentType: 'cash',
613
613
  amountToPay: 1,
614
614
  lockPaymentModifiers: true,
615
615
  });
616
- fullyPaidOrderWithCash.items[0].totalPaid += 1;
617
- fullyPaidOrderWithCash.totalPaid += 1;
616
+ paidOrderWithCash.items[0].totalPaid += 1;
617
+ paidOrderWithCash.totalPaid += 1;
618
618
 
619
619
  const orderBalanceWithCash = pricingService.order.getOrdersBalance({
620
- orders: [fullyPaidOrderWithCash],
620
+ orders: [paidOrderWithCash],
621
621
  });
622
622
  const itemBalanceWithCash = pricingService.item.getItemsBalance({
623
- items: fullyPaidOrderWithCash.items,
623
+ items: paidOrderWithCash.items,
624
624
  });
625
625
 
626
- expect(fullyPaidOrderWithCash).toHaveProperty('total', 11.34);
627
- expect(fullyPaidOrderWithCash).toHaveProperty('subTotal', 13.5);
628
- expect(fullyPaidOrderWithCash).toHaveProperty('subTotals', {
626
+ expect(paidOrderWithCash).toHaveProperty('total', 11.34);
627
+ expect(paidOrderWithCash).toHaveProperty('subTotal', 13.5);
628
+ expect(paidOrderWithCash).toHaveProperty('subTotals', {
629
629
  discount: -2.835,
630
630
  fee: 0.675,
631
631
  });
632
632
 
633
- expect(fullyPaidOrderWithCash.items[0].modifiers).toHaveLength(4);
633
+ expect(paidOrderWithCash.items[0].modifiers).toHaveLength(4);
634
634
 
635
- expect(fullyPaidOrderWithCash.items[0].modifiers[0]._computed).toEqual(
635
+ expect(paidOrderWithCash.items[0].modifiers[0]._computed).toEqual(
636
636
  expect.objectContaining({
637
637
  amount: 0,
638
638
  description: 'CASH 20% DISCOUNT',
639
639
  })
640
640
  );
641
641
 
642
- expect(fullyPaidOrderWithCash.items[0].modifiers[1]._computed).toEqual(
642
+ expect(paidOrderWithCash.items[0].modifiers[1]._computed).toEqual(
643
643
  expect.objectContaining({
644
644
  amount: 0.675,
645
645
  description: '5% FEE ($0.68)',
646
646
  })
647
647
  );
648
648
 
649
- expect(fullyPaidOrderWithCash.items[0].modifiers[2]._computed).toEqual(
649
+ expect(paidOrderWithCash.items[0].modifiers[2]._computed).toEqual(
650
650
  expect.objectContaining({
651
651
  amount: -0.25,
652
652
  description: '$0.25 discount (-$0.25)',
653
653
  })
654
654
  );
655
655
 
656
- expect(fullyPaidOrderWithCash.items[0].modifiers[3]._computed).toEqual(
656
+ expect(paidOrderWithCash.items[0].modifiers[3]._computed).toEqual(
657
657
  expect.objectContaining({
658
658
  amount: -2.585,
659
659
  description: '$2.59 discount (-$2.59)',
@@ -3743,7 +3743,7 @@ describe('Order actions', () => {
3743
3743
  const newOrder = pricing.order.calculate(order);
3744
3744
 
3745
3745
  expect(newOrder).toHaveProperty('total', 0);
3746
- expect(newOrder.status).toMatchObject({ fullyPaid: true });
3746
+ expect(newOrder.status).toMatchObject({ paid: true });
3747
3747
  expect(newOrder.items[0].total).toBe(0);
3748
3748
  expect(newOrder.items[0].status).toMatchObject({
3749
3749
  paid: {
@@ -3770,11 +3770,11 @@ describe('Order actions', () => {
3770
3770
  const pricing = usePricing({
3771
3771
  store: { _settings: { order: { autoMarkAsPaid: true } } },
3772
3772
  });
3773
- const order = { items: [orderItem], status: { fullyPaid: true } };
3773
+ const order = { items: [orderItem], status: { paid: true } };
3774
3774
  const newOrder = pricing.order.calculate(order);
3775
3775
 
3776
3776
  expect(newOrder).toHaveProperty('total', 25);
3777
- expect(newOrder.status).toMatchObject({ fullyPaid: false });
3777
+ expect(newOrder.status).toMatchObject({ paid: false });
3778
3778
  expect(newOrder.items[0].total).toBe(25);
3779
3779
  expect(newOrder.items[0].status).toMatchObject({
3780
3780
  paid: undefined,
@@ -3783,7 +3783,7 @@ describe('Order actions', () => {
3783
3783
  const newOrder2 = pricingService.order.calculate(order);
3784
3784
 
3785
3785
  expect(newOrder2).toHaveProperty('total', 25);
3786
- expect(newOrder2.status).toMatchObject({ fullyPaid: true });
3786
+ expect(newOrder2.status).toMatchObject({ paid: true });
3787
3787
  expect(newOrder2.items[0].total).toBe(25);
3788
3788
  expect(newOrder2.items[0].status).toMatchObject({ paid: { value: true } });
3789
3789
  });
@@ -3933,4 +3933,37 @@ describe('Order actions', () => {
3933
3933
  expect(parentCount).toBe(1);
3934
3934
  expect(result).toEqual(items);
3935
3935
  });
3936
+
3937
+ test('Should remove notes with no message, file, or url', () => {
3938
+ const order = {
3939
+ notes: [
3940
+ { message: '', file: '', url: '' }, // empty
3941
+ { message: 'Hello', file: '', url: '' }, // valid
3942
+ { message: '', file: 'a.pdf', url: '' }, // valid
3943
+ { message: '', file: '', url: 'http://x.com' }, // valid
3944
+ ],
3945
+ };
3946
+
3947
+ const { removeEmptyNotes } = pricingService.order;
3948
+ const result = removeEmptyNotes(order);
3949
+
3950
+ expect(result.notes.length).toBe(3);
3951
+ expect(result.notes).toEqual([
3952
+ { message: 'Hello', file: '', url: '' },
3953
+ { message: '', file: 'a.pdf', url: '' },
3954
+ { message: '', file: '', url: 'http://x.com' },
3955
+ ]);
3956
+ });
3957
+
3958
+ test('Should return order unchanged if notes is missing or not an array', () => {
3959
+ const { removeEmptyNotes } = pricingService.order;
3960
+
3961
+ const order1 = {};
3962
+ const order2 = { notes: null };
3963
+ const order3 = { notes: 'invalid' };
3964
+
3965
+ expect(removeEmptyNotes(order1)).toEqual(order1);
3966
+ expect(removeEmptyNotes(order2)).toEqual(order2);
3967
+ expect(removeEmptyNotes(order3)).toEqual(order3);
3968
+ });
3936
3969
  });
@@ -5,7 +5,7 @@ const getDefaultSettings = schedules => ({
5
5
  store: {
6
6
  _settings: {
7
7
  schedule: {
8
- close: [
8
+ closed: [
9
9
  {
10
10
  date: '2024-09-03',
11
11
  },
@@ -14,9 +14,9 @@ describe('Order actions - unpick order', () => {
14
14
  quantity: 2,
15
15
  status: { picked: { value: true, date: new Date() } },
16
16
  };
17
- const order = { items: [orderItem], status: { fullyPicked: true } };
17
+ const order = { items: [orderItem], status: { picked: true } };
18
18
  const newOrder = pricingService.order.unpickOrder(order);
19
- expect(newOrder.status.fullyPicked).toBe(false);
19
+ expect(newOrder.status.picked).toBe(false);
20
20
  newOrder.items.map(item =>
21
21
  expect(item.status.picked).toStrictEqual({ value: false, date: '' })
22
22
  );
@@ -28,7 +28,7 @@ describe('Order actions - unpick order', () => {
28
28
  status: { picked: { value: true, date: new Date() } },
29
29
  };
30
30
  const order = {
31
- status: { fullyPicked: true },
31
+ status: { picked: true },
32
32
  items: [
33
33
  orderItem,
34
34
  orderItem,
@@ -43,7 +43,7 @@ describe('Order actions - unpick order', () => {
43
43
  ],
44
44
  };
45
45
  const newOrder = pricingService.order.unpickOrder(order);
46
- expect(newOrder.status.fullyPicked).toBe(false);
46
+ expect(newOrder.status.picked).toBe(false);
47
47
  newOrder.items.map(item =>
48
48
  expect(item.status.picked).toStrictEqual({ value: false, date: '' })
49
49
  );
@@ -61,10 +61,10 @@ describe('Order actions - unpick order', () => {
61
61
  };
62
62
  const order = {
63
63
  items: [orderItem, orderItemNotPicked],
64
- status: { fullyPicked: true },
64
+ status: { picked: true },
65
65
  };
66
66
  const newOrder = pricingService.order.unpickOrder(order);
67
- expect(newOrder.status.fullyPicked).toBe(false);
67
+ expect(newOrder.status.picked).toBe(false);
68
68
  newOrder.items.map(item =>
69
69
  expect(item.status.picked).toStrictEqual({ value: false, date: '' })
70
70
  );
@@ -77,18 +77,18 @@ describe('Order actions - unpick order', () => {
77
77
  status: { picked: { value: true, date: new Date() } },
78
78
  };
79
79
 
80
- const subOrder = { items: [orderItem], status: { fullyPicked: true } };
80
+ const subOrder = { items: [orderItem], status: { picked: true } };
81
81
  const order = {
82
82
  items: [orderItem],
83
83
  orders: [subOrder],
84
- status: { fullyPicked: true },
84
+ status: { picked: true },
85
85
  };
86
86
  const newOrder = pricingService.order.unpickOrder(order);
87
87
  newOrder.items.map(item =>
88
88
  expect(item.status.picked).toStrictEqual({ value: false, date: '' })
89
89
  );
90
90
  newOrder.orders.map(_order => {
91
- expect(_order.status.fullyPicked).toBe(false);
91
+ expect(_order.status.picked).toBe(false);
92
92
  return _order.items.map(item =>
93
93
  expect(item.status.picked).toStrictEqual({ value: false, date: '' })
94
94
  );
@@ -2,13 +2,13 @@ const Order = Object.freeze({
2
2
  OPEN: 'open',
3
3
  HOLD: 'hold',
4
4
  VOID: 'void',
5
- CLOSED: 'close',
5
+ CLOSED: 'closed',
6
6
  });
7
7
 
8
8
  const Invoice = Object.freeze({
9
9
  PARTIAL: 'partial',
10
10
  PENDING: 'pending',
11
- CLOSED: 'close',
11
+ CLOSED: 'closed',
12
12
  });
13
13
 
14
14
  const Kitchen = Object.freeze({
@@ -5,7 +5,7 @@ module.exports = ({ utils, actions, modifierActions }) => {
5
5
  const selectedSubItemIndex = subItems.findIndex(
6
6
  subItem =>
7
7
  modifierActions.hasCreditModifier(subItem.modifiers) &&
8
- !actions.isFullyPaid(subItem) &&
8
+ !actions.isPaid(subItem) &&
9
9
  subItem.total > difference
10
10
  );
11
11
 
@@ -5,7 +5,7 @@ module.exports = ({ utils, actions, modifierActions, _ }) => {
5
5
  const selectedSubItemIndex = subItems.findIndex(
6
6
  subItem =>
7
7
  modifierActions.hasFixedModifier(subItem.modifiers) &&
8
- !actions.isFullyPaid(subItem) &&
8
+ !actions.isPaid(subItem) &&
9
9
  subItem.total > difference
10
10
  );
11
11
 
@@ -5,14 +5,11 @@ module.exports = ({ actions, settings }) =>
5
5
 
6
6
  const localStatus = status || {};
7
7
 
8
- if (actions.isFullyPaid({ item: { status: localStatus } }) && total !== 0) {
8
+ if (actions.isPaid({ item: { status: localStatus } }) && total !== 0) {
9
9
  return { ...localStatus, paid: undefined };
10
10
  }
11
11
 
12
- if (
13
- !actions.isFullyPaid({ item: { status: localStatus } }) &&
14
- total === 0
15
- ) {
12
+ if (!actions.isPaid({ item: { status: localStatus } }) && total === 0) {
16
13
  return { ...localStatus, paid: { value: true, date: new Date() } };
17
14
  }
18
15
 
package/lib/item/index.js CHANGED
@@ -29,7 +29,7 @@ const isRepairOnly = require('./isRepairOnly');
29
29
  const hasCreateSubscription = require('./hasCreateSubscription');
30
30
  const getItemModifiers = require('./getItemModifiers');
31
31
  const getItemsBalance = require('./getItemsBalance');
32
- const isFullyPaid = require('./isFullyPaid');
32
+ const isPaid = require('./isPaid');
33
33
  const getTotalPrice = require('./getTotalPrice');
34
34
  const getItems = require('./getItems');
35
35
  const getAmounts = require('./getAmounts');
@@ -118,7 +118,7 @@ const itemActions = (deps = {}) => {
118
118
  hasCreateSubscription: hasCreateSubscription(innerDeps),
119
119
  getItemModifiers: getItemModifiers(innerDeps),
120
120
  getItemsBalance: getItemsBalance(innerDeps),
121
- isFullyPaid: isFullyPaid(innerDeps),
121
+ isPaid: isPaid(innerDeps),
122
122
  getTotalPrice: getTotalPrice(innerDeps),
123
123
  getItems: getItems(innerDeps),
124
124
  getAmounts: getAmounts(innerDeps),
@@ -1,5 +1,5 @@
1
1
  module.exports = () =>
2
- function isFullyPaid({ item }) {
2
+ function isPaid({ item }) {
3
3
  if (!item) return false;
4
4
 
5
5
  return item.status && item.status.paid && item.status.paid.value;
@@ -123,7 +123,7 @@ module.exports = ({
123
123
 
124
124
  const itemIndex = calculatedItems.findIndex(
125
125
  item =>
126
- !itemActions.isFullyPaid(item) &&
126
+ !itemActions.isPaid(item) &&
127
127
  item.modifiers.some(
128
128
  mod =>
129
129
  modifierActions.isPercentage(mod) ||
@@ -26,8 +26,8 @@ module.exports = ({ actions, settings, _ }) => {
26
26
  order: 'open',
27
27
  delivery: status.delivery || false,
28
28
  detailed: status.detailed || false,
29
- fullyPaid: false,
30
- fullyPicked: false,
29
+ paid: false,
30
+ picked: false,
31
31
  },
32
32
  items,
33
33
  });
@@ -5,18 +5,12 @@ module.exports = ({ actions, settings }) =>
5
5
 
6
6
  const localStatus = status || {};
7
7
 
8
- if (
9
- actions.isFullyPaid({ order: { status: localStatus } }) &&
10
- total !== 0
11
- ) {
12
- return { ...localStatus, fullyPaid: false };
8
+ if (actions.isPaid({ order: { status: localStatus } }) && total !== 0) {
9
+ return { ...localStatus, paid: false };
13
10
  }
14
11
 
15
- if (
16
- !actions.isFullyPaid({ order: { status: localStatus } }) &&
17
- total === 0
18
- ) {
19
- return { ...localStatus, fullyPaid: true };
12
+ if (!actions.isPaid({ order: { status: localStatus } }) && total === 0) {
13
+ return { ...localStatus, paid: true };
20
14
  }
21
15
 
22
16
  return localStatus;
@@ -89,12 +89,13 @@ const resetItem = require('./resetItem');
89
89
  const splitItems = require('./splitItems');
90
90
  const getNewItems = require('./getNewItems');
91
91
  const mapSubOrders = require('./mapSubOrders');
92
- const isFullyPaid = require('./isFullyPaid');
92
+ const isPaid = require('./isPaid');
93
93
  const getUpdatedStatus = require('./getUpdatedStatus');
94
94
  const setPieces = require('./setPieces');
95
95
  const copyItemToParents = require('./copyItemToParents');
96
96
  const getItemsWithParents = require('./getItemsWithParents');
97
97
  const addModifiersToParentItem = require('./addModifiersToParentItem');
98
+ const removeEmptyNotes = require('./removeEmptyNotes');
98
99
 
99
100
  const orderActions = (deps = {}) => {
100
101
  const actions = {};
@@ -195,12 +196,13 @@ const orderActions = (deps = {}) => {
195
196
  splitItems: splitItems(innerDeps),
196
197
  getNewItems: getNewItems(innerDeps),
197
198
  mapSubOrders: mapSubOrders(innerDeps),
198
- isFullyPaid: isFullyPaid(innerDeps),
199
+ isPaid: isPaid(innerDeps),
199
200
  getUpdatedStatus: getUpdatedStatus(innerDeps),
200
201
  setPieces: setPieces(innerDeps),
201
202
  copyItemToParents: copyItemToParents(innerDeps),
202
203
  getItemsWithParents: getItemsWithParents(innerDeps),
203
204
  addModifiersToParentItem: addModifiersToParentItem(innerDeps),
205
+ removeEmptyNotes: removeEmptyNotes(innerDeps),
204
206
  });
205
207
 
206
208
  Object.keys(freezedActions).forEach(actionName => {
@@ -0,0 +1,6 @@
1
+ module.exports = () =>
2
+ function isPaid({ order }) {
3
+ if (!order) return false;
4
+
5
+ return order.status && order.status.paid;
6
+ };
@@ -0,0 +1,11 @@
1
+ module.exports = () =>
2
+ function removeEmptyNotes(order) {
3
+ if (!order || !Array.isArray(order.notes)) return order;
4
+
5
+ return {
6
+ ...order,
7
+ notes: order.notes.filter(
8
+ note => !!note.message || !!note.file || !!note.url
9
+ ),
10
+ };
11
+ };
@@ -6,8 +6,8 @@ module.exports = ({ itemActions }) =>
6
6
  const orderItems = [...(order.items || [])].map(item =>
7
7
  itemActions.unpickItem(item)
8
8
  );
9
- if (nextOrder.status && nextOrder.status.fullyPicked) {
10
- nextOrder.status.fullyPicked = false;
9
+ if (nextOrder.status && nextOrder.status.picked) {
10
+ nextOrder.status.picked = false;
11
11
  }
12
12
  nextOrder.items = orderItems;
13
13
  }
@@ -17,8 +17,8 @@ module.exports = ({ itemActions }) =>
17
17
  ..._order,
18
18
  items: _order.items.map(item => itemActions.unpickItem(item)),
19
19
  };
20
- if (nextsubOrder.status && nextsubOrder.status.fullyPicked) {
21
- nextsubOrder.status.fullyPicked = false;
20
+ if (nextsubOrder.status && nextsubOrder.status.picked) {
21
+ nextsubOrder.status.picked = false;
22
22
  }
23
23
  return nextsubOrder;
24
24
  });
@@ -35,9 +35,9 @@ module.exports = ({ settings, _, moment }) => {
35
35
 
36
36
  const getClosedDays = () => {
37
37
  const schedule = _.get(settings, 'schedule', {});
38
- const { close = [] } = schedule;
39
- if (!Array.isArray(close)) return [];
40
- return close;
38
+ const { closed = [] } = schedule;
39
+ if (!Array.isArray(closed)) return [];
40
+ return closed;
41
41
  };
42
42
 
43
43
  const MAX_ADD_DAYS = 365;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.133",
3
+ "version": "1.0.134",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -52,5 +52,5 @@
52
52
  "supertest": "^6.2.3",
53
53
  "supervisor": "^0.12.0"
54
54
  },
55
- "gitHead": "1cec04f4a6fc32238922712068994984b62ab92d"
55
+ "gitHead": "cfe52c49a64c3418b808a7c5ce7f76324b8340a5"
56
56
  }
@@ -1,6 +0,0 @@
1
- module.exports = () =>
2
- function isFullyPaid({ order }) {
3
- if (!order) return false;
4
-
5
- return order.status && order.status.fullyPaid;
6
- };