PHP code example of sunfoxcz / price-calculator

1. Go to this page and download the library: Download sunfoxcz/price-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/ */

    

sunfoxcz / price-calculator example snippets


 declare(strict_types=1);

use Sunfox\PriceCalculator\Discount\PercentDiscount;
use Sunfox\PriceCalculator\PriceCalculator;

/* @var Sunfox\PriceCalculator\PriceCalculatorResult $calc */
$calc = (new PriceCalculator)
	->setBasePrice(1983.48)
	->setDiscount(new PercentDiscount(10.0))
	->setVatRate(21.0)
	->calculate();

$calc->getBasePrice(); // price without VAT and discount
$calc->getDiscount();  // discount in percent without VAT
$calc->getPrice();     // price after discount without VAT
$calc->getVatRate();   // VAT rate in percent
$calc->getVat();       // VAT value
$calc->getPriceVat();  // price after discount with VAT
$calc->toArray();      // Ger results as array

$calc->getCalculator(); // Sunfox\PriceCalculator\PriceCalculator