softseti-sale-calculator-library
v4.0.1
Published
Sales calculation engine by Softseti
Readme
Sale Calculator Strategy
Calculate complex sales totals with taxes, discounts, and wholesale pricing.
Versioning and Publishing (For Maintainers)
To release a new version of the library:
Bump the version in package.json:
Patch (1.0.X)
npm version patch
Minor (1.X.0)
npm version minor
Major (X.0.0)
npm version major
Publish to npm:
npm publish
Install
npm install softseti-sale-calculator-library
# Install the library
npm install softseti-sale-calculator-library
# Update to the latest version
npm update softseti-sale-calculator-libraryBasic Usage javascript
const { init, calcTotal } = require('softseti-sale-calculator-library');
// 1. Setup your products
init({
products: {
101: {
original_public_price: 20000, // $200.00 MXN
quantity: 1
}
},
taxes: {
vat: { rate: 16, general: true }
}
});
// 2. Create a sale
const myOrder = {
receipt_type_key: 'invoice',
dwSaleProducts: [{
product_id: 101,
quantity: 5
}]
};
// 3. Get total
const total = calcTotal(myOrder);
console.log(`Total: $${total / 100}`); // $1000 * 1.16 = $1160.00Key Features Bulk Pricing
init({
wholesale_levels: {
101: [{
quantity_min: 10,
quantity_max: 20,
price: 15000 // $150.00 per unit for 10-20 units
}]
}
});Apply Discounts javascript
const saleWithDeal = {
...myOrder,
dwSaleDeals: [{ amount: 5000 }] // $50.00 discount
};
calcTotal(saleWithDeal); // Applies discount proportionallyCustom Prices javascript
dwSaleProducts: [{
product_id: 101,
quantity: 2,
custom_price: 18000 // Override price to $180.00
}]Error Handling javascript
try {
calcTotal({ invalid: 'data' });
} catch (error) {
console.error('Failed:', error.message);
// Example error: "Invalid sale structure - Missing dwSaleProducts"
}}Version: 1.0.2
License: MIT © Softseti
