@darkpos/pricing
v1.0.25
Published
Pricing calculator
Downloads
140
Readme
@dark/pricing
Dark Pricing
TODO: calculation of defined schemas
Usage
const usePricing = require('@darkpos/pricing');
const options = {
...localization,
};
const pricingService = usePricing(options);
//
const newOrder = pricingService.order.calculate(oldOrder);
Sample of a calculated Item:
const item = {
name: 'shirt',
price: 2,
modifiers: [
{
action: 'add',
type: 'fixed',
amount: 1
attributes: [hidden]
category: 'fee',
properties: {
sort: 1,
included: true,
},
computed: {
amount: 1
}
} ----> subTotal: 3
{
action: 'add',
type: 'percentage',
amount: 20
category: 'tax',
properties: {
direct: false,
sort: 2,
included: true
}
computed: {
amount: 0.60
}
}
{
action: 'add',
type: 'percentage',
amount: 30
category: 'tax',
properties: {
direct: false,
sort: 2,
included: true
}
computed: {
amount: 0.90
}
}
----> subTotal: 4.50
{
action: 'subtract',
type: 'fixed',
amount: 1
category: 'discount'
properties: {
direct: false,
sort: 3,
included: false
}
computed: {
amount: -1
}
}],
subTotals: {
tax: (included: false) ---> 0.60
discount: (included: false) --->-1.00
fee: ---> 0.00
_included: (included: true) ---> 1
_xincluded ---> -0.40
_direct: sum(modifiers with direct: true) ---> 1.60 *
_xdirect: (direct: false) ---> -1
_simple: price * quantity ---> 2.00 *
_actual: _simple + _included ---> 3.00
}
total: _actual + _xincluded ---> 2.60
}
const order = {
items: [item],
modifiers: [{
action: 'subtract',
type: 'fixed',
amount: 1
attributes: [hidden]
group: 'discount'
}],
subTotal: sum of _actuals ---> 3.00
---
subTotals: {
tax: sum of subTotals.tax ---> 0.60
fee: sum of subTotals.fee ---> 0.00
discount: sum of subTotals.discount --->-1.00
}
---
total: sum of above ---> 2.60
}