npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@heartinz/price_gst_india_calculator_rupee

v2.0.0

Published

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

Downloads

49

Readme

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.