addeeandra / vat-calculator
VAT Calculator
1.0.0
2025-01-11 11:07 UTC
Requires
- php: ^8.2|^8.3|^8.4
- illuminate/contracts: ^10.0||^11.0
- spatie/laravel-package-tools: ^1.16
Requires (Dev)
- larastan/larastan: ^2.9
- laravel/pint: ^1.14
- nunomaduro/collision: ^8.1.1||^7.10.0
- pestphp/pest: ^3.0
README
VAT Calculator
Configurable VAT Rate & Calculator
Vat Calculator ID
This library is a simple VAT calculator.
What's in this library?
- VAT Rule 11%
- VAT Rule 12% with custom base (e.g. 11/12)
- VAT Calculator, when given VAT Rule, you can
- Calculate VAT of an amount (e.g.
AmountExclVat=100_000
=>11_000
) - Extract VAT from an amount (e.g.
AmountInclVat=111_000
=>11_000
) - Get total amount include VAT (e.g.
AmountExclVat=100_000
=>111_000
) - Get amount exclude VAT from (e.g.
AmountInclVat=111_000
=>100_000
)
- Calculate VAT of an amount (e.g.
Installation
You can install this package by simply running composer require addeeandra/vat-calculator
How to use
To use this library is simple.
use \Addeeandra\VatCalculator\Rules; use \Addeeandra\VatCalculator\Builders; # To use PPN 11% Rule $rule = new Rules\Vat12Rule(); $rule->calculate(100_000); // 11_000 (float) $rule->calculator()->vatInAmount(111_000); // 11_000 (float) # To use PPN 12% Rule $rule = new Rules\Vat12Rule(); $rule->calculate(100_000); // 11_000 (float) $rule->calculator()->vatInAmount(111_000); // 11_000 (float)
See VatRuleTest and VatCalculatorTest for more examples.
Need Custom VAT Rule?
You can make custom VAT Rule using VatRuleBuilder
considering how fluid is our country's regulation.
// new VAT Rate 12% without base 11/12 $newVatRule = \Addeeandra\VatCalculator\Builders\VatRuleBuilder::make() ->rate(12) // 12% ->build(); // new VAT Rate 12% with base 15/12 which equals to 15% $newVatRule = \Addeeandra\VatCalculator\Builders\VatRuleBuilder::make() ->rate(12) // 12% ->base(fn (int|float $amount) => $amount * 15 / 12) // whoops, it's actually 15% :) ->build();
License
MIT License