Giter Club home page Giter Club logo

vat-calculator's Introduction

Hi there 👋

I'm Dries, open-source maintainer and one of the core team members of Laravel where I maintain the first-party libraries. I also do the weekly releases of all the first-party packages.

In my free time I've built and maintain various open-source projects of my own like:

  • Lemon Squeezy for Laravel - A package to easily integrate your Laravel application with Lemon Squeezy
  • Blade UI Kit - A set of renderless components to utilise in your Laravel Blade views
  • Blade Icons - Easily use SVG icons in your Laravel Blade views
  • Dotfiles - Start using dotfiles on your Mac
  • Laravel.io - The Laravel community portal
  • VatCalculator - Handle all the hard stuff related to EU MOSS tax/vat regulations

Working on open-source is my great joy in life and I want to be able to do that as much and as long as I possible can. I hope you like what I work on and that some of it is useful to you. Thanks for visiting!

If you found anything that I built useful for you or your company, consider sponsoring me ❤️

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

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!

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.

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.

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

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?

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.

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 ?

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 :)

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()

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.

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

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?

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 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

Decimal separator

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

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?

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.

VAT in Sweden

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

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%?

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?

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!

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

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;

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

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 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.

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

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?

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?

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:

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.

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

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.

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

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!

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.