Coding and Programming

GST Calculator Script for your website

Today’s  in India GST calculation needed for every software So. I am thinking about the developer who wants to implement GST calculation on there software or website. They can be used my scripts for GST calculation.

function Calculation(){
    var rate = 0, disc = 0, cgst=0, sgst=0, igst=0, total=0;
    

    this.setRate = function(mainPrice){
        rate = mainPrice;
    }

    this.setDiscount = function(discount, type='%'){
        if(type === '%'){
            disc = rate * discount / 100
        }else{
            disc = discount;
        } 
    }

    this.setCGST = function(val, type='%'){
        if(type === '%'){
            cgst = (rate - disc) * val/100;
        }else{
            cgst = val;
        }
    }

    this.setSGST = function(val, type='%'){
        if (type === '%') {
            sgst = (rate - disc) * val / 100;
        }else{
            sgst = val;
        }
    }

    this.setIGST = function(val, type='%'){
        if (type === '%') {
            igst = (rate - disc) * val / 100;
        } else {
            igst = val;
        }
    }

    this.getCost = function(igstApply=false){
        if (igstApply === false) {
            total = (rate - disc) + (cgst + sgst);
        }else{
            total = (rate - disc) + igst;
        }

        return total;
    }
}


// How To Use

var c = new Calculation();
c.setRate(100);
c.setDiscount(20);
c.setCGST(5);
c.setSGST(5);
c.setIGST(18);
var cost = c.getCost();
var costWithIgst = c.getCost(true);

console.log('Actual Cost of the product: '+cost);
console.log('Actual Cost of the Service: ' + costWithIgst);
function Calculation(){
    var rate = 0, disc = 0, cgst=0, sgst=0, igst=0, total=0;
    

    this.setRate = function(mainPrice){
        rate = mainPrice;
    }

    this.setDiscount = function(discount, type='%'){
        if(type === '%'){
            disc = rate * discount / 100
        }else{
            disc = discount;
        } 
    }

    this.setCGST = function(val, type='%'){
        if(type === '%'){
            cgst = (rate - disc) * val/100;
        }else{
            cgst = val;
        }
    }

    this.setSGST = function(val, type='%'){
        if (type === '%') {
            sgst = (rate - disc) * val / 100;
        }else{
            sgst = val;
        }
    }

    this.setIGST = function(val, type='%'){
        if (type === '%') {
            igst = (rate - disc) * val / 100;
        } else {
            igst = val;
        }
    }

    this.getCost = function(igstApply=false){
        if (igstApply === false) {
            total = (rate - disc) + (cgst + sgst);
        }else{
            total = (rate - disc) + igst;
        }

        return total;
    }
}


// How To Use

var c = new Calculation();
c.setRate(100);
c.setDiscount(20);
c.setCGST(5);
c.setSGST(5);
c.setIGST(18);
var cost = c.getCost();
var costWithIgst = c.getCost(true);

console.log('Actual Cost of the product: '+cost);
console.log('Actual Cost of the Service: ' + costWithIgst);

You can use this code everywhere.

Shibaji Debnath

Recent Posts

Is a full-stack developer course suitable for you?

A full-stack developer course is good or not. This time, so many people want to…

2 months ago

Setting up a Developer Workspace: Tips for setting up a comfortable and productive coding environment

As a software developer, having a comfortable and productive coding environment is essential to your…

4 months ago

Top 5 Software Development Career Options

Discovering the Software Development Career: This article will teach you everything you need to know…

5 months ago

How to Start Learning about Software Programming

Software Programming is done with various software programming languages. We are using these languages used…

2 years ago

How can start AI Application development with JavaScript?

There are several ways to AI application development using JavaScript, depending on your goals and…

2 years ago

Streaming Audio Player app develop by Angular

This is the angular live project on audio player for website and mobile. This app…

4 years ago

This website uses cookies.