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