src/Controller/Front/PoolGraphExportController.php line 66

Open in your IDE?
  1. <?php
  2. // src/Controller/PoolGraphExportController.php
  3. namespace App\Controller\Front;
  4. use App\Controller\CustomController;
  5. use App\Entity\HttParsing;
  6. use App\Entity\PoolProgram;
  7. use App\Entity\PoolProgramType;
  8. use App\Form\Front\GraphExportType;
  9. use App\Service\CurrencyService;
  10. use App\Service\Export\HttReportPdf;
  11. use App\Service\HttGraph\GraphAmortisation;
  12. use App\Service\HttGraph\GraphBreakdownByInterestRate;
  13. use App\Service\HttGraph\GraphBreakdownByRepaymentType;
  14. use App\Service\HttGraph\GraphBreakdownByTypeOfDebtor;
  15. use App\Service\HttGraph\GraphConcentrationRisks;
  16. use App\Service\HttGraph\GraphCurrencyBreakdownCoverAssets;
  17. use App\Service\HttGraph\GraphCurrencyBreakdownCoveredBonds;
  18. use App\Service\HttGraph\GraphGeographicBreakdownDomestic;
  19. use App\Service\HttGraph\GraphGeographicBreakdownInternational;
  20. use App\Service\HttGraph\GraphInterestRateBreakdown;
  21. use App\Service\HttGraph\GraphLoanSeasoningBar;
  22. use App\Service\HttGraph\GraphLoanSizeInformationCommercial;
  23. use App\Service\HttGraph\GraphLoanSizeInformationResidential;
  24. use App\Service\HttGraph\GraphLtvDistributionIndexed;
  25. use App\Service\HttGraph\GraphLtvDistributionUnindexed;
  26. use App\Service\HttGraph\GraphOvercollateralisation;
  27. use App\Service\HttGraph\GraphTypeTenureCommercial;
  28. use App\Service\HttGraph\GraphTypeTenureResidential;
  29. use App\Service\HttParser\PoolType\PoolTypeConfigMortgage;
  30. use App\Service\HttParser\PoolType\PoolTypeConfigPublic;
  31. use App\Service\HttParser\PoolType\PoolTypeConfigShipping;
  32. use App\Service\HttService;
  33. use Doctrine\ORM\EntityManagerInterface;
  34. use Symfony\Component\DependencyInjection\ContainerInterface;
  35. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  36. use Symfony\Component\HttpFoundation\JsonResponse;
  37. use Symfony\Component\HttpFoundation\Request;
  38. use Symfony\Component\HttpFoundation\RequestStack;
  39. use Symfony\Component\HttpFoundation\ResponseHeaderBag;
  40. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  41. use Symfony\Component\Mime\FileinfoMimeTypeGuesser;
  42. use Symfony\Component\Routing\Annotation\Route;
  43. use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter;
  44. class PoolGraphExportController extends CustomController
  45. {
  46.     protected CurrencyService $currencyService;
  47.     public function __construct(
  48.         EntityManagerInterface $em,
  49.         RequestStack $requestStack,
  50.         CurrencyService $currencyService
  51.     )
  52.     {
  53.         parent::__construct($em$requestStack);
  54.         $this->currencyService $currencyService;
  55.     }
  56.     /**
  57.      * @Route("/pool/{id}/graph/{parsingId}/export/maker", name="public_pool_graph_export_maker")
  58.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  59.      */
  60.     public function exportMaker(Request $requestPoolProgram $poolHttParsing $parsingHttService $httService)
  61.     {
  62.         $this->denyAccessUnlessGranted('view'$pool);
  63.         $this->denyAccessUnlessGranted('view'$parsing);
  64.         $form $this->createForm(GraphExportType::class, null, ['method' => 'get''parsing' => $parsing]);
  65.         $form->handleRequest($request);
  66.         if ($form->isSubmitted()) {
  67.             if($form->isValid()){
  68.                 $this->session->set('exportData'$form->getData());
  69.                 return $this->redirectToRoute('public_pool_graph_export_step1', ['id' => $pool->getId(), 'parsingId' => $parsing->getId()]);
  70.             }
  71.         }else{
  72.             $form->setData([
  73.                 'generalInformation' => true,
  74.                 'contactsDetail' => true,
  75.                 'poolDetail' => true,
  76.                 'httOverview' => true,
  77.                 'httGeneral' => true,
  78.                 'httMortgage' => true,
  79.                 'httPublic' => true,
  80.                 'httShipping' => true,
  81.                 'bonds' => true,
  82.                 'httGenerals' => ['a''b''c''d'],
  83.                 'httMortgages' => [
  84.                     PoolTypeConfigMortgage::SECTION_GEOGRAPHIC_BREAKDOWN_INTERNATIONAL,
  85.                     PoolTypeConfigMortgage::SECTION_BREAKDOWN_BY_INTERESTS_RATE,
  86.                     PoolTypeConfigMortgage::SECTION_BREAKDOWN_BY_REPAYMENT_TYPE,
  87.                     PoolTypeConfigMortgage::SECTION_LOAN_SEASONING_BAR,
  88.                     PoolTypeConfigMortgage::SECTION_LOAN_SIZE_INFORMATION_RESIDENTIAL,
  89.                     PoolTypeConfigMortgage::SECTION_LTV_DISTRIBUTION_INDEXED,
  90.                     PoolTypeConfigMortgage::SECTION_TYPE_OF_TENURE_RESIDENTIAL,
  91.                 ],
  92.                 'httPublics' => [
  93.                     PoolTypeConfigPublic::SECTION_GEOGRAPHIC_BREAKDOWN_INTERNATIONAL,
  94.                     PoolTypeConfigPublic::SECTION_BREAKDOWN_BY_INTERESTS_RATE,
  95.                     PoolTypeConfigPublic::SECTION_BREAKDOWN_BY_REPAYMENT_TYPE,
  96.                     PoolTypeConfigPublic::SECTION_LOAN_SIZE_INFORMATION_RESIDENTIAL,
  97.                     PoolTypeConfigPublic::SECTION_CONCENTRATION_RISK,
  98.                     PoolTypeConfigPublic::SECTION_BREAKDOWN_BY_TYPE_OF_DEBTOR,
  99.                 ],
  100.                 'httShippings' => [
  101.                     PoolTypeConfigShipping::SECTION_GEOGRAPHIC_BREAKDOWN_INTERNATIONAL,
  102.                     PoolTypeConfigShipping::SECTION_BREAKDOWN_BY_INTERESTS_RATE,
  103.                     PoolTypeConfigShipping::SECTION_BREAKDOWN_BY_REPAYMENT_TYPE,
  104.                     PoolTypeConfigShipping::SECTION_LOAN_SEASONING_BAR,
  105.                     PoolTypeConfigShipping::SECTION_LOAN_SIZE_INFORMATION_RESIDENTIAL,
  106.                     PoolTypeConfigShipping::SECTION_LTV_DISTRIBUTION_INDEXED,
  107.                     PoolTypeConfigShipping::SECTION_BREAKDOWN_BY_TYPE_OF_SHIP,
  108.                 ],
  109.             ]);
  110.         }
  111.         $httService->setParsing($parsing);
  112.         return $this->render('front/pool/graph-export/maker.html.twig', [
  113.             'httService' => $httService,
  114.             'parsing' => $parsing,
  115.             'pool' => $pool,
  116.             'issuer' => $pool->getIssuer(),
  117.             'form' => $form->createView(),
  118.         ]);
  119.     }
  120.     /**
  121.      * @Route("/pool/{id}/graph/{parsingId}/export/step1", name="public_pool_graph_export_step1")
  122.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  123.      */
  124.     public function step1(Request $requestPoolProgram $poolHttParsing $parsingHttService $httService)
  125.     {
  126.         $exportData $this->session->get('exportData');
  127.         if(!$exportData){
  128.             $this->redirectToRoute('public_pool_graph_export_maker', ['id' => $pool->getId(), 'parsingId' => $parsing->getId()]);
  129.         }
  130.         $httService->setParsing($parsing);
  131.         return $this->render('front/pool/graph-export/step1.html.twig', [
  132.             'httService' => $httService,
  133.             'parsing' => $parsing,
  134.             'pool' => $pool,
  135.             'issuer' => $pool->getIssuer(),
  136.             'exportData' => $exportData,
  137.         ]);
  138.     }
  139.     /**
  140.      * @Route("/pool/{id}/graph/{parsingId}/export/step1/send-data", name="public_pool_graph_export_step1_send_data")
  141.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  142.      */
  143.     public function step1SendData(Request $requestPoolProgram $poolHttParsing $parsingHttService $httServiceHttReportPdf $exportService)
  144.     {
  145.         try{
  146.             $data $request->get('data');
  147.             $exportService->saveDataStep1($data);
  148.             return new JsonResponse(['success' => true]);
  149.         }catch(\Exception $e){
  150.             return new JsonResponse(['success' => false'errorMessage' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
  151.         }
  152.     }
  153.     /**
  154.      * @Route("/pool/{id}/graph/{parsingId}/export/step2", name="public_pool_graph_export_step2")
  155.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  156.      */
  157.     public function step2(Request $requestPoolProgram $poolHttParsing $parsingHttService $httServiceHttReportPdf $exportServiceGraphGeographicBreakdownInternational $graphService)
  158.     {
  159.         $exportData $this->session->get('exportData');
  160.         if(!$exportData){
  161.             $this->redirectToRoute('public_pool_graph_export_maker', ['id' => $pool->getId(), 'parsingId' => $parsing->getId()]);
  162.         }
  163.         $httService->setParsing($parsing);
  164.         return $this->render('front/pool/graph-export/step2.html.twig', [
  165.             'httService' => $httService,
  166.             'parsing' => $parsing,
  167.             'pool' => $pool,
  168.             'issuer' => $pool->getIssuer(),
  169.             'exportData' => $exportData,
  170.             'graphService' => $graphService,
  171.         ]);
  172.     }
  173.     /**
  174.      * @Route("/pool/{id}/graph/{parsingId}/export/step2/send-data", name="public_pool_graph_export_step2_send_data")
  175.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  176.      */
  177.     public function step2SendData(Request $requestPoolProgram $poolHttParsing $parsingHttService $httServiceHttReportPdf $exportService)
  178.     {
  179.         try{
  180.             $data $request->get('data');
  181.             $exportService->saveDataStep2($data);
  182.             $exportService
  183.                 ->setExportOptions($this->session->get('exportData'))
  184.                 ->setPool($pool)
  185.                 ->setParsing($parsing)
  186.                 ->export();
  187.             return new JsonResponse(['success' => true]);
  188.         }catch(\Exception $e){
  189.             return new JsonResponse(['success' => false'errorMessage' => $e->getMessage(), 'stack' => $e->getTraceAsString()]);
  190.         }
  191.     }
  192.     /**
  193.      * @Route("/pool/{id}/graph/{parsingId}/export/download", name="public_pool_graph_export_download")
  194.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  195.      */
  196.     public function download(Request $requestPoolProgram $poolHttParsing $parsingHttService $httServiceHttReportPdf $exportService)
  197.     {
  198.         $exportData $this->session->get('exportData');
  199.         if(!$exportData){
  200.             $this->redirectToRoute('public_pool_graph_export_maker', ['id' => $pool->getId(), 'parsingId' => $parsing->getId()]);
  201.         }
  202.         $httService->setParsing($parsing);
  203.         return $this->render('front/pool/graph-export/download.html.twig', [
  204.             'httService' => $httService,
  205.             'parsing' => $parsing,
  206.             'pool' => $pool,
  207.             'issuer' => $pool->getIssuer(),
  208.         ]);
  209.     }
  210.     /**
  211.      * @Route("/pool/{id}/graph/{parsingId}/export/download-file", name="public_pool_graph_export_download_file")
  212.      * @ParamConverter("parsing", options={"mapping": {"parsingId": "id"}})
  213.      */
  214.     public function downloadFile(Request $requestPoolProgram $poolHttParsing $parsingHttReportPdf $exportService)
  215.     {
  216.         $exportService->setParsing($parsing);
  217.         $response = new BinaryFileResponse($exportService->getFilePath());
  218.         $mimeTypeGuesser = new FileinfoMimeTypeGuesser();
  219.         if($mimeTypeGuesser->isGuesserSupported()){
  220.             $response->headers->set('Content-Type'$mimeTypeGuesser->guessMimeType($exportService->getFilePath()));
  221.         }else{
  222.             $response->headers->set('Content-Type''text/plain');
  223.         }
  224.         $response->setContentDisposition(
  225.             ResponseHeaderBag::DISPOSITION_ATTACHMENT,
  226.             'Report.pdf'
  227.         );
  228.         return $response;
  229.     }
  230. }