Feat: Implement disposition document handling for admins
This commit is contained in:
@@ -22,12 +22,18 @@ framework:
|
||||
confirm_contract:
|
||||
from: checking_contract
|
||||
to: confirmed
|
||||
reject_contract:
|
||||
from: checking_contract
|
||||
to: new
|
||||
upload_invoice:
|
||||
from: confirmed
|
||||
to: checking_invoice
|
||||
confirm_invoice:
|
||||
from: checking_invoice
|
||||
to: paid
|
||||
reject_invoice:
|
||||
from: checking_invoice
|
||||
to: confirmed
|
||||
complete:
|
||||
from: confirmed
|
||||
to: completed
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Event\DocumentRejectedEvent;
|
||||
use App\Form\DocumentCheckType;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
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\JsonResponse;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\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('/admin/document/check/{uuid}', name: 'app_admin_document_check')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $document, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formData = new DocumentCheckDto($document);
|
||||
$formAction = $this->generateUrl('app_admin_document_check', ['uuid' => $document->getUuid()]);
|
||||
$form = $this->createForm(
|
||||
DocumentCheckType::class,
|
||||
$formData,
|
||||
[
|
||||
'action' => $formAction,
|
||||
'ajax_submit' => true,
|
||||
'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);
|
||||
$this->eventDispatcher->dispatch(new DocumentRejectedEvent($formData), DocumentRejectedEvent::NAME);
|
||||
}
|
||||
|
||||
$returnUrl = $this->generateUrl('app_admin_document_index');
|
||||
$response->setCloseAndRedirect($returnUrl);
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/check.html.twig', [
|
||||
'document' => $document,
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
|
||||
return $this->json($response);
|
||||
}
|
||||
|
||||
private function rejectDocument(Upload $document): void
|
||||
{
|
||||
$transition = Upload::TYPE_CONTRACT === $document->getType() ? 'reject_contract' : 'reject_invoice';
|
||||
$this->workflow->apply($document->getDisposition(), $transition);
|
||||
$document->setStatus(Upload::STATUS_REJECTED);
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->addFlash('success', 'Das Dokument wurde abgelehnt');
|
||||
$this->logger->info('Reject document', [
|
||||
'document' => $document->getOriginalFilename(),
|
||||
]);
|
||||
|
||||
}
|
||||
|
||||
private function confirmDocument(Upload $document, string $transition, string $status): void
|
||||
{
|
||||
if (true === $this->workflow->can($document->getDisposition(), $transition)) {
|
||||
$document->setStatus($status);
|
||||
$this->workflow->apply($document->getDisposition(), $transition);
|
||||
$this->entityManager->flush();
|
||||
$this->addFlash('success', 'Das Dokument wurde bestätigt');
|
||||
$this->logger->info('Confirm document', [
|
||||
'document' => $document->getOriginalFilename(),
|
||||
]);
|
||||
} else {
|
||||
$blockers = $this->workflow->buildTransitionBlockerList($document->getDisposition(), $transition);
|
||||
foreach ($blockers as $blocker) {
|
||||
$this->addFlash('error', $blocker->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class DeleteController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
)
|
||||
{
|
||||
}
|
||||
|
||||
#[Route('/admin/document/delete/{uuid}', name: 'app_admin_document_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $document): Response
|
||||
{
|
||||
$this->entityManager->remove($document);
|
||||
$this->entityManager->flush();
|
||||
|
||||
return $this->render('');
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,9 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
public const TYPE_DOCUMENT = 'document';
|
||||
|
||||
public const STATUS_NEW = 'new';
|
||||
public const CHECKING = 'checking';
|
||||
public const STATUS_CHECKED = 'checked';
|
||||
public const STATUS_PAID = 'paid';
|
||||
public const STATUS_ERROR = 'error';
|
||||
public const STATUS_REJECTED = 'rejected';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace App\Event;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\DocumentCheckDto;
|
||||
use Symfony\Contracts\EventDispatcher\Event;
|
||||
|
||||
class DocumentRejectedEvent extends Event
|
||||
{
|
||||
public const NAME = 'document.rejected';
|
||||
|
||||
private Upload $document;
|
||||
private ?string $comment;
|
||||
|
||||
public function __construct(DocumentCheckDto $documentCheckDto)
|
||||
{
|
||||
$this->document = $documentCheckDto->getUpload();
|
||||
$this->comment = $documentCheckDto->getComment();
|
||||
}
|
||||
|
||||
public function getDocument(): Upload
|
||||
{
|
||||
return $this->document;
|
||||
}
|
||||
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
|
||||
namespace App\Form;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\DocumentCheckDto;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
|
||||
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\OptionsResolver\OptionsResolver;
|
||||
|
||||
class DocumentCheckType extends AbstractType
|
||||
{
|
||||
public function buildForm(FormBuilderInterface $builder, array $options): void
|
||||
{
|
||||
$builder
|
||||
->add('status', ChoiceType::class, [
|
||||
'label' => 'neuer Status',
|
||||
'choices' => $options['status_choices'][$options['document_type']],
|
||||
])
|
||||
->add('comment', TextareaType::class, [
|
||||
'label' => 'Kommentar/Begründung',
|
||||
'required' => false,
|
||||
'attr' => [
|
||||
'rows' => 3,
|
||||
],
|
||||
])
|
||||
;
|
||||
}
|
||||
|
||||
public function configureOptions(OptionsResolver $resolver): void
|
||||
{
|
||||
$resolver
|
||||
->setDefaults([
|
||||
'data_class' => DocumentCheckDto::class,
|
||||
'status_choices' => [
|
||||
Upload::TYPE_CONTRACT => [
|
||||
'bestätigt' => Upload::STATUS_CHECKED,
|
||||
'abgelehnt' => Upload::STATUS_REJECTED,
|
||||
],
|
||||
Upload::TYPE_INVOICE => [
|
||||
'bezahlt' => Upload::STATUS_PAID,
|
||||
'abgelehnt' => Upload::STATUS_REJECTED,
|
||||
],
|
||||
],
|
||||
])
|
||||
->setRequired(['document_type'])
|
||||
->setAllowedTypes('document_type', 'string')
|
||||
->setAllowedValues('document_type', [Upload::TYPE_INVOICE, Upload::TYPE_CONTRACT])
|
||||
;
|
||||
}
|
||||
}
|
||||
@@ -49,6 +49,13 @@ class TeamerMenuBuilder extends AbstractMenuBuilder
|
||||
[
|
||||
'route' => 'app_teamer_bookmark_index',
|
||||
'title' => 'Merkliste',
|
||||
'children' => [
|
||||
[
|
||||
'route' => 'app_teamer_assignment',
|
||||
'title' => 'Einsatzdetails',
|
||||
'routeParameters' => $this->getDefaultRouteParameters('uuid'),
|
||||
]
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => 'app_teamer_application_index',
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace App\Model;
|
||||
|
||||
use App\Entity\Upload;
|
||||
|
||||
class DocumentCheckDto
|
||||
{
|
||||
private Upload $upload;
|
||||
private ?string $status = null;
|
||||
private ?string $comment = null;
|
||||
|
||||
public function __construct(Upload $upload)
|
||||
{
|
||||
$this->upload = $upload;
|
||||
}
|
||||
|
||||
public function getUpload(): Upload
|
||||
{
|
||||
return $this->upload;
|
||||
}
|
||||
|
||||
public function getStatus(): string
|
||||
{
|
||||
return $this->status;
|
||||
}
|
||||
|
||||
public function setStatus(string $status): static
|
||||
{
|
||||
$this->status = $status;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getComment(): ?string
|
||||
{
|
||||
return $this->comment;
|
||||
}
|
||||
|
||||
public function setComment(?string $comment): static
|
||||
{
|
||||
$this->comment = $comment;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -103,7 +103,7 @@ class AppRuntime implements RuntimeExtensionInterface
|
||||
$class = 'upload-status-badge ';
|
||||
$class .= match($status) {
|
||||
Upload::STATUS_NEW => 'upload-status-badge--new',
|
||||
Upload::STATUS_ERROR => 'upload-status-badge--error',
|
||||
Upload::STATUS_REJECTED => 'upload-status-badge--error',
|
||||
Upload::STATUS_PAID => 'upload-status-badge--paid',
|
||||
Upload::STATUS_CHECKED => 'upload-status-badge--checked',
|
||||
default => 'upload-status-badge--default',
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
{{ form_start(form) }}
|
||||
<h2 class="font-bold text-lg pb-4">
|
||||
{{ ('label.document.type.' ~ document.type)|trans }} {{ document.disposition.teamer }} vom {{ document.createdAt|date('d.m.Y') }}
|
||||
</h2>
|
||||
<div class="flex flex-col space-y-4 pb-4">
|
||||
{{ form_row(form.status) }}
|
||||
{{ form_row(form.comment) }}
|
||||
</div>
|
||||
<button type="submit" class="btn">
|
||||
Aktualisieren
|
||||
</button>
|
||||
{{ form_rest(form) }}
|
||||
{{ form_end(form) }}
|
||||
@@ -60,9 +60,21 @@
|
||||
{{ upload.status|upload_status_badge }}
|
||||
</td>
|
||||
<td>
|
||||
{% include '_partials/_dropdown.html.twig' with { 'links': [
|
||||
{ 'url': path('app_common_download', { 'uuid': upload.uuid }), 'label': 'Download', 'target': '_blank' },
|
||||
] } %}
|
||||
<div class="flex items-center space-x-2">
|
||||
<button type="button"
|
||||
{{ stimulus_controller('modal-button', [], [], {'ajax-modal': '#ajax-modal'}) }}
|
||||
{{ stimulus_action('modal-button', 'ajax', null, {
|
||||
'title': 'Dokumentenstatus bearbeiten',
|
||||
'url': path('app_admin_document_check', { 'uuid': upload.uuid })
|
||||
}) }}>
|
||||
{{ icon('edit') }}
|
||||
</button>
|
||||
<a href="{{ path('app_common_download', { 'uuid': upload.uuid }) }}"
|
||||
target="_blank"
|
||||
title="Download">
|
||||
{{ icon('download') }}
|
||||
</a>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
{% else %}
|
||||
|
||||
@@ -19,8 +19,8 @@ label:
|
||||
new: neu
|
||||
checking: in Bearbeitung
|
||||
checked: geprüft
|
||||
payed: bezahlt
|
||||
error: Fehler
|
||||
paid: bezahlt
|
||||
rejected: abgelehnt
|
||||
|
||||
message:
|
||||
confirm_contract:
|
||||
|
||||
Reference in New Issue
Block a user