PaymentRegionFormTrait
Add/edit form of a payment region.
The skeleton comes from BasePresenter::createForm(). Translated:
name. Untranslated: currencyId / regionId (selects), isDefault, active (header toggle).
Also edits the PDF variant matrix, a second view of the same relation as
InvoiceTypeFormTrait (axes from
PdfVariantMatrixTrait; the presenter supplies
$matrixInvoiceTypes). The matrix is saved by one atomic Api operation
(api/invoicer/invoice-type/save-pdf-variant-matrix, one DB transaction) and touches only
cells of this region, see self::savePdfVariantMatrix().
The matrix is dense also in seller mode (seller_use_vat): the grid is rendered twice (payer
and non-payer tab, PdfVariantMatrixTrait::pdfVariantSellerModes()).
IMPORTANT: both halves must always be rendered; Nette evaluates a skipped widget as empty on
submit and the full replace would delete that half of the matrix.
Table of Contents
Methods
- createComponentEditForm() : Form
- addPdfVariantMatrixFields() : void
- PDF variant matrix from the region view: columns are invoice types, rows are user types, separately for each half by seller mode (a tab of its own in the template).
- addSettingsFields() : void
- Settings: currency and region (selects), default region, VAT rate, global activation.
- addTranslationFields() : void
- Multilingual fields: name per language (`name_<langId>`), active by checkbox.
- buildPaymentRegionEntity() : PaymentRegion
- buildPdfVariantCells() : array<int, array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null}>
- Returns the matrix cells of this region from the form: a dense grid over all 4 axes (invoice type, product type, customer type, seller mode). An empty cell is sent with `pdfTemplateVariantId = null` instead of being omitted: the matrix is dense in the DB and an omitted cell would vanish after the transactional delete plus insert.
- pdfVariantFieldName() : string
- Returns the matrix field name: 4 axes joined by underscores (no collision with other fields).
- prepareCountryOptions() : array<string, string>
- Country options `code => "CODE — name"` (admin language, seed order: CZ, SK first).
- prepareCurrencyOptions() : array<int, string>
- Returns currency options: `id => name`.
- prepareLanguageOptions() : array<int, string>
- Returns options of the default document language: `id => name` from the system language code list (the same source as the multilingual form fields).
- prepareRegionOptions() : array<int, string>
- Returns region options: `id => name` (current language, else the first non-empty).
- regionLabel() : string
- Returns the region name in the current language (else the first non-empty).
- savePaymentRegionForm() : bool
- Saves the form data. The redirect is done by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
- savePdfVariantMatrix() : bool
- Saves the whole PDF variant matrix of this region by one Api operation `api/invoicer/invoice-type/save-pdf-variant-matrix`.
- setPaymentRegionFormDefaults() : void
- setPdfVariantMatrixDefaults() : void
- Default matrix values; the argument order of `getPdfTemplateVariantRel()` is (productType, paymentRegion, buyerVatType, sellerUseVat).
- tr() : string
- Translates a key in the form domain to a finished string (for fields with `setTranslator(null)`).
Methods
createComponentEditForm()
protected
createComponentEditForm() : Form
Return values
FormaddPdfVariantMatrixFields()
PDF variant matrix from the region view: columns are invoice types, rows are user types, separately for each half by seller mode (a tab of its own in the template).
private
addPdfVariantMatrixFields(Form $form) : void
Parameters
- $form : Form
addSettingsFields()
Settings: currency and region (selects), default region, VAT rate, global activation.
private
addSettingsFields(Form $form) : void
Parameters
- $form : Form
addTranslationFields()
Multilingual fields: name per language (`name_<langId>`), active by checkbox.
private
addTranslationFields(Form $form) : void
Parameters
- $form : Form
buildPaymentRegionEntity()
private
buildPaymentRegionEntity(ArrayHash<string|int, mixed> $values) : PaymentRegion
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
PaymentRegionbuildPdfVariantCells()
Returns the matrix cells of this region from the form: a dense grid over all 4 axes (invoice type, product type, customer type, seller mode). An empty cell is sent with `pdfTemplateVariantId = null` instead of being omitted: the matrix is dense in the DB and an omitted cell would vanish after the transactional delete plus insert.
private
buildPdfVariantCells(ArrayHash<string|int, mixed> $values) : array<int, array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null}>
IMPORTANT: both halves (payer/non-payer) are always built; Nette evaluates a skipped widget as empty on submit and that half of the matrix would be reset.
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
array<int, array{invoiceTypeId: int, productTypeId: int, buyerVatType: int, sellerUseVat: int, pdfTemplateVariantId: int|null}>pdfVariantFieldName()
Returns the matrix field name: 4 axes joined by underscores (no collision with other fields).
private
pdfVariantFieldName(int|null $productTypeId, int|null $invoiceTypeId, int|null $buyerVatType, int|null $sellerUseVat) : string
The 4th part is the seller mode (1 = payer, 0 = non-payer), i.e. the matrix half.
Parameters
- $productTypeId : int|null
- $invoiceTypeId : int|null
- $buyerVatType : int|null
- $sellerUseVat : int|null
Return values
stringprepareCountryOptions()
Country options `code => "CODE — name"` (admin language, seed order: CZ, SK first).
private
prepareCountryOptions() : array<string, string>
Return values
array<string, string>prepareCurrencyOptions()
Returns currency options: `id => name`.
private
prepareCurrencyOptions() : array<int, string>
Return values
array<int, string>prepareLanguageOptions()
Returns options of the default document language: `id => name` from the system language code list (the same source as the multilingual form fields).
private
prepareLanguageOptions() : array<int, string>
Return values
array<int, string>prepareRegionOptions()
Returns region options: `id => name` (current language, else the first non-empty).
private
prepareRegionOptions() : array<int, string>
IMPORTANT: only countries (level 1). A payment region (prices, payments, VAT) may refer
only to a country, not to a county, district or municipality; after the municipality
import into cms_system_regions (~9.5k nodes) an unfiltered findAll() would flood the
select.
Return values
array<int, string>regionLabel()
Returns the region name in the current language (else the first non-empty).
private
regionLabel(Region $region, int|null $currentLang) : string
Parameters
- $region : Region
- $currentLang : int|null
Return values
stringsavePaymentRegionForm()
Saves the form data. The redirect is done by {@see \App\Core\Base\Admin\BasePresenter::createForm()}.
private
savePaymentRegionForm(ArrayHash<string|int, mixed> $values) : bool
Parameters
- $values : ArrayHash<string|int, mixed>
Return values
boolsavePdfVariantMatrix()
Saves the whole PDF variant matrix of this region by one Api operation `api/invoicer/invoice-type/save-pdf-variant-matrix`.
private
savePdfVariantMatrix(int $paymentRegionId, ArrayHash<string|int, mixed> $values) : bool
The matrix is one DB transaction
(PdfVariantMatrixTrait::savePdfVariantMatrix()):
either all of it is written or it is rolled back and nothing changes in the DB. The
operation touches only rows of this paymentRegionId, so cells of other regions need not
be carried back and forth (omitting them would let orphanRemoval delete them).
The failure message stays form.messages.matrix.restored: "nothing changed in the matrix"
is literally true after a rollback.
Parameters
- $paymentRegionId : int
- $values : ArrayHash<string|int, mixed>
Return values
boolsetPaymentRegionFormDefaults()
private
setPaymentRegionFormDefaults(Form $form) : void
Parameters
- $form : Form
setPdfVariantMatrixDefaults()
Default matrix values; the argument order of `getPdfTemplateVariantRel()` is (productType, paymentRegion, buyerVatType, sellerUseVat).
private
setPdfVariantMatrixDefaults(array<string, mixed> &$defaults, int $paymentRegionId) : void
Parameters
- $defaults : array<string, mixed>
- $paymentRegionId : int
tr()
Translates a key in the form domain to a finished string (for fields with `setTranslator(null)`).
private
tr(string $key) : string
Parameters
- $key : string