Crates.io | baggins |
lib.rs | baggins |
version | 0.2.0 |
source | src |
created_at | 2023-12-31 01:49:00.107614 |
updated_at | 2024-01-11 01:58:18.420938 |
description | Utilities to Perform Sales Calculation Operations |
homepage | |
repository | |
max_upload_size | |
id | 1084518 |
size | 85,548 |
Utilities to Perform Sales Totals and Subtotals Calculation Operations.
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}")
}
}