SupplyKindFieldsTrait
Supply kind on admin item forms: the supply kind select and the rate map for the helper field "price with VAT" (`product-price-vat.js`).
- addSupplyKindSelect() builds the select of active kinds (without
voucher_mpv); the current value of the item stays offered even if the kind was deactivated meanwhile. - buildSupplyKindRegionVatMaps() builds, per payment region,
supplyKindId => ratevalid today in the region country; a region without a country uses the seller country (7/invoice.default.sellerId). Rates are read by the Api (api/system/vat-rate/rate-maptoVatRateManager::findRateMap()); a missing rate means the kind is missing in the map and the helper field stays empty (nothing is invented).
Managers come through #[Inject] (like TariffBillingFieldsTrait), so the host presenters
need no constructor change; the property names are prefixed so they do not collide with the
presenter constructor.
Table of Contents
Constants
- 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.
- 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.
- 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.
Constants
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
SelectBoxbuildSupplyKindRegionVatMaps()
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|nullresolveSupplyKindSellerCountryCode()
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