spaze / vat-calculator

[EOL, use driesvints/vat-calculator] Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be. Fork of mpociot/vat-calculator, standalone, PHP 7.3+, modernized, with more features.
MIT License
48 stars 2 forks source link

20% fixed tax #24

Closed officialmmt closed 3 years ago

officialmmt commented 3 years ago

Hi Michal,

First of all, I would like to thank you. I have been using the package you wrote for two months and I am very satisfied.

I had a need. How can I convert to a fixed 20% tax rate for Europe only in the package?

Thanks in advance for your answer

spaze commented 3 years ago

Hi, thanks! :-) Why do you need a fixed tax, what is the case for fixed VAT?

officialmmt commented 3 years ago

As you know, there are annual sales volume limits for Moss (starting from 10000 €). Those who do not reach this limit must apply the tax amount of their own country without applying Moss tax scheme. In this case, it will be a need for me and such companies.

spaze commented 3 years ago

Can you solve the problem by not setting $businessCountryCode in VatCalculator constructor or by passing $company = false when calling calculate()? That might help, if I understand the issue correctly.

officialmmt commented 3 years ago

If I do this 20% tax will be applied to the European Union. 0% to others right?

spaze commented 3 years ago

shouldCollectEuVat would return false for non-EU countries, so you don't even try to calculate VAT as this package only works with EU VAT (and a few exceptions, if configured manually)

officialmmt commented 3 years ago

I have previously made the company variable false.

$vatRates = new VatRates();
$vatRate = new VatCalculator($vatRates);
$rates = $vatRate->getTaxRateForLocation($code, null, false);
$oredertaxed = $vatRate->calculate(Cart::subtotal(), $code, null, false);
spaze commented 3 years ago

If I understand it correctly, you want VatRates::getTaxRateForLocation() to always return 20%, no matter what $countryCode etc is passed? Probably the easiest way would be to use a custom VatRates object with a method getTaxRateForLocation that would always return what you need and then pass the object to new VatCalculator(...).

I could add VatRatesInterface so yo don't need to extend anything. Would that be fine with you?

spaze commented 3 years ago

Thinking about it, it seems the best way is to extend VatRates and override the method, something like

class FixedVatRate
{
    public function getTaxRateForLocation(string $countryCode, ?string $postalCode, ?string $type = self::GENERAL, ?DateTimeInterface $date = null): float
    {
        return 0.2;
        }
}

$vatRates = new FixedVatRate();
$vatRate = new VatCalculator($vatRates);

Does it help?

officialmmt commented 3 years ago

I did try like this and always return 0.2 vat rate for Eu and non-Eu countries. If non-EU countries can get 0% vat rate we will reach the goal.

use DateTimeInterface;
use Spaze\VatCalculator\VatRates;

class FixedVatRate extends VatRates
{
    public function getTaxRateForLocation(string $countryCode, ?string $postalCode, ?string $type = self::GENERAL, ?DateTimeInterface $date = null): float
    {
        return 0.2;
    }
}
spaze commented 3 years ago

Sure, you can return whatever you want, check the VatRates class, you probably have all you need there :-) shouldCollectEuVat would help.

officialmmt commented 3 years ago

shouldCollectEuVat return boolean so I should handle with if.

spaze commented 3 years ago

Indeed. Glad you've found the solution 👍