src/Controller/RCA/RCAController.php line 175

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