From e5231e29f2ffbd7e933b3e990e03a4fed41100f0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Tue, 10 Feb 2026 17:13:54 +0100 Subject: [PATCH] Allow to set a global default if new orderdetails should contain VAT or not --- src/Form/Part/PartBaseType.php | 7 ++++++- .../SystemSettings/LocalizationSettings.php | 13 ++++++++++++- templates/form/extended_bootstrap_layout.html.twig | 11 +++++++++++ templates/parts/edit/edit_form_styles.html.twig | 2 +- translations/messages.en.xlf | 12 ++++++++++++ 5 files changed, 42 insertions(+), 3 deletions(-) diff --git a/src/Form/Part/PartBaseType.php b/src/Form/Part/PartBaseType.php index 902aff40..2145db93 100644 --- a/src/Form/Part/PartBaseType.php +++ b/src/Form/Part/PartBaseType.php @@ -43,6 +43,7 @@ use App\Services\InfoProviderSystem\DTOs\PartDetailDTO; use App\Services\LogSystem\EventCommentNeededHelper; use App\Services\LogSystem\EventCommentType; use App\Settings\MiscSettings\IpnSuggestSettings; +use App\Settings\SystemSettings\LocalizationSettings; use Symfony\Bundle\SecurityBundle\Security; use Symfony\Component\Form\AbstractType; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; @@ -63,6 +64,7 @@ class PartBaseType extends AbstractType protected UrlGeneratorInterface $urlGenerator, protected EventCommentNeededHelper $event_comment_needed_helper, protected IpnSuggestSettings $ipnSuggestSettings, + private readonly LocalizationSettings $localizationSettings, ) { } @@ -267,6 +269,9 @@ class PartBaseType extends AbstractType 'entity' => $part, ]); + $orderdetailPrototype = new Orderdetail(); + $orderdetailPrototype->setPricesIncludesVAT($this->localizationSettings->pricesIncludeTaxByDefault); + //Orderdetails section $builder->add('orderdetails', CollectionType::class, [ 'entry_type' => OrderdetailType::class, @@ -275,7 +280,7 @@ class PartBaseType extends AbstractType 'allow_delete' => true, 'label' => false, 'by_reference' => false, - 'prototype_data' => new Orderdetail(), + 'prototype_data' => $orderdetailPrototype, 'entry_options' => [ 'measurement_unit' => $part->getPartUnit(), ], diff --git a/src/Settings/SystemSettings/LocalizationSettings.php b/src/Settings/SystemSettings/LocalizationSettings.php index c6780c6c..d0c3ce75 100644 --- a/src/Settings/SystemSettings/LocalizationSettings.php +++ b/src/Settings/SystemSettings/LocalizationSettings.php @@ -25,6 +25,7 @@ namespace App\Settings\SystemSettings; use App\Form\Settings\LanguageMenuEntriesType; use App\Form\Type\LocaleSelectType; +use App\Form\Type\TriStateCheckboxType; use App\Settings\SettingsIcon; use Jbtronics\SettingsBundle\Metadata\EnvVarMode; use Jbtronics\SettingsBundle\ParameterTypes\ArrayType; @@ -46,7 +47,7 @@ class LocalizationSettings #[Assert\Locale()] #[Assert\NotBlank()] #[SettingsParameter(label: new TM("settings.system.localization.locale"), formType: LocaleSelectType::class, - envVar: "string:DEFAULT_LANG", envVarMode: EnvVarMode::OVERWRITE)] + envVar: "string:DEFAULT_LANG", envVarMode: EnvVarMode::OVERWRITE)] public string $locale = 'en'; #[Assert\Timezone()] @@ -73,4 +74,14 @@ class LocalizationSettings )] #[Assert\All([new Assert\Locale()])] public array $languageMenuEntries = []; + + #[SettingsParameter(label: new TM("settings.system.localization.prices_include_tax_by_default"), + description: new TM("settings.system.localization.prices_include_tax_by_default.description"), + formType: TriStateCheckboxType::class + )] + /** + * Indicates whether prices should include tax by default. This is used when creating new pricedetails. + * Null means that the VAT state should be indetermine by default. + */ + public ?bool $pricesIncludeTaxByDefault = null; } diff --git a/templates/form/extended_bootstrap_layout.html.twig b/templates/form/extended_bootstrap_layout.html.twig index 75e44a15..ecd7caf0 100644 --- a/templates/form/extended_bootstrap_layout.html.twig +++ b/templates/form/extended_bootstrap_layout.html.twig @@ -100,6 +100,17 @@ {%- endif -%} {%- endblock tristate_widget %} +{% block tristate_row -%} + {#--#} +
{#--#} +
+ {{- form_widget(form) -}} + {{- form_help(form) -}} + {{- form_errors(form) -}} +
{#--#} + +{%- endblock tristate_row %} + {%- block choice_widget_collapsed -%} {# Only add the BS5 form-select class if we dont use bootstrap-selectpicker #} {# {% if attr["data-controller"] is defined and attr["data-controller"] not in ["elements--selectpicker"] %} diff --git a/templates/parts/edit/edit_form_styles.html.twig b/templates/parts/edit/edit_form_styles.html.twig index aa68f38a..1856dbff 100644 --- a/templates/parts/edit/edit_form_styles.html.twig +++ b/templates/parts/edit/edit_form_styles.html.twig @@ -32,7 +32,7 @@ {{ form_row(form.supplierpartnr, {'attr': {'class': 'form-control-sm'}}) }} {{ form_row(form.supplier_product_url, {'attr': {'class': 'form-control-sm'}}) }} {{ form_widget(form.obsolete) }} - {{ form_row(form.pricesIncludesVAT) }} + {{ form_widget(form.pricesIncludesVAT) }}
diff --git a/translations/messages.en.xlf b/translations/messages.en.xlf index a776eb9d..36fc10d1 100644 --- a/translations/messages.en.xlf +++ b/translations/messages.en.xlf @@ -12455,5 +12455,17 @@ Buerklin-API Authentication server: Excl. VAT + + + settings.system.localization.prices_include_tax_by_default + Prices include VAT by default + + + + + settings.system.localization.prices_include_tax_by_default.description + The default value for newly created purchase infos, if prices include VAT or not. + +