WIP: Implement teamer document upload handling
This commit is contained in:
@@ -22,14 +22,17 @@ class IndexController extends AbstractController
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = $this->uploadRepository->getDocumentListQuery();
|
||||
$query = $this
|
||||
->uploadRepository
|
||||
->getUploadListQuery()
|
||||
;
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'upload.originalFilename',
|
||||
'defaultSortFieldName' => 'upload.createdAt',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
+3
-3
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
namespace App\Controller\Admin\System\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
@@ -18,7 +18,7 @@ class DeleteController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/delete/{uuid}', name: 'app_admin_document_delete')]
|
||||
#[Route('/admin/system/document/delete/{uuid}', name: 'app_admin_system_document_delete')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
#[IsGranted('DELETE', subject: 'document')]
|
||||
public function index(Upload $document): Response
|
||||
@@ -31,6 +31,6 @@ class DeleteController extends AbstractController
|
||||
'document' => $document->getOriginalFilename(),
|
||||
]);
|
||||
|
||||
return $this->redirectToRoute('app_admin_document_index');
|
||||
return $this->redirectToRoute('app_admin_system_document_index');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\System\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\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class IndexController extends AbstractController
|
||||
{
|
||||
public function __construct(
|
||||
private readonly UploadRepository $uploadRepository,
|
||||
private readonly PaginatorInterface $paginator
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/system/document', name: 'app_admin_system_document_index')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): Response
|
||||
{
|
||||
$query = $this->uploadRepository->getDocumentListQuery();
|
||||
|
||||
$pagination = $this->paginator->paginate(
|
||||
$query,
|
||||
$request->query->getInt('page', 1),
|
||||
10,
|
||||
[
|
||||
'defaultSortFieldName' => 'upload.originalFilename',
|
||||
'defaultSortDirection' => 'asc',
|
||||
]
|
||||
);
|
||||
|
||||
return $this->render('admin/system/document/index.html.twig', [
|
||||
'pagination' => $pagination,
|
||||
]);
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
namespace App\Controller\Admin\System\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Model\AjaxModalResponseDto;
|
||||
@@ -21,12 +21,12 @@ class RenameController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/rename/{uuid}', name: 'app_admin_document_rename')]
|
||||
#[Route('/admin/system/document/rename/{uuid}', name: 'app_admin_system_document_rename')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
$formAction = $this->generateUrl('app_admin_system_document_rename', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder($upload, ['action' => $formAction, 'ajax_submit' => true])
|
||||
@@ -42,9 +42,9 @@ class RenameController extends AbstractController
|
||||
$this->addFlash('success', 'Das Dokument wurden umbenannt');
|
||||
$this->logger->info('Rename document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/rename.html.twig', [
|
||||
$response->setContent($this->renderView('admin/system/document/rename.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
namespace App\Controller\Admin\System\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
@@ -23,7 +23,7 @@ class ReplaceController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/replace/{uuid}', name: 'app_admin_document_replace')]
|
||||
#[Route('/admin/system/document/replace/{uuid}', name: 'app_admin_system_document_replace')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Upload $upload, Request $request): JsonResponse
|
||||
{
|
||||
@@ -39,7 +39,7 @@ class ReplaceController extends AbstractController
|
||||
}
|
||||
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_replace', ['uuid' => $upload->getUuid()]);
|
||||
$formAction = $this->generateUrl('app_admin_system_document_replace', ['uuid' => $upload->getUuid()]);
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
@@ -51,9 +51,9 @@ class ReplaceController extends AbstractController
|
||||
$this->addFlash('success', 'Das Dokument wurden ersetzt');
|
||||
$this->logger->info('Replace document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/replace.html.twig', [
|
||||
$response->setContent($this->renderView('admin/system/document/replace.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
+5
-5
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller\Admin\Document;
|
||||
namespace App\Controller\Admin\System\Document;
|
||||
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
@@ -23,7 +23,7 @@ class UploadController extends AbstractController
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/admin/document/upload', name: 'app_admin_document_upload')]
|
||||
#[Route('/admin/system/document/upload', name: 'app_admin_system_document_upload')]
|
||||
#[IsGranted('ROLE_ADMINISTRATIVE')]
|
||||
public function index(Request $request): JsonResponse
|
||||
{
|
||||
@@ -42,7 +42,7 @@ class UploadController extends AbstractController
|
||||
}
|
||||
|
||||
$response = new AjaxModalResponseDto();
|
||||
$formAction = $this->generateUrl('app_admin_document_upload');
|
||||
$formAction = $this->generateUrl('app_admin_system_document_upload');
|
||||
|
||||
$form = $this
|
||||
->createFormBuilder(null, ['action' => $formAction, 'ajax_submit' => true])
|
||||
@@ -54,9 +54,9 @@ class UploadController extends AbstractController
|
||||
$this->addFlash('success', 'Das/die Dokument/e wurden hochgeladen');
|
||||
$this->logger->info('Upload document');
|
||||
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_document_index'));
|
||||
$response->setCloseAndRedirect($this->generateUrl('app_admin_system_document_index'));
|
||||
} else {
|
||||
$response->setContent($this->renderView('admin/document/upload.html.twig', [
|
||||
$response->setContent($this->renderView('admin/system/document/upload.html.twig', [
|
||||
'form' => $form,
|
||||
]));
|
||||
}
|
||||
+2
-2
@@ -10,12 +10,12 @@ use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
|
||||
class ContractController extends AbstractController
|
||||
class ContractPdfController extends AbstractController
|
||||
{
|
||||
public function __construct(private readonly ContractRenderer $renderer)
|
||||
{}
|
||||
|
||||
#[Route('/teamer/disposition/contract/{uuid}', name: 'app_teamer_disposition_contract')]
|
||||
#[Route('/teamer/disposition/contract/{uuid}', name: 'app_teamer_disposition_contractpdf')]
|
||||
#[IsGranted('CONTRACT', subject: 'disposition')]
|
||||
public function index(Disposition $disposition): Response
|
||||
{
|
||||
@@ -15,6 +15,7 @@ use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
use Symfony\Component\Security\Http\Attribute\IsGranted;
|
||||
use Symfony\Component\Workflow\WorkflowInterface;
|
||||
|
||||
class DetailController extends AbstractController
|
||||
{
|
||||
@@ -23,6 +24,7 @@ class DetailController extends AbstractController
|
||||
public function __construct(
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly WorkflowInterface $dispositionStateMachine,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
@@ -31,16 +33,22 @@ class DetailController extends AbstractController
|
||||
#[IsGranted('VIEW', subject: 'disposition')]
|
||||
public function index(Disposition $disposition, Request $request): Response
|
||||
{
|
||||
// Handle upload independently from form submission to avoid issues with failing validation
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
if (true === $request->isMethod('POST') && 0 < $uploadSession->getCount()) {
|
||||
$this->updateContract($disposition, $uploadSession);
|
||||
}
|
||||
|
||||
// Create dummy form without fields to generate POST requests
|
||||
$form = $this->createFormBuilder()->getForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
$uploadSession = $this->uploadHandler->getUploadSession();
|
||||
|
||||
if (0 < $uploadSession->getCount()) {
|
||||
if (true === $this->dispositionStateMachine->can($disposition, 'upload_contract')) {
|
||||
$this->uploadContract($disposition, $uploadSession);
|
||||
}
|
||||
if (true === $this->dispositionStateMachine->can($disposition, 'upload_invoice')) {
|
||||
$this->uploadInvoice($disposition, $uploadSession);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->redirectToRoute('app_teamer_disposition_detail', [
|
||||
'uuid' => $disposition->getUuid(),
|
||||
]);
|
||||
@@ -48,28 +56,61 @@ class DetailController extends AbstractController
|
||||
|
||||
return $this->render('teamer/disposition/detail.html.twig', [
|
||||
'disposition' => $disposition,
|
||||
'returnUrl' => $this->getReturnUrl($request, 'app_teamer_index'),
|
||||
'form' => $form,
|
||||
'returnUrl' => $this->getReturnUrl($request, 'app_teamer_index'),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function updateContract(Disposition $disposition, UploadSessionDto $uploadSession): void
|
||||
private function uploadContract(Disposition $disposition, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
if (null !== $existingUpload = $disposition->getContractPdf()) {
|
||||
if (null !== $existingUpload = $disposition->getDocumentByType(Upload::TYPE_CONTRACT)) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_CONTRACT);
|
||||
$disposition->setContractPdf($upload);
|
||||
$upload->setStatus(Upload::STATUS_NEW);
|
||||
|
||||
$disposition->addDocument($upload);
|
||||
$this->dispositionStateMachine->apply($disposition, 'upload_contract');
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_CONTRACT, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
|
||||
$this->addFlash('success', 'Der Honorarvertrag wurde hochgeladen');
|
||||
$this->logger->info('Update contract', [
|
||||
|
||||
$this->logger->info('Upload contract', [
|
||||
'user' => $user->getUserIdentifier(),
|
||||
]);
|
||||
}
|
||||
|
||||
private function uploadInvoice(Disposition $disposition, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
if (null !== $existingUpload = $disposition->getDocumentByType(Upload::TYPE_INVOICE)) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_INVOICE);
|
||||
$upload->setStatus(Upload::STATUS_NEW);
|
||||
|
||||
$disposition->addDocument($upload);
|
||||
$this->dispositionStateMachine->apply($disposition, 'upload_invoice');
|
||||
|
||||
$this->entityManager->flush();
|
||||
|
||||
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_INVOICE, $uploadSession);
|
||||
$this->uploadHandler->destroyUploadSession();
|
||||
|
||||
$this->addFlash('success', 'Die Honornote wurde hochgeladen');
|
||||
|
||||
$this->logger->info('Upload invoice', [
|
||||
'user' => $user->getUserIdentifier(),
|
||||
]);
|
||||
}
|
||||
|
||||
+37
-17
@@ -5,6 +5,8 @@ namespace App\Entity;
|
||||
use App\Entity\Traits\BlameableEntity;
|
||||
use App\Entity\Traits\TimestampableEntity;
|
||||
use App\Repository\DispositionRepository;
|
||||
use Doctrine\Common\Collections\ArrayCollection;
|
||||
use Doctrine\Common\Collections\Collection;
|
||||
use Doctrine\DBAL\Types\Types;
|
||||
use Doctrine\ORM\Mapping as ORM;
|
||||
use Symfony\Component\Uid\Uuid;
|
||||
@@ -16,8 +18,11 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
use TimestampableEntity;
|
||||
|
||||
public const STATUS_NEW = 'new';
|
||||
public const STATUS_PENDING = 'pending';
|
||||
public const STATUS_CHECKING_CONTRACT = 'checking_contract';
|
||||
public const STATUS_CONFIRMED = 'confirmed';
|
||||
public const STATUS_CHECKING_INVOICE = 'checking_invoice';
|
||||
public const STATUS_PAID = 'paid';
|
||||
public const STATUS_COMPLETED = 'completed';
|
||||
|
||||
#[ORM\Id]
|
||||
#[ORM\GeneratedValue]
|
||||
@@ -39,11 +44,8 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
#[ORM\Column(type: Types::TEXT, nullable: true)]
|
||||
private ?string $remarks;
|
||||
|
||||
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
|
||||
private ?Upload $contractPdf = null;
|
||||
|
||||
#[ORM\OneToOne(cascade: ['persist', 'remove'])]
|
||||
private ?Upload $invoicePdf = null;
|
||||
#[ORM\OneToMany(mappedBy: 'disposition', targetEntity: Upload::class, cascade: ['persist', 'remove'])]
|
||||
private Collection $documents;
|
||||
|
||||
public function __construct(Application $application)
|
||||
{
|
||||
@@ -52,6 +54,7 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
$this->assignment = $application->getAssignment();
|
||||
$this->teamer = $application->getTeamer();
|
||||
$this->remarks = $application->getRemarks();
|
||||
$this->documents = new ArrayCollection();
|
||||
}
|
||||
|
||||
public function getId(): ?int
|
||||
@@ -112,26 +115,43 @@ class Disposition implements BlameableEntityInterface, TimestampableEntityInterf
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getContractPdf(): ?Upload
|
||||
/**
|
||||
* @return Collection<int, Upload>
|
||||
*/
|
||||
public function getDocuments(): Collection
|
||||
{
|
||||
return $this->contractPdf;
|
||||
return $this->documents;
|
||||
}
|
||||
|
||||
public function setContractPdf(?Upload $contractPdf): static
|
||||
public function getDocumentByType(string $type): ?Upload
|
||||
{
|
||||
$this->contractPdf = $contractPdf;
|
||||
foreach ($this->getDocuments() as $upload) {
|
||||
if ($type === $upload->getType()) {
|
||||
return $upload;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public function addDocument(Upload $document): static
|
||||
{
|
||||
if (!$this->documents->contains($document)) {
|
||||
$this->documents->add($document);
|
||||
$document->setDisposition($this);
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getInvoicePdf(): ?Upload
|
||||
public function removeDocument(Upload $document): static
|
||||
{
|
||||
return $this->invoicePdf;
|
||||
}
|
||||
|
||||
public function setInvoicePdf(?Upload $invoicePdf): static
|
||||
{
|
||||
$this->invoicePdf = $invoicePdf;
|
||||
if ($this->documents->removeElement($document)) {
|
||||
// set the owning side to null (unless already changed)
|
||||
if ($document->getDisposition() === $this) {
|
||||
$document->setDisposition(null);
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
+17
-2
@@ -22,9 +22,9 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
public const TYPE_DOCUMENT = 'document';
|
||||
|
||||
public const STATUS_NEW = 'new';
|
||||
public const STATUS_IN_PROCESS = 'in_process';
|
||||
public const CHECKING = 'checking';
|
||||
public const STATUS_CHECKED = 'checked';
|
||||
public const STATUS_PAYED = 'payed';
|
||||
public const STATUS_PAID = 'paid';
|
||||
public const STATUS_ERROR = 'error';
|
||||
|
||||
#[ORM\Id]
|
||||
@@ -59,6 +59,9 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
#[ORM\ManyToOne]
|
||||
private ?User $owner = null;
|
||||
|
||||
#[ORM\ManyToOne(inversedBy: 'documents')]
|
||||
private ?Disposition $disposition = null;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->uuid = Uuid::v4();
|
||||
@@ -184,4 +187,16 @@ class Upload implements BlameableEntityInterface, TimestampableEntityInterface
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function getDisposition(): ?Disposition
|
||||
{
|
||||
return $this->disposition;
|
||||
}
|
||||
|
||||
public function setDisposition(?Disposition $disposition): static
|
||||
{
|
||||
$this->disposition = $disposition;
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,6 +83,10 @@ class AdminMenuBuilder extends AbstractMenuBuilder
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'route' => 'app_admin_system_document_index',
|
||||
'title' => 'Dokumente',
|
||||
],
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
@@ -68,4 +68,19 @@ class UploadRepository extends ServiceEntityRepository
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getUploadListQuery(): Query
|
||||
{
|
||||
$qb = $this->createQueryBuilder('upload');
|
||||
|
||||
return $qb
|
||||
->select('upload', 'disposition', 'assignment', 'job_profile', 'destination', 'teamer')
|
||||
->innerJoin('upload.disposition', 'disposition')
|
||||
->innerJoin('disposition.assignment', 'assignment')
|
||||
->innerJoin('assignment.jobProfile', 'job_profile')
|
||||
->innerJoin('assignment.destination', 'destination')
|
||||
->innerJoin('disposition.teamer', 'teamer')
|
||||
->getQuery()
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user