TariffBillingFieldsTrait uses trait:short
Billing axes of a tariff, shared by all four admin tariff forms (bazaar, comcat, discussion, membership).
A tariff carries a supply kind (supplyKindId, select from SupplyKindFieldsTrait).
It replaced the product type and the flat tariff VAT rate (%). Their columns
(product_type_id, vat_percents) remain and are still read by PriceTrait (rate chain)
and the PDF variant matrix: the form neither displays nor writes them, the edited entity is
loaded from the Api with all columns, and saving leaves their values unchanged. A new
tariff gets vat_percents null (meaning "default from settings") and product_type_id
derived from the supply nature (tariffLegacyProductTypeId()).
The per-region VAT rate in the price list (regionVat_{rid} to TariffPrice::vatPercents)
stays; PriceTrait charges it. The helper field "price with VAT" is computed from the
supply kind rate in the region country instead.
Table of Contents
Constants
- FALLBACK_VAT_PERCENTS : mixed = 21
- Fallback rate when `7/invoice.default.vatPercents` is missing or not a number.
- LEGACY_PRODUCT_TYPE_GOODS : mixed = 1
- `cms_mod_invoicer_product_types`: 1 goods, 2 service; only for the legacy PDF axis.
- LEGACY_PRODUCT_TYPE_SERVICE : mixed = 2
- REGION_VAT_OPTIONS : array<int, string> = ['0', '2.1', '5', '5.5', '6', '7', '8', '9', '1...
- VAT rates offered in the region select: common EU bands including decimals (2.1, 5.5, 13.5 %; 0 means exempt or non-payer). The rate belongs to a concrete tariff and region combination (another service means another rate even in the same region), so it is stored on the price list row (`TariffPrice::vatPercents`), not on the shared payment region entity.
- SETTING_MODULE_INVOICER : mixed = 7
- Module "invoicer" in the settings table (`cms_system_settings.module`).
- SUPPLY_KIND_SETTING_MODULE_INVOICER : mixed = 7
- Module "invoicer" in the settings table (`cms_system_settings.module`); holds the portal `sellerId`.
Properties
- $supplyKindFieldsManager : SupplyKindManager
- $supplyKindFieldsSellerManager : SellerManager
- $supplyKindFieldsVatRateManager : VatRateManager
Methods
- addSupplyKindSelect() : SelectBox
- Adds the supply kind select. The options are database names, so the select translator is off and the prompt is translated here. IMPORTANT: the label must stay a translation key (`BaseControl::getLabel()` takes the translator from the form); a translated label would be translated twice.
- addTariffBillingFields() : void
- Adds the required supply kind of a tariff. `data-price-vat-source` is the live rate source of the helper field "price with VAT" in the price list (`product-price-vat.js` reads the region `data-price-vat-map`).
- buildSupplyKindRegionVatMaps() : array<int, array<int, string>>
- Returns the rate map for the helper field "price with VAT": `regionId => supplyKindId => percent` (valid today).
-
buildSupplyKindVatMapAttributes()
: array<int, array{json: string, map: array
}> - Returns the same as {@see buildSupplyKindRegionVatMaps()} plus JSON for the `data-price-vat-map` attribute of the region matrix (keys as strings, because JS reads `map[select.value]`).
- getSupplyKindOptions() : array<int, string>
- Returns active supply kinds as `id => name` in the admin language.
- supplyKindIdValue() : int|null
- Converts the supply kind select value to an id, or null for the empty prompt.
- buildRegionVatOptions() : array<string, string>
- Builds the options of the region VAT rate select: key is `VatRate::key()` ('21', '5.5'), label "5,5 %". A rate already stored on price list rows that is missing from the offer (e.g. 4.75) is added, otherwise saving would erase it.
- getTariffVatFallback() : string
- Returns the default VAT rate from setting `7/invoice.default.vatPercents` (stored as text) in the `VatRate::key()` form ('21', '5.5'); the fallback rate when missing or not a number.
- resolveSupplyKindSellerCountryCode() : string|null
- Returns the portal seller country (`7/invoice.default.sellerId`) as a fallback for a region without a country; null when the seller is not found.
- tariffLegacyProductTypeId() : int|null
- Returns the legacy PDF variant matrix axis (`product_type_id`) for a tariff that does not have it yet (a new tariff), derived from the supply nature (goods give goods, anything else gives service). The form no longer offers a product type; without this a new tariff would fall back to the blind default `7/invoice.default.productTypeId` and its invoice would get another PDF variant than existing tariffs. An existing value is never overwritten (the PDF matrix reads it). Null means unknown kind, so the current fallback stays.
- tariffVatPercentsValue() : string|null
- Converts the region VAT rate select value to a `decimal(5,2)` string or null. Unlike `intOrNull()`, 0 is a valid value (VAT non-payer); only an empty or non-numeric field becomes null.
- translateTariffKey() : string
- Translates a key in the presenter domain (the select has its translator off).
Constants
FALLBACK_VAT_PERCENTS
Fallback rate when `7/invoice.default.vatPercents` is missing or not a number.
private
mixed
FALLBACK_VAT_PERCENTS
= 21
LEGACY_PRODUCT_TYPE_GOODS
`cms_mod_invoicer_product_types`: 1 goods, 2 service; only for the legacy PDF axis.
private
mixed
LEGACY_PRODUCT_TYPE_GOODS
= 1
LEGACY_PRODUCT_TYPE_SERVICE
private
mixed
LEGACY_PRODUCT_TYPE_SERVICE
= 2
REGION_VAT_OPTIONS
VAT rates offered in the region select: common EU bands including decimals (2.1, 5.5, 13.5 %; 0 means exempt or non-payer). The rate belongs to a concrete tariff and region combination (another service means another rate even in the same region), so it is stored on the price list row (`TariffPrice::vatPercents`), not on the shared payment region entity.
private
array<int, string>
REGION_VAT_OPTIONS
= ['0', '2.1', '5', '5.5', '6', '7', '8', '9', '10', '12', '13', '13.5', '14', '15', '17', '19', '20', '21', '22', '23', '24', '25', '27']
SETTING_MODULE_INVOICER
Module "invoicer" in the settings table (`cms_system_settings.module`).
private
mixed
SETTING_MODULE_INVOICER
= 7
SUPPLY_KIND_SETTING_MODULE_INVOICER
Module "invoicer" in the settings table (`cms_system_settings.module`); holds the portal `sellerId`.
private
mixed
SUPPLY_KIND_SETTING_MODULE_INVOICER
= 7
Properties
$supplyKindFieldsManager
public
SupplyKindManager
$supplyKindFieldsManager
Attributes
- #[Inject]
$supplyKindFieldsSellerManager
public
SellerManager
$supplyKindFieldsSellerManager
Attributes
- #[Inject]
$supplyKindFieldsVatRateManager
public
VatRateManager
$supplyKindFieldsVatRateManager
Attributes
- #[Inject]
Methods
addSupplyKindSelect()
Adds the supply kind select. The options are database names, so the select translator is off and the prompt is translated here. IMPORTANT: the label must stay a translation key (`BaseControl::getLabel()` takes the translator from the form); a translated label would be translated twice.
protected
addSupplyKindSelect(Form $form, string $name, string $labelKey, string|null $promptKey[, string|null $descriptionKey = null ][, int|null $currentId = null ]) : SelectBox
Parameters
- $form : Form
- $name : string
- $labelKey : string
- $promptKey : string|null
-
null = no prompt (the field is required, the first or current kind is preselected)
- $descriptionKey : string|null = null
- $currentId : int|null = null
Return values
SelectBoxaddTariffBillingFields()
Adds the required supply kind of a tariff. `data-price-vat-source` is the live rate source of the helper field "price with VAT" in the price list (`product-price-vat.js` reads the region `data-price-vat-map`).
protected
addTariffBillingFields(Form $form[, int|null $currentSupplyKindId = null ]) : void
Parameters
- $form : Form
- $currentSupplyKindId : int|null = null
buildSupplyKindRegionVatMaps()
Returns the rate map for the helper field "price with VAT": `regionId => supplyKindId => percent` (valid today).
protected
buildSupplyKindRegionVatMaps(iterable<string|int, PaymentRegion> $regions) : array<int, array<int, string>>
Parameters
- $regions : iterable<string|int, PaymentRegion>
Return values
array<int, array<int, string>>buildSupplyKindVatMapAttributes()
Returns the same as {@see buildSupplyKindRegionVatMaps()} plus JSON for the `data-price-vat-map` attribute of the region matrix (keys as strings, because JS reads `map[select.value]`).
protected
buildSupplyKindVatMapAttributes(iterable<string|int, PaymentRegion> $regions) : array<int, array{json: string, map: array}>
For the template: regionId => {json, map}.
Parameters
- $regions : iterable<string|int, PaymentRegion>
Return values
array<int, array{json: string, map: arraygetSupplyKindOptions()
Returns active supply kinds as `id => name` in the admin language.
protected
getSupplyKindOptions([int|null $keepId = null ]) : array<int, string>
Parameters
- $keepId : int|null = null
Return values
array<int, string>supplyKindIdValue()
Converts the supply kind select value to an id, or null for the empty prompt.
protected
supplyKindIdValue(mixed $value) : int|null
Parameters
- $value : mixed
Return values
int|nullbuildRegionVatOptions()
Builds the options of the region VAT rate select: key is `VatRate::key()` ('21', '5.5'), label "5,5 %". A rate already stored on price list rows that is missing from the offer (e.g. 4.75) is added, otherwise saving would erase it.
private
buildRegionVatOptions([iterable<string|int, object> $storedPrices = [] ]) : array<string, string>
Parameters
- $storedPrices : iterable<string|int, object> = []
-
tariff price list rows (
TariffPrice); onlygetVatPercents()is read
Return values
array<string, string>getTariffVatFallback()
Returns the default VAT rate from setting `7/invoice.default.vatPercents` (stored as text) in the `VatRate::key()` form ('21', '5.5'); the fallback rate when missing or not a number.
private
getTariffVatFallback() : string
Return values
stringresolveSupplyKindSellerCountryCode()
Returns the portal seller country (`7/invoice.default.sellerId`) as a fallback for a region without a country; null when the seller is not found.
private
resolveSupplyKindSellerCountryCode() : string|null
Return values
string|nulltariffLegacyProductTypeId()
Returns the legacy PDF variant matrix axis (`product_type_id`) for a tariff that does not have it yet (a new tariff), derived from the supply nature (goods give goods, anything else gives service). The form no longer offers a product type; without this a new tariff would fall back to the blind default `7/invoice.default.productTypeId` and its invoice would get another PDF variant than existing tariffs. An existing value is never overwritten (the PDF matrix reads it). Null means unknown kind, so the current fallback stays.
private
tariffLegacyProductTypeId(int|null $currentProductTypeId, int|null $supplyKindId) : int|null
Parameters
- $currentProductTypeId : int|null
- $supplyKindId : int|null
Return values
int|nulltariffVatPercentsValue()
Converts the region VAT rate select value to a `decimal(5,2)` string or null. Unlike `intOrNull()`, 0 is a valid value (VAT non-payer); only an empty or non-numeric field becomes null.
private
tariffVatPercentsValue(mixed $value) : string|null
Parameters
- $value : mixed
Return values
string|nulltranslateTariffKey()
Translates a key in the presenter domain (the select has its translator off).
private
translateTariffKey(string $key) : string
Parameters
- $key : string