baggins

Crates.iobaggins
lib.rsbaggins
version0.2.0
sourcesrc
created_at2023-12-31 01:49:00.107614
updated_at2024-01-11 01:58:18.420938
descriptionUtilities to Perform Sales Calculation Operations
homepage
repository
max_upload_size
id1084518
size85,548
Andrés Reyes el Programador Pobre (profe-ajedrez)

documentation

README

baggins

Utilities to Perform Sales Totals and Subtotals Calculation Operations.

Use

baggins exposes a calculator to obtain sales subtotals, into which taxes and discounts can be entered.

use baggins::{Calculator, discount, tax};

let mut c = baggins::DetailCalculator::new();

let err = c.add_discount_from_str(
    "10.0", 
    discount::Mode::Percentual
);
assert!(err.is_none(), "error adding percentual discount {:?}", err);

let err = c.add_tax_from_str(
    "16.0",
    tax::Stage::OverTaxable,
    tax::Mode::Percentual,
);

assert!(err.is_none(), "error adding percentual 16% tax {:?}", err);

Once taxes and discounts have been entered, the compute method can be called to obtain the results

let r = c.compute(
    BigDecimal::from_str("100.0").unwrap(),
    BigDecimal::from_str("2.0").unwrap(),
    None,
);

match r {
    Ok(calc) => {
        println!("calc: {}", calc);
    }
    Err(e) => {
        panic!("{e}")
    }
}
Commit count: 0

cargo fmt