1.0.46 • Published 8 months ago

@darkpos/pricing v1.0.46

Weekly downloads
5
License
ISC
Repository
gitlab
Last release
8 months ago

@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
}
1.0.46

8 months ago

1.0.45

8 months ago

1.0.44

8 months ago

1.0.40

9 months ago

1.0.43

9 months ago

1.0.41

9 months ago

1.0.39

9 months ago

1.0.38

9 months ago

1.0.37

9 months ago

1.0.35

9 months ago

1.0.34

10 months ago

1.0.33

10 months ago

1.0.32

10 months ago

1.0.31

10 months ago

1.0.30

10 months ago

1.0.29

10 months ago

1.0.26

12 months ago

1.0.28

10 months ago

1.0.27

12 months ago

1.0.25

2 years ago

1.0.24

2 years ago

1.0.23

2 years ago

1.0.22

2 years ago

1.0.21

2 years ago

1.0.20

2 years ago

1.0.19

2 years ago

1.0.18

2 years ago

1.0.17

2 years ago

1.0.16

3 years ago

1.0.15

3 years ago

1.0.14

3 years ago

1.0.13

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.12

3 years ago

1.0.5

4 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago