src/Controller/BuildReportsByClientsController.php line 35

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Report;
  4. use App\Form\BuildAllReportsType;
  5. use App\Form\ReportGeneratorType;
  6. use App\Form\ReportLogosType;
  7. use App\Form\UploadFileType;
  8. use App\Repository\AnswerRepository;
  9. use App\Repository\ReportRepository;
  10. use App\Service\BuildReportsByClientsService;
  11. use App\Service\ProcessResultService;
  12. use App\Service\S3TXTManager;
  13. use Doctrine\ORM\EntityRepository;
  14. use Exception;
  15. use FontLib\Table\Type\name;
  16. use Psr\Log\LoggerInterface;
  17. use Symfony\Bridge\Doctrine\Form\Type\EntityType;
  18. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  19. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  20. use Symfony\Component\Form\Extension\Core\Type\CollectionType;
  21. use Symfony\Component\Form\Extension\Core\Type\SubmitType;
  22. use Symfony\Component\Form\FormError;
  23. use Symfony\Component\HttpFoundation\Request;
  24. use Symfony\Component\HttpFoundation\Response;
  25. use Symfony\Component\HttpKernel\KernelInterface;
  26. use Symfony\Component\Routing\Annotation\Route;
  27. class BuildReportsByClientsController extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/upload/reports/by/clients", name="upload_reports_by_clients")
  31.      */
  32.     public function index
  33.         Request $request
  34.         BuildReportsByClientsService $srvBuildReport,
  35.         S3TXTManager $s3TXTManager): Response
  36.     {
  37.         
  38.         $form $this->createForm(UploadFileType::class);
  39.         $form->handleRequest($request);
  40.         if ($form->isSubmitted() && $form->isValid()) 
  41.         {
  42.             /** @var \Symfony\Component\HttpFoundation\File\UploadedFile $file */
  43.             $file $form['txt']->getData();
  44.              $fileName md5(uniqid()).'.'.$file->guessExtension();
  45.            
  46.             $cvDir $srvBuildReport->getTxtDir();
  47.             $s3Path $cvDir $fileName;
  48.     
  49.  
  50.             if ($s3TXTManager->uploadFileTXT_ToS3($file$s3Path)) {
  51.                 return $this->redirect($this->generateUrl('select_reports_by_clients', ['names' => $s3Path]));
  52.             } else {
  53.                 $this->addFlash('error''Failed to upload the file to S3.');
  54.             }
  55.             return $this->redirect($this->generateUrl('select_reports_by_clients',
  56.             ['names'=>$fileName]));
  57.         }
  58.         return $this->render('build_reports_by_clients/index.html.twig', [
  59.             'controller_name' => 'BuildReportsByClientsController',
  60.             'form' => $form->createView()
  61.         ]);
  62.     }
  63.     
  64.     /**
  65.      * @Route("/select/reports/by/clients", name="select_reports_by_clients")
  66.      */
  67.     public function selectReportByClient(Request $request
  68.     BuildReportsByClientsService $srvReportsByClients
  69.     ReportRepository $rr,
  70.     AnswerRepository $answerRepository
  71.     LoggerInterface $logger,
  72.     ProcessResultService $processResultService): Response
  73.     {
  74.         $clients $srvReportsByClients->nameGrabber($request->get('names'));
  75.         if (!$clients) {
  76.             //manejar Exception estandar
  77.            throw new Exception("no se escontraron clientes en este txt"1);           
  78.         }
  79.         $form $this->createForm(BuildAllReportsType::class, null, [
  80.             'data'=> [
  81.                 'clients'=>$clients['clients'], 
  82.                 'plans'=>$rr->findAllBySubsetionNotAutomatic()]
  83.             ]);
  84.         $form->handleRequest($request);
  85.         if ($form->isSubmitted() && $form->isValid()) 
  86.         {
  87.             try {            
  88.                 $pending $srvReportsByClients->confirmGeneration($form->getData());
  89.                 $pending $processResultService->processResult($pending$clients['rowAndColum']);
  90.                 return $this->render('build_reports_by_clients/generator_loading.html.twig', [
  91.                     'pendingReport'=> $pending,
  92.                     'answerRepository' => $answerRepository
  93.                 ]);
  94.             } catch (\Exception $ex) {
  95.                 $logger->error($ex->getFile().' '.$ex->getLine());
  96.                 $form->addError(new FormError($ex->getMessage()));
  97.                 // return $this->json($ex->getMessage(), Response::HTTP_CONFLICT);
  98.             }                 
  99.         }
  100.  
  101.         return $this->render('build_reports_by_clients/select_reports_by_clients.html.twig', [
  102.             'form' => $form->createView(),
  103.             'clients' => count($clients)
  104.         ]);
  105.     }
  106.     /**
  107.      * @Route("/find/plans/{report}", name="find_plans")
  108.      */
  109.     public function find_plans($reportAnswerRepository $answerRepository): Response
  110.     {
  111.         try {
  112.             if (!isset($report)) {
  113.                 return $this->json(['message'=> 'reporte no valido'Response::HTTP_CONFLICT]);
  114.             }
  115.             $optionPlans= [];
  116.             foreach ($answerRepository->findPlanByReporNotAutomatic($report) as $value) {
  117.                 $optionPlans[$value['id']] = $value['answer'].': '.$value['descriptiveAnswer'];
  118.             }
  119.             if (count($optionPlans)>0) {
  120.                 $optionPlans[0] = 'Automatico: El sistema lo determina segun los marcadores geneticos';
  121.             }
  122.         } catch (\Throwable $th) {
  123.             return $this->json(['message'=> $th->getMessage(), Response::HTTP_CONFLICT]);
  124.         }       
  125.         return $this->json(['data'=> $optionPlansResponse::HTTP_OK]);
  126.     }
  127. }