diff --git a/migrations/Version20231020142152.php b/migrations/Version20231020142152.php new file mode 100644 index 0000000..0d3743c --- /dev/null +++ b/migrations/Version20231020142152.php @@ -0,0 +1,31 @@ +addSql('ALTER TABLE fee ADD name_internal VARCHAR(255) NOT NULL'); + } + + public function down(Schema $schema): void + { + // this down() migration is auto-generated, please modify it to your needs + $this->addSql('ALTER TABLE fee DROP name_internal'); + } +} diff --git a/src/Controller/Admin/System/Fee/CreateController.php b/src/Controller/Admin/System/Fee/CreateController.php index 016453c..b76d5fb 100644 --- a/src/Controller/Admin/System/Fee/CreateController.php +++ b/src/Controller/Admin/System/Fee/CreateController.php @@ -38,13 +38,13 @@ class CreateController extends AbstractController $this->addFlash('success', 'Das Honorar wurde angelegt'); $this->logger->info('Create fee', [ - 'fee' => $fee->getName(), + 'fee' => $fee->getNameInternal(), ]); $redirectUrl = $this->generateUrl('app_admin_system_fee_index'); $response->setCloseAndRedirect($redirectUrl); } else { - $content = $this->renderView('admin/system/fee/create.html.twig', [ + $content = $this->renderView('admin/system/fee/form.html.twig', [ 'form' => $form ]); $response->setContent($content); diff --git a/src/Controller/Admin/System/Fee/DuplicateController.php b/src/Controller/Admin/System/Fee/DuplicateController.php new file mode 100644 index 0000000..8dc0dcd --- /dev/null +++ b/src/Controller/Admin/System/Fee/DuplicateController.php @@ -0,0 +1,56 @@ +generateUrl('app_admin_system_fee_duplicate', ['id' => $fee->getId()]); + + $form = $this->createForm(FeeType::class, $copy, ['action' => $action, 'ajax_submit' => true]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->persist($copy); + $this->entityManager->flush(); + + $this->addFlash('success', 'Das Honorar wurde dupliziert'); + $this->logger->info('Duplicate fee', [ + 'fee' => $fee->getNameInternal(), + ]); + + $redirectUrl = $this->generateUrl('app_admin_system_fee_index'); + $response->setCloseAndRedirect($redirectUrl); + } else { + $content = $this->renderView('admin/system/fee/form.html.twig', [ + 'form' => $form + ]); + $response->setContent($content); + } + + return $this->json($response); + } +} \ No newline at end of file diff --git a/src/Controller/Admin/System/Fee/EditController.php b/src/Controller/Admin/System/Fee/EditController.php new file mode 100644 index 0000000..283f309 --- /dev/null +++ b/src/Controller/Admin/System/Fee/EditController.php @@ -0,0 +1,53 @@ +generateUrl('app_admin_system_fee_edit', ['id' => $fee->getId()]); + + $form = $this->createForm(FeeType::class, $fee, ['action' => $action, 'ajax_submit' => true]); + $form->handleRequest($request); + + if ($form->isSubmitted() && $form->isValid()) { + $this->entityManager->flush(); + + $this->addFlash('success', 'Das Honorar wurde aktualisiert'); + $this->logger->info('Edit fee', [ + 'fee' => $fee->getNameInternal(), + ]); + + $redirectUrl = $this->generateUrl('app_admin_system_fee_index'); + $response->setCloseAndRedirect($redirectUrl); + } else { + $content = $this->renderView('admin/system/fee/form.html.twig', [ + 'form' => $form + ]); + $response->setContent($content); + } + + return $this->json($response); + } +} \ No newline at end of file diff --git a/src/Entity/Fee.php b/src/Entity/Fee.php index 1d8bdf9..6bbabdb 100644 --- a/src/Entity/Fee.php +++ b/src/Entity/Fee.php @@ -27,6 +27,22 @@ class Fee implements BlameableEntityInterface, TimestampableEntityInterface #[Assert\NotBlank(message: 'Bitte gib die Bezeichnung an')] private ?string $name = null; + #[ORM\Column(length: 255)] + #[Assert\NotBlank(message: 'Bitte gib die interne Bezeichnung an')] + private ?string $nameInternal = null; + + public static function duplicate(Fee $fee): static + { + $instance = new static(); + $instance + ->setName($fee->getName()) + ->setNameInternal($fee->getNameInternal()) + ->setValue($fee->getValue()) + ; + + return $instance; + } + public function getId(): ?int { return $this->id; @@ -55,4 +71,16 @@ class Fee implements BlameableEntityInterface, TimestampableEntityInterface return $this; } + + public function getNameInternal(): ?string + { + return $this->nameInternal; + } + + public function setNameInternal(?string $nameInternal): static + { + $this->nameInternal = $nameInternal; + + return $this; + } } diff --git a/src/Form/AssignmentType.php b/src/Form/AssignmentType.php index ef1c66d..87618d8 100644 --- a/src/Form/AssignmentType.php +++ b/src/Form/AssignmentType.php @@ -71,7 +71,13 @@ class AssignmentType extends AbstractType ->add('fees', EntityType::class, [ 'label' => 'Honorar(e)', 'class' => Fee::class, - 'choice_label' => 'name', + 'choice_label' => function (Fee $fee) { + if (false === empty($fee->getNameInternal())) { + return $fee->getNameInternal(); + } + + return $fee->getName(); + }, 'multiple' => true, 'expanded' => true, ]) diff --git a/src/Form/FeeType.php b/src/Form/FeeType.php index 5a39c7c..a0a8a85 100644 --- a/src/Form/FeeType.php +++ b/src/Form/FeeType.php @@ -15,7 +15,10 @@ class FeeType extends AbstractType { $builder ->add('name', TextType::class, [ - 'label' => 'Bezeichnung', + 'label' => 'Bezeichnung öffentlich', + ]) + ->add('nameInternal', TextType::class, [ + 'label' => 'Bezeichnung intern', ]) ->add('value', MoneyType::class, [ 'label' => 'Wert', diff --git a/templates/admin/system/fee/create.html.twig b/templates/admin/system/fee/form.html.twig similarity index 86% rename from templates/admin/system/fee/create.html.twig rename to templates/admin/system/fee/form.html.twig index 79bd00a..f16a388 100644 --- a/templates/admin/system/fee/create.html.twig +++ b/templates/admin/system/fee/form.html.twig @@ -1,6 +1,7 @@ {{ form_start(form) }}
{{ form_row(form.name) }} + {{ form_row(form.nameInternal) }} {{ form_row(form.value) }}
+ +