driesvints / vat-calculator

Handle all the hard stuff related to EU MOSS tax/vat regulations, the way it should be.
MIT License
1.2k stars 88 forks source link

Custom rules seem to be ignored #153

Closed ghost closed 1 year ago

ghost commented 1 year ago

I am probably doing something wrong, but I am switching back to this repo from @spaze his fork and added back some countries to config/vat_calculator.php like so:

<?php

return [

    /*
    |--------------------------------------------------------------------------
    | VAT rules
    |--------------------------------------------------------------------------
    |
    | If you need to apply custom VAT rules for a specific country code,
    | use this array to define the rules that fit your needs. All EU
    | VAT rules are preconfigured inside but can be overwritten
    | at this point
    |
    */

    'rules' => [
            'GB' => [ // United Kingdom
                'rate' => 0.20,
                'exceptions' => [
                    // UK RAF Bases in Cyprus are taxed at Cyprus rate
                    'Akrotiri' => 0.19,
                    'Dhekelia' => 0.19,
                ],
            ],
            'TR' => [ // Turkey
                'rate' => 0.18,
            ],
            'NO' => [ // Norway
                'rate' => 0.25
            ],
    ],

But neither of these countries seem to be recognized and I get a VAT rate of 0% returned. I did run artisan config:cache

Artisan Tinker:

> $vat = new VatCalculator();
= Mpociot\VatCalculator\VatCalculator {#5936}

> $vat->getTaxRateForLocation('DE');
= 0.19

> $vat->getTaxRateForLocation('NO');
= 0

> config('vat_calculator');
= [
    "rules" => [
      "GB" => [
        "rate" => 0.2,
        "exceptions" => [
          "Akrotiri" => 0.19,
          "Dhekelia" => 0.19,
        ],
      ],
      "TR" => [
        "rate" => 0.18,
      ],
      "NO" => [
        "rate" => 0.25,
      ],
    ],
    "business_country_code" => "FR",
    "forward_soap_faults" => false,
    "soap_timeout" => 30,
  ]

Looks like it misses the added data from the config file here and only uses the rules from the VatCalculator.php itself: https://github.com/driesvints/vat-calculator/blob/3.x/src/VatCalculator.php#L785

driesvints commented 1 year ago

Heya. The line you link to points to a docblock. Make sure to press "Y" before copying a line in github to always get the exact commit line you're pointing to.

ghost commented 1 year ago

Ah, here it is: https://github.com/driesvints/vat-calculator/blob/3b31ecd22b0685321909f32287889bc747a25930/src/VatCalculator.php#L780

Seems it only looks for rules within the $this->taxRules variable in that file and never checks the extra rules in the config.

ghost commented 1 year ago

Any way you could look into this @driesvints? I'd love to push my changes live soon :-)

driesvints commented 1 year ago

Heya, I don't have time right now, sorry. I'll get to this once I find some.

ghost commented 1 year ago

Lol jesus I am an idiot and was using use Mpociot\VatCalculator\VatCalculator; which VS Code imported for me.

Instead I need to use the Facade use Mpociot\VatCalculator\Facades\VatCalculator