Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/add tests for retentions #3

Merged
merged 9 commits into from
Mar 15, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 115 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
# Very short description of the package
# Calculate taxes for a given amount

[![Latest Version on Packagist](https://img.shields.io/packagist/v/feimx/tax.svg?style=flat-square)](https://packagist.org/packages/feimx/tax)
[![Build Status](https://img.shields.io/travis/feimx/tax/master.svg?style=flat-square)](https://travis-ci.org/feimx/tax)
[![Quality Score](https://img.shields.io/scrutinizer/g/feimx/tax.svg?style=flat-square)](https://scrutinizer-ci.com/g/feimx/tax)
[![Total Downloads](https://img.shields.io/packagist/dt/feimx/tax.svg?style=flat-square)](https://packagist.org/packages/feimx/tax)

This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
The `feimx/tax` package provide a simple way for calculate taxes of an amount.

## Basic Usage

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

## Installation

Expand All @@ -15,12 +23,115 @@ You can install the package via composer:
composer require feimx/tax
```

Next, you must install the service provider:

```php
// config/app.php
'providers' => [
FeiMx\Tax\TaxServiceProvider::class,
];
```

_Note:_ If your laravel versions is `>=5.5` you don't need register providers.

You can optionally publish the config file with:

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

This is the contents of the published config file:

```php
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,
],
],
];
```

## Usage

Firt need create a new instance of `TaxManager`:

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

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);
```

You can add multiple taxes at once:

``` php
$taxManager->addTaxes([
'iva', $isr, $ieps,
]);
```

Now you can get the final amount:

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

You can get a list for given data:

``` php
$taxManager->get();
```

This is the contents of get method:

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

### Testing
Expand Down
12 changes: 10 additions & 2 deletions config/tax.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
<?php

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.16,
'retention' => -0.106667,
],
'isr' => [
'default' => -0.106667,
Expand Down
8 changes: 4 additions & 4 deletions tests/TaxManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ public function testCanCalculateIVARetention()

$taxManager = new TaxManager(100);
$taxManager->addTax('iva', $retention);
$this->assertEquals(84.000000, $taxManager->total());
$this->assertEquals(89.333300, $taxManager->total());

$taxManager = new TaxManager(5470);
$taxManager->addTax('iva', $retention);
$this->assertEquals(4594.800000, $taxManager->total());
$this->assertEquals(4886.531510, $taxManager->total());

$taxManager = new TaxManager(2300.90);
$taxManager->addTax('iva', $retention);
$this->assertEquals(1932.756000, $taxManager->total());
$this->assertEquals(2055.469900, $taxManager->total());
}

public function testCanCalculateIEPS()
Expand Down Expand Up @@ -241,6 +241,6 @@ public function testCombineTraslateAndRetentions()
$taxManager->addTax('isr');
$taxManager->addTax('iva', $retention);
$taxManager->addTax('ieps', $retention);
$this->assertEquals(81.333300, $taxManager->total());
$this->assertEquals(86.6666, $taxManager->total());
}
}
6 changes: 3 additions & 3 deletions tests/TaxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function testCanGetCalculatedAmount()
$this->assertEquals(16.000000, $iva->calculate(100));

$iva = new IVA($retention);
$this->assertEquals(-16.000000, $iva->calculate(100));
$this->assertEquals(-10.666700, $iva->calculate(100));

$isr = new ISR();
$this->assertEquals(-10.666700, $isr->calculate(100));
Expand All @@ -49,11 +49,11 @@ public function testCanGetPercentageByType()

$iva = new IVA();
$this->assertEquals(0.16, $iva->percentage());
$this->assertEquals(-0.16, $iva->percentage('retention'));
$this->assertEquals(-0.106667, $iva->percentage('retention'));
$this->assertEquals(0.16, $iva->percentage('unexist'));

$iva = new IVA($retention);
$this->assertEquals(-0.16, $iva->percentage());
$this->assertEquals(-0.106667, $iva->percentage());

$isr = new ISR();
$this->assertEquals(-0.106667, $isr->percentage());
Expand Down