- <?php
- namespace DcSiteBundle\Controller;
- use CoreBundle\Component\CoreFormFactory;
- use CoreBundle\Component\FormManager;
- use CoreBundle\Entity\Brand;
- use CoreBundle\Entity\Dealer;
- use CoreBundle\Entity\Model;
- use CoreBundle\Entity\User;
- use CoreBundle\Entity\UserCar;
- use CoreBundle\Factory\Vehicle as VehicleFactory;
- use CoreBundle\Model\Api\MVD\MvdServer;
- use CoreBundle\Model\Api\OnlineService\ApiServer1C;
- use CoreBundle\Model\Vehicles\Repository;
- use CoreBundle\Services\MediaExtensionVidi;
- use DateTime;
- use DcSiteBundle\Entity\OnlineServiceBooking;
- use DcSiteBundle\Entity\OnlineServiceBookingWorks;
- use DcSiteBundle\Entity\ServiceVariation;
- use DcSiteBundle\Entity\ServiceWork;
- use DcSiteBundle\Entity\ServiceWorkJob;
- use DcSiteBundle\Entity\ServiceWorkPart;
- use Doctrine\ORM\EntityManagerInterface;
- use Exception;
- use MyBundle\Component\InfobipSmsSender;
- use MyBundle\Factory\OtpCodeGenerator;
- use MyBundle\Service\NightBookingService;
- use PortalBundle\Model\SeoMetaTag;
- use Symfony\Component\Filesystem\Filesystem;
- use Symfony\Component\HttpFoundation\JsonResponse;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Component\HttpFoundation\RequestStack;
- use Symfony\Component\HttpFoundation\Session\SessionInterface;
- use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
- use Symfony\Component\Routing\RouterInterface;
- use Symfony\Contracts\Translation\TranslatorInterface;
- use Twig\Environment;
- class OnlineServiceController extends BaseDcController
- {
-     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 init(Request $request): JsonResponse
-     {
-         $userData = $this->initUserDealer($request);
-         $variationId = $request->request->get('variationId');
-         $modelVariation = $request->request->get('modelVariation');
-         $Variation = null;
-         if ($variationId) {
-             /** @var ServiceVariation $Variation */
-             $Variation = $this->em->getRepository(ServiceVariation::class)->find($variationId);
-         }
-         if ($Variation) {
-             $Dealer = $Variation->getDealer();;
-         } else {
-             $Dealer = $this->getDealer($request->get('dealerId'));
-         }
-         $Brand = $Dealer->getBrand();
-         $brandId = $request->get('brandId');
-         if (!$brandId) {
-             $brandId = $Brand->getId();
-         }
-         if ($modelVariation) {
-             $Models = $this->em->getRepository(Model::class)->findByBrand($brandId);
-         } else {
-             $Models = $this->em->getRepository(Model::class)->findByBrandWithVariation($brandId);
-         }
-         $modelsArray = [];
-         /** @var Model $model */
-         foreach ($Models as $model) {
-             if ($model->getIsAutocreate() || !$model->getUid1c()) {
-                 continue;
-             }
-             $modelImg = null;
-             if ($model->getImage()) {
-                 $modelImg = $this->mediaExtensionVidi->getPath($model->getImage(), 'reference');
-             }
-             $modelsArray[] = [
-                 'id' => $model->getId(),
-                 'title' => strtolower($model->getTitle()),
-                 'brand' => $model->getBrand()->getName(),
-                 'brandId' => $model->getBrand()->getId(),
-                 'img' => $modelImg,
-             ];
-         }
-         usort($modelsArray, fn($a, $b) => $a['title'] <=> $b['title']);
-         $firstLetter = false;
-         foreach ($modelsArray as &$model) {
-             $fL = substr($model['title'], 0, 1);
-             if (!$firstLetter || $fL != $firstLetter) {
-                 $model['isFirstLetter'] = true;
-                 $firstLetter = $fL;
-             }
-         }
-         $responseData = [
-             'user' => $userData,
-             'models' => $modelsArray,
-             'isNightDealer' => $Dealer->getIsNightDealer(),
-             'brandId' => $Dealer->getBrand()->getId(),
-             'brand' => $Dealer->getBrand()->getName(),
-             'brandLogo' => $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference'),
-         ];
-         if ($Variation) {
-             $yearTo = (new DateTime())->format('Y');
-             if ($Variation->getYearTo()) {
-                 $yearTo = $Variation->getYearTo();
-             }
-             $carData = [
-                 'title' => (string)$Variation->getModel(),
-                 'MakeYear' => $Variation->getYearFrom() . ' - ' . $yearTo,
-                 'modelId' => $Variation->getModel()->getId(),
-                 'variationId' => $variationId,
-             ];
-             $responseData['defaultCar'] = $carData;
-             $responseData['dealer_id'] = $Dealer->getId();
-         }
-         return new JsonResponse($responseData);
-     }
-     public function findDealerBrand(Request $request): JsonResponse
-     {
-         $userData = $this->initUserDealer($request);
-         $brands = $this->vehicleRepository->getAvailBrandsInstance($request->getLocale());
-         return new JsonResponse(['success' => true, 'brands' => $brands, 'user' => $userData]);
-     }
-     public function initService(Request $request): JsonResponse
-     {
-         $userData = $this->initUserDealer($request);
-         $repositoryBrands = $this->em->getRepository(Brand::class)->getBrandsHasRegulation();
-         $brands = [];
-         $models = [];
-         $dealers = [];
-         /** @var Brand $brand */
-         foreach ($repositoryBrands as $brand) {
-             $brands[$brand->getId()] = [
-                 'id' => $brand->getId(),
-                 'title' => $brand->getName(),
-                 'dealers' => []
-             ];
-             /** @var Dealer $dealer */
-             foreach ($brand->getDealer() as $dealer) {
-                 if ($dealer->getId() == 7) {
-                     continue;
-                 }
-                 $isNight = $dealer->getIsNightDealer();
-                 $agreementUrl = ($isNight) ? $this->router->generate('my_profile_night_service_agreement_dealer', ['dealerUrl' => $dealer->getUrl()]) : false;
-                 $dealers[$dealer->getId()] = [
-                     'id' => $dealer->getId(),
-                     'title' => $dealer->getNameByLocale($request->getLocale()),
-                     'address' => $dealer->getAddressByLocale($request->getLocale()),
-                     'isNight' => $isNight,
-                     'agreementUrl' => $agreementUrl,
-                     'brandId' => $brand->getId(),
-                     'image' => $this->mediaExtensionVidi->getPath($brand->getLogo(), 'reference'),
-                 ];
-                 $brands[$brand->getId()]['dealers'][] = [
-                     'id' => $dealer->getId(),
-                     'title' => $dealer->getNameByLocale($request->getLocale())
-                 ];
-             }
-             $repositoryModels = $this->em->getRepository(Model::class)->getModelsHasRegulationByBrand($brand->getId());
-             /** @var Model $item */
-             foreach ($repositoryModels as $item) {
-                 $models[$item->getId()] = [
-                     'id' => $item->getId(),
-                     'title' => $item->getTitle(),
-                     'brandId' => $item->getBrand()->getId(),
-                 ];
-             }
-         }
-         return new JsonResponse(['success' => true, 'user' => $userData, 'brands' => $brands, 'models' => $models, 'dealers' => $dealers]);
-     }
-     public function findServiceVariationByFilter(Request $request): JsonResponse
-     {
-         $modelId = $request->get('modelId');
-         $dealerId = $request->get('dealerId');
-         $locale = $request->getLocale();
-         $repositoryServiceVariations = $this->em->getRepository(ServiceVariation::class)->findRegulationWorkByVariation($dealerId, $modelId);
-         $hasWorkByVariation = false;
-         $makeYears = [];
-         $variations = [];
-         /** @var ServiceVariation $serviceVariation */
-         foreach ($repositoryServiceVariations as $serviceVariation) {
-             $yearTo = ($serviceVariation->getYearTo() == 0) ? date('Y', time()) : $serviceVariation->getYearTo();
-             $makeYearId = $serviceVariation->getYearFrom() . $yearTo;
-             if (!isset($makeYears[$serviceVariation->getYearFrom()])) {
-                 $makeYears[$makeYearId] = [
-                     'id' => $makeYearId,
-                     'title' => $serviceVariation->getYearFrom() . ' - ' . $yearTo,
-                 ];
-             }
-             $variationsTitle = '';
-             if ($serviceVariation->getFuelType()) {
-                 $variationsTitle .= $serviceVariation->getFuelType()->getValue($locale);
-             }
-             $variationsTitle .= ' ' . round($serviceVariation->getEngineVolume() / 1000, 1) . 'л';
-             $titleShort = $variationsTitle;
-             if ($serviceVariation->getDriveUnit()) {
-                 $variationsTitle .= ', ' . $serviceVariation->getDriveUnit()->getValue($locale);
-             }
-             if ($serviceVariation->getTransmissionType()) {
-                 $variationsTitle .= ', ' . $serviceVariation->getTransmissionType()->getValue($locale);
-             }
-             $variationsTitle .= ($serviceVariation->getTransmissionStepCount()) ? ', ' . $serviceVariation->getTransmissionStepCount() . 'ст.' : '';
-             if ($serviceVariation->getEmission()) {
-                 $variationsTitle .= ', ' . $serviceVariation->getEmission();
-             }
-             if ($serviceVariation->getDescription()) {
-                 $variationsTitle .= ', ' . $serviceVariation->getDescription();
-             }
-             $variations[$serviceVariation->getId()] = [
-                 'id' => $serviceVariation->getId(),
-                 'title' => $variationsTitle,
-                 'titleShort' => $titleShort,
-                 'makeYearId' => $makeYearId,
-                 'yearFrom' => $serviceVariation->getYearFrom(),
-                 'yearTo' => $yearTo,
-                 'fuelType' => ($serviceVariation->getFuelType()) ? $serviceVariation->getFuelType()->getValue($locale) : '',
-                 'engineVolume' => round($serviceVariation->getEngineVolume() / 1000, 1),
-             ];
-         }
-         if (count($variations)) {
-             $hasWorkByVariation = true;
-         }
-         return new JsonResponse(['success' => true, 'makeYears' => $makeYears, 'variations' => $variations, 'hasWorkByVariation' => $hasWorkByVariation]);
-     }
-     public function initDealer(Request $request): JsonResponse
-     {
-         $userData = $this->initUserDealer($request);
-         $brands = $this->vehicleRepository->getAvailBrandsInstance($request->getLocale(), true);
-         foreach ($brands as &$brand) {
-             $brand['image'] = $this->mediaExtensionVidi->getPath($brand['image'], 'menu');
-         }
-         return new JsonResponse(['success' => true, 'brands' => $brands, 'user' => $userData]);
-     }
-     public function initUserDealer(Request $request): array
-     {
-         /** @var User $User */
-         if ($User = $this->getUser()) {
-             $cars = [];
-             /** @var UserCar $car */
-             foreach ($User->getCars() as $car) {
-                 if (!$car->getCarModel()) {
-                     continue;
-                 }
-                 if ($car->getIsDeleted()) {
-                     continue;
-                 }
-                 $dealers = $car->getCarModel()->getBrand()->getDealer();
-                 $dealersData = [];
-                 /** @var Dealer $dealer */
-                 foreach ($dealers as $dealer) {
-                     $dealersData[] = [
-                         'id' => $dealer->getId(),
-                         'title' => $dealer->getNameByLocale($request->getLocale()),
-                         'adress' => $dealer->getAddressByLocale($request->getLocale()),
-                     ];
-                 }
-                 $cars[] = [
-                     'id' => $car->getId(),
-                     'title' => $car->getBrand() . ' ' . $car->getModel(),
-                     'MakeYear' => $car->getYearOfProduction(),
-                     'Number' => $car->getNumber(),
-                     'dealer' => $dealersData,
-                     'VIN' => $car->getVin(),
-                     'brandId' => $car->getCarModel()->getBrand()->getId(),
-                     'modelId' => $car->getCarModel()->getId(),
-                     'variationId' => $car->getServiceVariation() ? $car->getServiceVariation()->getId() : null,
-                 ];
-             }
-             $userData = [
-                 'id' => $User->getId(),
-                 'name' => $User->getFullName(),
-                 'email' => $User->getEmail(),
-                 'phone' => $User->getPhone(),
-                 'cars' => $cars,
-             ];
-         } else {
-             $userData = [
-                 'id' => null,
-                 'name' => null,
-                 'email' => null,
-                 'phone' => null,
-                 'cars' => [],
-             ];
-         }
-         return $userData;
-     }
-     public function findVariation(Request $request): JsonResponse
-     {
-         $dealerId = $request->get('dealerId');
-         $modelId = $request->get('modelId');
-         $byGroup = $request->get('byGroup');
-         if (!$dealerId) {
-             throw new NotFoundHttpException();
-         }
-         $Dealer = $this->em->getRepository(Dealer::class)->find($dealerId);
-         if ($byGroup) {
-             $variationsResult = [];
-             $variations = $this->em->getRepository(ServiceVariation::class)->findBy(['dealer' => $Dealer, 'model' => $modelId, 'is_delete' => [0, null]], ['year_from' => 'ASC']);
-             /** @var ServiceVariation $row */
-             foreach ($variations as $row) {
-                 if (!$row->getFuelType()) {
-                     continue;
-                 }
-                 $key = $row->getYearFrom() . ' - ' . ('...');
-                 if ($row->getYearTo()) {
-                     $key = $row->getYearFrom() . ' - ' . ($row->getYearTo());
-                 }
-                 if (!isset($variationsResult[$key])) {
-                     $variationsResult[$key] = [
-                         'period' => $key,
-                         'from' => $row->getYearFrom(),
-                         'to' => $row->getYearTo() ?: (new DateTime())->format('Y'),
-                         'image' => null,
-                         'items' => [],
-                     ];
-                 }
-                 $vImage = $row->getImage();
-                 if (!$variationsResult[$key]['image'] && $vImage) {
-                     $variationsResult[$key]['image'] = $this->mediaExtensionVidi->getPath($vImage, 'reference');
-                 }
-                 $transmission = false;
-                 if ($row->getTransmissionType()) {
-                     $transmission = $row->getTransmissionType()->getValue($request->getLocale());
-                 }
-                 if ($transmission && $row->getTransmissionStepCount()) {
-                     $transmission .= ', ' . $row->getTransmissionStepCount() . ' ст.';
-                 }
-                 $volume = $row->getEngineVolume();
-                 if ($volume > 200) {
-                     $volume = number_format(round($volume / 1000, 1), 1, '.', '');
-                 }
-                 $variationsResult[$key]['items'][] = [
-                     'id' => $row->getId(),
-                     'capacity' => $volume,
-                     'drive' => $row->getDriveUnit() ? $row->getDriveUnit()->getValue($request->getLocale()) : null,
-                     'driveId' => $row->getDriveUnit() ? $row->getDriveUnit()->getId() : null,
-                     'fuel' => $row->getFuelType()->getValue($request->getLocale()),
-                     'fuelId' => $row->getFuelType()->getId(),
-                     'transmission' => $transmission,
-                     'engineName' => $row->getEngineName(),
-                     'emission' => $row->getEmission(),
-                     'transmissionId' => $row->getTransmissionType() ? $row->getTransmissionType()->getId() : null,
-                     'power' => $row->getPower(),
-                     'form' => $row->getYearFrom(),
-                     'to' => $row->getYearTo() ?: '...',
-                     'description' => $row->getDescription(),
-                 ];
-             }
-             foreach ($variationsResult as &$row) {
-                 if (!$row['image']) {
-                     $row['image'] = $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference');
-                 }
-             }
-             return new JsonResponse(['variations' => $variationsResult]);
-         }
-         $year = $request->get('MakeYear');
-         $SaleMonth = $request->get('SaleMonth');
-         $SaleYear = $request->get('SaleYear');
-         $SaleData = null;
-         if ($SaleMonth && $SaleYear) {
-             $SaleData = new DateTime($SaleYear . '-' . $SaleMonth . '-01');
-         }
-         $variationsResult = [];
-         $variations = $this->em->getRepository(ServiceVariation::class)->getByCarParams($Dealer->getId(), $modelId, $year, $SaleData);
-         /** @var ServiceVariation $row */
-         foreach ($variations as $row) {
-             $transmission = false;
-             if ($row->getTransmissionType()) {
-                 $transmission = $row->getTransmissionType()->getValue($request->getLocale());
-             }
-             if ($transmission && $row->getTransmissionStepCount()) {
-                 $transmission .= ', ' . $row->getTransmissionStepCount() . ' ст.';
-             }
-             $variationsResult[] = [
-                 'id' => $row->getId(),
-                 'capacity' => $row->getEngineVolume(),
-                 'drive' => $row->getDriveUnit() ? $row->getDriveUnit()->getValue($request->getLocale()) : null,
-                 'driveId' => $row->getDriveUnit() ? $row->getDriveUnit()->getId() : null,
-                 'fuel' => $row->getFuelType()->getValue($request->getLocale()),
-                 'fuelId' => $row->getFuelType()->getId(),
-                 'transmission' => $transmission,
-                 'engineName' => $row->getEngineName(),
-                 'transmissionId' => $row->getTransmissionType() ? $row->getTransmissionType()->getId() : null,
-                 'power' => $row->getPower(),
-                 'form' => $row->getYearFrom(),
-                 'to' => $row->getYearTo() ?: '...',
-             ];
-         }
-         return new JsonResponse(['variations' => $variationsResult]);
-     }
-     public function findVariationBy(Request $request): JsonResponse
-     {
-         $dealerId = $request->get('dealerId');
-         $modelId = $request->get('modelId');
-         $variationsResult = [];
-         $Dealer = $this->em->getRepository(Dealer::class)->find($dealerId);
-         $variations = $this->em->getRepository(ServiceVariation::class)->findBy(['dealer' => $Dealer, 'model' => $modelId, 'is_delete' => [0, null]], ['year_from' => 'ASC']);
-         /** @var ServiceVariation $row */
-         foreach ($variations as $row) {
-             if (!$row->getFuelType()) {
-                 continue;
-             }
-             $transmission = false;
-             $to = (new DateTime())->format('Y');
-             if ($row->getTransmissionType()) {
-                 $transmission = $row->getTransmissionType()->getValue($request->getLocale());
-             }
-             if ($transmission && $row->getTransmissionStepCount()) {
-                 $transmission .= ', ' . $row->getTransmissionStepCount() . ' ст.';
-             }
-             $volume = $row->getEngineVolume();
-             if ($volume > 200) {
-                 $volume = number_format(round($volume / 1000, 1), 1, '.', '');
-             }
-             if ($row->getYearTo()) {
-                 $to = $row->getYearTo();
-             }
-             $variationsResult[] = [
-                 'id' => $row->getId(),
-                 'dealerId' => (int)$dealerId,
-                 'modelId' => (int)$modelId,
-                 'capacityId' => $row->getEngineVolume(),
-                 'capacity' => $volume,
-                 'driveId' => $row->getDriveUnit() ? $row->getDriveUnit()->getId() : null,
-                 'driveUnit' => $row->getDriveUnit() ? $row->getDriveUnit()->getValue($request->getLocale()) : null,
-                 'fuelId' => $row->getFuelType()->getId(),
-                 'fuelType' => $row->getFuelType()->getValue($request->getLocale()),
-                 'transmissionId' => $row->getTransmissionType() ? $row->getTransmissionType()->getId() : null,
-                 'transmissionType' => $transmission,
-                 'engineName' => $row->getEngineName(),
-                 'emission' => $row->getEmission(),
-                 'power' => $row->getPower(),
-                 'year' => $row->getYearFrom() . ' - ' . $to,
-             ];
-         }
-         return new JsonResponse(['variations' => $variationsResult]);
-     }
-     private function checkModel(Brand $brand, $modelStr)
-     {
-         $models = $brand->getModels();
-         /** @var Model $model */
-         foreach ($models as $model) {
-             $modelTitle = str_replace(' ', '', $model->getTitle());
-             $modelTitle = str_replace('-', '', $modelTitle);
-             $modelTitle = strtolower($modelTitle);
-             $modelStr = str_replace(' ', '', $modelStr);
-             $modelStr = str_replace('-', '', $modelStr);
-             $modelStr = strtolower($modelStr);
-             if ($modelTitle == $modelStr) {
-                 return $model;
-             }
-         }
-         /** @var Model $model */
-         foreach ($models as $model) {
-             $modelTitle = str_replace(' ', '', $model->getTitle());
-             $modelTitle = str_replace('-', '', $modelTitle);
-             $modelTitle = strtolower($modelTitle);
-             $modelStr = str_replace(' ', '', $modelStr);
-             $modelStr = str_replace('-', '', $modelStr);
-             $modelStr = strtolower($modelStr);
-             if ($modelTitle && $modelTitle !== '' && strpos($modelStr, $modelTitle) !== false) {
-                 return $model;
-             }
-             if (strpos($modelTitle, $modelStr) !== false) {
-                 return $model;
-             }
-         }
-         return false;
-     }
-     public function find(Request $request, MvdServer $mvdServer, ApiServer1C $apiServer1C): JsonResponse
-     {
-         $responseData = [];
-         $num = $request->get('number');
-         $carData = $mvdServer->getCarInfoByNumber($num, null, $request->getLocale());
-         $dealer = false;
-         try {
-             $dealer = $this->getDealer($request->get('dealerId'));
-         } catch (NotFoundHttpException $e) {
-         }
-         $apiData = false;
-         if ($dealer) {
-             $apiData = $apiServer1C->getCarInfoByVin(['VIN' => $carData['VIN']], $dealer);
-         }
-         if (!$carData) {
-             return new JsonResponse(['car' => false]);
-         }
-         $brandStr = $carData['Brand'];
-         $brand = $this->em->getRepository(Brand::class)->getByName($brandStr);
-         if (!$brand) {
-             $brand = new Brand();
-             $brand->setName(ucfirst(mb_strtolower($brandStr)));
-             $this->em->persist($brand);
-             $this->em->flush();
-         }
-         $modelStr = $carData['Model'];
-         //TODO ForBrand Lexus
-         if ($brand->getId() == 5) {
-             $modelStr = preg_replace('/[\d\s]/', '', $carData['Model']);
-         }
-         $model = $this->em->getRepository(Model::class)->getByMVDName($modelStr, $brand->getId(), $dealer);
-         if (!$model) {
-             $model = $this->checkModel($brand, $modelStr);
-         }
-         if (!$model) {
-             $model = new Model();
-             $model->setBrand($brand);
-             $model->setTitle($modelStr);
-             $model->setIsAutocreate(1);
-             $this->em->persist($model);
-             $this->em->flush();
-         }
-         $carData['BrandInfo'] = [
-             'id' => $brand->getId(),
-             'name' => $brand->getName(),
-         ];
-         $carData['ModelInfo'] = [
-             'id' => $model->getId(),
-             'name' => $model->getTitle(),
-         ];
-         $modelImg = null;
-         if ($model->getImage()) {
-             $modelImg = $this->mediaExtensionVidi->getPath($model->getImage(), 'reference');
-         }
-         $carData['ModelImg'] = $modelImg;
-         $carData['ModelUrl'] = $model->getUrl();
-         $carData['ModelName'] = "{$carData['Brand']} {$carData['Model']} {$carData['MakeYear']}";
-         $responseData['car'] = $carData;
-         $fuelId = null;
-         if (isset($carData['FuelInfo']) && isset($carData['FuelInfo']['id'])) {
-             $fuelId = $carData['FuelInfo']['id'];
-         }
-         if (!$dealer) {
-             $brands = [];
-             $dealers = $brand->getDealer();
-             if (count($dealers) == 1) {
-                 $dealer = $dealers->first();
-                 $responseData['brands'][] = [
-                     'id' => $brand->getId(),
-                     'name' => $brand->getName(),
-                     'image' => $this->mediaExtensionVidi->getPath($brand->getImage(), 'menu'),
-                     'dealerId' => $dealers->first()->getId()
-                 ];
-             } else {
-                 if (count($dealers)) {
-                     $item = [
-                         'id' => $brand->getId(),
-                         'name' => $brand->getName(),
-                         'image' => $this->mediaExtensionVidi->getPath($brand->getLogo(), 'menu'),
-                     ];
-                     foreach ($dealers as $row) {
-                         $item['dealers'][] = [
-                             'id' => $row->getId(),
-                             'title' => $row->getNameByLocale($request->getLocale()),
-                             'adres' => $row->getAddressByLocale($request->getLocale()),
-                         ];
-                     }
-                     $brands[] = $item;
-                 } else {
-                     $brands = $this->vehicleRepository->getAvailBrandsInstance($request->getLocale());
-                     foreach ($brands as &$item) {
-                         $item['image'] = $this->mediaExtensionVidi->getPath($item['image'], 'menu');
-                     }
-                 }
-                 $responseData['brands'] = $brands;
-                 return new JsonResponse($responseData);
-             }
-         }
-         $variations = false;
-         $variationsResult = [];
-         $currentVariation = null;
-         if ($apiData && $apiData->VariationID) {
-             $currentVariation = $this->em->getRepository(ServiceVariation::class)->findOneBy(['uid_1c' => $apiData->VariationID, 'dealer' => $dealer]);
-             if ($currentVariation) {
-                 $variations[] = $currentVariation;
-             }
-         }
-         if (!$variations && $dealer->getBrand()->getId() == $brand->getId()) {
-             $variations = $this->em->getRepository(ServiceVariation::class)
-                 ->getByCarParams(
-                     $dealer->getId(),
-                     $model->getId(),
-                     $carData['MakeYear'],
-                     null,
-                     $fuelId,
-                     $carData['Capacity']
-                 );
-         }
-         if (!empty($variations)) {
-             /** @var ServiceVariation $row */
-             foreach ($variations as $row) {
-                 $transmission = null;
-                 $drive = null;
-                 $driveId = null;
-                 $to = '...';
-                 $toYear = (new DateTime())->format('Y');
-                 $transmission = false;
-                 if ($row->getTransmissionType()) {
-                     $transmission = $row->getTransmissionType()->getValue($request->getLocale());
-                 }
-                 if ($transmission && $row->getTransmissionStepCount()) {
-                     $transmission .= ', ' . $row->getTransmissionStepCount() . ' ст.';
-                 }
-                 if ($row->getDriveUnit()) {
-                     $drive = $row->getDriveUnit()->getValue($request->getLocale());
-                 }
-                 $driveId = ($row->getDriveUnit()) ? $row->getDriveUnit()->getId() : $row->getDriveUnit();
-                 $transmissionId = ($row->getTransmissionType()) ? $row->getTransmissionType()->getId() : $row->getTransmissionType();
-                 if ($row->getYearTo()) {
-                     $to = $toYear = $row->getYearTo();
-                 }
-                 $volume = $row->getEngineVolume();
-                 if ($volume > 200) {
-                     $volume = number_format(round($volume / 1000, 1), 1, '.', '');
-                 }
-                 $variationsResult[] = [
-                     'id' => $row->getId(),
-                     'capacity' => $volume,
-                     'drive' => $drive,
-                     'driveId' => $driveId,
-                     'fuel' => $row->getFuelType()->getValue($request->getLocale()),
-                     'fuelId' => $row->getFuelType()->getId(),
-                     'transmission' => $transmission,
-                     'emission' => $row->getEmission(),
-                     'transmissionId' => $transmissionId,
-                     'power' => $row->getPower(),
-                     'form' => $row->getYearFrom(),
-                     'to' => $to,
-                     'year' => $row->getYearFrom() . ' - ' . $toYear,
-                 ];
-             }
-         }
-         $responseData['variations'] = $variationsResult;
-         if ($dealer) {
-             $responseData['dealerId'] = $dealer->getId();
-         }
-         return new JsonResponse($responseData);
-     }
-     public function saveCar(Request $request): JsonResponse
-     {
-         $User = $this->getUser();
-         if (!($User instanceof User)) {
-             return new JsonResponse(['success' => false]);
-         }
-         $vin = $request->get('VIN');
-         $UserCar = $this->em->getRepository(UserCar::class)->findOneBy(['vin' => $vin]);
-         $number = $request->get('Number');
-         if ($number) {
-             $UserCar = $this->em->getRepository(UserCar::class)->findOneBy(['is_deleted' => [0, null], 'number' => $number]);
-         }
-         if (!$UserCar) {
-             $UserCar = new UserCar();
-         }
-         $UserCar->setUser($User);
-         $UserCar->setVin($request->get('VIN'));
-         $modelId = $request->get('modelId');
-         $Model = false;
-         if ($modelId) {
-             $Model = $this->em->getRepository(Model::class)->find($modelId);
-         }
-         if (!$Model) {
-             return new JsonResponse(['success' => false]);
-         }
-         /** @var Brand $Brand */
-         $Brand = $Model->getBrand();
-         $UserCar->setIsDeleted(0);
-         $UserCar->setBrand($Brand->getName());
-         $UserCar->setModel($Model->getTitle());
-         $UserCar->setCarModel($Model);
-         $UserCar->setYearOfProduction($request->get('MakeYear'));
-         $UserCar->setNumber($request->get('Number'));
-         $Variation = false;
-         $variationId = $request->get('variationId');
-         if ($variationId) {
-             $Variation = $this->em->getRepository(ServiceVariation::class)->find($variationId);
-         }
-         if ($Variation) {
-             $UserCar->setServiceVariation($Variation);
-         }
-         $this->em->persist($UserCar);
-         $this->em->flush();
-         return new JsonResponse(['success' => true]);
-     }
-     public function byModel(Request $request): JsonResponse
-     {
-         $locale = $request->getLocale();
-         $variationId = $request->get('variationId');
-         $Variation = null;
-         if ($variationId) {
-             $Variation = $this->em->getRepository(ServiceVariation::class)->find($variationId);
-         }
-         $Dealer = $this->getDealer($request->get('dealerId'));
-         $works = $this->em->getRepository(ServiceWork::class)->findByVariation($Variation, $Dealer);
-         $groupsArray = [];
-         /** @var ServiceWork $work */
-         foreach ($works as $work) {
-             $Group = $this->getWorkGroup($work->getGroup());
-             if (!$Group) {
-                 continue;
-             }
-             $groupsArray[$Group->getId()] = [
-                 'id' => $Group->getId(),
-                 'title' => $Group->getTitle($request->getLocale()),
-                 'position' => $Group->getPosition(),
-                 'groups' => [
-                     [
-                         'id' => $Group->getId(),
-                         'title' => $Group->getTitle($request->getLocale()),
-                     ]
-                 ],
-             ];
-         }
-         usort($groupsArray, fn($a, $b) => $a['position'] <=> $b['position']);
-         $worksArray = [];
-         /** @var ServiceWork $work */
-         foreach ($works as $work) {
-             $Group = $this->getWorkGroup($work->getGroup());
-             if (!$Group) {
-                 continue;
-             }
-             $groupId = $Group->getId();
-             if (!isset($worksArray[$groupId])) {
-                 $worksArray[$groupId] = [
-                     'id' => $groupId,
-                     'title' => $Group->getTitle($request->getLocale()),
-                     'works' => [],
-                 ];
-             }
-             $workItem = [
-                 'id' => $work->getId(),
-                 'groupId' => $groupId,
-                 'position' => $work->getPosition(),
-                 'isRegulation' => $work->getIsRegulations(),
-                 'millage' => $work->getMileage(),
-                 'title' => $work->getTitle($request->getLocale()),
-                 'totalCost' => 0,
-                 'worksCost' => 0,
-                 'partsCost' => 0,
-                 'time' => 0,
-                 'works' => [],
-                 'parts' => [],
-             ];
-             /** @var ServiceWorkJob $rJob */
-             foreach ($work->getJobs() as $rJob) {
-                 $workItem['works'][] = [
-                     'title' => $rJob->getJob()->getNameByLocale($locale),
-                     'hours' => $rJob->getJobHours(),
-                     'price' => round($rJob->getPrice()),
-                 ];
-                 $workItem['worksCost'] += $rJob->getPrice();
-                 $workItem['time'] += $rJob->getJobHours();
-             }
-             /** @var ServiceWorkPart $rPart */
-             foreach ($work->getParts() as $rPart) {
-                 if (empty($rPart->getPrice())) {
-                     $cost = round($rPart->getCount() * $rPart->getPart()->getPrice());
-                 } else {
-                     $cost = round($rPart->getCount() * $rPart->getPrice());
-                 }
-                 $workItem['parts'][] = [
-                     'title' => $rPart->getPart()->getNameByLocale($locale),
-                     'count' => $rPart->getCount(),
-                     'unit' => $rPart->getUnits()->getShort($locale),
-                     'price' => round($cost),
-                 ];
-                 $workItem['partsCost'] += $cost;
-             }
-             $workItem['time'] = round($workItem['time'], 2);
-             $workItem['worksCost'] = round($workItem['worksCost']);
-             $workItem['partsCost'] = round($workItem['partsCost']);
-             $workItem['totalCost'] = round($workItem['partsCost'] + $workItem['worksCost']);
-             $worksArray[$groupId]['works'][] = $workItem;
-         }
-         foreach ($worksArray as &$row) {
-             usort($row['works'], function ($a, $b) {
-                 $aVal = $a['isRegulation'] ? $a['millage'] : $a['position'];
-                 $bVal = $b['isRegulation'] ? $b['millage'] : $b['position'];
-                 return $aVal <=> $bVal;
-             });
-         }
-         return $this->json(['success' => true, 'works' => $worksArray, 'groups' => $groupsArray]);
-     }
-     private function getWorkGroup($Group)
-     {
-         if (!$Group) {
-             return false;
-         }
-         if (!$Group->getParent()) {
-             return $Group;
-         }
-         $ParentGroup = $Group->getParent();
-         //Якщо аксессуари
-         if ($ParentGroup->getUid() == 'eb2b75eb-4a5d-11ef-ac14-005056a799b6') {
-             return $ParentGroup;
-         }
-         if (!$ParentGroup->getParent()) {
-             return $Group;
-         }
-         return $this->getWorkGroup($ParentGroup);
-     }
-     public function getWorksByModel(Request $request): JsonResponse
-     {
-         $locale = $request->getLocale();
-         $variationId = $request->get('variationId');
-         $Variation = null;
-         if ($variationId) {
-             $Variation = $this->em->getRepository(ServiceVariation::class)->find($variationId);
-         }
-         $Dealer = $this->getDealer($request->get('dealerId'));
-         $works = $this->em->getRepository(ServiceWork::class)->findByVariation($Variation, $Dealer);
-         $serviceGroupArray = [];
-         $serviceWorksArray = [];
-         /** @var ServiceWork $work */
-         foreach ($works as $work) {
-             $Group = $this->getWorkGroup($work->getGroup());
-             if (!$Group || $Group->getUid() == 'eb2b75eb-4a5d-11ef-ac14-005056a799b6') {
-                 continue;
-             }
-             $serviceGroupArray[$Group->getId()] = [
-                 'id' => $Group->getId(),
-                 'title' => $Group->getTitle($request->getLocale()),
-                 'position' => $Group->getPosition(),
-                 'groups' => [
-                     [
-                         'id' => $Group->getId(),
-                         'title' => $Group->getTitle($request->getLocale()),
-                     ]
-                 ],
-             ];
-             $workItem = [
-                 'id' => $work->getId(),
-                 'title' => $work->getTitle($locale),
-                 'groupId' => $Group->getId(),
-                 'parentGroupId' => $Group->getId(),
-                 'position' => $work->getPosition(),
-                 'isRegulation' => $work->getIsRegulations(),
-                 'millage' => $work->getMileage(),
-                 'totalCost' => 0,
-                 'worksCost' => 0,
-                 'partsCost' => 0,
-                 'time' => 0,
-                 'works' => [],
-                 'parts' => [],
-             ];
-             /** @var ServiceWorkJob $wJob */
-             foreach ($work->getJobs() as $wJob) {
-                 $workItem['works'][] = [
-                     'title' => $wJob->getJob()->getNameByLocale($locale),
-                     'hours' => $wJob->getJobHours(),
-                     'price' => round($wJob->getPrice()),
-                 ];
-                 $workItem['worksCost'] += $wJob->getPrice();
-                 $workItem['time'] += $wJob->getJobHours();
-             }
-             /** @var ServiceWorkPart $wPart */
-             foreach ($work->getParts() as $wPart) {
-                 if (empty($wPart->getPrice())) {
-                     $cost = round($wPart->getCount() * $wPart->getPart()->getPrice());
-                 } else {
-                     $cost = round($wPart->getCount() * $wPart->getPrice());
-                 }
-                 $workItem['parts'][] = [
-                     'title' => $wPart->getPart()->getNameByLocale($locale),
-                     'count' => $wPart->getCount(),
-                     'unit' => $wPart->getUnits()->getShort($locale),
-                     'price' => round($cost),
-                 ];
-                 $workItem['partsCost'] += $cost;
-             }
-             $workItem['time'] = round($workItem['time'], 2);
-             $workItem['worksCost'] = round($workItem['worksCost']);
-             $workItem['partsCost'] = round($workItem['partsCost']);
-             $workItem['totalCost'] = round($workItem['partsCost'] + $workItem['worksCost']);
-             $serviceWorksArray[] = $workItem;
-         }
-         usort($serviceGroupArray, fn($a, $b) => $a['position'] <=> $b['position']);
-         return $this->json(['success' => true, 'groups' => $serviceGroupArray, 'works' => $serviceWorksArray]);
-     }
-     public function getTime(Request $request, ApiServer1C $apiServer1C, TranslatorInterface $translator): JsonResponse
-     {
-         $date = new DateTime($request->get('date'));
-         $Dealer = $this->getDealer($request->get('dealerId'));
-         $works = $request->request->all('works');
-         $worksArray = [];
-         $servicesWorks = $this->em->getRepository(ServiceWork::class)->findBy(['id' => $works]);
-         /** @var ServiceWork $servicesWork */
-         foreach ($servicesWorks as $servicesWork) {
-             /** @var ServiceWorkJob $job */
-             foreach ($servicesWork->getJobs() as $job) {
-                 $worksArray[] = [
-                     'WorkID' => $job->getJob()->getUid(),
-                     'Count' => $job->getJobHours(),
-                 ];
-             }
-         }
-         $times = $apiServer1C->getTimes($date, $Dealer, $worksArray);
-         if (!$times) {
-             return new JsonResponse(['success' => false, 'error' => [
-                 'title' => $translator->trans('modules.online-booking.time-error-title', [], 'dc_base'),
-                 'text' => $translator->trans('modules.online-booking.time-error-text', [], 'dc_base'),
-             ]]);
-         }
-         $result = [];
-         foreach ($times as $time) {
-             $tDate = new DateTime((string)$time->StartDate);
-             $result[] = $tDate->format('H:i');
-         }
-         return new JsonResponse(['success' => true, 'time' => (array)$result]);
-     }
-     public function bookingConfirm(Request          $request, ApiServer1C $apiServer1C, TranslatorInterface $translator,
-                                    InfobipSmsSender $infobipSmsSender, NightBookingService $nightBookingService): JsonResponse
-     {
-         $code = $request->get('confirmCode');
-         $id = $request->get('bookingId');
-         $isNight = filter_var($request->get('isNight'), FILTER_VALIDATE_BOOLEAN);
-         $User = null;
-         $UserCar = null;
-         $selectedConnectionType = $request->get('selectedConnectionType');
-         $selectedMobilityService = $request->get('selectedMobilityService');
-         $toGoService = strtolower($request->get('toGoService')) === 'false' ? false : true;
-         try {
-             if ($isNight) {
-                 $User = $this->getUserNight($request);
-                 $UserCar = $this->getUserCarNight($request, $User);
-             }
-         } catch (Exception $e) {
-             return new JsonResponse(
-                 [
-                     'success' => false,
-                     'error' =>
-                         [
-                             'title' => $translator->trans('modules.online-booking.booking-error-2-title', [], 'dc_base'),
-                             'text' => $translator->trans('modules.online-booking.booking-total-text', [], 'dc_base'),
-                             'message' => $e->getMessage()
-                         ]
-                 ]
-             );
-         }
-         /** @var OnlineServiceBooking $onlineBookingEntity */
-         $onlineBookingEntity = $this->em->getRepository(OnlineServiceBooking::class)->find($id);
-         if (!$onlineBookingEntity) {
-             return new JsonResponse(
-                 [
-                     'success' => false,
-                     'error' =>
-                         [
-                             'title' => $translator->trans('modules.online-booking.time-error-title', [], 'dc_base'),
-                             'text' => $translator->trans('modules.online-booking.booking-total-text', [], 'dc_base'),
-                         ]
-                 ]
-             );
-         }
-         if ($onlineBookingEntity->getConfirmCode() != $code) {
-             return new JsonResponse(
-                 [
-                     'success' => false,
-                     'error' =>
-                         [
-                             'title' => $translator->trans('modules.online-booking.time-error-title', [], 'dc_base'),
-                             'text' => $translator->trans('modules.online-booking.confirm-code-error', [], 'dc_base'),
-                         ]
-                 ]
-             );
-         }
-         $worksArray = [];
-         /** @var OnlineServiceBookingWorks $work */
-         foreach ($onlineBookingEntity->getWorks() as $work) {
-             $worksArray[] = [
-                 'WorkID' => $work->getJob()->getUid(),
-                 'Count' => $work->getTime(),
-             ];
-         }
-         $car = json_decode($onlineBookingEntity->getCarData(), true);
-         $carVinCode = null;
-         if (isset($car['VIN'])) {
-             $carVinCode = $car['VIN'];
-         }
-         $visitDate = $onlineBookingEntity->getVisitDate()->format('d.m.Y H:i:s');
-         $comment = sprintf("%s %s %s, %s %s, %s %s",
-             $onlineBookingEntity->getComment(),
-             ' Послуга мобільності - ', $selectedMobilityService,
-             "Спосіб зв`язку - ", $selectedConnectionType,
-             "Послуга To Go - ", $toGoService ? 'Так' : 'Ні'
-         );
-         $data = [
-             'CustomerID' => null,
-             'CustomerName' => $onlineBookingEntity->getName(),
-             'PhoneMobile' => $onlineBookingEntity->getPhone(),
-             'VehicleID' => null,
-             'VehicleDescriptin' => $car['title'] . ' ' . $car['MakeYear'],
-             'VIN' => $carVinCode,
-             'Date' => $onlineBookingEntity->getVisitDate()->format('d.m.Y H:i:s'),
-             'Works' => $worksArray,
-             'Comment' => $comment,
-             'isNight' => filter_var($request->get('isNight'), FILTER_VALIDATE_BOOLEAN)
-         ];
-         $dealer = $this->getDealer($request->get('dealerId'));
-         $resultBooking = $apiServer1C->booking($data, $dealer);
-         if ($resultBooking->Code != 0) {
-             switch ((int)$resultBooking->Code) {
-                 //TODO need some documentation
-                 case 2:
-                 case 5:
-                     $error = [
-                         'title' => $translator->trans('modules.online-booking.booking-error-2-title', [], 'dc_base'),
-                         'text' => $translator->trans('modules.online-booking.booking-error-2-text', [], 'dc_base'),
-                     ];
-                     break;
-                 default:
-                     $error = [
-                         'title' => $translator->trans('modules.online-booking.time-error-title', [], 'dc_base'),
-                         'text' => $translator->trans('modules.online-booking.booking-total-text', [], 'dc_base'),
-                     ];
-                     break;
-             }
-             return new JsonResponse(['success' => false, 'code' => (int)$resultBooking->Code, 'error' => $error]);
-         }
-         try {
-             if ($isNight) {
-                 $result = $nightBookingService->addToBookingForService($User, $dealer, (string)$resultBooking->Data->RegistrationID, $visitDate, $UserCar);
-                 if (!$result['success']) {
-                     throw new Exception($result['error']);
-                 }
-                 $infobipSmsSender->sendSms($User->getPhone(), "Ваша заявка на нічне приймання {$result['href']}");
-             }
-         } catch (Exception $e) {
-             return new JsonResponse(
-                 [
-                     'success' => false,
-                     'error' =>
-                         [
-                             'title' => $translator->trans('modules.online-booking.booking-error-2-title', [], 'dc_base'),
-                             'text' => $translator->trans('modules.online-booking.booking-total-text', [], 'dc_base'),
-                             'message' => $e->getMessage()
-                         ]
-                 ]
-             );
-         }
-         $onlineBookingEntity->setDealer($dealer);
-         $onlineBookingEntity->setBookingUid((string)$resultBooking->Data->RegistrationID);
-         $onlineBookingEntity->setIsSend(1);
-         $this->em->persist($onlineBookingEntity);
-         $this->em->flush();
-         return new JsonResponse(['success' => true, 'message' => [
-             'title' => $translator->trans('modules.online-booking.booking-success-title', [], 'dc_base'),
-             'text' => $translator->trans('modules.online-booking.booking-success-text', [], 'dc_base'),
-         ]]);
-     }
-     public function booking(Request          $request, TranslatorInterface $translator, InfobipSmsSender $infobipSmsSenderb,
-                             OtpCodeGenerator $otpCodeGenerator): JsonResponse
-     {
-         $car = $request->get('car');
-         $userData = $request->get('user');
-         $user = $this->getUser();
-         $works = $request->get('works');
-         $comment = $request->get('comment');
-         $date = $request->get('date');
-         $phone = $userData['phone'];
-         $selectedConnectionType = $request->get('selectedConnectionType');
-         $selectedMobilityService = $request->get('selectedMobilityService');
-         $toGoService = strtolower($request->get('toGoService')) === 'false' ? false : true;
-         $senderCode = (is_null($request->get('senderCode'))) ? true : boolval($request->get('senderCode'));
-         $dateInst = new DateTime($date);
-         $dealer = $this->getDealer($request->get('dealerId'));
-         $onlineBookingEntity = $this->em->getRepository(OnlineServiceBooking::class)
-             ->getByDate($dateInst, $phone, $user, $dealer);
-         if ($onlineBookingEntity) {
-             return new JsonResponse(
-                 [
-                     'success' => false,
-                     'error' =>
-                         [
-                             'title' => $translator->trans('modules.online-booking.time-error-title', [], 'dc_base'),
-                             'text' => $translator->trans('modules.online-booking.today-double', [], 'dc_base'),
-                         ]
-                 ]
-             );
-         }
-         $id = $request->get('bookingId');
-         $onlineBookingEntity = $this->em->getRepository(OnlineServiceBooking::class)->find($id);
-         if (!$onlineBookingEntity) {
-             $onlineBookingEntity = new OnlineServiceBooking();
-             $onlineBookingEntity->setReferrer($request->get('referrer'));
-             $onlineBookingEntity->setHref($request->get('href'));
-             $onlineBookingEntity->setUtm($request->get('utm'));
-             $onlineBookingEntity->setGclId($request->get('gcl_id'));
-         }
-         $onlineBookingEntity->setNotifySend(0);
-         $onlineBookingEntity->setDateCreate(new DateTime());
-         $onlineBookingEntity->setName($userData['name']);
-         if (isset($userData['email'])) {
-             $onlineBookingEntity->setEmail($userData['email']);
-         }
-         $onlineBookingEntity->setPhone($phone);
-         $onlineBookingEntity->setIsSend(0);
-         $code = $otpCodeGenerator->generateCustomLength(4);
-         $onlineBookingEntity->setConfirmCode($code);
-         $onlineBookingEntity->setVisitDate($dateInst);
-         $onlineBookingEntity->setDealer($dealer);
-         $onlineBookingEntity->setComment($comment);
-         if ($user) {
-             $onlineBookingEntity->setUser($user);
-         }
-         $carId = false;
-         if (isset($car['id'])) {
-             $carId = $car['id'];
-         }
-         if ($carId) {
-             $userCar = $this->em->getRepository(UserCar::class)->find($carId);
-             if ($userCar) {
-                 $onlineBookingEntity->setUserCar($userCar);
-             }
-         }
-         $onlineBookingEntity->setCarData(json_encode($car));
-         if ($request->get('dealerId') == 14) {
-             $extra_options = [
-                 'ConnectionType' => $selectedConnectionType,
-                 'MobilityService' => $selectedMobilityService,
-                 'ToGoService' => $toGoService
-             ];
-             $onlineBookingEntity->setExtraOptionsData(json_encode($extra_options));
-         }
-         if ($works && count($works)) {
-             foreach ($works as $regulationId) {
-                 $Regulation = $this->em->getRepository(ServiceWork::class)->find($regulationId);
-                 if (!$Regulation) {
-                     continue;
-                 }
-                 /** @var ServiceWorkJob $job */
-                 foreach ($Regulation->getJobs() as $job) {
-                     $Work = new OnlineServiceBookingWorks();
-                     $Work->setJob($job->getJob());
-                     $Work->setTime($job->getJobHours());
-                     $Work->setBooking($onlineBookingEntity);
-                     $this->em->persist($Work);
-                 }
-             }
-         }
-         $this->em->persist($onlineBookingEntity);
-         $this->em->flush();
-         $smsMsgWithAuthCode = $translator->trans('auth.your_confirm_code', ['%code%' => $code], 'loyality');
-         if ($senderCode) {
-             $infobipSmsSenderb->sendSms($phone, $smsMsgWithAuthCode);
-         }
-         return new JsonResponse(['success' => true, 'bookingId' => $onlineBookingEntity->getId()]);
-     }
-     public function getDealer($dealerId = null): Dealer
-     {
-         $Dealer = false;
-         try {
-             $Dealer = parent::getDealer();
-         } catch (NotFoundHttpException $e) {
-             if ($dealerId) {
-                 $Dealer = $this->em->getRepository(Dealer::class)->find($dealerId);
-             }
-         }
-         if (!$Dealer) {
-             throw new NotFoundHttpException();
-         }
-         return $Dealer;
-     }
-     public function getServiceModelByDealer(Request $request): JsonResponse
-     {
-         $dealerId = $request->get('dealerId');
-         $models = [];
-         $repositoryModels = $this->em->getRepository(Model::class)->getModelsHasRegulationByDealer($dealerId);
-         foreach ($repositoryModels as $item) {
-             $models[$item->getId()] = [
-                 'id' => $item->getId(),
-                 'title' => $item->getTitle(),
-                 'brandId' => $item->getBrand()->getId(),
-             ];
-         }
-         return new JsonResponse(['success' => true, 'models' => $models]);
-     }
-     private function getUserNight(Request $request): User
-     {
-         $phone = $request->get('phone');
-         $phone = preg_replace("/[^0-9]/", '', $phone);
-         $phone = preg_replace("/^38/", '', $phone);
-         $rows = $this->em->getRepository(User::class)
-             ->createQueryBuilder('u')
-             ->where('u.phone = :phone')
-             ->setParameter('phone', $phone)
-             ->orderBy('u.id', 'DESC')
-             ->getQuery()
-             ->getResult();
-         if (!empty($rows)) {
-             return $rows[0];
-         }
-         $User = new User();
-         $User->setName($request->get('name'));
-         $User->setPhone($phone);
-         $User->setEmail(bin2hex(random_bytes(5)) . '@gmail.com');
-         $User->setConfirmedPhone(true);
-         $User->setUsername($phone);
-         $User->setUsernameCanonical($phone);
-         $User->setEnabled(true);
-         $User->setPlainPassword(time());
-         $User->addRole('ROLE_LOYALTY_USER');
-         $User->setRegistrationConfirm(true);
-         $this->em->persist($User);
-         $this->em->flush();
-         return $User;
-     }
-     private function getUserCarNight(Request $request, User $User)
-     {
-         $UserCar = $this->em->getRepository(UserCar::class)->findOneBy(['number' => $request->get('carNumber'), 'user' => $User]);
-         if (empty($UserCar)) {
-             $UserCar = new UserCar();
-             $UserCar->setUser($User);
-         }
-         $UserCar->setBrand($request->get('carBrand'));
-         $UserCar->setModel($request->get('carModel'));
-         $UserCar->setNumber($request->get('carNumber'));
-         $this->em->persist($UserCar);
-         $this->em->flush();
-         return $UserCar;
-     }
- }
-