@darkpos/pricing 1.0.139 → 1.0.140

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.
@@ -3808,6 +3808,27 @@ describe('Order actions', () => {
3808
3808
  expect(newOrder2.items[0].status).toMatchObject({ paid: { value: true } });
3809
3809
  });
3810
3810
 
3811
+ test('Mark paid status true if totalPaid is greater than total', () => {
3812
+ const orderItem = {
3813
+ price: 25,
3814
+ quantity: 1,
3815
+ status: {},
3816
+ totalPaid: 30,
3817
+ };
3818
+ const pricing = usePricing({
3819
+ store: { _settings: { order: { autoMarkAsPaid: false } } },
3820
+ });
3821
+ const order = { items: [orderItem], status: {} };
3822
+ const newOrder = pricing.order.calculate(order);
3823
+
3824
+ expect(newOrder).toHaveProperty('total', 25);
3825
+ expect(newOrder).toHaveProperty('totalPaid', 30);
3826
+ expect(newOrder.status).toMatchObject({ paid: true });
3827
+ expect(newOrder.items[0].status).toMatchObject({
3828
+ paid: { value: true },
3829
+ });
3830
+ });
3831
+
3811
3832
  test('Dont update status if not needed', () => {
3812
3833
  const orderItem = {
3813
3834
  price: 25,
@@ -0,0 +1,7 @@
1
+ module.exports = ({ utils }) =>
2
+ function getOverpaidAmount({ item }) {
3
+ const total = Number(item.total || 0);
4
+ const totalPaid = Number(item.totalPaid || 0);
5
+
6
+ return utils.math.sub(totalPaid, total);
7
+ };
@@ -9,21 +9,21 @@ module.exports = ({ actions, settings }) =>
9
9
  const total = totalParam || 0;
10
10
  const totalPaid = totalPaidParam || 0;
11
11
 
12
- if (
13
- actions.isPaid({ item: { status: localStatus } }) &&
14
- total !== 0 &&
15
- total > totalPaid
16
- ) {
12
+ const isPaid = actions.isPaid({ item: { status: localStatus } });
13
+
14
+ const paid = { value: true, date: new Date() };
15
+
16
+ if (isPaid && total !== 0 && total > totalPaid) {
17
17
  return undefined;
18
18
  }
19
19
 
20
+ if (!isPaid && totalPaid > total) return paid;
21
+
20
22
  if (!settings || !settings.order || !settings.order.autoMarkAsPaid) {
21
23
  return localStatus.paid;
22
24
  }
23
25
 
24
- if (!actions.isPaid({ item: { status: localStatus } }) && total === 0) {
25
- return { value: true, date: new Date() };
26
- }
26
+ if (!isPaid && total === 0) return paid;
27
27
 
28
28
  return localStatus.paid;
29
29
  };
package/lib/item/index.js CHANGED
@@ -82,6 +82,8 @@ const getTaxes = require('./getTaxes');
82
82
  const getAmountToPayById = require('./getAmountToPayById');
83
83
  const applyPayment = require('./applyPayment');
84
84
  const getBalanceForPaymentModifier = require('./getBalanceForPaymentModifier');
85
+ const isOverpaid = require('./isOverpaid');
86
+ const getOverpaidAmount = require('./getOverpaidAmount');
85
87
 
86
88
  const itemActions = (deps = {}) => {
87
89
  const actions = {};
@@ -177,6 +179,8 @@ const itemActions = (deps = {}) => {
177
179
  getAmountToPayById: getAmountToPayById(innerDeps),
178
180
  applyPayment: applyPayment(innerDeps),
179
181
  getBalanceForPaymentModifier: getBalanceForPaymentModifier(innerDeps),
182
+ isOverpaid: isOverpaid(innerDeps),
183
+ getOverpaidAmount: getOverpaidAmount(innerDeps),
180
184
  });
181
185
 
182
186
  Object.keys(freezedActions).forEach(actionName => {
@@ -0,0 +1,7 @@
1
+ module.exports = () =>
2
+ function isOverpaid({ item }) {
3
+ const total = Number(item.total || 0);
4
+ const totalPaid = Number(item.totalPaid || 0);
5
+
6
+ return totalPaid > total;
7
+ };
@@ -0,0 +1,8 @@
1
+ module.exports = ({ utils }) =>
2
+ function getOverPaidAmount({ order }) {
3
+ if (!order) return 0;
4
+ const total = Number(order.total || 0);
5
+ const totalPaid = Number(order.totalPaid || 0);
6
+
7
+ return utils.math.sub(totalPaid, total);
8
+ };
@@ -100,6 +100,7 @@ const removeEmptyNotes = require('./removeEmptyNotes');
100
100
  const getTaxes = require('./getTaxes');
101
101
  const getPickedStatus = require('./getPickedStatus');
102
102
  const calculateWithPayment = require('./calculateWithPayment');
103
+ const getOverpaidAmount = require('./getOverpaidAmount');
103
104
 
104
105
  const orderActions = (deps = {}) => {
105
106
  const actions = {};
@@ -211,6 +212,7 @@ const orderActions = (deps = {}) => {
211
212
  getTaxes: getTaxes(innerDeps),
212
213
  getPickedStatus: getPickedStatus(innerDeps),
213
214
  calculateWithPayment: calculateWithPayment(innerDeps),
215
+ getOverpaidAmount: getOverpaidAmount(innerDeps),
214
216
  });
215
217
 
216
218
  Object.keys(freezedActions).forEach(actionName => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@darkpos/pricing",
3
- "version": "1.0.139",
3
+ "version": "1.0.140",
4
4
  "description": "Pricing calculator",
5
5
  "author": "Dark POS",
6
6
  "license": "ISC",
@@ -53,5 +53,5 @@
53
53
  "supertest": "^6.2.3",
54
54
  "supervisor": "^0.12.0"
55
55
  },
56
- "gitHead": "643797505f915f1c4562c19e59a82dd98ae888ec"
56
+ "gitHead": "a679a827cb2a83762ae4ec5ce76ae5416b654a48"
57
57
  }