src/Controller/BookingProcessCMMVP1Controller.php line 3244

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\DependencyInjection\ContainerInterface;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\JsonResponse;
  8. use Symfony\Component\HttpFoundation\Cookie;
  9. use Symfony\Component\HttpFoundation\RequestStack;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\HttpFoundation\RedirectResponse;
  12. use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
  13. use Symfony\Contracts\HttpClient\HttpClientInterface;
  14. use Symfony\Contracts\HttpClient\Exception\TransportExceptionInterface;
  15. use Doctrine\ORM\Query\Expr;
  16. use Doctrine\ORM\Query\Expr\Join;
  17. use Doctrine\Persistence\ManagerRegistry;
  18. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  19. use App\Security\LoginFormAuthenticator;
  20. use Symfony\Component\Security\Guard\GuardAuthenticatorHandler;
  21. use Orc\BookingBundle\Entity\Crew;
  22. use Orc\BookingBundle\Entity\Region;
  23. use Orc\BookingBundle\Entity\Location;
  24. use Orc\BookingBundle\Entity\Boundary;
  25. use Orc\BookingBundle\Entity\Booking;
  26. use Orc\BookingBundle\Entity\BookingStatus;
  27. use Orc\BookingBundle\Entity\BookingServiceField;
  28. use Orc\BookingBundle\Entity\Customer;
  29. use Orc\BookingBundle\Entity\CustomerBilling;
  30. use Orc\BookingBundle\Entity\Service;
  31. use Orc\BookingBundle\Entity\ServiceField;
  32. use Orc\BookingBundle\Booking\PointInPolygon;
  33. use Orc\BookingBundle\Schedule\Scheduler\StrictScheduler\Scheduler;
  34. use Orc\BookingBundle\Schedule\Scheduler\StrictScheduler\DayScheduler;
  35. use Orc\BookingBundle\Twig\Extension\CalendarExtension;
  36. use Orc\BookingBundle\Repository\BookingRepository;
  37. use Orc\BookingBundle\Repository\HoursOfOperationRepository;
  38. use Orc\BookingBundle\Repository\HoursChangeRepository;
  39. use Orc\BookingBundle\Booking\EndTimeCalculator;
  40. use Orc\BookingBundle\Repository\RegionRepository;
  41. use Orc\BookingBundle\Repository\CustomerRepository;
  42. use Orc\BookingBundle\Mailer\ConfirmationMailer;
  43. use Orc\BookingBundle\Mailer\ConfirmationMailerForProcess;
  44. use Orc\BookingBundle\Mailer\ChangeMailer;
  45. use Orc\BookingBundle\Mailer\NotificationMailer;
  46. use Symfony\Component\Mailer\MailerInterface;
  47. use Symfony\Component\Mime\Email;
  48. use Symfony\Component\Mime\Address;
  49. use Orc\SaasBundle\Entity\Client;
  50. use Orc\UserBundle\Entity\User;
  51. use App\Controller\BaseController;
  52. use App\Entity\BookingProcess;
  53. use App\Entity\BookingProcessBooking;
  54. use App\Entity\BookingProcessLocation;
  55. use App\Entity\BookingProcessCustomer;
  56. use App\Entity\BookingProcessCustomerBilling;
  57. use App\Entity\BookingProcessBookingNote;
  58. use App\Entity\BookingProcessBookingRegion;
  59. use App\Entity\BookingProcessBookingServiceAnswer;
  60. use App\Model\EntityModel\ClientEntityModel;
  61. use App\Model\EntityModel\EmailsEntityModel;
  62. use App\Service\BaseService;
  63. use App\Service\IpStackService;
  64. use App\Service\ColorUtilsService;
  65. use App\Service\Mapservice;
  66. use App\Service\WebhookService;
  67. use App\Service\ScheduleAvailabilityCMMVP1Service;
  68. use App\Service\RoutezillaDebugger;
  69. use App\Service\SalesForceI360AppointmentsService;
  70. use App\Model\GoogleCalendarModel;
  71. use App\Model\Google\GoogleClient;
  72. use App\Model\EntityModel\WorkerEnityModel;
  73. use Orc\BookingBundle\Mailer\GoogleCalendarNotificationMailer;
  74. use Ramsey\Uuid\Uuid;
  75. use Symfony\Component\Serializer\Encoder\JsonEncoder;
  76. use Symfony\Component\Serializer\Encoder\XmlEncoder;
  77. use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
  78. use Symfony\Component\Serializer\Serializer;
  79. use Orc\BookingBundle\Booking\RadiusUpdater;
  80. use \Orc\BookingBundle\Booking\DistanceCalculator;
  81. use App\Model\EntityModel\BookingEntityModel;
  82. use Mobile_Detect;
  83. class BookingProcessCMMVP1Controller extends BaseController
  84. {
  85.     protected $doctrine null;
  86.     protected $entityManager null;
  87.     protected $userRepository null;
  88.     protected $bookingProcessRepository null;
  89.     protected $regionRepository null;
  90.     protected $serviceRepository null;
  91.     protected $customerRepository null;
  92.     protected $loginFormAuthenticator null;
  93.     protected $guardAuthenticatorHandler null;
  94.     protected $request null;
  95.     protected $pointInPolygon null;
  96.     protected $baseService null;
  97.     protected $client null;
  98.     protected $clientEntityModel null;
  99.     protected $stepoutput = ['code' => 0'message' => '''exception' => null];
  100.     protected $endTimeCalculator null;
  101.     protected $dayScheduler null;
  102.     protected $scheduler null;
  103.     protected $ipStackService null;
  104.     protected $ipStackInfo null;
  105.     protected $confirmationMailer null;
  106.     protected $confirmationMailerForProcess null;
  107.     protected $changeMailer null;
  108.     protected $notificationMailer null;
  109.     protected $colorUtilsService null;
  110.     protected $emailsEntityModel null;
  111.     protected $googleClient null;
  112.     protected $googleCalendarModel null;
  113.     protected $googleCalendarNotificationMailer null;
  114.     protected $workerEnityModel null;
  115.     protected $radiusUpdater null;
  116.     protected $container null;
  117.     protected $mapservice null;
  118.     protected $distanceCalculator null;
  119.     protected $scheduleAvailabilityCMMVP1Service null;
  120.     protected $bookingEntityModel null;
  121.     protected $httpClient null;
  122.     protected $webhookService null;
  123.     protected $salesForceI360AppointmentsService null;
  124.     public function __construct(ManagerRegistry $doctrineUserPasswordEncoderInterface $passwordEncoderLoginFormAuthenticator $loginFormAuthenticatorGuardAuthenticatorHandler $guardAuthenticatorHandlerRequestStack $requestStackPointInPolygon $pointInPolygonBaseService $baseServiceClientEntityModel $clientEntityModelEndTimeCalculator $endTimeCalculatorDayScheduler $daySchedulerScheduler $schedulerIpStackService $ipStackServiceConfirmationMailer $confirmationMailerConfirmationMailerForProcess $confirmationMailerForProcessChangeMailer $changeMailerNotificationMailer $notificationMailerColorUtilsService $colorUtilsServiceEmailsEntityModel $emailsEntityModelGoogleClient $googleClientGoogleCalendarModel $googleCalendarModelGoogleCalendarNotificationMailer $googleCalendarNotificationMailerWorkerEnityModel $workerEnityModelRadiusUpdater $radiusUpdaterContainerInterface $containerMapservice $mapserviceDistanceCalculator $distanceCalculatorBookingRepository $bookingRepositoryBookingEntityModel $bookingEntityModelScheduleAvailabilityCMMVP1Service $scheduleAvailabilityCMMVP1ServiceHttpClientInterface $httpClientWebhookService $webhookServiceCustomerRepository $customerRepositorySalesForceI360AppointmentsService $salesForceI360AppointmentsServiceMailerInterface $mailerInterface)
  125.     {
  126.         //throw new \Exception("This MVP is not available anymore");
  127.         $this->doctrine $doctrine;
  128.         $this->entityManager $doctrine->getManager();
  129.         $this->userRepository $doctrine->getRepository(User::class);
  130.         $this->bookingProcessRepository $doctrine->getRepository(BookingProcess::class);
  131.         $this->regionRepository $doctrine->getRepository(Region::class);
  132.         $this->serviceRepository $doctrine->getRepository(Service::class);
  133.         $this->serviceFieldRepository $doctrine->getRepository(ServiceField::class);
  134.         $this->customerRepository $customerRepository;
  135.         $this->passwordEncoder $passwordEncoder;
  136.         $this->loginFormAuthenticator $loginFormAuthenticator;
  137.         $this->guardAuthenticationHandler $guardAuthenticatorHandler;
  138.         $this->pointInPolygon $pointInPolygon;
  139.         $this->baseService $baseService;
  140.         $this->clientEntityModel $clientEntityModel;
  141.         $this->endTimeCalculator $endTimeCalculator;
  142.         $this->scheduler $scheduler;
  143.         $this->dayScheduler $dayScheduler;
  144.         $this->ipStackService $ipStackService;
  145.         $this->confirmationMailer $confirmationMailer;
  146.         $this->confirmationMailerForProcess $confirmationMailerForProcess;
  147.         $this->changeMailer $changeMailer;
  148.         $this->notificationMailer $notificationMailer;
  149.         $this->colorUtilsService $colorUtilsService;
  150.         $this->emailsEntityModel $emailsEntityModel;
  151.         $this->client $baseService->getClient();
  152.         $this->request $requestStack->getCurrentRequest();
  153.         $this->encoders = [new XmlEncoder(), new JsonEncoder()];
  154.         $this->normalizers = [new ObjectNormalizer()];
  155.         $this->serializer = new Serializer($this->normalizers$this->encoders);
  156.         $this->ipStackInfo $this->ipStackService->getLocationFromIp($this->request->getClientIp());
  157.         $this->googleClient $googleClient;
  158.         $this->googleCalendarModel $googleCalendarModel;
  159.         $this->googleCalendarNotificationMailer $googleCalendarNotificationMailer;
  160.         $this->workerEnityModel $workerEnityModel;
  161.         $this->radiusUpdater $radiusUpdater;
  162.         $this->container $container;
  163.         $this->mapservice $mapservice;
  164.         $this->distanceCalculator $distanceCalculator;
  165.         $this->bookingRepository $bookingRepository;
  166.         $this->bookingEntityModel $bookingEntityModel;
  167.         $this->scheduleAvailabilityCMMVP1Service $scheduleAvailabilityCMMVP1Service;
  168.         $this->httpClient $httpClient;
  169.         $this->webhookService $webhookService;
  170.         $this->salesForceI360AppointmentsService $salesForceI360AppointmentsService;
  171.         $this->mailerInterface $mailerInterface;
  172.     }
  173.     protected $screens = [
  174.         'message',
  175.         'input-location-callback',
  176.         'input-location',
  177.         'input-confirmlocation',
  178.         'input-service',
  179.         'input-servicefields',
  180.         //'input-schedule-type',
  181.         'input-datetime',
  182.         'input-contact',
  183.         'input-billing',
  184.         'commit',
  185.         'commit-confirm',
  186.         'complete',
  187.         'complete-callback'
  188.     ];
  189.     protected $screensmap = [
  190.         'input-location-callback' => 'booking_process_cm_mvp1_step_input_location_callback',
  191.         'input-location' => 'booking_process_cm_mvp1_step_input_location',
  192.         'input-confirmlocation' => 'booking_process_cm_mvp1_step_input_confirmlocation',
  193.         'input-service' => 'booking_process_cm_mvp1_step_input_service',
  194.         'input-servicefields' => 'booking_process_cm_mvp1_step_input_servicefields',
  195.         //'input-schedule-type' => 'booking_process_cm_mvp1_step_input_schedule_type',
  196.         'input-datetime' => 'booking_process_cm_mvp1_step_input_datetime',
  197.         'input-contact' => 'booking_process_cm_mvp1_step_input_contact',
  198.         'input-billing' => 'booking_process_cm_mvp1_step_input_billing',
  199.         'commit' => 'booking_process_cm_mvp1_step_commit',
  200.         'complete' => 'booking_process_cm_mvp1_step_complete',
  201.         'complete-callback' => 'booking_process_cm_mvp1_step_complete_callback'
  202.     ];
  203.     private function assertBookingProcess($request$create_new_process true)
  204.     {
  205.         $booking null;
  206.         $booking_id $request->query->get('booking');
  207.         $newbooking = ($request->query->get('new') != null);
  208.         if ($booking_id != null) {
  209.             $booking $this->bookingRepository->find($booking_id);
  210.         }
  211.         $cpo = ['message' => ''];
  212.         if (!$this->client->isActive()) {
  213.             $cpo['booking_process'] = null;
  214.             $cpo['set_cookie'] = false;
  215.             //$cpo['message'] = 'This account is inactive';
  216.             //$cpo['message'] = sprintf('__redirect: %s', $this->client->getWebsite());
  217.             if ($this->client->getIsBookingRedirect() && $this->client->getWebsite() != null && preg_match('/^(ftp|http|https):\/\/[^ "]+$/'$this->client->getWebsite())) {
  218.                 $cpo['message'] = sprintf('__redirect: %s'$this->client->getWebsite());
  219.             } else {
  220.                 $cpo['message'] = sprintf('__inactive: %s''We apologize for the incovenience. This page has not been activated. Please click the button to complete your request.');
  221.             }
  222.         } else {
  223.             $nbBookings $this->bookingEntityModel->getNumberOfBookings($this->client);
  224.             $maxBookings $this->clientEntityModel->getMaxBookings($this->client);
  225.             $nBookings $totalNumberOfBookings array_sum($nbBookings);
  226.             if ($maxBookings && $nBookings >= $maxBookings) {
  227.                 //if (true) {
  228.                 $cpo['booking_process'] = null;
  229.                 $cpo['set_cookie'] = false;
  230.                 if ($this->getUser() !== null) {
  231.                     $cpo['message'] = sprintf('__redirect: %s'$this->generateUrl('billing', []));
  232.                 } else {
  233.                     $cpo['message'] = sprintf('__inactive: %s''We apologize for the incovenience. This account has reached the maximum number of bookings.');
  234.                 }
  235.                 try {
  236.                     $from = new Address(
  237.                         $this->container->getParameter('orc_booking.mail.from.address'),
  238.                         $this->container->getParameter('orc_booking.mail.from.name')
  239.                     );
  240.                     $to = new Address($this->client->getEmail(), $this->client->getName());
  241.                     $email = (new Email())
  242.                         ->from($from)
  243.                         ->to($to)
  244.                         ->subject('You are getting accesses but no more bookings left on your plan cycle!')
  245.                         ->text(sprintf('You are getting accesses on your Routezilla site, but your current plan cycle has no more bookings available! Please check your billing page if you want to change your plan.'))
  246.                         ->html(sprintf('You are getting accesses on your Routezilla site, but your current plan cycle has no more bookings available! Please check your billing page if you want to change your plan.'));
  247.                     $this->mailerInterface->send($email);
  248.                 } catch (\Throwable $throwable) {
  249.                     // NOTHINIG
  250.                 }
  251.             } else if ($newbooking) {
  252.                 $cpo['booking_process'] = $this->generateBookingProcess($request);
  253.                 $cpo['set_cookie'] = true;
  254.             } else if ($booking != null) {
  255.                 $cpo['booking_process'] = $this->checkEditBookingProcessWithType($request'edit');
  256.                 if ($cpo['booking_process'] == null || $cpo['booking_process']->getBooking() == null || $cpo['booking_process']->getMaterialBooking()->getId() != $booking->getId()) {
  257.                     $bp $this->checkEditBookingProcessByBookingId($request$booking_id);
  258.                     if ($bp != null) {
  259.                         $currentUser $this->getUser();
  260.                         $bpbUser $bp->getBooking() !== null && $bp->getBooking()->getUser() !== null $bp->getBooking()->getUser() : null;
  261.                         $allowedit false;
  262.                         if ($bpbUser == null && $currentUser !== null) {
  263.                             $allowedit true;
  264.                         }
  265.                         if ($bpbUser != null && $currentUser !== null && $currentUser->getId() == $bpbUser->getId()) {
  266.                             $allowedit true;
  267.                         }
  268.                         if ($allowedit) {
  269.                             $cpo['booking_process'] = $this->generateBookingProcessFromBooking($booking$request);
  270.                             $cpo['set_cookie'] = true;
  271.                         } else {
  272.                             $cpo['booking_process'] = null;
  273.                             $cpo['set_cookie'] = false;
  274.                             $cpo['message'] = 'This booking is blocked for edit / reschedule because there is already an ongoing process for it.';
  275.                         }
  276.                     } else {
  277.                         $cpo['booking_process'] = $this->generateBookingProcessFromBooking($booking$request);
  278.                         $cpo['set_cookie'] = true;
  279.                     }
  280.                 } else {
  281.                     $cpo['set_cookie'] = false;
  282.                 }
  283.             } else {
  284.                 $cpo['booking_process'] = $this->checkBookingProcess($request);
  285.                 if ($cpo['booking_process'] == null) {
  286.                     if ($create_new_process) {
  287.                         $cpo['booking_process'] = $this->generateBookingProcess($request);
  288.                         $cpo['set_cookie'] = true;
  289.                     } else {
  290.                         $cpo['booking_process'] = null;
  291.                         $cpo['set_cookie'] = false;
  292.                     }
  293.                 } else {
  294.                     $cpo['set_cookie'] = false;
  295.                 }
  296.             }
  297.         }
  298.         return $cpo;
  299.     }
  300.     private function checkBookingProcess($request)
  301.     {
  302.         $bookingProcess null;
  303.         $_booking_process_code_ $request->cookies->get('_booking_process_code_');
  304.         $_booking_process_restrictions_ $request->query->get('restrictions');
  305.         if ($_booking_process_code_ == null || $_booking_process_restrictions_ !== null) {
  306.             $bookingProcess null;
  307.         } else {
  308.             $bookingProcess $this->bookingProcessRepository->findOneBy(['code' => $_booking_process_code_'status' => 'form']);
  309.         }
  310.         return $bookingProcess;
  311.     }
  312.     private function checkEditBookingProcessWithType($request$type)
  313.     {
  314.         $bookingProcess null;
  315.         $_booking_process_code_ $request->cookies->get('_booking_process_code_');
  316.         if ($_booking_process_code_ == null) {
  317.             $bookingProcess null;
  318.         } else {
  319.             $bookingProcess $this->bookingProcessRepository->findOneBy(['code' => $_booking_process_code_'status' => 'form''type' => $type]);
  320.         }
  321.         return $bookingProcess;
  322.     }
  323.     private function checkEditBookingProcessByBookingId($request$booking_id)
  324.     {
  325.         $bookingProcess $this->bookingProcessRepository->findOneBy(['status' => 'form''type' => 'edit''material_booking' => $booking_id]);
  326.         return $bookingProcess;
  327.     }
  328.     private function generateBookingProcess($request)
  329.     {
  330.         $now = new \DateTime();
  331.         $nowPlus48h = clone $now;
  332.         $nowPlus48h->add(new \DateInterval('PT48H'));
  333.         $uuid Uuid::uuid4();
  334.         $suuid $uuid->toString();
  335.         $_booking_process_code_ $suuid;
  336.         $bookingProcess = new BookingProcess();
  337.         $bookingProcess->setType('create');
  338.         $bookingProcess->setScope('cm_mvp1');
  339.         $bookingProcess->setCode($_booking_process_code_);
  340.         $bookingProcess->setStatus('form');
  341.         $bookingProcess->setEmbeddedStatus('');
  342.         $bookingProcess->setShowHeader('');
  343.         $bookingProcess->setScreen('input-location');
  344.         $bookingProcess->setStep('input-location');
  345.         $bookingProcess->setAllowedCrews($this->extractStringRestrictions('allowedCrews'$request->query->get('restrictions')));
  346.         $bookingProcess->setAllowedServices($this->extractStringRestrictions('allowedServices'$request->query->get('restrictions')));
  347.         $bookingProcess->setAllowedRegions($this->extractStringRestrictions('allowedRegions'$request->query->get('restrictions')));
  348.         $bookingProcessBooking = new BookingProcessBooking();
  349.         $bookingProcessBooking->setScope('cm_mvp1');
  350.         $bookingProcessBooking->setClient($this->client);
  351.         $user null;
  352.         if ($this->getUser() !== null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId())) {
  353.             $user $this->userRepository->findOneBy(['id' => $this->getUser()->getId()]);
  354.             $bookingProcessBooking->setUser($user);
  355.         }
  356.         $bookingProcess->setBooking($bookingProcessBooking);
  357.         $this->entityManager->persist($bookingProcessBooking);
  358.         $this->entityManager->flush();
  359.         $bookingProcess->setCreatedAt($now);
  360.         $bookingProcess->setUpdatedAt($now);
  361.         $bookingProcess->setExpiresAt($nowPlus48h);
  362.         $bookingProcess->setIpAddress($request->getClientIp());
  363.         $this->entityManager->persist($bookingProcess);
  364.         $this->entityManager->flush();
  365.         return $bookingProcess;
  366.     }
  367.     private function extractStringRestrictions(string $restrictionKey, ?string $restrictions): ?string
  368.     {
  369.         if (!$restrictions) {
  370.             return null;
  371.         }
  372.         $decodedRestrictions json_decode(base64_decode($restrictions), true);
  373.         if (!isset($decodedRestrictions[$restrictionKey]) || !is_array($decodedRestrictions[$restrictionKey])) {
  374.             return null;
  375.         }
  376.         return implode(', '$decodedRestrictions[$restrictionKey]);
  377.     }
  378.     private function generateBookingProcessFromBooking($booking$request)
  379.     {
  380.         $now = new \DateTime();
  381.         $nowPlus48h = clone $now;
  382.         $nowPlus48h->add(new \DateInterval('PT48H'));
  383.         $uuid Uuid::uuid4();
  384.         $suuid $uuid->toString();
  385.         $_booking_process_code_ $suuid;
  386.         $customer $booking->getCustomer();
  387.         $customerLocation $customer->getLocation();
  388.         $customerBilling $customer->getBilling();
  389.         $customerBillingLocation = ($customerBilling != null $customerBilling->getLocation() : null);
  390.         $location $booking->getLocation();
  391.         $bookingProcess = new BookingProcess();
  392.         $bookingProcess->setType('edit');
  393.         $bookingProcess->setScope('cm_mvp1');
  394.         $bookingProcess->setMaterialBooking($booking);
  395.         $bookingProcess->setCode($_booking_process_code_);
  396.         $bookingProcess->setStatus('form');
  397.         $bookingProcess->setEmbeddedStatus('');
  398.         $bookingProcess->setShowHeader('');
  399.         $bookingProcess->setScreen('input-location');
  400.         $bookingProcess->setStep('input-billing');
  401.         $bookingProcessBooking = new BookingProcessBooking();
  402.         $bookingProcessBooking->setScope('cm_mvp1');
  403.         // POPULATE BOOKING PROCESS FROM BOOKING
  404.         $bookingProcessBookingCustomerBilling null;
  405.         if ($customerBilling != null) {
  406.             $bookingProcessBookingCustomerBillingLocation null;
  407.             if ($customerBillingLocation != null) {
  408.                 $bookingProcessBookingCustomerBillingLocation = new BookingProcessLocation();
  409.                 $bookingProcessBookingCustomerBillingLocation->setStreet($customerBillingLocation->getStreet());
  410.                 $bookingProcessBookingCustomerBillingLocation->setCity($customerBillingLocation->getCity());
  411.                 $bookingProcessBookingCustomerBillingLocation->setCode($customerBillingLocation->getCode());
  412.                 $bookingProcessBookingCustomerBillingLocation->setProvince($customerBillingLocation->getProvince());
  413.                 $bookingProcessBookingCustomerBillingLocation->setCountry($customerBillingLocation->getCountry());
  414.                 $bookingProcessBookingCustomerBillingLocation->setLatitude($customerBillingLocation->getLatitude());
  415.                 $bookingProcessBookingCustomerBillingLocation->setLongitude($customerBillingLocation->getLongitude());
  416.                 $bookingProcessBookingCustomerBillingLocation->setLine2($customerBillingLocation->getLine2());
  417.                 $bookingProcessBookingCustomerBillingLocation->buildInput();
  418.                 $bookingProcessBookingCustomerBillingLocation->buildFormattedAddress();
  419.                 $this->entityManager->persist($bookingProcessBookingCustomerBillingLocation);
  420.             }
  421.             $bookingProcessBookingCustomerBilling = new BookingProcessCustomerBilling();
  422.             $bookingProcessBookingCustomerBilling->setLocation($bookingProcessBookingCustomerBillingLocation);
  423.             $bookingProcessBookingCustomerBilling->setName($customerBilling->getName());
  424.             $bookingProcessBookingCustomerBilling->setEmail($customerBilling->getEmail());
  425.             $bookingProcessBookingCustomerBilling->setPhone($customerBilling->getPhone());
  426.             $bookingProcessBookingCustomerBilling->setPhoneCanonical($customerBilling->getPhoneCanonical());
  427.             $this->entityManager->persist($bookingProcessBookingCustomerBilling);
  428.         }
  429.         $bookingProcessBookingCustomerLocation = new BookingProcessLocation();
  430.         $bookingProcessBookingCustomerLocation->setStreet($customerLocation->getStreet());
  431.         $bookingProcessBookingCustomerLocation->setCity($customerLocation->getCity());
  432.         $bookingProcessBookingCustomerLocation->setCode($customerLocation->getCode());
  433.         $bookingProcessBookingCustomerLocation->setProvince($customerLocation->getProvince());
  434.         $bookingProcessBookingCustomerLocation->setCountry($customerLocation->getCountry());
  435.         $bookingProcessBookingCustomerLocation->setLatitude($customerLocation->getLatitude());
  436.         $bookingProcessBookingCustomerLocation->setLongitude($customerLocation->getLongitude());
  437.         $bookingProcessBookingCustomerLocation->setLine2($customerLocation->getLine2());
  438.         $bookingProcessBookingCustomerLocation->buildInput();
  439.         $bookingProcessBookingCustomerLocation->buildFormattedAddress();
  440.         $bookingProcessBookingCustomer = new BookingProcessCustomer();
  441.         $bookingProcessBookingCustomer->setLocation($bookingProcessBookingCustomerLocation);
  442.         $bookingProcessBookingCustomer->setEmail($customer->getEmail());
  443.         $bookingProcessBookingCustomer->setName($customer->getName());
  444.         $bookingProcessBookingCustomer->setPhone($customer->getPhone());
  445.         $bookingProcessBookingCustomer->setPhoneCanonical($customer->getPhoneCanonical());
  446.         $bookingProcessBookingCustomer->setClient($customer->getClient());
  447.         $bookingProcessBookingCustomer->setPhoneDescription($customer->getPhoneDescription());
  448.         $bookingProcessBookingCustomer->setBilling($bookingProcessBookingCustomerBilling);
  449.         $bookingProcessBookingLocation null;
  450.         if ($location != null) {
  451.             $bookingProcessBookingLocation = new BookingProcessLocation();
  452.             $bookingProcessBookingLocation->setStreet($customerLocation->getStreet());
  453.             $bookingProcessBookingLocation->setCity($customerLocation->getCity());
  454.             $bookingProcessBookingLocation->setCode($customerLocation->getCode());
  455.             $bookingProcessBookingLocation->setProvince($customerLocation->getProvince());
  456.             $bookingProcessBookingLocation->setCountry($customerLocation->getCountry());
  457.             $bookingProcessBookingLocation->setLatitude($customerLocation->getLatitude());
  458.             $bookingProcessBookingLocation->setLongitude($customerLocation->getLongitude());
  459.             $bookingProcessBookingLocation->setLine2($customerLocation->getLine2());
  460.             $bookingProcessBookingLocation->buildInput();
  461.             $bookingProcessBookingLocation->buildFormattedAddress();
  462.             $this->entityManager->persist($bookingProcessBookingLocation);
  463.         }
  464.         $bookingProcessBooking->setClient($booking->getClient());
  465.         $bookingProcessBooking->setCustomer($bookingProcessBookingCustomer);
  466.         $bookingProcessBooking->setService($booking->getService());
  467.         $bookingProcessBooking->setServiceType($booking->getServiceType());
  468.         $bookingProcessBooking->setLocation($bookingProcessBookingLocation);
  469.         $bookingProcessBooking->setSelectedRegion($booking->getSelectedRegion());
  470.         $bookingProcessBooking->setCrew($booking->getCrew());
  471.         //$bookingProcessBooking->setRadius($booking->getRadius());
  472.         $bookingProcessBooking->setDateStart($booking->getDateStart());
  473.         $bookingProcessBooking->setDateEnd($booking->getDateEnd());
  474.         $bookingProcessBooking->setStatus($booking->getStatus());
  475.         $bookingProcessBooking->setAdditionalInformation($booking->getAdditionalInformation());
  476.         $bookingProcessBooking->setNotes($booking->getNotes());
  477.         $bookingProcessBooking->setBilled($booking->getBilled());
  478.         $bookingProcessBooking->setDatePosted($booking->getDatePosted());
  479.         $bookingProcessBooking->setDateUpdated($booking->getDateUpdated());
  480.         $bookingProcessBooking->setUser($booking->getUser());
  481.         $bookingProcessBooking->setAdditionalMinutes($booking->getAdditionalMinutes());
  482.         //$workerNotes
  483.         $regions $booking->getRegions();
  484.         foreach ($regions as $region) {
  485.             $bookingProcessBooking->addRegion($region);
  486.         }
  487.         $fields $booking->getFields();
  488.         foreach ($fields as $field) {
  489.             $bookingProcessBookingServiceAnswer = new BookingProcessBookingServiceAnswer();
  490.             $bookingProcessBookingServiceAnswer->setBooking($bookingProcessBooking);
  491.             $bookingProcessBookingServiceAnswer->setField($field->getField());
  492.             $bookingProcessBookingServiceAnswer->setSlug($field->getSlug());
  493.             $bookingProcessBookingServiceAnswer->setAnswer($field->getAnswer());
  494.             $this->entityManager->persist($bookingProcessBookingServiceAnswer);
  495.         }
  496.         $bookingProcess->setBooking($bookingProcessBooking);
  497.         $this->entityManager->persist($bookingProcessBookingCustomer);
  498.         $this->entityManager->persist($bookingProcessBooking);
  499.         $this->entityManager->persist($bookingProcess);
  500.         $this->entityManager->flush();
  501.         $bookingProcess->setCreatedAt($now);
  502.         $bookingProcess->setUpdatedAt($now);
  503.         $bookingProcess->setExpiresAt($nowPlus48h);
  504.         $bookingProcess->setIpAddress($request->getClientIp());
  505.         $this->entityManager->persist($bookingProcess);
  506.         $this->entityManager->flush();
  507.         return $bookingProcess;
  508.     }
  509.     private function setCookie($request$response$value)
  510.     {
  511.         $now = new \DateTime();
  512.         $dt = clone $now;
  513.         $dt->add(new \DateInterval('PT24H'));
  514.         $scheme $request->getScheme();
  515.         if ($scheme == 'https') {
  516.             //$response->headers->setCookie(new Cookie('_booking_process_code_', $value, $dt, '/booking/process', null, true, true, false, Cookie::SAMESITE_NONE));
  517.             $response->headers->setCookie(new Cookie('_booking_process_code_'$value$dt'/'nulltruetruefalseCookie::SAMESITE_NONE));
  518.         } else {
  519.             //$response->headers->setCookie(new Cookie('_booking_process_code_', $value, $dt, '/booking/process'));
  520.             $response->headers->setCookie(new Cookie('_booking_process_code_'$value$dt'/'));
  521.         }
  522.     }
  523.     private function unsetCookie($response)
  524.     {
  525.         $response->headers->clearCookie('_booking_process_code_''/'null);
  526.     }
  527.     private function doIncrementGmbClicks($request)
  528.     {
  529.         $rwg_token $request->query->get('rwg_token');
  530.         if ($rwg_token != null) {
  531.             $countGmbClicks $this->client->getCountGmbClicks();
  532.             if ($countGmbClicks === null) {
  533.                 $countGmbClicks 0;
  534.             }
  535.             $countGmbClicks++;
  536.             $this->client->setCountGmbClicks($countGmbClicks);
  537.             $this->entityManager->persist($this->client);
  538.             $this->entityManager->flush();
  539.         }
  540.     }
  541.     private function addPreProcessHeaders($request$response$bookingProcess)
  542.     {
  543.         $rwg_token $request->query->get('rwg_token');
  544.         $entity_id $request->query->get('entity_id');
  545.         $scheme $request->getScheme();
  546.         if ($rwg_token != null) {
  547.             $now = new \DateTime();
  548.             $dt = clone $now;
  549.             $dt->add(new \DateInterval('P30D'));
  550.             $gmbPage null;
  551.             if ($entity_id != null) {
  552.                 $a_entity_id explode('-'$entity_id);
  553.                 $gmb_page_id null;
  554.                 if (count($a_entity_id) >= 3) {
  555.                     $gmb_page_id $a_entity_id[2];
  556.                 } else if (count($a_entity_id) >= 2) {
  557.                     $gmb_page_id $a_entity_id[1];
  558.                 }
  559.                 if ($gmb_page_id !== null) {
  560.                     $gmbPage $this->client->getGmbPage($gmb_page_id);
  561.                 }
  562.             }
  563.             if ($scheme == 'https') {
  564.                 //$response->headers->setCookie(new Cookie('_booking_process_code_', $value, $dt, '/booking/process', null, true, true, false, Cookie::SAMESITE_NONE));
  565.                 $response->headers->setCookie(new Cookie('_rwg_token'$rwg_token$dt'/'nulltruetruefalseCookie::SAMESITE_NONE));
  566.                 if ($entity_id != null) {
  567.                     $response->headers->setCookie(new Cookie('_merchant_id'$entity_id$dt'/'nulltruetruefalseCookie::SAMESITE_NONE));
  568.                 }
  569.             } else {
  570.                 //$response->headers->setCookie(new Cookie('_booking_process_code_', $value, $dt, '/booking/process'));
  571.                 $response->headers->setCookie(new Cookie('_rwg_token'$rwg_token$dt'/'));
  572.                 if ($entity_id != null) {
  573.                     $response->headers->setCookie(new Cookie('_merchant_id'$rwg_token$dt'/'));
  574.                 }
  575.             }
  576.             $bookingProcess->setRwgToken($rwg_token);
  577.             $bookingProcess->setEntityId($entity_id);
  578.             $countGmbClicks $this->client->getCountGmbClicks();
  579.             if ($countGmbClicks === null) {
  580.                 $countGmbClicks 0;
  581.             }
  582.             $countGmbClicks++;
  583.             $this->client->setCountGmbClicks($countGmbClicks);
  584.             if ($gmbPage !== null) {
  585.                 $countGmbPageClicks $gmbPage->getCountGmbClicks();
  586.                 if ($countGmbPageClicks === null) {
  587.                     $countGmbPageClicks 0;
  588.                 }
  589.                 $countGmbPageClicks++;
  590.                 $gmbPage->setCountGmbClicks($countGmbPageClicks);
  591.             }
  592.             $this->entityManager->persist($bookingProcess);
  593.             $this->entityManager->persist($this->client);
  594.             if ($gmbPage !== null) {
  595.                 $this->entityManager->persist($gmbPage);
  596.             }
  597.             $this->entityManager->flush();
  598.         }
  599.     }
  600.     private function doStepRedirectionGET($request$bookingProcess)
  601.     {
  602.         switch ($bookingProcess->getScreen()) {
  603.             case 'input-location': {
  604.                 return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  605.             }
  606.                 break;
  607.             case 'input-location-callback': {
  608.                 return $this->redirect($this->generateUrl($this->screensmap['input-location-callback']));
  609.             }
  610.                 break;
  611.             case 'input-confirmlocation': {
  612.                 return $this->redirect($this->generateUrl($this->screensmap['input-confirmlocation']));
  613.             }
  614.                 break;
  615.             case 'input-service': {
  616.                 return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  617.             }
  618.                 break;
  619.             case 'input-servicefields': {
  620.                 return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  621.             }
  622.                 break;
  623.             case 'input-datetime': {
  624.                 return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  625.             }
  626.                 break;
  627.             case 'input-contact': {
  628.                 return $this->redirect($this->generateUrl($this->screensmap['input-contact']));
  629.             }
  630.                 break;
  631.             case 'input-billing': {
  632.                 return $this->redirect($this->generateUrl($this->screensmap['input-billing']));
  633.             }
  634.                 break;
  635.             default: {
  636.                 //return $this->step_company($request);
  637.                 //return $this->forward('App\Controller\SignUpController::step_company', array());
  638.                 return new Response(
  639.                     'INVALID STEP',
  640.                     Response::HTTP_OK,
  641.                     ['content-type' => 'text/html']
  642.                 );
  643.             }
  644.         }
  645.     }
  646.     private function setGoToScreenOnBookingProcess($bookingProcess$newscreen)
  647.     {
  648.         $now = new \DateTime();
  649.         $newposition array_search($newscreen$this->screens);
  650.         if ($newposition === false) {
  651.             return;
  652.         }
  653.         $currentstep array_search($bookingProcess->getStep(), $this->screens);
  654.         if ($newposition $currentstep) {
  655.             $bookingProcess->setStep($newscreen);
  656.         }
  657.         $bookingProcess->setScreen($newscreen);
  658.         $bookingProcess->setUpdatedAt($now);
  659.         $bookingProcess->setIpAddress($this->request->getClientIp());
  660.         $this->entityManager->persist($bookingProcess);
  661.         $this->entityManager->flush();
  662.     }
  663.     private function redirectOnInvalidStep($request$bookingProcess$screen$setCookie false)
  664.     {
  665.         $response null;
  666.         $position array_search($screen$this->screens);
  667.         if ($position === false) {
  668.             //return $this->redirect($this->generateUrl($this->screensmap[$bookingProcess->getStep()]));
  669.             $response = new RedirectResponse($this->generateUrl($this->screensmap[$bookingProcess->getStep()]));
  670.             if ($setCookie) {
  671.                 $this->setCookie($request$response$bookingProcess->getCode());
  672.             }
  673.         }
  674.         $currentstep array_search($bookingProcess->getStep(), $this->screens);
  675.         if ($position $currentstep) {
  676.             //return $this->redirect($this->generateUrl($this->screensmap[$bookingProcess->getStep()]));
  677.             $response = new RedirectResponse($this->generateUrl($this->screensmap[$bookingProcess->getStep()]));
  678.             if ($setCookie) {
  679.                 $this->setCookie($request$response$bookingProcess->getCode());
  680.             }
  681.         }
  682.         return $response;
  683.     }
  684.     /**
  685.      * @Route("/booking/process/cm/mvp1", name="booking_process_cm_mvp1")
  686.      * @Route("/booking/process", name="booking_process_cm_mvp1_default", condition="(((context.getHost() not in %app.beta.clients%) and ('%booking_process.scope%' == 'cm_mvp1')) or ((context.getHost() in %app.beta.clients%) and ('%booking_process.beta.scope%' == 'cm_mvp1')))")
  687.      */
  688.     public function index(Request $request): Response
  689.     {
  690.         $booking_id $request->query->get('booking');
  691.         if ($booking_id != null) {
  692.             return $this->redirect($this->generateUrl($this->screensmap['input-location'], array('booking' => $booking_id)));
  693.         } else {
  694.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  695.         }
  696.         // return $this->render('booking_process_cm_mvp1/index.html.twig', [
  697.         //     'controller_name' => 'BookingProcessController',
  698.         // ]);
  699.     }
  700.     /**
  701.      * @Route("/booking/process/cm/mvp1/cancel", name="booking_process_cm_mvp1_cancel")
  702.      */
  703.     public function cancel(Request $request)
  704.     {
  705.         $booking_process $this->checkBookingProcess($request);
  706.         $response $this->getUser() ? new RedirectResponse($this->generateUrl('book_admin')) : new RedirectResponse($this->generateUrl('booking_process_cm_mvp1'));
  707.         if ($booking_process != null) {
  708.             $this->unsetCookie($response);
  709.         }
  710.         return $response;
  711.     }
  712.     public function doStepInputLocation($request$bookingProcess)
  713.     {
  714.         $now = new \DateTime();
  715.         $bookingProcessBooking $bookingProcess->getBooking();
  716.         $bookingProcessLocation null;
  717.         $existing_customer_id $request->request->get('customer-id');
  718.         if ($existing_customer_id != null && $existing_customer_id != '') {
  719.             $actual_customer $this->customerRepository->findOneBy(['id' => intval($existing_customer_id)]);
  720.             $customer $bookingProcess->getBooking()->getCustomer();
  721.             if ($customer == null) {
  722.                 $customer = new BookingProcessCustomer();
  723.                 $bookingProcessBooking->setCustomer($customer);
  724.             }
  725.             $customer->setEmail($actual_customer->getEmail());
  726.             $customer->setName($actual_customer->getName());
  727.             $customer->setPhone($actual_customer->getPhone());
  728.             $customer->setPhoneCanonical($actual_customer->getPhone());
  729.             $customer->setClient($this->client);
  730.             $customer->setDeleted(false);
  731.             $customer->setPhoneDescription('');
  732.             $this->entityManager->persist($customer);
  733.             $this->entityManager->persist($bookingProcessBooking);
  734.             $this->entityManager->flush();
  735.         }
  736.         if ($request->request->get('id') == "") {
  737.             if ($request->request->get('type') === 'fixed') {
  738.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  739.                 if ($bookingProcessLocation != null) {
  740.                     $bookingProcessBooking->setLocation(null);
  741.                     $this->entityManager->persist($bookingProcessBooking);
  742.                     $this->entityManager->remove($bookingProcessLocation);
  743.                     $this->entityManager->flush();
  744.                 }
  745.                 $bookingProcessLocation = new BookingProcessLocation();
  746.                 $region_id intval($request->request->get('fixed_region_id'));
  747.                 $region $this->regionRepository->find($region_id);
  748.                 //$location = $region->getBoundaries()[0]->getLocation();
  749.                 $bookingProcessLocation->setInput($region->getAddress());
  750.                 $bookingProcessLocation->setFormattedAddress($region->getAddress());
  751.                 $bookingProcessLocation->setStreet($region->getStreet());
  752.                 $bookingProcessLocation->setCity($region->getCity());
  753.                 $bookingProcessLocation->setProvince($region->getProvince());
  754.                 $bookingProcessLocation->setCountry($region->getCountry());
  755.                 $bookingProcessLocation->setCode($region->getCode());
  756.                 $bookingProcessLocation->setLatitude($region->getLatitude());
  757.                 $bookingProcessLocation->setLongitude($region->getLongitude());
  758.                 //$ad = $this->mapservice->getAddressDetailsFromLatLng($location->getLatitude(), $location->getLongitude());
  759.                 // $bookingProcessLocation->setInput('');
  760.                 // $bookingProcessLocation->setFormattedAddress('');
  761.                 // $bookingProcessLocation->setStreet(property_exists($ad, 'street') ? $ad->street : '');
  762.                 // $bookingProcessLocation->setCity(property_exists($ad, 'city') ? $ad->city : '');
  763.                 // $bookingProcessLocation->setProvince(property_exists($ad, 'province') ? $ad->province : '');
  764.                 // $bookingProcessLocation->setCountry(property_exists($ad, 'country') ? $ad->country : '');
  765.                 // $bookingProcessLocation->setCode(property_exists($ad, 'code') ? $ad->code : '');
  766.                 // $bookingProcessLocation->setLatitude(property_exists($ad, 'latitude') ? $ad->latitude : null);
  767.                 // $bookingProcessLocation->setLongitude(property_exists($ad, 'longitude') ? $ad->longitude : null);
  768.                 $this->entityManager->persist($bookingProcessLocation);
  769.                 $this->entityManager->flush();
  770.                 $bookingProcessBooking->setLocation($bookingProcessLocation);
  771.                 $this->entityManager->persist($bookingProcessBooking);
  772.                 $this->entityManager->flush();
  773.                 $bookingRegions $bookingProcessBooking->getRegions();
  774.                 $bookingRegionsIds = [];
  775.                 if ($bookingRegions) {
  776.                     foreach ($bookingRegions as $bookingRegion) {
  777.                         $bookingRegionsIds[] = $bookingRegion->getId();
  778.                     }
  779.                 }
  780.                 $bookingProcessBooking->setServiceType('fixed');
  781.                 $bookingProcessBooking->setSelectedRegion($region);
  782.                 $bookingProcessBooking->setDateStart(null);
  783.                 $bookingProcessBooking->setDateEnd(null);
  784.                 $this->entityManager->persist($bookingProcessBooking);
  785.                 $this->entityManager->flush();
  786.                 foreach ($bookingRegions as $bookingRegion) {
  787.                     $bookingProcessBooking->removeRegion($bookingRegion);
  788.                 }
  789.                 //$locationRegions = $this->getRegionsFromLocation($bookingProcessLocation, $bookingProcess->getAllowedRegions());
  790.                 // if (!$locationRegions || count($locationRegions) < 1) {
  791.                 //     $bookingProcessBooking->addRegion($region);
  792.                 // } else {
  793.                 //     foreach ($locationRegions as $locationRegion) {
  794.                 //         $bookingProcessBooking->addRegion($locationRegion);
  795.                 //     }
  796.                 // }
  797.                 $bookingProcessBooking->addRegion($region);
  798.                 // TODO: REMOVE THIS
  799.                 // foreach($locationRegions as $locationRegion) {
  800.                 //     if (!in_array($locationRegion->getId(), $bookingRegionsIds)) {
  801.                 //         $bookingProcessBooking->addRegion($locationRegion);
  802.                 //     }
  803.                 // }
  804.                 $this->entityManager->persist($bookingProcessBooking);
  805.                 $this->entityManager->flush();
  806.             } else {
  807.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  808.                 if ($request->request->get('input') == "") {
  809.                     if ($bookingProcessLocation != null) {
  810.                         $bookingProcessBooking->setLocation(null);
  811.                         $this->entityManager->remove($bookingProcessLocation);
  812.                     }
  813.                     throw new \Exception("Location is empty!");
  814.                 }
  815.                 if ($bookingProcessLocation != null) {
  816.                     $bookingProcessBooking->setLocation(null);
  817.                     $this->entityManager->persist($bookingProcessBooking);
  818.                     $this->entityManager->remove($bookingProcessLocation);
  819.                     $this->entityManager->flush();
  820.                 }
  821.                 $bookingProcessLocation = new BookingProcessLocation();
  822.                 if ($request->request->get('geolocation') == 'true') {
  823.                     $bookingProcessLocation->setInput($request->request->get('input'));
  824.                     $bookingProcessLocation->setFormattedAddress($request->request->get('formatted_address'));
  825.                     $bookingProcessLocation->setStreet($request->request->get('street'));
  826.                     $bookingProcessLocation->setCity($request->request->get('city'));
  827.                     $bookingProcessLocation->setProvince($request->request->get('province'));
  828.                     $bookingProcessLocation->setCountry($request->request->get('country'));
  829.                     $bookingProcessLocation->setCode($request->request->get('code'));
  830.                     $bookingProcessLocation->setLatitude(doubleval($request->request->get('latitude')));
  831.                     $bookingProcessLocation->setLongitude(doubleval($request->request->get('longitude')));
  832.                 } else {
  833.                     $ad $this->mapservice->getAddressDetails($request->request->get('input'));
  834.                     if ($ad == null) {
  835.                         $bookingProcessLocation->setInput($request->request->get('input'));
  836.                         $this->entityManager->persist($bookingProcessLocation);
  837.                         $this->entityManager->flush();
  838.                         $bookingProcessBooking->setLocation($bookingProcessLocation);
  839.                         $this->entityManager->persist($bookingProcessBooking);
  840.                         $this->entityManager->flush();
  841.                         throw new \Exception("Please select from search suggestions!");
  842.                     }
  843.                     $bookingProcessLocation->setInput($request->request->get('input'));
  844.                     $bookingProcessLocation->setFormattedAddress(property_exists($ad'formatted_address') ? $ad->formatted_address '');
  845.                     $bookingProcessLocation->setStreet(property_exists($ad'street') ? $ad->street '');
  846.                     $bookingProcessLocation->setCity(property_exists($ad'city') ? $ad->city '');
  847.                     $bookingProcessLocation->setProvince(property_exists($ad'province') ? $ad->province '');
  848.                     $bookingProcessLocation->setCountry(property_exists($ad'country') ? $ad->country '');
  849.                     $bookingProcessLocation->setCode(property_exists($ad'code') ? $ad->code '');
  850.                     $bookingProcessLocation->setLatitude(property_exists($ad'latitude') ? $ad->latitude null);
  851.                     $bookingProcessLocation->setLongitude(property_exists($ad'longitude') ? $ad->longitude null);
  852.                 }
  853.                 $this->entityManager->persist($bookingProcessLocation);
  854.                 $this->entityManager->flush();
  855.                 $bookingProcessBooking->setLocation($bookingProcessLocation);
  856.                 $bookingProcessBooking->setSelectedRegion(null);
  857.                 $bookingProcessBooking->setServiceType('onsite');
  858.                 $this->entityManager->persist($bookingProcessBooking);
  859.                 $this->entityManager->flush();
  860.                 $bookingRegions $bookingProcessBooking->getRegions();
  861.                 $bookingRegionsIds = [];
  862.                 if ($bookingRegions) {
  863.                     foreach ($bookingRegions as $bookingRegion) {
  864.                         $bookingRegionsIds[] = $bookingRegion->getId();
  865.                     }
  866.                 }
  867.                 $bookingProcessBooking->setDateStart(null);
  868.                 $bookingProcessBooking->setDateEnd(null);
  869.                 $this->entityManager->persist($bookingProcessBooking);
  870.                 $this->entityManager->flush();
  871.                 $locationRegions $this->getRegionsFromLocation($bookingProcessLocation$bookingProcess->getAllowedRegions());
  872.                 if (!$locationRegions || count($locationRegions) < 1) {
  873.                     throw new \Exception("Location is out of bounds!");
  874.                 }
  875.                 foreach ($bookingRegions as $bookingRegion) {
  876.                     $bookingProcessBooking->removeRegion($bookingRegion);
  877.                 }
  878.                 foreach ($locationRegions as $locationRegion) {
  879.                     $bookingProcessBooking->addRegion($locationRegion);
  880.                 }
  881.                 // TODO: REMOVE THIS
  882.                 // foreach($locationRegions as $locationRegion) {
  883.                 //     if (!in_array($locationRegion->getId(), $bookingRegionsIds)) {
  884.                 //         $bookingProcessBooking->addRegion($locationRegion);
  885.                 //     }
  886.                 // }
  887.                 $this->entityManager->persist($bookingProcessBooking);
  888.                 $this->entityManager->flush();
  889.             }
  890.         } else {
  891.             $bookingProcessLocation $bookingProcess->getBooking()->getLocation();
  892.             $bookingRegions $bookingProcessBooking->getRegions();
  893.             $bookingRegionsIds = [];
  894.             if ($bookingRegions) {
  895.                 foreach ($bookingRegions as $bookingRegion) {
  896.                     $bookingRegionsIds[] = $bookingRegion->getId();
  897.                 }
  898.             }
  899.             $locationRegions $this->getRegionsFromLocation($bookingProcessLocation$bookingProcess->getAllowedRegions());
  900.             if ($request->request->get('type') === 'fixed') {
  901.                 $region_id intval($request->request->get('fixed_region_id'));
  902.                 $region $this->regionRepository->find($region_id);
  903.                 // dump($request->request->get('id'));
  904.                 // dump($request->request->get('type'));
  905.                 // dump($region_id);
  906.                 // dd($region);
  907.                 foreach ($bookingRegions as $bookingRegion) {
  908.                     $bookingProcessBooking->removeRegion($bookingRegion);
  909.                 }
  910.                 // if (!$locationRegions || count($locationRegions) < 1) {
  911.                 //     $bookingProcessBooking->addRegion($region);
  912.                 // } else {
  913.                 //     foreach ($locationRegions as $locationRegion) {
  914.                 //         $bookingProcessBooking->addRegion($locationRegion);
  915.                 //     }
  916.                 // }
  917.                 $bookingProcessLocation->setInput($region->getAddress());
  918.                 $bookingProcessLocation->setFormattedAddress($region->getAddress());
  919.                 $bookingProcessLocation->setStreet($region->getStreet());
  920.                 $bookingProcessLocation->setCity($region->getCity());
  921.                 $bookingProcessLocation->setProvince($region->getProvince());
  922.                 $bookingProcessLocation->setCountry($region->getCountry());
  923.                 $bookingProcessLocation->setCode($region->getCode());
  924.                 $bookingProcessLocation->setLatitude($region->getLatitude());
  925.                 $bookingProcessLocation->setLongitude($region->getLongitude());
  926.                 $this->entityManager->persist($bookingProcessLocation);
  927.                 $this->entityManager->flush();
  928.                 $bookingProcessBooking->addRegion($region);
  929.                 $bookingProcessBooking->setSelectedRegion($region);
  930.             } else {
  931.                 if (!$locationRegions) {
  932.                     throw new \Exception("Location is out of bounds!");
  933.                 }
  934.                 foreach ($bookingRegions as $bookingRegion) {
  935.                     $bookingProcessBooking->removeRegion($bookingRegion);
  936.                 }
  937.                 foreach ($locationRegions as $locationRegion) {
  938.                     $bookingProcessBooking->addRegion($locationRegion);
  939.                 }
  940.             }
  941.             $this->entityManager->persist($bookingProcessBooking);
  942.             $this->entityManager->flush();
  943.         }
  944.         return true;
  945.     }
  946.     public function doStepInputLocationCallback($request$bookingProcess)
  947.     {
  948.         $now = new \DateTime();
  949.         $bookingProcessBooking $bookingProcess->getBooking();
  950.         $bookingProcessBooking->setStatus(BookingStatus::STATUS_REQUESTED);
  951.         $bookingProcessBooking->setAdditionalMinutes(0);
  952.         $bookingProcessBooking->setAdditionalInformation('');
  953.         //$bookingProcessBooking->setDateStart(clone $now);
  954.         //$bookingProcessBooking->setService($this->client->getServices()[0]);
  955.         $bookingProcessLocation $bookingProcessBooking->getLocation();
  956.         $bookingProcessCustomer $bookingProcessBooking->getCustomer();
  957.         if ($bookingProcessCustomer == null) {
  958.             $bookingProcessCustomer = new BookingProcessCustomer();
  959.             $bookingProcessBooking->setCustomer($bookingProcessCustomer);
  960.         }
  961.         $bookingProcessCustomer->setEmail($request->request->get('contact-email'));
  962.         $bookingProcessCustomer->setName($request->request->get('contact-name'));
  963.         $bookingProcessCustomer->setPhone($request->request->get('contact-phone'));
  964.         $bookingProcessCustomer->setPhoneCanonical($request->request->get('contact-phone'));
  965.         $bookingProcessCustomer->setClient($this->client);
  966.         $bookingProcessCustomer->setDeleted(false);
  967.         $bookingProcessCustomer->setPhoneDescription('');
  968.         $bookingProcessCustomerLocation $bookingProcessCustomer->getLocation();
  969.         if ($bookingProcessCustomerLocation == null) {
  970.             $bookingProcessCustomerLocation = new BookingProcessLocation();
  971.             $bookingProcessCustomer->setLocation($bookingProcessCustomerLocation);
  972.         }
  973.         $bookingProcessCustomerLocation->setStreet($request->request->get('contact-street'));
  974.         $bookingProcessCustomerLocation->setCity($request->request->get('contact-city'));
  975.         $bookingProcessCustomerLocation->setCode($request->request->get('contact-code'));
  976.         $bookingProcessCustomerLocation->setProvince($request->request->get('contact-province'));
  977.         $bookingProcessCustomerLocation->setCountry($request->request->get('contact-country'));
  978.         $bookingProcessCustomerLocation->setLatitude(0);
  979.         $bookingProcessCustomerLocation->setLongitude(0);
  980.         $bookingProcessCustomerLocation->setLine2($request->request->get('contact-line2'));
  981.         $bookingProcessCustomerLocation->setInput('');
  982.         $bookingProcessCustomerLocation->setFormattedAddress('');
  983.         $isBillingSame = ($request->request->get('contact-billing-same') != null);
  984.         $bookingProcessCustomerBilling null;
  985.         if ($isBillingSame) {
  986.             // $bookingProcessCustomerBilling = $bookingProcessCustomer->getBilling();
  987.             // $bookingProcessCustomerBillingLocation = null;
  988.             // if ($bookingProcessCustomerBilling != null) {
  989.             //     $bookingProcessCustomer->setBilling(null);
  990.             //     $this->entityManager->remove($bookingProcessCustomerBilling);
  991.             // }
  992.             $bookingProcessCustomerBilling $bookingProcessCustomer->getBilling();
  993.             $bookingProcessCustomerBillingLocation null;
  994.             if ($bookingProcessCustomerBilling == null) {
  995.                 $bookingProcessCustomerBilling = new BookingProcessCustomerBilling();
  996.                 $bookingProcessCustomerBillingLocation $bookingProcessCustomerBilling->getLocation();
  997.                 if ($bookingProcessCustomerBillingLocation == null) {
  998.                     $bookingProcessCustomerBillingLocation = new BookingProcessLocation();
  999.                     $bookingProcessCustomerBilling->setLocation($bookingProcessCustomerBillingLocation);
  1000.                 }
  1001.             } else {
  1002.                 $bookingProcessCustomerBillingLocation $bookingProcessCustomerBilling->getLocation();
  1003.                 if ($bookingProcessCustomerBillingLocation == null) {
  1004.                     $bookingProcessCustomerBillingLocation = new BookingProcessLocation();
  1005.                     $bookingProcessCustomerBilling->setLocation($bookingProcessCustomerBillingLocation);
  1006.                 }
  1007.             }
  1008.             $bookingProcessCustomerBilling->setName($bookingProcessCustomer->getName());
  1009.             $bookingProcessCustomerBilling->setEmail($bookingProcessCustomer->getEmail());
  1010.             $bookingProcessCustomerBilling->setPhone($bookingProcessCustomer->getPhone());
  1011.             $bookingProcessCustomerBillingLocation->setStreet($bookingProcessCustomerLocation->getStreet());
  1012.             $bookingProcessCustomerBillingLocation->setCity($bookingProcessCustomerLocation->getCity());
  1013.             $bookingProcessCustomerBillingLocation->setCode($bookingProcessCustomerLocation->getCode());
  1014.             $bookingProcessCustomerBillingLocation->setProvince($bookingProcessCustomerLocation->getProvince());
  1015.             $bookingProcessCustomerBillingLocation->setCountry($bookingProcessCustomerLocation->getCountry());
  1016.             $bookingProcessCustomerBillingLocation->setLatitude($bookingProcessCustomerLocation->getLatitude());
  1017.             $bookingProcessCustomerBillingLocation->setLongitude($bookingProcessCustomerLocation->getLongitude());
  1018.             $bookingProcessCustomerBillingLocation->setLine2($bookingProcessCustomerLocation->getLine2());
  1019.             $bookingProcessCustomerBillingLocation->setInput($bookingProcessCustomerLocation->getInput());
  1020.             $bookingProcessCustomerBillingLocation->setFormattedAddress($bookingProcessCustomerLocation->getFormattedAddress());
  1021.             $bookingProcessCustomer->setBilling($bookingProcessCustomerBilling);
  1022.         } else {
  1023.             $bookingProcessCustomerBilling $bookingProcessCustomer->getBilling();
  1024.             $bookingProcessCustomerBillingLocation null;
  1025.             if ($bookingProcessCustomerBilling == null) {
  1026.                 $bookingProcessCustomerBilling = new BookingProcessCustomerBilling();
  1027.                 $bookingProcessCustomerBillingLocation $bookingProcessCustomerBilling->getLocation();
  1028.                 if ($bookingProcessCustomerBillingLocation == null) {
  1029.                     $bookingProcessCustomerBillingLocation = new BookingProcessLocation();
  1030.                     $bookingProcessCustomerBilling->setLocation($bookingProcessCustomerBillingLocation);
  1031.                 }
  1032.             } else {
  1033.                 $bookingProcessCustomerBillingLocation $bookingProcessCustomerBilling->getLocation();
  1034.                 if ($bookingProcessCustomerBillingLocation == null) {
  1035.                     $bookingProcessCustomerBillingLocation = new BookingProcessLocation();
  1036.                     $bookingProcessCustomerBilling->setLocation($bookingProcessCustomerBillingLocation);
  1037.                 }
  1038.             }
  1039.             $bookingProcessCustomerBilling->setName($request->request->get('billing-street'));
  1040.             $bookingProcessCustomerBilling->setEmail($request->request->get('billing-email'));
  1041.             $bookingProcessCustomerBilling->setPhone($request->request->get('billing-phone'));
  1042.             $bookingProcessCustomerBillingLocation->setStreet($request->request->get('billing-street'));
  1043.             $bookingProcessCustomerBillingLocation->setCity($request->request->get('billing-city'));
  1044.             $bookingProcessCustomerBillingLocation->setCode($request->request->get('billing-code'));
  1045.             $bookingProcessCustomerBillingLocation->setProvince($request->request->get('billing-province'));
  1046.             $bookingProcessCustomerBillingLocation->setCountry($request->request->get('billing-country'));
  1047.             $bookingProcessCustomerBillingLocation->setLatitude(doubleval($request->request->get('billing-latitude')));
  1048.             $bookingProcessCustomerBillingLocation->setLongitude(doubleval($request->request->get('billing-longitude')));
  1049.             $bookingProcessCustomerBillingLocation->setLine2($request->request->get('billing-line2'));
  1050.             $bookingProcessCustomerBillingLocation->setInput('');
  1051.             $bookingProcessCustomerBillingLocation->setFormattedAddress('');
  1052.             $bookingProcessCustomer->setBilling($bookingProcessCustomerBilling);
  1053.         }
  1054.         if ($bookingProcessCustomerBilling != null) {
  1055.             $this->entityManager->persist($bookingProcessCustomerBilling);
  1056.         }
  1057.         $this->entityManager->persist($bookingProcessLocation);
  1058.         $this->entityManager->persist($bookingProcessCustomer);
  1059.         $this->entityManager->persist($bookingProcessBooking);
  1060.         $this->entityManager->flush();
  1061.         $booking = new Booking();
  1062.         $customer_location = new Location();
  1063.         if ($bookingProcessBooking->getServiceType() === 'fixed' && false) {
  1064.             $customer_location->setStreet('');
  1065.             $customer_location->setCity('');
  1066.             $customer_location->setProvince('');
  1067.             $customer_location->setCountry('');
  1068.             $customer_location->setCode('');
  1069.             $customer_location->setLatitude(null);
  1070.             $customer_location->setLongitude(null);
  1071.             $customer_location->setLine2('');
  1072.         } else {
  1073.             $customer_location->setStreet($bookingProcessCustomerLocation->getStreet());
  1074.             $customer_location->setCity($bookingProcessCustomerLocation->getCity());
  1075.             $customer_location->setProvince($bookingProcessCustomerLocation->getProvince());
  1076.             $customer_location->setCountry($bookingProcessCustomerLocation->getCountry());
  1077.             $customer_location->setCode($bookingProcessCustomerLocation->getCode());
  1078.             $customer_location->setLatitude($bookingProcessCustomerLocation->getLatitude());
  1079.             $customer_location->setLongitude($bookingProcessCustomerLocation->getLongitude());
  1080.             $customer_location->setLine2($bookingProcessCustomerLocation->getLine2());
  1081.         }
  1082.         $customer_billing_location null;
  1083.         $customer_billing null;
  1084.         $bookingProcessBookingCustomerBilling $bookingProcessCustomer->getBilling();
  1085.         if ($bookingProcessBookingCustomerBilling != null) {
  1086.             $bookingProcessBookingCustomerBillingLocation $bookingProcessBookingCustomerBilling->getLocation();
  1087.             if ($bookingProcessBookingCustomerBillingLocation != null) {
  1088.                 $customer_billing_location = new Location();
  1089.                 if ($bookingProcessBooking->getServiceType() === 'fixed' && false) {
  1090.                     $customer_billing_location->setStreet('');
  1091.                     $customer_billing_location->setCity('');
  1092.                     $customer_billing_location->setProvince('');
  1093.                     $customer_billing_location->setCountry('');
  1094.                     $customer_billing_location->setCode('');
  1095.                     $customer_billing_location->setLatitude(null);
  1096.                     $customer_billing_location->setLongitude(null);
  1097.                     $customer_billing_location->setLine2('');
  1098.                 } else {
  1099.                     $customer_billing_location->setStreet($bookingProcessBookingCustomerBillingLocation->getStreet());
  1100.                     $customer_billing_location->setCity($bookingProcessBookingCustomerBillingLocation->getCity());
  1101.                     $customer_billing_location->setProvince($bookingProcessBookingCustomerBillingLocation->getProvince());
  1102.                     $customer_billing_location->setCountry($bookingProcessBookingCustomerBillingLocation->getCountry());
  1103.                     $customer_billing_location->setCode($bookingProcessBookingCustomerBillingLocation->getCode());
  1104.                     $customer_billing_location->setLatitude($bookingProcessBookingCustomerBillingLocation->getLatitude());
  1105.                     $customer_billing_location->setLongitude($bookingProcessBookingCustomerBillingLocation->getLongitude());
  1106.                     $customer_billing_location->setLine2($bookingProcessBookingCustomerBillingLocation->getLine2());
  1107.                 }
  1108.             }
  1109.             $customer_billing = new CustomerBilling();
  1110.             $customer_billing->setLocation($customer_billing_location);
  1111.             $customer_billing->setName($bookingProcessBookingCustomerBilling->getName());
  1112.             $customer_billing->setEmail($bookingProcessBookingCustomerBilling->getEmail());
  1113.             $customer_billing->setPhone($bookingProcessBookingCustomerBilling->getPhone());
  1114.             $customer_billing->setPhoneCanonical($bookingProcessBookingCustomerBilling->getPhoneCanonical());
  1115.         }
  1116.         $customer = new Customer();
  1117.         $customer->setLocation($customer_location);
  1118.         if ($customer_billing != null) {
  1119.             $customer->setBilling($customer_billing);
  1120.         }
  1121.         $customer->setEmail($bookingProcessCustomer->getEmail());
  1122.         $customer->setName($bookingProcessCustomer->getName());
  1123.         $customer->setPhone($bookingProcessCustomer->getPhone());
  1124.         $customer->setPhoneCanonical($bookingProcessCustomer->getPhoneCanonical());
  1125.         $customer->setClient($bookingProcessCustomer->getClient());
  1126.         $customer->setDeleted($bookingProcessCustomer->getDeleted());
  1127.         $customer->setPhoneDescription($bookingProcessCustomer->getPhoneDescription());
  1128.         $location = new Location();
  1129.         $location->setStreet($bookingProcessLocation->getStreet());
  1130.         $location->setCity($bookingProcessLocation->getCity());
  1131.         $location->setProvince($bookingProcessLocation->getProvince());
  1132.         $location->setCountry($bookingProcessLocation->getCountry());
  1133.         $location->setCode($bookingProcessLocation->getCode());
  1134.         $location->setLatitude($bookingProcessLocation->getLatitude());
  1135.         $location->setLongitude($bookingProcessLocation->getLongitude());
  1136.         $location->setLine2($bookingProcessLocation->getLine2());
  1137.         $booking->setScope('cm_mvp1');
  1138.         $booking->setClient($bookingProcessBooking->getClient());
  1139.         $booking->setCustomer($customer);
  1140.         $booking->setService($bookingProcessBooking->getService());
  1141.         $booking->setLocation($location);
  1142.         $booking->setServiceType($bookingProcessBooking->getServiceType());
  1143.         $booking->setSelectedRegion($bookingProcessBooking->getSelectedRegion());
  1144.         $booking->setCrew($bookingProcessBooking->getCrew());
  1145.         $booking->setRadius($bookingProcessBooking->getRadius());
  1146.         $booking->setDateStart($bookingProcessBooking->getDateStart());
  1147.         $booking->setDateEnd($bookingProcessBooking->getDateEnd());
  1148.         $booking->setAdditionalInformation($bookingProcessBooking->getAdditionalInformation());
  1149.         //$booking->setNotes($bookingProcessBooking->getNotes());
  1150.         $booking->setDatePosted(clone $now);
  1151.         $booking->setDateUpdated(clone $now);
  1152.         //$booking->setUser(null);
  1153.         $booking->setAdditionalMinutes($bookingProcessBooking->getAdditionalMinutes());
  1154.         $booking->setStatus($bookingProcessBooking->getStatus());
  1155.         $bookingProcessBookingRegions $bookingProcessBooking->getRegions();
  1156.         foreach ($bookingProcessBookingRegions as $bookingProcessBookingRegion) {
  1157.             $booking->addRegion($bookingProcessBookingRegion);
  1158.         }
  1159.         if ($customer_billing_location != null) {
  1160.             $this->entityManager->persist($customer_billing_location);
  1161.         }
  1162.         if ($customer_billing != null) {
  1163.             $this->entityManager->persist($customer_billing);
  1164.         }
  1165.         if ($customer_location != null) {
  1166.             $this->entityManager->persist($customer_location);
  1167.         }
  1168.         if ($customer != null) {
  1169.             $this->entityManager->persist($customer);
  1170.         }
  1171.         if ($location != null) {
  1172.             $this->entityManager->persist($location);
  1173.         }
  1174.         if ($booking != null) {
  1175.             $this->entityManager->persist($booking);
  1176.         }
  1177.         $this->entityManager->flush();
  1178.         if ($region $this->getRegion($booking->getLocation())) {
  1179.             $regions $booking->getRegions();
  1180.             $regionIds = [];
  1181.             if ($regions != null) {
  1182.                 foreach ($regions as $region) {
  1183.                     $regionIds[] = $region->getId();
  1184.                 }
  1185.             }
  1186.             if (!in_array($region->getId(), $regionIds)) {
  1187.                 $booking->addRegion($region);
  1188.             }
  1189.             $this->entityManager->persist($booking);
  1190.             $this->entityManager->flush();
  1191.         }
  1192.         $notificationMailer $this->notificationMailer;
  1193.         try {
  1194.             $notificationMailer->send($booking);
  1195.         } catch (TransportException $e) {
  1196.             //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  1197.             //$result = self::FAILED_TO_SEND_EMAIL;
  1198.         }
  1199.         try {
  1200.             $notificationMailer->sendSMS($booking);
  1201.         } catch (\Throwable $e) {
  1202.             //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  1203.             //$result = self::FAILED_TO_SEND_EMAIL;
  1204.         }
  1205.         try {
  1206.             $this->webhookService->__trigger_event_request_booking($booking);
  1207.         } catch (\Throwable $throwable) {
  1208.             // NOTHING
  1209.             if ($this->client !== null && $this->client->getEnvType() !== 'production') {
  1210.                 dd([
  1211.                     'message' => $throwable->getMessage(),
  1212.                     'file' => $throwable->getFile(),
  1213.                     'line' => $throwable->getLine(),
  1214.                     'trace' => $throwable->getTrace()
  1215.                 ]);
  1216.             }
  1217.         }
  1218.         return true;
  1219.     }
  1220.     public function doStepInputConfirmLocation($request$bookingProcess)
  1221.     {
  1222.         $now = new \DateTime();
  1223.         $bookingProcessBooking $bookingProcess->getBooking();
  1224.         $bookingProcessLocation $bookingProcess->getBooking()->getLocation();
  1225.         $address $this->getAddress($request);
  1226.         $ad $this->mapservice->getAddressDetails($address);
  1227.         if ($ad != null) {
  1228.             $bookingProcessLocation->setInput($address);
  1229.             $bookingProcessLocation->setLine2($request->request->get('line2'));
  1230.             $bookingProcessLocation->setFormattedAddress(property_exists($ad'formatted_address') ? $ad->formatted_address '');
  1231.             $bookingProcessLocation->setStreet(property_exists($ad'street') ? $ad->street $request->request->get('street'));
  1232.             $bookingProcessLocation->setCity(property_exists($ad'city') ? $ad->city $request->request->get('city'));
  1233.             $bookingProcessLocation->setProvince(property_exists($ad'province') ? $ad->province $request->request->get('province'));
  1234.             $bookingProcessLocation->setCountry(property_exists($ad'country') ? $ad->country $request->request->get('country'));
  1235.             $bookingProcessLocation->setCode(property_exists($ad'code') ? $ad->code $request->request->get('code'));
  1236.             $bookingProcessLocation->setLatitude(property_exists($ad'latitude') ? $ad->latitude null);
  1237.             $bookingProcessLocation->setLongitude(property_exists($ad'longitude') ? $ad->longitude null);
  1238.         } else {
  1239.             $bookingProcessLocation->setStreet($request->request->get('street'));
  1240.             $bookingProcessLocation->setLine2($request->request->get('line2'));
  1241.             $bookingProcessLocation->setCity($request->request->get('city'));
  1242.             $bookingProcessLocation->setCode($request->request->get('code'));
  1243.             $bookingProcessLocation->setProvince($request->request->get('province'));
  1244.             $bookingProcessLocation->setCountry($request->request->get('country'));
  1245.             $bookingProcessLocation->setLatitude(null);
  1246.             $bookingProcessLocation->setLongitude(null);
  1247.         }
  1248.         $this->entityManager->persist($bookingProcessLocation);
  1249.         $this->entityManager->flush();
  1250.         $bookingRegions $bookingProcessBooking->getRegions();
  1251.         $bookingRegionsIds = [];
  1252.         if ($bookingRegions) {
  1253.             foreach ($bookingRegions as $bookingRegion) {
  1254.                 $bookingRegionsIds[] = $bookingRegion->getId();
  1255.             }
  1256.         }
  1257.         $locationRegions $this->getRegionsFromLocation($bookingProcessLocation$bookingProcess->getAllowedRegions());
  1258.         if (!$locationRegions) {
  1259.             throw new \Exception("Location is out of bounds!");
  1260.         }
  1261.         foreach ($bookingRegions as $bookingRegion) {
  1262.             $bookingProcessBooking->removeRegion($bookingRegion);
  1263.         }
  1264.         foreach ($locationRegions as $locationRegion) {
  1265.             $bookingProcessBooking->addRegion($locationRegion);
  1266.         }
  1267.         // TODO: REMOVE THIS
  1268.         // foreach($locationRegions as $locationRegion) {
  1269.         //     if (!in_array($locationRegion->getId(), $bookingRegionsIds)) {
  1270.         //         $bookingProcessBooking->addRegion($locationRegion);
  1271.         //     }
  1272.         // }
  1273.         $this->entityManager->persist($bookingProcessBooking);
  1274.         $this->entityManager->flush();
  1275.         return true;
  1276.     }
  1277.     public function doStepInputService($request$bookingProcess, ?string $serviceId null)
  1278.     {
  1279.         $now = new \DateTime();
  1280.         if ($serviceId) {
  1281.             $newId intval($serviceId);
  1282.         } else {
  1283.             $newId intval($request->request->get('service_id'));
  1284.         }
  1285.         $bookingProcessBooking $bookingProcess->getBooking();
  1286.         $bookingProcessBookingService $bookingProcessBooking->getService();
  1287.         if ($bookingProcessBookingService == null || $bookingProcessBookingService->getId() != $newId) {
  1288.             $service $this->serviceRepository->findOneById($newId);
  1289.             $bookingProcessBooking->setService($service);
  1290.             $bookingProcessBooking->setAdditionalInformation('');
  1291.             $a $bookingProcessBooking->emptyBookingProcessBookingServiceAnswers();
  1292.             foreach ($a as $bookingProcessBookingServiceAnswer) {
  1293.                 $this->entityManager->remove($bookingProcessBookingServiceAnswer);
  1294.             }
  1295.             $this->entityManager->persist($bookingProcessBooking);
  1296.             $this->entityManager->flush();
  1297.         }
  1298.         return true;
  1299.     }
  1300.     public function doStepInputServiceFields($request$bookingProcess)
  1301.     {
  1302.         $now = new \DateTime();
  1303.         $bookingProcessBooking $bookingProcess->getBooking();
  1304.         $answers $bookingProcessBooking->getBookingProcessBookingServiceAnswers();
  1305.         foreach ($answers as $answer) {
  1306.             $this->entityManager->remove($answer);
  1307.         }
  1308.         $this->entityManager->flush();
  1309.         $sfields $request->request->get('fields');
  1310.         $afields explode(','$sfields);
  1311.         foreach ($afields as $field_id) {
  1312.             $serviceField $this->serviceFieldRepository->find($field_id);
  1313.             if ($serviceField == null) {
  1314.                 continue;
  1315.             }
  1316.             $bookingProcessBookingServiceAnswer = new BookingProcessBookingServiceAnswer();
  1317.             $bookingProcessBookingServiceAnswer->setBooking($bookingProcessBooking);
  1318.             $bookingProcessBookingServiceAnswer->setField($serviceField);
  1319.             $bookingProcessBookingServiceAnswer->setSlug($serviceField->getSlug());
  1320.             $bookingProcessBookingServiceAnswer->setAnswer($request->request->get("field_${field_id}"));
  1321.             $this->entityManager->persist($bookingProcessBookingServiceAnswer);
  1322.             $this->entityManager->flush();
  1323.         }
  1324.         $additionalMinutes 0;
  1325.         $bookingProcessBooking->setAdditionalInformation($request->request->get('comments'));
  1326.         $bookingProcessBooking->setAdditionalMinutes($additionalMinutes);
  1327.         $this->entityManager->persist($bookingProcessBooking);
  1328.         return true;
  1329.     }
  1330.     public function doStepInputScheduleType($request$bookingProcess)
  1331.     {
  1332.         // TODO
  1333.         return true;
  1334.     }
  1335.     public function doStepInputDateTime($request$bookingProcess)
  1336.     {
  1337.         $now = new \DateTime();
  1338.         $bookingProcessBooking $bookingProcess->getBooking();
  1339.         $sdate $request->request->get('date');
  1340.         $ssstart $request->request->get('start');
  1341.         $astart explode('|'$ssstart);
  1342.         $sscheduletype 'exact';
  1343.         $sstarttype count($astart) > $astart[0] : '';
  1344.         $sstart count($astart) > $astart[1] : '';
  1345.         $previousCrew $bookingProcessBooking->getCrew();
  1346.         $previousDateStart $bookingProcessBooking->getDateStart();
  1347.         $previousDateEnd $bookingProcessBooking->getDateEnd();
  1348.         $isValueNull true;
  1349.         $date null;
  1350.         $available_times = [];
  1351.         try {
  1352.             $adate explode('-'$sdate);
  1353.             if (count($adate) < 3) {
  1354.                 throw new \Exception('Invalid date');
  1355.             }
  1356.             $idateyear intval($adate[0]);
  1357.             $idatemonth intval($adate[1]);
  1358.             $idateday intval($adate[2]);
  1359.             $date = \DateTime::createFromFormat('Y-m-d'$sdate);
  1360.             switch ($sstarttype) {
  1361.                 case 'gap': {
  1362.                     $sscheduletype $sstart;
  1363.                     $available_times $this->ptimeAvailability($date$sscheduletype$bookingProcessBooking);
  1364.                     $istarthour 0;
  1365.                     $istartminute 0;
  1366.                     foreach ($available_times as $available_time) {
  1367.                         $aoption explode('|'$available_time);
  1368.                         if ($aoption[0] == 'time') {
  1369.                             $aaoption explode(':'$aoption[1]);
  1370.                             $istarthour intval($aaoption[0]);
  1371.                             $istartminute intval($aaoption[1]);
  1372.                             break;
  1373.                         }
  1374.                     }
  1375.                 }
  1376.                     break;
  1377.                 case 'time':
  1378.                 default: {
  1379.                     $sscheduletype 'exact';
  1380.                     RoutezillaDebugger::setMark(false'START');
  1381.                     $available_times $this->ptimeAvailability($date$sscheduletype$bookingProcessBooking);
  1382.                     RoutezillaDebugger::setMark(false, [
  1383.                         'label' => 'CHECKPOINT 1',
  1384.                         '$available_times' => $available_times
  1385.                     ]);
  1386.                     $astart explode(':'$sstart);
  1387.                     if (count($astart) < 2) {
  1388.                         throw new \Exception('Invalid time');
  1389.                     }
  1390.                     $istarthour intval($astart[0]);
  1391.                     $istartminute intval($astart[1]);
  1392.                 }
  1393.                     break;
  1394.             }
  1395.             $isValueNull false;
  1396.         } catch (\Throwable $throwable) {
  1397.             $isValueNull true;
  1398.         }
  1399.         if (!$isValueNull) {
  1400.             if ($bookingProcessBooking->getDateStart() == null) {
  1401.                 $bookingProcessBooking->setDateStart(new \DateTime());
  1402.             }
  1403.             $bookingProcessBooking->getDateStart()->setDate(
  1404.                 $idateyear,
  1405.                 $idatemonth,
  1406.                 $idateday
  1407.             );
  1408.             $bookingProcessBooking->getDateStart()->setTime(
  1409.                 $istarthour,
  1410.                 $istartminute
  1411.             );
  1412.             $bookingProcessBooking->setDateStart(clone $bookingProcessBooking->getDateStart());
  1413.             $bookingProcessBooking->setScheduleType($sscheduletype);
  1414.             if ($sscheduletype == 'exact') {
  1415.                 $bookingProcessBooking->setScheduleStatus('locked');
  1416.             } else {
  1417.                 //$bookingProcessBooking->setScheduleStatus('unlocked');
  1418.                 $bookingProcessBooking->setScheduleStatus('locked');
  1419.             }
  1420.             $this->entityManager->persist($bookingProcessBooking);
  1421.             $this->entityManager->flush();
  1422.             $start = clone $bookingProcessBooking->getDateStart();
  1423.             $start->setTime(00);
  1424.             $start->modify('-1 day');
  1425.             $end = clone $start;
  1426.             $end->modify('+2 days');
  1427.             $bookingProcessBooking->setDateEnd($this->endTimeCalculator->getEndTimeForProcess($bookingProcessBooking));
  1428.             $this->entityManager->persist($bookingProcessBooking);
  1429.             $this->entityManager->flush();
  1430.             $this->scheduler->setRange($start$end);
  1431.             $availableCrew $this->scheduler->getAvailableCrewForProcess($bookingProcessBooking$this->client);
  1432.             RoutezillaDebugger::setMark(false, [
  1433.                 'label' => 'CREWS',
  1434.                 $availableCrew
  1435.             ]);
  1436.             //RoutezillaDebugger::stop();
  1437.             //dd($availableCrew != null ? $availableCrew->getId() : '-- NULL --');
  1438.             if ($availableCrew == null) {
  1439.                 if ($previousCrew != null && $previousDateStart != null && $previousDateEnd != null) {
  1440.                     $dtup = clone ($previousDateStart);
  1441.                     $dtup->setTime(000);
  1442.                     $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($bookingProcessBooking->getClient(), $previousCrew$dtup);
  1443.                 }
  1444.                 throw new \Exception("Date / Time not available anymore");
  1445.             }
  1446.             $bookingProcessBooking->setCrew($availableCrew);
  1447.             $additionalMinutes $this->endTimeCalculator->getAdditionalMinutesForProcess($bookingProcessBooking);
  1448.             $bookingProcessBooking->setAdditionalMinutes($additionalMinutes);
  1449.             $this->entityManager->persist($bookingProcessBooking);
  1450.             $this->entityManager->flush();
  1451.             $bookableHours $this->getBookableHours($request);
  1452.             $hour $bookingProcessBooking->getDateStart();
  1453.             if ($previousCrew != null && $previousDateStart != null && $previousDateEnd != null) {
  1454.                 $dtup = clone ($previousDateStart);
  1455.                 $dtup->setTime(000);
  1456.                 $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($bookingProcessBooking->getClient(), $previousCrew$dtup);
  1457.             }
  1458.             if ($bookingProcessBooking->getCrew() != null) {
  1459.                 $dtu = clone ($bookingProcessBooking->getDateStart());
  1460.                 $dtu->setTime(000);
  1461.                 $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($bookingProcessBooking->getClient(), $bookingProcessBooking->getCrew(), $dtu);
  1462.             }
  1463.             // if (!in_array($hour, $bookableHours)) {
  1464.             //     throw new \Exception("Date / Time not available anymore");
  1465.             // }
  1466.             if (!in_array($ssstart$available_times)) {
  1467.                 throw new \Exception("Date / Time not available anymore");
  1468.             }
  1469.         } else if ($previousCrew != null && $previousDateStart != null && $previousDateEnd != null) {
  1470.             $dtup = clone ($previousDateStart);
  1471.             $dtup->setTime(000);
  1472.             $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($bookingProcessBooking->getClient(), $previousCrew$dtup);
  1473.         }
  1474.         return true;
  1475.     }
  1476.     public function doStepInputContact($request$bookingProcess)
  1477.     {
  1478.         $now = new \DateTime();
  1479.         $bookingProcessBooking $bookingProcess->getBooking();
  1480.         $bookingProcessBookingLocation $bookingProcessBooking->getLocation();
  1481.         if ($this->getUser() != null) {
  1482.             $bookingProcessBooking->setNotes($request->request->get('admin-notes'));
  1483.         }
  1484.         #$customer_id = $request->request->get('customer-id');
  1485.         $customer $bookingProcess->getBooking()->getCustomer();
  1486.         if ($customer == null) {
  1487.             $customer = new BookingProcessCustomer();
  1488.             $bookingProcessBooking->setCustomer($customer);
  1489.         }
  1490.         $customer->setEmail($request->request->get('customer-email'));
  1491.         $customer->setName($request->request->get('customer-name'));
  1492.         $customer->setPhone($request->request->get('customer-phone'));
  1493.         $customer->setPhoneCanonical($request->request->get('customer-phone'));
  1494.         $customer->setClient($this->client);
  1495.         $customer->setDeleted(false);
  1496.         $customer->setPhoneDescription('');
  1497.         $location $customer->getLocation();
  1498.         if ($location == null) {
  1499.             $location = new BookingProcessLocation();
  1500.             $customer->setLocation($location);
  1501.         }
  1502.         if ($bookingProcessBooking->getServiceType() === 'fixed') {
  1503.             $location->setStreet('');
  1504.             $location->setCity('');
  1505.             $location->setCode('');
  1506.             $location->setProvince('');
  1507.             $location->setCountry('');
  1508.             $location->setLatitude(null);
  1509.             $location->setLongitude(null);
  1510.             $location->setLine2('');
  1511.             $location->setInput('');
  1512.             $location->setFormattedAddress('');
  1513.         } else {
  1514.             $location->setStreet($bookingProcessBookingLocation->getStreet());
  1515.             $location->setCity($bookingProcessBookingLocation->getCity());
  1516.             $location->setCode($bookingProcessBookingLocation->getCode());
  1517.             $location->setProvince($bookingProcessBookingLocation->getProvince());
  1518.             $location->setCountry($bookingProcessBookingLocation->getCountry());
  1519.             $location->setLatitude($bookingProcessBookingLocation->getLatitude());
  1520.             $location->setLongitude($bookingProcessBookingLocation->getLongitude());
  1521.             $location->setLine2($bookingProcessBookingLocation->getLine2());
  1522.             $location->setInput($bookingProcessBookingLocation->getInput());
  1523.             $location->setFormattedAddress($bookingProcessBookingLocation->getFormattedAddress());
  1524.         }
  1525.         $billing null;
  1526.         $billing_location null;
  1527.         $isBillingSame = ($request->request->get('customer-billing-same') != null);
  1528.         if ($isBillingSame) {
  1529.             $billing $customer->getBilling();
  1530.             if ($billing != null) {
  1531.                 $customer->setBilling(null);
  1532.                 $this->entityManager->remove($billing);
  1533.                 $this->entityManager->flush();
  1534.             }
  1535.             $billing = new BookingProcessCustomerBilling();
  1536.             $billing_location = new BookingProcessLocation();
  1537.             $billing->setLocation($billing_location);
  1538.             $billing_location->setStreet($location->getStreet());
  1539.             $billing_location->setCity($location->getCity());
  1540.             $billing_location->setCode($location->getCode());
  1541.             $billing_location->setProvince($location->getProvince());
  1542.             $billing_location->setCountry($location->getCountry());
  1543.             $billing_location->setLatitude($location->getLatitude());
  1544.             $billing_location->setLongitude($location->getLongitude());
  1545.             $billing_location->setLine2($location->getLine2());
  1546.             $billing_location->setInput($location->getInput());
  1547.             $billing_location->setFormattedAddress($location->getFormattedAddress());
  1548.             $billing->setName($customer->getName());
  1549.             $billing->setPhone($customer->getPhone());
  1550.             $billing->setEmail($customer->getEmail());
  1551.             $customer->setBilling($billing);
  1552.         } else {
  1553.             $billing $customer->getBilling();
  1554.             if ($billing == null) {
  1555.                 $billing = new BookingProcessCustomerBilling();
  1556.                 $billing_location = new BookingProcessLocation();
  1557.                 $billing->setLocation($billing_location);
  1558.             }
  1559.             $customer->setBilling($billing);
  1560.         }
  1561.         if ($billing != null) {
  1562.             if ($billing_location != null) {
  1563.                 $this->entityManager->persist($billing_location);
  1564.             }
  1565.             $this->entityManager->persist($billing);
  1566.         }
  1567.         $this->entityManager->persist($location);
  1568.         $this->entityManager->persist($customer);
  1569.         $this->entityManager->persist($bookingProcessBooking);
  1570.         $this->entityManager->flush();
  1571.         return true;
  1572.     }
  1573.     public function doStepInputBilling($request$bookingProcess)
  1574.     {
  1575.         $now = new \DateTime();
  1576.         if (!$bookingProcess || !$bookingProcess->getBooking() || !$bookingProcess->getBooking()->getCustomer() || !$bookingProcess->getBooking()->getCustomer()->getBilling() || !$bookingProcess->getBooking()->getCustomer()->getBilling()->getLocation()) {
  1577.             return false;
  1578.         }
  1579.         $bookingProcessBooking $bookingProcess->getBooking();
  1580.         $bookingProcessBookingCustomer $bookingProcessBooking->getCustomer();
  1581.         $bookingProcessBookingCustomerBilling $bookingProcessBookingCustomer->getBilling();
  1582.         $bookingProcessBookingCustomerBillingLocation $bookingProcessBookingCustomerBilling->getLocation();
  1583.         $bookingProcessBookingCustomerBillingLocation->setStreet($request->request->get('street'));
  1584.         $bookingProcessBookingCustomerBillingLocation->setCity($request->request->get('city'));
  1585.         $bookingProcessBookingCustomerBillingLocation->setCode($request->request->get('code'));
  1586.         $bookingProcessBookingCustomerBillingLocation->setProvince($request->request->get('province'));
  1587.         $bookingProcessBookingCustomerBillingLocation->setCountry($request->request->get('country'));
  1588.         $bookingProcessBookingCustomerBillingLocation->setLatitude(doubleval($request->request->get('latitude')));
  1589.         $bookingProcessBookingCustomerBillingLocation->setLongitude(doubleval($request->request->get('longitude')));
  1590.         $bookingProcessBookingCustomerBillingLocation->setLine2($request->request->get('line2'));
  1591.         $bookingProcessBookingCustomerBillingLocation->setInput('');
  1592.         $bookingProcessBookingCustomerBillingLocation->setFormattedAddress('');
  1593.         $bookingProcessBookingCustomerBilling->setName($request->request->get('name'));
  1594.         $bookingProcessBookingCustomerBilling->setPhone($request->request->get('phone'));
  1595.         $bookingProcessBookingCustomerBilling->setEmail($request->request->get('email'));
  1596.         $this->entityManager->persist($bookingProcessBookingCustomerBillingLocation);
  1597.         $this->entityManager->persist($bookingProcessBookingCustomerBilling);
  1598.         $this->entityManager->flush();
  1599.         return true;
  1600.     }
  1601.     public function doStepConfirm($request$bookingProcess)
  1602.     {
  1603.         $now = new \DateTime();
  1604.         // TODO - IMPLEMENT COMMIT ON EDIT
  1605.         switch ($bookingProcess->getType()) {
  1606.             case "create": {
  1607.                 $bookingProcessBooking $bookingProcess->getBooking();
  1608.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  1609.                 $bookingProcessCustomer $bookingProcessBooking->getCustomer();
  1610.                 $bookingProcessCustomerLocation $bookingProcessCustomer->getLocation();
  1611.                 $customer $this->customerRepository->findLastCustomerEmail($bookingProcessCustomer->getEmail());
  1612.                 if ($customer !== null) {
  1613.                     $bookingProcess->setStatus("commit-confirm");
  1614.                     $this->entityManager->persist($bookingProcess);
  1615.                     $this->entityManager->flush();
  1616.                     try {
  1617.                         $this->confirmationMailerForProcess->send($bookingProcessBooking);
  1618.                     } catch (TransportException $e) {
  1619.                         //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  1620.                         //$result = self::FAILED_TO_SEND_EMAIL;
  1621.                     }
  1622.                     // try {
  1623.                     //     $this->confirmationMailerForProcess->sendSMS($booking);
  1624.                     // }
  1625.                     // catch (\Throwable $e) {
  1626.                     //     //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  1627.                     //     //$result = self::FAILED_TO_SEND_EMAIL;
  1628.                     // }
  1629.                     return 'commit-confirm';
  1630.                 } else {
  1631.                     return $this->doStepCommit($request$bookingProcess) ? 'commit-success' 'commit-failure';
  1632.                 }
  1633.             }
  1634.                 break;
  1635.             case "edit": {
  1636.                 $bookingProcessBooking $bookingProcess->getBooking();
  1637.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  1638.                 $bookingProcessCustomer $bookingProcessBooking->getCustomer();
  1639.                 $bookingProcessCustomerLocation $bookingProcessCustomer->getLocation();
  1640.                 $booking $bookingProcess->getMaterialBooking();
  1641.                 if ($booking == null) {
  1642.                     $booking = new Booking();
  1643.                 }
  1644.                 $customer $this->customerRepository->findLastCustomerEmail($bookingProcessCustomer->getEmail());
  1645.                 if ($booking->getCustomer() !== null && $customer !== null && $booking->getCustomer()->getId() !== $customer->getId()) {
  1646.                     $this->entityManager->persist($bookingProcess);
  1647.                     $this->entityManager->flush();
  1648.                     try {
  1649.                         $this->confirmationMailerForProcess->send($bookingProcessBooking);
  1650.                     } catch (TransportException $e) {
  1651.                         //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  1652.                         //$result = self::FAILED_TO_SEND_EMAIL;
  1653.                     }
  1654.                     // try {
  1655.                     //     $this->confirmationMailerForProcess->sendSMS($booking);
  1656.                     // }
  1657.                     // catch (\Throwable $e) {
  1658.                     //     //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  1659.                     //     //$result = self::FAILED_TO_SEND_EMAIL;
  1660.                     // }
  1661.                     return 'commit-confirm';
  1662.                 } else {
  1663.                     return $this->doStepCommit($request$bookingProcess) ? 'commit-success' 'commit-failure';
  1664.                 }
  1665.             }
  1666.                 break;
  1667.         }
  1668.     }
  1669.     public function doStepCommit($request$bookingProcess)
  1670.     {
  1671.         $now = new \DateTime();
  1672.         // TODO - IMPLEMENT COMMIT ON EDIT
  1673.         switch ($bookingProcess->getType()) {
  1674.             case "create": {
  1675.                 $bookingProcessBooking $bookingProcess->getBooking();
  1676.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  1677.                 $bookingProcessCustomer $bookingProcessBooking->getCustomer();
  1678.                 $bookingProcessCustomerLocation $bookingProcessCustomer->getLocation();
  1679.                 $booking = new Booking();
  1680.                 $customer null;
  1681.                 $isnewcustomer false;
  1682.                 $customer_mode_find $this->client->getPropertyValue('booking.customer.mode.find');
  1683.                 if (!empty($customer_mode_find) && in_array($customer_mode_find, ['true''1'])) {
  1684.                     $customer $this->customerRepository->findLastCustomerEmail($bookingProcessCustomer->getEmail());
  1685.                     if ($customer === null) {
  1686.                         $customer = new Customer();
  1687.                         $isnewcustomer true;
  1688.                     }
  1689.                 } else {
  1690.                     $customer = new Customer();
  1691.                     $isnewcustomer true;
  1692.                 }
  1693.                 $customer_location null;
  1694.                 if ($isnewcustomer || $customer->getLocation() === null) {
  1695.                     $customer_location = new Location();
  1696.                 } else {
  1697.                     $customer_location $customer->getLocation();
  1698.                 }
  1699.                 $customer_location->setStreet($bookingProcessCustomerLocation->getStreet());
  1700.                 $customer_location->setCity($bookingProcessCustomerLocation->getCity());
  1701.                 $customer_location->setProvince($bookingProcessCustomerLocation->getProvince());
  1702.                 $customer_location->setCountry($bookingProcessCustomerLocation->getCountry());
  1703.                 $customer_location->setLatitude($bookingProcessCustomerLocation->getLatitude());
  1704.                 $customer_location->setLongitude($bookingProcessCustomerLocation->getLongitude());
  1705.                 $customer_location->setLine2($bookingProcessCustomerLocation->getLine2());
  1706.                 $customer_location->setCode($bookingProcessCustomerLocation->getCode());
  1707.                 $customer_billing_location null;
  1708.                 $customer_billing null;
  1709.                 $bookingProcessBookingCustomerBilling $bookingProcessCustomer->getBilling();
  1710.                 if ($bookingProcessBookingCustomerBilling != null) {
  1711.                     $bookingProcessBookingCustomerBillingLocation $bookingProcessBookingCustomerBilling->getLocation();
  1712.                     if ($bookingProcessBookingCustomerBillingLocation != null) {
  1713.                         $customer_billing_location $isnewcustomer || $customer->getBilling() === null ? new Location() : $customer->getBilling()->getLocation();
  1714.                         $customer_billing_location->setStreet($bookingProcessBookingCustomerBillingLocation->getStreet());
  1715.                         $customer_billing_location->setCity($bookingProcessBookingCustomerBillingLocation->getCity());
  1716.                         $customer_billing_location->setProvince($bookingProcessBookingCustomerBillingLocation->getProvince());
  1717.                         $customer_billing_location->setCountry($bookingProcessBookingCustomerBillingLocation->getCountry());
  1718.                         $customer_billing_location->setLatitude($bookingProcessBookingCustomerBillingLocation->getLatitude());
  1719.                         $customer_billing_location->setLongitude($bookingProcessBookingCustomerBillingLocation->getLongitude());
  1720.                         $customer_billing_location->setLine2($bookingProcessBookingCustomerBillingLocation->getLine2());
  1721.                         $customer_billing_location->setCode($bookingProcessBookingCustomerBillingLocation->getCode());
  1722.                     }
  1723.                     $customer_billing $isnewcustomer || $customer->getBilling() === null ? new CustomerBilling() : $customer->getBilling();
  1724.                     $customer_billing->setLocation($customer_billing_location);
  1725.                     $customer_billing->setName($bookingProcessBookingCustomerBilling->getName());
  1726.                     $customer_billing->setEmail($bookingProcessBookingCustomerBilling->getEmail());
  1727.                     $customer_billing->setPhone($bookingProcessBookingCustomerBilling->getPhone());
  1728.                     $customer_billing->setPhoneCanonical($bookingProcessBookingCustomerBilling->getPhoneCanonical());
  1729.                 }
  1730.                 $customer->setLocation($customer_location);
  1731.                 if ($customer_billing != null) {
  1732.                     $customer->setBilling($customer_billing);
  1733.                 }
  1734.                 $customer->setEmail($bookingProcessCustomer->getEmail());
  1735.                 $customer->setName($bookingProcessCustomer->getName());
  1736.                 $customer->setPhone($bookingProcessCustomer->getPhone());
  1737.                 $customer->setPhoneCanonical($bookingProcessCustomer->getPhoneCanonical());
  1738.                 $customer->setClient($bookingProcessCustomer->getClient());
  1739.                 $customer->setDeleted($bookingProcessCustomer->getDeleted());
  1740.                 $customer->setPhoneDescription($bookingProcessCustomer->getPhoneDescription());
  1741.                 $location = new Location();
  1742.                 $location->setStreet($bookingProcessLocation->getStreet());
  1743.                 $location->setCity($bookingProcessLocation->getCity());
  1744.                 $location->setProvince($bookingProcessLocation->getProvince());
  1745.                 $location->setCountry($bookingProcessLocation->getCountry());
  1746.                 $location->setLatitude($bookingProcessLocation->getLatitude());
  1747.                 $location->setLongitude($bookingProcessLocation->getLongitude());
  1748.                 $location->setLine2($bookingProcessLocation->getLine2());
  1749.                 $location->setCode($bookingProcessLocation->getCode());
  1750.                 $booking->setScope('cm_mvp1');
  1751.                 $booking->setClient($bookingProcessBooking->getClient());
  1752.                 $booking->setCustomer($customer);
  1753.                 $booking->setService($bookingProcessBooking->getService());
  1754.                 $booking->setLocation($location);
  1755.                 $booking->setServiceType($bookingProcessBooking->getServiceType());
  1756.                 $booking->setSelectedRegion($bookingProcessBooking->getSelectedRegion());
  1757.                 $booking->setCrew($bookingProcessBooking->getCrew());
  1758.                 //$booking->setRadius($bookingProcessBooking->getRadius());
  1759.                 $booking->setDateStart($bookingProcessBooking->getDateStart());
  1760.                 $booking->setDateEnd($bookingProcessBooking->getDateEnd());
  1761.                 $booking->setScheduleType($bookingProcessBooking->getScheduleType());
  1762.                 $booking->setScheduleStatus($bookingProcessBooking->getScheduleStatus());
  1763.                 $booking->setStatus(BookingStatus::STATUS_ASSIGNED);
  1764.                 $booking->setAdditionalInformation($bookingProcessBooking->getAdditionalInformation());
  1765.                 $booking->setNotes($bookingProcessBooking->getNotes());
  1766.                 $booking->setDatePosted(clone $now);
  1767.                 $booking->setDateUpdated(clone $now);
  1768.                 //$booking->setUser(null);
  1769.                 $booking->setUser($bookingProcessBooking->getUser());
  1770.                 $booking->setAdditionalMinutes($bookingProcessBooking->getAdditionalMinutes());
  1771.                 $bookingProcessBookingRegions $bookingProcessBooking->getRegions();
  1772.                 foreach ($bookingProcessBookingRegions as $bookingProcessBookingRegion) {
  1773.                     $booking->addRegion($bookingProcessBookingRegion);
  1774.                 }
  1775.                 $bookingProcessBookingServiceAnswers $bookingProcessBooking->getBookingProcessBookingServiceAnswers();
  1776.                 foreach ($bookingProcessBookingServiceAnswers as $bookingProcessBookingServiceAnswer) {
  1777.                     $field = new BookingServiceField();
  1778.                     $field->setBooking($booking);
  1779.                     $field->setField($bookingProcessBookingServiceAnswer->getField());
  1780.                     $field->setSlug($bookingProcessBookingServiceAnswer->getSlug());
  1781.                     $field->setAnswer($bookingProcessBookingServiceAnswer->getAnswer());
  1782.                     $booking->addField($field);
  1783.                 }
  1784.                 if ($customer_billing_location != null) {
  1785.                     $customer_billing_location->setKeepChanges(true);
  1786.                     $this->entityManager->persist($customer_billing_location);
  1787.                 }
  1788.                 if ($customer_billing != null) {
  1789.                     $this->entityManager->persist($customer_billing);
  1790.                 }
  1791.                 if ($customer_location != null) {
  1792.                     $customer_location->setKeepChanges(true);
  1793.                     $this->entityManager->persist($customer_location);
  1794.                 }
  1795.                 if ($customer != null) {
  1796.                     $this->entityManager->persist($customer);
  1797.                 }
  1798.                 if ($location != null) {
  1799.                     $this->entityManager->persist($location);
  1800.                 }
  1801.                 if ($booking != null) {
  1802.                     $this->entityManager->persist($booking);
  1803.                 }
  1804.                 $bookingProcess->setMaterialBooking($booking);
  1805.                 $this->entityManager->persist($bookingProcess);
  1806.                 $this->entityManager->flush();
  1807.                 $this->radiusUpdater->setEntityManager($this->entityManager);
  1808.                 $this->radiusUpdater->updateRadius($bookingnull$booking->getCrew());
  1809.                 if ($this->getUser() == null) {
  1810.                     $customerMailer $this->confirmationMailer;
  1811.                     try {
  1812.                         $customerMailer->send($booking);
  1813.                     } catch (TransportException $e) {
  1814.                         //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  1815.                         //$result = self::FAILED_TO_SEND_EMAIL;
  1816.                     }
  1817.                     try {
  1818.                         $customerMailer->sendSMS($booking);
  1819.                     } catch (\Throwable $e) {
  1820.                         //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  1821.                         //$result = self::FAILED_TO_SEND_EMAIL;
  1822.                     }
  1823.                 }
  1824.                 $companyMailer $this->notificationMailer;
  1825.                 try {
  1826.                     $companyMailer->send($booking);
  1827.                 } catch (TransportException $e) {
  1828.                     //$this->emailErrors[] = 'Failed to send an email notification to the company. It seems that there is some issue with this compny email address. You may contact them by phone to make sure they received your request.';
  1829.                     //$result = self::FAILED_TO_SEND_EMAIL;
  1830.                 }
  1831.                 if ($booking->getCrew() != null) {
  1832.                     $dtu = clone ($booking->getDateStart());
  1833.                     $dtu->setTime(000);
  1834.                     $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($booking->getClient(), $booking->getCrew(), $dtu);
  1835.                 }
  1836.                 // FINAL TASKS
  1837.                 {
  1838.                     if (
  1839.                         $this->googleClient->setRedirectUrl(
  1840.                             $this->getGoogleOauthRedirectUrl()
  1841.                         )->authenticate($request->getUri())
  1842.                     ) {
  1843.                         try {
  1844.                             $this->googleCalendarModel->setGoogleModels(
  1845.                                 new \Google_Service_Calendar($this->googleClient->getClient()),
  1846.                                 $this->getWatchGoogleChannelParams($this->client)
  1847.                             );
  1848.                             $this->addOrUpdateGoogleEvent(
  1849.                                 $request,
  1850.                                 $this->googleClient,
  1851.                                 $this->googleCalendarModel,
  1852.                                 $booking
  1853.                             );
  1854.                         } catch (\Google\Service\Exception $ex) {
  1855.                         }
  1856.                     }
  1857.                     $crew $booking->getCrew();
  1858.                     if ($crew) {
  1859.                         $workers $this->workerEnityModel->findByCrew($crew);
  1860.                         foreach ($workers as $worker) {
  1861.                             $workerEmail $worker->getUser()->getEmail();
  1862.                             if ($worker->isNotify()) {
  1863.                                 try {
  1864.                                     $this->googleCalendarNotificationMailer->send(
  1865.                                         $booking,
  1866.                                         $worker
  1867.                                     );
  1868.                                 } catch (TransportException $e) {
  1869.                                     error_log(__FILE__ ': ' __LINE__ ': ignored email error ');
  1870.                                 }
  1871.                             }
  1872.                         }
  1873.                     }
  1874.                 }
  1875.                 $_rwg_token $request->cookies->get('_rwg_token');
  1876.                 if ($_rwg_token != null) {
  1877.                     $gmbeurls = [
  1878.                         'production' => 'https://www.google.com/maps/conversion/collect',
  1879.                         'sandbox' => 'https://www.google.com/maps/conversion/debug/collect'
  1880.                     ];
  1881.                     $gmbeaccid '20001772';
  1882.                     try {
  1883.                         $response $this->httpClient->request(
  1884.                             'POST',
  1885.                             $gmbeurls['production'],
  1886.                             [
  1887.                                 'headers' => [
  1888.                                     'Content-Type' => 'application/json'
  1889.                                 ],
  1890.                                 'body' => json_encode([
  1891.                                     'conversion_partner_id' => $gmbeaccid,
  1892.                                     'rwg_token' => $_rwg_token,
  1893.                                     'merchant_changed' => 2
  1894.                                 ])
  1895.                             ]
  1896.                         );
  1897.                     } catch (\Throwable $e) {
  1898.                         // NOTHING
  1899.                     }
  1900.                 }
  1901.                 //$this->webhookService->setClient(1320);
  1902.                 try {
  1903.                     $this->webhookService->__trigger_event_create_booking($booking);
  1904.                 } catch (\Throwable $throwable) {
  1905.                     // NOTHING
  1906.                     if ($this->client !== null && $this->client->getEnvType() !== 'production') {
  1907.                         dd([
  1908.                             'message' => $throwable->getMessage(),
  1909.                             'file' => $throwable->getFile(),
  1910.                             'line' => $throwable->getLine(),
  1911.                             'trace' => $throwable->getTrace()
  1912.                         ]);
  1913.                     }
  1914.                 }
  1915.                 return true;
  1916.             }
  1917.                 break;
  1918.             case "edit": {
  1919.                 $bookingProcessBooking $bookingProcess->getBooking();
  1920.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  1921.                 $bookingProcessCustomer $bookingProcessBooking->getCustomer();
  1922.                 $bookingProcessCustomerLocation $bookingProcessCustomer->getLocation();
  1923.                 $booking $bookingProcess->getMaterialBooking();
  1924.                 if ($booking == null) {
  1925.                     $booking = new Booking();
  1926.                 }
  1927.                 $previousCrew $booking->getCrew();
  1928.                 $previousDateStart $booking->getDateStart();
  1929.                 $previousDateEnd $booking->getDateEnd();
  1930.                 $crew $booking->getCrew();
  1931.                 $customer null;
  1932.                 $isnewcustomer false;
  1933.                 $customer_mode_find $this->client->getPropertyValue('booking.customer.mode.find');
  1934.                 if (!empty($customer_mode_find) && in_array($customer_mode_find, ['true''1'])) {
  1935.                     $customer $this->customerRepository->findLastCustomerEmail($bookingProcessCustomer->getEmail());
  1936.                     if ($customer === null) {
  1937.                         $customer = new Customer();
  1938.                         $isnewcustomer true;
  1939.                     }
  1940.                 } else {
  1941.                     $customer = new Customer();
  1942.                     $isnewcustomer true;
  1943.                 }
  1944.                 $customer_location null;
  1945.                 if ($isnewcustomer || $customer->getLocation() === null) {
  1946.                     $customer_location = new Location();
  1947.                 } else {
  1948.                     $customer_location $customer->getLocation();
  1949.                 }
  1950.                 $customer_location->setStreet($bookingProcessCustomerLocation->getStreet());
  1951.                 $customer_location->setCity($bookingProcessCustomerLocation->getCity());
  1952.                 $customer_location->setProvince($bookingProcessCustomerLocation->getProvince());
  1953.                 $customer_location->setCountry($bookingProcessCustomerLocation->getCountry());
  1954.                 $customer_location->setLatitude($bookingProcessCustomerLocation->getLatitude());
  1955.                 $customer_location->setLongitude($bookingProcessCustomerLocation->getLongitude());
  1956.                 $customer_location->setLine2($bookingProcessCustomerLocation->getLine2());
  1957.                 $customer_location->setCode($bookingProcessCustomerLocation->getCode());
  1958.                 $customer_billing_location null;
  1959.                 $customer_billing null;
  1960.                 $bookingProcessBookingCustomerBilling $bookingProcessCustomer->getBilling();
  1961.                 if ($bookingProcessBookingCustomerBilling != null) {
  1962.                     $bookingProcessBookingCustomerBillingLocation $bookingProcessBookingCustomerBilling->getLocation();
  1963.                     if ($bookingProcessBookingCustomerBillingLocation != null) {
  1964.                         $customer_billing_location $isnewcustomer || $customer->getBilling() === null ? new Location() : $customer->getBilling()->getLocation();
  1965.                         $customer_billing_location->setStreet($bookingProcessBookingCustomerBillingLocation->getStreet());
  1966.                         $customer_billing_location->setCity($bookingProcessBookingCustomerBillingLocation->getCity());
  1967.                         $customer_billing_location->setProvince($bookingProcessBookingCustomerBillingLocation->getProvince());
  1968.                         $customer_billing_location->setCountry($bookingProcessBookingCustomerBillingLocation->getCountry());
  1969.                         $customer_billing_location->setLatitude($bookingProcessBookingCustomerBillingLocation->getLatitude());
  1970.                         $customer_billing_location->setLongitude($bookingProcessBookingCustomerBillingLocation->getLongitude());
  1971.                         $customer_billing_location->setLine2($bookingProcessBookingCustomerBillingLocation->getLine2());
  1972.                         $customer_billing_location->setCode($bookingProcessBookingCustomerBillingLocation->getCode());
  1973.                     }
  1974.                     $customer_billing $isnewcustomer || $customer->getBilling() === null ? new CustomerBilling() : $customer->getBilling();
  1975.                     $customer_billing->setLocation($customer_billing_location);
  1976.                     $customer_billing->setName($bookingProcessBookingCustomerBilling->getName());
  1977.                     $customer_billing->setEmail($bookingProcessBookingCustomerBilling->getEmail());
  1978.                     $customer_billing->setPhone($bookingProcessBookingCustomerBilling->getPhone());
  1979.                     $customer_billing->setPhoneCanonical($bookingProcessBookingCustomerBilling->getPhoneCanonical());
  1980.                 }
  1981.                 $customer->setLocation($customer_location);
  1982.                 if ($customer_billing != null) {
  1983.                     $customer->setBilling($customer_billing);
  1984.                 }
  1985.                 $customer->setEmail($bookingProcessCustomer->getEmail());
  1986.                 $customer->setName($bookingProcessCustomer->getName());
  1987.                 $customer->setPhone($bookingProcessCustomer->getPhone());
  1988.                 $customer->setPhoneCanonical($bookingProcessCustomer->getPhoneCanonical());
  1989.                 $customer->setClient($bookingProcessCustomer->getClient());
  1990.                 $customer->setDeleted($bookingProcessCustomer->getDeleted());
  1991.                 $customer->setPhoneDescription($bookingProcessCustomer->getPhoneDescription());
  1992.                 $location = new Location();
  1993.                 $location->setStreet($bookingProcessLocation->getStreet());
  1994.                 $location->setCity($bookingProcessLocation->getCity());
  1995.                 $location->setProvince($bookingProcessLocation->getProvince());
  1996.                 $location->setCountry($bookingProcessLocation->getCountry());
  1997.                 $location->setLatitude($bookingProcessLocation->getLatitude());
  1998.                 $location->setLongitude($bookingProcessLocation->getLongitude());
  1999.                 $location->setLine2($bookingProcessLocation->getLine2());
  2000.                 $location->setCode($bookingProcessLocation->getCode());
  2001.                 $booking->setScope('cm_mvp1');
  2002.                 $booking->setClient($bookingProcessBooking->getClient());
  2003.                 $booking->setCustomer($customer);
  2004.                 $booking->setService($bookingProcessBooking->getService());
  2005.                 $booking->setLocation($location);
  2006.                 $booking->setServiceType($bookingProcessBooking->getServiceType());
  2007.                 $booking->setSelectedRegion($bookingProcessBooking->getSelectedRegion());
  2008.                 $booking->setCrew($bookingProcessBooking->getCrew());
  2009.                 //$booking->setRadius($bookingProcessBooking->getRadius());
  2010.                 $booking->setDateStart($bookingProcessBooking->getDateStart());
  2011.                 $booking->setDateEnd($bookingProcessBooking->getDateEnd());
  2012.                 $booking->setScheduleType($bookingProcessBooking->getScheduleType());
  2013.                 $booking->setScheduleStatus($bookingProcessBooking->getScheduleStatus());
  2014.                 $booking->setStatus(BookingStatus::STATUS_ASSIGNED);
  2015.                 $booking->setAdditionalInformation($bookingProcessBooking->getAdditionalInformation());
  2016.                 $booking->setNotes($bookingProcessBooking->getNotes());
  2017.                 //$booking->setDatePosted(clone $now);
  2018.                 $booking->setDateUpdated(clone $now);
  2019.                 //$booking->setUser(null);
  2020.                 $booking->setAdditionalMinutes($bookingProcessBooking->getAdditionalMinutes());
  2021.                 $bookingProcessBookingRegions $bookingProcessBooking->getRegions();
  2022.                 $booking->getRegions()->clear();
  2023.                 foreach ($bookingProcessBookingRegions as $bookingProcessBookingRegion) {
  2024.                     $booking->addRegion($bookingProcessBookingRegion);
  2025.                 }
  2026.                 $bookingProcessBookingServiceAnswers $bookingProcessBooking->getBookingProcessBookingServiceAnswers();
  2027.                 foreach ($bookingProcessBookingServiceAnswers as $bookingProcessBookingServiceAnswer) {
  2028.                     $field = new BookingServiceField();
  2029.                     $field->setBooking($booking);
  2030.                     $field->setField($bookingProcessBookingServiceAnswer->getField());
  2031.                     $field->setSlug($bookingProcessBookingServiceAnswer->getSlug());
  2032.                     $field->setAnswer($bookingProcessBookingServiceAnswer->getAnswer());
  2033.                     $booking->addField($field);
  2034.                 }
  2035.                 if ($customer_billing_location != null) {
  2036.                     $customer_billing_location->setKeepChanges(true);
  2037.                     $this->entityManager->persist($customer_billing_location);
  2038.                 }
  2039.                 if ($customer_billing != null) {
  2040.                     $this->entityManager->persist($customer_billing);
  2041.                 }
  2042.                 if ($customer_location != null) {
  2043.                     $customer_location->setKeepChanges(true);
  2044.                     $this->entityManager->persist($customer_location);
  2045.                 }
  2046.                 if ($customer != null) {
  2047.                     $this->entityManager->persist($customer);
  2048.                 }
  2049.                 if ($location != null) {
  2050.                     $this->entityManager->persist($location);
  2051.                 }
  2052.                 if ($booking != null) {
  2053.                     $this->entityManager->persist($booking);
  2054.                 }
  2055.                 $bookingProcess->setMaterialBooking($booking);
  2056.                 $this->entityManager->persist($bookingProcess);
  2057.                 $this->entityManager->flush();
  2058.                 $this->radiusUpdater->setEntityManager($this->entityManager);
  2059.                 $this->radiusUpdater->updateRadius($booking$crew$booking->getCrew());
  2060.                 $customerMailer $this->changeMailer;
  2061.                 try {
  2062.                     $customerMailer->send($booking);
  2063.                 } catch (TransportException $e) {
  2064.                     //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  2065.                     //$result = self::FAILED_TO_SEND_EMAIL;
  2066.                 }
  2067.                 try {
  2068.                     $customerMailer->sendSMS($booking);
  2069.                 } catch (\Throwable $e) {
  2070.                     //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  2071.                     //$result = self::FAILED_TO_SEND_EMAIL;
  2072.                 }
  2073.                 $companyMailer $this->notificationMailer;
  2074.                 try {
  2075.                     $companyMailer->send($booking);
  2076.                 } catch (TransportException $e) {
  2077.                     //$this->emailErrors[] = 'Failed to send an email notification to the company. It seems that there is some issue with this compny email address. You may contact them by phone to make sure they received your request.';
  2078.                     //$result = self::FAILED_TO_SEND_EMAIL;
  2079.                 }
  2080.                 if ($previousCrew != null && $previousDateStart != null && $previousDateEnd != null) {
  2081.                     $dtup = clone ($previousDateStart);
  2082.                     $dtup->setTime(000);
  2083.                     $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($booking->getClient(), $previousCrew$dtup);
  2084.                 }
  2085.                 if ($booking->getCrew() != null) {
  2086.                     $dtu = clone ($booking->getDateStart());
  2087.                     $dtu->setTime(000);
  2088.                     $this->scheduleAvailabilityCMMVP1Service->buildScheduleAvailability($booking->getClient(), $booking->getCrew(), $dtu);
  2089.                 }
  2090.                 // FINAL TASKS
  2091.                 {
  2092.                     if (
  2093.                         $this->googleClient->setRedirectUrl(
  2094.                             $this->getGoogleOauthRedirectUrl()
  2095.                         )->authenticate($request->getUri())
  2096.                     ) {
  2097.                         try {
  2098.                             $this->googleCalendarModel->setGoogleModels(
  2099.                                 new \Google_Service_Calendar($this->googleClient->getClient()),
  2100.                                 $this->getWatchGoogleChannelParams($this->client)
  2101.                             );
  2102.                             $this->addOrUpdateGoogleEvent(
  2103.                                 $request,
  2104.                                 $this->googleClient,
  2105.                                 $this->googleCalendarModel,
  2106.                                 $booking
  2107.                             );
  2108.                             if ($previousCrew) {
  2109.                                 $this->googleCalendarModel->removeBookingEventFromCrew(
  2110.                                     $booking,
  2111.                                     $previousCrew
  2112.                                 );
  2113.                             }
  2114.                         } catch (\Google\Service\Exception $ex) {
  2115.                         }
  2116.                     }
  2117.                     $crew $booking->getCrew();
  2118.                     if ($crew) {
  2119.                         $workers $this->workerEnityModel->findByCrew($crew);
  2120.                         foreach ($workers as $worker) {
  2121.                             $workerEmail $worker->getUser()->getEmail();
  2122.                             if ($worker->isNotify()) {
  2123.                                 try {
  2124.                                     $this->googleCalendarNotificationMailer->send(
  2125.                                         $booking,
  2126.                                         $worker
  2127.                                     );
  2128.                                 } catch (TransportException $e) {
  2129.                                     error_log(__FILE__ ': ' __LINE__ ': ignored email error ');
  2130.                                 }
  2131.                             }
  2132.                         }
  2133.                     }
  2134.                 }
  2135.                 if ($previousDateStart !== null && $previousDateEnd && $booking->getDateStart() !== null && $booking->getDateEnd() !== null && ($previousDateStart !== $booking->getDateStart() || $previousDateEnd !== $booking->getDateEnd())) {
  2136.                     try {
  2137.                         $this->webhookService->__trigger_event_reschedule_booking($booking);
  2138.                     } catch (\Throwable $throwable) {
  2139.                         // NOTHING
  2140.                     }
  2141.                 }
  2142.                 try {
  2143.                     $this->webhookService->__trigger_event_update_booking($booking);
  2144.                 } catch (\Throwable $throwable) {
  2145.                     // NOTHING
  2146.                 }
  2147.                 return true;
  2148.             }
  2149.                 break;
  2150.         }
  2151.     }
  2152.     public function doStepCommitConfirm($request$bookingProcess)
  2153.     {
  2154.         $now = new \DateTime();
  2155.         $bookingProcess->setStatus('commit-confirm');
  2156.         $bookingProcess->setUpdatedAt($now);
  2157.         $bookingProcess->setIpAddress($this->request->getClientIp());
  2158.         $this->entityManager->persist($bookingProcess);
  2159.         $this->entityManager->flush();
  2160.         return true;
  2161.     }
  2162.     public function doStepComplete($request$bookingProcess)
  2163.     {
  2164.         $now = new \DateTime();
  2165.         $bookingProcess->setStatus('complete');
  2166.         $bookingProcess->setUpdatedAt($now);
  2167.         $bookingProcess->setIpAddress($this->request->getClientIp());
  2168.         $this->entityManager->persist($bookingProcess);
  2169.         $this->entityManager->flush();
  2170.         return true;
  2171.     }
  2172.     private function doStepRedirectionPOST($request$bookingProcess)
  2173.     {
  2174.         $go $request->request->get('go');
  2175.         $now = new \DateTime();
  2176.         $embedded_status $request->request->get('embedded-status');
  2177.         if ($embedded_status != null) {
  2178.             $bookingProcess->setEmbeddedStatus($embedded_status);
  2179.         }
  2180.         $show_header $request->request->get('show-header');
  2181.         if ($show_header != null) {
  2182.             $bookingProcess->setShowHeader($show_header);
  2183.         }
  2184.         $this->entityManager->persist($bookingProcess);
  2185.         $this->entityManager->flush();
  2186.         switch ($bookingProcess->getScreen()) {
  2187.             case 'input-location-callback': {
  2188.                 $b false;
  2189.                 try {
  2190.                     $b $this->doStepInputLocationCallback($request$bookingProcess);
  2191.                     if (!$b) {
  2192.                         throw new \Exception("Unexpected error!");
  2193.                     }
  2194.                     $warningbody json_encode([
  2195.                         'code' => 0,
  2196.                         'message' => '',
  2197.                         'trace' => null
  2198.                     ]);
  2199.                     $bookingProcess->setWarningstatus(0);
  2200.                     $bookingProcess->setWarningbody($warningbody);
  2201.                     $bookingProcess->setUpdatedAt($now);
  2202.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2203.                     $this->entityManager->persist($bookingProcess);
  2204.                     $this->entityManager->flush();
  2205.                 } catch (\Throwable $throwable) {
  2206.                     throw $throwable;
  2207.                     $warningbody json_encode([
  2208.                         'code' => $throwable->getCode(),
  2209.                         'line' => $throwable->getLine(),
  2210.                         'file' => $throwable->getFile(),
  2211.                         'message' => $throwable->getMessage(),
  2212.                         'trace' => $throwable->getTrace()
  2213.                     ]);
  2214.                     $bookingProcess->setWarningstatus(1);
  2215.                     $bookingProcess->setWarningbody($warningbody);
  2216.                     $bookingProcess->setUpdatedAt($now);
  2217.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2218.                     $this->entityManager->persist($bookingProcess);
  2219.                     $this->entityManager->flush();
  2220.                 }
  2221.                 switch ($go) {
  2222.                     case 'previous':
  2223.                     case 'back';
  2224.                         $this->setGoToScreenOnBookingProcess($bookingProcess'input-location');
  2225.                         return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2226.                         break;
  2227.                     case 'next':
  2228.                     default:
  2229.                         if ($b) {
  2230.                             $this->setGoToScreenOnBookingProcess($bookingProcess'complete-callback');
  2231.                             return $this->redirect($this->generateUrl($this->screensmap['complete-callback']));
  2232.                         }
  2233.                         break;
  2234.                 }
  2235.                 return $this->redirect($this->generateUrl($this->screensmap['input-location-callback']));
  2236.             }
  2237.                 break;
  2238.             case 'input-location': {
  2239.                 $b false;
  2240.                 try {
  2241.                     $b $this->doStepInputLocation($request$bookingProcess);
  2242.                     if (!$b) {
  2243.                         throw new \Exception("Unexpected error!");
  2244.                     }
  2245.                     $warningbody json_encode([
  2246.                         'code' => 0,
  2247.                         'message' => '',
  2248.                         'trace' => null
  2249.                     ]);
  2250.                     $bookingProcess->setWarningstatus(0);
  2251.                     $bookingProcess->setWarningbody($warningbody);
  2252.                     $bookingProcess->setUpdatedAt($now);
  2253.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2254.                     $this->entityManager->persist($bookingProcess);
  2255.                     $this->entityManager->flush();
  2256.                 } catch (\Throwable $throwable) {
  2257.                     $warningbody json_encode([
  2258.                         'code' => $throwable->getCode(),
  2259.                         'line' => $throwable->getLine(),
  2260.                         'file' => $throwable->getFile(),
  2261.                         'message' => $throwable->getMessage(),
  2262.                         'trace' => $throwable->getTrace()
  2263.                     ]);
  2264.                     $bookingProcess->setWarningstatus(1);
  2265.                     $bookingProcess->setWarningbody($warningbody);
  2266.                     $bookingProcess->setUpdatedAt($now);
  2267.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2268.                     $this->entityManager->persist($bookingProcess);
  2269.                     $this->entityManager->flush();
  2270.                 }
  2271.                 switch ($go) {
  2272.                     case 'previous':
  2273.                     case 'back';
  2274.                         $this->setGoToScreenOnBookingProcess($bookingProcess'input-location');
  2275.                         return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2276.                         break;
  2277.                     case 'next':
  2278.                     default:
  2279.                         if ($b) {
  2280.                             if ($request->request->get('type') == 'fixed') {
  2281.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-service');
  2282.                                 return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  2283.                             } else {
  2284.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-confirmlocation');
  2285.                                 return $this->redirect($this->generateUrl($this->screensmap['input-confirmlocation']));
  2286.                             }
  2287.                         }
  2288.                         break;
  2289.                 }
  2290.                 return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2291.             }
  2292.                 break;
  2293.             case 'input-confirmlocation': {
  2294.                 $b false;
  2295.                 try {
  2296.                     $b $this->doStepInputConfirmLocation($request$bookingProcess);
  2297.                     if (!$b) {
  2298.                         throw new \Exception("Unexpected error!");
  2299.                     }
  2300.                     $warningbody json_encode([
  2301.                         'code' => 0,
  2302.                         'message' => '',
  2303.                         'trace' => null
  2304.                     ]);
  2305.                     $bookingProcess->setWarningstatus(0);
  2306.                     $bookingProcess->setWarningbody($warningbody);
  2307.                     $bookingProcess->setUpdatedAt($now);
  2308.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2309.                     $this->entityManager->persist($bookingProcess);
  2310.                     $this->entityManager->flush();
  2311.                 } catch (\Throwable $throwable) {
  2312.                     $warningbody json_encode([
  2313.                         'code' => $throwable->getCode(),
  2314.                         'line' => $throwable->getLine(),
  2315.                         'file' => $throwable->getFile(),
  2316.                         'message' => $throwable->getMessage(),
  2317.                         'trace' => $throwable->getTrace()
  2318.                     ]);
  2319.                     $bookingProcess->setWarningstatus(1);
  2320.                     $bookingProcess->setWarningbody($warningbody);
  2321.                     $bookingProcess->setUpdatedAt($now);
  2322.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2323.                     $this->entityManager->persist($bookingProcess);
  2324.                     $this->entityManager->flush();
  2325.                 }
  2326.                 switch ($go) {
  2327.                     case 'previous':
  2328.                     case 'back';
  2329.                         $this->setGoToScreenOnBookingProcess($bookingProcess'input-location');
  2330.                         return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2331.                         break;
  2332.                     case 'next':
  2333.                     default:
  2334.                         if ($b) {
  2335.                             if ($bookingProcess->getAllowedServices()) {
  2336.                                 $arrayAllowedServices explode(','str_replace(', '','$bookingProcess->getAllowedServices()));
  2337.                                 if (count($arrayAllowedServices) == 1) {
  2338.                                     $b $this->doStepInputService($request$bookingProcesscurrent($arrayAllowedServices));
  2339.                                     if (!$b) {
  2340.                                         throw new \Exception("Unexpected error!");
  2341.                                     }
  2342.                                     return $this->verifyServiceFieldsNext($bookingProcess);
  2343.                                 }
  2344.                             }
  2345.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-service');
  2346.                             return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  2347.                         }
  2348.                         break;
  2349.                 }
  2350.                 return $this->redirect($this->generateUrl($this->screensmap['input-confirmlocation']));
  2351.             }
  2352.                 break;
  2353.             case 'input-service': {
  2354.                 $b false;
  2355.                 try {
  2356.                     $b $this->doStepInputService($request$bookingProcess);
  2357.                     if (!$b) {
  2358.                         throw new \Exception("Unexpected error!");
  2359.                     }
  2360.                     $warningbody json_encode([
  2361.                         'code' => 0,
  2362.                         'message' => '',
  2363.                         'trace' => null
  2364.                     ]);
  2365.                     $bookingProcess->setWarningstatus(0);
  2366.                     $bookingProcess->setWarningbody($warningbody);
  2367.                     $bookingProcess->setUpdatedAt($now);
  2368.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2369.                     $this->entityManager->persist($bookingProcess);
  2370.                     $this->entityManager->flush();
  2371.                 } catch (\Throwable $throwable) {
  2372.                     $warningbody json_encode([
  2373.                         'code' => $throwable->getCode(),
  2374.                         'line' => $throwable->getLine(),
  2375.                         'file' => $throwable->getFile(),
  2376.                         'message' => $throwable->getMessage(),
  2377.                         'trace' => $throwable->getTrace()
  2378.                     ]);
  2379.                     $bookingProcess->setWarningstatus(1);
  2380.                     $bookingProcess->setWarningbody($warningbody);
  2381.                     $bookingProcess->setUpdatedAt($now);
  2382.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2383.                     $this->entityManager->persist($bookingProcess);
  2384.                     $this->entityManager->flush();
  2385.                 }
  2386.                 if ($b) {
  2387.                     switch ($go) {
  2388.                         case 'previous':
  2389.                         case 'back';
  2390.                             if ($bookingProcess->getBooking()->getServiceType() == 'fixed') {
  2391.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-location');
  2392.                                 return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2393.                             } else {
  2394.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-location');
  2395.                                 return $this->redirect($this->generateUrl($this->screensmap['input-confirmlocation']));
  2396.                             }
  2397.                             break;
  2398.                         case 'next':
  2399.                         default:
  2400.                             $allfields $bookingProcess->getBooking()->getService()->getFields();
  2401.                             $fields = [];
  2402.                             foreach ($allfields as $field) {
  2403.                                 if ($field->getIsActive() && $field->getQuestion() != null && $field->getQuestion() != '') {
  2404.                                     $fields[] = $field;
  2405.                                 }
  2406.                             }
  2407.                             if (count($fields) > 0) {
  2408.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-servicefields');
  2409.                                 return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  2410.                             } else {
  2411.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-datetime');
  2412.                                 return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  2413.                             }
  2414.                             break;
  2415.                     }
  2416.                 }
  2417.                 return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  2418.             }
  2419.                 break;
  2420.             case 'input-servicefields': {
  2421.                 $b false;
  2422.                 try {
  2423.                     $b $this->doStepInputServiceFields($request$bookingProcess);
  2424.                     if (!$b) {
  2425.                         throw new \Exception("Unexpected error!");
  2426.                     }
  2427.                     $warningbody json_encode([
  2428.                         'code' => 0,
  2429.                         'message' => '',
  2430.                         'trace' => null
  2431.                     ]);
  2432.                     $bookingProcess->setWarningstatus(0);
  2433.                     $bookingProcess->setWarningbody($warningbody);
  2434.                     $bookingProcess->setUpdatedAt($now);
  2435.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2436.                     $this->entityManager->persist($bookingProcess);
  2437.                     $this->entityManager->flush();
  2438.                 } catch (\Throwable $throwable) {
  2439.                     $warningbody json_encode([
  2440.                         'code' => $throwable->getCode(),
  2441.                         'line' => $throwable->getLine(),
  2442.                         'file' => $throwable->getFile(),
  2443.                         'message' => $throwable->getMessage(),
  2444.                         'trace' => $throwable->getTrace()
  2445.                     ]);
  2446.                     $bookingProcess->setWarningstatus(1);
  2447.                     $bookingProcess->setWarningbody($warningbody);
  2448.                     $bookingProcess->setUpdatedAt($now);
  2449.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2450.                     $this->entityManager->persist($bookingProcess);
  2451.                     $this->entityManager->flush();
  2452.                 }
  2453.                 if ($b) {
  2454.                     switch ($go) {
  2455.                         case 'previous':
  2456.                         case 'back';
  2457.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-service');
  2458.                             return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  2459.                             break;
  2460.                         case 'next':
  2461.                         default:
  2462.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-datetime');
  2463.                             return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  2464.                             break;
  2465.                     }
  2466.                 }
  2467.                 return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  2468.             }
  2469.                 break;
  2470.             case 'input-schedule-type': {
  2471.                 $b false;
  2472.                 try {
  2473.                     $b $this->doStepInputScheduleType($request$bookingProcess);
  2474.                     if (!$b) {
  2475.                         throw new \Exception("Unexpected error!");
  2476.                     }
  2477.                     $warningbody json_encode([
  2478.                         'code' => 0,
  2479.                         'message' => '',
  2480.                         'trace' => null
  2481.                     ]);
  2482.                     $bookingProcess->setWarningstatus(0);
  2483.                     $bookingProcess->setWarningbody($warningbody);
  2484.                     $bookingProcess->setUpdatedAt($now);
  2485.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2486.                     $this->entityManager->persist($bookingProcess);
  2487.                     $this->entityManager->flush();
  2488.                 } catch (\Throwable $throwable) {
  2489.                     $warningbody json_encode([
  2490.                         'code' => $throwable->getCode(),
  2491.                         'line' => $throwable->getLine(),
  2492.                         'file' => $throwable->getFile(),
  2493.                         'message' => $throwable->getMessage(),
  2494.                         'trace' => $throwable->getTrace()
  2495.                     ]);
  2496.                     $bookingProcess->setWarningstatus(1);
  2497.                     $bookingProcess->setWarningbody($warningbody);
  2498.                     $bookingProcess->setUpdatedAt($now);
  2499.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2500.                     $this->entityManager->persist($bookingProcess);
  2501.                     $this->entityManager->flush();
  2502.                 }
  2503.                 if ($b) {
  2504.                     switch ($go) {
  2505.                         case 'previous':
  2506.                         case 'back';
  2507.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-servicefields');
  2508.                             return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  2509.                             break;
  2510.                         case 'next':
  2511.                         default:
  2512.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-datetime');
  2513.                             return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  2514.                             break;
  2515.                     }
  2516.                 }
  2517.                 return $this->redirect($this->generateUrl($this->screensmap['input-schedule-type']));
  2518.             }
  2519.                 break;
  2520.             case 'input-datetime': {
  2521.                 $b false;
  2522.                 try {
  2523.                     $b $this->doStepInputDateTime($request$bookingProcess);
  2524.                     if (!$b) {
  2525.                         throw new \Exception("Unexpected error!");
  2526.                     }
  2527.                     $warningbody json_encode([
  2528.                         'code' => 0,
  2529.                         'message' => '',
  2530.                         'trace' => null
  2531.                     ]);
  2532.                     $bookingProcess->setWarningstatus(0);
  2533.                     $bookingProcess->setWarningbody($warningbody);
  2534.                     $bookingProcess->setUpdatedAt($now);
  2535.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2536.                     $this->entityManager->persist($bookingProcess);
  2537.                     $this->entityManager->flush();
  2538.                 } catch (\Throwable $throwable) {
  2539.                     $warningbody json_encode([
  2540.                         'code' => $throwable->getCode(),
  2541.                         'line' => $throwable->getLine(),
  2542.                         'file' => $throwable->getFile(),
  2543.                         'message' => $throwable->getMessage(),
  2544.                         'trace' => $throwable->getTrace()
  2545.                     ]);
  2546.                     $bookingProcess->setWarningstatus(1);
  2547.                     $bookingProcess->setWarningbody($warningbody);
  2548.                     $bookingProcess->setUpdatedAt($now);
  2549.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2550.                     $this->entityManager->persist($bookingProcess);
  2551.                     $this->entityManager->flush();
  2552.                 }
  2553.                 if ($b) {
  2554.                     switch ($go) {
  2555.                         case 'previous':
  2556.                         case 'back';
  2557.                             $allfields $bookingProcess->getBooking()->getService()->getFields();
  2558.                             $fields = [];
  2559.                             foreach ($allfields as $field) {
  2560.                                 if ($field->getIsActive() && $field->getQuestion() != null && $field->getQuestion() != '') {
  2561.                                     $fields[] = $field;
  2562.                                 }
  2563.                             }
  2564.                             if (count($fields) > 0) {
  2565.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-servicefields');
  2566.                                 return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  2567.                             } else {
  2568.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-service');
  2569.                                 return $this->redirect($this->generateUrl($this->screensmap['input-service']));
  2570.                             }
  2571.                             break;
  2572.                         case 'next':
  2573.                         default:
  2574.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-contact');
  2575.                             return $this->redirect($this->generateUrl($this->screensmap['input-contact']));
  2576.                             break;
  2577.                     }
  2578.                 }
  2579.                 return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  2580.             }
  2581.                 break;
  2582.             case 'input-contact': {
  2583.                 $b false;
  2584.                 try {
  2585.                     $b $this->doStepInputContact($request$bookingProcess);
  2586.                     if (!$b) {
  2587.                         throw new \Exception("Unexpected error!");
  2588.                     }
  2589.                     $warningbody json_encode([
  2590.                         'code' => 0,
  2591.                         'message' => '',
  2592.                         'trace' => null
  2593.                     ]);
  2594.                     $bookingProcess->setWarningstatus(0);
  2595.                     $bookingProcess->setWarningbody($warningbody);
  2596.                     $bookingProcess->setUpdatedAt($now);
  2597.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2598.                     $this->entityManager->persist($bookingProcess);
  2599.                     $this->entityManager->flush();
  2600.                 } catch (\Throwable $throwable) {
  2601.                     $warningbody json_encode([
  2602.                         'code' => $throwable->getCode(),
  2603.                         'line' => $throwable->getLine(),
  2604.                         'file' => $throwable->getFile(),
  2605.                         'message' => $throwable->getMessage(),
  2606.                         'trace' => $throwable->getTrace()
  2607.                     ]);
  2608.                     $bookingProcess->setWarningstatus(1);
  2609.                     $bookingProcess->setWarningbody($warningbody);
  2610.                     $bookingProcess->setUpdatedAt($now);
  2611.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2612.                     $this->entityManager->persist($bookingProcess);
  2613.                     $this->entityManager->flush();
  2614.                 }
  2615.                 if ($b) {
  2616.                     switch ($go) {
  2617.                         case 'previous':
  2618.                         case 'back';
  2619.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-datetime');
  2620.                             return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  2621.                             break;
  2622.                         case 'next':
  2623.                         default:
  2624.                             $isBillingSame = ($request->request->get('customer-billing-same') != null);
  2625.                             if ($isBillingSame) {
  2626.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'commit');
  2627.                                 return $this->redirect($this->generateUrl($this->screensmap['commit']));
  2628.                             } else {
  2629.                                 $this->setGoToScreenOnBookingProcess($bookingProcess'input-billing');
  2630.                                 return $this->redirect($this->generateUrl($this->screensmap['input-billing']));
  2631.                             }
  2632.                             break;
  2633.                     }
  2634.                 }
  2635.                 return $this->redirect($this->generateUrl($this->screensmap['input-contact']));
  2636.             }
  2637.                 break;
  2638.             case 'input-billing': {
  2639.                 $b false;
  2640.                 try {
  2641.                     $b $this->doStepInputBilling($request$bookingProcess);
  2642.                     if (!$b) {
  2643.                         throw new \Exception("Unexpected error!");
  2644.                     }
  2645.                     $warningbody json_encode([
  2646.                         'code' => 0,
  2647.                         'message' => '',
  2648.                         'trace' => null
  2649.                     ]);
  2650.                     $bookingProcess->setWarningstatus(0);
  2651.                     $bookingProcess->setWarningbody($warningbody);
  2652.                     $bookingProcess->setUpdatedAt($now);
  2653.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2654.                     $this->entityManager->persist($bookingProcess);
  2655.                     $this->entityManager->flush();
  2656.                 } catch (\Throwable $throwable) {
  2657.                     $warningbody json_encode([
  2658.                         'code' => $throwable->getCode(),
  2659.                         'line' => $throwable->getLine(),
  2660.                         'file' => $throwable->getFile(),
  2661.                         'message' => $throwable->getMessage(),
  2662.                         'trace' => $throwable->getTrace()
  2663.                     ]);
  2664.                     $bookingProcess->setWarningstatus(1);
  2665.                     $bookingProcess->setWarningbody($warningbody);
  2666.                     $bookingProcess->setUpdatedAt($now);
  2667.                     $bookingProcess->setIpAddress($this->request->getClientIp());
  2668.                     $this->entityManager->persist($bookingProcess);
  2669.                     $this->entityManager->flush();
  2670.                 }
  2671.                 if ($b) {
  2672.                     switch ($go) {
  2673.                         case 'previous':
  2674.                         case 'back';
  2675.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-contact');
  2676.                             return $this->redirect($this->generateUrl($this->screensmap['input-contact']));
  2677.                             break;
  2678.                         case 'next':
  2679.                         default:
  2680.                             //$this->setGoToScreenOnBookingProcess($bookingProcess, 'commit');
  2681.                             //return $this->redirect($this->generateUrl($this->screensmap['commit']));
  2682.                             $this->setGoToScreenOnBookingProcess($bookingProcess'commit');
  2683.                             return $this->redirect($this->generateUrl($this->screensmap['commit']));
  2684.                             break;
  2685.                     }
  2686.                 }
  2687.                 return $this->redirect($this->generateUrl($this->screensmap['input-contact']));
  2688.             }
  2689.                 break;
  2690.             case 'complete': {
  2691.                 //$b = $this->doStepComplete($request, $bookingProcess);
  2692.                 $b true;
  2693.                 if ($b) {
  2694.                     switch ($go) {
  2695.                         case 'previous':
  2696.                         case 'back';
  2697.                             $this->setGoToScreenOnBookingProcess($bookingProcess'input-billing');
  2698.                             return $this->redirect($this->generateUrl($this->screensmap['input-billing']));
  2699.                             break;
  2700.                         case 'next':
  2701.                         default:
  2702.                             $this->setGoToScreenOnBookingProcess($bookingProcess'complete');
  2703.                             return $this->redirect($this->generateUrl($this->screensmap['complete']));
  2704.                             break;
  2705.                     }
  2706.                 }
  2707.                 return $this->redirect($this->generateUrl($this->screensmap['complete']));
  2708.             }
  2709.                 break;
  2710.             default: {
  2711.                 //return $this->step_company($request);
  2712.                 //return $this->forward('App\Controller\SignUpController::step_company', array());
  2713.                 return new Response(
  2714.                     'INVALID STEP',
  2715.                     Response::HTTP_OK,
  2716.                     ['content-type' => 'text/html']
  2717.                 );
  2718.             }
  2719.         }
  2720.     }
  2721.     /**
  2722.      * @Route("/booking/process/cm/mvp1/step", name="booking_process_cm_mvp1_step")
  2723.      */
  2724.     public function step(Request $request): Response
  2725.     {
  2726.         $bookingProcess $this->checkBookingProcess($request);
  2727.         if ($bookingProcess == null) {
  2728.             $response $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2729.             $this->unsetCookie($response);
  2730.             return $response;
  2731.         }
  2732.         $screen $request->request->get('screen');
  2733.         if ($screen != null) {
  2734.             $this->setGoToScreenOnBookingProcess($bookingProcess$screen);
  2735.         }
  2736.         if ($request->getMethod() == 'POST') {
  2737.             return $this->doStepRedirectionPOST($request$bookingProcess);
  2738.         } else {
  2739.             return $this->doStepRedirectionGET($request$bookingProcess);
  2740.         }
  2741.     }
  2742.     /**
  2743.      * @Route("/booking/process/cm/mvp1/iframe", name="booking_process_cm_mvp1_test_iframe")
  2744.      */
  2745.     public function test_iframe(Request $request): Response
  2746.     {
  2747.         $response $this->render('booking_process_cm_mvp1/test_iframe.html.twig', [
  2748.             'controller_name' => 'BookingProcessController',
  2749.             'client' => $this->client
  2750.         ]);
  2751.         return $response;
  2752.     }
  2753.     /**
  2754.      * @Route("/booking/process/cm/mvp1/safari-fix", name="booking_process_cm_mvp1_safari_fix")
  2755.      * @Route("/booking/process/safari-fix", name="booking_process_cm_mvp1_safari_fix_default", condition="(((context.getHost() not in %app.beta.clients%) and ('%booking_process.scope%' == 'cm_mvp1')) or ((context.getHost() in %app.beta.clients%) and ('%booking_process.beta.scope%' == 'cm_mvp1')))")
  2756.      */
  2757.     public function safari_fix(Request $request): Response
  2758.     {
  2759.         $setCookie false;
  2760.         $bookingProcess $this->checkBookingProcess($request);
  2761.         if ($bookingProcess == null) {
  2762.             $bookingProcess $this->generateBookingProcess($request);
  2763.             $setCookie true;
  2764.         }
  2765.         $sreferrer $request->query->get('sreferrer');
  2766.         if ($sreferrer == null) {
  2767.             $sreferrer $this->generateUrl('booking_process_cm_mvp1_step_input_location');
  2768.         }
  2769.         $response $this->redirect($sreferrer);
  2770.         if ($setCookie) {
  2771.             $this->setCookie($request$response$bookingProcess->getCode());
  2772.         }
  2773.         return $response;
  2774.     }
  2775.     protected function checkCanBook(Request $request)
  2776.     {
  2777.         $bookingsPercent $this->clientEntityModel->getBookingsPercent($this->client);
  2778.         if (
  2779.             $bookingsPercent >= 100 || $this->client->isExpired() ||
  2780.             $this->client->isCanceled() || $this->client->isBlocked()
  2781.         ) {
  2782.             // return $this->redirect(
  2783.             //     //$this->generateUrl('book_online_not_accepted')
  2784.             //     $this->client->getWebsite()
  2785.             // );
  2786.             return null;
  2787.         } else {
  2788.             return null;
  2789.         }
  2790.     }
  2791.     /**
  2792.      * @Route("/booking/process/cm/mvp1/step/input-location", name="booking_process_cm_mvp1_step_input_location")
  2793.      * @Route("/cm/mvp1", name="booking_process_cm_mvp1_step_input_location_alt")
  2794.      * @Route("/", name="booking_process_cm_mvp1_step_input_location_default", condition="(((context.getHost() not in %app.beta.clients%) and ('%booking_process.scope%' == 'cm_mvp1')) or ((context.getHost() in %app.beta.clients%) and ('%booking_process.beta.scope%' == 'cm_mvp1')))")
  2795.      */
  2796.     public function step_input_location(Request $requestContainerInterface $container): Response
  2797.     {
  2798.         $now = new \DateTime();
  2799.         //$tesresult = $this->salesForceI360AppointmentsService->findContactByExternalId('somevalue');
  2800.         //dd($tesresult);
  2801.         if (strpos($request->server->get('HTTP_HOST'), $container->getParameter('orc_saas.login.domain')) === 0) {
  2802.             return $this->forward('orc_saas.controller.login:loginAction');
  2803.         } else if (strpos($request->server->get('HTTP_HOST'), $container->getParameter('orc_saas.admin.domain')) === 0) {
  2804.             return new Response(
  2805.                 '<html><body>Welcome to the administration page!</body></html>'
  2806.             );
  2807.         }
  2808.         try {
  2809.             $this->getClient();
  2810.         } catch (NotFoundHttpException $e) {
  2811.             if (
  2812.                 $container->getParameter('marketing_subdomain') . '.' .
  2813.                 $container->getParameter('domain_name') == $request->server->get('HTTP_HOST')
  2814.             ) {
  2815.                 return $this->redirect($this->generateUrl('app_marketing_index'));
  2816.             } else {
  2817.                 throw $e;
  2818.             }
  2819.         } catch (\Exception $e) {
  2820.             dd(get_class($e));
  2821.         }
  2822.         $canBookResponse $this->checkCanBook($request);
  2823.         if ($canBookResponse != null) {
  2824.             return $canBookResponse;
  2825.         }
  2826.         $setCookie false;
  2827.         $cpo $this->assertBookingProcess($request);
  2828.         $bookingProcess $cpo['booking_process'];
  2829.         $setCookie $cpo['set_cookie'];
  2830.         $message $cpo['message'];
  2831.         if ($message != null and $message != '') {
  2832.             if (str_starts_with($message'__redirect: ')) {
  2833.                 $url substr($message12);
  2834.                 $this->doIncrementGmbClicks($request);
  2835.                 return $this->redirect($url);
  2836.             }
  2837.             $response null;
  2838.             if (str_starts_with($message'__inactive: ')) {
  2839.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  2840.                     'screen' => 'inactive',
  2841.                     'headersteps' => true,
  2842.                     'complete' => true,
  2843.                     'controller_name' => 'BookingProcessController',
  2844.                     'next' => '',
  2845.                     'client' => $this->client,
  2846.                     'bookingProcess' => null,
  2847.                     'displaywarning' => false,
  2848.                     'warningstatus' => 0,
  2849.                     'warningbody' => '',
  2850.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2851.                     'title' => '',
  2852.                     'message' => substr($cpo['message'], 12)
  2853.                 ]);
  2854.                 $this->doIncrementGmbClicks($request);
  2855.             } else {
  2856.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  2857.                     'screen' => 'message',
  2858.                     'headersteps' => true,
  2859.                     'complete' => false,
  2860.                     'controller_name' => 'BookingProcessController',
  2861.                     'next' => '',
  2862.                     'client' => $this->client,
  2863.                     'bookingProcess' => null,
  2864.                     'displaywarning' => false,
  2865.                     'warningstatus' => 0,
  2866.                     'warningbody' => '',
  2867.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2868.                     'title' => 'THERE WAS A PROBLEM',
  2869.                     'message' => $cpo['message']
  2870.                 ]);
  2871.             }
  2872.             if ($setCookie) {
  2873.                 $this->setCookie($request$response$bookingProcess->getCode());
  2874.             }
  2875.             return $response;
  2876.         }
  2877.         $o $this->redirectOnInvalidStep($request$bookingProcess'input-location');
  2878.         if ($o != null) {
  2879.             return $o;
  2880.         } else {
  2881.             $bookingProcess->setScreen('input-location');
  2882.             $bookingProcess->setUpdatedAt($now);
  2883.             $bookingProcess->setIpAddress($this->request->getClientIp());
  2884.             $this->entityManager->persist($bookingProcess);
  2885.             $this->entityManager->flush();
  2886.         }
  2887.         $warningbody = ($bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null);
  2888.         $response $this->render('booking_process_cm_mvp1/step_input_location.html.twig', [
  2889.             'screen' => 'input-location',
  2890.             'headersteps' => true,
  2891.             'complete' => false,
  2892.             'controller_name' => 'BookingProcessController',
  2893.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2894.             'next' => $this->generateUrl($this->screensmap['input-confirmlocation']),
  2895.             'client' => $this->client,
  2896.             'regions' => $this->getRegionsGroupedByServiceType(),
  2897.             'rawRegions' => $this->regionRepository->findByClient($this->client),
  2898.             'bookingProcess' => $bookingProcess,
  2899.             'displaywarning' => $warningbody != null && $warningbody->message != 'Location is out of bounds!' true false,
  2900.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  2901.             'warningbody' => $warningbody,
  2902.             'ipStackInfo' => $this->ipStackInfo
  2903.         ]);
  2904.         if ($setCookie) {
  2905.             $this->setCookie($request$response$bookingProcess->getCode());
  2906.         }
  2907.         $this->addPreProcessHeaders($request$response$bookingProcess);
  2908.         return $response;
  2909.     }
  2910.     /**
  2911.      * @Route("/booking/process/cm/mvp1/step/input-location-callback", name="booking_process_cm_mvp1_step_input_location_callback")
  2912.      */
  2913.     public function step_input_location_callback(Request $request): Response
  2914.     {
  2915.         $now = new \DateTime();
  2916.         $canBookResponse $this->checkCanBook($request);
  2917.         if ($canBookResponse != null) {
  2918.             return $canBookResponse;
  2919.         }
  2920.         $cpo $this->assertBookingProcess($request);
  2921.         $bookingProcess $cpo['booking_process'];
  2922.         $setCookie $cpo['set_cookie'];
  2923.         $message $cpo['message'];
  2924.         if ($message != null and $message != '') {
  2925.             if (str_starts_with($message'__redirect: ')) {
  2926.                 $url substr($message12);
  2927.                 $this->doIncrementGmbClicks($request);
  2928.                 return $this->redirect($url);
  2929.             }
  2930.             $response null;
  2931.             if (str_starts_with($message'__inactive: ')) {
  2932.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  2933.                     'screen' => 'inactive',
  2934.                     'headersteps' => true,
  2935.                     'complete' => false,
  2936.                     'controller_name' => 'BookingProcessController',
  2937.                     'next' => '',
  2938.                     'client' => $this->client,
  2939.                     'bookingProcess' => null,
  2940.                     'displaywarning' => false,
  2941.                     'warningstatus' => 0,
  2942.                     'warningbody' => '',
  2943.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2944.                     'title' => '',
  2945.                     'message' => substr($cpo['message'], 12)
  2946.                 ]);
  2947.                 $this->doIncrementGmbClicks($request);
  2948.             } else {
  2949.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  2950.                     'screen' => 'message',
  2951.                     'headersteps' => true,
  2952.                     'complete' => false,
  2953.                     'controller_name' => 'BookingProcessController',
  2954.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2955.                     'next' => '',
  2956.                     'client' => $this->client,
  2957.                     'bookingProcess' => null,
  2958.                     'displaywarning' => false,
  2959.                     'warningstatus' => 0,
  2960.                     'warningbody' => '',
  2961.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2962.                     'title' => 'THERE WAS A PROBLEM',
  2963.                     'message' => $cpo['message']
  2964.                 ]);
  2965.             }
  2966.             if ($setCookie) {
  2967.                 $this->setCookie($request$response$bookingProcess->getCode());
  2968.             }
  2969.             return $response;
  2970.         }
  2971.         if ($bookingProcess == null) {
  2972.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  2973.         } else {
  2974.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-location-callback'$cpo['set_cookie']);
  2975.             if ($o != null) {
  2976.                 return $o;
  2977.             } else {
  2978.                 $bookingProcess->setScreen('input-location-callback');
  2979.                 $bookingProcess->setUpdatedAt($now);
  2980.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  2981.                 $this->entityManager->persist($bookingProcess);
  2982.                 $this->entityManager->flush();
  2983.             }
  2984.         }
  2985.         $response $this->render('booking_process_cm_mvp1/step_input_location_callback.html.twig', [
  2986.             'screen' => 'input-location-callback',
  2987.             'headersteps' => true,
  2988.             'complete' => false,
  2989.             'controller_name' => 'BookingProcessController',
  2990.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  2991.             'next' => $this->generateUrl($this->screensmap['input-confirmlocation']),
  2992.             'nextlabel' => 'REQUEST CALLBACK',
  2993.             'client' => $this->client,
  2994.             'bookingProcess' => $bookingProcess,
  2995.             'displaywarning' => false,
  2996.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  2997.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null,
  2998.             'ipStackInfo' => $this->ipStackInfo
  2999.         ]);
  3000.         if ($setCookie) {
  3001.             $this->setCookie($request$response$bookingProcess->getCode());
  3002.         }
  3003.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3004.         return $response;
  3005.     }
  3006.     /**
  3007.      * @Route("/booking/process/cm/mvp1/step/input-confirmlocation", name="booking_process_cm_mvp1_step_input_confirmlocation")
  3008.      */
  3009.     public function step_input_confirmlocation(Request $request): Response
  3010.     {
  3011.         $now = new \DateTime();
  3012.         $canBookResponse $this->checkCanBook($request);
  3013.         if ($canBookResponse != null) {
  3014.             return $canBookResponse;
  3015.         }
  3016.         $cpo $this->assertBookingProcess($request);
  3017.         $bookingProcess $cpo['booking_process'];
  3018.         $setCookie $cpo['set_cookie'];
  3019.         $message $cpo['message'];
  3020.         if ($message != null and $message != '') {
  3021.             if (str_starts_with($message'__redirect: ')) {
  3022.                 $url substr($message12);
  3023.                 $this->doIncrementGmbClicks($request);
  3024.                 return $this->redirect($url);
  3025.             }
  3026.             $response null;
  3027.             if (str_starts_with($message'__inactive: ')) {
  3028.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3029.                     'screen' => 'inactive',
  3030.                     'headersteps' => true,
  3031.                     'complete' => false,
  3032.                     'controller_name' => 'BookingProcessController',
  3033.                     'next' => '',
  3034.                     'client' => $this->client,
  3035.                     'bookingProcess' => null,
  3036.                     'displaywarning' => false,
  3037.                     'warningstatus' => 0,
  3038.                     'warningbody' => '',
  3039.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3040.                     'title' => '',
  3041.                     'message' => substr($cpo['message'], 12)
  3042.                 ]);
  3043.                 $this->doIncrementGmbClicks($request);
  3044.             } else {
  3045.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3046.                     'screen' => 'message',
  3047.                     'headersteps' => true,
  3048.                     'complete' => false,
  3049.                     'controller_name' => 'BookingProcessController',
  3050.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3051.                     'next' => '',
  3052.                     'client' => $this->client,
  3053.                     'bookingProcess' => null,
  3054.                     'displaywarning' => false,
  3055.                     'warningstatus' => 0,
  3056.                     'warningbody' => '',
  3057.                     'title' => 'THERE WAS A PROBLEM',
  3058.                     'message' => $cpo['message']
  3059.                 ]);
  3060.             }
  3061.             if ($setCookie) {
  3062.                 $this->setCookie($request$response$bookingProcess->getCode());
  3063.             }
  3064.             return $response;
  3065.         }
  3066.         if ($bookingProcess == null) {
  3067.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3068.         } else {
  3069.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-confirmlocation'$cpo['set_cookie']);
  3070.             if ($o != null) {
  3071.                 return $o;
  3072.             } else {
  3073.                 $bookingProcess->setScreen('input-confirmlocation');
  3074.                 $bookingProcess->setUpdatedAt($now);
  3075.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3076.                 $this->entityManager->persist($bookingProcess);
  3077.                 $this->entityManager->flush();
  3078.             }
  3079.         }
  3080.         $response $this->render('booking_process_cm_mvp1/step_input_confirmlocation.html.twig', [
  3081.             'screen' => 'input-confirmlocation',
  3082.             'headersteps' => true,
  3083.             'complete' => false,
  3084.             'controller_name' => 'BookingProcessController',
  3085.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3086.             'previous' => $this->generateUrl($this->screensmap['input-location']),
  3087.             'next' => $this->generateUrl($this->screensmap['input-service']),
  3088.             'client' => $this->client,
  3089.             'bookingProcess' => $bookingProcess,
  3090.             'displaywarning' => true,
  3091.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3092.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3093.         ]);
  3094.         if ($setCookie) {
  3095.             $this->setCookie($request$response$bookingProcess->getCode());
  3096.         }
  3097.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3098.         return $response;
  3099.     }
  3100.     /**
  3101.      * @Route("/booking/process/cm/mvp1/step/input-service", name="booking_process_cm_mvp1_step_input_service")
  3102.      */
  3103.     public function step_input_service(Request $request): Response
  3104.     {
  3105.         $now = new \DateTime();
  3106.         $canBookResponse $this->checkCanBook($request);
  3107.         if ($canBookResponse != null) {
  3108.             return $canBookResponse;
  3109.         }
  3110.         $cpo $this->assertBookingProcess($request);
  3111.         $bookingProcess $cpo['booking_process'];
  3112.         $setCookie $cpo['set_cookie'];
  3113.         $message $cpo['message'];
  3114.         if ($message != null and $message != '') {
  3115.             if (str_starts_with($message'__redirect: ')) {
  3116.                 $url substr($message12);
  3117.                 $this->doIncrementGmbClicks($request);
  3118.                 return $this->redirect($url);
  3119.             }
  3120.             $response null;
  3121.             if (str_starts_with($message'__inactive: ')) {
  3122.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3123.                     'screen' => 'inactive',
  3124.                     'headersteps' => true,
  3125.                     'complete' => false,
  3126.                     'controller_name' => 'BookingProcessController',
  3127.                     'next' => '',
  3128.                     'client' => $this->client,
  3129.                     'bookingProcess' => null,
  3130.                     'displaywarning' => false,
  3131.                     'warningstatus' => 0,
  3132.                     'warningbody' => '',
  3133.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3134.                     'title' => '',
  3135.                     'message' => substr($cpo['message'], 12)
  3136.                 ]);
  3137.                 $this->doIncrementGmbClicks($request);
  3138.             } else {
  3139.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3140.                     'screen' => 'message',
  3141.                     'headersteps' => true,
  3142.                     'complete' => false,
  3143.                     'controller_name' => 'BookingProcessController',
  3144.                     'next' => '',
  3145.                     'client' => $this->client,
  3146.                     'bookingProcess' => null,
  3147.                     'displaywarning' => false,
  3148.                     'warningstatus' => 0,
  3149.                     'warningbody' => '',
  3150.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3151.                     'title' => 'THERE WAS A PROBLEM',
  3152.                     'message' => $cpo['message']
  3153.                 ]);
  3154.             }
  3155.             if ($setCookie) {
  3156.                 $this->setCookie($request$response$bookingProcess->getCode());
  3157.             }
  3158.             return $response;
  3159.         }
  3160.         if ($bookingProcess == null) {
  3161.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3162.         } else {
  3163.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-service'$cpo['set_cookie']);
  3164.             if ($o != null) {
  3165.                 return $o;
  3166.             } else {
  3167.                 $bookingProcess->setScreen('input-service');
  3168.                 $bookingProcess->setUpdatedAt($now);
  3169.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3170.                 $this->entityManager->persist($bookingProcess);
  3171.                 $this->entityManager->flush();
  3172.             }
  3173.         }
  3174.         $regions null;
  3175.         $services = [];
  3176.         $allowedServices null;
  3177.         $bookingProcessBooking $bookingProcess->getBooking();
  3178.         if ($bookingProcessBooking->getServiceType() == 'fixed') {
  3179.             $regions = [$bookingProcessBooking->getSelectedRegion()];
  3180.             $services = array();
  3181.             foreach ($this->serviceRepository->findCustomerFacingWithRegions($regions) as $service) {
  3182.                 $services[$service->getId()] = $service;
  3183.             }
  3184.             $allowedServices $bookingProcess->getAllowedServices();
  3185.             if ($allowedServices) {
  3186.                 $arrayAllowedServices explode(','str_replace(', '','$allowedServices));
  3187.                 $services array_filter($services, function ($service) use ($arrayAllowedServices) {
  3188.                     if (in_array($service->getId(), $arrayAllowedServices)) {
  3189.                         return true;
  3190.                     }
  3191.                     return false;
  3192.                 });
  3193.             }
  3194.         } else {
  3195.             $regions $this->getRegionsFromLocation($bookingProcess->getBooking()->getLocation());
  3196.             $services = array();
  3197.             foreach ($this->serviceRepository->findCustomerFacingWithRegions($regions) as $service) {
  3198.                 $services[$service->getId()] = $service;
  3199.             }
  3200.             $allowedServices $bookingProcess->getAllowedServices();
  3201.             if ($allowedServices) {
  3202.                 $arrayAllowedServices explode(','str_replace(', '','$allowedServices));
  3203.                 $services array_filter($services, function ($service) use ($arrayAllowedServices) {
  3204.                     if (in_array($service->getId(), $arrayAllowedServices)) {
  3205.                         return true;
  3206.                     }
  3207.                     return false;
  3208.                 });
  3209.             }
  3210.         }
  3211.         $response $this->render('booking_process_cm_mvp1/step_input_service.html.twig', [
  3212.             'screen' => 'input-service',
  3213.             'headersteps' => true,
  3214.             'complete' => false,
  3215.             'controller_name' => 'BookingProcessController',
  3216.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3217.             'previous' => $this->generateUrl($this->screensmap['input-confirmlocation']),
  3218.             'next' => $this->generateUrl($this->screensmap['input-servicefields']),
  3219.             'client' => $this->client,
  3220.             'services' => $services,
  3221.             'bookingProcess' => $bookingProcess,
  3222.             'displaywarning' => true,
  3223.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3224.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3225.         ]);
  3226.         if ($setCookie) {
  3227.             $this->setCookie($request$response$bookingProcess->getCode());
  3228.         }
  3229.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3230.         return $response;
  3231.     }
  3232.     /**
  3233.      * @Route("/booking/process/cm/mvp1/step/input-servicefields", name="booking_process_cm_mvp1_step_input_servicefields")
  3234.      */
  3235.     public function step_input_servicefields(Request $request): Response
  3236.     {
  3237.         $now = new \DateTime();
  3238.         $canBookResponse $this->checkCanBook($request);
  3239.         if ($canBookResponse != null) {
  3240.             return $canBookResponse;
  3241.         }
  3242.         $cpo $this->assertBookingProcess($request);
  3243.         $bookingProcess $cpo['booking_process'];
  3244.         $setCookie $cpo['set_cookie'];
  3245.         $message $cpo['message'];
  3246.         if ($message != null and $message != '') {
  3247.             if (str_starts_with($message'__redirect: ')) {
  3248.                 $url substr($message12);
  3249.                 $this->doIncrementGmbClicks($request);
  3250.                 return $this->redirect($url);
  3251.             }
  3252.             $response null;
  3253.             if (str_starts_with($message'__inactive: ')) {
  3254.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3255.                     'screen' => 'inactive',
  3256.                     'headersteps' => true,
  3257.                     'complete' => false,
  3258.                     'controller_name' => 'BookingProcessController',
  3259.                     'next' => '',
  3260.                     'client' => $this->client,
  3261.                     'bookingProcess' => null,
  3262.                     'displaywarning' => false,
  3263.                     'warningstatus' => 0,
  3264.                     'warningbody' => '',
  3265.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3266.                     'title' => '',
  3267.                     'message' => substr($cpo['message'], 12)
  3268.                 ]);
  3269.                 $this->doIncrementGmbClicks($request);
  3270.             } else {
  3271.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3272.                     'screen' => 'message',
  3273.                     'headersteps' => true,
  3274.                     'complete' => false,
  3275.                     'controller_name' => 'BookingProcessController',
  3276.                     'next' => '',
  3277.                     'client' => $this->client,
  3278.                     'bookingProcess' => null,
  3279.                     'displaywarning' => false,
  3280.                     'warningstatus' => 0,
  3281.                     'warningbody' => '',
  3282.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3283.                     'title' => 'THERE WAS A PROBLEM',
  3284.                     'message' => $cpo['message']
  3285.                 ]);
  3286.             }
  3287.             if ($setCookie) {
  3288.                 $this->setCookie($request$response$bookingProcess->getCode());
  3289.             }
  3290.             return $response;
  3291.         }
  3292.         if ($bookingProcess == null) {
  3293.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3294.         } else {
  3295.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-servicefields'$cpo['set_cookie']);
  3296.             if ($o != null) {
  3297.                 return $o;
  3298.             } else {
  3299.                 $bookingProcess->setScreen('input-servicefields');
  3300.                 $bookingProcess->setUpdatedAt($now);
  3301.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3302.                 $this->entityManager->persist($bookingProcess);
  3303.                 $this->entityManager->flush();
  3304.             }
  3305.         }
  3306.         $response $this->render('booking_process_cm_mvp1/step_input_servicefields.html.twig', [
  3307.             'screen' => 'input-servicefields',
  3308.             'headersteps' => true,
  3309.             'complete' => false,
  3310.             'controller_name' => 'BookingProcessController',
  3311.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3312.             'previous' => $this->generateUrl($this->screensmap['input-service']),
  3313.             'next' => $this->generateUrl($this->screensmap['input-datetime']),
  3314.             'client' => $this->client,
  3315.             'bookingProcess' => $bookingProcess,
  3316.             'displaywarning' => true,
  3317.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3318.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3319.         ]);
  3320.         if ($setCookie) {
  3321.             $this->setCookie($request$response$bookingProcess->getCode());
  3322.         }
  3323.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3324.         return $response;
  3325.     }
  3326.     /**
  3327.      * @Route("/booking/process/cm/mvp1/step/input-schedule-type", name="booking_process_cm_mvp1_step_input_schedule_type")
  3328.      */
  3329.     public function step_input_schedule_type(Request $request)
  3330.     {
  3331.         $now = new \DateTime();
  3332.         $canBookResponse $this->checkCanBook($request);
  3333.         if ($canBookResponse != null) {
  3334.             return $canBookResponse;
  3335.         }
  3336.         $cpo $this->assertBookingProcess($request);
  3337.         $bookingProcess $cpo['booking_process'];
  3338.         $setCookie $cpo['set_cookie'];
  3339.         $message $cpo['message'];
  3340.         if ($message != null and $message != '') {
  3341.             if (str_starts_with($message'__redirect: ')) {
  3342.                 $url substr($message12);
  3343.                 $this->doIncrementGmbClicks($request);
  3344.                 return $this->redirect($url);
  3345.             }
  3346.             $response null;
  3347.             if (str_starts_with($message'__inactive: ')) {
  3348.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3349.                     'screen' => 'inactive',
  3350.                     'headersteps' => true,
  3351.                     'complete' => false,
  3352.                     'controller_name' => 'BookingProcessController',
  3353.                     'next' => '',
  3354.                     'client' => $this->client,
  3355.                     'bookingProcess' => null,
  3356.                     'displaywarning' => false,
  3357.                     'warningstatus' => 0,
  3358.                     'warningbody' => '',
  3359.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3360.                     'title' => '',
  3361.                     'message' => substr($cpo['message'], 12)
  3362.                 ]);
  3363.                 $this->doIncrementGmbClicks($request);
  3364.             } else {
  3365.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3366.                     'screen' => 'message',
  3367.                     'headersteps' => true,
  3368.                     'complete' => false,
  3369.                     'controller_name' => 'BookingProcessController',
  3370.                     'next' => '',
  3371.                     'client' => $this->client,
  3372.                     'bookingProcess' => null,
  3373.                     'displaywarning' => false,
  3374.                     'warningstatus' => 0,
  3375.                     'warningbody' => '',
  3376.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3377.                     'title' => 'THERE WAS A PROBLEM',
  3378.                     'message' => $cpo['message']
  3379.                 ]);
  3380.             }
  3381.             if ($setCookie) {
  3382.                 $this->setCookie($request$response$bookingProcess->getCode());
  3383.             }
  3384.             return $response;
  3385.         }
  3386.         if ($bookingProcess == null) {
  3387.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3388.         } else {
  3389.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-schedule-type'$cpo['set_cookie']);
  3390.             if ($o != null) {
  3391.                 return $o;
  3392.             } else {
  3393.                 $bookingProcess->setScreen('input-schedule-type');
  3394.                 $bookingProcess->setUpdatedAt($now);
  3395.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3396.                 $this->entityManager->persist($bookingProcess);
  3397.                 $this->entityManager->flush();
  3398.             }
  3399.         }
  3400.         $response $this->render('booking_process_cm_mvp1/step_input_schedule_type.html.twig', [
  3401.             'screen' => 'input-schedule-type',
  3402.             'headersteps' => true,
  3403.             'complete' => false,
  3404.             'controller_name' => 'BookingProcessController',
  3405.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3406.             'previous' => $this->generateUrl($this->screensmap['input-servicefields']),
  3407.             'next' => $this->generateUrl($this->screensmap['input-datetime']),
  3408.             'client' => $this->client,
  3409.             'bookingProcess' => $bookingProcess,
  3410.             'choices' => [
  3411.                 'exact' => [
  3412.                     'title' => 'Exact Time Booking',
  3413.                     'description' => 'Choose an exact date and time for your booking'
  3414.                 ],
  3415.                 'anytime' => [
  3416.                     'title' => 'Anytime Booking',
  3417.                     'description' => 'Choose a date and schedule your booking to happen anytime in that day'
  3418.                 ],
  3419.                 'morning' => [
  3420.                     'title' => 'Morning Booking',
  3421.                     'description' => 'Choose a date and schedule your booking to happen in the morning of that day'
  3422.                 ],
  3423.                 'afternoon' => [
  3424.                     'title' => 'Afternoon Booking',
  3425.                     'description' => 'Choose a date and schedule your booking to happen in the afternoon of that day'
  3426.                 ],
  3427.                 'evening' => [
  3428.                     'title' => 'Evening Booking',
  3429.                     'description' => 'Choose a date and schedule your booking to happen in the evening of that day'
  3430.                 ]
  3431.             ],
  3432.             'displaywarning' => true,
  3433.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3434.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3435.         ]);
  3436.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3437.         return $response;
  3438.     }
  3439.     /**
  3440.      * @Route("/booking/process/cm/mvp1/step/input-datetime", name="booking_process_cm_mvp1_step_input_datetime")
  3441.      */
  3442.     public function step_input_datetime(Request $request): Response
  3443.     {
  3444.         $now = new \DateTime();
  3445.         $canBookResponse $this->checkCanBook($request);
  3446.         if ($canBookResponse != null) {
  3447.             return $canBookResponse;
  3448.         }
  3449.         $cpo $this->assertBookingProcess($request);
  3450.         $bookingProcess $cpo['booking_process'];
  3451.         $setCookie $cpo['set_cookie'];
  3452.         $message $cpo['message'];
  3453.         if ($message != null and $message != '') {
  3454.             if (str_starts_with($message'__redirect: ')) {
  3455.                 $url substr($message12);
  3456.                 $this->doIncrementGmbClicks($request);
  3457.                 return $this->redirect($url);
  3458.             }
  3459.             $response null;
  3460.             if (str_starts_with($message'__inactive: ')) {
  3461.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3462.                     'screen' => 'inactive',
  3463.                     'headersteps' => true,
  3464.                     'complete' => false,
  3465.                     'controller_name' => 'BookingProcessController',
  3466.                     'next' => '',
  3467.                     'client' => $this->client,
  3468.                     'bookingProcess' => null,
  3469.                     'displaywarning' => false,
  3470.                     'warningstatus' => 0,
  3471.                     'warningbody' => '',
  3472.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3473.                     'title' => '',
  3474.                     'message' => substr($cpo['message'], 12)
  3475.                 ]);
  3476.                 $this->doIncrementGmbClicks($request);
  3477.             } else {
  3478.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3479.                     'screen' => 'message',
  3480.                     'headersteps' => true,
  3481.                     'complete' => false,
  3482.                     'controller_name' => 'BookingProcessController',
  3483.                     'next' => '',
  3484.                     'client' => $this->client,
  3485.                     'bookingProcess' => null,
  3486.                     'displaywarning' => false,
  3487.                     'warningstatus' => 0,
  3488.                     'warningbody' => '',
  3489.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3490.                     'title' => 'THERE WAS A PROBLEM',
  3491.                     'message' => $cpo['message']
  3492.                 ]);
  3493.             }
  3494.             if ($setCookie) {
  3495.                 $this->setCookie($request$response$bookingProcess->getCode());
  3496.             }
  3497.             return $response;
  3498.         }
  3499.         if ($bookingProcess == null) {
  3500.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3501.         } else {
  3502.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-datetime'$cpo['set_cookie']);
  3503.             if ($o != null) {
  3504.                 return $o;
  3505.             } else {
  3506.                 $bookingProcess->setScreen('input-datetime');
  3507.                 $bookingProcess->setUpdatedAt($now);
  3508.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3509.                 $this->entityManager->persist($bookingProcess);
  3510.                 $this->entityManager->flush();
  3511.             }
  3512.         }
  3513.         $response $this->render('booking_process_cm_mvp1/step_input_datetime.html.twig', [
  3514.             'screen' => 'input-datetime',
  3515.             'headersteps' => true,
  3516.             'complete' => false,
  3517.             'controller_name' => 'BookingProcessController',
  3518.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3519.             'previous' => $this->generateUrl($this->screensmap['input-servicefields']),
  3520.             'next' => $this->generateUrl($this->screensmap['input-contact']),
  3521.             'client' => $this->client,
  3522.             'bookingProcess' => $bookingProcess,
  3523.             'displaywarning' => true,
  3524.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3525.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3526.         ]);
  3527.         if ($setCookie) {
  3528.             $this->setCookie($request$response$bookingProcess->getCode());
  3529.         }
  3530.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3531.         return $response;
  3532.     }
  3533.     /**
  3534.      * @Route("/booking/process/cm/mvp1/step/input-contact", name="booking_process_cm_mvp1_step_input_contact")
  3535.      */
  3536.     public function step_input_contact(Request $request): Response
  3537.     {
  3538.         $now = new \DateTime();
  3539.         $canBookResponse $this->checkCanBook($request);
  3540.         if ($canBookResponse != null) {
  3541.             return $canBookResponse;
  3542.         }
  3543.         $cpo $this->assertBookingProcess($request);
  3544.         $bookingProcess $cpo['booking_process'];
  3545.         $setCookie $cpo['set_cookie'];
  3546.         $message $cpo['message'];
  3547.         if ($message != null and $message != '') {
  3548.             if (str_starts_with($message'__redirect: ')) {
  3549.                 $url substr($message12);
  3550.                 $this->doIncrementGmbClicks($request);
  3551.                 return $this->redirect($url);
  3552.             }
  3553.             $response null;
  3554.             if (str_starts_with($message'__inactive: ')) {
  3555.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3556.                     'screen' => 'inactive',
  3557.                     'headersteps' => true,
  3558.                     'complete' => false,
  3559.                     'controller_name' => 'BookingProcessController',
  3560.                     'next' => '',
  3561.                     'client' => $this->client,
  3562.                     'bookingProcess' => null,
  3563.                     'displaywarning' => false,
  3564.                     'warningstatus' => 0,
  3565.                     'warningbody' => '',
  3566.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3567.                     'title' => '',
  3568.                     'message' => substr($cpo['message'], 12)
  3569.                 ]);
  3570.                 $this->doIncrementGmbClicks($request);
  3571.             } else {
  3572.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3573.                     'screen' => 'message',
  3574.                     'headersteps' => true,
  3575.                     'complete' => false,
  3576.                     'controller_name' => 'BookingProcessController',
  3577.                     'next' => '',
  3578.                     'client' => $this->client,
  3579.                     'bookingProcess' => null,
  3580.                     'displaywarning' => false,
  3581.                     'warningstatus' => 0,
  3582.                     'warningbody' => '',
  3583.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3584.                     'title' => 'THERE WAS A PROBLEM',
  3585.                     'message' => $cpo['message']
  3586.                 ]);
  3587.             }
  3588.             if ($setCookie) {
  3589.                 $this->setCookie($request$response$bookingProcess->getCode());
  3590.             }
  3591.             return $response;
  3592.         }
  3593.         if ($bookingProcess == null) {
  3594.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3595.         } else {
  3596.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-contact'$cpo['set_cookie']);
  3597.             if ($o != null) {
  3598.                 return $o;
  3599.             } else {
  3600.                 $bookingProcess->setScreen('input-contact');
  3601.                 $bookingProcess->setUpdatedAt($now);
  3602.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3603.                 $this->entityManager->persist($bookingProcess);
  3604.                 $this->entityManager->flush();
  3605.             }
  3606.         }
  3607.         $response $this->render('booking_process_cm_mvp1/step_input_contact.html.twig', [
  3608.             'screen' => 'input-contact',
  3609.             'headersteps' => true,
  3610.             'complete' => false,
  3611.             'headerheight' => 30,
  3612.             'controller_name' => 'BookingProcessController',
  3613.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3614.             'previous' => $this->generateUrl($this->screensmap['input-datetime']),
  3615.             'next' => $this->generateUrl($this->screensmap['input-billing']),
  3616.             'client' => $this->client,
  3617.             'bookingProcess' => $bookingProcess,
  3618.             'displaywarning' => true,
  3619.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3620.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3621.         ]);
  3622.         if ($setCookie) {
  3623.             $this->setCookie($request$response$bookingProcess->getCode());
  3624.         }
  3625.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3626.         return $response;
  3627.     }
  3628.     /**
  3629.      * @Route("/booking/process/cm/mvp1/step/input-billing", name="booking_process_cm_mvp1_step_input_billing")
  3630.      */
  3631.     public function step_input_billing(Request $request): Response
  3632.     {
  3633.         $now = new \DateTime();
  3634.         $canBookResponse $this->checkCanBook($request);
  3635.         if ($canBookResponse != null) {
  3636.             return $canBookResponse;
  3637.         }
  3638.         $cpo $this->assertBookingProcess($request);
  3639.         $bookingProcess $cpo['booking_process'];
  3640.         $setCookie $cpo['set_cookie'];
  3641.         $message $cpo['message'];
  3642.         if ($message != null and $message != '') {
  3643.             if (str_starts_with($message'__redirect: ')) {
  3644.                 $url substr($message12);
  3645.                 $this->doIncrementGmbClicks($request);
  3646.                 return $this->redirect($url);
  3647.             }
  3648.             $response null;
  3649.             if (str_starts_with($message'__inactive: ')) {
  3650.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3651.                     'screen' => 'inactive',
  3652.                     'headersteps' => true,
  3653.                     'complete' => false,
  3654.                     'controller_name' => 'BookingProcessController',
  3655.                     'next' => '',
  3656.                     'client' => $this->client,
  3657.                     'bookingProcess' => null,
  3658.                     'displaywarning' => false,
  3659.                     'warningstatus' => 0,
  3660.                     'warningbody' => '',
  3661.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3662.                     'title' => '',
  3663.                     'message' => substr($cpo['message'], 12)
  3664.                 ]);
  3665.                 $this->doIncrementGmbClicks($request);
  3666.             } else {
  3667.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3668.                     'screen' => 'message',
  3669.                     'headersteps' => true,
  3670.                     'complete' => false,
  3671.                     'controller_name' => 'BookingProcessController',
  3672.                     'next' => '',
  3673.                     'client' => $this->client,
  3674.                     'bookingProcess' => null,
  3675.                     'displaywarning' => false,
  3676.                     'warningstatus' => 0,
  3677.                     'warningbody' => '',
  3678.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3679.                     'title' => 'THERE WAS A PROBLEM',
  3680.                     'message' => $cpo['message']
  3681.                 ]);
  3682.             }
  3683.             if ($setCookie) {
  3684.                 $this->setCookie($request$response$bookingProcess->getCode());
  3685.             }
  3686.             return $response;
  3687.         }
  3688.         if ($bookingProcess == null) {
  3689.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3690.         } else {
  3691.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-billing'$cpo['set_cookie']);
  3692.             if ($o != null) {
  3693.                 return $o;
  3694.             } else {
  3695.                 $bookingProcess->setScreen('input-billing');
  3696.                 $bookingProcess->setUpdatedAt($now);
  3697.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3698.                 $this->entityManager->persist($bookingProcess);
  3699.                 $this->entityManager->flush();
  3700.             }
  3701.         }
  3702.         $response $this->render('booking_process_cm_mvp1/step_input_billing.html.twig', [
  3703.             'screen' => 'input-billing',
  3704.             'headersteps' => true,
  3705.             'complete' => false,
  3706.             'controller_name' => 'BookingProcessController',
  3707.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3708.             'previous' => $this->generateUrl($this->screensmap['input-contact']),
  3709.             'next' => $this->generateUrl($this->screensmap['complete']),
  3710.             'client' => $this->client,
  3711.             'bookingProcess' => $bookingProcess,
  3712.             'displaywarning' => true,
  3713.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3714.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3715.         ]);
  3716.         if ($setCookie) {
  3717.             $this->setCookie($request$response$bookingProcess->getCode());
  3718.         }
  3719.         $this->addPreProcessHeaders($request$response$bookingProcess);
  3720.         return $response;
  3721.     }
  3722.     /**
  3723.      * @Route("/booking/process/cm/mvp1/step/confirm/{code}", name="booking_process_cm_mvp1_step_confirm")
  3724.      */
  3725.     public function step_confirm(Request $requeststring $code): Response
  3726.     {
  3727.         $bookingProcess $this->bookingProcessRepository->findOneBy([
  3728.             "code" => $code,
  3729.             "status" => "commit-confirm"
  3730.         ]);
  3731.         $response null;
  3732.         if ($bookingProcess !== null) {
  3733.             $b $this->doStepCommit($request$bookingProcess);
  3734.             if ($b) {
  3735.                 $emails $this->emailsEntityModel->findByClient($this->client);
  3736.                 $this->setGoToScreenOnBookingProcess($bookingProcess'complete');
  3737.                 $this->doStepComplete($request$bookingProcess);
  3738.                 $response $this->render('booking_process_cm_mvp1/step_complete.html.twig', [
  3739.                     'screen' => 'complete',
  3740.                     'headersteps' => true,
  3741.                     'complete' => true,
  3742.                     'controller_name' => 'BookingProcessController',
  3743.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3744.                     'previous' => $this->generateUrl($this->screensmap['input-billing']),
  3745.                     'next' => $this->generateUrl($this->screensmap['complete']),
  3746.                     'client' => $this->client,
  3747.                     'emails' => $emails,
  3748.                     'bookingProcess' => $bookingProcess,
  3749.                     'displaywarning' => true,
  3750.                     'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3751.                     'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3752.                 ]);
  3753.             }
  3754.         } else {
  3755.             $response = new JsonResponse(
  3756.                 'THIS BOOKING CANNOT BE CONFIRMED',
  3757.                 Response::HTTP_BAD_REQUEST
  3758.             );
  3759.         }
  3760.         return $response;
  3761.     }
  3762.     /**
  3763.      * @Route("/booking/process/cm/mvp1/step/commit", name="booking_process_cm_mvp1_step_commit")
  3764.      */
  3765.     public function step_commit(Request $request): Response
  3766.     {
  3767.         $now = new \DateTime();
  3768.         $canBookResponse $this->checkCanBook($request);
  3769.         if ($canBookResponse != null) {
  3770.             return $canBookResponse;
  3771.         }
  3772.         $cpo $this->assertBookingProcess($request);
  3773.         $bookingProcess $cpo['booking_process'];
  3774.         $setCookie $cpo['set_cookie'];
  3775.         $message $cpo['message'];
  3776.         if ($message != null and $message != '') {
  3777.             if (str_starts_with($message'__redirect: ')) {
  3778.                 $url substr($message12);
  3779.                 $this->doIncrementGmbClicks($request);
  3780.                 return $this->redirect($url);
  3781.             }
  3782.             $response null;
  3783.             if (str_starts_with($message'__inactive: ')) {
  3784.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3785.                     'screen' => 'inactive',
  3786.                     'headersteps' => true,
  3787.                     'complete' => false,
  3788.                     'controller_name' => 'BookingProcessController',
  3789.                     'next' => '',
  3790.                     'client' => $this->client,
  3791.                     'bookingProcess' => null,
  3792.                     'displaywarning' => false,
  3793.                     'warningstatus' => 0,
  3794.                     'warningbody' => '',
  3795.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3796.                     'title' => 'THERE WAS A PROBLEM',
  3797.                     'message' => substr($cpo['message'], 12)
  3798.                 ]);
  3799.                 $this->doIncrementGmbClicks($request);
  3800.             } else {
  3801.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3802.                     'screen' => 'message',
  3803.                     'headersteps' => true,
  3804.                     'complete' => false,
  3805.                     'controller_name' => 'BookingProcessController',
  3806.                     'next' => '',
  3807.                     'client' => $this->client,
  3808.                     'bookingProcess' => null,
  3809.                     'displaywarning' => false,
  3810.                     'warningstatus' => 0,
  3811.                     'warningbody' => '',
  3812.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3813.                     'title' => 'THERE WAS A PROBLEM',
  3814.                     'message' => $cpo['message']
  3815.                 ]);
  3816.             }
  3817.             if ($setCookie) {
  3818.                 $this->setCookie($request$response$bookingProcess->getCode());
  3819.             }
  3820.             return $response;
  3821.         }
  3822.         if ($bookingProcess == null) {
  3823.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3824.         } else {
  3825.             $o $this->redirectOnInvalidStep($request$bookingProcess'commit'$cpo['set_cookie']);
  3826.             if ($o != null) {
  3827.                 return $o;
  3828.             } else {
  3829.                 $bookingProcess->setScreen('input-billing');
  3830.                 $bookingProcess->setUpdatedAt($now);
  3831.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3832.                 $this->entityManager->persist($bookingProcess);
  3833.                 $this->entityManager->flush();
  3834.             }
  3835.         }
  3836.         $commit_type $this->client->getPropertyValue('booking.commit.type');
  3837.         $commit_result null;
  3838.         if ($commit_type === 'confirm' && $this->getUser() === null) {
  3839.             $commit_result $this->doStepConfirm($request$bookingProcess);
  3840.         } else {
  3841.             $commit_result $this->doStepCommit($request$bookingProcess) ? 'commit-success' 'commit-failure';
  3842.         }
  3843.         if ($commit_result === 'commit-confirm') {
  3844.             $emails $this->emailsEntityModel->findByClient($this->client);
  3845.             $this->setGoToScreenOnBookingProcess($bookingProcess'commit-confirm');
  3846.             $this->doStepCommitConfirm($request$bookingProcess);
  3847.             $response $this->render('booking_process_cm_mvp1/step_confirm.html.twig', [
  3848.                 'screen' => 'complete',
  3849.                 'headersteps' => true,
  3850.                 'complete' => true,
  3851.                 'controller_name' => 'BookingProcessController',
  3852.                 'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3853.                 'previous' => $this->generateUrl($this->screensmap['input-billing']),
  3854.                 'next' => $this->generateUrl($this->screensmap['complete']),
  3855.                 'client' => $this->client,
  3856.                 'emails' => $emails,
  3857.                 'bookingProcess' => $bookingProcess,
  3858.                 'displaywarning' => true,
  3859.                 'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3860.                 'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3861.             ]);
  3862.             $this->unsetCookie($response);
  3863.         } else if ($commit_result === 'commit-success') {
  3864.             $emails $this->emailsEntityModel->findByClient($this->client);
  3865.             $this->setGoToScreenOnBookingProcess($bookingProcess'complete');
  3866.             $this->doStepComplete($request$bookingProcess);
  3867.             $response $this->render('booking_process_cm_mvp1/step_complete.html.twig', [
  3868.                 'screen' => 'complete',
  3869.                 'headersteps' => true,
  3870.                 'complete' => true,
  3871.                 'controller_name' => 'BookingProcessController',
  3872.                 'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3873.                 'previous' => $this->generateUrl($this->screensmap['input-billing']),
  3874.                 'next' => $this->generateUrl($this->screensmap['complete']),
  3875.                 'client' => $this->client,
  3876.                 'emails' => $emails,
  3877.                 'bookingProcess' => $bookingProcess,
  3878.                 'displaywarning' => true,
  3879.                 'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3880.                 'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3881.             ]);
  3882.             $this->unsetCookie($response);
  3883.         } else {
  3884.             $response = new Response(
  3885.                 'COMMIT FAILED',
  3886.                 Response::HTTP_OK,
  3887.                 ['content-type' => 'text/html']
  3888.             );
  3889.         }
  3890.         return $response;
  3891.     }
  3892.     /**
  3893.      * @Route("/booking/process/cm/mvp1/step/complete", name="booking_process_cm_mvp1_step_complete")
  3894.      */
  3895.     public function step_input_complete(Request $request): Response
  3896.     {
  3897.         $now = new \DateTime();
  3898.         $canBookResponse $this->checkCanBook($request);
  3899.         if ($canBookResponse != null) {
  3900.             return $canBookResponse;
  3901.         }
  3902.         $cpo $this->assertBookingProcess($request);
  3903.         $bookingProcess $cpo['booking_process'];
  3904.         $setCookie $cpo['set_cookie'];
  3905.         $message $cpo['message'];
  3906.         if ($message != null and $message != '') {
  3907.             if (str_starts_with($message'__redirect: ')) {
  3908.                 $url substr($message12);
  3909.                 $this->doIncrementGmbClicks($request);
  3910.                 return $this->redirect($url);
  3911.             }
  3912.             $response null;
  3913.             if (str_starts_with($message'__inactive: ')) {
  3914.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  3915.                     'screen' => 'inactive',
  3916.                     'headersteps' => true,
  3917.                     'complete' => false,
  3918.                     'controller_name' => 'BookingProcessController',
  3919.                     'next' => '',
  3920.                     'client' => $this->client,
  3921.                     'bookingProcess' => null,
  3922.                     'displaywarning' => false,
  3923.                     'warningstatus' => 0,
  3924.                     'warningbody' => '',
  3925.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3926.                     'title' => 'THERE WAS A PROBLEM',
  3927.                     'message' => substr($cpo['message'], 12)
  3928.                 ]);
  3929.                 $this->doIncrementGmbClicks($request);
  3930.             } else {
  3931.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  3932.                     'screen' => 'message',
  3933.                     'headersteps' => true,
  3934.                     'complete' => false,
  3935.                     'controller_name' => 'BookingProcessController',
  3936.                     'next' => '',
  3937.                     'client' => $this->client,
  3938.                     'bookingProcess' => null,
  3939.                     'displaywarning' => false,
  3940.                     'warningstatus' => 0,
  3941.                     'warningbody' => '',
  3942.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3943.                     'title' => 'THERE WAS A PROBLEM',
  3944.                     'message' => $cpo['message']
  3945.                 ]);
  3946.             }
  3947.             if ($setCookie) {
  3948.                 $this->setCookie($request$response$bookingProcess->getCode());
  3949.             }
  3950.             return $response;
  3951.         }
  3952.         if ($bookingProcess == null) {
  3953.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  3954.         } else {
  3955.             $o $this->redirectOnInvalidStep($request$bookingProcess'input-complete'$cpo['set_cookie']);
  3956.             if ($o != null) {
  3957.                 return $o;
  3958.             } else {
  3959.                 $bookingProcess->setScreen('complete');
  3960.                 $bookingProcess->setUpdatedAt($now);
  3961.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  3962.                 $this->entityManager->persist($bookingProcess);
  3963.                 $this->entityManager->flush();
  3964.             }
  3965.         }
  3966.         return $this->render('booking_process_cm_mvp1/step_complete.html.twig', [
  3967.             'screen' => 'complete',
  3968.             'headersteps' => true,
  3969.             'complete' => true,
  3970.             'controller_name' => 'BookingProcessController',
  3971.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  3972.             'previous' => $this->generateUrl($this->screensmap['input-billing']),
  3973.             'next' => $this->generateUrl($this->screensmap['complete']),
  3974.             'client' => $this->client,
  3975.             'bookingProcess' => $bookingProcess,
  3976.             'displaywarning' => true,
  3977.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  3978.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  3979.         ]);
  3980.     }
  3981.     /**
  3982.      * @Route("/booking/process/cm/mvp1/step/complete-callback", name="booking_process_cm_mvp1_step_complete_callback")
  3983.      */
  3984.     public function step_input_complete_callback(Request $request): Response
  3985.     {
  3986.         $now = new \DateTime();
  3987.         $canBookResponse $this->checkCanBook($request);
  3988.         if ($canBookResponse != null) {
  3989.             return $canBookResponse;
  3990.         }
  3991.         $cpo $this->assertBookingProcess($request);
  3992.         $bookingProcess $cpo['booking_process'];
  3993.         $setCookie $cpo['set_cookie'];
  3994.         $message $cpo['message'];
  3995.         if ($message != null and $message != '') {
  3996.             if (str_starts_with($message'__redirect: ')) {
  3997.                 $url substr($message12);
  3998.                 $this->doIncrementGmbClicks($request);
  3999.                 return $this->redirect($url);
  4000.             }
  4001.             $response null;
  4002.             if (str_starts_with($message'__inactive: ')) {
  4003.                 $response $this->render('booking_process_cm_mvp1/message_inactive.html.twig', [
  4004.                     'screen' => 'message',
  4005.                     'headersteps' => true,
  4006.                     'complete' => false,
  4007.                     'controller_name' => 'BookingProcessController',
  4008.                     'next' => '',
  4009.                     'client' => $this->client,
  4010.                     'bookingProcess' => null,
  4011.                     'displaywarning' => false,
  4012.                     'warningstatus' => 0,
  4013.                     'warningbody' => '',
  4014.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  4015.                     'title' => 'THERE WAS A PROBLEM',
  4016.                     'message' => substr($cpo['message'], 12)
  4017.                 ]);
  4018.                 $this->doIncrementGmbClicks($request);
  4019.             } else {
  4020.                 $response $this->render('booking_process_cm_mvp1/message.html.twig', [
  4021.                     'screen' => 'message',
  4022.                     'headersteps' => true,
  4023.                     'complete' => false,
  4024.                     'controller_name' => 'BookingProcessController',
  4025.                     'next' => '',
  4026.                     'client' => $this->client,
  4027.                     'bookingProcess' => null,
  4028.                     'displaywarning' => false,
  4029.                     'warningstatus' => 0,
  4030.                     'warningbody' => '',
  4031.                     'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  4032.                     'title' => 'THERE WAS A PROBLEM',
  4033.                     'message' => $cpo['message']
  4034.                 ]);
  4035.             }
  4036.             if ($setCookie) {
  4037.                 $this->setCookie($request$response$bookingProcess->getCode());
  4038.             }
  4039.             return $response;
  4040.         }
  4041.         if ($bookingProcess == null) {
  4042.             return $this->redirect($this->generateUrl($this->screensmap['input-location']));
  4043.         } else {
  4044.             $o $this->redirectOnInvalidStep($request$bookingProcess'complete-callback'$cpo['set_cookie']);
  4045.             if ($o != null) {
  4046.                 return $o;
  4047.             } else {
  4048.                 $bookingProcess->setScreen('complete-callback');
  4049.                 $bookingProcess->setStatus('complete-callback');
  4050.                 $bookingProcess->setUpdatedAt($now);
  4051.                 $bookingProcess->setIpAddress($this->request->getClientIp());
  4052.                 $this->entityManager->persist($bookingProcess);
  4053.                 $this->entityManager->flush();
  4054.             }
  4055.         }
  4056.         $response $this->render('booking_process_cm_mvp1/step_complete_callback.html.twig', [
  4057.             'screen' => 'complete',
  4058.             'headersteps' => true,
  4059.             'complete' => true,
  4060.             'controller_name' => 'BookingProcessController',
  4061.             'user' => $this->getUser() != null && ($this->getUser()->getClient() == null || $this->getUser()->getClient()->getId() == $this->client->getId()) ? $this->getUser() : null,
  4062.             'previous' => $this->generateUrl($this->screensmap['input-billing']),
  4063.             'next' => $this->generateUrl($this->screensmap['complete']),
  4064.             'client' => $this->client,
  4065.             'bookingProcess' => $bookingProcess,
  4066.             'displaywarning' => true,
  4067.             'warningstatus' => $bookingProcess != null && $bookingProcess->getWarningstatus() != null $bookingProcess->getWarningstatus() : 0,
  4068.             'warningbody' => $bookingProcess != null && $bookingProcess->getWarningbody() != null && $bookingProcess->getWarningbody() != '' json_decode($bookingProcess->getWarningbody()) : null
  4069.         ]);
  4070.         $this->unsetCookie($response);
  4071.         return $response;
  4072.     }
  4073.     /**
  4074.      * @Route("/booking/process/cm/mvp1/reschedule/{id}", name="booking_process_cm_mvp1_reschedule")
  4075.      * @Route("/reschedule/cm/mvp1/{id}", name="booking_reschedule_cm_mvp1")
  4076.      * @Route("/reschedule/{id}", name="booking_reschedule_cm_mvp1_default", condition="(((context.getHost() not in %app.beta.clients%) and ('%booking_process.scope%' == 'cm_mvp1')) or ((context.getHost() in %app.beta.clients%) and ('%booking_process.beta.scope%' == 'cm_mvp1')))")
  4077.      */
  4078.     public function reschedule(Request $requestint $id)
  4079.     {
  4080.         return $this->redirect($this->generateUrl($this->screensmap['input-datetime'], array('booking' => $id)));
  4081.     }
  4082.     /**
  4083.      * @Route("/booking/process/cm/mvp1/edit/{id}", name="booking_process_cm_mvp1_edit")
  4084.      * @Route("/edit/cm/mvp1/{id}", name="booking_edit_cm_mvp1")
  4085.      * @Route("/edit/{id}", name="booking_edit_cm_mvp1_default", condition="(((context.getHost() not in %app.beta.clients%) and ('%booking_process.scope%' == 'cm_mvp1')) or ((context.getHost() in %app.beta.clients%) and ('%booking_process.beta.scope%' == 'cm_mvp1')))")
  4086.      */
  4087.     public function edit(Request $requestint $id)
  4088.     {
  4089.         return $this->redirect($this->generateUrl($this->screensmap['input-confirmlocation'], array('booking' => $id)));
  4090.     }
  4091.     protected function getRegionsFromLocation(BookingProcessLocation $location)
  4092.     {
  4093.         $regions = [];
  4094.         $point $this->locationToCoordinates($location);
  4095.         foreach ($this->regionRepository->findByClient($this->client) as $region) {
  4096.             $polygon array_map(
  4097.                 array($this'locationToCoordinates'),
  4098.                 $region->getBoundaries()->toArray()
  4099.             );
  4100.             if ($this->pointInPolygon->inPolygon($point$polygon)) {
  4101.                 $regions[] = $region;
  4102.             }
  4103.         }
  4104.         return $regions;
  4105.     }
  4106.     protected function getRegionsGroupedByServiceType()
  4107.     {
  4108.         $regions = [
  4109.             'fixed' => [],
  4110.             'onsite' => []
  4111.         ];
  4112.         $aregions $this->regionRepository->findByClient($this->client);
  4113.         foreach ($aregions as $region) {
  4114.             $regions[$this->client->getServiceType() == 'fixed' 'fixed' 'onsite'][] = $region;
  4115.         }
  4116.         return $regions;
  4117.     }
  4118.     protected function locationToCoordinates($location)
  4119.     {
  4120.         if ($location instanceof Boundary) {
  4121.             $location $location->getLocation();
  4122.         }
  4123.         if (!$location instanceof Location && !$location instanceof BookingProcessLocation) {
  4124.             throw new \InvalidArgumentException('$location must be a Location|Boundary|BookingProcessLocation');
  4125.         }
  4126.         return array($location->getLatitude(), $location->getLongitude());
  4127.     }
  4128.     /**
  4129.      * @Route("/booking/process/cm/mvp1/step/datetime/availability/date", name="booking_process_cm_mvp1_step_datetime_dateavailability")
  4130.      */
  4131.     public function dateAvailability(
  4132.         Request $request,
  4133.         DayScheduler $dayScheduler,
  4134.         CalendarExtension $calendarExtension,
  4135.         HoursOfOperationRepository $hoursOfOperationRepository,
  4136.         Scheduler $scheduler,
  4137.         HoursChangeRepository $hoursChangeRepository
  4138.     ) {
  4139.         try {
  4140.             $now = new \DateTime();
  4141.             $bookingProcess $this->checkBookingProcess($request);
  4142.             if ($bookingProcess == null) {
  4143.                 $response = new JsonResponse(
  4144.                     'MISSING BOOKING PROCESS',
  4145.                     Response::HTTP_NOT_FOUND
  4146.                 );
  4147.                 return $response;
  4148.             }
  4149.             $bookingProcessBooking $bookingProcess->getBooking();
  4150.             if ($bookingProcess == null) {
  4151.                 $response = new JsonResponse(
  4152.                     'MISSING BOOKING FOR THIS BOOKING PROCESS',
  4153.                     Response::HTTP_NOT_FOUND
  4154.                 );
  4155.                 return $response;
  4156.             }
  4157.             $bookingProcessBookingLocation $bookingProcessBooking->getLocation();
  4158.             if ($bookingProcessBookingLocation == null) {
  4159.                 $response = new JsonResponse(
  4160.                     'MISSING BOOKING LOCATION FOR THIS BOOKING PROCESS',
  4161.                     Response::HTTP_NOT_FOUND
  4162.                 );
  4163.                 return $response;
  4164.             } {
  4165.                 $bookingRegions $bookingProcessBooking->getRegions();
  4166.                 $bookingRegionsIds = [];
  4167.                 if ($bookingRegions) {
  4168.                     foreach ($bookingRegions as $bookingRegion) {
  4169.                         $bookingRegionsIds[] = $bookingRegion->getId();
  4170.                     }
  4171.                 }
  4172.                 $bookingProcessLocation $bookingProcessBooking->getLocation();
  4173.                 $locationRegions $this->getRegionsFromLocation($bookingProcessLocation$bookingProcess->getAllowedRegions());
  4174.                 foreach ($bookingRegions as $bookingRegion) {
  4175.                     $bookingProcessBooking->removeRegion($bookingRegion);
  4176.                 }
  4177.                 $region_id $bookingRegionsIds[0];
  4178.                 $region $this->regionRepository->find($region_id);
  4179.                 if ($bookingProcessBooking->getServiceType() === 'fixed') {
  4180.                     $bookingProcessBooking->addRegion($region);
  4181.                 } else {
  4182.                     foreach ($locationRegions as $locationRegion) {
  4183.                         $bookingProcessBooking->addRegion($locationRegion);
  4184.                     }
  4185.                 }
  4186.                 if ($bookingProcessBooking->getServiceType() !== 'fixed' && (!$locationRegions || count($locationRegions) < 1)) {
  4187.                     throw new \Exception("Location is out of bounds!");
  4188.                 } else {
  4189.                     foreach ($locationRegions as $locationRegion) {
  4190.                         $bookingProcessBooking->addRegion($locationRegion);
  4191.                     }
  4192.                 }
  4193.                 $this->entityManager->persist($bookingProcessBooking);
  4194.                 $this->entityManager->flush();
  4195.             }
  4196.             $schedule_type $request->query->get('schedule_type');
  4197.             if ($schedule_type == null) {
  4198.                 $schedule_type 'anytime';
  4199.             }
  4200.             $input_start $request->query->get('start');
  4201.             $start null;
  4202.             if ($input_start == null) {
  4203.                 $start = clone $now;
  4204.             } else {
  4205.                 $start = \DateTime::createFromFormat('Y-m-d H:i:s'$input_start ' 00:00:00');
  4206.                 if (!$start) {
  4207.                     throw new \Exception("Invalid start date");
  4208.                 }
  4209.             }
  4210.             $input_end $request->query->get('end');
  4211.             $end null;
  4212.             if ($input_end == null) {
  4213.                 $end = clone $now;
  4214.                 $end->modify($this->getParameter('orc_booking.schedule.calendar.lookahead'));
  4215.             } else {
  4216.                 $end = \DateTime::createFromFormat('Y-m-d H:i:s'$input_end ' 23:59:59');
  4217.                 $end->modify('+1 day');
  4218.                 $end->setTime(000);
  4219.             }
  4220.             if ($start <= $now) {
  4221.                 $start = clone $now;
  4222.                 // $start = $this->determineCalendarQueryStartForProcess(
  4223.                 //     $start, $bookingProcessBooking, $hoursOfOperationRepository,
  4224.                 //     $this->endTimeCalculator, $hoursChangeRepository
  4225.                 // );
  4226.             }
  4227.             $availableDays $this->scheduleAvailabilityCMMVP1Service->getServiceAvailability($this->client$bookingProcessBooking->getService(), $start$end$bookingProcessBooking->getRegions(), $this->endTimeCalculator->getTimeRequiredForProcess($bookingProcessBooking), $bookingProcessBooking);
  4228.             $aavailableDays = [];
  4229.             foreach ($availableDays as $ssdt => $oovalue) {
  4230.                 $oavailability $this->ptimeAvailability(\DateTime::createFromFormat('Y-m-d'$ssdt), null$bookingProcessBooking);
  4231.                 if (count($oavailability) > 0) {
  4232.                     $aavailableDays[$ssdt] = $oovalue;
  4233.                 }
  4234.             }
  4235.             // TODO
  4236.             {
  4237.                 $response = new JsonResponse(
  4238.                     $aavailableDays,
  4239.                     Response::HTTP_OK
  4240.                 );
  4241.                 return $response;
  4242.             }
  4243.             // $response = new Response();
  4244.             // $response->headers->set('Content-Type', 'application/json');
  4245.             // $response->setContent(
  4246.             //     $calendarExtension->getDatesAsJsonEvents(
  4247.             //         []
  4248.             //     )
  4249.             // );
  4250.             //
  4251.             // return $response;
  4252.         } catch (\Throwable $throwable) {
  4253.             $response = new JsonResponse(
  4254.                 [
  4255.                     'message' => $throwable->getMessage(),
  4256.                     'file' => $throwable->getFile(),
  4257.                     'line' => $throwable->getLine(),
  4258.                     'trace' => $throwable->getTrace()
  4259.                 ],
  4260.                 Response::HTTP_INTERNAL_SERVER_ERROR
  4261.             );
  4262.             return $response;
  4263.         }
  4264.     }
  4265.     public function ptimeAvailability(\DateTime $day$schedule_type nullBookingProcessBooking $bookingProcessBooking)
  4266.     {
  4267.         $now = new \DateTime();
  4268.         $nowpluscutoff = clone $now;
  4269.         $nowpluscutoff->modify(sprintf('+%d hours'$bookingProcessBooking->getService()->getCutofftime()));
  4270.         $available_times = [];
  4271.         $available_times_gap = [];
  4272.         $available_times_exact = [];
  4273.         $start = clone $day;
  4274.         if ($start < new \DateTime('today')) {
  4275.             $start = new \DateTime();
  4276.         }
  4277.         $end = clone $day;
  4278.         $end->modify('+1 day');
  4279.         $date $day;
  4280.         $publicInterval $this->baseService->round15($bookingProcessBooking->getService()->getBaseTime());
  4281.         $requiredTime $this->endTimeCalculator->getTimeRequiredForProcess($bookingProcessBooking);
  4282.         $qb_crews $this->entityManager->createQueryBuilder();
  4283.         $debugging false;
  4284.         // if ($day->format('Y-m-d') === '2023-12-28') {
  4285.         //     $debugging = true;
  4286.         // }
  4287.         if ($debugging) {
  4288.             dump($day->format('Y-m-d'));
  4289.         }
  4290.         $qb_crews
  4291.             ->select([
  4292.                 'crew' ' AS ocrew',
  4293.                 $qb_crews->expr()->count('b.id') . ' AS count_b',
  4294.                 'r.id AS radius_id',
  4295.                 'rl.latitude AS radius_latitude',
  4296.                 'rl.longitude AS radius_longitude',
  4297.                 'r.radius AS radius_size'
  4298.             ])
  4299.             ->from('Orc\BookingBundle\Entity\Crew''crew')
  4300.             ->innerJoin('crew.services''service'Expr\Join::WITH$qb_crews->expr()->eq('service'':service'))
  4301.             ->innerJoin('crew.regions''region'Expr\Join::WITH$qb_crews->expr()->in('region'':regions'))
  4302.             ->leftJoin('crew.bookings''b'Expr\Join::WITH"DATE_FORMAT(b.dateStart, '%Y-%m-%d') = :start AND b.radius IS NOT NULL")
  4303.             ->leftJoin('b.radius''r')
  4304.             ->leftJoin('r.location''rl')
  4305.             //->andWhere($qb_crews->expr()->eq('crew.status', ':status_active'))
  4306.             ->andWhere($qb_crews->expr()->eq('crew.status'':status_active'))
  4307.             ->andWhere($qb_crews->expr()->eq('crew.active'true));
  4308.         $qb_crews
  4309.             ->addGroupBy('crew.id')
  4310.             ->setParameter('service'$bookingProcessBooking->getService())
  4311.             ->setParameter('regions'$bookingProcessBooking->getRegions())
  4312.             ->setParameter('status_active'Crew::STATUS_ACTIVE)
  4313.             ->setParameter('start'$start->format("Y-m-d"));
  4314.         $acrews $qb_crews
  4315.             ->getQuery()
  4316.             ->getResult();
  4317.         if ($debugging) {
  4318.             //dump(['$acrews' => $acrews]);
  4319.         }
  4320.         // dump(array_map(function($o) { return [
  4321.         //     'count_b' => $o['count_b'],
  4322.         //     'radius_id' => $o['radius_id'],
  4323.         //     'radius_latitude' => $o['radius_latitude'],
  4324.         //     'radius_longitude' => $o['radius_longitude'],
  4325.         //     'radius_size' => $o['radius_size'],
  4326.         //     'id' => $o['ocrew']->getId(),
  4327.         //     'name' => $o['ocrew']->getName(),
  4328.         //     'regions' => array_map(function ($oo) {
  4329.         //         return [
  4330.         //             'id' => $oo->getId(),
  4331.         //             'name' => $oo->getName()
  4332.         //         ];
  4333.         //     },$o['ocrew']->getRegions()->toArray())
  4334.         // ]; }, $acrews));
  4335.         $crews array_map(function ($o) {
  4336.             return $o['ocrew']; }, $acrews);
  4337.         $mapradiuscrew = [];
  4338.         foreach ($acrews as $o) {
  4339.             $mapradiuscrew[$o['ocrew']->getId()] = [
  4340.                 'crew_id' => $o['ocrew']->getId(),
  4341.                 'count_b' => $o['count_b'],
  4342.                 'radius_id' => $o['radius_id'],
  4343.                 'radius_latitude' => $o['radius_latitude'],
  4344.                 'radius_longitude' => $o['radius_longitude'],
  4345.                 'radius_size' => $o['radius_size']
  4346.             ];
  4347.         }
  4348.         //$bookableHours = $this->getBookableHours($this->request, $day);
  4349.         $gaps = [];
  4350.         $gaps_morning = [];
  4351.         $gaps_afternoon = [];
  4352.         $gaps_evening = [];
  4353.         $is_anytime_available false;
  4354.         $is_morning_available false;
  4355.         $is_afternoon_available false;
  4356.         $is_evening_available false;
  4357.         $is_anytime_actually_available false;
  4358.         $is_morning_actually_available false;
  4359.         $is_afternoon_actually_available false;
  4360.         $is_evening_actually_available false;
  4361.         // if ($debugging) {
  4362.         //     dump($acrews);
  4363.         // }
  4364.         foreach ($acrews as $oocrew) {
  4365.             $crew $oocrew['ocrew'];
  4366.             $count_b $oocrew['count_b'] != null intval($oocrew['count_b']) : null;
  4367.             $radius_id $oocrew['radius_id'] != null intval($oocrew['radius_id']) : null;
  4368.             $radius_latitude $oocrew['radius_latitude'] != null floatval($oocrew['radius_latitude']) : null;
  4369.             $radius_longitude $oocrew['radius_longitude'] != null floatval($oocrew['radius_longitude']) : null;
  4370.             $radius_size $oocrew['radius_size'] != null floatval($oocrew['radius_size']) : null;
  4371.             $distance null;
  4372.             if (
  4373.                 $bookingProcessBooking != null
  4374.                 && $bookingProcessBooking->getServiceType() !== 'fixed'
  4375.                 && $radius_id !== null
  4376.                 && $radius_latitude !== null
  4377.                 && $radius_longitude !== null
  4378.                 && $radius_size !== null
  4379.                 && $bookingProcessBooking->getLocation() != null
  4380.                 && $bookingProcessBooking->getLocation()->getLatitude() !== null
  4381.                 && $bookingProcessBooking->getLocation()->getLongitude() !== null
  4382.             ) {
  4383.                 $distance $this->distanceCalculator->getDistanceP($radius_latitude$radius_longitude$bookingProcessBooking->getLocation()->getLatitude(), $bookingProcessBooking->getLocation()->getLongitude(), ($this->client->getUnits() == 'km' DistanceCalculator::EARTH_RADIUS_KM DistanceCalculator::EARTH_RADIUS_MILES));
  4384.                 if ($distance $radius_size) {
  4385.                     if ($debugging) {
  4386.                         dump(sprintf('Skipping crew %d'$crew->getId()));
  4387.                     }
  4388.                     continue;
  4389.                 }
  4390.             }
  4391.             // dump([
  4392.             //     'crew' => $crew->getId(),
  4393.             //     'distance' => $distance,
  4394.             //     'radius_size' => $radius_size,
  4395.             // ]);
  4396.             if ($distance <= $radius_size) {
  4397.                 $materialBooking null;
  4398.                 if ($bookingProcessBooking->getProcess() != null && $bookingProcessBooking->getProcess()->getMaterialBooking() != null) {
  4399.                     $materialBooking $this->bookingRepository->findOneBy(['id' => $bookingProcessBooking->getProcess()->getMaterialBooking()->getId()]);
  4400.                 }
  4401.                 $gapInfo $this->scheduleAvailabilityCMMVP1Service->getGapInfo($this->client$crew$date$materialBooking$bookingProcessBooking);
  4402.                 // dump([
  4403.                 //     'crew' => $crew->getId(),
  4404.                 //     '$gapInfo' => $gapInfo
  4405.                 // ]);
  4406.                 //$gapInfo = $this->scheduleAvailabilityCMMVP1Service->getGapInfo($this->client, $crew, $date);
  4407.                 if ($this->client->getCmEnabled() && $day->format('Y-m-d') > $nowpluscutoff->format('Y-m-d')) {
  4408.                     if ($crew->getCanBookAnytime() && $gapInfo['gaps']['anytime'] >= $requiredTime && !$is_anytime_available) {
  4409.                         //$available_times[] = 'gap|anytime';
  4410.                         $is_anytime_available true;
  4411.                     }
  4412.                     if ($crew->getCanBookMorning() && $gapInfo['gaps']['morning'] >= $requiredTime && !$is_morning_available) {
  4413.                         //$available_times[] = 'gap|morning';
  4414.                         $is_morning_available true;
  4415.                     }
  4416.                     if ($crew->getCanBookAfternoon() && $gapInfo['gaps']['afternoon'] >= $requiredTime && !$is_afternoon_available) {
  4417.                         //$available_times[] = 'gap|afternoon';
  4418.                         $is_afternoon_available true;
  4419.                     }
  4420.                     if ($crew->getCanBookEvening() && $gapInfo['gaps']['evening'] >= $requiredTime && !$is_evening_available) {
  4421.                         //$available_times[] = 'gap|evening';
  4422.                         $is_evening_available true;
  4423.                     }
  4424.                 }
  4425.                 $gaps array_merge($gaps$gapInfo['gaps']['gaps']['anytime']);
  4426.                 $gaps_morning array_merge($gaps_morning$gapInfo['gaps']['gaps']['morning']);
  4427.                 $gaps_afternoon array_merge($gaps_afternoon$gapInfo['gaps']['gaps']['afternoon']);
  4428.                 $gaps_evening array_merge($gaps_evening$gapInfo['gaps']['gaps']['evening']);
  4429.             }
  4430.         }
  4431.         if ($debugging) {
  4432.             dump($gaps);
  4433.         }
  4434.         switch ($schedule_type) {
  4435.             case 'morning':
  4436.                 $actual_gaps $gaps_morning;
  4437.                 break;
  4438.             case 'afternoon':
  4439.                 $actual_gaps $gaps_afternoon;
  4440.                 break;
  4441.             case 'evening':
  4442.                 $actual_gaps $gaps_evening;
  4443.                 break;
  4444.             case 'anytime':
  4445.             case 'exact':
  4446.             default:
  4447.                 $actual_gaps $gaps;
  4448.                 break;
  4449.         }
  4450.         uasort($actual_gaps'App\Service\ScheduleAvailabilityCMMVP1Service::block_compare');
  4451.         $i_day_of_week intval($date->format('w'));
  4452.         $hos $this->client->getHoursOfOperation();
  4453.         $ho null;
  4454.         foreach ($hos as $aho) {
  4455.             if ($aho->getDay() == $i_day_of_week) {
  4456.                 $ho $aho;
  4457.                 break;
  4458.             }
  4459.         }
  4460.         if ($debugging) {
  4461.             dump(['$nowpluscutoff' => $nowpluscutoff]);
  4462.         }
  4463.         if ($ho != null && !$ho->getOff()) {
  4464.             $block_morning = [
  4465.                 'start' => $ho->getStartTime()->format('H:i'),
  4466.                 'end' => $ho->getStartTimeAfternoon()->format('H:i')
  4467.             ];
  4468.             $block_afternoon = [
  4469.                 'start' => $ho->getStartTimeAfternoon()->format('H:i'),
  4470.                 'end' => $ho->getStartTimeEvening()->format('H:i')
  4471.             ];
  4472.             $block_evening = [
  4473.                 'start' => $ho->getStartTimeEvening()->format('H:i'),
  4474.                 'end' => $ho->getStartTime()->format('H:i')
  4475.             ];
  4476.             $quarters $this->scheduleAvailabilityCMMVP1Service->getTimeIntervals($ho->getStartTime(), $ho->getEndTime());
  4477.             $bookable_quarters = [];
  4478.             //RoutezillaDebugger::setMark(false, $quarters);
  4479.             //RoutezillaDebugger(false, sprintf('', ''));
  4480.             if (true) {
  4481.                 $bookable_quarters = [];
  4482.                 $i 0;
  4483.                 foreach ($quarters as $quarter) {
  4484.                     $dt_quarter = \DateTime::createFromFormat('Y-m-d H:i:s'sprintf('%s %s:00'$start->format('Y-m-d'), $quarter));
  4485.                     //RoutezillaDebugger::setMark(false, sprintf('LOOPING %d: $quarter = %s', $i, $quarter));
  4486.                     if ($i == 0) {
  4487.                         //RoutezillaDebugger::setMark(false, sprintf('LOOPING %d: $dt_quarter = %s', $i, $dt_quarter->format('Y-m-d H:i:s')));
  4488.                         if (true || $dt_quarter >= $nowpluscutoff) {
  4489.                             $bookable_quarters[] = $quarter;
  4490.                         }
  4491.                     } else {
  4492.                         if (count($bookable_quarters) > 0) {
  4493.                             $last_quarter $bookable_quarters[count($bookable_quarters) - 1];
  4494.                             $dt_lp_quarter = \DateTime::createFromFormat('Y-m-d H:i:s'sprintf('%s %s:00'$start->format('Y-m-d'), $last_quarter));
  4495.                             $dt_lp_quarter->modify(sprintf('+%d minutes'$publicInterval));
  4496.                             if ($dt_quarter >= $dt_lp_quarter) {
  4497.                                 if (true || $dt_quarter $nowpluscutoff) {
  4498.                                     $bookable_quarters[] = $quarter;
  4499.                                 }
  4500.                             }
  4501.                         } else {
  4502.                             if (true || $dt_quarter $nowpluscutoff) {
  4503.                                 $bookable_quarters[] = $quarter;
  4504.                             }
  4505.                         }
  4506.                     }
  4507.                     $i++;
  4508.                 }
  4509.             } else {
  4510.                 $bookable_quarters $quarters;
  4511.             }
  4512.             //RoutezillaDebugger::setMark(true, 'STOP');
  4513.             //dd($quarters);
  4514.             foreach ($bookable_quarters as $quarter) {
  4515.                 $dt_start = clone $date;
  4516.                 $a explode(':'$quarter);
  4517.                 $h intval($a[0]);
  4518.                 $m intval($a[1]);
  4519.                 $dt_start->setTime($h$m0);
  4520.                 $dt_end = clone $dt_start;
  4521.                 $dt_end->modify(sprintf("+%d minutes"$requiredTime));
  4522.                 $block = [
  4523.                     'start' => $dt_start->format('H:i'),
  4524.                     'end' => $dt_end->format('H:i')
  4525.                 ];
  4526.                 // dump([
  4527.                 //     '$block' => $block,
  4528.                 //     '$dt_start' => $dt_start,
  4529.                 //     '$nowpluscutoff' => $nowpluscutoff->format('Y-m-d H:i:s'),
  4530.                 //     '$actual_gaps' => $actual_gaps
  4531.                 // ]);
  4532.                 if ($dt_start >= $nowpluscutoff && $this->scheduleAvailabilityCMMVP1Service->isBlockFitInside($block$actual_gaps)) { {
  4533.                         $is_anytime_actually_available true;
  4534.                     }
  4535.                     if (!$is_morning_actually_available && $this->scheduleAvailabilityCMMVP1Service->isBlockInside($block$block_morning)) {
  4536.                         $is_morning_actually_available true;
  4537.                     }
  4538.                     if (!$is_afternoon_actually_available && $this->scheduleAvailabilityCMMVP1Service->isBlockInside($block$block_afternoon)) {
  4539.                         $is_afternoon_actually_available true;
  4540.                     }
  4541.                     if (!$is_evening_actually_available && $this->scheduleAvailabilityCMMVP1Service->isBlockInside($block$block_evening)) {
  4542.                         $is_evening_actually_available true;
  4543.                     }
  4544.                     if ($this->client->getArrivalWindow() > 0) {
  4545.                         $available_times_exact[] = sprintf('time|%s|%s'$block['start'], $block['end']);
  4546.                     } else {
  4547.                         $available_times_exact[] = sprintf('time|%s|%s'$block['start'], $block['end']);
  4548.                     }
  4549.                 }
  4550.             }
  4551.         }
  4552.         if ($this->client->getCmEnabled()) {
  4553.             if ($is_anytime_actually_available) {
  4554.                 $available_times_gap[] = 'gap|anytime';
  4555.             }
  4556.             if ($is_morning_actually_available) {
  4557.                 $available_times_gap[] = 'gap|morning';
  4558.             }
  4559.             if ($is_afternoon_actually_available) {
  4560.                 $available_times_gap[] = 'gap|afternoon';
  4561.             }
  4562.             if ($is_evening_actually_available) {
  4563.                 $available_times_gap[] = 'gap|evening';
  4564.             }
  4565.         }
  4566.         $available_times array_merge($available_times_gap$available_times_exact);
  4567.         if ($debugging) {
  4568.             dd('END');
  4569.         }
  4570.         return $available_times;
  4571.     }
  4572.     /**
  4573.      * @Route("/booking/process/cm/mvp1/step/datetime/availability/time/{day}", name="booking_process_cm_mvp1_step_datetime_timeavailability")
  4574.      */
  4575.     public function timeAvailability(\DateTime $dayRequest $request)
  4576.     {
  4577.         try {
  4578.             $bookingProcess $this->checkBookingProcess($request);
  4579.             if ($bookingProcess == null) {
  4580.                 $response = new JsonResponse(
  4581.                     'MISSING BOOKING PROCESS',
  4582.                     Response::HTTP_NOT_FOUND
  4583.                 );
  4584.                 return $response;
  4585.             }
  4586.             $bookingProcessBooking $bookingProcess->getBooking();
  4587.             if ($bookingProcess == null) {
  4588.                 $response = new JsonResponse(
  4589.                     'MISSING BOOKING FOR THIS BOOKING PROCESS',
  4590.                     Response::HTTP_NOT_FOUND
  4591.                 );
  4592.                 return $response;
  4593.             }
  4594.             $bookingProcessBookingLocation $bookingProcessBooking->getLocation();
  4595.             if ($bookingProcessBookingLocation == null) {
  4596.                 $response = new JsonResponse(
  4597.                     'MISSING BOOKING LOCATION FOR THIS BOOKING PROCESS',
  4598.                     Response::HTTP_NOT_FOUND
  4599.                 );
  4600.                 return $response;
  4601.             }
  4602.             $available_times $this->ptimeAvailability($daynull$bookingProcessBooking); {
  4603.                 $response = new JsonResponse(
  4604.                     $available_times,
  4605.                     Response::HTTP_OK
  4606.                 );
  4607.                 return $response;
  4608.             }
  4609.         } catch (\Throwable $throwable) {
  4610.             $response = new JsonResponse(
  4611.                 [
  4612.                     'message' => $throwable->getMessage(),
  4613.                     'file' => $throwable->getFile(),
  4614.                     'line' => $throwable->getLine(),
  4615.                     'trace' => $throwable->getTrace()
  4616.                 ],
  4617.                 Response::HTTP_INTERNAL_SERVER_ERROR
  4618.             );
  4619.             return $response;
  4620.         }
  4621.     }
  4622.     /**
  4623.      * @Route("/booking/process/cm/mvp1/step/customer/list", name="booking_process_cm_mvp1_step_customer_list")
  4624.      */
  4625.     public function getCustomers()
  4626.     {
  4627.         $oresponsedata = [];
  4628.         $oresponsestatus Response::HTTP_OK;
  4629.         $user $this->getUser();
  4630.         if ($user == null) {
  4631.             // RETURN EMPTY
  4632.         } else {
  4633.             //$acustomers = $this->customerRepository->findBy([ 'client' => $this->client->getId(), 'deleted' => 0 ]);
  4634.             $acustomers $this->customerRepository->findClientCustomers();
  4635.             $amarked = [];
  4636.             foreach ($acustomers as $ocustomer) {
  4637.                 $smarked sprintf('%s|%s|%s'$ocustomer->getName(), $ocustomer->getEmail(), $ocustomer->getPhone());
  4638.                 if (!in_array($smarked$amarked)) {
  4639.                     $amarked[] = $smarked;
  4640.                     $oresponsedata[] = [
  4641.                         'id' => $ocustomer->getId(),
  4642.                         'name' => $ocustomer->getName(),
  4643.                         'email' => $ocustomer->getEmail(),
  4644.                         'phone' => $ocustomer->getPhone(),
  4645.                         'location' => $ocustomer->getLocation() != null ? [
  4646.                             'id' => $ocustomer->getLocation()->getId(),
  4647.                             'street' => $ocustomer->getLocation()->getStreet(),
  4648.                             'line2' => $ocustomer->getLocation()->getLine2(),
  4649.                             'city' => $ocustomer->getLocation()->getCity(),
  4650.                             'code' => $ocustomer->getLocation()->getCode(),
  4651.                             'province' => $ocustomer->getLocation()->getProvince(),
  4652.                             'country' => $ocustomer->getLocation()->getCountry(),
  4653.                             'latitude' => $ocustomer->getLocation()->getLatitude(),
  4654.                             'longitude' => $ocustomer->getLocation()->getLongitude(),
  4655.                             'address' => $ocustomer->getLocation()->getAddress()
  4656.                         ] : null
  4657.                     ];
  4658.                 }
  4659.             }
  4660.         }
  4661.         return new JsonResponse($oresponsedata$oresponsestatus);
  4662.     }
  4663.     /**
  4664.      * @Route("/booking/process/cm/mvp1/step/customer/notify", name="booking_process_cm_mvp1_step_customer_notify")
  4665.      */
  4666.     public function doCustomerNotify(Request $request)
  4667.     {
  4668.         $sbody $request->getContent();
  4669.         if ($sbody != null) {
  4670.             $customerMailer $this->confirmationMailer;
  4671.             $obody json_decode($sbody);
  4672.             $obooking property_exists($obody'booking') ? $obody->booking null;
  4673.             $oendpoints property_exists($obody'endpoints') ? $obody->endpoints null;
  4674.             $bemail $oendpoints !== null && property_exists($oendpoints'email') ? $oendpoints->email false;
  4675.             $bsms $oendpoints !== null && property_exists($oendpoints'sms') ? $oendpoints->sms false;
  4676.             if ($obooking !== null) {
  4677.                 $booking $this->bookingRepository->findOneBy(['id' => $obooking->id]);
  4678.                 $nnotifications 0;
  4679.                 $sentemail false;
  4680.                 $sentsms false;
  4681.                 if ($bemail) {
  4682.                     try {
  4683.                         $customerMailer->send($booking);
  4684.                         $nnotifications++;
  4685.                         $sendemail true;
  4686.                     } catch (TransportException $e) {
  4687.                         //$this->emailErrors[] = 'Failed to send you an e-mail confirmation at ' . htmlspecialchars($customer->getEmail()) . '. It seems that this e-mail is not valid.';
  4688.                         //$result = self::FAILED_TO_SEND_EMAIL;
  4689.                     }
  4690.                 }
  4691.                 if ($bsms) {
  4692.                     try {
  4693.                         $customerMailer->sendSMS($booking);
  4694.                         $nnotifications++;
  4695.                         $sendemail sms;
  4696.                     } catch (\Throwable $e) {
  4697.                         //$this->emailErrors[] = 'Failed to send you an SMS confirmation to ' . htmlspecialchars($customer->getPhone()) . '.';
  4698.                         //$result = self::FAILED_TO_SEND_EMAIL;
  4699.                     }
  4700.                 }
  4701.                 if ($nnotifications 0) {
  4702.                     $response = new JsonResponse(
  4703.                         [
  4704.                             'icon' => 'success',
  4705.                             'message' => 'NOTIFICATION SENT SUCCESSFULY TO THE CUSTOMER'
  4706.                         ],
  4707.                         Response::HTTP_OK
  4708.                     );
  4709.                 } else {
  4710.                     $response = new JsonResponse(
  4711.                         [
  4712.                             'icon' => 'error',
  4713.                             'message' => 'FAILED TO SEND NOTIFICATIONS',
  4714.                             'email' => $sentemail,
  4715.                             'sms' => $sentsms
  4716.                         ],
  4717.                         Response::HTTP_INTERNAL_SERVER_ERROR
  4718.                     );
  4719.                 }
  4720.             }
  4721.         } else {
  4722.             $response = new JsonResponse(
  4723.                 [
  4724.                     'icon' => 'error',
  4725.                     'message' => 'INVALID NOTIFICATION DATA'
  4726.                 ],
  4727.                 Response::HTTP_BAD_REQUEST
  4728.             );
  4729.         }
  4730.         return $response;
  4731.     }
  4732.     /**
  4733.      * Query schedule for available times, and filter into bookable hours based on service length
  4734.      * @return   DateTime[]
  4735.      */
  4736.     public function getBookableHours(Request $request$date null)
  4737.     {
  4738.         $bookingProcess $this->checkBookingProcess($request);
  4739.         if ($bookingProcess == null) {
  4740.             return [];
  4741.         }
  4742.         $bookingProcessBooking $bookingProcess->getBooking();
  4743.         if ($bookingProcess == null) {
  4744.             return [];
  4745.         }
  4746.         $cutofftime $bookingProcessBooking->getService()->getCutofftime();
  4747.         $publicInterval $this->baseService->round15($bookingProcessBooking->getService()->getBaseTime());
  4748.         if (!$publicInterval) {
  4749.             $publicInterval $this->baseService->round15($bookingProcessBooking->getService()->getBaseTime());
  4750.         }
  4751.         if ($date === null) {
  4752.             $date $bookingProcessBooking->getDateStart();
  4753.             $bookingProcessBooking->setDateEnd($this->endTimeCalculator->getEndTimeForProcess($bookingProcessBooking));
  4754.         }
  4755.         $start = clone $date;
  4756.         $start->modify('-1 day');
  4757.         $end = clone $date;
  4758.         $end->setTime(00);
  4759.         $end->modify('+1 day');
  4760.         // if ( $booking->getStatus() == BookingStatus::STATUS_UNASSIGNABLE) {
  4761.         //     $start = clone $date;
  4762.         //     $end = clone $date;
  4763.         //     $maxHoursOfOperation = $this->hoursOfOperationRepository->getMaxHoursOfOperation();
  4764.         //     $earliestTimeHour = (int)(new \DateTime($maxHoursOfOperation[0]['earliestTime']))->format('H');
  4765.         //     $earliestTimeMinutes = (int)(new \DateTime($maxHoursOfOperation[0]['earliestTime']))->format('i');
  4766.         //     $latestTimeHour = (int)(new \DateTime($maxHoursOfOperation[0]['latestTime']))->format('H');
  4767.         //     $latestTimeMinutes = (int)(new \DateTime($maxHoursOfOperation[0]['latestTime']))->format('i');
  4768.         //     $start->setTime($earliestTimeHour, $earliestTimeMinutes);
  4769.         //     $end->setTime($latestTimeHour, $latestTimeMinutes);
  4770.         // }
  4771.         $this->scheduler->setRange($start$end);
  4772.         $availableSlots $this->scheduler->getAvailableTimeSlotsForProcess($this->client$bookingProcessBooking);
  4773.         $todaysSlots array_filter($availableSlots, function ($slot) use ($date) {
  4774.             return $slot->format('Y-m-d') == $date->format('Y-m-d');
  4775.         });
  4776.         $bookable = array();
  4777.         $i 0;
  4778.         foreach ($todaysSlots as $slot) {
  4779.             if ($i == 0) {
  4780.                 if ($slot >= (new \DateTime)->modify($cutofftime ' hours')) {
  4781.                     $bookable[] = $slot;
  4782.                 }
  4783.                 $lastTestedSlot $slot;
  4784.             } else {
  4785.                 if ($bookable) {
  4786.                     $lastSlot = clone $bookable[count($bookable) - 1];
  4787.                     if ($slot >= $lastSlot->modify('+' $publicInterval ' minutes')) {
  4788.                         if ($slot > (new \DateTime)->modify($cutofftime ' hours')) {
  4789.                             $bookable[] = $slot;
  4790.                         }
  4791.                     }
  4792.                 } else {
  4793.                     if ($slot >= (new \DateTime)->modify($cutofftime ' hours')) {
  4794.                         $bookable[] = $slot;
  4795.                     }
  4796.                 }
  4797.             }
  4798.             $i++;
  4799.         }
  4800.         return $bookable;
  4801.     }
  4802.     /**
  4803.      * Gets the Region containing Location, if any
  4804.      * @param    Location
  4805.      * @return   Region|null
  4806.      */
  4807.     protected function getRegion(Location $location)
  4808.     {
  4809.         $point $this->locationToCoordinates($location);
  4810.         foreach ($this->regionRepository->findAll() as $region) {
  4811.             $polygon array_map(
  4812.                 array($this'locationToCoordinates'),
  4813.                 $region->getBoundaries()->toArray()
  4814.             );
  4815.             if ($this->pointInPolygon->inPolygon($point$polygon)) {
  4816.                 return $region;
  4817.             }
  4818.         }
  4819.         return false;
  4820.     }
  4821.     protected function getAddress($request)
  4822.     {
  4823.         return trim(
  4824.             sprintf(
  4825.                 '%s%s, %s, %s, %s',
  4826.                 $request->request->get('street'),
  4827.                 $request->request->get('line2') ? ' ' $request->request->get('line2') : '',
  4828.                 $request->request->get('city'),
  4829.                 $request->request->get('province'),
  4830.                 $request->request->get('code')
  4831.             ),
  4832.             ' ,'
  4833.         );
  4834.     }
  4835.     private function verifyServiceFieldsNext($bookingProcess): RedirectResponse
  4836.     {
  4837.         $allfields $bookingProcess->getBooking()->getService()->getFields();
  4838.         $fields = [];
  4839.         foreach ($allfields as $field) {
  4840.             if ($field->getIsActive() && $field->getQuestion() != null && $field->getQuestion() != '') {
  4841.                 $fields[] = $field;
  4842.             }
  4843.         }
  4844.         if (count($fields) > 0) {
  4845.             $this->setGoToScreenOnBookingProcess($bookingProcess'input-servicefields');
  4846.             return $this->redirect($this->generateUrl($this->screensmap['input-servicefields']));
  4847.         } else {
  4848.             $this->setGoToScreenOnBookingProcess($bookingProcess'input-datetime');
  4849.             return $this->redirect($this->generateUrl($this->screensmap['input-datetime']));
  4850.         }
  4851.     }
  4852. }