Git Product home page Git Product logo

vat-calculator's Introduction

VatCalculator

Tests Coding Standards Latest Stable Version Total Downloads

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Integrates with Laravel and Cashier — or in a standalone PHP application. Originally created by Marcel Pociot.

// Easy to use!
VatCalculator::calculate(24.00, $countryCode = 'DE');
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');

Warning

This package does not provide any promises for correctly calculated taxes. You are still responsible to making sure that any calculated tax is correct for your use case. If you're uncertain if a certain tax is correct or not, it's best that you talk to an accountant.

Requirements

  • PHP 7.3 or higher
  • (optional) Laravel 6.0 or higher

Installation

Install the package with composer:

composer require mpociot/vat-calculator

Standalone

You can also use this package without Laravel. Simply create a new instance of the VatCalculator and use it. All documentation examples use the Laravel Facade code, so make sure not to call the methods as if they were static methods.

use Mpociot\VatCalculator\VatCalculator;

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

Upgrading

Please refer to the upgrade guide when upgrading the library.

Usage

Calculate the gross price

To calculate the gross price use the calculate method with a net price and a country code as parameters.

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

The third parameter is the postal code of the customer.

As a fourth parameter, you can pass in a boolean indicating whether the customer is a company or a private person. If the customer is a company, which you should check by validating the VAT number, the net price gets returned.

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

Receive more information

After calculating the gross price you can extract more information from the VatCalculator.

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

Validate EU VAT numbers

Prior to validating your customers VAT numbers, you can use the shouldCollectVAT method to check if the country code requires you to collect VAT in the first place.

if (VatCalculator::shouldCollectVAT('DE')) {
    // This country code requires VAT collection...
}

To validate your customers VAT numbers, you can use the isValidVATNumber method. The VAT number should be in a format specified by the VIES. The given VAT numbers will be truncated and non relevant characters / whitespace will automatically be removed.

This service relies on a third party SOAP API provided by the EU. If, for whatever reason, this API is unavailable a VATCheckUnavailableException will be thrown.

try {
    $validVAT = VatCalculator::isValidVATNumber('NL 123456789 B01');
} catch (VATCheckUnavailableException $e) {
    // The VAT check API is unavailable...
}

Alternatively, it is also possible to validate only the format of the VAT Number specified by VIES. This is useful, if you do not want to wait for a response from the SOAP API.

// This check will return false because no connection to VIES could be made...
$validVAT = VatCalculator::isValidVATNumber('NL 123456789 B01');

// This check will return true because only the format is checked...
$validVAT = VatCalculator::isValidVatNumberFormat('NL 123456789 B01');

Get EU VAT number details

To get the details of a VAT number, you can use the getVATDetails method. The VAT number should be in a format specified by the VIES. The given VAT numbers will be truncated and non relevant characters / whitespace will automatically be removed.

This service relies on a third party SOAP API provided by the EU. If, for whatever reason, this API is unavailable a VATCheckUnavailableException will be thrown.

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) {
    // The VAT check API is unavailable...
}

UK VAT Numbers

UK VAT numbers are formatted a little differently:

try {
    $vat_details = VatCalculator::getVATDetails('GB 553557881');
    print_r($vat_details);
    /* Outputs
    array(3) {
        ["name"]=>
            string(26) "Credite Sberger Donal Inc."
        ["vatNumber"]=>
            string(9) "553557881"
        ["address"]=>
            array(3) {
                ["line1"]=>
                    string(18) "131B Barton Hamlet"
                ["postcode"]=>
                    string(8) "SW97 5CK"
                ["countryCode"]=>
                    string(2) "GB"
            }
    }
    */
} catch (VATCheckUnavailableException $e) {
    // The VAT check API is unavailable...
}

Laravel

Configuration

By default, the VatCalculator has all EU VAT rules predefined, so that it can easily be updated, if it changes for a specific country.

If you need to define other VAT rates, you can do so by publishing the configuration and add more rules.

Warning
Be sure to set your business country code in the configuration file, to get correct VAT calculation when selling to business customers in your own country.

To publish the configuration files, run the vendor:publish command

php artisan vendor:publish --provider="Mpociot\VatCalculator\VatCalculatorServiceProvider"

This will create a vat_calculator.php in your config directory.

Handling SOAP Faults

If for some reason, SOAP faults happen when the VIES API is faulty, these errors will be handled gracefully and false will be returned. However, if you explicitly want to be aware of any SOAP faults you may instruct VatCalculator to throw them as a VATCheckUnavailableException. The VATCheckUnavailableException will then contain the specific message of the SOAP fault.

Set the option to true in your config file:

<?php

return [
    'forward_soap_faults' => true,
];

You can also set a timeout for the SOAP client. By default, SOAP aborts the request to VIES after 30 seconds. If you do not want to wait that long, you can reduce the timeout, for example to 10 seconds:

<?php

return [
    'soap_timeout' => 10,
];

ValidVatNumber Validation Rule

VatCalculator also ships with a ValidVatNumber validation rule for VAT Numbers. You can use this when validation input from a form request or a standalone validator instance:

use Mpociot\VatCalculator\Rules\ValidVatNumber;

$validator = Validator::make(Input::all(), [
    'first_name' => 'required',
    'last_name' => 'required',
    'company_vat' => ['required', new ValidVatNumber],
]);

if ($validator->passes()) {
    // Input is correct...
}

Warning

The validator extension returns false when the VAT ID Check SOAP API is unavailable.

Cashier Stripe Integration

Note

At the moment this package is not compatible with Cashier Stripe v13 or higher because it still relies on the old taxPercentage method which has been removed from Cashier v13. You can still use it on older Cashier Stripe versions in the meantime.

If you want to use this package in combination with Laravel Cashier Stripe you can let your billable model use the BillableWithinTheEU trait. Because this trait overrides the taxPercentage method of the Billable trait, we have to explicitly tell our model to do so.

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'];
}

By using the BillableWithinTheEU trait, your billable model has new methods to set the tax rate for the billable model.

Set everything in one command:

  • setTaxForCountry($countryCode, $company = false)

Or use the more readable, chainable approach:

  • useTaxFrom($countryCode) — Use the given countries tax rate
  • asIndividual() — The billable model is not a company (default)
  • asBusiness() — The billable model is a valid company

So in order to set the correct tax percentage prior to subscribing your customer, consider the following workflow:

$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);

Changelog

Check out the CHANGELOG in this repository for all the recent changes.

Maintainers

VatCalculator is maintained by Dries Vints. Originally created by Marcel Pociot.

License

VatCalculator is open-sourced software licensed under the MIT license.

vat-calculator's People

Contributors

driesvints avatar ettemlevest avatar fossil01 avatar galexth avatar gherkins avatar greenhof avatar hanspagel avatar iruoy avatar k2oumais avatar kduma avatar kitbs avatar lanort avatar lsimeonov avatar michellaurent avatar mpociot avatar mrk-j avatar netpok avatar nspehler avatar orottier avatar pascalbaljet avatar pmochine avatar rossbearman avatar shad9w avatar shuvroroy avatar spaze avatar spekulatius avatar stylecibot avatar webcraft avatar webdevvie avatar willselby avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vat-calculator's Issues

SoapClient in the __construct()?

Is that really necessary to init SoapClient in the constructor?
I mean, if I need vat calculator for other reasons (check vat rate) do i really have to load 'wsdl' all the time? What about to use setSoapClient() for that reason?

Include requestor VAT number

Hi,

I would like to be able to pass along our own VAT number to the VIES validation service. When doing so, the VIES validation service returns a reference of the check. This reference can be kept by us to 'proof' we validated the VAT number with VIES, in case we ever have an issue with the tax officers.

It would be nice that we can optionally send the $requestorVAT and get that reference as return.

THank you for considering this.

Temporary problems with FR and BE vat numbers

For anyone researching problems with French or Belgian vat numbers: the European database has trouble with these. (so not package related)

Belgium’s (BE) National VIES Component is facing temporary technical issues related to the validation of some Belgian VAT numbers.
As a result, some Belgian VAT numbers are incorrectly considered as invalid.
The Belgian Tax Administration is working towards a resolution. Sincere apologies for any inconvenience.
We will inform you as soon as the concerned issue is solved.

Further reading: http://ec.europa.eu/taxation_customs/vies/vatRequest.html

Standalone... requires Facade

Hello,

I have been exploring the most starred options in what regards VAT validation and company information retrieval and I've come up with your repository.

As I've moved forward the documentation and the installation I have faced some problems regarding your Facade implementation.

I have a project where I am using Yii2 as the framework. From what I've seen the main focus of this repo is Laravel and Standalone options. I would guess that Standalone would work for me, however my framework does not seem to accept facades as Laravel does.

I would like to ask, if removing the Facade Pattern dependency would eventually come to the roadmap?

Thanks and congrats for the great work!

Problem with getIPBasedCountry and isValidVATNumber

Hi,

I try to make use of VatCalculator in Laravel but got this error when running locally:

ErrorException in VatCalculator.php line 136:
file_get_contents(http://ip2c.org/::1): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

when I run:

$countryCode = VatCalculator::getIPBasedCountry();

I think I installed it correctly because this works: VatCalculator::calculate( 10.00, 'PL' );

Also VatCalculator::isValidVATNumber('NL 123456789 B01'); returns nothing.

Thx.

SoapFault

Hi,

I get this error (have not changed anything to my code, just booted up my VM this morning):

SoapFault in VatCalculator.php line 115:
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl' : failed to load external entity "http://ec.europa.eu/taxation_customs/vies/checkVatService.wsdl"

Is it just a problem on ec.europe's part maybe?

Fatal error: while using version 1.6.2

Hello @mpociot , I run into this error:

Fatal error: Call to undefined method Mpociot\VatCalculator\VatCalculator::shouldCollectVAT()

My version is: mpociot/vat-calculator (1.6.2)

I have checked the package in vender folder and the shouldCollectVAT method in VatCalculator.php is not present.

Nuno

Edge case - make postal code not required for Irish addresses

Hi there,

Ireland introduced the Eircode system in 2015 but it's not mandatory for people to use it, and so there are a few cases where Irish customers have been unable to complete purchase due to this being required for calculating the VAT rate.

It's not a case of simply asking these customers to fill in their Eircode - many don't even know what their Eircode is. Do you have any plans for dealing with this edge-case? Maybe a simple if statement - if country is IE and postcode is null, set VAT to 23%?

Validation message not translated

Hi

We are using Laravel 5.2 and cannot get the validation message to be translated. We placed the vat_number key inside the validation.php file, but we always get: vatnumber-validator::validation.vat_number as a result. Any idea what we could be missing?

Calculate net from gross amount?

We'd like to make sure that all of our customers are billed a fixed amount, regardless of their country. This means we'd need to take the gross subscription cost and calculate the net amount from it. Is there any way to do it or plans to support it? AFAIK, this should be a fairly standard practice in EU - you always display the price with VAT.

Let's say I have a subscription plan that's priced at gross 15€/month, and my business is located in Germany. Since VAT rate in Germany is 19%, the net price would be 15€ - 2,39€ = 12,61€.

  1. Customer is from Germany - price is 15€ (including 19% or 2,39€ VAT)
  2. Customer is from Finland, does not have a VAT number - price is 15€ (including 24% or 2,9€ VAT)
  3. Customer is from outside of EU - price is 12,61€ (VAT is always 0% when exporting)
  4. Customer is from any EU country (except from Germany), and has a valid VAT number - price is 12,61€ (VAT is always 0% in this case)

The above calculations are based on the input we've had from our accountant. They are basically the same as your library already does, with one exception - the base price is a gross price, not a net price. This does, admittedly, make the calculation a bit trickier, but then again is fair and easier to understand for customers.

VAT Calculator JS returns zero tax for business country code

The VAT JavaScript calculator always returns 0 for tax_rate and tax_value, even when there's a valid VAT ID and location. This happens because Mpociot\VatCalculator\Http\Controller doesn't construct the VatCalculator with the config file.

This can be fixed by changing the constructor from:
public function __construct(VatCalculator $calculator) { $this->calculator = $calculator; }

to:
public function __construct() { $config = resolve('Illuminate\Contracts\Config\Repository'); $this->calculator = new \Mpociot\VatCalculator\VatCalculator($config); }

Setting own company's country?

Hi Marcel,

First, thank you for this very useful package.

One feature that seems to be missing, is having the possibility to set your 'home' country. If I understand the EU VAT rules correctly, VAT should be charged to companies based in your own country. So, if my company is based in Belgium and I sell to another Belgian company, I have to charge VAT. Right?

How should I handle this situation with this package? It seems VAT 0% is applied to all companies, regardless of the country.
If it's not in there yet, I can see if I can make a pull request one of the coming days if you like.

Get EU VAT number details doesn´t work

Hello,
I´m trying to replicate this example with real VAT number: https://github.com/mpociot/vat-calculator#get-eu-vat-number-details

But I get the following response:

object(stdClass)#1133 (6) {
  ["countryCode"]=>
  string(2) "ES"
  ["vatNumber"]=>
  string(9) "B75149773"
  ["requestDate"]=>
  string(16) "2020-01-22+01:00"
  ["valid"]=>
  bool(true)
  ["name"]=>
  string(3) "---"
  ["address"]=>
  string(3) "---"
}

The name and address is not defined as I can´t give them as input for the validation.

Example of updating data-amount with JS

I am trying to make use of VATCalculator.calculate() to update the preview cost on the DOM when the plan select price changes.

As a test I have set a button on click to update the form data-amount value then run the VATCalculator.calculate() function but nothing appears to happen. I've also tried passing a value. Is there something I'm missing here? Thanks!

    jQuery('.test').on('click', function(){
      planPrice = '10000';
      $('#payment-form').data('amount', planPrice);
        VATCalculator.calculate(function(planPrice){
            console.log(planPrice);
        });
    });
    jQuery('.test').on('click', function(){
      VATCalculator.calculate('10000', 'US');
    });

Best Way To Add Custom Exception Handling

We use this wonderful package with the built-in API routes via ajax from vue. We just call get on the route /vatcalculator/calculate which works fine most of the time, but sometimes - as often discussed - there are availability issues with the VIES service so that this request fails.
I saw I can activate exception forwarding in the config, but then the whole thing just blows up and I don't know where to handle the exception.
I would like to handle this stuff in the backend, preferably without implemeting my own controller, routes, etc.
So is there a neat way to integrate custom fallback logic without having to reinvent the wheel?

VAT Number not UE

This is a question not a issue, what will be the behavior of vat validation if we try to validate a vat number that is not UE?

Tks

Method [validateVatNumber] does not exist.

Hello,

I just installed the package, added the service provider and alias to the app.php config file.

I would like to validate an input with the vat_number validation rule. For this I added 'required|vat_number' in the rules for that field.

However with this I'm getting the following error:

Method [validateVatNumber] does not exist.

When checking the VatCalculatorServiceProvider class, the registerValidatorExtension method get's called, however the VatCalculatorValidatorExtension@validateVatNumber does not.

I'm using laravel 5.1.32, with package version 1.6.3.

Did I miss something ?

Thank you,

Edit:

I've found that when I comment the following:

private function registerMaxFolderSizeValidator()
    {
        Validator::resolver(function ($translator, $data, $rules, $messages, $attributes) {
            return new MaxFolderSizeValidator($translator, $data, $rules, $messages, $attributes);
        });
    }

here: https://github.com/AsgardCms/Media/blob/master/Providers/MediaServiceProvider.php#L80

The Vat Validation rules works. Somehow laravel doesn't like multiple resolvers ?

Calculator will always return 0 for tax rate on a country with post code exceptions

If you supply a country code and post code for a country that has post code exceptions listed, but the postcode doesn't match any of the exceptions, the VAT is zero rated by this code. This means if you supply a postal code, the countries of AT, CH, DE, ES, GB, GR, IT and PT all get 0 tax applied.

To reproduce, visit this URL on a site with the VAT calculator installed, which should, due to the random post code, return the standard VAT rate, but instead returns 0:
vatcalculator/calculate?netPrice=20&country=ES&postal_code=dso8576yj89f5

Or this valid UK post code, which also gets zero rated:
vatcalculator/calculate?netPrice=20&country=GB&postal_code=S1A%202AA

When each iteration of the foreach loop doesn't match the postcode to an exception, it continues to the next, until when the loop eventually breaks it hits the return 0;

Presumably instead of return 0, the condition should just be inverted so that lines 547 to 563 are replaced with this:

        if (isset($this->postalCodeExceptions[$countryCode]) && $postalCode !== null) {
            foreach ($this->postalCodeExceptions[$countryCode] as $postalCodeException) {
                if (!preg_match($postalCodeException['postalCode'], $postalCode)) {
                    continue;
                }
                if (isset($postalCodeException['name'])) {
                    return $this->taxRules[$postalCodeException['code']]['exceptions'][$postalCodeException['name']];
                }

                return $this->taxRules[$postalCodeException['code']]['rate'];
            }
        }

        return isset($this->taxRules[strtoupper($countryCode)]['rate']) ? $this->taxRules[strtoupper($countryCode)]['rate'] : 0;

Support for Spark Teams?

Trying to get this to play nicely with Laravel Spark Teams - have modified the Team Model as follows:

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Mpociot\VatCalculator\Traits\BillableWithinTheEU;

class Team extends Model
{
    use Notifiable, Billable, BillableWithinTheEU {
        BillableWithinTheEU::getTaxPercent insteadof Billable;
    }

But get the following error:

(1/1) FatalErrorExceptionTrait method taxPercentage has not been applied, because there are collisions with other trait methods on Laravel\Spark\Team

Its been a long day so I'm probably missing something obvious, but do you have any ideas?

Set default value for individuals outside of the EU

We're based in the UK and are required to add VAT to all purchases from us if the buyer is an individual (businesses don't get taxed).

Is it possible set a rule for this? i.e. if the user is outside any of the countries listed and is an individual set VAT rate to XX otherwise set to XX

VAT validation fails silently

I know there are similar issues reported (one closed, one open about SOAP failure), but this one looks different. I'm checking a valid German VAT ID. I confirmed with VIES site by entering this random but valid German VAT ID 160475096 that their service is currently down.

The call to:

(new VatCalculator)->isValidVATNumber($value)

returns false instead of throwing an Exception.

IP6 adresses not working for VatCalculator::getIPBasedCountry()

Seems the IP2C service does not handle IPv6 adresses.

Ran into this issue while testing my web-app from my mobile phone in Norway.

file_get_contents(http://ip2c.org/2a02:2121:301:e44e:0:47:4cb1:7301): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found
....
 at /....../vendor/mpociot/vat-calculator/src/Mpociot/VatCalculator/VatCalculator.php:427)
[stacktrace]
>#0 [internal function]: Illuminate\\Foundation\\Bootstrap\\HandleExceptions->handleError(2, 'file_get_conten...', '/var/www/0/1638...', 427, Array)
>#2 /...../vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(237): Mpociot\\VatCalculator\\VatCalculator->getIPBasedCountry()

Incorrect handling of Norway?

Hi,

Thanks for your great vat-calculator, we use it as part of spark.laravel.com. And now run into an issue with a customer from Norway (outside EU) and we are in The Netherlands (within EU). The customer is being charged VAT but says that he shouldn't. And as far as I can see he's correct, regardless if he's a business or individual.
Does this need to be changed in the code?

Thanks in advance!

Laravel 6 compatability - Carbon v2

Laravel 6 is deprecating Carbon v1:

Carbon 1.x is no longer supported since it is nearing its maintenance end of life. Please upgrade your application to Carbon 2.0.

This package currently uses Carbon 1.2. Are there any plans to take this to Carbon 2.x?

Vat service check URL should be used over SSL

Hi Team,

First of all, I would say thanks to the team for making this package and we started to use it in our development to calculate the VAT with laravel application.
vat_service_url

Our team observed that to verify VAT number, you used URL set with this constant(VAT_SERVICE_URL) without SSL(https) which you should think to replace to use with SSL (with https).

We would suggest you add this improvement as earlier as possible.

Thanks,
Arun Yadav

VAT in Sweden

There are three vat rates in Sweden.
12 food
6 books
25 everything else

Timeout option

Hello,

Yesterday the VIES service was down and I had my website blocked on loading when I was using the class VatCalculator. It appear that the SoapClient was in kind of timeout as the VIES service was down.

Any luck to add a timeout param?

Decimal separator

Allow the specify if the decimal separator should be a coma or a point in js script.

Add Switzerland to the VAT Calculator

Hey there,

first, thank you for this wonderful package. It's really helpful especially combined with Laravel Spark.

I was wondering if it you could add the Swiss VAT to your package ? Switzerland's not in the EU and has a VAT that differs from EU's percentage. It is a 7.7 % tax (source : The Swiss authorities ).

It would really help me finish my app (many of my users will be in Switzerland). Using the config.php does not seem to be changing much (maybe I'm using it wrong ?) :

    'rules' => [
        // 'XX' => 0.17,
	    'CH' => 0.077
    ],

Thank you in advance for your help.

EDIT : I see this has already been discussed (#29), however I believe this package could also add Switzerland, especially since Norway has been added. Since Norway's not in the EU, I believe Switzerland should be in there too.

I believe there is a problem with Business Country Code set to UK

--- update: I just figured out that I should use GB instead of UK, so there is no BUG. You can delete my bug report. ----

Hello,
I believe there is a bug in the way the vat calculator handle the VAT in UK.

if I set the BusinessCountryCode to UK and try to calculate the tax/gross price for an individual in UK I get TAX 0 which is wrong as all the business in UK should charge the 19% to all the invoices to individuals.
$vatCalculator = new Mpociot\VatCalculator\VatCalculator();
$vatCalculator->setBusinessCountryCode('UK');
//$countryCode = $vatCalculator->getIPBasedCountry();
$grossPrice = $vatCalculator->calculate( 10, 'UK' );
$taxRate = $vatCalculator->getTaxRate();

The result is that taxRate is 0.

I am doing something wrong or there is a real bug?

Thank you,

Flaviu

Uniform `VAT` case

Hey 👋
A small not for the next major version:

Currently, there are two ways of writing VAT in the code. The all-uppercase and the capitalized version Vat.

(From the README)

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

In my opinion it'd be great to agree on a uniform way of writing the abbreviation ☺️

VAT number can't be optional in Laravel 5.4

Hello

I just upgraded a project to Laravel 5.4 and it seems the VAT number field is now always required even if it's empty and no required validation rule is set. I don't think this was the case before?

As a quick work around, I copied your validation rule and added a check if the value is empty:

Validator::extend('vat', function($attribute, $value, $parameters, $validator) use ($cooldown) {
    if ( ! $value) {
        return true;
    }

    $validator->setCustomMessages([
        'vat_number' => $validator->getTranslator()->get('vatnumber-validator::validation.vat_number'),
    ]);

    try {
        return VatCalculator::isValidVATNumber($value);
    } catch (VATCheckUnavailableException $e) {
        return false;
    }
});

If I want it to be required, I can now add the required rule manually.

For Turkey returning invalid VAT number

Thank you so much for the library, it was very helpful.

I'm facing issue with Turkey country, can you please look in to this?
I have provided valid VAT only, but it's returning Invalid VAT.

But as Turkey belongs to EU, it should validate right ?
please let me know if I'm wrong.

Thanks in advance!

Change of German VAT rate

In commit b65422b the German VAT rate has been changed from 0.19 to 0.16 which exposes a huge problem the library has at the moment. When using this library for batch invoice creation you'll end up with wrong tax calculations, if you want to create invoices for June in July. The library lacks the possibility to take the invoice date into account when calculating the VAT accordingly.

Laravel 5.2 Support

Hello,

This is a question not a issue, very nice work here 👍 💯

Does this package have support for laravel 5.2?

Tks m:8ball:

Problem with Laravel and VatCalculator autoloading

Hi,

there is an issue with the way that VatCalculatorServiceProvider binds the VatCalculator dependency in Laravel.

This is the registerVatCalculator method:

    /**
     * Register the application bindings.
     *
     * @return void
     */
    protected function registerVatCalculator()
    {
        $this->app->bind('vatcalculator', '\Mpociot\VatCalculator\VatCalculator');

        $this->app->bind('\Mpociot\VatCalculator\VatCalculator', function ($app) {
            $config = $app->make('Illuminate\Contracts\Config\Repository');

            return new \Mpociot\VatCalculator\VatCalculator($config);
        });
    }

Instead of using the special PHP VatCalculator::class constant which resolves to 'Mpociot\VatCalculator\VatCalculator'
the method is using:
'\Mpociot\VatCalculator\VatCalculator'
(note the leading slash)

In my vat_calculator.php config file I have the following config:
'business_country_code' => 'ES',

Which gets applied when creating a new instance of VatCalculator only if VatCalculator is loaded using the Laravel IoC Container.

The problem is that if anywhere in my code I declare VatCalculator as a dependency, Laravel (5.5 at least) doesn't use the binding provided by VatCalculatorServiceProvider, and creates the class with a $config = null.

In php artisan tinker:

>>> app('Mpociot\VatCalculator\VatCalculator')->getTaxRateForLocation('ES', null, true);
=> 0
>>> app('\Mpociot\VatCalculator\VatCalculator')->getTaxRateForLocation('ES', null, true);
=> 0.21

The solution would be to use the name without the leading slash in the registerVatCalculator method of the VatCalculatorServiceProvider (The best would be to use the ::class constant).

I could send you a PR if you are willing to accept it :)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.