Tax Calculation
Tax Calculation
in ,

Tax Calculation Logic Based On Tax Profile Of An Item

//TaxCalculator here..
var program2 = (function () {
    function program2() {
    }
    program2.run = function () {
        console.log("Running Program...");
        var itemSize = {
            "ItemSizeId": 1,
            "SiteItemId": 1,
            "Name": "Default",
            "Description": "Default",
            "IsWeighted": false,
            "Price": 350,
            "IsFree": false,
            "PointsPercentage": 2,
            "PointsPrice": 15,
            "CanBePaidUsingPoints": true,
            "OrderingUniqueId": "0192837465",
            "ThirdPartyId": "",
            "DefaultPatronCount": 0,
        };
        var taxProfiles = [
            {
                "ItemSizeTaxProfileId": 1,
                "TaxProfileId": 1,
                "Name": "Vat",
                "Description": "Vat",
                "Rate": 12,
                "Type": 0,
                "Priority": 1
            },
            {
                "ItemSizeTaxProfileId": 1,
                "TaxProfileId": 1,
                "Name": "Vat",
                "Description": "Vat",
                "Rate": 15,
                "Type": 0,
                "Priority": 1
            },
            // {
            //     "ItemSizeTaxProfileId": 2,
            //     "TaxProfileId": 2,
            //     "Name": "Sales Tax",
            //     "Description": "Sales Tax",
            //     "Rate": 12,
            //     "Type": 2,
            //     "Priority": 2
            // }
            // ,
            // {
            //     "ItemSizeTaxProfileId": 1,
            //     "TaxProfileId": 1,
            //     "Name": "Vat",
            //     "Description": "Vat",
            //     "Rate": 12,
            //     "Type": 2,
            //     "Priority": 1
            // }
            // ,
            // {
            //     "ItemSizeTaxProfileId": 2,
            //     "TaxProfileId": 2,
            //     "Name": "Sales Tax",
            //     "Description": "Sales Tax",
            //     "Rate": 12,
            //     "Type": 2,
            //     "Priority": 2
            // }
        ];
        var taxSettings = [
            {
                "SiteId": 1,
                "SiteTransactionType": 3,
                "SiteTransactionTypeName": "ItemPriceIncludeTax",
                "Text": "ItemPriceIncludeTax",
                "Value": "1"
            },
            {
                "SiteId": 1,
                "SiteTransactionType": 4,
                "SiteTransactionTypeName": "ItemPriceIncludeServiceCharge",
                "Text": "ItemPriceIncludeServiceCharge",
                "Value": "1"
            },
            {
                "SiteId": 1,
                "SiteTransactionType": 5,
                "SiteTransactionTypeName": "CalculateTaxBeforeDiscount",
                "Text": "CalculateTaxBeforeDiscount",
                "Value": "0"
            },
            {
                "SiteId": 1,
                "SiteTransactionType": 6,
                "SiteTransactionTypeName": "CalculateTaxAfterDiscount",
                "Text": "CalculateTaxAfterDiscount",
                "Value": "0"
            },
            {
                "SiteId": 1,
                "SiteTransactionType": 7,
                "SiteTransactionTypeName": "CalculateScPreDiscountedPrice",
                "Text": "CalculateScPreDiscountedPrice",
                "Value": "0"
            },
            {
                "SiteId": 1,
                "SiteTransactionType": 8,
                "SiteTransactionTypeName": "ReCalculateScAfterDiscount",
                "Text": "ReCalculateScAfterDiscount",
                "Value": "0"
            },
            //[6]    
            {
                "SiteId": 1,
                "SiteTransactionType": 9,
                "SiteTransactionTypeName": "ApplyServiceChargeTax",
                "Text": "ApplyServiceChargeTax",
                "Value": "1"
            },
            //[7]
            {
                "SiteId": 1,
                "SiteTransactionType": 10,
                "SiteTransactionTypeName": "ServiceChargeTaxRate",
                "Text": "ServiceChargeTaxRate",
                "Value": "15"
            }
        ];
        //tax behaviour mapper..
        this.TaxBehaviourMapper(itemSize, taxProfiles, taxSettings);
    };
    /**
     * BasePriceCalculator
     */

    //STinclusive>>>>>>>>>>>>>>>>>> Only
    program2.CalculateBasePriceSalesTaxInclusiveOnly = function (itemSize, taxProfiles, taxSettings) {
        //Calculate Base Price for ST Inclusive
        if (taxProfiles.length != 0) {
            // if (taxProfiles.length==1) {
            // }
            var STrate_1 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 0) {
                    STrate_1 = STrate_1 + tax.Rate;
                }
            });
            itemSize.BasePrice = ((itemSize.Price) / (100 + STrate_1)) * 100;
            // itemSize.BasePrice = itemSize.BasePrice;
            itemSize.appliedPrice = itemSize.Price;
            itemSize.SalesTax = (itemSize.Price - itemSize.BasePrice);
            console.log("ItemSize Before applying Service Charge : ", itemSize);
            //applying Exclusive Service Charge..
            var SCrate_1 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 2) {
                    SCrate_1 = SCrate_1 + tax.Rate;
                }
            });
            itemSize.ServiceCharge = (itemSize.BasePrice * (SCrate_1 / 100));
            itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.ServiceCharge);
            console.log(STrate_1);
            console.log("ItemSize After applying Service Charge : ", itemSize);
            //Apply TSC logic..
            console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            if (!!+taxSettings[6].Value == true) {
                console.log("Applying Tax On Service Charge..");
                itemSize.TaxOnServiceCharge = (itemSize.ServiceCharge * (taxSettings[7].Value / 100));
                itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.TaxOnServiceCharge);
            }
            else {
                console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            }
            console.log("ItemSize After applying Tax On Service Charge : ", itemSize);
            // console.log(itemSize);
        }
    };
    //SCinclusive>>>>>>>>>>>>>>>>>> Only    
    program2.CalculateBasePriceServiceChargeInclusiveOnly = function (itemSize, taxProfiles, taxSettings) {
        //Calculate Base Price for SC Inclusive
        if (taxProfiles.length != 0) {
            // if (taxProfiles.length==1) {
            // }
            var SCrate_2 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 2) {
                    SCrate_2 = SCrate_2 + tax.Rate;
                }
            });
            itemSize.BasePrice = ((itemSize.Price) / (100 + SCrate_2)) * 100;
            itemSize.BasePrice = itemSize.BasePrice;
            itemSize.appliedPrice = itemSize.Price;
            itemSize.ServiceCharge = (itemSize.Price - itemSize.BasePrice);
            console.log("ItemSize Before applying Sales Tax : ", itemSize);
            //applying ST Exclusive..
            var STrate_2 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 0) {
                    STrate_2 = STrate_2 + tax.Rate;
                }
            });
            itemSize.SalesTax = (itemSize.BasePrice * (STrate_2 / 100));
            itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.SalesTax);
            console.log("ItemSize Before Tax On Service Charge : ", itemSize);
            //Apply TSC logic..
            console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            if (!!+taxSettings[6].Value == true) {
                console.log("Applying Tax On Service Charge..");
                itemSize.TaxOnServiceCharge = (itemSize.ServiceCharge * (taxSettings[7].Value / 100));
                itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.TaxOnServiceCharge);
            }
            else {
                console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            }
            console.log("ItemSize After applying Tax On Service Charge : ", itemSize);
            // console.log(itemSize);
        }
    };
    program2.CalculateBasePriceSalesTaxServiceChargeInclusive = function (itemSize, taxProfiles, taxSettings) {
        //Calculate Base Price for ST SC Inclusive
        if (taxProfiles.length != 0) {
            // if (taxProfiles.length==1) {
            // }
            var STrate_3 = 0;
            var SCrate_3 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 0) {
                    STrate_3 = STrate_3 + tax.Rate;
                }
                if (tax.Type == 2) {
                    SCrate_3 = SCrate_3 + tax.Rate;
                }
            });
            if (!!+taxSettings[6].Value == true) {
                itemSize.BasePrice = itemSize.Price / (1 + (STrate_3 / 100) + (SCrate_3 / 100) + ((taxSettings[7].Value / 100) * (SCrate_3 / 100)));
            }
            else {
                itemSize.BasePrice = itemSize.Price / (1 + (STrate_3 / 100) + (SCrate_3 / 100));
            }
            itemSize.BasePrice = itemSize.BasePrice;
            itemSize.appliedPrice = itemSize.Price;
            itemSize.SalesTax = (itemSize.BasePrice) * (STrate_3 / 100);
            itemSize.ServiceCharge = (itemSize.BasePrice) * (SCrate_3 / 100);
            itemSize.ServiceCharge = itemSize.ServiceCharge;
            console.log("ItemSize Before applying Tax On Service Charge : ", itemSize);
            //Apply TSC logic..
            console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            if (!!+taxSettings[6].Value == true) {
                itemSize.TaxOnServiceCharge = (itemSize.ServiceCharge * (taxSettings[7].Value / 100));
                //POS dont add this value to applied price... 
                //itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.TaxOnServiceCharge);
            }
            else {
                console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            }
            console.log("ItemSize After applying Tax On Service Charge : ", itemSize);
            // console.log(itemSize);
        }
    };
    //done..
    program2.CalculateBasePriceSalesTaxServiceChargeExclusive = function (itemSize, taxProfiles, taxSettings) {
        //Calculate Base Price for ST SC Exclusive
        if (taxProfiles.length != 0) {
            // if (taxProfiles.length==1) {
            // }
            var STrate_4 = 0;
            var SCrate_4 = 0;
            taxProfiles.forEach(function (tax) {
                if (tax.Type == 0) {
                    STrate_4 = STrate_4 + tax.Rate;
                }
                if (tax.Type == 2) {
                    SCrate_4 = SCrate_4 + tax.Rate;
                }
            });
            itemSize.BasePrice = itemSize.Price;
            // if (!!+taxSettings[6].Value == true) {
            //     console.log("Changing base price by applying TSC");
            //     // itemSize.BasePrice = itemSize.Price /(1 + (STrate/100) + (SCrate/100) + ((taxSettings[7].Value/100)*(SCrate/100)))
            // }else{
            //     itemSize.BasePrice = itemSize.Price;
            // }
            itemSize.SalesTax = (itemSize.BasePrice) * (STrate_4 / 100);
            itemSize.SalesTax = itemSize.SalesTax;
            itemSize.ServiceCharge = (itemSize.BasePrice) * (SCrate_4 / 100);
            itemSize.ServiceCharge = itemSize.ServiceCharge;
            //todo calculate tax on service charge
            itemSize.appliedPrice = parseFloat(itemSize.BasePrice) + parseFloat(itemSize.ServiceCharge) + parseFloat(itemSize.SalesTax);
            //Apply TSC logic..
            console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            if (!!+taxSettings[6].Value == true) {
                console.log("Applying Tax On Service Charge..");
                itemSize.TaxOnServiceCharge = (itemSize.ServiceCharge * (taxSettings[7].Value / 100));
                itemSize.appliedPrice = itemSize.appliedPrice + parseFloat(itemSize.TaxOnServiceCharge);
            }
            else {
                console.log("Tax On Service Charge Enabled : ", !!+taxSettings[6].Value);
            }
            console.log("ItemSize After applying Tax On Service Charge : ", itemSize);
            console.log(itemSize);
        }
    };
    /**
     * TaxBehaviourMapper
     */
    program2.TaxBehaviourMapper = function (itemSize, taxProfiles, taxSettings) {
        console.log("Tax Behaviour Check : ");
        var switchFlag = 0;
        //ST Inclusive Only..
        console.log(this.STinclusiveOnly(taxSettings));
        if (this.STinclusiveOnly(taxSettings)) {
            switchFlag = 1;
        }
        // else {
        //     switchFlag = 4;
        // }
        //SC Inclusive Only..
        console.log(this.SCinclusiveOnly(taxSettings));
        if (this.SCinclusiveOnly(taxSettings)) {
            switchFlag = 2;
        }
        // else {
        //     switchFlag = 5;
        // }
        //Both Inclusive..
        console.log(this.BothInclusive(taxSettings));
        if (this.BothInclusive(taxSettings)) {
            switchFlag = 3;
        }
        //Both Exclusive..
        console.log(this.BothExclusive(taxSettings));
        if (this.BothExclusive(taxSettings)) {
            switchFlag = 6;
        }
        ////---------------------------------------------------
        console.log("Switch Flag : ", switchFlag);
        switch (switchFlag) {
            case 0:
                {
                    //test only..
                    // this.CalculateBasePriceSalesTaxExclusive(itemSize, taxProfiles);
                    //this.CalculateBasePriceServiceChargeExclusive(itemSize, taxProfiles);
                    // this.CalculateBasePriceSalesTaxServiceChargeExclusive(itemSize, taxProfiles);
                }
                break;
            case 1:
                {
                    //ST Inclusive Only..
                    //calculate base price from ST
                    this.CalculateBasePriceSalesTaxInclusiveOnly(itemSize, taxProfiles, taxSettings);
                }
                break;
            case 4:
                {
                }
                break;
            case 2:
                {
                    //SC Inclusive Only..
                    //calculate base price from SC
                    this.CalculateBasePriceServiceChargeInclusiveOnly(itemSize, taxProfiles, taxSettings);
                }
                break;
            case 5:
                {
                }
                break;
            case 3:
                {
                    //Both Inclusive..
                    this.CalculateBasePriceSalesTaxServiceChargeInclusive(itemSize, taxProfiles, taxSettings);
                }
                break;
            case 6:
                {
                    //Both Exclusive..
                    this.CalculateBasePriceSalesTaxServiceChargeExclusive(itemSize, taxProfiles, taxSettings);
                }
                break;
            default:
                break;
        }
    };
    program2.STinclusiveOnly = function (taxSettings) {
        if (!!+taxSettings[0].Value == true && !!+taxSettings[1].Value == false) {
            // if (!!+taxSettings[1].Value==false ) {
            //   return true;
            // }
            return true;
        }
        else {
            return false;
        }
    };
    program2.SCinclusiveOnly = function (taxSettings) {
        if (!!+taxSettings[1].Value == true && !!+taxSettings[0].Value == false) {
            return true;
        }
        else {
            return false;
        }
    };
    program2.BothInclusive = function (taxSettings) {
        if (!!+taxSettings[0].Value == true && !!+taxSettings[1].Value == true) {
            return true;
        }
        else {
            return false;
        }
    };
    program2.BothExclusive = function (taxSettings) {
        if (this.STinclusiveOnly(taxSettings) == false && this.SCinclusiveOnly(taxSettings) == false && this.BothInclusive(taxSettings) == false) {
            return true;
        }
        else {
            return false;
        }
    };
    return program2;
}());
var Startup2 = (function () {
    function Startup2() {
    }
    Startup2.main = function () {
        // console.log('Hello World');
        //to run program..
        program2.run();
        return 0;
    };
    return Startup2;
}());
Startup2.main();
//# sourceMappingURL=taxImplementation.1.js.map

Author Profile

PREM KUMAR
PREM KUMAR
Hey Its..! Tech Lover , Ionic, Angular, Typescript, Dotnet Core, Node, Like Opencv, AI, ML, Robotics, Iot, Love Music, Cooking, Girls, Innovation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

What do you think?

400 Points
Upvote Downvote
database storage

How to manage database storage structures?

instance_recovery1

How to tune instance recovery in Oracle?