- <?php
- namespace DcSiteBundle\Controller\ToyotaBorispol;
- use AcquiringBundle\Entity\Order;
- use CoreBundle\Component\CoreFormFactory;
- use CoreBundle\Component\FormManager;
- use CoreBundle\Entity\Forms;
- use CoreBundle\Entity\Model;
- use CoreBundle\Entity\ServicePage;
- use CoreBundle\Factory\Vehicle as VehicleFactory;
- use CoreBundle\Model\Api\OnlineService\ApiServer1C;
- use CoreBundle\Model\Vehicles\Repository;
- use CoreBundle\Model\ViDiDepartmentModel;
- use CoreBundle\Model\ViDiWorkerModel;
- use CoreBundle\Services\MediaExtensionVidi;
- use DcSiteBundle\Entity\OnlineServiceBooking;
- use DcSiteBundle\Services\RentVehicleService;
- use DcSiteBundle\Services\ServicePageService;
- use DcSiteBundle\Services\VehicleService;
- use Doctrine\ORM\EntityManagerInterface;
- use MyBundle\Service\OrderService;
- use PortalBundle\Model\SeoMetaTag;
- use stdClass;
- use Symfony\Component\Filesystem\Filesystem;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Response;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\Routing\RouterInterface;
- use Twig\Environment;
- class ServiceController extends BaseController
- {
-     public function __construct(CoreFormFactory $coreFormFactory, SeoMetaTag $seoMetaTag, RequestStack $requestStack, RouterInterface $router, FormManager $formManager, EntityManagerInterface $em, ApiServer1C $apiServer1C, SessionInterface $session, Filesystem $filesystem, MediaExtensionVidi $mediaExtensionVidi, Repository $vehicleRepository, VehicleFactory $vehicleFactory, Environment $twig)
-     {
-         parent::__construct($coreFormFactory, $seoMetaTag, $requestStack, $router, $formManager, $em, $apiServer1C, $session, $filesystem, $mediaExtensionVidi, $vehicleRepository, $vehicleFactory, $twig);
-     }
-     public function to(ServicePageService $servicePageService): ?Response
-     {
-         $services = $servicePageService->getServiceByDealer($this->getDealer());
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/to.html.twig', [
-             'services' => $services,
-             'serviceForm' => $this->CoreFormFactory()->serviceForm()->createView(),
-             'isNight' => false
-         ]);
-     }
-     public function servicePage(Request $request, ServicePageService $servicePageService, ViDiWorkerModel $viDiWorkerModel): ?Response
-     {
-         /** @var ServicePage $servicePage */
-         $servicePage = $this->em->getRepository(ServicePage::class)->findOneBy(['dealer' => $this->getDealer(), 'state' => true, 'url' => $request->get('url')]);
-         if (!$servicePage) {
-             throw $this->createNotFoundException('service page not exists');
-         }
-         $pageServiceJobs = $servicePageService->getPageServiceJobByPage($this->getDealer());
-         $pageNearbyService = $servicePageService->getServiceByNearbyService($this->getDealer(), $servicePage);
-         $facilities = explode(', ', $this->getDealer()->getFacilities());
-         $workers = $viDiWorkerModel->getAllByDealer($this->getDealer(), $request->getLocale());
-         $departmentService = $workers[ViDiDepartmentModel::DEPARTMENT_TYPE_SERVICE];
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/service-page.html.twig', [
-             'servicePage' => $servicePage,
-             'pageServiceJobs' => $pageServiceJobs,
-             'pageNearbyService' => $pageNearbyService,
-             'dealerFacilities' => $facilities,
-             'departmentService' => $departmentService,
-         ]);
-     }
-     public function regulationsTo(VehicleService $vehicleService): ?Response
-     {
-         $models = $vehicleService->getModelsForRegulationsTo($this->getDealer());
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/regulations-to.html.twig', [
-             'models' => $models,
-         ]);
-     }
-     public function regulationsToModel($model): ?Response
-     {
-         $model = $this->em->getRepository(Model::class)->findOneBy(['url' => $model]);
-         if (!$model) {
-             throw new NotFoundHttpException();
-         }
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/regulations-to-single.html.twig', [
-             'model' => $model,
-             'modelTitle' => $model->getTitle(),
-         ]);
-     }
-     public function bodyRepair(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/body-repair.html.twig', [
-             'repairPhotoForm' => $this->CoreFormFactory()->repairPhotoForm()->createView(),
-         ]);
-     }
-     public function tuning(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/tuning.html.twig', [
-                 'form' => $this->CoreFormFactory()->fbDefQuestionForm('Замовлення тюнінга', ViDiDepartmentModel::DEPARTMENT_TYPE_SERVICE, null, $this->getDealer())->createView(),
-             ]
-         );
-     }
-     public function tireHotel(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/tire-hotel.html.twig', [
-             'tireHotelOrder' => $this->CoreFormFactory()->serviceForm()->createView(),
-         ]);
-     }
-     public function creditCalc(Request $request, ViDiWorkerModel $viDiWorkerModel): ?Response
-     {
-         $departments = $viDiWorkerModel->getAllByDealer($this->getDealer(), $request->getLocale());
-         $needDepartment = $request->getLocale() == 'ru' ? 'Отдел продаж' : 'Відділ продажу';
-         $team = array_filter($departments, fn($department) => $department['departmentTitle'] === $needDepartment);
-         $form = $this->CoreFormFactory()
-             ->callMeForm(new Forms(), true);
-         $form->get('dealer')->setData($this->getDealer());
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/credit-calc.html.twig', [
-             'creditForm' => $this->CoreFormFactory()->creditForm($this->getDealer())->createView(),
-             'brandId' => $this->getDealer()->getBrand()->getId(),
-             'dealerId' => $this->getDealer()->getId(),
-             'team' => current($team),
-             'callMeForm' => $form->createView(),
-         ]);
-     }
-     public function assistance(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/assistance.html.twig');
-     }
-     public function warranty(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/warranty.html.twig');
-     }
-     public function extendedWarranty(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/extended-warranty.html.twig');
-     }
-     public function manuals(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/manuals.html.twig');
-     }
-     public function myToyota(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/my-toyota.html.twig');
-     }
-     public function accessory(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/accessory.html.twig', [
-         ]);
-     }
-     public function part(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/part.html.twig', [
-             'spareForm' => $this->CoreFormFactory()->buySparePartsForm($this->getDealer())->createView(),
-         ]);
-     }
-     public function multiConsultationFormOnline(Request $request): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/consultation-form-online.html.twig', [
-             'consultationForm' => $this->CoreFormFactory()->feedbackQuestionForm(null, $this->getDealer(), false, $request->getLocale())->createView(),
-         ]);
-     }
-     public function motorOil(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/motor-oil.html.twig', [
-         ]);
-     }
-     public function motorOilSingle(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/motor-oil-single.html.twig', [
-         ]);
-     }
-     //    Oil static start
-     public function oil5w30(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-5w-30.html.twig', [
-             'spareForm' => $this->CoreFormFactory()->buySparePartsForm($this->getDealer())->createView(),
-         ]);
-     }
-     public function afeOw16(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-afe-ow-16.html.twig');
-     }
-     public function afeOw20(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-afe-ow-20.html.twig');
-     }
-     public function pfeOw30(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-pfe-ow-30.html.twig');
-     }
-     public function fuelEconomy5w30(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-fuel-economy-5w-30.html.twig');
-     }
-     public function premiumFuelEconomy5w30(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-prem-fuel-economy-5w-30.html.twig');
-     }
-     public function sae5w40(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/motor-oils-sae-5w-40.html.twig');
-     }
-     //    Oil static end
-     public function transmissionOil(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/transmission-oil.html.twig');
-     }
-     public function transmissionOilSingle(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/transmission-oil-single.html.twig');
-     }
-     //    Oil static start
-     public function sae75w90gl5(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-sae-75w-90-gl5.html.twig');
-     }
-     public function sae75w90gl4(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-sae-75w-90-gl4.html.twig');
-     }
-     public function lsdSae85w90(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-lsd-sae-85w-90.html.twig');
-     }
-     public function lt75w85Sae75w85(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-lt-75w-85-sae-75w-85.html.twig');
-     }
-     public function hypoidGearLsdSae85w90(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-hypoid-gear-lsd-sae-85w-90.html.twig');
-     }
-     public function lf75w(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-lf-75w.html.twig');
-     }
-     public function dexron3(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-dexron-3.html.twig');
-     }
-     public function t4(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-t-4.html.twig');
-     }
-     public function ws(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-ws.html.twig');
-     }
-     public function cvtFe(): ?Response
-     {
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/oil_static/transmission-oils-cvt-fe.html.twig');
-     }
-     //    Oil static end
-     // Sms landing page
-     public function SmsLandingTradeIn(Request $request): ?Response
-     {
-         if ($this->checkSend($request)) {
-             return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Services/sms-landing-vidi-select.html.twig');
-         }
-         $this->sendSmsLead($request);
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Services/sms-landing-vidi-select.html.twig');
-     }
-     public function replacementCarSingle(Request $request): Response
-     {
-         $booking = null;
-         if ($request->get('bookingId')) {
-             $booking = $this->em->getRepository(OnlineServiceBooking::class)->find($request->get('bookingId'));
-         }
-         if ($request->get('hash')) {
-             $order = $this->em->getRepository(Order::class)->findOneBy(['hash' => $request->get('hash')]);
-         }
-         $form = $this->CoreFormFactory()
-             ->callMeForm(new Forms(), true);
-         $form->get('dealer')->setData($this->getDealer());
-         return $this->baseToyotaBorispol('@DcSite/Toyota_Borispol/Service/replacement-car-single.html.twig', [
-             'booking' => $booking,
-             'dealer' => $this->getDealer(),
-             'order' => isset($order) ? $order->getId() : null,
-             'callMeFormPopUp' => $form->createView()
-         ]);
-     }
-     public function orderForRentCar(OrderService $orderService): JsonResponse
-     {
-         return $this->json($orderService->createOrderWithoutUserForRentCar($this->getDealer()));
-     }
-     public function getAvailableRentCar(RentVehicleService $rentVehicleService): JsonResponse
-     {
-         $result = $rentVehicleService->getRentCarFrom1C($this->getDealer());
-         if (!$result) {
-             $result = new stdClass();
-             $result->success = false;
-         } else {
-             $result->success = true;
-         }
-         return new JsonResponse($result);
-     }
-     public function saveReplacementCarForm(Request $request, RentVehicleService $rentVehicleService): JsonResponse
-     {
-         $rentVehicleService->saveForm(
-             $this->getDealer(),
-             $request->request->all(),
-             $request->getHost());
-         return new JsonResponse([
-             'success' => true,
-         ]);
-     }
- }
-