wip: functionality for new role 'management'
This commit is contained in:
@@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Event\DocumentRejectedEvent;
|
||||
use App\Form\DocumentCheckType;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use App\Model\DocumentCheckDto;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\DependencyInjection\Attribute\Target;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Component\Workflow\WorkflowInterface;
|
||||
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
|
||||
|
||||
class CheckController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
#[Target('disposition')]
|
||||
private readonly WorkflowInterface $workflow,
|
||||
private readonly EventDispatcherInterface $eventDispatcher,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/document/check/{uuid}', name: 'app_administrative_document_check')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
#[IsGranted('CHECK', subject: 'document')]
|
||||
public function index(Upload $document, Request $request): Response
|
||||
{
|
||||
$formData = new DocumentCheckDto($document);
|
||||
$form = $this->createForm(DocumentCheckType::class, $formData, ['document_type' => $document->getType()]);
|
||||
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
switch ($formData->getStatus()) {
|
||||
case Upload::STATUS_CHECKED:
|
||||
$this->confirmDocument($document, 'confirm_contract', Upload::STATUS_CHECKED);
|
||||
break;
|
||||
case Upload::STATUS_PAID:
|
||||
$this->confirmDocument($document, 'confirm_invoice', Upload::STATUS_PAID);
|
||||
break;
|
||||
case Upload::STATUS_REJECTED:
|
||||
$this->rejectDocument($document, $formData->getComment());
|
||||
$this->eventDispatcher->dispatch(new DocumentRejectedEvent($formData), DocumentRejectedEvent::NAME);
|
||||
default:
|
||||
$document
|
||||
->setStatus($formData->getStatus())
|
||||
->setComment($formData->getComment())
|
||||
;
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Der Status wurde aktualisiert');
|
||||
$this->logger->info('Update document status', [
|
||||
'document_id' => $document->getId(),
|
||||
'document_filename' => $document->getOriginalFilename(),
|
||||
'owner' => $document->getOwner()->getFullName(),
|
||||
'status' => $formData->getStatus(),
|
||||
]);
|
||||
}
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_document_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/document/modal_check.html.twig', [
|
||||
'document' => $document,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function rejectDocument(Upload $document, string $comment = null): void
|
||||
{
|
||||
$document
|
||||
->setStatus(Upload::STATUS_REJECTED)
|
||||
->setComment($comment)
|
||||
;
|
||||
|
||||
$this->addFlash('success', 'Das Dokument wurde abgelehnt');
|
||||
$this->logger->info('Reject document', [
|
||||
'document_id' => $document->getId(),
|
||||
'document_filename' => $document->getOriginalFilename(),
|
||||
'owner' => $document->getOwner()->getFullName(),
|
||||
]);
|
||||
|
||||
$transition = Upload::TYPE_CONTRACT === $document->getType() ? 'reject_contract' : 'reject_invoice';
|
||||
$this->workflow->apply($document->getDisposition(), $transition);
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
||||
private function confirmDocument(Upload $document, string $transition, string $status): void
|
||||
{
|
||||
$document->setStatus($status);
|
||||
$this->addFlash('success', 'Das Dokument wurde bestätigt');
|
||||
$this->logger->info('Confirm document', [
|
||||
'document_id' => $document->getId(),
|
||||
'document_filename' => $document->getOriginalFilename(),
|
||||
'owner' => $document->getOwner()->getFullName(),
|
||||
]);
|
||||
|
||||
if (true === $this->workflow->can($document->getDisposition(), $transition)) {
|
||||
$this->workflow->apply($document->getDisposition(), $transition);
|
||||
} else {
|
||||
$blockers = $this->workflow->buildTransitionBlockerList($document->getDisposition(), $transition);
|
||||
foreach ($blockers as $blocker) {
|
||||
$this->addFlash('error', $blocker->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Htmx\HxRedirectResponse;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/document/delete/{uuid}', name: 'app_administrative_document_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
#[IsGranted('DELETE', subject: 'document')]
|
||||
public function index(Upload $document, Request $request): Response
|
||||
{
|
||||
if (true === $request->isMethod('POST')) {
|
||||
$this->entityManager->remove($document);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Das Dokument wurde gelöscht');
|
||||
$this->logger->info('Delete document', [
|
||||
'document_filename' => $document->getOriginalFilename(),
|
||||
'owner' => $document->getOwner()->getFullName(),
|
||||
]);
|
||||
|
||||
return new HxRedirectResponse($this->generateUrl('app_administrative_document_index'));
|
||||
}
|
||||
|
||||
return $this->render('administrative/document/modal_delete.html.twig', [
|
||||
'document' => $document,
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Administrative\Document;
|
||||
|
||||
use App\Repository\UploadRepository;
|
||||
use Knp\Component\Pager\PaginatorInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Attribute\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UploadRepository $uploadRepository,
|
||||
private readonly PaginatorInterface $paginator
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/administrative/document', name: 'app_administrative_document_index')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = $this
|
||||
->uploadRepository
|
||||
->getUploadListQuery()
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'upload.createdAt',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
return $this->render('administrative/document/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user