@darkpos/pricing 1.0.168 → 1.0.169
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.
- package/__TEST__/statement.test.js +25 -0
- package/lib/index.js +3 -0
- package/lib/statement/adjustEndBalance.js +11 -0
- package/lib/statement/index.js +21 -0
- package/package.json +2 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
const usePricing = require('../index');
|
|
2
|
+
|
|
3
|
+
const pricing = usePricing({});
|
|
4
|
+
|
|
5
|
+
describe('statement.adjustEndBalance', () => {
|
|
6
|
+
test('preserves the end balance when editable balances do not change', () => {
|
|
7
|
+
expect(
|
|
8
|
+
pricing.statement.adjustEndBalance({
|
|
9
|
+
endBalance: 73.04,
|
|
10
|
+
startBalance: 61.89,
|
|
11
|
+
previousStartBalance: 61.89,
|
|
12
|
+
})
|
|
13
|
+
).toBe(73.04);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
test('applies start balance and late fee changes', () => {
|
|
17
|
+
expect(
|
|
18
|
+
pricing.statement.adjustEndBalance({
|
|
19
|
+
endBalance: 73.04,
|
|
20
|
+
startBalance: 60,
|
|
21
|
+
previousStartBalance: 61.89,
|
|
22
|
+
})
|
|
23
|
+
).toBe(71.15);
|
|
24
|
+
});
|
|
25
|
+
});
|
package/lib/index.js
CHANGED
|
@@ -10,6 +10,7 @@ const makeOrderActions = require('./order');
|
|
|
10
10
|
const makeModifierActions = require('./modifier');
|
|
11
11
|
const makePaymentActions = require('./payment');
|
|
12
12
|
const makeInvoiceActions = require('./invoice');
|
|
13
|
+
const makeStatementActions = require('./statement');
|
|
13
14
|
|
|
14
15
|
const constants = require('./constants');
|
|
15
16
|
|
|
@@ -59,6 +60,7 @@ module.exports = session => {
|
|
|
59
60
|
storeActions,
|
|
60
61
|
paymentActions,
|
|
61
62
|
});
|
|
63
|
+
const statementActions = makeStatementActions(deps);
|
|
62
64
|
|
|
63
65
|
return {
|
|
64
66
|
item: itemActions,
|
|
@@ -67,6 +69,7 @@ module.exports = session => {
|
|
|
67
69
|
store: storeActions,
|
|
68
70
|
payment: paymentActions,
|
|
69
71
|
invoice: invoiceActions,
|
|
72
|
+
statement: statementActions,
|
|
70
73
|
constants,
|
|
71
74
|
};
|
|
72
75
|
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
module.exports = ({ utils }) =>
|
|
2
|
+
function adjustEndBalance({
|
|
3
|
+
endBalance = 0,
|
|
4
|
+
startBalance = 0,
|
|
5
|
+
previousStartBalance = 0,
|
|
6
|
+
}) {
|
|
7
|
+
const { math } = utils;
|
|
8
|
+
const startBalanceChange = math.sub(startBalance, previousStartBalance);
|
|
9
|
+
|
|
10
|
+
return math.toDecimalPlaces(math.add(endBalance, startBalanceChange));
|
|
11
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const adjustEndBalance = require('./adjustEndBalance');
|
|
2
|
+
|
|
3
|
+
const statementActions = (deps = {}) => {
|
|
4
|
+
const actions = {};
|
|
5
|
+
const innerDeps = {
|
|
6
|
+
...deps,
|
|
7
|
+
actions,
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const freezedActions = Object.freeze({
|
|
11
|
+
adjustEndBalance: adjustEndBalance(innerDeps),
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
Object.keys(freezedActions).forEach(actionName => {
|
|
15
|
+
actions[actionName] = freezedActions[actionName];
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
return freezedActions;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
module.exports = statementActions;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@darkpos/pricing",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.169",
|
|
4
4
|
"description": "Pricing calculator",
|
|
5
5
|
"author": "Dark POS",
|
|
6
6
|
"license": "ISC",
|
|
@@ -54,5 +54,5 @@
|
|
|
54
54
|
"supertest": "^6.2.3",
|
|
55
55
|
"supervisor": "^0.12.0"
|
|
56
56
|
},
|
|
57
|
-
"gitHead": "
|
|
57
|
+
"gitHead": "39bcdea9fdfcd1f04ffed395217362bbc80a3669"
|
|
58
58
|
}
|