GithubHelp home page GithubHelp logo

bolson's Introduction

bolson

Utils to calculate sales values

Install

$ go get github.com/profe-ajedrez/bolson

Usage

bolson is the handler provided to perform the sales operations over sales values

Internally bolson has a handler for taxes and a handler for discounts which performs operations and calculations over these concepts.

bolson can register different types of taxes and discounts and is able to calculate them correctly.

Taxes

bolson uses the concept of stages to the taxes registry and calculations, where a tax can be registered in a particular stage which determines when is calculated.

The taxes stages are:

  • OverTaxableStage represents taxes calculated over its value.

  • OverTaxesStage represents taxes calculated over its value plus the cummulated amount of the taxes calculated in the OvertaxableStage

  • OverTaxesIgnorableStage represents taxes which are calculated like the taxes of the OverTaxableStage, but are not included in the OVerTaxesStage

b := bolson.New()

// adds a percentual tax to the Overtaxable stage
err  := b.AddTax(decimal.NewFromInt(10), tax.PercentualMode, tax.OverTaxableStage)

if err != nil {
    panic(err) // Remember! Dont Panic!
}

Discounts

You can register discounts in bolson.

b := bolson.New()

// register a percentual discount
err := b.AddDiscount(decimal.NewFromInt(10), discount.PercentualMode)

if err != nil {
    panic(err) // Remember! Dont Panic!
}

Calculate results

When you are done registering taxes an discount you can invoke the method Calculate.

b := bolson.New()

// adds a percentual tax to the Overtaxable stage
err  := b.AddTax(decimal.NewFromInt(10), tax.PercentualMode, tax.OverTaxableStage)

if err != nil {
    panic(err) // Remember! Dont Panic!
}

// register a percentual discount
err := b.AddDiscount(decimal.NewFromInt(10), discount.PercentualMode)

if err != nil {
    panic(err) // Remember! Dont Panic!
}

unitValue := decimal.NewFromInt(100)
quantity := decimal.NewFromInt(10)

result, err := b.Calculate(unitValue, quantity)

if err != nil {
    panic(err) // Remember! Dont Panic!
}

js, _ := json.Marshal(result)
fmt.Println(js)

// prints
//
//  {{"withDiscount":{"net":"900","brute":"990","tax":"90","discount":"10","discountedValue":"100","discountedValueBrute":"110","unitValue":"90"},"withoutDiscount":{"net":"1000","brute":"1100","tax":"100","unitValue":"100"}}

bolson's People

Contributors

areyes-bsale avatar profe-ajedrez avatar

Watchers

 avatar  avatar

bolson's Issues

Stats

@coderabbitai generate interesting stats about this repository and render them as a table

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.