Feat: Implement contract generation and up-/downloading
This commit is contained in:
@@ -4,6 +4,12 @@ namespace App\Controller\Teamer\Disposition;
|
||||
|
||||
use App\Controller\Traits\ReturnUrlTrait;
|
||||
use App\Entity\Disposition;
|
||||
use App\Entity\Upload;
|
||||
use App\Entity\User;
|
||||
use App\Model\UploadSessionDto;
|
||||
use App\Service\Upload\UploadHandler;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
@@ -14,13 +20,57 @@ class DetailController extends AbstractController
|
||||
{
|
||||
use ReturnUrlTrait;
|
||||
|
||||
public function __construct(
|
||||
private readonly UploadHandler $uploadHandler,
|
||||
private readonly EntityManagerInterface $entityManager,
|
||||
private readonly LoggerInterface $logger
|
||||
) {
|
||||
}
|
||||
|
||||
#[Route('/teamer/disposition/detail/{uuid}', name: 'app_teamer_disposition_detail')]
|
||||
#[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);
|
||||
}
|
||||
|
||||
$form = $this->createFormBuilder()->getForm();
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
return $this->redirectToRoute('app_teamer_disposition_detail', [
|
||||
'uuid' => $disposition->getUuid(),
|
||||
]);
|
||||
}
|
||||
|
||||
return $this->render('teamer/disposition/detail.html.twig', [
|
||||
'disposition' => $disposition,
|
||||
'returnUrl' => $this->getReturnUrl($request, 'app_teamer_index'),
|
||||
'form' => $form,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
private function updateContract(Disposition $disposition, UploadSessionDto $uploadSession): void
|
||||
{
|
||||
if (null !== $existingUpload = $disposition->getContractPdf()) {
|
||||
$this->entityManager->remove($existingUpload);
|
||||
}
|
||||
|
||||
/** @var User $user */
|
||||
$user = $this->getUser();
|
||||
$upload = Upload::fromUploadDto($uploadSession->getUploads()->first(), $user, Upload::TYPE_CONTRACT);
|
||||
$disposition->setContractPdf($upload);
|
||||
$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', [
|
||||
'user' => $user->getUserIdentifier(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user