src/DcSiteBundle/Controller/RegulationToController.php line 297

Open in your IDE?
  1. <?php
  2. namespace DcSiteBundle\Controller;
  3. use CoreBundle\Component\CoreFormFactory;
  4. use CoreBundle\Component\FormManager;
  5. use CoreBundle\Entity\Brand;
  6. use CoreBundle\Entity\Dealer;
  7. use CoreBundle\Entity\Model;
  8. use CoreBundle\Entity\Vehicles\Vehicle;
  9. use CoreBundle\Factory\Vehicle as VehicleFactory;
  10. use CoreBundle\Model\Api\OnlineService\ApiServer1C;
  11. use CoreBundle\Model\Vehicles\Repository;
  12. use CoreBundle\Services\MediaExtensionVidi;
  13. use DateTime;
  14. use DcSiteBundle\Entity\ServiceVariation;
  15. use DcSiteBundle\Entity\ServiceWork;
  16. use DcSiteBundle\Entity\ServiceWorkJob;
  17. use DcSiteBundle\Entity\ServiceWorkPart;
  18. use Doctrine\ORM\EntityManagerInterface;
  19. use Monolog\Handler\StreamHandler;
  20. use Monolog\Logger;
  21. use Mpdf\Mpdf;
  22. use Mpdf\MpdfException;
  23. use PortalBundle\Model\SeoMetaTag;
  24. use Symfony\Component\Filesystem\Filesystem;
  25. use Symfony\Component\HttpFoundation\JsonResponse;
  26. use Symfony\Component\HttpFoundation\Request;
  27. use Symfony\Component\HttpFoundation\RequestStack;
  28. use Symfony\Component\HttpFoundation\Response;
  29. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  30. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  31. use Symfony\Component\Routing\RouterInterface;
  32. use Twig\Environment;
  33. class RegulationToController extends BaseDcController
  34. {
  35.     public function __construct(CoreFormFactory $coreFormFactorySeoMetaTag $seoMetaTagRequestStack $requestStackRouterInterface $routerFormManager $formManagerEntityManagerInterface $emApiServer1C $apiServer1CSessionInterface $sessionFilesystem $filesystemMediaExtensionVidi $mediaExtensionVidiRepository $vehicleRepositoryVehicleFactory $vehicleFactoryEnvironment $twig)
  36.     {
  37.         parent::__construct($coreFormFactory$seoMetaTag$requestStack$router$formManager$em$apiServer1C$session$filesystem$mediaExtensionVidi$vehicleRepository$vehicleFactory$twig);
  38.     }
  39.     public function init(Request $request): JsonResponse
  40.     {
  41.         try {
  42.             $dealerId $request->get('dealer');
  43.             if ($dealerId) {
  44.                 $Dealer $this->em->getRepository(Dealer::class)->find($dealerId);
  45.             } else {
  46.                 $Dealer $this->getDealer();
  47.             }
  48.         } catch (NotFoundHttpException $e) {
  49.             $Dealer false;
  50.         }
  51.         if (!$Dealer) {
  52.             $CarRepo $this->vehicleRepository;
  53.             $brands $CarRepo->getAvailBrandsInstance($request->getLocale());
  54.             foreach ($brands as &$brand) {
  55.                 $brand['image'] = $this->mediaExtensionVidi->getPath($brand['image'], 'menu');
  56.             }
  57.             return new JsonResponse(['success' => true'brands' => $brands]);
  58.         }
  59.         $imageProvider $this->mediaExtensionVidi;
  60.         $brandId $request->get('brandId');
  61.         $variations $this->em->getRepository(ServiceVariation::class)->getRegulationVariations($Dealer$brandId);
  62.         $models = [];
  63.         /** @var ServiceVariation $variation */
  64.         foreach ($variations as $variation) {
  65.             $Model $variation->getModel();
  66.             if (!isset($models[$Model->getId()])) {
  67.                 $modelImage $Model->getImage();
  68.                 if ($modelImage) {
  69.                     $img $imageProvider->getPath($modelImage'small');
  70.                 } else {
  71.                     $vehicle $this->em->getRepository(Vehicle::class)->findOneBy(['dealer' => $Dealer'model' => $Model'state' => 1'is_used' => 0]);
  72.                     $img = ($vehicle) ? $imageProvider->getPath($vehicle->getPreview(), 'small') : $imageProvider->getPath($Model->getBrand()->getLogo(), 'reference');
  73.                 }
  74.                 $models[$Model->getId()] = [
  75.                     'id' => $Model->getId(),
  76.                     'title' => $Model->getTitle(),
  77.                     'img' => $img,
  78.                 ];
  79.             }
  80.         }
  81.         usort($models, fn($item1$item2) => $item1['title'] <=> $item2['title']);
  82.         return new JsonResponse(['success' => true'models' => $models]);
  83.     }
  84.     public function getDataRegulationTo(): JsonResponse
  85.     {
  86.         $repositoryBrands $this->em->getRepository(Brand::class)->getBrandsHasRegulation();
  87.         $brands = [];
  88.         $models = [];
  89.         $dealers = [];
  90.         /** @var Brand $brand */
  91.         foreach ($repositoryBrands as $brand) {
  92.             $brands[$brand->getId()] = [
  93.                 'id' => $brand->getId(),
  94.                 'title' => $brand->getName()
  95.             ];
  96.             /** @var Dealer $dealer */
  97.             foreach ($brand->getDealer() as $dealer) {
  98.                 $isNight $dealer->getIsNightDealer();
  99.                 $agreementUrl = ($isNight) ? $this->router->generate('my_profile_night_service_agreement_dealer', ['dealerUrl' => $dealer->getUrl()]) : false;
  100.                 $dealers[$brand->getId()][$dealer->getId()] = [
  101.                     'id' => $dealer->getId(),
  102.                     'title' => $dealer->getNameByLocale('ua'),
  103.                     'isNight' => $isNight,
  104.                     'agreementUrl' => $agreementUrl,
  105.                     'brandId' => $brand->getId()
  106.                 ];
  107.             }
  108.             $models[$brand->getId()] = $this->getModelsHasRegulationByBrand($brand->getId());
  109.         }
  110.         return new JsonResponse(['success' => true'brands' => $brands'models' => $models'dealers' => $dealers]);
  111.     }
  112.     public function getModelsHasRegulationByBrand($brandId): array
  113.     {
  114.         $repositoryModels $this->em->getRepository(Model::class)->getModelsHasRegulationByBrand($brandId);
  115.         $models = [];
  116.         /** @var Model $item */
  117.         foreach ($repositoryModels as $item) {
  118.             $models[$item->getId()] = [
  119.                 'id' => $item->getId(),
  120.                 'title' => $item->getTitle(),
  121.                 'brandId' => $item->getBrand()->getId()
  122.             ];
  123.         }
  124.         return $models;
  125.     }
  126.     public function getFilteredDealersByModel(Request $request): JsonResponse
  127.     {
  128.         $modelId $request->get('modelId');
  129.         $repositoryServiceVariations $this->em->getRepository(ServiceVariation::class)->findDealersByModel($modelId);
  130.         $dealerIds = [];
  131.         foreach ($repositoryServiceVariations as $repositoryServiceVariation) {
  132.             if ($repositoryServiceVariation->getDealer()->getId() == 7) { // unset Toyota Palmira
  133.                 continue;
  134.             }
  135.             $dealerIds[] = $repositoryServiceVariation->getDealer()->getId();
  136.         }
  137.         return new JsonResponse(['success' => true'dealerIds' => array_values(array_unique($dealerIds))]);
  138.     }
  139.     public function getVariationRegulationToByFilter(Request $request): JsonResponse
  140.     {
  141.         $modelId $request->get('modelId');
  142.         $dealerId $request->get('dealerId');
  143.         $locale $request->getLocale();
  144.         $repositoryServiceVariations $this->em->getRepository(ServiceVariation::class)->findRegulationWorkByVariation($dealerId$modelId);
  145.         $makeYears = [];
  146.         $variations = [];
  147.         $works = [];
  148.         /** @var ServiceVariation $serviceVariation */
  149.         foreach ($repositoryServiceVariations as $serviceVariation) {
  150.             $yearTo = ($serviceVariation->getYearTo() == 0) ? date('Y'time()) : $serviceVariation->getYearTo();
  151.             $makeYearId $serviceVariation->getYearFrom() . $yearTo;
  152.             if (!isset($makeYears[$serviceVariation->getYearFrom()])) {
  153.                 $makeYears[$makeYearId] = [
  154.                     'id' => $makeYearId,
  155.                     'title' => $serviceVariation->getYearFrom() . ' - ' $yearTo,
  156.                 ];
  157.             }
  158.             $variationsTitle '';
  159.             if ($serviceVariation->getFuelType()) {
  160.                 $variationsTitle .= $serviceVariation->getFuelType()->getValue($locale);
  161.             }
  162.             $variationsTitle .= ' ' round($serviceVariation->getEngineVolume() / 10001) . 'л';
  163.             if ($serviceVariation->getDriveUnit()) {
  164.                 $variationsTitle .= ', ' $serviceVariation->getDriveUnit()->getValue($locale);
  165.             }
  166.             if ($serviceVariation->getTransmissionType()) {
  167.                 $variationsTitle .= ', ' $serviceVariation->getTransmissionType()->getValue($locale);
  168.             }
  169.             $variationsTitle .= ($serviceVariation->getTransmissionStepCount()) ? ', ' $serviceVariation->getTransmissionStepCount() . 'ст.' '';
  170.             if ($serviceVariation->getEmission()) {
  171.                 $variationsTitle .= ', ' $serviceVariation->getEmission();
  172.             }
  173.             if ($serviceVariation->getDescription()) {
  174.                 $variationsTitle .= ', ' $serviceVariation->getDescription();
  175.             }
  176.             $variations[] = [
  177.                 'id' => $serviceVariation->getId(),
  178.                 'title' => $variationsTitle,
  179.                 'makeYearId' => $makeYearId,
  180.                 'yearFrom' => $serviceVariation->getYearFrom(),
  181.                 'yearTo' => $yearTo,
  182.             ];
  183.             $repositoryServiceWorks $this->em->getRepository(ServiceWork::class)->findRegulationWorkByVariation($serviceVariation);
  184.             /** @var ServiceWork $serviceWork */
  185.             foreach ($repositoryServiceWorks as $serviceWork) {
  186.                 $works[$serviceWork->getId()] = [
  187.                     'id' => $serviceWork->getId(),
  188.                     'title' => $serviceWork->getMileage(),
  189.                     'variationId' => $serviceVariation->getId(),
  190.                 ];
  191.             }
  192.             usort($works, fn($item1$item2) => $item1['title'] <=> $item2['title']);
  193.         }
  194.         return new JsonResponse(['success' => true'makeYears' => $makeYears'variations' => $variations'works' => $works]);
  195.     }
  196.     public function getRegulationWork(Request $request): JsonResponse
  197.     {
  198.         $locale $request->getLocale();
  199.         $workId $request->get('workId');
  200.         $work $this->em->getRepository(ServiceWork::class)->find($workId);
  201.         if (!$work) {
  202.             return new JsonResponse(['success' => false]);
  203.         }
  204.         $regulationWork $this->getRegulationToWork($work$locale);
  205.         return new JsonResponse(['success' => true'regulationWork' => $regulationWork]);
  206.     }
  207.     private function getRegulationToWork(ServiceWork $work$locale): array
  208.     {
  209.         $regulationWork = [
  210.             'works' => [],
  211.             'parts' => [],
  212.             'cost' => [
  213.                 'costWorks' => 0,
  214.                 'costParts' => 0,
  215.                 'costRegulationWork' => 0,
  216.             ],
  217.             'mileage' => $work->getMileage(),
  218.         ];
  219.         /** @var ServiceWorkJob $job */
  220.         foreach ($work->getJobs() as $job) {
  221.             $regulationWork['works'][] = [
  222.                 'title' => $job->getJob()->getNameByLocale($locale),
  223.                 'price' => round($job->getPrice()),
  224.             ];
  225.             $regulationWork['cost']['costWorks'] += round($job->getPrice());
  226.         }
  227.         /** @var ServiceWorkPart $part */
  228.         foreach ($work->getParts() as $part) {
  229.             if (empty($part->getPrice())) {
  230.                 $cost round($part->getCount() * $part->getPart()->getPrice());
  231.             } else {
  232.                 $cost round($part->getCount() * $part->getPrice());
  233.             }
  234.             $regulationWork['parts'][] = [
  235.                 'title' => $part->getPart()->getNameByLocale($locale),
  236.                 'count' => $part->getCount(),
  237.                 'price' => round($cost),
  238.             ];
  239.             $regulationWork['cost']['costParts'] += round($cost);
  240.         }
  241.         $regulationWork['cost']['costRegulationWork'] = $regulationWork['cost']['costWorks'] + $regulationWork['cost']['costParts'];
  242.         return $regulationWork;
  243.     }
  244.     public function variations(Request $request): JsonResponse
  245.     {
  246.         $modelId $request->request->get('modelId');
  247.         $dealerId $request->get('dealer');
  248.         if ($dealerId) {
  249.             $Dealer $this->em->getRepository(Dealer::class)->find($dealerId);
  250.         } else {
  251.             $Dealer $this->getDealer();
  252.         }
  253.         $variations $this->em->getRepository(ServiceVariation::class)->findBy(['dealer' => $Dealer'model' => $modelId'is_delete' => [0null]], ['year_from' => 'ASC']);
  254.         $variationsArray = [];
  255.         /** @var ServiceVariation $variation */
  256.         foreach ($variations as $variation) {
  257.             $hasRegulation false;
  258.             /** @var ServiceWork $work */
  259.             foreach ($variation->getServiceWorks() as $work) {
  260.                 if ($work->getIsRegulations()) {
  261.                     $hasRegulation true;
  262.                 }
  263.             }
  264.             if (!$hasRegulation) {
  265.                 continue;
  266.             }
  267.             $key $variation->getYearFrom() . ' - ' . ($variation->getYearTo() ?: '...');
  268.             if (!isset($variationsArray[$key])) {
  269.                 $variationsArray[$key] = [
  270.                     'period' => $key,
  271.                     'from' => $variation->getYearFrom(),
  272.                     'to' => $variation->getYearTo() ?: (int)(new DateTime())->format('Y'),
  273.                     'image' => null,
  274.                     'image_webp' => null,
  275.                     'items' => [],
  276.                 ];
  277.             }
  278.             $vImage $variation->getImage();
  279.             if (!$variationsArray[$key]['image'] && $vImage) {
  280.                 $variationsArray[$key]['image'] = $this->mediaExtensionVidi->getPath($vImage'reference');
  281.                 $variationsArray[$key]['image_webp'] = $this->mediaExtensionVidi->pathWebp($vImage'reference');
  282.             } else if (!$variationsArray[$key]['image']) {
  283.                 $variationsArray[$key]['image'] = $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference');
  284.                 $variationsArray[$key]['image_webp'] = $this->mediaExtensionVidi->pathWebp($Dealer->getBrand()->getLogo(), 'reference');
  285.             }
  286.             $fuel $variation->getFuelType() ? $variation->getFuelType()->getValue($request->getLocale()) : '';
  287.             $volume $variation->getEngineVolume();
  288.             if ($volume 200) {
  289.                 $volume number_format(round($volume 10001), 1'.''');
  290.             }
  291.             $power $variation->getPower();
  292. //            $engine = $fuel.' / '.$volume.' куб.см.';
  293. //            if($power) {
  294. //                $engine .= ' / '. $power . ($request->getLocale() == 'ru' ? 'л.с.' : 'к.с.');
  295. //            }
  296.             $transmission $variation->getTransmissionType() ? $variation->getTransmissionType()->getValue($request->getLocale()) : false;
  297.             if ($transmission && $variation->getTransmissionStepCount()) {
  298.                 $transmission .= ', ' $variation->getTransmissionStepCount() . ' ст.';
  299.             }
  300.             $variationsArray[$key]['items'][] = [
  301.                 'id' => $variation->getId(),
  302.                 'fuel' => $fuel,
  303.                 'volume' => $volume,
  304.                 'engineName' => $variation->getEngineName(),
  305.                 'emission' => $variation->getEmission(),
  306.                 'power' => $power,
  307.                 'trans' => $transmission,
  308.                 'drive' => $variation->getDriveUnit() ? $variation->getDriveUnit()->getValue($request->getLocale()) : false,
  309.                 'description' => $variation->getDescription(),
  310.             ];
  311.         }
  312.         foreach ($variationsArray as &$variationPeriod) {
  313.             usort($variationPeriod['items'], fn($item1$item2) => $item1['drive'] <=> $item2['drive']);
  314.             usort($variationPeriod['items'], fn($item1$item2) => $item1['trans'] <=> $item2['trans']);
  315.             usort($variationPeriod['items'], fn($item1$item2) => $item1['volume'] <=> $item2['volume']);
  316.         }
  317.         return new JsonResponse(['success' => true'variations' => $variationsArray]);
  318.     }
  319.     public function reg(Request $request): JsonResponse
  320.     {
  321.         $dealerId $request->get('dealer');
  322.         if ($dealerId) {
  323.             $Dealer $this->em->getRepository(Dealer::class)->find($dealerId);
  324.         } else {
  325.             $Dealer $this->getDealer();
  326.         }
  327.         $vId $request->request->get('vId');
  328.         $V $this->em->getRepository(ServiceVariation::class)->find($vId);
  329.         $regulations $V->getServiceWorks();
  330.         $regulationsArray = [
  331.             'mileages' => [],
  332.             'parts' => [],
  333.             'works' => [],
  334.             'amounts' => [],
  335.             'id' => [],
  336.         ];
  337.         /** @var ServiceWork $regulation */
  338.         foreach ($regulations as $regulation) {
  339.             if (!$regulation->getIsRegulations()) {
  340.                 continue;
  341.             }
  342.             $regulationsArray['mileages'][] = $regulation->getMileage();
  343.             $regulationsArray['id'][$regulation->getMileage()] = $regulation->getId();
  344.             /** @var ServiceWorkPart $part */
  345.             foreach ($regulation->getParts() as $part) {
  346.                 if (!$part->getPart()) {
  347.                     continue;
  348.                 }
  349.                 if (empty($part->getPrice())) {
  350.                     $pCost round($part->getPart()->getPrice() * $part->getCount());
  351.                 } else {
  352.                     $pCost round($part->getPrice() * $part->getCount());
  353.                 }
  354.                 if (!isset($regulationsArray['parts'][$part->getPart()->getId()])) {
  355.                     $regulationsArray['parts'][$part->getPart()->getId()] = [
  356.                         'title' => $part->getPart()->getNameByLocale($request->getLocale()),
  357.                         'price' => $part->getPart()->getPrice(),
  358.                         'units' => $part->getUnits()->getShortRu(),
  359.                         'unit' => $part->getUnits()->getShortRu(),
  360.                         'mileages' => [],
  361.                     ];
  362.                 }
  363.                 $regulationsArray['parts'][$part->getPart()->getId()]['mileages'][$regulation->getMileage()] = [
  364.                     'count' => $part->getCount(),
  365.                     'amount' => $pCost,
  366.                 ];
  367.                 if (!isset($regulationsArray['amounts'][$regulation->getMileage()])) {
  368.                     $regulationsArray['amounts'][$regulation->getMileage()] = 0;
  369.                 }
  370.                 if (!isset($regulationsArray['partsAmount'][$regulation->getMileage()])) {
  371.                     $regulationsArray['partsAmount'][$regulation->getMileage()] = 0;
  372.                 }
  373.                 $regulationsArray['amounts'][$regulation->getMileage()] += $pCost;
  374.                 $regulationsArray['partsAmount'][$regulation->getMileage()] += $pCost;
  375.             }
  376.             /** @var ServiceWorkJob $job */
  377.             foreach ($regulation->getJobs() as $job) {
  378.                 if (!isset($regulationsArray['works'][$job->getJob()->getId()])) {
  379.                     $regulationsArray['works'][$job->getJob()->getId()] = [
  380.                         'title' => $job->getJob()->getNameByLocale($request->getLocale()),
  381.                         'mileages' => [],
  382.                     ];
  383.                 }
  384.                 $regulationsArray['works'][$job->getJob()->getId()]['mileages'][$regulation->getMileage()] = [
  385.                     'amount' => $job->getJobHours(),
  386.                 ];
  387.                 if (!isset($regulationsArray['amounts'][$regulation->getMileage()])) {
  388.                     $regulationsArray['amounts'][$regulation->getMileage()] = 0;
  389.                 }
  390.                 if (!isset($regulationsArray['jobsAmount'][$regulation->getMileage()])) {
  391.                     $regulationsArray['jobsAmount'][$regulation->getMileage()] = 0;
  392.                 }
  393.                 $regulationsArray['amounts'][$regulation->getMileage()] += $job->getPrice();
  394.                 $regulationsArray['jobsAmount'][$regulation->getMileage()] += $job->getPrice();
  395.             }
  396.             $regulationsArray['amounts'][$regulation->getMileage()] = round($regulationsArray['amounts'][$regulation->getMileage()], 2);
  397.             $regulationsArray['jobsAmount'][$regulation->getMileage()] = round($regulationsArray['jobsAmount'][$regulation->getMileage()], 2);
  398.         }
  399.         sort($regulationsArray['mileages']);
  400.         return new JsonResponse(['regulations' => $regulationsArray]);
  401.     }
  402.     public function download(Request $requestFilesystem $filesystem): Response
  403.     {
  404.         $dealerId $request->get('dealer');
  405.         $vidiSite false;
  406.         $excludeDealers = [315];
  407.         if ($dealerId) {
  408.             $Dealer $this->em->getRepository(Dealer::class)->find($dealerId);
  409.             $vidiSite true;
  410.         } else {
  411.             $Dealer $this->getDealer();
  412.             if (in_array($Dealer->getId(), $excludeDealers)) {
  413.                 $vidiSite true;
  414.             }
  415.         }
  416.         $vId $request->get('vId');
  417.         $ToVariation $this->em->getRepository(ServiceVariation::class)->find($vId);
  418.         if (!$ToVariation) {
  419.             throw new NotFoundHttpException();
  420.         }
  421.         $regulationTo = [];
  422.         $workId $request->get('workId');
  423.         if ($workId) {
  424.             $serviceWorkTo $this->em->getRepository(ServiceWork::class)->find($workId);
  425.             $regulationTo $this->getRegulationToWork($serviceWorkTo'ua');
  426.         }
  427.         $regulationData $this->getRegulationData($Dealer$ToVariation$request);
  428.         $model $ToVariation->getModel();
  429.         $fTypeName $ToVariation->getFuelType() ? $ToVariation->getFuelType()->getValueUa() : '';
  430.         $tTypeName $ToVariation->getTransmissionType() ? $ToVariation->getTransmissionType()->getValueUa() : '';
  431.         $dTypeName $ToVariation->getDriveUnit() ? $ToVariation->getDriveUnit()->getValueUa() : '';
  432.         $title $model->getBrand()->getNameUa() . ' ' .
  433.             $model->getTitle() . ' ' .
  434.             $fTypeName ', ' .
  435.             $tTypeName ', ' .
  436.             $dTypeName ' ';
  437.         try {
  438.             $rootDir $this->getParameter('kernel.project_dir');
  439.             $newTempDir $this->getParameter('file_directory_mpdf');
  440.             if (!$filesystem->exists($newTempDir)) {
  441.                 $filesystem->mkdir($newTempDir0777);
  442.             }
  443.             $mpdf = new Mpdf(['mode' => 'utf-8''format' => [420270], 'tempDir' => $newTempDir'curlAllowUnsafeSslRequests' => true]);
  444.             $mpdf->curlAllowUnsafeSslRequests true;
  445. //            $mpdf->showImageErrors = true;
  446.             $logger = new Logger('mpdf');
  447.             $logger->pushHandler(new StreamHandler($rootDir '/var/logs/mpdf.log'Logger::DEBUG));
  448.             $mpdf->setLogger($logger);
  449.             if ($filesystem->exists($rootDir '/public' $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference'))) {
  450.                 $brandLogoImage file_get_contents($rootDir '/public' $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference'));
  451.                 $mpdf->imageVars['brand'] = $brandLogoImage;
  452.             }
  453.             $mpdf->imageVars['header'] = file_get_contents($rootDir '/src/DcSiteBundle/Resources/public/img/modules/reglament-to-pdf/logo-header.png');
  454.             $mpdf->imageVars['footer'] = file_get_contents($rootDir '/src/DcSiteBundle/Resources/public/img/logo-vidi-big.jpg');
  455.             $mpdf->imageVars['qr'] = file_get_contents($rootDir '/public/bundles/dcsite/img/qr_code/map/qr_code_night_booking.svg');
  456.             $mpdf->imageVars['dcMap'] = file_get_contents($rootDir '/public/bundles/dcsite/img/qr_code/map/dc_map_' $Dealer->getId() . '.svg');
  457.             $mpdf->imageVars['map'] = file_get_contents($rootDir '/public/bundles/dcsite/img/map-icon.png');
  458.             $mpdf->imageVars['phone'] = file_get_contents($rootDir '/public/bundles/dcsite/img/phone-icon.png');
  459.             $mpdf->imageVars['watch'] = file_get_contents($rootDir '/public/bundles/dcsite/img/watch-icon.png');
  460.             $regulationData['regulationData'] = array_slice($regulationData['regulationData'], 012);
  461.             $logoMediaUrl $Dealer->getBrand() ? $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogo(), 'reference') : null;
  462.             $logoMediaWhiteUrl $Dealer->getBrand() ? $this->mediaExtensionVidi->getPath($Dealer->getBrand()->getLogoWhite(), 'reference') : null;
  463.             $logoImage '';
  464.             $logoWhiteImage '';
  465.             if ($vidiSite) {
  466.                 $logoImage parse_url($logoMediaUrlPHP_URL_PATH);
  467.                 $logoWhiteImage parse_url($logoMediaWhiteUrlPHP_URL_PATH);
  468.             }
  469.             $html $this->twig->render('@DcSite/Modules/reglament-to-pdf/reglament-to.html.twig', [
  470.                 'regulations' => $regulationData['regulationData'],
  471.                 'regulationTo' => $regulationTo,
  472.                 'dealer' => $Dealer,
  473.                 'logoImage' => $logoImage,
  474.                 'logoWhiteImage' => $logoWhiteImage,
  475.                 'model' => $model,
  476.                 'title' => $title,
  477.                 'amountWork' => $regulationData['amountWorks'],
  478.                 'amountParts' => $regulationData['amountParts'],
  479.                 'amountOverall' => $regulationData['overall'],
  480.             ]);
  481.             $mpdf->WriteHTML($html);
  482.             $mpdf->Output();
  483.             return new Response();
  484.         } catch (MpdfException $exception) {
  485.             throw new NotFoundHttpException();
  486.         }
  487.     }
  488.     public function getRegulationData(Dealer $dealerServiceVariation $serviceVariationRequest $request): array
  489.     {
  490.         $regulations $serviceVariation->getServiceWorks();
  491.         $regulationsArray = [
  492.             'mileages' => [],
  493.             'parts' => [],
  494.             'works' => [],
  495.             'amounts' => [],
  496.         ];
  497.         $amountParts false;
  498.         $amountWorks false;
  499.         $overall false;
  500.         $hCost $dealer->getHourCost();
  501.         /** @var ServiceWork $regulation */
  502.         foreach ($regulations as $regulation) {
  503.             if (!$regulation->getIsRegulations() || count($regulationsArray['mileages']) >= 12) {
  504.                 continue;
  505.             }
  506.             $regulationsArray['mileages'][] = $regulation->getMileage();
  507.             $amountParts[$regulation->getMileage()] = 0;
  508.             $amountWorks[$regulation->getMileage()] = 0;
  509.             /** @var ServiceWorkPart $part */
  510.             foreach ($regulation->getParts() as $part) {
  511.                 if (!$part->getPart()) {
  512.                     continue;
  513.                 }
  514.                 if (empty($part->getPrice())) {
  515.                     $pCost round($part->getPart()->getPrice() * $part->getCount());
  516.                 } else {
  517.                     $pCost round($part->getPrice() * $part->getCount());
  518.                 }
  519.                 if (!isset($regulationsArray['parts'][$part->getPart()->getId()])) {
  520.                     $regulationsArray['parts'][$part->getPart()->getId()] = [
  521.                         'title' => $part->getPart()->getNameByLocale($request->getLocale()),
  522.                         'price' => $part->getPart()->getPrice(),
  523.                         'units' => $part->getUnits()->getShortRu(),
  524.                         'count' => $part->getCount(),
  525.                         'mileages' => [],
  526.                     ];
  527.                 }
  528.                 $regulationsArray['parts'][$part->getPart()->getId()]['mileages'][$regulation->getMileage()] = [
  529.                     'amount' => $pCost,
  530.                 ];
  531.                 if (!isset($regulationsArray['amounts'][$regulation->getMileage()])) {
  532.                     $regulationsArray['amounts'][$regulation->getMileage()] = 0;
  533.                 }
  534.                 $regulationsArray['amounts'][$regulation->getMileage()] += $pCost;
  535.                 $amountParts[$regulation->getMileage()] += $pCost;
  536.             }
  537.             /** @var ServiceWorkJob $job */
  538.             foreach ($regulation->getJobs() as $job) {
  539.                 $jCost round($job->getPrice(), 2);
  540.                 if (!isset($regulationsArray['works'][$job->getJob()->getId()])) {
  541.                     $regulationsArray['works'][$job->getJob()->getId()] = [
  542.                         'title' => $job->getJob()->getNameByLocale($request->getLocale()),
  543.                         'mileages' => [],
  544.                     ];
  545.                 }
  546.                 $regulationsArray['works'][$job->getJob()->getId()]['mileages'][$regulation->getMileage()] = [
  547.                     'amount' => $jCost,
  548.                     'hours' => $job->getJobHours(),
  549.                 ];
  550.                 if (!isset($regulationsArray['amounts'][$regulation->getMileage()])) {
  551.                     $regulationsArray['amounts'][$regulation->getMileage()] = 0;
  552.                 }
  553.                 $regulationsArray['amounts'][$regulation->getMileage()] += $jCost;
  554.                 $amountWorks[$regulation->getMileage()] += $jCost;
  555.                 if (!isset($overall[$regulation->getMileage()])) {
  556.                     $overall[$regulation->getMileage()] = 0;
  557.                 }
  558.                 $overall[$regulation->getMileage()] = $amountWorks[$regulation->getMileage()] + $amountParts[$regulation->getMileage()];
  559.             }
  560.         }
  561.         sort($regulationsArray['mileages']);
  562.         return ['regulationData' => $regulationsArray'amountParts' => $amountParts'amountWorks' => $amountWorks'overall' => $overall];
  563.     }
  564.     public function widgetTest(): Response
  565.     {
  566.         return new Response('<iframe width="100%" height="100%" src="http://new.vidi.yz/ua/regulation/toyota"></iframe>'Response::HTTP_OK);
  567.     }
  568. }