Feat: Make fees editable, duplicatable and add internal name

This commit is contained in:
Björn Fromme
2023-10-20 16:35:56 +02:00
parent 992bdcc46c
commit 9e9608e604
9 changed files with 205 additions and 5 deletions
+31
View File
@@ -0,0 +1,31 @@
<?php
declare(strict_types=1);
namespace DoctrineMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20231020142152 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$this->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');
}
}
@@ -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);
@@ -0,0 +1,56 @@
<?php
namespace App\Controller\Admin\System\Fee;
use App\Entity\Fee;
use App\Form\FeeType;
use App\Model\AjaxModalResponseDto;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class DuplicateController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/admin/system/fee/duplicate/{id}', name: 'app_admin_system_fee_duplicate')]
#[IsGranted('ROLE_ADMIN')]
public function index(Fee $fee, Request $request): JsonResponse
{
$copy = Fee::duplicate($fee);
$response = new AjaxModalResponseDto();
$action = $this->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);
}
}
@@ -0,0 +1,53 @@
<?php
namespace App\Controller\Admin\System\Fee;
use App\Entity\Fee;
use App\Form\FeeType;
use App\Model\AjaxModalResponseDto;
use Doctrine\ORM\EntityManagerInterface;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Attribute\IsGranted;
class EditController extends AbstractController
{
public function __construct(
private readonly EntityManagerInterface $entityManager,
private readonly LoggerInterface $logger
) {
}
#[Route('/admin/system/fee/edit/{id}', name: 'app_admin_system_fee_edit')]
#[IsGranted('ROLE_ADMIN')]
public function index(Fee $fee, Request $request): JsonResponse
{
$response = new AjaxModalResponseDto();
$action = $this->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);
}
}
+28
View File
@@ -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;
}
}
+7 -1
View File
@@ -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,
])
+4 -1
View File
@@ -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',
@@ -1,6 +1,7 @@
{{ form_start(form) }}
<div class="flex flex-col space-y-4 pb-8">
{{ form_row(form.name) }}
{{ form_row(form.nameInternal) }}
{{ form_row(form.value) }}
</div>
<button type="submit" class="btn">
+23 -1
View File
@@ -12,7 +12,10 @@
<thead>
<tr>
<th>
Bezeichnung
Bezeichnung öffentlich
</th>
<th>
Bezeichnung intern
</th>
<th>
Wert
@@ -26,6 +29,9 @@
<td>
{{ fee.name }}
</td>
<td>
{{ fee.nameInternal|default('-') }}
</td>
<td>
{{ fee.value|format_money }}
</td>
@@ -41,6 +47,22 @@
}) }}>
{{ icon('delete') }}
</button>
<button type="button"
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
{{ stimulus_action('modal-button', 'ajax', null, {
'title': 'Honorar bearbeiten',
'url': path('app_admin_system_fee_edit', { 'id': fee.id })
}) }}>
{{ icon('edit') }}
</button>
<button type="button"
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
{{ stimulus_action('modal-button', 'ajax', null, {
'title': 'Honorar duplizieren',
'url': path('app_admin_system_fee_duplicate', { 'id': fee.id })
}) }}>
{{ icon('copy') }}
</button>
</div>
</td>
</tr>