Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
omaralalwi committed May 31, 2024
1 parent e839b6e commit 1df879f
Show file tree
Hide file tree
Showing 6 changed files with 224 additions and 384 deletions.
226 changes: 224 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,236 @@
# Laravel Taxify

<p align="center">
<a href="https://omaralalwi.github.io/laravel-taxify" target="_blank">
<a href="https://github.com/omaralalwi/laravel-taxify" target="_blank">
<img src="https://raw.githubusercontent.com/omaralalwi/laravel-taxify/master/public/images/taxify.jpg" alt="Laravel Taxify">
</a>
</p>

Laravel Taxify provides a 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.
## Installation

To install the latest stable version of the Laravel Taxify package, use Composer. Please note that version `2.0.x` supports Laravel `8.x` and later, along with PHP `8.0.x` and above. If your application uses an older version, refer to the Compatibility section below.

```bash
composer require omaralalwi/laravel-taxify
```
publish the package's configuration file:

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

## Compatibility

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

```bash
composer require omaralalwi/laravel-taxify:^1.0.4
```

## Usage

### Available Helper Functions

laravel taxify many of helper functions to simplify usage.

- `calculateTax()`.
- `calculateTaxForCollection()`.
- `getTaxAmount()` .
- `getTaxRate()` .
- `getTaxType()` .
- `getTaxRateAsPercentage()` .

### Examples:

#### Calculate tax for an amount:

- get Tax As object (default)
by default the function return result as object
```php
$amount = 250;
$tax = calculateTax($amount,'profileName');
```
Result
```php
$tax = {
"amount_with_tax": 287.5,
"tax_amount": 37.5,
"tax_rate": 0.15,
}
```
access it as object property
```php
$taxAmount = $tax->tax_amount
// 37.5
$AmountWithTax = $tax->amount_with_tax
// 287.5
$taxRate = $tax->tax_rate
// 0.15
```

Or simplify access it directly
```php
$amount = 250;
$taxAmount = calculateTax($amount,'profileName')->tax_amount;
```

- use `calculateTax` to get Tax As Array
you can pass $asArray param as true to get result as array
```php
$amount = 250;
$tax = calculateTax($amount,'profileName',true);
```
Result
```
$tax = [
"amount_with_tax" => 287.5,
"tax_amount" => 37.5,
"tax_rate" => 0.15,
]
```
access it as array key
```php
$taxAmount = $tax['tax_amount']
// 37.5
$AmountWithTax = $tax['amount_with_tax']
// 287.5
$taxRate = $tax['tax_rate']
// 0.15
```

Or simplify access it directly
```php
$amount = 250;
$taxAmount = calculateTax($amount,'',true)['tax_amount'];
```

**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 .

- use `calculateTaxForCollection` to get a tax for a collection of amounts by passing amounts as array (first param) -> Result wanted as object (default).

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

$tax = calculateTaxForCollection([$productAmount,$featureAmount, $sarrantyAmount, $chargeAmount]);
```
Result (object)
```php
$tax = {
"amount_with_tax": 507.265,
"tax_amount": 66.165,
"tax_rate": 0.15,
}
```
```php
$taxAmount = $tax->tax_amount // 507.265
```

- get a tax for a collection of amounts by passing amounts as array (first param) --> Result wanted as array.

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

$tax = calculateTaxForCollection([$productAmount,$featureAmount, $sarrantyAmount, $chargeAmount],'',true);
```
Result (object)
```php
$tax = [
"amount_with_tax" => 507.265,
"tax_amount" => 66.165,
"tax_rate" => 0.15,
]
```

#### Get Tax Amount as numeric value

- use `getTaxAmount` to get Tax Amount as number

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

#### Get tax rate or tax amount:

- use `getTaxRate` to get Tax Rate or amount (according to tax type for specified profile in config file)

```php
getTaxRate()
// Result 0.15
```

```php
getTaxRate('sales')
// 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:

- use `getTaxType` to you can get Tax Type

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

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

you can get Tax Rate As Percentage
- you can get a tax rate percentage (for percentage type only)

```php
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:

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

example configuration for fixed tax type:

```dotenv
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 .


## [Documentation](https://omaralalwi.github.io/laravel-taxify)

## Features

Expand Down
Empty file removed docs/.nojekyll
Empty file.
Loading

0 comments on commit 1df879f

Please sign in to comment.