Skip to content

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

License

Notifications You must be signed in to change notification settings

gwharton/autocustomergroup

Repository files navigation

AutoCustomerGroup

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

Features

  • Operates on UK, EU, Norway VOEC, AU GST and NZ GST Schemes
  • Validation of Customers Tax ID on frontend during checkout, including feedback of validation status to customer.
  • Automatically change customer group during frontend orders based on order contents, Tax ID and Country.
  • Admin Create Customer - Tax ID's are validated and saved with the order address, but group change functionality disabled (only available while placing orders).
  • Admin Create Order - Tax ID's are validated using the "validate" link during order creation, and customer is assigned new group if applicable.
  • Option to add scheme currencies to Base Currency list for automatic exchange rate download, or able to use hard coded exchange rates.
  • Module can be disabled, where legacy Magento functionality is restored. Module can be enabled/disabled on a per store basis with legacy functionality on one store, and new functionality on another store.
  • Extends Tax Rate functionality to allow linking of Tax Rates to Tax Schemes
  • Includes Code to allow retieval of Order Tax Rates and linked Tax Schemes, for example when producing Invoice PDF's so the Tax Scheme details can be added to the PDF depending on which rates were used on the order. (example code below)
  • Records details of Tax Scheme used on orders to new table sales_order_tax_scheme.
  • Sales Order Grid column to show Tax Scheme Details for order.

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

  • Enable Automatic Assignment to Customer Group - This activates and deactivates the module. When turned off, orders will be processed using the existing Magento settings ane the existing VAT control is used on the frontend.
  • Validate on Each Transaction - If the order is being placed by a customer that has existing Tax ID Validation data stored in their shipping address, then this can be re-used on each subsequent order, or it can be revalidated every time.
  • VAT/Tax Identifier Frontend Label - The label for the VAT/Tax Id Input Box at Checkout.
  • Enable download of Additional Base Currencies - Adds the Scheme Currencies (for enabled Schemes) to the list of Magento Base Currencies. This enables the downloading of the correct exchange rates for use in this module. This can be verified in Stores -> Currency Rates.
  • Enable recording of Tax Scheme details to sales_order_tax_scheme table - When an order is placed, and a tax rule is triggered that is linked to a tax scheme, then the tax scheme information is recorded in table sales_order_tax_scheme in the database.
  • Default Customer Group for Guest Orders - Which Customer Group to assign guest orders to.

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

  • Enabled - Enable/Disable this Scheme.
  • Tax Identifier Field - Displayed to the customer during checkout when this scheme is being used.
  • Environment - Whether to use the Sandbox or Production servers for the HMRC VAT Validation Service.
  • VAT Registration Number - The UK VAT Registration Number for the Merchant. This will be provided to HMRC when all validation checks are made.
  • Import VAT Threshold - If the order value is above the VAT Threshold, no VAT should be charged.
  • Use Magento Exchange Rate - To convert from GBP Threshold to Store Currency Threshold, should we use the Magento Exchange Rate, or our own.
  • Exchange Rate - The exchange rate to use to convert from GBP Threshold to Store Currency Threshold.
  • Customer Group - Domestic - Merchant Country is within the UK/IM, Item is being shipped to the UK/IM.
  • Customer Group - Intra-EU B2B - Merchant Country is within the EU, Item is being shipped to NI, Validated UK VAT Number Supplied.
  • Customer Group - Intra-EU B2C - Merchant Country is within the EU, Item is being shipped to NI, Validated UK VAT Number is NOT Supplied.
  • Customer Group - Import B2B - Merchant Country is not within the UK/IM, Item is being shipped to the UK/IM, Validated EU VAT Number Supplied.
  • Customer Group - Import Taxed - Merchant Country is not within the UK/IM, Item is being shipped to the UKIM, Order Value is below or equal to Import VAT Threshold.
  • Customer Group - Import Untaxed - Merchant Country is not within the UK/Isle of Man, Item is being shipped to the UK/Isle of Man, Order Value is above the Import VAT Threshold.

EU OSS/IOSS Scheme

  • Enabled - Enable/Disable this Scheme.
  • Tax Identifier Field - Displayed to the customer during checkout when this scheme is being used.
  • VIES Registration Country - Optional. Must be valid EU country, if completed, it will be passed to the VIES with the validation request and a unique verification code will be returned and stored with the order as proof of validation.
  • VIES Registration Number - Optional. Must be valid EU VAT number, if completed, it will be passed to the VIES with the validation request and a unique verification code will be returned and stored with the order as proof of validation.
  • VAT Registration Number - The Scheme Registration Number for the Merchant.
  • Environment - Whether to use the Sandbox or Production servers for the VIES VAT Validation Service.
  • Import VAT Threshold - If the order value is above the VAT Threshold, no VAT should be charged.
  • Use Magento Exchange Rate - To convert from EUR Threshold to Store Currency Threshold, should we use the Magento Exchange Rate, or our own.
  • Exchange Rate - The exchange rate to use to convert from EUR Threshold to Store Currency Threshold.
  • Customer Group - Domestic - Merchant Country is within the EU, Item is being shipped to the same country.
  • Customer Group - Intra-EU B2B - Merchant Country is within the EU or NI, Item is being shipped to the EU, Merchant Country and Shipping Country are not the same, Validated EU VAT Number Supplied.
  • Customer Group - Intra-EU B2C - Merchant Country is within the EU or NI, Item is being shipped to the EU, Merchant Country and Shipping Country are not the same, Validated EU VAT Number is NOT Supplied.
  • Customer Group - Import B2B - Merchant Country is not within the EU, Item is being shipped to the EU, Validated EU VAT Number Supplied.
  • Customer Group - Import Taxed - Merchant Country is not within the EU, Item is being shipped to the EU, Order Value is below or equal to the Import VAT Threshold.
  • Customer Group - Import Untaxed - Merchant Country is not within the EU, Item is being shipped to the EU, Order Value is above the Import VAT Threshold.

Norway VOEC Scheme

  • Enabled - Enable/Disable this Scheme.
  • Tax Identifier Field - Displayed to the customer during checkout when this scheme is being used.
  • VOEC Registration Number - The Norway VOEC Registration Number for the Merchant. This is not currently used by the module.
  • Import VAT Threshold - If any single item within the order is valued above the VAT threshold then no VAT should be charged.
  • Use Magento Exchange Rate - To convert from NOK Threshold to Store Currency Threshold, should we use the Magento Exchange Rate, or our own.
  • Exchange Rate - The exchange rate to use to convert from NOK Threshold to Store Currency Threshold.
  • Customer Group - Domestic - Merchant Country is within Norway, Item is being shipped to Norway.
  • Customer Group - Import B2B - Merchant Country is not within Norway, Item is being shipped to Norway, Norwegian Business Number Supplied.
  • Customer Group - Import Taxed - Merchant Country is not within Norway, Item is being shipped to Norway, All items valued at or below the Import VAT Threshold.
  • Customer Group - Import Untaxed - Merchant Country is not within Norway, Item is being shipped to Norway, One or more items in the order is valued above the Import VAT Threshold.

Australia GST for Non Residents Scheme

  • Enabled - Enable/Disable this Scheme.
  • Tax Identifier Field - Displayed to the customer during checkout when this scheme is being used.
  • ABN API GUID - The GUID provided by the Australian Business Register website for API access.
  • ATO Registration Number - The ATO Registration Number for the Merchant. This is not currently used by the module.
  • Import GST Threshold - If the order value is above the GST Threshold, no GST should be charged.
  • Use Magento Exchange Rate - To convert from AUD Threshold to Store Currency Threshold, should we use the Magento Exchange Rate, or our own.
  • Exchange Rate - The exchange rate to use to convert from AUD Threshold to Store Currency Threshold.
  • Customer Group - Domestic - Merchant Country is within Australia, Item is being shipped to Australia.
  • Customer Group - Import B2B - Merchant Country is not within Australia, Item is being shipped to Australia, GST Validated ABN Number Supplied.
  • Customer Group - Import Taxed - Merchant Country is not within Australia, Item is being shipped to Australia, Order Value is below or equal to the Import GST Threshold.
  • Customer Group - Import Untaxed - Merchant Country is not within Australia, Item is being shipped to Australia, Order Value is above the Import GST Threshold.

New Zealand GST Scheme

  • Enabled - Enable/Disable this Scheme.
  • Tax Identifier Field - Displayed to the customer during checkout when this scheme is being used.
  • Validate Online - Whether the customers NZBN number should be validated online for GST registration. (Please note, not all Businesses have their GST registration status recorded on the NZBN checking website so this setting should be used with caution. This may change in the future if recording of registration status becomes mandatory.)
  • Environment - Whether to use the Sandbox or Production servers for the NZBN Validation Service.
  • API Access Token - The API Access Token provided by the NZBN Business Register website for API access.
  • GST Registration Number - The GST Registration Number for the Merchant. This is not currently used by the module.
  • Import GST Threshold - If the order value is above the GST Threshold, no GST should be charged.
  • Use Magento Exchange Rate - To convert from NZD Threshold to Store Currency Threshold, should we use the Magento Exchange Rate, or our own.
  • Exchange Rate - The exchange rate to use to convert from NZD Threshold to Store Currency Threshold.
  • Customer Group - Domestic - Merchant Country is within New Zealand, Item is being shipped to New Zealand.
  • Customer Group - Import B2B - Merchant Country is not within New Zealand, Item is being shipped to New Zealand, GST Number Supplied.
  • Customer Group - Import Taxed - Merchant Country is not within New Zealand, Item is being shipped to New Zealand, All items valued at or below the Import GST Threshold.
  • Customer Group - Import Untaxed - Merchant Country is not within New Zealand, Item is being shipped to New Zealand, One or more items in the order is valued above the Import GST Threshold.

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

  • autocustomergroup/australiagst/apiguid
  • autocustomergroup/newzealandgst/accesstoken

About

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

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages