Skip to main content
Services · Revision #2

What is the tax accountant service?

What is the tax accountant service?

The Tax Account is the service responsible for determining the tax multiplier that should be applied to a product price.

It uses the store's tax configuration together with the current customer's tax information and location to determine which tax rules and rates apply. The service can then use those multipliers to convert prices between tax-exclusive and tax-inclusive values.

Converting prices

Ex => Inc

The priceInc method can be used to convert an ex price to an inc price, we use it when handling prices for products:

app('aero.accountant')->priceInc($value, $this->product_tax_group_id);

Inc => Ex

The priceEx method can be used to convert an inc price to an ex price, we use it when handling prices for products:

app('aero.accountant')->priceEx($value, $this->product_tax_group_id);

Resolvers

Tax Group Resolver

The Tax Account uses a tax group resolver to resolve a customer's tax group id.

A resolver is set by the Aero\Store\Http\Middleware\SetTaxResolver middleware:

$this->accountant->setTaxGroupResolver(static function (?\Aero\Account\Models\Customer $customer) {
    if ($customer && ($group = $customer->getAttribute('customer_tax_group_id'))) {
        return $group;
    }

    if ($customer && $customer->customer_group_id && ($group = $customer->group->getAttribute('customer_tax_group_id'))) {
        return $group;
    }

    return null;
});

If no customer tax group id is resolved, the store's default will be used.

Country Resolver

The Tax Account uses a country resolver to resolve the country it should use.

A resolver is set by the Aero\Store\Http\Middleware\SetTaxResolver middleware:

$this->accountant->setCountryResolver(static function (?\Aero\Account\Models\Customer $customer) {
    if ($cartLocale = \Aero\Cart\Facades\Cart::instance(PaymentDriver::MOTO)->locale()) {
        return $cartLocale->countryCode;
    }
    
    return null;
});

If no country code is resolved, the store's default will be used.

Zone Resolver

The Tax Account uses a country resolver to resolve the country it should use.

A resolver is set by the Aero\Store\Http\Middleware\SetTaxResolver middleware:

$this->accountant->setZoneResolver(static function (?\Aero\Account\Models\Customer $customer) {
    if ($cartLocale = \Aero\Cart\Facades\Cart::instance(PaymentDriver::MOTO)->locale()) {
        return $cartLocale->zoneId;
    }
    
    return null;
});

If no zone id is resolved, then no zone id will be used.

Postcode Resolver

The Tax Account uses a country resolver to resolve the country it should use.

A resolver is set by the Aero\Store\Http\Middleware\SetTaxResolver middleware:

$this->accountant->setPostcodeResolver(static function (?\Aero\Account\Models\Customer $customer) {
    if ($cartLocale = \Aero\Cart\Facades\Cart::instance(PaymentDriver::MOTO)->locale()) {
        return $cartLocale->postcode;
    }
    
    return null;
});

If no postcode is resolved, then no postcode will be used.