@heartinz/price_gst_india_calculator_rupee

2.0.0 • Public • Published

GST India Price and Tax Calculator

An NPM package for calculating GST-inclusive and GST-exclusive prices in India based on MRP, sale price, base price, and tax percentage.

Features

  • Calculate MRP, discount, sale price, base price, and detailed GST amounts.
  • Lock calculations based on either SALEPRICE or BASEPRICE.
  • Accurate currency conversions between subunits and standard units.
  • Error handling for invalid inputs.

Installation

npm install @heartinz/gst-india-price-tax-calculator

Dependencies

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

Usage

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);
}

Function: calculateAllPrice

Parameters

  • 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'.

Returns

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.

Exceptions

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'.

Example

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
}

Error Handling

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'.

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any bugs or improvements.

License

/**
 * Copyright (c) 2024 Kiran Morais
 * (Heartinz Technologies Private Limited, India)
 * All Rights Reserved. Unauthorized use, distribution, or modification of this code is prohibited.
 */

Note

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.

Dependents (0)

Package Sidebar

Install

npm i @heartinz/price_gst_india_calculator_rupee

Weekly Downloads

151

Version

2.0.0

License

ISC

Unpacked Size

12.8 kB

Total Files

6

Last publish

Collaborators

  • heartinz-admin