An NPM package for calculating GST-inclusive and GST-exclusive prices in India based on MRP, sale price, base price, and tax percentage.
- Calculate MRP, discount, sale price, base price, and detailed GST amounts.
- Lock calculations based on either
SALEPRICE
orBASEPRICE
. - Accurate currency conversions between subunits and standard units.
- Error handling for invalid inputs.
npm install @heartinz/gst-india-price-tax-calculator
Make sure to install the following dependencies as they are required for this package to function correctly:
npm install @heartinz/currency_subunit_converter
npm install @heartinz/gst_india_price_tax_calculator
import priceCalculator from '@heartinz/gst-india-price-tax-calculator';
const mrp = 1000; // Maximum Retail Price in INR
const salePrice = 900; // Sale Price in INR
const basePrice = 0; // Base Price in INR (set to 0 if unknown)
const taxPercent = 18; // GST percentage
const lock = 'SALEPRICE'; // Lock calculations based on 'SALEPRICE' or 'BASEPRICE'
try {
const result = priceCalculator.calculateAllPrice(mrp, salePrice, basePrice, taxPercent, lock);
console.log(result);
} catch (error) {
console.error(error.message);
}
- mrp (number): The Maximum Retail Price.
- salePrice (number): The Sale Price.
- basePrice (number): The Base Price (excluding GST).
- taxPercent (number): The GST percentage (must be a positive integer).
- lock (string): Determines which price to lock during calculation. Accepts 'SALEPRICE' or 'BASEPRICE'.
An object containing the calculated pricing details:
- mrp: Calculated MRP.
- discount: Calculated discount amount.
- salePrice: Calculated sale price.
- basePrice: Calculated base price (excluding GST).
- gstPercent: GST percentage used.
- gstAmount: Total GST amount.
- sgstPercent: SGST percentage.
- sgstAmount: SGST amount.
- cgstPercent: CGST percentage.
- cgstAmount: CGST amount.
- igstPercent: IGST percentage.
- igstAmount: IGST amount.
Throws an error if:
- mrp, salePrice, or basePrice are not valid decimal numbers.
- taxPercent is not a positive integer.
- lock is not 'SALEPRICE' or 'BASEPRICE'.
import priceCalculator from '@heartinz/gst-india-price-tax-calculator';
const mrp = 1500;
const salePrice = 1350;
const basePrice = 0;
const taxPercent = 18;
const lock = 'SALEPRICE';
try {
const result = priceCalculator.calculateAllPrice(mrp, salePrice, basePrice, taxPercent, lock);
console.log(result);
} catch (error) {
console.error(error.message);
}
Sample Output:
{
"mrp": 1500,
"discount": 150,
"salePrice": 1350,
"basePrice": 1144.07,
"gstPercent": 18,
"gstAmount": 205.93,
"sgstPercent": 9,
"sgstAmount": 102.96,
"cgstPercent": 9,
"cgstAmount": 102.96,
"igstPercent": 0,
"igstAmount": 0
}
The function includes input validation and will throw descriptive errors for invalid inputs:
- Invalid mrp: Must be a decimal number.
- Invalid salePrice: Must be a decimal number.
- Invalid basePrice: Must be a decimal number.
- Invalid taxPercent: Must be a positive integer.
- Invalid lock: Must be either 'SALEPRICE' or 'BASEPRICE'.
Contributions are welcome! Please open an issue or submit a pull request for any bugs or improvements.
/**
* Copyright (c) 2024 Kiran Morais
* (Heartinz Technologies Private Limited, India)
* All Rights Reserved. Unauthorized use, distribution, or modification of this code is prohibited.
*/
This package relies on accurate currency conversions and GST calculations as per Indian taxation laws. Always ensure the tax percentages and calculations comply with the latest regulations.