PHP code example of viddyoze-engineering / vat-calculator

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

    

viddyoze-engineering / vat-calculator example snippets


// Easy to use!
$countryCode = VatCalculator::getIPBasedCountry();
VatCalculator::calculate( 24.00, $countryCode );
VatCalculator::calculate( 24.00, $countryCode, $postalCode );
VatCalculator::calculate( 71.00, 'DE', '41352', $isCompany = true );
VatCalculator::getTaxRateForLocation( 'NL' );
// Check validity of a VAT number
VatCalculator::isValidVATNumber('NL123456789B01');

use Mpociot\VatCalculator\VatCalculator;

$vatCalculator = new VatCalculator();
$vatCalculator->setBusinessCountryCode('DE');
$countryCode = $vatCalculator->getIPBasedCountry();
$grossPrice = $vatCalculator->calculate( 49.99, 'LU' );

$grossPrice = VatCalculator::calculate( 24.00, 'DE' );

$grossPrice = VatCalculator::calculate( 24.00, 'DE', '12345', $isCompany = true );

$grossPrice = VatCalculator::calculate( 24.00, 'DE' ); // 28.56
$taxRate    = VatCalculator::getTaxRate(); // 0.19
$netPrice   = VatCalculator::getNetPrice(); // 24.00
$taxValue   = VatCalculator::getTaxValue(); // 4.56

if (VatCalculator::shouldCollectVAT('DE')) {

}

try {
	$validVAT = VatCalculator::isValidVATNumber('NL 123456789 B01');
} catch( VATCheckUnavailableException $e ){
	// Please handle me
}

try {
	$vat_details = VatCalculator::getVATDetails('NL 123456789 B01');
	print_r($vat_details);
	/* Outputs
	stdClass Object
	(
		[countryCode] => NL
		[vatNumber] => 123456789B01
		[requestDate] => 2017-04-06+02:00
		[valid] => false
		[name] => Name of the company
		[address] => Address of the company
	)
	*/
} catch( VATCheckUnavailableException $e ){
	// Please handle me
}

$rules = array(
    'first_name'  => ''company_vat' => 'vat_number'
);

$validator = Validator::make(Input::all(), $rules);

use Laravel\Cashier\Billable;
use Mpociot\VatCalculator\Traits\BillableWithinTheEU;
use Laravel\Cashier\Contracts\Billable as BillableContract;

class User extends Model implements BillableContract
{
    use Billable, BillableWithinTheEU {
        BillableWithinTheEU::taxPercentage insteadof Billable;
    }

    protected $dates = ['trial_ends_at', 'subscription_ends_at'];
}

$user = User::find(1);

// For individuals use:
$user->useTaxFrom('NL');

// For business customers with a valid VAT ID, use:
$user->useTaxFrom('NL')->asBusiness();

$user->subscription('monthly')->create($creditCardToken);

$countryCode = VatCalculator::getIPBasedCountry();
bash
$ php artisan vendor:publish --provider="Mpociot\VatCalculator\VatCalculatorServiceProvider"
bash
$ php artisan vendor:publish --provider="Mpociot\VatCalculator\VatCalculatorServiceProvider"