Feat: Make fees editable, duplicatable and add internal name
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user