src/Controller/RCA/RCAController.php line 169

Open in your IDE?
  1. <?php
  2. namespace App\Controller\RCA;
  3. use App\Controller\BaseController;
  4. use App\Entity\Addressing\Address;
  5. use App\Entity\Addressing\Country;
  6. use App\Entity\Addressing\County;
  7. use App\Entity\Log\LogEmailSending;
  8. use App\Entity\Partner\Partner;
  9. use App\Entity\Vignette\Vignette;
  10. use App\Manager\BitbagStatic\BlockManager;
  11. use App\Entity\Customer\TrackerActivity;
  12. use App\Entity\Order\Order;
  13. use App\Entity\RCA\Availability;
  14. use App\Entity\RCA\FuelType;
  15. use App\Entity\RCA\InsuranceCompany;
  16. use App\Entity\RCA\LeasingCompany;
  17. use App\Entity\RCA\MappedCategory;
  18. use App\Entity\RCA\MappedVehicleMake;
  19. use App\Entity\RCA\MappedVehicleModel;
  20. use App\Entity\RCA\RCA;
  21. use App\Entity\RCA\SubCategory;
  22. use App\Entity\RCA\UsageType;
  23. use App\Entity\RCA\VehicleType;
  24. use App\Entity\RoadAssistance\RoadAssistance;
  25. use App\Manager\Cart\CartManager;
  26. use App\Manager\Customer\VehicleManager;
  27. use App\Manager\HuVignette\HuVignetteManager;
  28. use App\Manager\Partner\PartnerManager;
  29. use App\Manager\Rca\HistoryRcaManager;
  30. use App\Manager\Rca\InsuranceCompanyManager;
  31. use App\Manager\Rca\RcaManager;
  32. use App\Manager\Rca\RcaOfferManager;
  33. use App\Manager\Rca\RcaOfferV2Manager;
  34. use App\Manager\RoadAssistance\RoadAssistanceManager;
  35. use App\Model\ShopUserModel;
  36. use App\Model\VignetteCategoryModel;
  37. use App\Service\AddressService;
  38. use App\Service\AuthTokenService;
  39. use App\Service\CustomerService;
  40. use App\Service\EmailService;
  41. use App\Service\Log\LogEmailSendingService;
  42. use App\Service\LogService;
  43. use App\Service\RCAService;
  44. use App\Service\ReCaptcha;
  45. use App\Service\StaticPagesBitbagService;
  46. use App\Service\SystemService;
  47. use App\Validator\RCAVehicleDetailsFormValidator;
  48. use Symfony\Component\HttpFoundation\JsonResponse;
  49. use Symfony\Component\HttpFoundation\Request;
  50. use Symfony\Component\HttpFoundation\Response;
  51. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  52. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  53. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  54. use Symfony\Component\Serializer\Serializer;
  55. use Symfony\Contracts\Translation\TranslatorInterface;
  56. class RCAController extends BaseController
  57. {
  58.     public function getVehicleDetails(Request $request)
  59.     {
  60.         $reCaptcha = new ReCaptcha($_ENV['RECAPTCHA_INVISIBLE_SECRET']);
  61.         $response json_encode(array('error' => 1));
  62.         if ($reCaptcha->verify($request->get('token'), $request->getClientIp())->isSuccess()) {
  63.             $result null;
  64.             $partnerLimitless false;
  65.             $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  66.             $hashService $this->getContainer()->get('app.service.security.hash_generator');
  67.             $partnerPublicToken $request->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME);
  68.             $partnerService =  $this->getContainer()->get('app.service.partner.partner');
  69.             $partner $this->getEntityManager()->getRepository(Partner::class)
  70.                 ->findOneBy(array('publicToken' => $partnerPublicToken));
  71.             if ($hashService->isEncryptedValueValid($request->get('hash'))) {
  72.                 $vehicleRetrieverRestrictionService $this->getContainer()->get('app.service.vehicle_restriction');
  73.                 $apiVehicleDataService $this->getContainer()->get('app.service.api_vehicle_data');
  74.                 if ($savedCar $vehicleRetrieverRestrictionService->getSavedRcaCar()) {
  75.                     return new Response($savedCar);
  76.                 }
  77.                 $serializer $this->getContainer()->get('serializer');
  78.                 if ($partner && $partnerService->checkPartnerAccessRights($partner)) {
  79.                     $partnerLimitless $partner->hasAutocompleteLimitless();
  80.                 }
  81.                 if ($vehicleRetrieverRestrictionService->checkUserForRcaCarService($this->getUser(), $serializer) || $partnerLimitless) {
  82.                     if ($vehicleId $request->get('vehicleId')) {
  83.                         if (VehicleManager::checkIfVehicleIsEligibleForRcaByVehicleId($vehicleId$this->getEntityManager())) {
  84.                             $result $apiVehicleDataService->findVehicleInDatabaseAndFormatDataForUI($vehicleId);
  85.                         } else {
  86.                             $vehicleData VehicleManager::getRegistrationPlateAndVinByVehicleId($vehicleId$this->getEntityManager());
  87.                             $request->request->set('registrationPlate'$vehicleData['registrationPlate']);
  88.                             $request->request->set('vin'$vehicleData['vin']);
  89.                         }
  90.                     }
  91.                     if (!$result) {
  92.                         $result $apiVehicleDataService->findVehicleDetails($request->get('registrationPlate'), $request->get('vin'));
  93.                         $vehicleRetrieverRestrictionService->logNewEntryForRcaCarService();
  94.                         if ($partnerLimitless) {
  95.                             PartnerManager::updateRemainingAutocompleteLimit($partner$this->getEntityManager());
  96.                         }
  97.                         if ($result) {
  98.                             $response RCAService::retrieveCustomerDataByVehicleDetailIfAvailable($result$this->getEntityManager());
  99.                             $vehicleRetrieverRestrictionService->saveRcaCar($response);
  100.                         } else {
  101.                             $response json_encode(array('status' => 'Nu a fost gasit(a).'));
  102.                         }
  103.                     }
  104.                 } else {
  105.                     $response json_encode(array('limitReached' => true));
  106.                 }
  107.             }
  108.             $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  109.             $rcaTrackerActivityService->setVehicleDetailsSearched($customer$response);
  110.         }
  111.         return new Response($response);
  112.     }
  113.     public function getVehicleDetailsByVin(Request $request)
  114.     {
  115.         $reCaptcha = new ReCaptcha($_ENV['RECAPTCHA_INVISIBLE_SECRET']);
  116.         $response json_encode(array('error' => 1));
  117.         if ($reCaptcha->verify($request->get('token'), $request->getClientIp())->isSuccess()) {
  118.             $result null;
  119.             $partnerLimitless false;
  120.             $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  121.             $hashService $this->getContainer()->get('app.service.security.hash_generator');
  122.             $partnerPublicToken $request->get('partnerPublicToken');
  123.             $partnerService =  $this->getContainer()->get('app.service.partner.partner');
  124.             $partner $this->getEntityManager()->getRepository(Partner::class)
  125.                 ->findOneBy(array('publicToken' => $partnerPublicToken));
  126.             if ($hashService->isEncryptedValueValid($request->get('hash'))) {
  127.                 $vehicleRetrieverRestrictionService $this->getContainer()->get('app.service.vehicle_restriction');
  128.                 $apiVehicleDataService $this->getContainer()->get('app.service.api_vehicle_data');
  129.                 $serializer $this->getContainer()->get('serializer');
  130.                 if ($partner && $partnerService->checkPartnerAccessRights($partner)) {
  131.                     $partnerLimitless $partner->hasAutocompleteLimitless();
  132.                 }
  133.                 if ($vehicleRetrieverRestrictionService->checkUserForRcaCarService($this->getUser(), $serializer) || $partnerLimitless) {
  134.                     if (!$result) {
  135.                         $result $apiVehicleDataService->findVehicleDetailsWsByVin($request->get('registrationPlate'), $request->get('vin'));
  136.                         $vehicleRetrieverRestrictionService->logNewEntryForRcaCarService();
  137.                         if ($partnerLimitless) {
  138.                             PartnerManager::updateRemainingAutocompleteLimit($partner$this->getEntityManager());
  139.                         }
  140.                         if ($result) {
  141.                             $response RCAService::retrieveCustomerDataByVehicleDetailIfAvailable($result$this->getEntityManager());
  142.                             $vehicleRetrieverRestrictionService->saveRcaCar($response);
  143.                         } else {
  144.                             $response json_encode(array('status' => 'Nu a fost gasit(a).'));
  145.                         }
  146.                     }
  147.                 } else {
  148.                     $response json_encode(array('limitReached' => true));
  149.                 }
  150.             }
  151.             $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  152.             $rcaTrackerActivityService->setVehicleDetailsSearched($customer$response);
  153.         }
  154.         return new Response($response);
  155.     }
  156.     public function detailsAction(Request $requestTranslatorInterface $translator)
  157.     {
  158.         $rcaData = [];
  159.         $historyRca = [];
  160.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  161.         $trackerActivityService $this->getContainer()->get('app.service.customer.tracker_activity');
  162.         $trackerActivityService->startTracking($customer);
  163.         $vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
  164.         $render '@templates/RcaApp/Front/homepage.html.twig';
  165.         if ($this->isMobile) {
  166.             $render '@templates/RcaApp/Mobile/homepage.html.twig';
  167.         }
  168.         $request->getSession()->remove('iframeSourceLink');
  169.         $leasingCompanies $this->getDoctrine()
  170.             ->getRepository(LeasingCompany::class)->findAll();
  171.         $country $this->getDoctrine()->getRepository(Country::class)->findOneBy(array('code' => 'RO'));
  172.         $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  173.         if ($request->get('modalVehicleId') && $customer) {
  174.             $rcaData RCAService::retrieveRcaDataByModalVehicleId($customer$request$this->getEntityManager());
  175.             $request->getSession()->remove('rcaVehicle');
  176.             $request->getSession()->remove('rcaCustomerData');
  177.         } else {
  178.             $historyRca HistoryRcaManager::validateHistoryRca($request->getSession()->get('historyRca'));
  179.             RCAService::checkRcaSession($request);
  180.         }
  181.         $hashGeneratorService $this->getContainer()->get('app.service.security.hash_generator');
  182.         return $this->render($render, [
  183.             'vignetteCategories' => $vignetteCategories,
  184.             'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY '-' date('Y')),
  185.             'customerVehicleOrderByOptions' => VehicleManager::getCustomerVehicleOrderByOptions(),
  186.             'customerVehicleSearchByFields' => VehicleManager::getCustomerVehicleSearchByFields(),
  187.             'historyRca' => $historyRca ?: [],
  188.             'countyList' => $this->getDoctrine()->getRepository(County::class)->findAllCountiesByCountryAsArray($country),
  189.             'vehicleTypeList' => $this->getDoctrine()->getRepository(VehicleType::class)->findAllAsArrayForUI(),
  190.             'rcaMappedCategoryList' => $this->getDoctrine()->getRepository(MappedCategory::class)->findAllAsArray(),
  191.             'defaultMakeList' => $this->getDoctrine()->getRepository(MappedVehicleMake::class)->findByVehicleMappedCategoryAsArray(MappedCategory::MAPPED_CATEGORY_VEHICLE),
  192.             'availabilityList' => $this->getDoctrine()->getRepository(Availability::class)->findAllAsArray(),
  193.             'availabilityIntervalList' => RcaManager::getAvailabilityIntervalList(),
  194.             'insuranceCompanyList' => $this->getDoctrine()->getRepository(InsuranceCompany::class)->findAllOnlyNameOrderedByPositionAsArray(),
  195.             'fuelTypeList' => $this->getDoctrine()->getRepository(FuelType::class)->findAllAsArray(),
  196.             'usageTypeList' => $this->getDoctrine()->getRepository(UsageType::class)->findAllAsArray(),
  197.             'leasingCompanyList' => $this->getDoctrine()->getRepository(LeasingCompany::class)->findAllAsArray(),
  198.             'leasingCompanies' => $leasingCompanies,
  199.             'step' => $request->get('step'),
  200.             'haveOldVehicleValues' => (bool)$request->getSession()->get('rcaVehicle'),
  201.             'haveOldCustomerValues' => (bool)$request->getSession()->get('rcaCustomerData'),
  202.             'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getEntityManager()),
  203.             'accordionBlocksAboutRca' => StaticPagesBitbagService::getAllFilteredBlocksAsArray($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_RCA_CODE_PATTERN),
  204.             'roadAssistanceDefaultPrice' => $roadAssistanceService->retrieveDefaultPrice(),
  205.             'roadAssistanceTranslations' => RoadAssistanceManager::getTranslationsForUI($translator),
  206.             'hash' => $hashGeneratorService->getHash(),
  207.             'recaptchaSiteKey' => $_ENV['RECAPTCHA_INVISIBLE_KEY'],
  208.             'oldVehicle' => $rcaData $rcaData['oldVehicle'] : $request->get('oldVehicle'),
  209.             'oldCustomer' => $rcaData $rcaData['oldCustomer'] : $request->get('oldCustomer'),
  210.             'oldOffer' => $rcaData $rcaData['oldOffer'] : $request->get('oldOffer'),
  211.             'canIssueRoadAssistance' => true,
  212.         ]);
  213.     }
  214.     public function vehicleDetailsAction(Request $request)
  215.     {
  216.         return $this->redirectToRoute('app_shop_rca_details');
  217.     }
  218.     public function vehicleDetailsFormSubmitAction(Request $requestTranslatorInterface $translator): Response
  219.     {
  220.         $errors null;
  221.         $session $request->getSession();
  222.         $isMobile false;
  223.         if ($request->request->has('isMobile')) {
  224.             $isMobile $request->get('isMobile') == 'true';
  225.         }
  226.         $rcaVehicleDetailsFormValidator = new RCAVehicleDetailsFormValidator($this->getEntityManager(), $this->getSerializer(), $isMobile);
  227.         if ($rcaVehicleDetailsFormValidator->checkForm($request)) {
  228.             if ($request->get('vehicleType') != VehicleType::VEHICLE_REGISTRATION_TYPE_FOR_REGISTRATION) {
  229.                 $request->request->set('registrationPlate'RCAService::validateAndFormatRegistrationPlate($request->get('registrationPlate')));
  230.             }
  231.             $rcaAlreadyActive RCAService::checkRcaAvailability($request$this->getEntityManager());
  232.             if (!$rcaAlreadyActive) {
  233.                 $errors json_encode(array('success' => true));
  234.                 if (RoadAssistanceManager::isVehicleEligibleForRoadAssistance($request->request->all(), true)
  235.                     && !RoadAssistanceManager::haveAnActiveRoadAssistanceForRegistrationPlate($request$this->getEntityManager())) {
  236.                     $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  237.                     $roadAssistanceResponse $roadAssistanceService->storeNewRoadAssistanceInCart(RoadAssistance::FLAG_SOURCE_EXTRA_OPTIONtrue);
  238.                     if (!$roadAssistanceResponse['success']) {
  239.                         if ($roadAssistanceResponse['errorCode']) {
  240.                             $this->addFlash('error'SystemService::retrieveMessage($roadAssistanceResponse['errorCode'], $translator));
  241.                         }
  242.                     }
  243.                 }
  244.             } else {
  245.                 $errors json_encode(array('already_an_active_rca' => 1'active_rca_valid_until' => $rcaAlreadyActive));
  246.             }
  247.         } else {
  248.             if ($session->has('rcaVehicleDetailsErrors')) {
  249.                 $errors $session->get('rcaVehicleDetailsErrors');
  250.             }
  251.         }
  252.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  253.         $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  254.         $rcaTrackerActivityService->setVehicleDetailsSubmitted($customer$errors);
  255.         return new Response($errors);
  256.     }
  257.     public function getVehicleSubCategoryByCategoryAction(Request $request): Response
  258.     {
  259.         $vehicleSubCategoryRepository $this->getDoctrine()->getRepository(SubCategory::class);
  260.         $vehicleCategoryId $request->get('vehicleCategoryId');
  261.         $vehicleSubCategory null;
  262.         if ($vehicleCategoryId != null) {
  263.             $encoders = [new JsonEncoder()];
  264.             $normalizers = [new ObjectNormalizer()];
  265.             $serializer = new Serializer($normalizers$encoders);
  266.             $vehicleSubCategory $vehicleSubCategoryRepository->findByCategoryId($vehicleCategoryId);
  267.             $vehicleSubCategory $serializer->serialize($vehicleSubCategory'json', [
  268.                 'circular_reference_handler' => function ($object) {
  269.                     return $object->getId();
  270.                 }
  271.             ]);
  272.         }
  273.         return new Response($vehicleSubCategory200, ['Content-Type' => 'application/json']);
  274.     }
  275.     /**
  276.      * @param Request $request
  277.      * @return Response
  278.      */
  279.     public function issueRcaManually(Request $request): Response
  280.     {
  281.         $response json_encode('fail');
  282.         $rcaId $request->get('rca') ?? $request->get('rcaId');
  283.         if ($rcaId) {
  284.             $rcaItem $this->getEntityManager()->getRepository(RCA::class)->find($rcaId);
  285.             if ($rcaItem) {
  286.                 $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  287.                 if ($rcaIssueService->issueRcaItem($rcaItem)) {
  288.                     if ($rcaIssueService->sendRcaToCustomer($rcaItem$this->getContainer()->get('twig'))) {
  289.                         $response json_encode('success');
  290.                     }
  291.                 }
  292.             }
  293.         }
  294.         return new Response($response);
  295.     }
  296.     /**
  297.      * @param Request $request
  298.      * @return Response
  299.      */
  300.     public function deactivateRca(Request $request): Response
  301.     {
  302.         $response = [
  303.             'status' => 'fail',
  304.             'message' => 'A apărut o eroare neprevăzută.'
  305.         ];
  306.         $rcaId $request->get('rcaId');
  307.         $userId $request->get('userId') ?? 0;
  308.         if ($rcaId) {
  309.             $rcaItem $this->getEntityManager()->getRepository(RCA::class)->find($rcaId);
  310.             if ($rcaItem) {
  311.                 $result RCAService::deactivateRcaAndCustomerVehicleRcaValidUntil($rcaItem$userId$this->getEntityManager());
  312.                 if ($result['status']) {
  313.                     $response['status'] = 'success';
  314.                     $response['message'] = $result['message'];
  315.                 } else {
  316.                     $response['message'] = $result['message'];
  317.                 }
  318.             } else {
  319.                 $response['message'] = 'PoliÈ›a nu a fost gasita';
  320.             }
  321.         }
  322.         return new Response(json_encode($response));
  323.     }
  324.     public function offerAction(Request $request)
  325.     {
  326.         $session $request->getSession();
  327.         $session->remove('rcaOffers');
  328.         $session->remove('rcaOfferParams');
  329.         $render '@templates/Front/rca-offers.html.twig';
  330.         if ($this->isMobile) {
  331.             $render '@templates/Mobile/rca-offers.html.twig';
  332.         }
  333.         $availabilityId InsuranceCompanyManager::retrieveAvailabilityIdFromSession($request->getSession(), $this->getEntityManager());
  334.         $insuranceCompanies InsuranceCompanyManager::getAllActiveInsuranceCompaniesForSelection($this->getEntityManager(), $availabilityId);
  335.         return $this->render($render, [
  336.             'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getEntityManager()),
  337.             'insuranceCompanies' => $insuranceCompanies
  338.         ]);
  339.     }
  340.     public function retrieveInsuranceCompanies()
  341.     {
  342.         return new Response(json_encode($this->getDoctrine()
  343.             ->getRepository(InsuranceCompany::class)->findAllOnlyNameOrderedByPosition()));
  344.     }
  345.     public function retrieveActiveInsuranceCompanies(Request $request)
  346.     {
  347.         return new Response(json_encode(InsuranceCompanyManager::getAllActiveInsuranceCompaniesForSelection($this->getEntityManager(), $request->get('availabilityId'))));
  348.     }
  349.     public function getOffers(Request $request)
  350.     {
  351.         $insuranceCompany $request->get('insuranceCompany');
  352.         $result json_encode(array('fail' => true));
  353.         if ($insuranceCompany) {
  354.             $session $request->getSession();
  355.             $offers = new \stdClass();
  356.             if ($session->has('rcaOffers')) {
  357.                 $offers json_decode($session->get('rcaOffers'));
  358.             }
  359.             $findOffer true;
  360.             if (!empty($offers)) {
  361.                 foreach ($offers as $key => $offer) {
  362.                     if ($key == $insuranceCompany) {
  363.                         $findOffer false;
  364.                     }
  365.                 }
  366.             }
  367.             if ($findOffer) {
  368.                 $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  369.                 if ($session->has('rcaOfferParams')) {
  370.                     $params $session->get('rcaOfferParams');
  371.                 } else {
  372.                     $params $rcaIssueService->setParamsForOffers($request$insuranceCompany);
  373.                     $session->set('rcaOfferParams'$params);
  374.                 }
  375.                 $offerWithDeductedPrice $rcaIssueService
  376.                     ->getOfferWithDeductedPriceByInsuranceCompanyName($params$insuranceCompany$request->request->all());
  377.                 $offerWithoutDeductedPrice $rcaIssueService
  378.                     ->getOfferWithoutDeductedPriceByInsuranceCompanyName($params$insuranceCompany$request->request->all());
  379.                 $offers->$insuranceCompany = array('offerWithDeductedPrice' => $offerWithDeductedPrice,
  380.                     'offerWithoutDeductedPrice' => $offerWithoutDeductedPrice);
  381.                 $session->set('rcaOffers'json_encode($offers));
  382.                 $result json_encode(array('offerWithDeductedPrice' => $offerWithDeductedPrice,
  383.                     'offerWithoutDeductedPrice' => $offerWithoutDeductedPrice));
  384.             } else {
  385.                 $result json_encode(array('offerWithDeductedPrice' => $offers->$insuranceCompany->offerWithDeductedPrice,
  386.                     'offerWithoutDeductedPrice' => $offers->$insuranceCompany->offerWithoutDeductedPrice));
  387.             }
  388.             LogService::checkRcaOfferErrorAndStoreItIfNew($result$this->getEntityManager(), $request$this->getUser(), $params);
  389.         }
  390.         return new Response($result);
  391.     }
  392.     public function getOfferWithVue(Request $request)
  393.     {
  394.         $offers = array();
  395.         $data $request->request->all();
  396.         $insuranceCompany $data['insuranceCompany'];
  397.         $quotationType $data['quotationType'];
  398.         $offersRequestUuid $data['offersRequestUuid'];
  399.         $quotationTypeName RcaOfferManager::getQuotationTypeNameById($quotationType);
  400.         $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  401.         $data['comision'] = $rcaIssueService->setDiscountCommission($request);
  402.         $data['vehicle']['validFrom'] = RcaOfferManager::checkVehicleValidFromData($data['vehicle']['validFrom']);
  403.         $firstAvailability $data['availabilityInterval'] != RcaManager::RCA_AVAILABILITY_OTHER_INTERVAL_VALUE ?
  404.             RcaManager::getFirstAvailabilityValueOfAvailabilityInterval($data['availabilityInterval']) : $data['vehicle']['availability'];
  405.         $params $rcaIssueService->setParamsForOffersWithVue($data);
  406.         if ($rcaIssueService->isOfferEnabledForInsuranceCompanyAndSelectedAvailability($insuranceCompany['id'], $firstAvailability)) {
  407.             $params['product']['motor']['termTime'] = $firstAvailability;
  408.             $offer $rcaIssueService->getOfferByInsuranceCompanyName($params$insuranceCompany$data);
  409.             $result json_encode(array($quotationTypeName => $offer));
  410.             LogService::checkRcaOfferErrorAndStoreItIfNew($result$this->getEntityManager(), $request$this->getUser(), $params$firstAvailability$offersRequestUuid);
  411.             $offers[$firstAvailability][$quotationTypeName]
  412.                 = RcaOfferV2Manager::formatWsOfferResponse($offer, (bool)$quotationType);
  413.         } else {
  414.             $offers[$firstAvailability][$quotationTypeName]
  415.                 = RcaOfferManager::getUnavailableMessageForInsuranceCompanyAndSelectedAvailability($insuranceCompany['name'], $firstAvailability);
  416.         }
  417.         //get Second interval as well if requested
  418.         if ($data['availabilityInterval'] != RcaManager::RCA_AVAILABILITY_OTHER_INTERVAL_VALUE) {
  419.             $secondAvailability RcaManager::getSecondAvailabilityValueOfAvailabilityInterval($data['availabilityInterval']);
  420.             $params['product']['motor']['termTime'] = $secondAvailability;
  421.             if ($rcaIssueService->isOfferEnabledForInsuranceCompanyAndSelectedAvailability($insuranceCompany['id'], $secondAvailability)) {
  422.                     $offer $rcaIssueService->getOfferByInsuranceCompanyName($params$insuranceCompany$data) ;
  423.                     $result json_encode(array($quotationTypeName => $offer));
  424.                     LogService::checkRcaOfferErrorAndStoreItIfNew($result$this->getEntityManager(), $request$this->getUser(), $params$secondAvailability$offersRequestUuid);
  425.                     $offers[$secondAvailability][$quotationTypeName]
  426.                         = RcaOfferV2Manager::formatWsOfferResponse($offer, (bool)$quotationType);
  427.             } else {
  428.                 $offers[$secondAvailability][$quotationTypeName]
  429.                     = RcaOfferManager::getUnavailableMessageForInsuranceCompanyAndSelectedAvailability($insuranceCompany['name'], $secondAvailability);
  430.             }
  431.         }
  432.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  433.         $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  434.         $paramsAsArray json_decode(json_encode($params), true);
  435.         $rcaTrackerActivityService->setOffers($customer$paramsAsArray$offers);
  436.         return new Response(json_encode($offers));
  437.     }
  438.     public function initLogMappingWithVue(Request $request) {
  439.         $data $request->request->all();
  440.         $data['insuranceCompany']['name'] = RCA::INSURANCE_COMPANY_GRAWE_NAME;
  441.         $data['comision'] = 0;
  442.         $firstAvailability $data['availabilityInterval'] != RcaManager::RCA_AVAILABILITY_OTHER_INTERVAL_VALUE ?
  443.             RcaManager::getFirstAvailabilityValueOfAvailabilityInterval($data['availabilityInterval']) : $data['vehicle']['availability'];
  444.         $secondAvailability $data['availabilityInterval'] != RcaManager::RCA_AVAILABILITY_OTHER_INTERVAL_VALUE ?
  445.             RcaManager::getSecondAvailabilityValueOfAvailabilityInterval($data['availabilityInterval']) : $data['vehicle']['availability'];
  446.         $offersRequestUuid $data['offersRequestUuid'];
  447.         $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  448.         $params $rcaIssueService->setParamsForOffersWithVue($data);
  449.         LogService::initLogMapping($this->getEntityManager(), $request$this->getUser(), $params$firstAvailability$offersRequestUuid);
  450.         LogService::initLogMapping($this->getEntityManager(), $request$this->getUser(), $params$secondAvailability$offersRequestUuid);
  451.         return new Response(json_encode(array('status' => 'success')));
  452.     }
  453.     public function getCountyFromRegistrationPlate(Request $request)
  454.     {
  455.         $data $request->request->all();
  456.         if(!empty($data['code'])) {
  457.             $county $this->getDoctrine()->getRepository(County::class)->findByCode($data['code']);
  458.             $countyName $county->getName();
  459.         }
  460.         if(!empty($countyName)) {
  461.             return new Response(json_encode(array('status' => 'success''county_name' => $countyName)));
  462.         }
  463.         return new Response(json_encode(array('status' => 'fail')));
  464.     }
  465.     public function offerSubmitAction(Request $request)
  466.     {
  467.         $response RCAService::retrieveSelectedOfferItemAndStoreIt($request);
  468.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  469.         $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  470.         $rcaTrackerActivityService->setOfferSubmitted($customer, ['is_stored' => $response]);
  471.         return new Response(json_encode(array('isStored' => $response)));
  472.     }
  473.     public function removeRcaFromCart(Request $request)
  474.     {
  475.         $response json_encode(array('status' => 'fail'));
  476.         $key $request->get('key');
  477.         $session $request->getSession();
  478.         if ($rcaGlobalOrder CartManager::getCartData($session'rcaGlobalOrder')) {
  479.             foreach ($rcaGlobalOrder as $indexKey => $rca) {
  480.                 if ($key == $indexKey) {
  481.                     RoadAssistanceManager::removeRoadAssistanceFromRca($rca$session);
  482.                     unset($rcaGlobalOrder[$key]);
  483.                 }
  484.             }
  485.             $rcaGlobalOrder array_values($rcaGlobalOrder);
  486.             CartManager::setToCart($session'rcaGlobalOrder'$rcaGlobalOrder);
  487.             $response json_encode(array('status' => 'success'));
  488.         }
  489.         return new Response($response);
  490.     }
  491.     public function setCustomerDataAction(Request $request)
  492.     {
  493.         $params $request->request->all();
  494.         $rcaService = new RCAService();
  495.         $validations $rcaService->identifyRcaTypeAndValidateVueData($params);
  496.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  497.         $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  498.         $rcaTrackerActivityService->setCustomerDetailsSubmitted($customer$validations->getContent());
  499.         return new Response($validations->getContent());
  500.     }
  501.     public function replaceDiacriticsCustomerDataAction(Request $request)
  502.     {
  503.         $params $request->request->all();
  504.         $response RcaManager::replaceDiacriticsCustomerForm($params);
  505.         return new Response(json_encode($response));
  506.     }
  507.     public function showRcaAction(Request $request)
  508.     {
  509.         $id $request->get('id');
  510.         $order $this->getDoctrine()->getRepository(Order::class)->find($id);
  511.         if ($order->hasRca()) {
  512.             $rca $order->getRca();
  513.             foreach ($rca as $rcaItem) {
  514.                 if ($rcaItem && $rcaItem->getWsOfferId() && $rcaItem->getSeries()) {
  515.                     $rcaApiService $this->getContainer()->get('app.rca.issue.service');
  516.                     $pdf $rcaApiService->getPdf($rcaItem->getWsOfferId(), $rcaItem->getWsPolicyId());
  517.                     $pdf base64_decode($pdf);
  518.                     header('Content-Type: application/pdf');
  519.                     echo $pdf;
  520.                     die();
  521.                 }
  522.             }
  523.         }
  524.         echo "<script>window.close();</script>";
  525.         return new Response('success');
  526.     }
  527.     public function getVehicleMakeByCategoryAction(Request $request): Response
  528.     {
  529.         $vehicleMakeRepository $this->getDoctrine()->getRepository(MappedVehicleMake::class);
  530.         $vehicleCategoryId $request->get('vehicleCategoryId');
  531.         $vehicleMake null;
  532.         if ($vehicleCategoryId != null) {
  533.             $vehicleMake $vehicleMakeRepository->findByVehicleMappedCategoryAsArray($vehicleCategoryId);
  534.         }
  535.         return new Response(json_encode($vehicleMake));
  536.     }
  537.     public function getVehicleModelsByMakeAction(Request $request): Response
  538.     {
  539.         $vehicleModelsRepository $this->getDoctrine()->getRepository(MappedVehicleModel::class);
  540.         $vehicleMakeId $request->get('vehicleMakeId');
  541.         $vehicleModel null;
  542.         if ($vehicleMakeId) {
  543.             $vehicleModel $vehicleModelsRepository->findByMakeIdAsArray($vehicleMakeId);
  544.         }
  545.         return new Response(json_encode($vehicleModel));
  546.     }
  547.     public function autoLoginRcaClient(Request $request)
  548.     {
  549.         $redirect $this->generateUrl('sylius_shop_homepage');
  550.         RCAService::removeRcaProcessSession($request);
  551.         $authTokenService = new AuthTokenService();
  552.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  553.             $registrationNumber $request->get('registrationNumber');
  554.             $this->get('security.token_storage')->setToken($token);
  555.             $event = new InteractiveLoginEvent($request$token);
  556.             $this->dispatcher->dispatch($event'security.interactive_login');
  557.             $session $request->getSession();
  558.             $session->set('_sylius.cart.FASHION_WEB'180);
  559.             $session->save();
  560.             $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  561.             $commercialNotificationService $this->getContainer()->get('app.service.customer.commercial_notification');
  562.             $commercialNotificationService->markCustomerAsDoubleOptin($customer$request->getClientIp());
  563.             $params $request->query->all();
  564.             $params RcaManager::formatUrlParams($params);
  565.             $params['from'] = TrackerActivity::FROM_COMMERCIAL_NOTIFICATION;
  566.             $params['step'] = TrackerActivity::STEP_VEHICLE;
  567.             $validFrom RcaManager::getValidFromForAutologin($request->get('validUntil'));
  568.             $params['validFrom'] = $validFrom;
  569.             $redirect $this->generateUrl('app_shop_rca_details'$params);
  570.         }
  571.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  572.             'url' => $redirect,
  573.         ]);
  574.     }
  575.     public function checkRcaAvailabilityAction(Request $request)
  576.     {
  577.         if ($rcaAlreadyActive RCAService::checkRcaAvailability($request$this->getEntityManager())) {
  578.             $response json_encode(array('already_an_active_rca' => 1'active_rca_valid_until' => $rcaAlreadyActive));
  579.         } else {
  580.             $response json_encode(array('already_an_active_rca' => 0));
  581.         }
  582.         return new Response($response);
  583.     }
  584.     public function retrieveCustomerInfoAction(Request $request)
  585.     {
  586.         $customerInfo RCAService::checkForCustomerInfoDetails($request$this->getUser(), $this->getEntityManager());
  587.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  588.         $vignettesRepository $this->getDoctrine()->getRepository(Vignette::class);
  589.         if (!$customerInfo && $customer) {
  590.             $address $this->getDoctrine()->getRepository(Address::class)->findLastLegalAddressForCustomer($customer->getId());
  591.             if ($address && $address->getCountryCode() == Country::RO_COUNTRY_CODE && $address->getCifCode()) {
  592.                 $customerInfo['isLeasing'] = false;
  593.                 $customerInfo['isLegalPerson'] = true;
  594.                 $customerInfo['cifCode'] = $address->getCifCode();
  595.                 $customerInfo['companyName'] = $address->getCompanyName();
  596.             } elseif ($lastVignetteAddress $vignettesRepository->getLastSimpleCustomerAddressByCustomer($customer)) {
  597.                 $vignetteAddress $lastVignetteAddress->getOrder()->getBillingAddress();
  598.                 $customerInfo AddressService::formatAddressDataSimpleCustomerForRca($vignetteAddress$this->getEntityManager());
  599.             }
  600.         }
  601.         if(!empty($request->get('countyCode')) && !$customerInfo['isLeasing'] && !$customerInfo['isLegalPerson'] ) {
  602.             $filledCountyCode $this->getDoctrine()->getRepository(County::class)->findCodeById($customerInfo['county']);
  603.             $hasDifferentCounty = !empty($filledCountyCode) && ($filledCountyCode !== $request->get('countyCode'));
  604.             if(!empty($hasDifferentCounty)) {
  605.                 $customerInfo = [];
  606.                 return new Response(json_encode($customerInfo));
  607.             }
  608.         }
  609.         $rcaTrackerActivityService $this->getContainer()->get('app.service.rca.tracker_activity');
  610.         $rcaTrackerActivityService->setCustomerInfoRetrieved($customer$customerInfo);
  611.         return new Response(json_encode($customerInfo));
  612.     }
  613.     public function retrieveAvailabilityInfoAction(Request $request)
  614.     {
  615.         $availabilityInfo RCAService::checkForAvailabilityInfoDetails($request$this->getEntityManager());
  616.         return new Response(json_encode($availabilityInfo));
  617.     }
  618.     public function checkRcaAlreadyInCart(Request $request)
  619.     {
  620.         $alreadyInCart RCAService::checkAlreadyInCart($request);
  621.         return new Response(json_encode(array('already_in_cart' => $alreadyInCart)));
  622.     }
  623.     public function retrieveOfferErrorMessage(Request $request)
  624.     {
  625.         $offer $request->get('offer');
  626.         return new Response(json_encode(RCAService::getErrorMessageForOfferDeductedPrice($offer)));
  627.     }
  628.     public function showRcaPolicy(Request $request)
  629.     {
  630.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  631.         $rca $this->getDoctrine()->getRepository(RCA::class)
  632.             ->findOneBy(array('wsOfferId' => $request->get('wsOfferId')));
  633.         if ($rca && $rca->getCustomer()->getId() == $customer->getId()) {
  634.             $rcaApiService $this->getContainer()->get('app.rca.issue.service');
  635.             $pdf $rcaApiService->getPdf($rca->getWsOfferId(), $rca->getWsPolicyId());
  636.             $pdf base64_decode($pdf);
  637.             header('Content-Type: application/pdf');
  638.             echo $pdf;
  639.         }
  640.         return new Response('error');
  641.     }
  642.     public function showRcaPolicyForPartner(Request $request)
  643.     {
  644.         $id $request->get('order_id');
  645.         $id base64_decode($id);
  646.         $order $this->getDoctrine()->getRepository(Order::class)->find($id);
  647.         if ($order->hasRca()) {
  648.             $rca $order->getRca();
  649.             foreach ($rca as $rcaItem) {
  650.                 if ($rcaItem && $rcaItem->getWsOfferId() && $rcaItem->getSeries()) {
  651.                     $rcaApiService $this->getContainer()->get('app.rca.issue.service');
  652.                     $pdf $rcaApiService->getPdf($rcaItem->getWsOfferId(), $rcaItem->getWsPolicyId());
  653.                     $pdf base64_decode($pdf);
  654.                     header('Content-Type: application/pdf');
  655.                     echo $pdf;
  656.                 }
  657.             }
  658.         }
  659.         return new Response('error');
  660.     }
  661.     public function storeDataInSessionAndInVehicleList(Request $request)
  662.     {
  663.         $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  664.         $rcaIssueService->storeDataInSessionHistory($request);
  665.         $rcaIssueService->storeDataInVehicleList($request$this->getUser());
  666.         return new Response(json_encode(array('status' => 1)));
  667.     }
  668.     public function deleteItemFromSession(Request $request)
  669.     {
  670.         $rcaIssueService $this->getContainer()->get('app.rca.issue.service');
  671.         $rcaIssueService->deleteItemFromSessionHistory($request);
  672.         return new Response(json_encode(array('status' => 1)));
  673.     }
  674.     public function addToCartWithOfferCode(Request $request)
  675.     {
  676.         $authTokenService = new AuthTokenService();
  677.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  678.             $this->get('security.token_storage')->setToken($token);
  679.             $event = new InteractiveLoginEvent($request$token);
  680.             $this->dispatcher->dispatch($event'security.interactive_login');
  681.             $session $request->getSession();
  682.             $session->set('_sylius.cart.FASHION_WEB'180);
  683.             $session->save();
  684.         }
  685.         $utm = [
  686.             'utm_source' => $request->get('utm_source'),
  687.             'utm_medium' => $request->get('utm_medium'),
  688.             'utm_campaign' => $request->get('utm_campaign'),
  689.             'utm_term' => $request->get('utm_term'),
  690.             'utm_content' => $request->get('utm_content'),
  691.             'utm_id' => $request->get('utm_id')
  692.         ];
  693.         $offer RcaOfferManager::retrieveOfferFromDb($request->get('code'), $this->getEntityManager());
  694.         if ($offer) {
  695.             if (!RcaOfferManager::isOfferExpired($offer) && !in_array($request->get('insurance_id'), [56])) {
  696.                 RCAService::addRcaToCartFromOffer($offer$request);
  697.                 $url $this->generateUrl('app_shop_customer_info'$utm);
  698.             } else {
  699.                 $oldVehicle $offer->getRequest()['vehicle'];
  700.                 if (is_int($oldVehicle['make']['name'])){
  701.                     $oldVehicle['make']['name'] = $this->getEntityManager()->getRepository(MappedVehicleMake::class)->find($oldVehicle['make']['id'])->getName();
  702.                 }
  703.                 $oldVehicle['validFrom'] = RcaOfferManager::checkVehicleValidFromData($oldVehicle['validFrom']);
  704.                 $utm['step'] = 'offer';
  705.                 $url $this->generateUrl('app_shop_rca_details', [
  706.                     'oldVehicle' => $oldVehicle,
  707.                     'oldCustomer' => $offer->getRequest()['customer'],
  708.                     'oldOffer' => $offer->getData(),
  709.                     ] + $utm);
  710.             }
  711.         } else {
  712.             $url $this->generateUrl('app_shop_rca_details'$utm);
  713.         }
  714.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  715.             'url' => $url,
  716.         ]);
  717.     }
  718.     public function showCartWithToken(Request $request)
  719.     {
  720.         $authTokenService = new AuthTokenService();
  721.         if ($token $authTokenService->authenticateUserWithToken($request$this->getEntityManager())) {
  722.             $this->get('security.token_storage')->setToken($token);
  723.             $event = new InteractiveLoginEvent($request$token);
  724.             $this->dispatcher->dispatch($event'security.interactive_login');
  725.             $session $request->getSession();
  726.             $session->set('_sylius.cart.FASHION_WEB'180);
  727.             $session->save();
  728.         }
  729.         $url $this->generateUrl('app_shop_customer_info');
  730.         return $this->render('@templates/ShopCustom/Redirect/wait_to_be_redirected.html.twig',[
  731.             'url' => $url,
  732.         ]);
  733.     }
  734.     public function rcaIframe(Request $requestTranslatorInterface $translator)
  735.     {
  736.         $session $request->getSession();
  737.         $partnerService $this->getContainer()->get('app.service.partner.partner');
  738.         $partnerService->verifyToken($requestPartnerManager::CAN_ISSUE_RCA_INDEX);
  739.         $partner $partnerService
  740.             ->retrievePartner($request->getSession()->get(PartnerManager::SESSION_PARTNER_PUBLIC_TOKEN_NAME));
  741.         $partnerRole $partner->getRole();
  742.         $token['partnerPublicToken'] = $partner->getPublicToken();
  743.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  744.         $trackerActivityService $this->getContainer()->get('app.service.customer.tracker_activity');
  745.         $trackerActivityService->startTracking($customer);
  746.         $vignetteCategories = (new VignetteCategoryModel($this->getEntityManager()))->getAllCategories();
  747.         $request->get('extOrderId') ? $rcaData RCAService::retrieveRcaDataForIframeByOrderId($partner$request$this->getEntityManager()) : $rcaData = [];
  748.         $render '@templates/RcaApp/Front/iframe.html.twig';
  749.         if ($this->isMobile) {
  750.             $render '@templates/RcaApp/Mobile/iframe.html.twig';
  751.         }
  752.         $request->getSession()->set('iframeSourceLink'$this->generateUrl('app_shop_rca_iframe'$token));
  753.         if ($partner->getWithoutLocalStorage()) {
  754.             RCAService::removeRcaProcessSession($request);
  755.             CartManager::removeAllProductsFromCartBySession($session);
  756.         } else {
  757.             RCAService::checkRcaSession($request);
  758.         }
  759.         PartnerManager::checkQRCodeFlow($request);
  760.         $leasingCompanies $this->getDoctrine()
  761.             ->getRepository(LeasingCompany::class)->findAll();
  762.         $country $this->getDoctrine()->getRepository(Country::class)->findOneBy(array('code' => 'RO'));
  763.         $roadAssistanceService $this->getContainer()->get('app.service.road_assistance.road_assistance');
  764.         $historyRca HistoryRcaManager::validateHistoryRca($request->getSession()->get('historyRca'));
  765.         $hashGeneratorService $this->getContainer()->get('app.service.security.hash_generator');
  766.         return $this->render($render, [
  767.             'vignetteCategories' => $vignetteCategories,
  768.             'isOneYearHuVignetteAvailableThisYear' => new \DateTime <= new \DateTime(HuVignetteManager::LAST_DATE_FOR_ONE_YEAR_HU_VIGNETTE_AVAILABILITY '-' date('Y')),
  769.             'customerVehicleOrderByOptions' => VehicleManager::getCustomerVehicleOrderByOptions(),
  770.             'customerVehicleSearchByFields' => VehicleManager::getCustomerVehicleSearchByFields(),
  771.             'historyRca' => $historyRca ?: [],
  772.             'countyList' => $this->getDoctrine()->getRepository(County::class)->findAllCountiesByCountryAsArray($country),
  773.             'vehicleTypeList' => $this->getDoctrine()->getRepository(VehicleType::class)->findAllAsArrayForUI(),
  774.             'rcaMappedCategoryList' => $this->getDoctrine()->getRepository(MappedCategory::class)->findAllAsArray(),
  775.             'defaultMakeList' => $this->getDoctrine()->getRepository(MappedVehicleMake::class)->findByVehicleMappedCategoryAsArray(MappedCategory::MAPPED_CATEGORY_VEHICLE),
  776.             'availabilityList' => $this->getDoctrine()->getRepository(Availability::class)->findAllAsArray(),
  777.             'availabilityIntervalList' => RcaManager::getAvailabilityIntervalList(),
  778.             'insuranceCompanyList' => $this->getDoctrine()->getRepository(InsuranceCompany::class)->findAllOnlyNameOrderedByPositionAsArray(),
  779.             'fuelTypeList' => $this->getDoctrine()->getRepository(FuelType::class)->findAllAsArray(),
  780.             'usageTypeList' => $this->getDoctrine()->getRepository(UsageType::class)->findAllAsArray(),
  781.             'leasingCompanyList' => $this->getDoctrine()->getRepository(LeasingCompany::class)->findAllAsArray(),
  782.             'leasingCompanies' => $leasingCompanies,
  783.             'step' => $request->get('step'),
  784.             'haveOldVehicleValues' => (bool)$request->getSession()->get('rcaVehicle'),
  785.             'haveOldCustomerValues' => (bool)$request->getSession()->get('rcaCustomerData'),
  786.             'isAdmin' => ShopUserModel::checkIfUserIsAdmin($this->getUser(), $this->getEntityManager()),
  787.             'accordionBlocksAboutRca' => StaticPagesBitbagService::getAllFilteredBlocksAsArray($this->getEntityManager(), BlockManager::BLOCK_ACCORDION_TEXT_RCA_CODE_PATTERN),
  788.             'roadAssistanceDefaultPrice' => $roadAssistanceService->retrieveDefaultPrice(),
  789.             'roadAssistanceTranslations' => RoadAssistanceManager::getTranslationsForUI($translator),
  790.             'hash' => $hashGeneratorService->getHash(),
  791.             'recaptchaSiteKey' => $_ENV['RECAPTCHA_INVISIBLE_KEY'],
  792.             'oldVehicle' => $rcaData $rcaData['oldVehicle'] : $request->get('oldVehicle'),
  793.             'oldCustomer' => $rcaData $rcaData['oldCustomer'] : $request->get('oldCustomer'),
  794.             'oldOffer' => $rcaData $rcaData['oldOffer'] : $request->get('oldOffer'),
  795.             'canIssueRoadAssistance' => PartnerManager::doRoleHaveAccess($partnerRolePartnerManager::CAN_ISSUE_ROAD_ASSISTANCE_INDEX),
  796.             'partner' => $partner,
  797.         ]);
  798.     }
  799.     public function showRcaPolicyDocument(Request $request)
  800.     {
  801.         $wsOfferId $request->get('ws_offer_id');
  802.         if ($wsOfferId) {
  803.             $rcaApiService $this->getContainer()->get('app.rca.issue.service');
  804.             $rca $this->getDoctrine()->getRepository(RCA::class)
  805.                 ->findOneBy(array('wsOfferId' => $wsOfferId));
  806.             $pdf $rcaApiService->getPdf($rca->getWsOfferId(), $rca->getWsPolicyId());
  807.             $pdf base64_decode($pdf);
  808.             header('Content-Type: application/pdf');
  809.             echo $pdf;
  810.         }
  811.         return new Response('error');
  812.     }
  813.     public function sendCustomerAndVehicleDataForCasco(Request $request)
  814.     {
  815.         $apiVehicleDataService $this->getContainer()->get('app.service.api_vehicle_data');
  816.         $logEmailSendingService = new LogEmailSendingService($this->getEntityManager());
  817.         $customer CustomerService::retrieveCustomerFromShopUser($this->getUser());
  818.         if (!$customer || !$request->get('vehicleId')) {
  819.             return new Response('error');
  820.         }
  821.         $rcaData RCAService::retrieveCustomerAndVehicleDataByModalVehicleId($customer$request$apiVehicleDataService$this->getEntityManager());
  822.         if (empty($rcaData)) {
  823.             $logEmailSendingService->storeNewLogEmailForCustomer($customerLogEmailSending::EMAIL_CASCO_OFFERfalse, array('error' => 'no valid data'));
  824.             return new Response('error');
  825.         }
  826.         if ($logEmailSendingService->checkIfEmailIsSentByAdditionalInfoAndEmailType($rcaData['vehicle']['registrationPlate'], LogEmailSending::EMAIL_CASCO_OFFER)) {
  827.             return new JsonResponse(['error' => 'Oferta a fost trimisa anterior, o sa fiti contactat pentru o oferta in cel mai scurt timp']);
  828.         }
  829.         $dataToSend EmailService::formatJsonDataForEmailReading($rcaData);
  830.         $message = (new \Swift_Message('Cerere Oferta Casco - Nume Client:' $customer->getFullName()))
  831.             ->setFrom($_ENV['EMAIL_USERNAME'])
  832.             ->setBcc($_ENV['EMAIL_ADMIN_SCALA'])
  833.             ->setTo($_ENV['EMAIL_PARTENER_CASCO'])
  834.             ->setBody('Buna ziua,<br>' $dataToSend)
  835.             ->setContentType("text/html");
  836.         $isSent EmailService::sendEmail($message$customer->getEmail());
  837.         $logEmailSendingService->storeNewLogEmailForCustomer($customerLogEmailSending::EMAIL_CASCO_OFFER$isSent$rcaData);
  838.         return new Response(json_encode($isSent));
  839.     }
  840. }