@darkpos/pricing 1.0.23 → 1.0.24

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.
@@ -126,21 +126,21 @@ describe('Order actions', () => {
126
126
  });
127
127
  expect(newOrder.items[0]).toHaveProperty('total', 58.29);
128
128
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
129
- discount: -1.71,
129
+ discount: -1.7142857142857142,
130
130
  _included: 0,
131
- _xincluded: -1.71,
131
+ _xincluded: -1.7142857142857142,
132
132
  _direct: 0,
133
- _xdirect: -1.71,
133
+ _xdirect: -1.7142857142857142,
134
134
  _simple: 60,
135
135
  _actual: 60,
136
136
  });
137
137
  expect(newOrder.items[1]).toHaveProperty('total', 9.71);
138
138
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
139
- discount: -0.29,
139
+ discount: -0.2857142857142857,
140
140
  _included: 0,
141
- _xincluded: -0.29,
141
+ _xincluded: -0.2857142857142857,
142
142
  _direct: 0,
143
- _xdirect: -0.29,
143
+ _xdirect: -0.2857142857142857,
144
144
  _simple: 10,
145
145
  _actual: 10,
146
146
  });
@@ -168,28 +168,28 @@ describe('Order actions', () => {
168
168
 
169
169
  const order = { items: [item1, item2], modifiers: [modifier1] };
170
170
  const newOrder = pricingService.order.calculate(order);
171
- expect(newOrder).toHaveProperty('total', 18.57);
171
+ expect(newOrder).toHaveProperty('total', 18.58);
172
172
  expect(newOrder).toHaveProperty('subTotal', 20.64);
173
173
  expect(newOrder).toHaveProperty('subTotals', {
174
- discount: -2.07,
174
+ discount: -2.06,
175
175
  });
176
176
  expect(newOrder.items[0]).toHaveProperty('total', 14.39);
177
177
  expect(newOrder.items[0]).toHaveProperty('subTotals', {
178
- discount: -1.6,
178
+ discount: -1.599,
179
179
  _included: 0,
180
- _xincluded: -1.6,
180
+ _xincluded: -1.599,
181
181
  _direct: 0,
182
- _xdirect: -1.6,
182
+ _xdirect: -1.599,
183
183
  _simple: 15.99,
184
184
  _actual: 15.99,
185
185
  });
186
- expect(newOrder.items[1]).toHaveProperty('total', 4.18);
186
+ expect(newOrder.items[1]).toHaveProperty('total', 4.19);
187
187
  expect(newOrder.items[1]).toHaveProperty('subTotals', {
188
- discount: -0.47,
188
+ discount: -0.465,
189
189
  _included: 0,
190
- _xincluded: -0.47,
190
+ _xincluded: -0.465,
191
191
  _direct: 0,
192
- _xdirect: -0.47,
192
+ _xdirect: -0.465,
193
193
  _simple: 4.65,
194
194
  _actual: 4.65,
195
195
  });
@@ -683,33 +683,33 @@ describe('Order actions', () => {
683
683
  tax: 7.21,
684
684
  });
685
685
  expect(newOrder.items[0]).toHaveProperty('total', 80.6);
686
- expect(newOrder.items[1]).toHaveProperty('total', 13.7);
687
- expect(newOrder.items[2]).toHaveProperty('total', 5.9);
686
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
687
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
688
688
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
689
689
  'amount',
690
690
  13.2
691
691
  );
692
692
  expect(newOrder.items[0].modifiers[1].compute).toHaveProperty(
693
693
  'amount',
694
- 5.8
694
+ 5.797
695
695
  );
696
696
 
697
697
  expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
698
698
  'amount',
699
- 2.24
699
+ 2.2425
700
700
  );
701
701
  expect(newOrder.items[1].modifiers[1].compute).toHaveProperty(
702
702
  'amount',
703
- 0.99
703
+ 0.985025
704
704
  );
705
705
 
706
706
  expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
707
707
  'amount',
708
- 0.97
708
+ 0.9675
709
709
  );
710
710
  expect(newOrder.items[2].modifiers[1].compute).toHaveProperty(
711
711
  'amount',
712
- 0.42
712
+ 0.4247
713
713
  );
714
714
  });
715
715
 
@@ -775,8 +775,8 @@ describe('Order actions', () => {
775
775
  tax: 7.21,
776
776
  });
777
777
  expect(newOrder.items[0]).toHaveProperty('total', 80.6);
778
- expect(newOrder.items[1]).toHaveProperty('total', 13.7);
779
- expect(newOrder.items[2]).toHaveProperty('total', 5.9);
778
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
779
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
780
780
  expect(newOrder.items[0].modifiers[0].compute).toHaveProperty(
781
781
  'amount',
782
782
  13.2
@@ -788,20 +788,20 @@ describe('Order actions', () => {
788
788
 
789
789
  expect(newOrder.items[1].modifiers[0].compute).toHaveProperty(
790
790
  'amount',
791
- 2.24
791
+ 2.2425
792
792
  );
793
793
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
794
794
  'amount',
795
- 0.985025
795
+ 0.98483125
796
796
  );
797
797
 
798
798
  expect(newOrder.items[2].modifiers[0].compute).toHaveProperty(
799
799
  'amount',
800
- 0.97
800
+ 0.9675
801
801
  );
802
802
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
803
803
  'amount',
804
- 0.4247
804
+ 0.42489375
805
805
  );
806
806
  });
807
807
 
@@ -959,15 +959,15 @@ describe('Order actions', () => {
959
959
  tax: 7.21,
960
960
  });
961
961
  expect(newOrder.items[0]).toHaveProperty('total', 80.6);
962
- expect(newOrder.items[1]).toHaveProperty('total', 13.7);
963
- expect(newOrder.items[2]).toHaveProperty('total', 5.9);
962
+ expect(newOrder.items[1]).toHaveProperty('total', 13.69);
963
+ expect(newOrder.items[2]).toHaveProperty('total', 5.91);
964
964
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
965
965
  'amount',
966
966
  -13.2
967
967
  );
968
968
  expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
969
969
  'amount',
970
- 5.8
970
+ 5.797
971
971
  );
972
972
 
973
973
  expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
@@ -976,7 +976,7 @@ describe('Order actions', () => {
976
976
  );
977
977
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
978
978
  'amount',
979
- 0.99
979
+ 0.985025
980
980
  );
981
981
 
982
982
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
@@ -985,7 +985,7 @@ describe('Order actions', () => {
985
985
  );
986
986
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
987
987
  'amount',
988
- 0.42
988
+ 0.4247
989
989
  );
990
990
  });
991
991
 
@@ -1133,40 +1133,40 @@ describe('Order actions', () => {
1133
1133
 
1134
1134
  const newOrder = pricingService.order.calculate(order);
1135
1135
 
1136
- expect(newOrder).toHaveProperty('total', 2.15);
1136
+ expect(newOrder).toHaveProperty('total', 2.16);
1137
1137
  expect(newOrder).toHaveProperty('subTotal', 3);
1138
1138
  expect(newOrder).toHaveProperty('subTotals', {
1139
1139
  fixed: -1,
1140
- tax: 0.15,
1140
+ tax: 0.16,
1141
1141
  });
1142
1142
  expect(newOrder.items[0]).toHaveProperty('total', 0.72);
1143
1143
  expect(newOrder.items[1]).toHaveProperty('total', 0.72);
1144
- expect(newOrder.items[2]).toHaveProperty('total', 0.71);
1144
+ expect(newOrder.items[2]).toHaveProperty('total', 0.72);
1145
1145
  expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
1146
1146
  'amount',
1147
- -0.33
1147
+ -0.3333333333333334
1148
1148
  );
1149
1149
  expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
1150
1150
  'amount',
1151
- 0.05
1151
+ 0.051925
1152
1152
  );
1153
1153
 
1154
1154
  expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
1155
1155
  'amount',
1156
- -0.33
1156
+ -0.3333333333333333
1157
1157
  );
1158
1158
  expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
1159
1159
  'amount',
1160
- 0.05
1160
+ 0.051925
1161
1161
  );
1162
1162
 
1163
1163
  expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
1164
1164
  'amount',
1165
- -0.17
1165
+ -0.16666666666666666
1166
1166
  );
1167
1167
  expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
1168
1168
  'amount',
1169
- 0.05
1169
+ 0.051925
1170
1170
  );
1171
1171
  });
1172
1172
 
@@ -1261,14 +1261,23 @@ describe('Order actions', () => {
1261
1261
 
1262
1262
  const [item1, item2, item3] = newOrder.items;
1263
1263
  expect(newOrder).toHaveProperty('total', 12.5);
1264
- expect(item1).toHaveProperty('total', 3.66);
1265
- expect(item1.modifiers[1].compute).toHaveProperty('amount', 5.84);
1264
+ expect(item1).toHaveProperty('total', 3.65);
1265
+ expect(item1.modifiers[1].compute).toHaveProperty(
1266
+ 'amount',
1267
+ 5.846153846153846
1268
+ );
1266
1269
 
1267
1270
  expect(item2).toHaveProperty('total', 5.38);
1268
- expect(item2.modifiers[1].compute).toHaveProperty('amount', 8.62);
1271
+ expect(item2.modifiers[1].compute).toHaveProperty(
1272
+ 'amount',
1273
+ 8.615384615384615
1274
+ );
1269
1275
 
1270
1276
  expect(item3).toHaveProperty('total', 3.46);
1271
- expect(item3.modifiers[1].compute).toHaveProperty('amount', 5.54);
1277
+ expect(item3.modifiers[1].compute).toHaveProperty(
1278
+ 'amount',
1279
+ 5.538461538461538
1280
+ );
1272
1281
  });
1273
1282
 
1274
1283
  test('Auto split a Parent Order', () => {
@@ -1602,7 +1611,7 @@ describe('Order actions', () => {
1602
1611
  discount: -10,
1603
1612
  fee: 2,
1604
1613
  });
1605
- expect(newOrder.items[0]).toHaveProperty('total', 8.08);
1614
+ expect(newOrder.items[0]).toHaveProperty('total', 8.07);
1606
1615
  expect(newOrder.items[1]).toHaveProperty('total', 7.71);
1607
1616
  expect(newOrder.items[2]).toHaveProperty('total', 11.36);
1608
1617
  expect(newOrder.items[3]).toHaveProperty('total', 7.3);
@@ -1630,9 +1639,422 @@ describe('Order actions', () => {
1630
1639
  discount: -10,
1631
1640
  fee: 4,
1632
1641
  });
1633
- expect(newOrder.items[0]).toHaveProperty('total', 8.09);
1642
+ expect(newOrder.items[0]).toHaveProperty('total', 8.08);
1634
1643
  expect(newOrder.items[1]).toHaveProperty('total', 7.7);
1635
1644
  expect(newOrder.items[2]).toHaveProperty('total', 11.36);
1636
1645
  expect(newOrder.items[3]).toHaveProperty('total', 9.3);
1637
1646
  });
1647
+
1648
+ test('CU-8678p4ky3. Get Balance to Pay from OrderItems', () => {
1649
+ const orderItems = [
1650
+ {
1651
+ __typename: 'OrderItem',
1652
+ modifiers: [
1653
+ {
1654
+ __typename: 'Modifier',
1655
+ addModifiers: [],
1656
+ delModifiers: [],
1657
+ conditions: null,
1658
+ compute: {
1659
+ __typename: 'Compute',
1660
+ type: 'percentage',
1661
+ action: 'add',
1662
+ amount: 7.75,
1663
+ },
1664
+ _createdAt: '2023-08-22T16:30:44.899Z',
1665
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1666
+ _id: '64e4e29b9f97bb39b2c97833',
1667
+ modifierId: '63d43d0bc159330012809f6a',
1668
+ _parentId: null,
1669
+ locked: false,
1670
+ name: '7.75% Tax',
1671
+ sku: '',
1672
+ description: '',
1673
+ group: 'Tax',
1674
+ type: 'tax',
1675
+ attributes: ['sort'],
1676
+ color: '',
1677
+ backgroundColor: '',
1678
+ icon: '',
1679
+ url: '',
1680
+ tags: ['default'],
1681
+ order: 99,
1682
+ included: false,
1683
+ direct: true,
1684
+ hidden: true,
1685
+ print: true,
1686
+ required: true,
1687
+ recommended: false,
1688
+ default: false,
1689
+ code: '',
1690
+ properties: {
1691
+ sort: 99,
1692
+ },
1693
+ _computed: {
1694
+ amount: 0.42625,
1695
+ description: '7.75% Tax ($0.43)',
1696
+ },
1697
+ },
1698
+ ],
1699
+ notes: [],
1700
+ totalPaid: 0,
1701
+ status: {
1702
+ picked: {
1703
+ value: false,
1704
+ date: '',
1705
+ },
1706
+ paid: {
1707
+ value: false,
1708
+ date: '',
1709
+ },
1710
+ tracker: [],
1711
+ },
1712
+ _id: '64e4e29b9f97bb39b2c97832',
1713
+ itemId: '64d3a7632d91061420342650',
1714
+ name: 'NAPKIN CKTL SAMSARA',
1715
+ description: '',
1716
+ modifiersTotalAmount: 0,
1717
+ location: null,
1718
+ price: 5.5,
1719
+ pieces: 1,
1720
+ quantity: 1,
1721
+ path: [],
1722
+ menuId: '63d43ec012bb091db8c62f87',
1723
+ serial: null,
1724
+ sku: '025096975858',
1725
+ total: 5.93,
1726
+ subTotals: {
1727
+ _included: 0,
1728
+ _xincluded: 0.42625,
1729
+ _direct: 0.42625,
1730
+ _xdirect: 0,
1731
+ _simple: 5.5,
1732
+ _actual: 5.5,
1733
+ tax: 0.42625,
1734
+ },
1735
+ taxes: [],
1736
+ properties: false,
1737
+ },
1738
+ {
1739
+ __typename: 'OrderItem',
1740
+ modifiers: [
1741
+ {
1742
+ __typename: 'Modifier',
1743
+ addModifiers: [],
1744
+ delModifiers: [],
1745
+ conditions: null,
1746
+ compute: {
1747
+ __typename: 'Compute',
1748
+ type: 'percentage',
1749
+ action: 'add',
1750
+ amount: 7.75,
1751
+ },
1752
+ _createdAt: '2023-08-22T16:30:44.899Z',
1753
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1754
+ _id: '64e4e2939f97bb39b2c977f5',
1755
+ modifierId: '63d43d0bc159330012809f6a',
1756
+ _parentId: null,
1757
+ locked: false,
1758
+ name: '7.75% Tax',
1759
+ sku: '',
1760
+ description: '',
1761
+ group: 'Tax',
1762
+ type: 'tax',
1763
+ attributes: ['sort'],
1764
+ color: '',
1765
+ backgroundColor: '',
1766
+ icon: '',
1767
+ url: '',
1768
+ tags: ['default'],
1769
+ order: 99,
1770
+ included: false,
1771
+ direct: true,
1772
+ hidden: true,
1773
+ print: true,
1774
+ required: true,
1775
+ recommended: false,
1776
+ default: false,
1777
+ code: '',
1778
+ properties: {
1779
+ sort: 99,
1780
+ },
1781
+ _computed: {
1782
+ amount: 2.47225,
1783
+ description: '7.75% Tax ($2.47)',
1784
+ },
1785
+ },
1786
+ ],
1787
+ notes: [],
1788
+ totalPaid: 0,
1789
+ status: {
1790
+ picked: {
1791
+ value: false,
1792
+ date: '',
1793
+ },
1794
+ paid: {
1795
+ value: false,
1796
+ date: '',
1797
+ },
1798
+ tracker: [],
1799
+ },
1800
+ _id: '64e4e2939f97bb39b2c977f4',
1801
+ itemId: '64c58811c3b8118e1c2f144e',
1802
+ name: 'Boxwood Orb 2/Asst.',
1803
+ description: '',
1804
+ modifiersTotalAmount: 0,
1805
+ location: null,
1806
+ price: 15.95,
1807
+ pieces: 1,
1808
+ quantity: 2,
1809
+ path: [],
1810
+ menuId: '63d43ec012bb091db8c62f87',
1811
+ serial: null,
1812
+ sku: '023271797394',
1813
+ total: 34.37,
1814
+ subTotals: {
1815
+ _included: 0,
1816
+ _xincluded: 2.47225,
1817
+ _direct: 2.47225,
1818
+ _xdirect: 0,
1819
+ _simple: 31.9,
1820
+ _actual: 31.9,
1821
+ tax: 2.47225,
1822
+ },
1823
+ taxes: [],
1824
+ properties: false,
1825
+ },
1826
+ {
1827
+ __typename: 'OrderItem',
1828
+ modifiers: [
1829
+ {
1830
+ __typename: 'Modifier',
1831
+ addModifiers: [],
1832
+ delModifiers: [],
1833
+ conditions: null,
1834
+ compute: {
1835
+ __typename: 'Compute',
1836
+ type: 'percentage',
1837
+ action: 'add',
1838
+ amount: 7.75,
1839
+ },
1840
+ _createdAt: '2023-08-22T16:30:44.899Z',
1841
+ _updatedAt: '2023-08-22T16:30:44.899Z',
1842
+ _id: '64e4e2879f97bb39b2c97799',
1843
+ modifierId: '63d43d0bc159330012809f6a',
1844
+ _parentId: null,
1845
+ locked: false,
1846
+ name: '7.75% Tax',
1847
+ sku: '',
1848
+ description: '',
1849
+ group: 'Tax',
1850
+ type: 'tax',
1851
+ attributes: ['sort'],
1852
+ color: '',
1853
+ backgroundColor: '',
1854
+ icon: '',
1855
+ url: '',
1856
+ tags: ['default'],
1857
+ order: 99,
1858
+ included: false,
1859
+ direct: true,
1860
+ hidden: true,
1861
+ print: true,
1862
+ required: true,
1863
+ recommended: false,
1864
+ default: false,
1865
+ code: '',
1866
+ properties: {
1867
+ sort: 99,
1868
+ },
1869
+ _computed: {
1870
+ amount: 4.495,
1871
+ description: '7.75% Tax ($4.50)',
1872
+ },
1873
+ },
1874
+ ],
1875
+ notes: [],
1876
+ totalPaid: 0,
1877
+ status: {
1878
+ picked: {
1879
+ value: false,
1880
+ date: '',
1881
+ },
1882
+ paid: {
1883
+ value: false,
1884
+ date: '',
1885
+ },
1886
+ tracker: [],
1887
+ },
1888
+ _id: '64e4e2879f97bb39b2c97798',
1889
+ itemId: '6453fce8ecba74556efe8c71',
1890
+ name: 'BASKET WILLOW MARKET',
1891
+ description: '',
1892
+ modifiersTotalAmount: 0,
1893
+ location: null,
1894
+ price: 58,
1895
+ pieces: 1,
1896
+ quantity: 1,
1897
+ path: [],
1898
+ menuId: '63d43ec012bb091db8c62f87',
1899
+ serial: null,
1900
+ sku: 'LC1900',
1901
+ total: 62.5,
1902
+ subTotals: {
1903
+ _included: 0,
1904
+ _xincluded: 4.495,
1905
+ _direct: 4.495,
1906
+ _xdirect: 0,
1907
+ _simple: 58,
1908
+ _actual: 58,
1909
+ tax: 4.495,
1910
+ },
1911
+ taxes: [],
1912
+ properties: false,
1913
+ },
1914
+ ];
1915
+
1916
+ const balanceToPay = pricingService.item.getBalanceToPay({ orderItems });
1917
+
1918
+ expect(balanceToPay).toBe(102.79);
1919
+ });
1920
+ });
1921
+
1922
+ test('CU-8678p4ky3. Get Calculated order. Multiple Items. 2 Modifiers. 1 Item tax. 1 Orde discount', () => {
1923
+ const taxMod = {
1924
+ _id: 2,
1925
+ name: `7.75% tax`,
1926
+ type: 'tax',
1927
+ compute: {
1928
+ amount: 7.75,
1929
+ type: 'percentage',
1930
+ action: 'add',
1931
+ },
1932
+ properties: {
1933
+ sort: 2,
1934
+ },
1935
+ };
1936
+
1937
+ const discountMod = {
1938
+ _id: 1,
1939
+ compute: {
1940
+ amount: 15,
1941
+ type: 'percentage',
1942
+ action: 'subtract',
1943
+ },
1944
+ name: `15%`,
1945
+ type: 'percentage',
1946
+ properties: {
1947
+ sort: 1,
1948
+ },
1949
+ };
1950
+
1951
+ const item1 = {
1952
+ _id: 1,
1953
+ price: 35.95,
1954
+ quantity: 2,
1955
+ modifiers: [taxMod],
1956
+ };
1957
+ const item2 = {
1958
+ _id: 2,
1959
+ price: 28.95,
1960
+ quantity: 2,
1961
+ modifiers: [taxMod],
1962
+ };
1963
+ const item3 = {
1964
+ _id: 3,
1965
+ price: 17.95,
1966
+ quantity: 4,
1967
+ modifiers: [taxMod],
1968
+ };
1969
+ const item4 = {
1970
+ _id: 4,
1971
+ price: 158,
1972
+ quantity: 1,
1973
+ modifiers: [taxMod],
1974
+ };
1975
+ const item5 = {
1976
+ _id: 5,
1977
+ price: 148,
1978
+ quantity: 2,
1979
+ modifiers: [taxMod],
1980
+ };
1981
+ const item6 = {
1982
+ _id: 6,
1983
+ price: 120,
1984
+ quantity: 1,
1985
+ modifiers: [taxMod],
1986
+ };
1987
+
1988
+ const order = {
1989
+ items: [item1, item2, item3, item4, item5, item6],
1990
+ modifiers: [discountMod],
1991
+ };
1992
+
1993
+ const newOrder = pricingService.order.calculate(order);
1994
+
1995
+ expect(newOrder).toHaveProperty('total', 710.35);
1996
+ expect(newOrder).toHaveProperty('subTotal', 775.6);
1997
+ expect(newOrder).toHaveProperty('subTotals', {
1998
+ percentage: -116.34,
1999
+ tax: 51.09,
2000
+ });
2001
+ expect(newOrder.items[0]).toHaveProperty('total', 65.85);
2002
+ expect(newOrder.items[1]).toHaveProperty('total', 53.03);
2003
+ expect(newOrder.items[2]).toHaveProperty('total', 65.76);
2004
+ expect(newOrder.items[3]).toHaveProperty('total', 144.71);
2005
+ expect(newOrder.items[4]).toHaveProperty('total', 271.1);
2006
+ expect(newOrder.items[5]).toHaveProperty('total', 109.91);
2007
+ expect(newOrder.items[0].modifiers[0]._computed).toHaveProperty(
2008
+ 'amount',
2009
+ -10.785
2010
+ );
2011
+ expect(newOrder.items[0].modifiers[1]._computed).toHaveProperty(
2012
+ 'amount',
2013
+ 4.7364125
2014
+ );
2015
+
2016
+ expect(newOrder.items[1].modifiers[0]._computed).toHaveProperty(
2017
+ 'amount',
2018
+ -8.685
2019
+ );
2020
+ expect(newOrder.items[1].modifiers[1]._computed).toHaveProperty(
2021
+ 'amount',
2022
+ 3.8141625
2023
+ );
2024
+
2025
+ expect(newOrder.items[2].modifiers[0]._computed).toHaveProperty(
2026
+ 'amount',
2027
+ -10.77
2028
+ );
2029
+ expect(newOrder.items[2].modifiers[1]._computed).toHaveProperty(
2030
+ 'amount',
2031
+ 4.729825
2032
+ );
2033
+
2034
+ expect(newOrder.items[3].modifiers[0]._computed).toHaveProperty(
2035
+ 'amount',
2036
+ -23.7
2037
+ );
2038
+ expect(newOrder.items[3].modifiers[1]._computed).toHaveProperty(
2039
+ 'amount',
2040
+ 10.40825
2041
+ );
2042
+
2043
+ expect(newOrder.items[4].modifiers[0]._computed).toHaveProperty(
2044
+ 'amount',
2045
+ -44.4
2046
+ );
2047
+ expect(newOrder.items[4].modifiers[1]._computed).toHaveProperty(
2048
+ 'amount',
2049
+ 19.499
2050
+ );
2051
+
2052
+ expect(newOrder.items[5].modifiers[0]._computed).toHaveProperty(
2053
+ 'amount',
2054
+ -18
2055
+ );
2056
+ expect(newOrder.items[5].modifiers[1]._computed).toHaveProperty(
2057
+ 'amount',
2058
+ 7.905
2059
+ );
1638
2060
  });
@@ -1,5 +1,5 @@
1
1
  /* eslint-disable no-restricted-syntax */
2
- module.exports = ({ _, utils, modifierActions }) => {
2
+ module.exports = ({ _, utils, actions, modifierActions }) => {
3
3
  const { math } = utils;
4
4
  //
5
5
  const calculateOne = inputItem => {
@@ -98,9 +98,7 @@ module.exports = ({ _, utils, modifierActions }) => {
98
98
 
99
99
  subTotals._actual = math.add(subTotals._simple, subTotals._included);
100
100
 
101
- const total = math.toDecimalPlaces(
102
- math.add(subTotals._actual, subTotals._xincluded)
103
- );
101
+ const total = math.toDecimalPlaces(actions.getTotal({ subTotals }));
104
102
 
105
103
  return {
106
104
  ...item,
@@ -1,12 +1,12 @@
1
- module.exports = ({ utils }) =>
1
+ module.exports = ({ utils, actions }) =>
2
2
  function getBalanceToPay({ orderItems = [] }) {
3
3
  const total = orderItems.reduce(
4
- (t, item) => utils.math.add(t, item && item.total),
4
+ (t, item) => utils.math.add(actions.getTotal(item), t),
5
5
  0
6
6
  );
7
7
  const totalPaid = orderItems.reduce(
8
8
  (t, item) => utils.math.add(t, item && item.totalPaid),
9
9
  0
10
10
  );
11
- return utils.math.sub(total, totalPaid);
11
+ return utils.math.toDecimalPlaces(utils.math.sub(total, totalPaid));
12
12
  };
@@ -2,7 +2,6 @@ module.exports = ({ utils }) => {
2
2
  const { math } = utils;
3
3
  return function getTotal(item) {
4
4
  if (!item || !item.subTotals) return 0;
5
-
6
- return math.add(item.subTotals._simple, item.subTotals._xincluded);
5
+ return math.add(item.subTotals._actual, item.subTotals._xincluded);
7
6
  };
8
7
  };
@@ -16,14 +16,12 @@ module.exports = ({ _, utils, constants, actions }) => {
16
16
  let modifierAmount = amount;
17
17
 
18
18
  if (type === Modifier.Compute.Types.PERCENTAGE) {
19
- const modifierAmountByPercentage = math.toDecimalPlaces(
20
- math.div(
21
- math.mul(
22
- modifier.type === 'credit' ? options.orderTotal : options.itemTotal,
23
- amount
24
- ),
25
- 100
26
- )
19
+ const modifierAmountByPercentage = math.div(
20
+ math.mul(
21
+ modifier.type === 'credit' ? options.orderTotal : options.itemTotal,
22
+ amount
23
+ ),
24
+ 100
27
25
  );
28
26
  modifierAmount =
29
27
  maxAmount !== null && modifierAmountByPercentage > maxAmount
@@ -37,12 +35,10 @@ module.exports = ({ _, utils, constants, actions }) => {
37
35
  !math.isZero(options.orderTotal) &&
38
36
  (type !== Modifier.Compute.Types.PERCENTAGE || modifier.type === 'credit')
39
37
  ) {
40
- amountToApply = math.toDecimalPlaces(
41
- math.div(
42
- math.mul(modifierAmount, options.itemTotal),
43
- options.orderTotal,
44
- options.itemQuantity
45
- )
38
+ amountToApply = math.div(
39
+ math.mul(modifierAmount, options.itemTotal),
40
+ options.orderTotal,
41
+ options.itemQuantity
46
42
  );
47
43
  }
48
44
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.23",
3
+ "version": "1.0.24",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -36,5 +36,5 @@
36
36
  "supertest": "^6.2.3",
37
37
  "supervisor": "^0.12.0"
38
38
  },
39
- "gitHead": "6648705882ec8351463ba823c213cf7c198129ce"
39
+ "gitHead": "a5c31d32fc9c21bc3d643d02e1171438b38f6826"
40
40
  }