PHP code example of addeeandra / vat-calculator
1. Go to this page and download the library: Download addeeandra/vat-calculator library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
addeeandra / vat-calculator example snippets
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)
// 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();