From 3542ad5bca12643ac4c7e286f0c0fa86ecec4b8e Mon Sep 17 00:00:00 2001 From: Laurent Muller Date: Tue, 24 Dec 2024 12:25:37 +0100 Subject: [PATCH] Remove fax from customer. --- composer.json | 4 +- composer.lock | 2 +- config/services.php | 1 + public/images/logo/logo-customer.svg | 11 ++ public/js/application/parameters_edit.js | 89 +++++++------ public/vendor.json | 10 +- src/Faker/EntityProvider.php | 2 +- src/Form/Admin/ApplicationParametersType.php | 4 - src/Form/FormHelper.php | 22 +--- .../AbstractHelperParametersType.php | 57 +++++++++ src/Form/Parameters/AbstractParameterType.php | 12 +- .../Parameters/ApplicationParametersType.php | 52 ++------ src/Form/Parameters/CustomerParameterType.php | 58 +++++++-- src/Form/Parameters/UserParametersType.php | 44 +------ src/Interfaces/PropertyServiceInterface.php | 5 - src/Interfaces/TimestampableInterface.php | 5 - src/Model/CustomerInformation.php | 59 --------- src/Parameter/CustomerParameter.php | 46 ++++++- src/Pdf/Html/AbstractHtmlChunk.php | 7 +- src/Pdf/Html/AbstractHtmlListChunk.php | 6 + src/Pdf/Html/HtmlListType.php | 22 ++-- src/Pdf/Html/HtmlOlChunk.php | 6 +- src/Pdf/Html/HtmlParser.php | 6 +- src/Pdf/Html/HtmlStyle.php | 12 +- src/Report/LogsReport.php | 8 +- src/Report/ReportHeader.php | 117 ++++-------------- src/Service/ApplicationService.php | 10 -- src/Spreadsheet/HeaderFooter.php | 5 + src/Spreadsheet/SpreadsheetDocument.php | 6 +- src/Spreadsheet/WorksheetDocument.php | 33 ++--- src/Traits/TimestampableTrait.php | 4 +- src/Twig/FunctionExtension.php | 3 - src/Utils/FileUtils.php | 13 +- src/Word/WordHeader.php | 85 +++---------- .../calculation_edit_panel_totals.html.twig | 8 +- templates/macros/_timestampable.html.twig | 28 ++--- .../parameters/_parameters_customer.html.twig | 9 +- templates/test/parameter.html.twig | 87 +++++++++---- tests/ContainerServiceTrait.php | 4 +- .../ResetPasswordControllerTest.php | 11 ++ tests/Form/FormHelperTest.php | 10 -- tests/Model/CustomerInformationTest.php | 31 ----- tests/Parameter/CustomerParameterTest.php | 24 +++- tests/Pdf/Html/HtmlListTypeTest.php | 33 ++--- tests/Service/ApplicationServiceTest.php | 1 - tests/Spreadsheet/WorksheetDocumentTest.php | 3 +- tests/Traits/TimestampableTraitTest.php | 8 +- tests/Utils/FileUtilsTest.php | 43 ++++++- tests/Word/AbstractWordDocumentTest.php | 1 - translations/messages.fr_CH.yaml | 32 ++--- 50 files changed, 545 insertions(+), 614 deletions(-) create mode 100644 public/images/logo/logo-customer.svg create mode 100644 src/Form/Parameters/AbstractHelperParametersType.php diff --git a/composer.json b/composer.json index ea35935d5..834f811e6 100644 --- a/composer.json +++ b/composer.json @@ -88,8 +88,8 @@ "vich/uploader-bundle": "^2.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.8", - "fortawesome/font-awesome": "^6.6", + "bamarni/composer-bin-plugin": "^1.0", + "fortawesome/font-awesome": "^6.0", "symfony/browser-kit": "7.2.*", "symfony/css-selector": "7.2.*", "symfony/debug-bundle": "7.2.*", diff --git a/composer.lock b/composer.lock index 1987924d9..afa4e7cd6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5c3424a5a9c6a77d6729eb3cc4bf148e", + "content-hash": "55a6bc8b2fa826580841da3370bbb21f", "packages": [ { "name": "bacon/bacon-qr-code", diff --git a/config/services.php b/config/services.php index 6514e0e71..fd44c878e 100644 --- a/config/services.php +++ b/config/services.php @@ -76,6 +76,7 @@ $path . 'Model', $path . 'Pdf', $path . 'Report', + $path . 'Response', $path . 'Spreadsheet', $path . 'Traits', $path . 'Util', diff --git a/public/images/logo/logo-customer.svg b/public/images/logo/logo-customer.svg new file mode 100644 index 000000000..12832a087 --- /dev/null +++ b/public/images/logo/logo-customer.svg @@ -0,0 +1,11 @@ + + + + + + + diff --git a/public/js/application/parameters_edit.js b/public/js/application/parameters_edit.js index 7fe56b2c1..d0ce1ed86 100644 --- a/public/js/application/parameters_edit.js +++ b/public/js/application/parameters_edit.js @@ -111,36 +111,38 @@ function displayNotification($source) { /** * Handle input change. * - * @param {string} inputId the input selector. + * @param {string} selector the input selector. * @param {string} groupId the group selector. * @param {function} callback the function to call. */ -function handleInput(inputId, groupId, callback) { +function handleInput(selector, groupId, callback) { 'use strict'; - const $input = $(inputId); - const $group = $input.parents('.input-group').find(groupId); - if (!$input.length || !$group.length) { - return; - } - const handler = function (e) { - e.preventDefault(); - const value = String($input.val()).trim(); - if ($input.valid() && value) { - try { - callback(value); - } catch (error) { - $group.off('click', handler).removeClass('cursor-pointer'); - window.console.error(error); - } + $(selector).each(function () { + const $input = $(this); + const $group = $input.parents('.input-group').find(groupId); + if (!$group.length) { + return; } - $input.trigger('focus'); - }; - $input.on('input', function () { - $group.removeClass('cursor-pointer').off('click', handler); - if ($input.valid() && String($input.val()).trim()) { - $group.addClass('cursor-pointer').on('click', handler); - } - }).trigger('input'); + const handler = function (e) { + e.preventDefault(); + const value = String($input.val()).trim(); + if (value && $input.valid()) { + try { + callback(value); + } catch (error) { + $group.off('click', handler).removeClass('cursor-pointer'); + window.console.error(error); + } + } + $input.trigger('focus'); + }; + $input.on('input', function () { + $group.removeClass('cursor-pointer').off('click', handler); + if ($input.valid() && String($input.val()).trim()) { + $group.addClass('cursor-pointer').on('click', handler); + } + }).trigger('input'); + }); } /** @@ -151,7 +153,7 @@ function handleUrl() { const handler = function (value) { window.open(value, '_blank'); }; - handleInput('#customer_url', '.input-group-url', handler); + handleInput('[inputmode="url"]', '.input-group-url', handler); } /** @@ -165,14 +167,6 @@ function handlePhone() { handleInput('#customer_phone', '.input-group-phone', handler); } -// function handleFax() { -// 'use strict'; -// const handler = function (value) { -// window.location.href = 'fax:' + value; -// }; -// handleInput('#customer_fax', '.input-group-fax', handler); -// } - /** * Handle the Email input. */ @@ -184,6 +178,11 @@ function handleEmail() { handleInput('#customer_email', '.input-group-email', handler); } +function findCollapseButton($source) { + 'use strict'; + return $source.prev('.card-header').find('a.card-title'); +} + /** * Ready function */ @@ -213,32 +212,30 @@ $(function () { $('.btn-item-all').on('click', function () { setDefaultValues(); }); - $('.btn-notify').on('click', () => { - const $items = $('.dropdown-notify'); - const index = Math.floor(Math.random() * $items.length); - $items.eq(index).trigger('click'); - }); - $('.dropdown-notify').on('click', (e) => { + const $notify = $('.dropdown-notify'); + $notify.on('click', (e) => { displayNotification($(e.currentTarget)); }); + $('.btn-notify').on('click', () => { + const index = Math.floor(Math.random() * $notify.length); + $notify.eq(index).trigger('click'); + }); $('.card-parameter .collapse').on('shown.bs.collapse', function () { - const $this = $(this); - const $button = $this.prev('.card-header').find('a.card-title'); + const $button = findCollapseButton($(this)); $button.attr('title', $button.data('hide')); const $page = getActivePage(); if ($page && $page.find('.is-invalid').length === 0) { - $page.find(':input:first').trigger('focus'); + $page.find(':input:first').trigger('focus') + .trigger('select'); } updateVisibleButton(); }).on('hidden.bs.collapse', function () { - const $this = $(this); - const $button = $this.prev('.card-header').find('a.card-title'); + const $button = findCollapseButton($(this)); $button.attr('title', $button.data('show')); updateVisibleButton(); }); updateVisibleButton(); handlePhone(); handleEmail(); - // handleFax(); handleUrl(); }); diff --git a/public/vendor.json b/public/vendor.json index 953c99b34..daeb6756b 100644 --- a/public/vendor.json +++ b/public/vendor.json @@ -50,7 +50,7 @@ }, { "name": "font-awesome", - "version": "6.7.1", + "version": "6.7.2", "source": "cdnjs", "files": [ "css/all.css", @@ -86,7 +86,7 @@ }, { "name": "highcharts", - "version": "12.0.2", + "version": "12.1.2", "source": "jsdelivr", "files": [ "highcharts.js" @@ -141,7 +141,7 @@ }, { "name": "bootstrap-table", - "version": "1.23.5", + "version": "1.24.0", "source": "cdnjs", "files": [ "bootstrap-table.js", @@ -151,7 +151,7 @@ { "name": "bootstrap-table", "display": "bootstrap-table:defer-url", - "version": "1.23.5", + "version": "1.24.0", "source": "cdnjs", "prefix": "extensions/defer-url/", "files": [ @@ -161,7 +161,7 @@ { "name": "bootstrap-table", "display": "bootstrap-table:custom-view", - "version": "1.23.5", + "version": "1.24.0", "source": "cdnjs", "prefix": "extensions/custom-view/", "files": [ diff --git a/src/Faker/EntityProvider.php b/src/Faker/EntityProvider.php index 1807fcd92..5b34c24cf 100644 --- a/src/Faker/EntityProvider.php +++ b/src/Faker/EntityProvider.php @@ -86,7 +86,7 @@ protected function distinctValue(string $field, bool $allowNull = false): mixed $values = $this->distinctValues[$field]; if ($allowNull) { - $values += [null]; + $values[] = null; } return static::randomElement($values); diff --git a/src/Form/Admin/ApplicationParametersType.php b/src/Form/Admin/ApplicationParametersType.php index b16d7696a..b4a5b4e98 100644 --- a/src/Form/Admin/ApplicationParametersType.php +++ b/src/Form/Admin/ApplicationParametersType.php @@ -70,10 +70,6 @@ private function addCustomerSection(FormHelper $helper): void ->notRequired() ->addTelType(); - $helper->field(PropertyServiceInterface::P_CUSTOMER_FAX) - ->notRequired() - ->addFaxType(); - $helper->field(PropertyServiceInterface::P_CUSTOMER_EMAIL) ->updateOption('prepend_title', 'parameters.fields.customer_email_title') ->notRequired() diff --git a/src/Form/FormHelper.php b/src/Form/FormHelper.php index bb9ed62f5..f698804fa 100644 --- a/src/Form/FormHelper.php +++ b/src/Form/FormHelper.php @@ -269,17 +269,6 @@ public function addEnumType(string $class): self return $this->add(EnumType::class); } - /** - * Add a fax (telephone) type to the builder and reset all values to the default. - */ - public function addFaxType(?string $pattern = null): self - { - return $this->updateAttribute('pattern', $pattern) - ->updateOption('prepend_icon', 'fa-solid fa-fax') - ->updateOption('prepend_class', 'input-group-fax') - ->add(TelType::class); - } - /** * Add a file type to the builder and reset all values to the default. * @@ -478,14 +467,15 @@ public function addTrueFalseType( /** * Add an Url type to the builder and reset all values to the default. * - * @param string $protocol If a value is submitted, that doesn't begin with some protocol, - * (http://, ftp://, etc.), this protocol will be prepended to - * the string when the data is submitted to the form. + * @param string $protocol If a value is submitted, that doesn't begin with some protocol, + * (http://, ftp://, etc.), this protocol will be prepended to + * the string when the data is submitted to the form. + * @param ?string $icon the prepended icon or null to use default (solid globe) */ - public function addUrlType(string $protocol = 'https'): self + public function addUrlType(string $protocol = 'https', ?string $icon = null): self { return $this->updateOption('default_protocol', $protocol) - ->updateOption('prepend_icon', 'fa-solid fa-globe') + ->updateOption('prepend_icon', $icon ?? 'fa-solid fa-globe') ->updateOption('prepend_class', 'input-group-url') ->updateAttribute('inputmode', 'url') ->add(UrlType::class); diff --git a/src/Form/Parameters/AbstractHelperParametersType.php b/src/Form/Parameters/AbstractHelperParametersType.php new file mode 100644 index 000000000..6a042738d --- /dev/null +++ b/src/Form/Parameters/AbstractHelperParametersType.php @@ -0,0 +1,57 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace App\Form\Parameters; + +use App\Parameter\AbstractParameters; +use Symfony\Component\Form\AbstractType; +use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\OptionsResolver\OptionsResolver; + +/** + * @template TParameters of AbstractParameters + * + * @extends AbstractType + */ +abstract class AbstractHelperParametersType extends AbstractType +{ + public const DEFAULT_VALUES = 'default_values'; + + public function buildForm(FormBuilderInterface $builder, array $options): void + { + $builder->add('display', DisplayParameterType::class); + $builder->add('homePage', HomePageParameterType::class); + $builder->add('message', MessageParameterType::class); + $builder->add('options', OptionsParameterType::class); + } + + public function configureOptions(OptionsResolver $resolver): void + { + $resolver->setDefaults([ + 'data_class' => $this->getParametersClass(), + ]); + + $resolver->setDefault(self::DEFAULT_VALUES, []) + ->setAllowedTypes(self::DEFAULT_VALUES, 'array'); + } + + public function getBlockPrefix(): string + { + return ''; + } + + /** + * @return class-string + */ + abstract protected function getParametersClass(): string; +} diff --git a/src/Form/Parameters/AbstractParameterType.php b/src/Form/Parameters/AbstractParameterType.php index e738debd1..f2bfe6ccc 100644 --- a/src/Form/Parameters/AbstractParameterType.php +++ b/src/Form/Parameters/AbstractParameterType.php @@ -92,24 +92,20 @@ private function convertValue(string $key, mixed $value): mixed return $value; } - private function getCacheKey(): string - { - return $this->getParameterClass()::getCacheKey(); - } - /** * @psalm-return array */ private function getDefaultValues(FormInterface $form): array { $config = $form->getRoot()->getConfig(); - if (!$config->hasOption(ApplicationParametersType::DEFAULT_VALUES)) { + if (!$config->hasOption(AbstractHelperParametersType::DEFAULT_VALUES)) { return []; } + $key = $this->getParameterClass()::getCacheKey(); /** @psalm-var array> $values */ - $values = $config->getOption(ApplicationParametersType::DEFAULT_VALUES); + $values = $config->getOption(AbstractHelperParametersType::DEFAULT_VALUES); - return $values[$this->getCacheKey()] ?? []; + return $values[$key] ?? []; } } diff --git a/src/Form/Parameters/ApplicationParametersType.php b/src/Form/Parameters/ApplicationParametersType.php index e2b6a164a..7902ea73e 100644 --- a/src/Form/Parameters/ApplicationParametersType.php +++ b/src/Form/Parameters/ApplicationParametersType.php @@ -13,60 +13,34 @@ namespace App\Form\Parameters; -use App\Form\AbstractHelperType; -use App\Form\FormHelper; use App\Interfaces\RoleInterface; use App\Parameter\ApplicationParameters; use Symfony\Bundle\SecurityBundle\Security; -use Symfony\Component\OptionsResolver\OptionsResolver; +use Symfony\Component\Form\FormBuilderInterface; -class ApplicationParametersType extends AbstractHelperType +/** + * @extends AbstractHelperParametersType + */ +class ApplicationParametersType extends AbstractHelperParametersType { - public const DEFAULT_VALUES = 'default_values'; - public function __construct(private readonly Security $security) { } - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => ApplicationParameters::class, - ]); - - $resolver->setDefault(self::DEFAULT_VALUES, []) - ->setAllowedTypes(self::DEFAULT_VALUES, 'array'); - } - - public function getBlockPrefix(): string - { - return ''; - } - - protected function addFormFields(FormHelper $helper): void + public function buildForm(FormBuilderInterface $builder, array $options): void { - $this->addParameterType($helper, 'customer', CustomerParameterType::class); - $this->addParameterType($helper, 'default', DefaultParameterType::class); - $this->addParameterType($helper, 'display', DisplayParameterType::class); - $this->addParameterType($helper, 'homePage', HomePageParameterType::class); - $this->addParameterType($helper, 'message', MessageParameterType::class); - $this->addParameterType($helper, 'options', OptionsParameterType::class); - $this->addParameterType($helper, 'product', ProductParameterType::class); + parent::buildForm($builder, $options); + $builder->add('customer', CustomerParameterType::class); + $builder->add('default', DefaultParameterType::class); + $builder->add('product', ProductParameterType::class); if ($this->isSuperAdmin()) { - $this->addParameterType($helper, 'security', SecurityParameterType::class); + $builder->add('security', SecurityParameterType::class); } } - /** - * @psalm-template T of AbstractParameterType - * - * @psalm-param class-string $class - */ - private function addParameterType(FormHelper $helper, string $name, string $class): void + protected function getParametersClass(): string { - $helper->field($name) - ->label(false) - ->add($class); + return ApplicationParameters::class; } private function isSuperAdmin(): bool diff --git a/src/Form/Parameters/CustomerParameterType.php b/src/Form/Parameters/CustomerParameterType.php index 6aed0e9e3..d1b40a2f4 100644 --- a/src/Form/Parameters/CustomerParameterType.php +++ b/src/Form/Parameters/CustomerParameterType.php @@ -24,39 +24,79 @@ protected function addFormFields(FormHelper $helper): void ->label('parameters.fields.customer_name') ->updateOption('prepend_icon', 'fa-solid fa-user-group') ->addTextType(); + $helper->field('address') ->label('parameters.fields.customer_address') ->updateOption('prepend_icon', 'fa-solid fa-location-dot') ->notRequired() ->addTextType(); + $helper->field('zipCity') ->label('parameters.fields.customer_zip_city') ->updateOption('prepend_icon', 'fa-solid fa-map-location-dot') ->notRequired() ->addTextType(); + $helper->field('phone') ->label('parameters.fields.customer_phone') ->updateOption('prepend_title', 'parameters.fields.customer_phone_title') ->notRequired() ->addTelType(); - $helper->field('fax') - ->label('parameters.fields.customer_fax') - ->notRequired() - ->addFaxType(); + $helper->field('email') ->label('parameters.fields.customer_email') ->updateOption('prepend_title', 'parameters.fields.customer_email_title') ->notRequired() ->addEmailType(); - $helper->field('url') - ->label('parameters.fields.customer_url') - ->updateOption('prepend_title', 'parameters.fields.customer_url_title') - ->notRequired() - ->addUrlType(); + + $this->addUrlType( + $helper, + 'url', + 'parameters.fields.customer_url', + 'parameters.fields.customer_url_title' + ); + + $this->addUrlType( + $helper, + 'linkedin', + 'parameters.fields.customer_linkedin', + 'parameters.fields.customer_linkedin_title', + 'fa-brands fa-linkedin' + ); + + $this->addUrlType( + $helper, + 'instagram', + 'parameters.fields.customer_instagram', + 'parameters.fields.customer_instagram_title', + 'fa-brands fa-instagram' + ); + + $this->addUrlType( + $helper, + 'facebook', + 'parameters.fields.customer_facebook', + 'parameters.fields.customer_facebook_title', + 'fa-brands fa-facebook' + ); } protected function getParameterClass(): string { return CustomerParameter::class; } + + private function addUrlType( + FormHelper $helper, + string $field, + string $label, + string $title, + ?string $icon = null + ): void { + $helper->field($field) + ->label($label) + ->updateOption('prepend_title', $title) + ->notRequired() + ->addUrlType(icon: $icon); + } } diff --git a/src/Form/Parameters/UserParametersType.php b/src/Form/Parameters/UserParametersType.php index 298ddf11f..d5a7e7d0f 100644 --- a/src/Form/Parameters/UserParametersType.php +++ b/src/Form/Parameters/UserParametersType.php @@ -13,47 +13,15 @@ namespace App\Form\Parameters; -use App\Form\AbstractHelperType; -use App\Form\FormHelper; use App\Parameter\UserParameters; -use Symfony\Component\OptionsResolver\OptionsResolver; -class UserParametersType extends AbstractHelperType +/** + * @extends AbstractHelperParametersType + */ +class UserParametersType extends AbstractHelperParametersType { - public const DEFAULT_VALUES = 'default_values'; - - public function configureOptions(OptionsResolver $resolver): void - { - $resolver->setDefaults([ - 'data_class' => UserParameters::class, - ]); - - $resolver->setDefault(self::DEFAULT_VALUES, []) - ->setAllowedTypes(self::DEFAULT_VALUES, 'array'); - } - - public function getBlockPrefix(): string - { - return ''; - } - - protected function addFormFields(FormHelper $helper): void - { - $this->addParameterType($helper, 'display', DisplayParameterType::class); - $this->addParameterType($helper, 'homePage', HomePageParameterType::class); - $this->addParameterType($helper, 'message', MessageParameterType::class); - $this->addParameterType($helper, 'options', OptionsParameterType::class); - } - - /** - * @psalm-template T of AbstractParameterType - * - * @psalm-param class-string $class - */ - private function addParameterType(FormHelper $helper, string $name, string $class): void + protected function getParametersClass(): string { - $helper->field($name) - ->label(false) - ->add($class); + return UserParameters::class; } } diff --git a/src/Interfaces/PropertyServiceInterface.php b/src/Interfaces/PropertyServiceInterface.php index 021e25a91..548f3505e 100644 --- a/src/Interfaces/PropertyServiceInterface.php +++ b/src/Interfaces/PropertyServiceInterface.php @@ -137,11 +137,6 @@ interface PropertyServiceInterface */ final public const P_CUSTOMER_EMAIL = 'customer_email'; - /** - * The property name for the customer fax number (string). - */ - final public const P_CUSTOMER_FAX = 'customer_fax'; - /** * The property name for the customer name (string). */ diff --git a/src/Interfaces/TimestampableInterface.php b/src/Interfaces/TimestampableInterface.php index 70685dd3c..c8a66a934 100644 --- a/src/Interfaces/TimestampableInterface.php +++ b/src/Interfaces/TimestampableInterface.php @@ -37,11 +37,6 @@ public function getCreatedBy(): ?string; */ public function getCreatedMessage(bool $short = false): TranslatableMessage; - /** - * Gets the entity identifier. - */ - public function getId(): ?int; - /** * Gets the updated date. */ diff --git a/src/Model/CustomerInformation.php b/src/Model/CustomerInformation.php index 94fac486d..66f075a85 100644 --- a/src/Model/CustomerInformation.php +++ b/src/Model/CustomerInformation.php @@ -13,8 +13,6 @@ namespace App\Model; -use Symfony\Contracts\Translation\TranslatorInterface; - /** * Contains information about the customer. */ @@ -22,7 +20,6 @@ class CustomerInformation { private ?string $address = null; private ?string $email = null; - private ?string $fax = null; private ?string $name = null; private ?string $phone = null; private bool $printAddress = false; @@ -45,14 +42,6 @@ public function getEmail(): ?string return $this->email; } - /** - * Gets the fax number. - */ - public function getFax(): ?string - { - return $this->fax; - } - /** * Gets the name. */ @@ -69,44 +58,6 @@ public function getPhone(): ?string return $this->phone; } - /** - * Gets the translated fax number. - */ - public function getTranslatedFax(?object $translator = null): string - { - $fax = $this->fax ?? ''; - if ('' === $fax) { - return $fax; - } - if ($translator instanceof TranslatorInterface) { - return $translator->trans('report.fax', ['{0}' => $fax]); - } - if (null !== $translator && \method_exists($translator, 'trans')) { - return (string) $translator->trans('report.fax', ['{0}' => $fax]); - } - - return "Fax: $fax"; - } - - /** - * Gets the translated phone number. - */ - public function getTranslatedPhone(?object $translator = null): string - { - $phone = $this->phone ?? ''; - if ('' === $phone) { - return $phone; - } - if ($translator instanceof TranslatorInterface) { - return $translator->trans('report.phone', ['{0}' => $phone]); - } - if (null !== $translator && \method_exists($translator, 'trans')) { - return (string) $translator->trans('report.phone', ['{0}' => $phone]); - } - - return "Phone: $phone"; - } - /** * Gets the url. */ @@ -151,16 +102,6 @@ public function setEmail(?string $email): self return $this; } - /** - * Sets the fax number. - */ - public function setFax(?string $fax): self - { - $this->fax = $fax; - - return $this; - } - /** * Sets the name. */ diff --git a/src/Parameter/CustomerParameter.php b/src/Parameter/CustomerParameter.php index e4f3e1303..969e0d150 100644 --- a/src/Parameter/CustomerParameter.php +++ b/src/Parameter/CustomerParameter.php @@ -28,8 +28,17 @@ class CustomerParameter implements ParameterInterface #[Parameter('customer_email')] private ?string $email = null; - #[Parameter('customer_fax')] - private ?string $fax = null; + #[Assert\Url] + #[Parameter('customer_facebook')] + private ?string $facebook = null; + + #[Assert\Url] + #[Parameter('customer_instagram')] + private ?string $instagram = null; + + #[Assert\Url] + #[Parameter('customer_linkedin')] + private ?string $linkedin = null; #[Assert\NotBlank] #[Parameter('customer_name')] @@ -38,6 +47,7 @@ class CustomerParameter implements ParameterInterface #[Parameter('customer_phone')] private ?string $phone = null; + #[Assert\Url] #[Parameter('customer_url')] private ?string $url = null; @@ -59,9 +69,19 @@ public function getEmail(): ?string return $this->email; } - public function getFax(): ?string + public function getFacebook(): ?string + { + return $this->facebook; + } + + public function getInstagram(): ?string { - return $this->fax; + return $this->instagram; + } + + public function getLinkedin(): ?string + { + return $this->linkedin; } public function getName(): ?string @@ -98,9 +118,23 @@ public function setEmail(?string $email): self return $this; } - public function setFax(?string $fax): self + public function setFacebook(?string $facebook): self + { + $this->facebook = $facebook; + + return $this; + } + + public function setInstagram(?string $instagram): self + { + $this->instagram = $instagram; + + return $this; + } + + public function setLinkedin(?string $linkedin): self { - $this->fax = $fax; + $this->linkedin = $linkedin; return $this; } diff --git a/src/Pdf/Html/AbstractHtmlChunk.php b/src/Pdf/Html/AbstractHtmlChunk.php index 2f737b143..9f872c0cd 100644 --- a/src/Pdf/Html/AbstractHtmlChunk.php +++ b/src/Pdf/Html/AbstractHtmlChunk.php @@ -62,8 +62,11 @@ abstract class AbstractHtmlChunk * @param ?HtmlParentChunk $parent the parent chunk * @param ?string $className the class name */ - public function __construct(private readonly string $name, ?HtmlParentChunk $parent = null, ?string $className = null) - { + public function __construct( + private readonly string $name, + ?HtmlParentChunk $parent = null, + ?string $className = null + ) { $parent?->add($this); $this->setClassName($className); } diff --git a/src/Pdf/Html/AbstractHtmlListChunk.php b/src/Pdf/Html/AbstractHtmlListChunk.php index d202c2e87..b0e17bdce 100644 --- a/src/Pdf/Html/AbstractHtmlListChunk.php +++ b/src/Pdf/Html/AbstractHtmlListChunk.php @@ -18,6 +18,12 @@ */ abstract class AbstractHtmlListChunk extends HtmlParentChunk { + /** + * Adds a child to this collection of children. + * + * Do nothing if the child is already in this collection, + * or if the child is not an instance of HtmlLiChunk + */ public function add(AbstractHtmlChunk $child): static { if ($child instanceof HtmlLiChunk) { diff --git a/src/Pdf/Html/HtmlListType.php b/src/Pdf/Html/HtmlListType.php index c9d8a1609..b2cc84e24 100644 --- a/src/Pdf/Html/HtmlListType.php +++ b/src/Pdf/Html/HtmlListType.php @@ -14,31 +14,35 @@ namespace App\Pdf\Html; /** - * Lists type enumeration. + * Ordered list type enumeration. * * @see HtmlOlChunk */ enum HtmlListType: string { - /* + /** * Numbered list with lowercase letters. */ case LETTER_LOWER = 'a'; - /* + + /** * Numbered list with uppercase letters. */ case LETTER_UPPER = 'A'; - /* + + /** * Numbered list with numbers (default). */ case NUMBER = '1'; - /* + + /** * Numbered list with lowercase roman numbers. * * N.B.: Allowed value must be in range from 1 to 3999 (inclusive). */ case ROMAN_LOWER = 'i'; - /* + + /** * Numbered list with uppercase roman numbers. * * N.B.: Allowed value must be in range from 1 to 3999 (inclusive). @@ -52,13 +56,11 @@ enum HtmlListType: string * @param string $suffix the suffix to append * * @return string the bullet text or an empty string if the number is not positive + * + * @psalm-param positive-int $number */ public function getBulletText(int $number, string $suffix = '.'): string { - if ($number <= 0) { - return ''; - } - return match ($this) { HtmlListType::LETTER_LOWER => $this->toLetterLower($number, $suffix) , HtmlListType::LETTER_UPPER => $this->toLetterUpper($number, $suffix), diff --git a/src/Pdf/Html/HtmlOlChunk.php b/src/Pdf/Html/HtmlOlChunk.php index c47dbf185..80149ac72 100644 --- a/src/Pdf/Html/HtmlOlChunk.php +++ b/src/Pdf/Html/HtmlOlChunk.php @@ -15,6 +15,8 @@ /** * A specialized chunk for the HTML ordered list (ol). + * + * @see HtmlListType */ class HtmlOlChunk extends AbstractHtmlListChunk { @@ -42,6 +44,8 @@ public function getBulletText(HtmlLiChunk $chunk): string /** * Gets the start counting. + * + * @psalm-return positive-int */ public function getStart(): int { @@ -63,7 +67,7 @@ public function getType(): HtmlListType */ public function setStart(int $start): self { - $this->start = \max($start, 1); + $this->start = $start; return $this; } diff --git a/src/Pdf/Html/HtmlParser.php b/src/Pdf/Html/HtmlParser.php index 8ba7bba8e..f5c314cad 100644 --- a/src/Pdf/Html/HtmlParser.php +++ b/src/Pdf/Html/HtmlParser.php @@ -67,13 +67,13 @@ private function createLiChunk(string $name, HtmlParentChunk $parent, ?string $c private function createOlChunk(string $name, HtmlParentChunk $parent, ?string $className, \DOMNode $node): HtmlOlChunk { - $type = HtmlAttribute::LIST_TYPE->getEnumValue($node, HtmlListType::NUMBER); /** @psalm-var positive-int $start */ $start = HtmlAttribute::LIST_START->getIntValue($node, 1); + $type = HtmlAttribute::LIST_TYPE->getEnumValue($node, HtmlListType::NUMBER); $chunk = new HtmlOlChunk($name, $parent, $className); - return $chunk->setType($type) - ->setStart($start); + return $chunk->setStart($start) + ->setType($type); } private function createPageBreakChunk(string $name, HtmlParentChunk $parent): HtmlParentChunk diff --git a/src/Pdf/Html/HtmlStyle.php b/src/Pdf/Html/HtmlStyle.php index 22b45f3b4..4c75f6fd6 100644 --- a/src/Pdf/Html/HtmlStyle.php +++ b/src/Pdf/Html/HtmlStyle.php @@ -122,12 +122,20 @@ public function getTopMargin(): float public function reset(): static { parent::reset(); - $this->resetMargins(); - $this->setAlignment(PdfTextAlignment::LEFT); + $this->resetAlignment() + ->resetMargins(); return $this; } + /** + * Sets alignement to default (left). + */ + public function resetAlignment(): self + { + return $this->setAlignment(PdfTextAlignment::LEFT); + } + /** * Sets all four margins to 0. */ diff --git a/src/Report/LogsReport.php b/src/Report/LogsReport.php index e2d3c91d7..718a41234 100644 --- a/src/Report/LogsReport.php +++ b/src/Report/LogsReport.php @@ -210,9 +210,7 @@ private function renderCards(): void $textCells[] = new PdfCell($total); $valueCells[] = new PdfCell(FormatUtils::formatInt($this->logFile->count())); - $level = $this->trans('log.fields.level'); - $chanel = $this->trans('log.fields.channel'); - $this->addBookmark(\sprintf('%s - %s', $level, $chanel)); + $this->addBookmark(text: $this->trans('calculation.edit.panel_resume'), isUTF8: true, currentY: false); $levelsCount = \max(1, \count($levels) * 2); $channelsCount = \count($channels) * 2 + 1; @@ -223,8 +221,8 @@ private function renderCards(): void PdfTable::instance($this) ->addColumns(...$columns) ->startRow() - ->add($level, $levelsCount, $titleStyle, PdfTextAlignment::LEFT) - ->add($chanel, $channelsCount, $titleStyle, PdfTextAlignment::LEFT) + ->add($this->trans('log.fields.level'), $levelsCount, $titleStyle, PdfTextAlignment::LEFT) + ->add($this->trans('log.fields.channel'), $channelsCount, $titleStyle, PdfTextAlignment::LEFT) ->endRow() ->addStyledRow($textCells, PdfStyle::getHeaderStyle()->resetFont()) ->addStyledRow($valueCells, PdfStyle::getCellStyle()->setFontSize(14)); diff --git a/src/Report/ReportHeader.php b/src/Report/ReportHeader.php index 499b2a743..7df6d32bd 100644 --- a/src/Report/ReportHeader.php +++ b/src/Report/ReportHeader.php @@ -164,13 +164,13 @@ private function isPrintAddress(): bool private function outputAddress(float $width): void { $this->applySmallStyle(); - $text = $this->customer?->getAddress(); $this->outputText( $width, self::SMALL_HEIGHT, - $text, + $this->customer?->getAddress(), PdfBorder::none(), - PdfTextAlignment::LEFT + PdfTextAlignment::RIGHT, + PdfMove::NEW_LINE ); } @@ -184,75 +184,15 @@ private function outputDescription(): void $this->parent->multiCell(height: self::SMALL_HEIGHT, text: $description, align: PdfTextAlignment::LEFT); } - private function outputEmail(float $width): void - { - $this->applySmallStyle(); - $text = $this->customer?->getEmail() ?? ''; - $link = '' === $text ? null : "mailto:$text"; - $this->outputText( - $width, - self::SMALL_HEIGHT, - $text, - PdfBorder::bottom(), - PdfTextAlignment::RIGHT, - PdfMove::NEW_LINE, - $link - ); - } - - private function outputFax(float $width): void - { - $this->applySmallStyle(); - $text = $this->customer?->getTranslatedFax($this->parent); - $this->outputText( - $width, - self::SMALL_HEIGHT, - $text, - PdfBorder::none(), - PdfTextAlignment::RIGHT, - PdfMove::NEW_LINE - ); - } - - private function outputLine1(float $printableWidth, bool $isAddress): void - { - if ($isAddress) { - // customer name + title + phone - $cellWidth = $printableWidth / 3.0; - $this->outputName($cellWidth, true); - $this->outputTitle($cellWidth, true); - $this->outputPhone($cellWidth); - } else { - // title + customer name - $cellWidth = $printableWidth / 2.0; - $this->outputTitle($cellWidth, false); - $this->outputName($cellWidth, false); - } - } - - private function outputLine2(float $printableWidth): void - { - $cellWidth = $printableWidth / 2.0; - $this->outputAddress($cellWidth); - $this->outputFax($cellWidth); - } - - private function outputLine3(float $printableWidth): void - { - $cellWidth = $printableWidth / 2.0; - $this->outputZipCity($cellWidth); - $this->outputEmail($cellWidth); - } - private function outputLines(): void { $parent = $this->parent; $isAddress = $this->isPrintAddress(); $printableWidth = $parent->getPrintableWidth(); - $this->outputLine1($printableWidth, $isAddress); + $this->outputTitleAndName($printableWidth, $isAddress); if ($isAddress) { - $this->outputLine2($printableWidth); - $this->outputLine3($printableWidth); + $this->outputAddress($printableWidth); + $this->outputZipCity($printableWidth); } $this->outputDescription(); $parent->resetStyle()->lineBreak(2); @@ -261,33 +201,16 @@ private function outputLines(): void private function outputName(float $width, bool $isAddress): void { $this->applyNameStyle(); - $name = $this->customer?->getName(); - $link = $this->customer?->getUrl() ?? null; - $align = $isAddress ? PdfTextAlignment::LEFT : PdfTextAlignment::RIGHT; $border = $isAddress ? PdfBorder::none() : PdfBorder::bottom(); - $move = $isAddress ? PdfMove::RIGHT : PdfMove::NEW_LINE; + $move = $isAddress ? PdfMove::NEW_LINE : PdfMove::BELOW; $this->outputText( $width, self::LINE_HEIGHT, - $name, + $this->customer?->getName(), $border, - $align, - $move, - $link - ); - } - - private function outputPhone(float $width): void - { - $this->applySmallStyle(); - $text = $this->customer?->getTranslatedPhone($this->parent); - $this->outputText( - $width, - self::SMALL_HEIGHT, - $text, - PdfBorder::none(), PdfTextAlignment::RIGHT, - PdfMove::NEW_LINE + $move, + $this->customer?->getUrl() ); } @@ -314,28 +237,34 @@ private function outputText( private function outputTitle(float $width, bool $isAddress): void { $this->applyTitleStyle(); - $title = $this->parent->getTitle(); - $align = $isAddress ? PdfTextAlignment::CENTER : PdfTextAlignment::LEFT; $border = $isAddress ? PdfBorder::none() : PdfBorder::bottom(); $this->outputText( $width, self::LINE_HEIGHT, - $title, + $this->parent->getTitle(), $border, - $align + PdfTextAlignment::LEFT, ); } + private function outputTitleAndName(float $printableWidth, bool $isAddress): void + { + // title + customer name + $cellWidth = $printableWidth / 2.0; + $this->outputTitle($cellWidth, $isAddress); + $this->outputName($cellWidth, $isAddress); + } + private function outputZipCity(float $width): void { $this->applySmallStyle(); - $text = $this->customer?->getZipCity(); $this->outputText( $width, self::SMALL_HEIGHT, - $text, + $this->customer?->getZipCity(), PdfBorder::bottom(), - PdfTextAlignment::LEFT + PdfTextAlignment::RIGHT, + PdfMove::NEW_LINE ); } } diff --git a/src/Service/ApplicationService.php b/src/Service/ApplicationService.php index a0b291beb..746f299a2 100644 --- a/src/Service/ApplicationService.php +++ b/src/Service/ApplicationService.php @@ -93,7 +93,6 @@ public function getCustomer(): CustomerInformation ->setAddress($this->getCustomerAddress()) ->setZipCity($this->getCustomerZipCity()) ->setPhone($this->getCustomerPhone()) - ->setFax($this->getCustomerFax()) ->setEmail($this->getCustomerEmail()) ->setUrl($this->getCustomerUrl()) ->setPrintAddress($this->isPrintAddress()); @@ -117,14 +116,6 @@ public function getCustomerEmail(): ?string return $this->getPropertyString(self::P_CUSTOMER_EMAIL); } - /** - * Gets the customer fax number. - */ - public function getCustomerFax(): ?string - { - return $this->getPropertyString(self::P_CUSTOMER_FAX); - } - /** * Gets the customer name. */ @@ -331,7 +322,6 @@ public function getProperties(bool $updateAdapter = true): array self::P_CUSTOMER_ADDRESS => $this->getCustomerAddress(), self::P_CUSTOMER_ZIP_CITY => $this->getCustomerZipCity(), self::P_CUSTOMER_PHONE => $this->getCustomerPhone(), - self::P_CUSTOMER_FAX => $this->getCustomerFax(), self::P_CUSTOMER_EMAIL => $this->getCustomerEmail(), self::P_CUSTOMER_URL => $this->getCustomerUrl(), // security diff --git a/src/Spreadsheet/HeaderFooter.php b/src/Spreadsheet/HeaderFooter.php index 41a2d3c7d..6674e0f82 100644 --- a/src/Spreadsheet/HeaderFooter.php +++ b/src/Spreadsheet/HeaderFooter.php @@ -43,14 +43,19 @@ class HeaderFooter // the date and time format private const DATE_AND_TIME = '&D - &T'; + // the initial font size private const INITIAL_FONT_SIZE = 11; + // the page/pages format private const PAGE_AND_PAGES = 'Page &P / &N'; + // the center text private string $centerText = ''; + // the left text private string $leftText = ''; + // the right text private string $rightText = ''; diff --git a/src/Spreadsheet/SpreadsheetDocument.php b/src/Spreadsheet/SpreadsheetDocument.php index b83221090..bd0ae7e9b 100644 --- a/src/Spreadsheet/SpreadsheetDocument.php +++ b/src/Spreadsheet/SpreadsheetDocument.php @@ -122,7 +122,7 @@ public function createSheetAndTitle( $customer = $controller->getUserService()->getCustomer(); return $sheet->setPrintGridlines(true) - ->updateHeaderFooter($customer, $this->translator); + ->updateHeaderFooter($customer); } /** @@ -230,7 +230,7 @@ public function setActiveTitle(string $title, ?AbstractController $controller = ->setTitle($title); if ($controller instanceof AbstractController) { $customer = $controller->getUserService()->getCustomer(); - $sheet->updateHeaderFooter($customer, $this->getTranslator()); + $sheet->updateHeaderFooter($customer); } return $this; @@ -360,7 +360,7 @@ protected function initialize(AbstractController $controller, string $title, boo $sheet = $this->getActiveSheet() ->setPrintGridlines(true) ->setTitle($title) - ->updateHeaderFooter($customer, $this->translator); + ->updateHeaderFooter($customer); if ($landscape) { $sheet->setPageLandscape(); } diff --git a/src/Spreadsheet/WorksheetDocument.php b/src/Spreadsheet/WorksheetDocument.php index 8001786eb..f1055d82c 100644 --- a/src/Spreadsheet/WorksheetDocument.php +++ b/src/Spreadsheet/WorksheetDocument.php @@ -26,7 +26,6 @@ use PhpOffice\PhpSpreadsheet\Worksheet\Drawing; use PhpOffice\PhpSpreadsheet\Worksheet\PageSetup; use PhpOffice\PhpSpreadsheet\Worksheet\Worksheet; -use Symfony\Contracts\Translation\TranslatorInterface; /** * Extends the worksheet class with shortcuts to render cells. @@ -486,7 +485,7 @@ public function setPageLandscape(): static } /** - * Set the page orientation (default, portait or landscape). + * Set the page orientation (default, portait, or landscape). * * @psalm-param PageSetup::ORIENTATION_* $orientation */ @@ -597,34 +596,26 @@ public function stringFromColumnIndex(int $columnIndex): string /** * Update this header and footer with the given customer information. */ - public function updateHeaderFooter(CustomerInformation $customer, ?TranslatorInterface $translator = null): static + public function updateHeaderFooter(CustomerInformation $customer): static { - $title = $this->getTitle(); - $pageMargins = $this->getPageMargins(); + $pageMargins = $this->getPageMargins() + ->setTop(self::HEADER_FOOTER_MARGIN) + ->setBottom(self::HEADER_FOOTER_MARGIN); + + $header = HeaderFooter::header() + ->addLeft($this->getTitle(), true) + ->addRight($customer->getName(), true); if ($customer->isPrintAddress()) { - HeaderFooter::header() - ->addLeft($customer->getName(), true) - ->addLeft($customer->getAddress()) - ->addLeft($customer->getZipCity()) - ->addCenter($title, true) - ->addRight($customer->getTranslatedPhone($translator)) - ->addRight($customer->getTranslatedFax($translator)) - ->addRight($customer->getEmail()) - ->apply($this); + $header->addRight($customer->getAddress()) + ->addRight($customer->getZipCity()); $pageMargins->setTop(self::HEADER_CUSTOMER_MARGIN); - } else { - HeaderFooter::header() - ->addLeft($title, true) - ->addRight($customer->getName(), true) - ->apply($this); - $pageMargins->setTop(self::HEADER_FOOTER_MARGIN); } + $header->apply($this); HeaderFooter::footer() ->addPages() ->addDateTime() ->apply($this); - $pageMargins->setBottom(self::HEADER_FOOTER_MARGIN); return $this; } diff --git a/src/Traits/TimestampableTrait.php b/src/Traits/TimestampableTrait.php index ea6ac7873..525b8baec 100644 --- a/src/Traits/TimestampableTrait.php +++ b/src/Traits/TimestampableTrait.php @@ -68,7 +68,7 @@ public function getCreatedMessage(bool $short = false): TranslatableMessage { $date = $this->getDateMessage($this->createdAt); $user = $this->getUserMessage($this->createdBy); - $id = $short ? 'common.entity_created_short' : 'common.entity_created'; + $id = $short ? 'common.entity_created_short' : 'common.entity_created_long'; return new TranslatableMessage($id, ['%date%' => $date, '%user%' => $user]); } @@ -87,7 +87,7 @@ public function getUpdatedMessage(bool $short = false): TranslatableMessage { $date = $this->getDateMessage($this->updatedAt); $user = $this->getUserMessage($this->updatedBy); - $id = $short ? 'common.entity_updated_short' : 'common.entity_updated'; + $id = $short ? 'common.entity_updated_short' : 'common.entity_updated_long'; return new TranslatableMessage($id, ['%date%' => $date, '%user%' => $user]); } diff --git a/src/Twig/FunctionExtension.php b/src/Twig/FunctionExtension.php index e043426a9..43109fb5b 100644 --- a/src/Twig/FunctionExtension.php +++ b/src/Twig/FunctionExtension.php @@ -205,9 +205,6 @@ private function getRealPath(?string $path): ?string if (false === $file) { return null; } - if (!FileUtils::isFile($file)) { - return null; - } return FileUtils::normalize($file); } diff --git a/src/Utils/FileUtils.php b/src/Utils/FileUtils.php index 5b83d7364..149ff0ead 100644 --- a/src/Utils/FileUtils.php +++ b/src/Utils/FileUtils.php @@ -215,16 +215,11 @@ public static function getLinesCount(string $filename, bool $skipEmpty = true): if ($skipEmpty) { $flags |= \SplFileObject::READ_AHEAD | \SplFileObject::SKIP_EMPTY; } + $file = new \SplFileObject($filename, 'r'); + $file->setFlags($flags); + $file->seek(\PHP_INT_MAX); - try { - $file = new \SplFileObject($filename, 'r'); - $file->setFlags($flags); - $file->seek(\PHP_INT_MAX); - - return $file->key(); - } catch (\Exception) { - return 0; - } + return $file->key(); } /** diff --git a/src/Word/WordHeader.php b/src/Word/WordHeader.php index 3a5249931..38f4af0dc 100644 --- a/src/Word/WordHeader.php +++ b/src/Word/WordHeader.php @@ -27,7 +27,7 @@ *
    *
  • The customer's name at the left and the address if applicable.
  • *
  • The document's title at the center, if applicable; at the right else.
  • - *
  • The phone, the fax and the email at the right if applicable.
  • + *
  • The phone and the email at the right if applicable.
  • *
* * Do nothing if both the document's title and the customer's name are empty. @@ -42,6 +42,8 @@ public function output(Section $section): void { $title = $this->getTitle() ?? ''; $name = $this->customer?->getName() ?? ''; + $url = $this->customer?->getUrl(); + if ('' === $title && '' === $name) { return; } @@ -49,17 +51,17 @@ public function output(Section $section): void $row = $section->addHeader() ->addTable(['borderBottomSize' => 1]) ->addRow(); + + $cell = $this->outputTitleAndName($row, $title, $name, $url); if ($this->printAddress) { - $this->outputAddress($row, $title, $name); - } else { - $this->outputDefault($row, $title, $name); + $this->outputAddress($cell); } } /** * Set the customer information. */ - public function setCustomer(?CustomerInformation $customer): self + public function setCustomer(CustomerInformation $customer): self { $this->customer = $customer; @@ -76,25 +78,8 @@ public function setPrintAddress(bool $printAddress): self return $this; } - private function addEmail(Cell $cell, array $cellStyle, array $textStyle): void - { - $email = $this->customer?->getEmail() ?? ''; - if ('' !== $email) { - $cell->addLink("mailto:$email", $email, $cellStyle, $textStyle); - } else { - $cell->addText($email, $cellStyle, $textStyle); - } - } - - private function addFax(Cell $cell, array $cellStyle, array $textStyle): void - { - $text = $this->customer?->getTranslatedFax($this->getTranslator()) ?? ''; - $cell->addText($text, $cellStyle, $textStyle); - } - - private function addName(Cell $cell, string $name, array $cellStyle, array $textStyle): void + private function addName(Cell $cell, string $name, ?string $url, array $cellStyle, array $textStyle): void { - $url = $this->customer?->getUrl(); if (null !== $url) { $cell->addLink($url, $name, $cellStyle, $textStyle); } else { @@ -102,66 +87,36 @@ private function addName(Cell $cell, string $name, array $cellStyle, array $text } } - private function addPhone(Cell $cell, array $cellStyle, array $textStyle): void - { - $text = $this->customer?->getTranslatedPhone($this->getTranslator()) ?? ''; - $cell->addText($text, $cellStyle, $textStyle); - } - - private function outputAddress(Row $row, string $title, string $name): void + private function outputAddress(Cell $cell): void { - $width = self::TOTAL_WIDTH / 3; $spaceAfter = Converter::pointToTwip(3); - $cellStyle = ['size' => 8, 'bold' => true]; - $textStyle = ['spaceBefore' => 0, 'spaceAfter' => 0, 'alignment' => Jc::START]; + $cellStyle = ['size' => 8, 'bold' => false]; + $textStyle = ['spaceBefore' => 0, 'spaceAfter' => 0, 'alignment' => Jc::END]; - // name - $cell = $row->addCell($width); - $this->addName($cell, $name, $cellStyle, $textStyle); // address - $cellStyle['bold'] = false; - $text = $this->customer?->getAddress() ?? ''; - $cell->addText($text, $cellStyle, $textStyle); - // zip and city - $textStyle['spaceAfter'] = $spaceAfter; - $text = $this->customer?->getZipCity() ?? ''; - $cell->addText($text, $cellStyle, $textStyle); - - // title - $cellStyle['bold'] = true; - $cellStyle['size'] = 10; - $textStyle['alignment'] = Jc::CENTER; - $textStyle['spaceAfter'] = 0; - $cell = $row->addCell($width); - $cell->addText($title, $cellStyle, $textStyle); + $cell->addText($this->customer?->getAddress() ?? '', $cellStyle, $textStyle); - // phone - $cellStyle['bold'] = false; - $cellStyle['size'] = 8; - $textStyle['alignment'] = Jc::END; - $cell = $row->addCell($width); - $this->addPhone($cell, $cellStyle, $textStyle); - // fax - $this->addFax($cell, $cellStyle, $textStyle); - // email + // zip and city $textStyle['spaceAfter'] = $spaceAfter; - $this->addEmail($cell, $cellStyle, $textStyle); + $cell->addText($this->customer?->getZipCity() ?? '', $cellStyle, $textStyle); } - private function outputDefault(Row $row, string $title, string $name): void + private function outputTitleAndName(Row $row, string $title, string $name, ?string $url): Cell { $width = self::TOTAL_WIDTH / 2; $cellStyle = ['size' => 10, 'bold' => true]; - $textStyle = ['spaceBefore' => 0, 'spaceAfter' => Converter::pointToTwip(3)]; + $textStyle = ['spaceBefore' => 0, 'spaceAfter' => 0, 'alignment' => Jc::START]; // title - $textStyle['alignment'] = Jc::START; $cell = $row->addCell($width); $cell->addText($title, $cellStyle, $textStyle); // name + $cellStyle['size'] = 8; $textStyle['alignment'] = Jc::END; $cell = $row->addCell($width); - $this->addName($cell, $name, $cellStyle, $textStyle); + $this->addName($cell, $name, $url, $cellStyle, $textStyle); + + return $cell; } } diff --git a/templates/calculation/calculation_edit_panel_totals.html.twig b/templates/calculation/calculation_edit_panel_totals.html.twig index bdd6f43b9..05d2e10bf 100644 --- a/templates/calculation/calculation_edit_panel_totals.html.twig +++ b/templates/calculation/calculation_edit_panel_totals.html.twig @@ -12,7 +12,9 @@ - + {% if not new %} + + {% endif %} diff --git a/templates/macros/_timestampable.html.twig b/templates/macros/_timestampable.html.twig index cfe693d3d..bafd06794 100644 --- a/templates/macros/_timestampable.html.twig +++ b/templates/macros/_timestampable.html.twig @@ -1,27 +1,19 @@ {# create timestampable row #} {% macro timestampable_footer(item, separator = true) %} -{% if not item.new %} - {% if not item.createdAt and not item.createdBy %} - {% set created = 'common.entity_created_empty'|trans %} - {% else %} + {% if not item.new %} {% set created = item.createdMessage(false)|trans %} - {% endif %} - {% if not item.updatedAt and not item.updatedBy %} - {% set updated = 'common.entity_updated_empty'|trans %} - {% else %} {% set updated = item.updatedMessage(false)|trans %} + {% if separator %} + + {% endif %} +
+ {{- created -}}{{- updated -}} +
{% endif %} - {% if separator %} - - {% endif %} -
- {{- created -}}{{- updated -}} -
-{% endif %} {% endmacro %} {% macro timestampable_properties(item) -%} -{% from 'macros/_properties.html.twig' import property %} -{{ property('calculation.fields.created', item.createdMessage(true)|trans) }} -{{ property('calculation.fields.updated', item.updatedMessage(true)|trans) }} + {% from 'macros/_properties.html.twig' import property %} + {{ property('calculation.fields.created', item.createdMessage(true)|trans) }} + {{ property('calculation.fields.updated', item.updatedMessage(true)|trans) }} {%- endmacro %} diff --git a/templates/parameters/_parameters_customer.html.twig b/templates/parameters/_parameters_customer.html.twig index c11e0c9c5..5e948c7c7 100644 --- a/templates/parameters/_parameters_customer.html.twig +++ b/templates/parameters/_parameters_customer.html.twig @@ -3,10 +3,7 @@ {{ form_row(form.customer_address) }} {{ form_row(form.customer_zip_city) }}
-
{{ form_row(form.customer_phone) }}
-
{{ form_row(form.customer_fax) }}
-
-
-
{{ form_row(form.customer_email) }}
-
{{ form_row(form.customer_url) }}
+
{{ form_row(form.customer_phone) }}
+
{{ form_row(form.customer_email) }}
+
{{ form_row(form.customer_url) }}
diff --git a/templates/test/parameter.html.twig b/templates/test/parameter.html.twig index 7e769cabd..2a363403c 100644 --- a/templates/test/parameter.html.twig +++ b/templates/test/parameter.html.twig @@ -8,10 +8,12 @@ {% block _message_progress_widget -%}
{{- block('choice_widget') -}} - - {% set types = enum_cases('App\\Enums\\FlashType') %}