src/Controller/IndexController.php line 21
<?phpnamespace App\Controller;use App\Entity\User;use App\Kernel;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\Form\Extension\Core\Type\FileType;use Symfony\Component\Form\Extension\Core\Type\SubmitType;use Symfony\Component\HttpFoundation\RedirectResponse;use Symfony\Component\HttpFoundation\Request;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\HttpKernel\KernelInterface;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\Security\Http\Attribute\IsGranted;use Symfony\Component\Validator\Constraints\File;class IndexController extends AbstractController{#[Route('/', name: 'app_index')]public function index(): RedirectResponse{return $this->redirectToRoute('dashboard.my_incentives');}#[Route('/user-payrolls/{fileName}', name: 'payroll')]#[IsGranted(User::ROLE_ADMIN)]public function payroll(string $fileName, KernelInterface $kernel){$filePath = $kernel->getProjectDir() . '/user-payrolls/' . $fileName;return $this->file($filePath);}#[Route('/credit_uploads_download', name: 'credit_uploads_download')]#[IsGranted(User::ROLE_ADMIN)]public function creditUploadsDownload(KernelInterface $kernel){$filePath = $kernel->getProjectDir() . '/manual_correction/man_cred.xlsx';return $this->file($filePath);}#[Route('/credit/upload', name: 'credit_upload')]#[IsGranted(User::ROLE_ADMIN)]public function creditUpload(Request $request, KernelInterface $kernel){$form = $this->createFormBuilder()->add('file', FileType::class, ['constraints' => [new File(['mimeTypes' => ['application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']])]])->add('submit', SubmitType::class)->getForm();$form->handleRequest($request);if ($form->isSubmitted() && $form->isValid()) {$newFile = $form->get('file')->getData();if ($newFile) {$fileDir = $kernel->getProjectDir() . '/manual_correction';$newFile->move($fileDir,'man_cred.xlsx');$this->addFlash('success', 'Uploaded');return $this->redirectToRoute('admin');}}return $this->render('base/form.html.twig', ['form' => $form->createView(),'link' => $this->generateUrl('credit_uploads_download')]);}}