From f8b37aff3ecabb159b0a848cf8214f9d7ebbdd07 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 2 Mar 2024 18:28:20 +0300 Subject: [PATCH 1/3] add pcakge docs --- docs/index.md | 1 - 1 file changed, 1 deletion(-) delete mode 100644 docs/index.md diff --git a/docs/index.md b/docs/index.md deleted file mode 100644 index be4505f..0000000 --- a/docs/index.md +++ /dev/null @@ -1 +0,0 @@ -The doc will coming soon . From e5c1cab763eb02eaf8b97bcca0f9e1eccb55cdd5 Mon Sep 17 00:00:00 2001 From: omaralalwi Date: Sat, 2 Mar 2024 18:30:00 +0300 Subject: [PATCH 2/3] update --- .idea/.gitignore | 8 + .idea/laravel-taxify.iml | 12 ++ .idea/modules.xml | 8 + .idea/php.xml | 20 ++ .idea/phpunit.xml | 10 + .idea/vcs.xml | 6 + README.md | 7 + docs/.nojekyll | 0 docs/README.md | 278 +++++++++++++++++++++++++++ docs/index.html | 22 +++ src/LaravelTaxifyServiceProvider.php | 4 +- 11 files changed, 373 insertions(+), 2 deletions(-) create mode 100644 .idea/.gitignore create mode 100644 .idea/laravel-taxify.iml create mode 100644 .idea/modules.xml create mode 100644 .idea/php.xml create mode 100644 .idea/phpunit.xml create mode 100644 .idea/vcs.xml create mode 100644 docs/.nojekyll create mode 100644 docs/README.md create mode 100644 docs/index.html diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/laravel-taxify.iml b/.idea/laravel-taxify.iml new file mode 100644 index 0000000..922c9ee --- /dev/null +++ b/.idea/laravel-taxify.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..6834a2b --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml new file mode 100644 index 0000000..a85fe78 --- /dev/null +++ b/.idea/php.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml new file mode 100644 index 0000000..4f8104c --- /dev/null +++ b/.idea/phpunit.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index 24db65c..21b13a7 100644 --- a/README.md +++ b/README.md @@ -17,10 +17,17 @@ You can install latest stable version of package via Composer: composer require omaralalwi/laravel-taxify ```` +publish all package resource + ```markdown php artisan vendor:publish --provider="Omaralalwi\LaravelTaxify\LaravelTaxifyServiceProvider" ``` +publish only config file +```markdown +php artisan vendor:publish --tag=laravel-taxify-config +``` + ## Compatibility The Laravel Taxify package has different versions based on the compatibility with Laravel and PHP versions. diff --git a/docs/.nojekyll b/docs/.nojekyll new file mode 100644 index 0000000..e69de29 diff --git a/docs/README.md b/docs/README.md new file mode 100644 index 0000000..21b13a7 --- /dev/null +++ b/docs/README.md @@ -0,0 +1,278 @@ +# Laravel Taxify + +

+ + Laravel Taxify + +

+ +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 + +You can install latest stable version of package via Composer: + +**Note**: version2.0.x support Laravel v8.x and Later , and PHPv8.0.x and up, if your app use older version , please see Compatibility section. +```bash +composer require omaralalwi/laravel-taxify +```` + +publish all package resource + +```markdown +php artisan vendor:publish --provider="Omaralalwi\LaravelTaxify\LaravelTaxifyServiceProvider" +``` + +publish only config file +```markdown +php artisan vendor:publish --tag=laravel-taxify-config +``` + +## Compatibility + +The Laravel Taxify package has different versions based on the compatibility with Laravel and PHP versions. + +### Laravel v7.x and Earlier + +For Laravel versions `5.8`, `6.x`, `7.x`, and PHP version `7.4`, use version `1.0.4` of the Laravel Taxify package. + +```bash +composer require omaralalwi/laravel-taxify:^1.0.4 +``` + +### Laravel v8.x and Later + +For Laravel versions `8.x`, `9.x`, `10.x`, and PHP versions `8.0`, `8.1`, `8.2`, `8.3`, and higher, use at least version `2.0.x` of the Laravel Taxify package, and keep up to date. + + +## Configuration + +### Environment Variables + +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: + +```markdown +DEFAULT_TAXIFY_PROFILE="default" +TAXIFY_DEFAULT_RATE="0.10" +TAXIFY_DEFAULT_TYPE="percentage" +``` + +For a fixed tax type: + +```markdown +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 . + +## Usage + +### Available Helper Functions + +laravel taxify many of helper functions to simplify usige. +- `calculateTax()` --> common usage. +- `calculateTaxForCollection()` common usage with E-commerce and Enterprise Applications. +- `getTaxAmount()` . +- `getTaxRate()` . +- `getTaxType()` . +- `getTaxRateAsPercentage()` . + +### Examples: + +#### Calculate tax for an amount: + +- get Tax As object (default) + by default the function return result as object +```markdown +$amount = 250; +$tax = calculateTax($amount,'profileName'); +``` +Result (object) +``` +amount_with_tax: 275 +tax_amount: 25 +tax_rate: 0.1 +``` +access it as object property +```markdown +$taxAmount = $tax->tax_amount +// 25 +$AmountWithTax = $tax->amount_with_tax +// 275 +$taxRate = $tax->tax_rate +// 0.1 +``` + +Or simpilify +```markdown +$amount = 250; +$taxAmount = calculateTax($amount,'profileName')->tax_amount; +``` + +- get Tax As Array + you can pass $asArray param as true to get result as array +```markdown +$amount = 250; +$tax = calculateTax($amount,'profileName',true); +``` +Result +``` +array ( +'amount_with_tax' => 220.0, +'tax_amount' => 20.0, +'tax_rate' => 0.1, +); +``` +access it as object property +```markdown +$taxAmount = $tax['tax_amount'] +// 25 +$AmountWithTax = $tax['amount_with_tax'] +// 275 +$taxRate = $tax['tax_rate'] +// 0.1 +``` + +Or simpilify +```markdown +$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 . +- get a tax for a collection of amounts by passing amounts as array (first param). +```markdown +// 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) +```markdown +'amount_with_tax' => 485.21, +'tax_amount' => 44.11, +'tax_rate' => 0.1, +``` + +access it as object property +```markdown +$taxAmount = $tax->tax_amount +// 485.21 +$AmountWithTax = $tax->amount_with_tax +// 44.11 +$taxRate = $tax->tax_rate +// 0.1 +``` + +#### Get Tax Amount as numeric value + +- get Tax Amount as number +```markdown +$amount = 250; +getTaxAmount($amount); +``` +Result +```markdown +25 +``` + +#### Get tax rate or tax amount: + +- get Tax Rate or amount (according to tax type for specified profile in config file) + +```markdown +getTaxRate() +``` +Result +```markdown +0.1 +``` + +```markdown +getTaxRate('sales') +``` +Result +```markdown +50 +``` +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: + +you can get Tax Type +```markdown +getTaxType('profileName') +``` +Result: +``` +fixed or percentage // according to 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) +```markdown + getTaxRateAsPercentage(); +``` +Result +``` +'10.00%' +``` +**Note**: for default profile no need to pass it + +## Features + +- Calculate tax for individual amounts or a collection of amounts +- Retrieve tax amount, rate, and type for any profile as individual. +- Retrieve tax `amount_with_tax` and `tax_amount` and `tax_rate` for any profile as individual for one amount or a collection of amounts +- Get tax rate as a percentage (for percentage type only) +- Customizable configuration options through environment variables easy. +- helper functions easy-to-use. +- support all php and laravel versions. +- Exception Handling: Robust error handling to ensure smooth operation and easy debugging. +- Logging: Automatic logging of errors and exceptions for better error tracking and debugging. +- Unit Tests. + +### Testing + +```bash +php artisan test --filter TaxifyTest +``` + +### Changelog + +Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recently. + +## Contributing + +Please see [CONTRIBUTING](CONTRIBUTING.md) 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 + +- [omar alalwi](https://omaralalwi.info) + +## License + +The MIT License (MIT). Please see [License File](LICENSE.md) for more information. diff --git a/docs/index.html b/docs/index.html new file mode 100644 index 0000000..04dd4a7 --- /dev/null +++ b/docs/index.html @@ -0,0 +1,22 @@ + + + + + Document + + + + + + +
+ + + + + diff --git a/src/LaravelTaxifyServiceProvider.php b/src/LaravelTaxifyServiceProvider.php index 51059de..329992a 100644 --- a/src/LaravelTaxifyServiceProvider.php +++ b/src/LaravelTaxifyServiceProvider.php @@ -17,8 +17,8 @@ public function boot() */ if ($this->app->runningInConsole()) { $this->publishes([ - __DIR__.'/../config/config.php' => config_path('taxify.php'), - ], 'config'); + __DIR__.'/../config/config.php' => config_path(TaxifyKeys::CONFIG_FILE.'.php'), + ], TaxifyKeys::CONFIG_FILE.'-config'); // $this->commands([]); } From 7e1dda9e57c17912239ee4e1bfd69812ca208bf3 Mon Sep 17 00:00:00 2001 From: Omar Alalwi Date: Sat, 2 Mar 2024 18:30:34 +0300 Subject: [PATCH 3/3] Delete .idea directory --- .idea/.gitignore | 8 -------- .idea/laravel-taxify.iml | 12 ------------ .idea/modules.xml | 8 -------- .idea/php.xml | 20 -------------------- .idea/phpunit.xml | 10 ---------- .idea/vcs.xml | 6 ------ 6 files changed, 64 deletions(-) delete mode 100644 .idea/.gitignore delete mode 100644 .idea/laravel-taxify.iml delete mode 100644 .idea/modules.xml delete mode 100644 .idea/php.xml delete mode 100644 .idea/phpunit.xml delete mode 100644 .idea/vcs.xml diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/laravel-taxify.iml b/.idea/laravel-taxify.iml deleted file mode 100644 index 922c9ee..0000000 --- a/.idea/laravel-taxify.iml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 6834a2b..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/php.xml b/.idea/php.xml deleted file mode 100644 index a85fe78..0000000 --- a/.idea/php.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/phpunit.xml b/.idea/phpunit.xml deleted file mode 100644 index 4f8104c..0000000 --- a/.idea/phpunit.xml +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file