laravel-taxify

Laravel Taxify

Laravel Taxify

set of helper functions and classes to simplify tax (VAT) calculations within Laravel applications. that allow developers to easily integrate tax calculation functionalities into their projects with multi tax profiles settings and (fixed, percentage) ways. it’s offers a straightforward and efficient solution Designed to streamline the process of handling taxes.

Requirements

Laravel 8.x or up , for version 2.x .

Installation

composer require omaralalwi/laravel-taxify

publish the package’s configuration file:

php artisan vendor:publish --tag=laravel-taxify-config

Compatibility

For applications running Laravel versions 7.x and older, use version 1.0.4.

composer require omaralalwi/laravel-taxify:^1.0.4

Usage

Available Helper Functions

laravel taxify many of helper functions to simplify usage.


calculate tax for an amount:

$amount = 250;
$taxAmount = calculateTax($amount,'profileName')->tax_amount; // 37.5

Another way to get Detailed Result.

$amount = 250;
$tax = calculateTax($amount,'profileName');

Result (Object)

 $tax = {
    "amount_with_tax": 287.5,
    "tax_amount": 37.5,
    "tax_rate": 0.15,
  }

Note: the second param refer to profile, we mad it null to take default profile, second param can take (default, null,’’’) all three values mean default.


Calculate tax for a collection of amounts:

like calculateTax but this for a many amounts .

// you can pass number as float or integer
$productAmount = 250;
$featureAmount = 70.5;
$warrantyAmount = 30.60;
$chargeAmount = 90;

$tax = calculateTaxForCollection([$productAmount,$featureAmount, $warrantyAmount, $chargeAmount]);

Result (object)

$tax = {
    "amount_with_tax": 507.265,
    "tax_amount": 66.165,
    "tax_rate": 0.15,
  }
$taxAmount = $tax->tax_amount // 66.165

Get Tax Amount as numeric value

$amount = 250;
getTaxAmount($amount); // Result 25

Get tax rate or tax amount:

getTaxRate()
// Result 0.15
getTaxRate('sales') // fore specific profile
// Result 50 , here the result is fixed number because the profile type is fixed amount Not percentage

if profile tax type is fixed will return the amount (read the tax rate as amount), else will return the tax rate.

Note: for default profile no need to pass `profileName.


Get tax type:

getTaxType('profileName')
// Result: fixed or percentage // depend on profile settings

Get tax rate as Percentage number (10%, 15%) - for percentage profiles Only:

you can get Tax Rate As Percentage

getTaxRateAsPercentage();  // Result '10.00%'

Note: for default profile no need to pass it

Configuration

Environment Variables

after you published config file .

You can configure Laravel Taxify by adding the following default configuration keys to your .env file. If you do not add these, the default values will be used.

For a percentage tax type:

DEFAULT_TAXIFY_PROFILE="default"
TAXIFY_DEFAULT_RATE="0.10"
TAXIFY_DEFAULT_TYPE="percentage"

example configuration for fixed tax type:

DEFAULT_TAXIFY_PROFILE="default"
TAXIFY_DEFAULT_RATE=50
TAXIFY_DEFAULT_TYPE="fixed"

Note: The TAXIFY_DEFAULT_RATE is a number representing the rate when the type is percentage or the amount when type is fixed.

You can add more than one of tax profile in config/taxify.php .

Features

Testing

php artisan test --filter TaxifyTest

Contributing

Please see CONTRIBUTING for details.

TODO

this todo list , contain the tasks that we planning to working on them, you can choose one of them and develop it if you want to contribute.

Security

If you discover any security related issues, please email omaralwi2010@gmail.com.

Credits

License

The MIT License (MIT). Please see License File for more information.


📚 Helpful Open Source Packages