2017 © Pedro Peláez
 

library tax

This Package allow calculate Tax to an amount

image

feimx/tax

This Package allow calculate Tax to an amount

  • Wednesday, April 18, 2018
  • by Yorchi
  • Repository
  • 1 Watchers
  • 1 Stars
  • 54 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 7 Versions
  • 29 % Grown

The README.md

Calculate taxes for a given amount

Latest Version on Packagist Build Status Quality Score Total Downloads, (*1)

The feimx/tax package provide a simple way for calculate taxes of an amount., (*2)

Basic Usage

``` php $taxManager = new FeiMx\Tax\TaxManager($amount = 100); $taxManager->addTax('iva'); echo $taxManager->total(); // 116.000000, (*3)


## Installation You can install the package via composer: ```bash composer require feimx/tax
// config/app.php
'providers' => [
    FeiMx\Tax\TaxServiceProvider::class,
];

Note: If your Laravel versions is >=5.5 you don't need register providers., (*4)

Note: This is not necesary if you are not using Laravel, (*5)

You can optionally publish the config file with:, (*6)

php artisan vendor:publish --provider="FeiMx\Tax\TaxServiceProvider" --tag="config"

This is the contents of the published config file:, (*7)

return [
    /**
     * Used The fallback type determines the type to use when the current one
     * is not available. You may change the value to correspond to any of
     * provided types
     */
    'fallback' => 'default',
    /**
     * List of taxes with their types ans percentages
     * You can add more types and percentages.
     */
    'taxes' => [
        'iva' => [
            'default' => 0.16,
            'retention' => -0.106667,
        ],
        'isr' => [
            'default' => -0.106667,
        ],
        'ieps' => [
            'default' => 0.08,
            'retention' => -0.08,
            'primary' => 0.11,
            'secondary' => 0.13,
        ],
    ],
];

Note: This is not necesary if you are not using Laravel, (*8)

You can optionally publish the migrations file with:, (*9)

php artisan vendor:publish --provider="FeiMx\Tax\TaxServiceProvider" --tag="migrations"

Note: This is not necesary if you are not using Laravel, (*10)

Usage

Firt need create a new instance of TaxManager:, (*11)

``` php $taxManager = new FeiMx\Tax\TaxManager($amount = 100);, (*12)


Second you need to add the taxes for calculate the final amount: The first parameter could be a tax name `['iva', 'ieps', 'isr']` or an instance of `FeiMx\Tax\Contracts\TaxContract`. Exist 3 Tax Objects: ``` php $iva = new \FeiMx\Tax\Taxes\IVA($retention = false); $isr = new \FeiMx\Tax\Taxes\ISR($retention = false); $ieps = new \FeiMx\Tax\Taxes\IEPS($retention = false); $taxManager->addTax($tax = 'iva', $retention = false); $taxManager->addTax($iva);

Note: You can pass a string for a tax type of given config file instead the retention boolean param., (*13)

``` php $iva = new \FeiMx\Tax\Taxes\IVA('free'); $taxManager->addTax($tax = 'iva', 'free');, (*14)


You can add multiple taxes at once: ``` php $taxManager->addTaxes([ 'iva', $isr, $ieps, ]);

Now you can get the final amount:, (*15)

``` php $taxManager->total(); // or $taxManager->total;, (*16)


You can get a list for given data: ``` php $taxManager->get();

This is the contents of get method:, (*17)

``` php [ 'amount' => 100, 'total' => '105.333300', 'taxes' => [ [ 'tax' => 'iva', 'amount' => '16.000000', ], [ 'tax' => 'isr', 'amount' => '-10.666700', ], ], ];, (*18)


## Models You can assign Taxable trait to your models. ``` php use FeiMx\Tax\Traits\Taxable; class Product extends Model { use Taxable; protected $fillable = ['price']; }

You can assign tax groups to your model:, (*19)

``` php $product = Product::first(); $taxGroup = \FeiMx\Tax\Models\TaxGroup::first();, (*20)

$product->assignTaxGroup($taxGroup);, (*21)


You can pass a name and multiples tax groups: ``` php $product->assignTaxGroup('iva'); $product->assignTaxGroup('iva', 'isr'); $product->assignTaxGroup(['iva', 'isr']); $product->assignTaxGroup(collect(['iva', $taxGroup]));

You can sync too:, (*22)

``` php $product->syncTaxGroups('iva'); $product->syncTaxGroups('iva', 'isr'); $product->syncTaxGroups(['iva', 'isr']);, (*23)


And you can remove: ``` php $product->removeTaxGroup('iva'); $product->removeTaxGroup($taxGroup);

You can verify if a model has a TaxGroup:, (*24)

``` php $product->hasTaxGroup('iva'); $product->hasTaxGroup($taxGroup); $product->hasTaxGroup([$taxGroup, 'iva']);, (*25)


For get the total amount after taxes, must need to know what column use, for defaul we use `price` column, but you can use another one: ``` php class Product extends Model { use Taxable; protected $fillable = ['price']; public static function priceColumn() { return 'price'; } }

Now you can get the total of a given TaxGroup:, (*26)

``` php $product->total($taxGroup);, (*27)


And you can obtain the content of the get method of the TaxManager: ``` php $product->getAmounts($taxGroup);

Testing

bash composer test, (*28)

Changelog

Please see CHANGELOG for more information what has changed recently., (*29)

Contributing

Please see CONTRIBUTING for details., (*30)

Security

If you discover any security related issues, please email yorch@fei.com.mx instead of using the issue tracker., (*31)

Credits

Support us

FEI is a Digital Invoicing startup based in Yucatán, México. You'll find an overview of all our open source projects on our website., (*32)

Does your business depend on our contributions? Reach out and support us on Patreon. All pledges will be dedicated to allocating workforce on maintenance and new awesome stuff., (*33)

License

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

The Versions

18/04 2018

dev-master

9999999-dev https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps

18/04 2018

1.1.3

1.1.3.0 https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps

18/04 2018

dev-feature/fix-issues-with-tax-model

dev-feature/fix-issues-with-tax-model https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi feimx iva isr ieps

02/04 2018

1.1.2

1.1.2.0 https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps

19/03 2018

dev-fix/error-with-missing-column-index

dev-fix/error-with-missing-column-index https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps

18/03 2018

1.1.0

1.1.0.0 https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps

15/03 2018

1.0.0

1.0.0.0 https://github.com/feimx/tax

This Package allow calculate Tax to an amount

  Sources   Download

MIT

The Requires

 

The Development Requires

tax cfdi facturación electrónica feimx iva isr ieps