feat: enable document uploads for admins on behalf of teamer

closes #869btf5bm
This commit is contained in:
Björn Fromme
2026-03-15 12:42:28 +01:00
parent 2195467f50
commit 6ec9fa6f9d
4 changed files with 109 additions and 62 deletions
@@ -31,22 +31,33 @@ class DocumentUploadController extends AbstractController
}
#[Route(
path: '/administrative/disposition/document-upload/{uuid}',
path: '/administrative/disposition/document-upload/{uuid}/{type}',
name: 'app_administrative_disposition_document_upload'
)]
#[IsGranted('CONTRACT_SUPPLEMENTARY', subject: 'disposition')]
public function index(Disposition $disposition, Request $request): Response
#[IsGranted('ADMIN_DOCUMENT_UPLOAD', subject: 'disposition')]
public function index(Disposition $disposition, string $type, Request $request): Response
{
if (false === in_array($type, [Upload::TYPE_CONTRACT, Upload::TYPE_INVOICE], true)) {
throw $this->createNotFoundException('Unsupported document type');
}
$teamer = $disposition->getTeamer();
$modalTitle = sprintf('Honorarvertrag für %s hochladen', $teamer);
$modalTitle = Upload::TYPE_CONTRACT === $type
? sprintf('Honorarvertrag für %s hochladen', $teamer)
: sprintf('Honorarnote für %s hochladen', $teamer);
$form = $this->createFormBuilder()->getForm();
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->processUpload($disposition);
$this->processUpload($disposition, $type);
$this->addFlash('success', 'Der Honorarvertrag wurde hochgeladen');
$this->addFlash(
'success',
Upload::TYPE_CONTRACT === $type
? 'Der Honorarvertrag wurde hochgeladen'
: 'Die Honorarnote wurde hochgeladen'
);
return new HxRedirectResponse($this->generateUrl('app_administrative_assignment_detail', [
'uuid' => $disposition->getAssignment()->getUuid(),
@@ -56,13 +67,16 @@ class DocumentUploadController extends AbstractController
return $this->render('administrative/disposition/modal_document_upload.html.twig', [
'disposition' => $disposition,
'modalTitle' => $modalTitle,
'endpointUpload' => Upload::TYPE_CONTRACT === $type
? '_uploader_upload_contract'
: '_uploader_upload_invoice',
'form' => $form->createView(),
]);
}
private function processUpload(Disposition $disposition): void
private function processUpload(Disposition $disposition, string $type): void
{
if (null !== $existingUpload = $disposition->getDocumentByType(Upload::TYPE_CONTRACT)) {
if (null !== $existingUpload = $disposition->getDocumentByType($type)) {
$this->entityManager->remove($existingUpload);
}
@@ -76,23 +90,28 @@ class DocumentUploadController extends AbstractController
$upload = Upload::fromUploadDto(
$uploadSession->getUploads()->first(),
$teamer->getUser(),
Upload::TYPE_CONTRACT
$type
);
$upload
->setStatus(Upload::STATUS_CHECKED)
->setApprovedAt(new \DateTimeImmutable())
->setApprovedBy($user->getInitials())
;
if (Upload::TYPE_CONTRACT === $type) {
$upload
->setStatus(Upload::STATUS_CHECKED)
->setApprovedAt(new \DateTimeImmutable())
->setApprovedBy($user->getInitials())
;
$disposition
->addDocument($upload)
->setStatus(Disposition::STATUS_CONFIRMED)
;
$disposition->setStatus(Disposition::STATUS_CONFIRMED);
} else {
$upload->setStatus(Upload::STATUS_NEW);
$disposition->setStatus(Disposition::STATUS_CHECKING_INVOICE);
}
$disposition->addDocument($upload);
$this->entityManager->flush();
$this->uploadHandler->moveUploadSessionFilesFromOrphanage(Upload::TYPE_CONTRACT, $uploadSession);
$this->uploadHandler->moveUploadSessionFilesFromOrphanage($type, $uploadSession);
$this->uploadHandler->destroyUploadSession();
if (true === $this->featureManager->isActive('sanitize_uploads')) {
@@ -100,14 +119,16 @@ class DocumentUploadController extends AbstractController
}
$this->eventDispatcher->dispatch(new DocumentUploadedEvent($upload), DocumentUploadedEvent::NAME);
$this->eventDispatcher->dispatch(new DocumentConfirmedEvent($upload), DocumentConfirmedEvent::NAME);
if (Upload::TYPE_CONTRACT === $type) {
$this->eventDispatcher->dispatch(new DocumentConfirmedEvent($upload), DocumentConfirmedEvent::NAME);
}
$this->logger->info('Document upload for teamer', [
$this->logger->info('Administrative document upload for teamer', [
'teamer_id' => $teamer->getId(),
'teamer_name' => $teamer->getFullName(),
'disposition_id' => $disposition->getId(),
'document_id' => $upload->getId(),
'upload_type' => Upload::TYPE_CONTRACT,
'upload_type' => $type,
]);
}
}