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.