gwharton / autocustomergroup

Magento 2 Module - Auto Assign Customer Group based on Tax Scheme validation
Other
17 stars 4 forks source link

AutoCustomerGroup

Magento 2 Module - Auto Assign Customer Group based on Tax Scheme validation

Features

Overview

Changes introduced to both the UK and EU VAT Tax systems require changes to be made to the Magento Tax system. These changes are required URGENTLY, and while Magento consider the changes required and work towards a permanent solution, this module can be used as an interim measure.

The module should be considered BETA. I encourage users to analyse the code, suggest improvements, generate PR's where applicable.

Once customers have been placed in an appropriate group, tax rules can be configured to apply different taxes to each group, depending on what is required.

When enabled, this module replaces the existing Magento VIV functionality with a new, more extendable system. When the module is disabled, the existing Magento functionality is restored.

The module allows different base currencies to be used per website, if the price scope is set per website.

General

Frontend Validation Feedback

When enabled, this module replaces the frontend Form Element for the VAT/Tax ID Input box. If the currently selected Country has a Tax Scheme associated with it, and the Tax Scheme enabled, and a valid format VAT/Tax Id is input on the frontend, then the Id is validated by the relevant Tax Scheme and the results displayed to the customer. As soon as a country is selected that has a valid Tax Scheme associated with it, the customer is presented with a prompt above the input field, notifying what they need to enter.

Valid Irish VAT Number

Correct format but not valid

Wrong Format

Valid UK VAT Numnber

UK VAT Scheme

EU OSS/IOSS Scheme

Norway VOEC Scheme

Australia GST for Non Residents Scheme

New Zealand GST Scheme

Tax Rule to Tax Scheme Links

The module allows you to link each tax rule to a particular tax scheme. In post order functions, this allows you to query this module using order details, and obtain the list of tax rules that were applicable to the order, and return the TAX Scheme Registration Numbers linked to these rules. This is useful when generating invoices for example.

The links can be set under the existing Tax Rules Screens

Sales Order Grid

The module introduces a new Sales Order Grid column that will display details of the Tax Scheme used for the order.

Getting Information on Tax Schemes used on Order

This module stores additional information into the sales_order_tax_scheme table whenever an order is placed that triggered a tax rule linked to a Tax Scheme.

This information can be easily accessed so that information on which tax schemes were used on an order, can be included on the Invoice PDF's for example.

The following code shows how this can be achieved.



    use Gw\AutoCustomerGroup\Model\ResourceModel\OrderTaxScheme\CollectionFactory;

    /**
     * @var CollectionFactory
     */
    private $orderTaxSchemeCollectionFactory;

    ...
    ...
    ...

    $orderTaxSchemes = $this->orderTaxSchemeCollectionFactory->create()->loadByOrder($order);
    foreach ($orderTaxSchemes as $orderTaxScheme) {
        $storeCurrency = $this->currencyFactory->create()->load($orderTaxScheme->getStoreCurrency());
        $schemeCurrency = $this->currencyFactory->create()->load($orderTaxScheme->getSchemeCurrency());
        $baseCurrency = $this->currencyFactory->create()->load($orderTaxScheme->getBaseCurrency());

        output("TAX Summary - " . $orderTaxScheme->getName());
        output("Registration Number - " . $orderTaxScheme->getReference());
    }

Integration Tests

To run the integration tests, you need your own credentials for the Australian ID Checker services. Please add them to config-global.php. The tests for UK (Sandbox), EU and Australia use the live API's