src/AdminBundle/Entity/Booking.php line 22

Open in your IDE?
  1. <?php
  2. namespace AdminBundle\Entity;
  3. use AdminBundle\Utils\DateTimeUtils;
  4. use Doctrine\Common\Collections\ArrayCollection;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Doctrine\ORM\Mapping as ORM;
  7. use Doctrine\ORM\Mapping\OrderBy;
  8. use Symfony\Component\Validator\Constraints as Assert;
  9. use Symfony\Component\Validator\Constraints\DateTime;
  10. #[ORM\Table(name: 'booking')]
  11. #[ORM\Index(name: 'status_date_index', columns: ['booking_status', 'pick_up_date', 'pick_up_time'])]
  12. #[ORM\Index(name: 'pickup_address_index', columns: ['pick_up_address', 'booking_status'])]
  13. #[ORM\Index(name: 'destination_address_index', columns: ['destination_address', 'booking_status'])]
  14. #[ORM\Index(name: 'client_first_name_index', columns: ['client_first_name', 'booking_status'])]
  15. #[ORM\Index(name: 'client_last_name_index', columns: ['client_last_name', 'booking_status'])]
  16. #[ORM\Index(name: 'client_email_index', columns: ['client_email', 'booking_status'])]
  17. #[ORM\Index(name: 'client_phone_index', columns: ['client_phone', 'booking_status'])]
  18. #[ORM\Entity(repositoryClass: \AdminBundle\Repository\BookingRepository::class)]
  19. class Booking extends BaseEntity
  20. {
  21. const STATUS_DELETED = 0;
  22. const STATUS_NEW_BOOKING = 1; //New booking in the web app system - not allocated/not dispatched
  23. const STATUS_DISPATCHED = 10; //Booking Dispatched to specific driver X
  24. const STATUS_DRIVER_REJECT = 11; //Driver X reject booking
  25. const STATUS_DRIVER_ACCEPT = 12; // Driver X accept booking
  26. const STATUS_ON_THE_WAY = 13; // The driver is on the way
  27. const STATUS_ARRIVED_AND_WAITING = 14; // The driver arrived and waiting passenger
  28. const STATUS_PASSENGER_ON_BOARD = 15; // Passenger up to car
  29. const STATUS_ABOUT_TO_DROP = 16; // almost at destination
  30. const STATUS_COMPLETED = 17;
  31. const STATUS_BROADCAST = 20; // booking sent to all available / qualified drivers
  32. const STATUS_DEALLOCATED_ON_DEMAND = 25; //Before pick up
  33. const STATUS_DEALLOCATED_LATE_PICKUP = 26; //Before pick up
  34. const STATUS_DEALLOCATED_NO_LONGER_AVAILABLE = 27; //Before pick up
  35. const STATUS_DEALLOCATED_CAR_BROKE_DOWN = 28; //Before pick up
  36. const STATUS_DEALLOCATED_OFFICE = 29; //Before pick up
  37. const STATUS_CANCELLED_OTHER_REASON = 30; //Cancellation with no defined reason
  38. const STATUS_CLIENT_CANCELLATION = 31;
  39. const STATUS_CLIENT_NOT_SHOW_UP = 32;
  40. const STATUS_CAR_BROKE_DOWN = 33; // the part with timer
  41. const STATUS_OFFICE_CANCELLATION = 34; //headquarter initiated cancellation
  42. const STATUS_PENDING = 90; //New booking but not paid ( external sources - website )
  43. const STATUS_PENDING_CANCELLATION = 91; //Special status from the office due to non payment
  44. public static $statusTypes = [
  45. self::STATUS_DELETED => 'Deleted',
  46. self::STATUS_NEW_BOOKING => 'New booking',
  47. self::STATUS_DISPATCHED => 'Dispatched',
  48. self::STATUS_DRIVER_REJECT => 'Dispatched reject',
  49. self::STATUS_DRIVER_ACCEPT => 'Dispatched accept',
  50. self::STATUS_ON_THE_WAY => 'On the way',
  51. self::STATUS_ARRIVED_AND_WAITING => 'Arrived and waiting',
  52. self::STATUS_PASSENGER_ON_BOARD => 'Passenger on board',
  53. self::STATUS_ABOUT_TO_DROP => 'About to drop',
  54. self::STATUS_COMPLETED => 'Completed',
  55. self::STATUS_BROADCAST => 'Broadcast',
  56. self::STATUS_DEALLOCATED_ON_DEMAND => 'Deallocated on demand',
  57. self::STATUS_DEALLOCATED_LATE_PICKUP => 'Deallocated - Late for pickup',
  58. self::STATUS_DEALLOCATED_NO_LONGER_AVAILABLE => 'Deallocated - No longer available',
  59. self::STATUS_DEALLOCATED_CAR_BROKE_DOWN => 'Deallocated - Car broke down',
  60. self::STATUS_DEALLOCATED_OFFICE => 'Deallocated - Office Deallocation',
  61. self::STATUS_CANCELLED_OTHER_REASON => 'Cancelled Other Reason',
  62. self::STATUS_CLIENT_CANCELLATION => 'Client cancellation',
  63. self::STATUS_CLIENT_NOT_SHOW_UP => 'Client didn’t show up',
  64. self::STATUS_CAR_BROKE_DOWN => 'Car broke down',
  65. self::STATUS_OFFICE_CANCELLATION => 'Office cancellation',
  66. self::STATUS_PENDING => 'Pending',
  67. self::STATUS_PENDING_CANCELLATION => 'Pending Cancellation',
  68. ];
  69. const CREATED_BY_DISPATCH = 'DISPATCH';
  70. const CREATED_BY_APP = 'APP';
  71. const CREATED_BY_CLIENT = 'CLIENT';
  72. const SOURCE_TYPE_FORM = 0;
  73. const SOURCE_TYPE_MOBILE = 1;
  74. const SOURCE_TYPE_ADMIN = 2;
  75. public static $sourceTypes = [
  76. self::SOURCE_TYPE_FORM => 'Booking Form',
  77. self::SOURCE_TYPE_MOBILE => 'Mobile',
  78. self::SOURCE_TYPE_ADMIN => 'Admin',
  79. ];
  80. /**
  81. * @var integer
  82. */
  83. #[ORM\Column(name: 'id', type: 'integer', nullable: false)]
  84. #[ORM\Id]
  85. #[ORM\GeneratedValue(strategy: 'IDENTITY')]
  86. protected $id;
  87. /**
  88. * @var string
  89. */
  90. #[ORM\Column(name: 'booking_key', type: 'string', length: 255, nullable: false, unique: true)]
  91. protected $key;
  92. /**
  93. * @var integer
  94. */
  95. #[ORM\Column(name: 'booking_status', type: 'integer')]
  96. protected $status = self::STATUS_PENDING;
  97. /**
  98. * @var integer
  99. */
  100. #[ORM\Column(name: 'return_booking_id', type: 'integer')]
  101. protected $returnBookingId;
  102. /**
  103. * @var integer
  104. */
  105. #[ORM\Column(name: 'drivers_confirmed_number', type: 'integer')]
  106. protected $driversConfirmedNumber = 0;
  107. /**
  108. * @var CarType
  109. */
  110. #[ORM\JoinColumn(name: 'car_type_id', referencedColumnName: 'id')]
  111. #[ORM\ManyToOne(targetEntity: \AdminBundle\Entity\CarType::class)]
  112. protected $carType;
  113. /**
  114. * @var integer
  115. */
  116. #[ORM\Column(name: 'payment_type', type: 'integer', nullable: false)]
  117. protected $paymentType = Payment::TYPE_CARD;
  118. /**
  119. * @var float
  120. */
  121. #[ORM\Column(name: 'quote_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  122. #[Assert\NotBlank]
  123. protected $quotePrice = 0;
  124. /**
  125. * @var float
  126. */
  127. #[ORM\Column(name: 'original_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  128. protected $originalPrice = 0;
  129. /**
  130. * @var float
  131. */
  132. #[ORM\Column(name: 'override_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  133. protected $overridePrice = 0;
  134. /**
  135. * @var string
  136. */
  137. #[ORM\Column(name: 'flight_number', type: 'string', length: 260, nullable: true)]
  138. protected $flightNumber;
  139. /**
  140. * @var \DateTime
  141. */
  142. #[ORM\Column(name: 'flight_landing_time', type: 'time', nullable: true)]
  143. protected $flightLandingTime;
  144. /**
  145. * @var \DateTime
  146. */
  147. #[ORM\Column(name: 'waiting_time', type: 'time', nullable: true)]
  148. protected $waitingTime;
  149. /**
  150. * @var \DateTime
  151. */
  152. #[ORM\Column(name: 'job_waiting_time', type: 'time', nullable: true)]
  153. protected $jobWaitingTime;
  154. /**
  155. * @var string
  156. */
  157. #[ORM\Column(name: 'return_flight_number', type: 'string', length: 260, nullable: true)]
  158. protected $returnFlightNumber;
  159. /**
  160. * @var \DateTime
  161. */
  162. #[ORM\Column(name: 'return_flight_landing_time', type: 'time', nullable: true)]
  163. protected $returnFlightLandingTime;
  164. /**
  165. * @var float
  166. */
  167. #[ORM\Column(name: 'driver_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  168. protected $driverPrice;
  169. /**
  170. * @var float
  171. */
  172. #[ORM\Column(name: 'return_driver_price', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  173. protected $returnDriverPrice;
  174. /**
  175. * @var float
  176. */
  177. #[ORM\Column(name: 'initial_amount_payment', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  178. protected $initialAmountPayment;
  179. /**
  180. * @var string
  181. */
  182. #[ORM\Column(name: 'payment_reference', type: 'string', nullable: true, length: 255)]
  183. protected $paymentReference;
  184. /**
  185. * @var float
  186. */
  187. #[ORM\Column(name: 'cc_fee', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  188. protected $ccFee;
  189. /**
  190. * @var float
  191. */
  192. #[ORM\Column(name: 'distance_unit', type: 'float', nullable: true)]
  193. #[Assert\NotBlank]
  194. protected $distanceUnit;
  195. /**
  196. * @var string
  197. */
  198. #[Assert\NotBlank]
  199. #[ORM\Column(name: 'estimated_time', type: 'text', nullable: true, length: 255)]
  200. protected $estimatedTime;
  201. /**
  202. * @var \DateTime
  203. */
  204. #[ORM\Column(name: 'booking_date', type: 'datetime', nullable: true)]
  205. protected $bookingDate;
  206. /**
  207. * @var \DateTime
  208. */
  209. #[ORM\Column(name: 'expire_broadcast_date', type: 'datetime', nullable: true)]
  210. protected $expireBroadcastDate;
  211. /**
  212. * @var Driver
  213. */
  214. #[ORM\JoinColumn(name: 'driver_id', referencedColumnName: 'id')]
  215. #[ORM\ManyToOne(targetEntity: \Driver::class, inversedBy: 'bookings')]
  216. protected $driver;
  217. /**
  218. * @var Car
  219. */
  220. #[ORM\JoinColumn(name: 'car_id', referencedColumnName: 'id')]
  221. #[ORM\ManyToOne(targetEntity: \Car::class)]
  222. protected $car;
  223. /**
  224. * @var string
  225. */
  226. #[ORM\Column(name: 'pick_up_address', type: 'string', length: 255, nullable: false)]
  227. protected $pickUpAddress;
  228. /**
  229. * @var string
  230. */
  231. #[ORM\Column(name: 'pick_up_map_address', type: 'string', length: 255, nullable: true)]
  232. protected $pickUpMapAddress;
  233. /**
  234. * @var float
  235. */
  236. #[ORM\Column(name: 'pmg', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  237. protected $pmg;
  238. /**
  239. * @var float
  240. */
  241. #[ORM\Column(name: 'return_pmg', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  242. protected $returnPmg;
  243. /**
  244. * @var float
  245. */
  246. #[ORM\Column(name: 'pick_up_lat', type: 'float', precision: 10, scale: 6, nullable: true)]
  247. protected $pickUpLat;
  248. /**
  249. * @var float
  250. */
  251. #[ORM\Column(name: 'pick_up_lng', type: 'float', precision: 10, scale: 6, nullable: true)]
  252. protected $pickUpLng;
  253. /**
  254. * @var string
  255. */
  256. #[ORM\Column(name: 'pick_up_post_code', type: 'string', length: 10)]
  257. protected $pickUpPostCode;
  258. /**
  259. * @var \DateTime
  260. */
  261. #[ORM\Column(name: 'pick_up_date', type: 'datetime', nullable: false)]
  262. protected $pickUpDate;
  263. /**
  264. * @var \DateTime
  265. */
  266. #[ORM\Column(name: 'pick_up_time', type: 'time', nullable: false)]
  267. protected $pickUpTime;
  268. /**
  269. * @var \DateTime
  270. */
  271. #[ORM\Column(name: 'pick_up_date_time', type: 'datetime', nullable: true)]
  272. protected $pickUpDateTime;
  273. /**
  274. * @var \DateTime
  275. */
  276. #[ORM\Column(name: 'return_pick_up_date', type: 'datetime', nullable: true)]
  277. protected $returnPickUpDate;
  278. /**
  279. * @var \DateTime
  280. */
  281. #[ORM\Column(name: 'return_pick_up_time', type: 'time', nullable: true)]
  282. protected $returnPickUpTime;
  283. /**
  284. * @var string
  285. */
  286. #[ORM\Column(name: 'destination_address', type: 'string', length: 255, nullable: false)]
  287. protected $destinationAddress;
  288. /**
  289. * @var string
  290. */
  291. #[ORM\Column(name: 'destination_map_address', type: 'string', length: 255, nullable: true)]
  292. protected $destinationMapAddress;
  293. /**
  294. * @var float
  295. */
  296. #[ORM\Column(name: 'destination_lat', type: 'float', precision: 10, scale: 6, nullable: true)]
  297. protected $destinationLat;
  298. /**
  299. * @var float
  300. */
  301. #[ORM\Column(name: 'destination_lng', type: 'float', precision: 10, scale: 6, nullable: true)]
  302. protected $destinationLng;
  303. /**
  304. * @var string
  305. */
  306. #[ORM\Column(name: 'destination_post_code', type: 'string', length: 10)]
  307. protected $destinationPostCode;
  308. /**
  309. * @var integer
  310. */
  311. #[ORM\Column(name: 'passengers_number', type: 'integer', nullable: true)]
  312. protected $passengersNumber = 1;
  313. /**
  314. * @var integer
  315. */
  316. #[ORM\Column(name: 'match_job', type: 'integer', nullable: true)]
  317. protected $matchJob;
  318. /**
  319. * @var string
  320. */
  321. #[ORM\Column(name: 'hand_luggage', type: 'string', length: 64, nullable: true)]
  322. protected $handLuggage = 0;
  323. /**
  324. * @var string
  325. */
  326. #[ORM\Column(name: 'checkin_luggage', type: 'string', length: 64, nullable: true)]
  327. protected $checkinLuggage = 0;
  328. /**
  329. * @var string
  330. */
  331. #[ORM\Column(name: 'notes', type: 'text', nullable: true)]
  332. protected $notes;
  333. /**
  334. * @var string
  335. */
  336. #[ORM\Column(name: 'operator_notes', type: 'text', nullable: true)]
  337. protected $operatorNotes;
  338. /**
  339. * @var string
  340. */
  341. #[ORM\Column(name: 'return_booking_notes', type: 'text', nullable: true)]
  342. protected $returnBookingNotes;
  343. /**
  344. * @var string
  345. */
  346. #[ORM\Column(name: 'client_first_name', type: 'string', length: 64, nullable: true)]
  347. protected $clientFirstName;
  348. /**
  349. * @var string
  350. */
  351. #[ORM\Column(name: 'client_last_name', type: 'string', length: 64, nullable: true)]
  352. protected $clientLastName;
  353. /**
  354. * @var string
  355. */
  356. #[ORM\Column(name: 'client_phone', type: 'string', length: 64, nullable: true)]
  357. protected $clientPhone;
  358. /**
  359. * @var string
  360. */
  361. #[ORM\Column(name: 'client_email', type: 'string', length: 64, nullable: true)]
  362. protected $clientEmail;
  363. /**
  364. * @var string
  365. */
  366. #[ORM\Column(name: 'client_alternative_phone', type: 'string', length: 64, nullable: true)]
  367. protected $clientAlternativePhone;
  368. /**
  369. * @var string
  370. */
  371. #[ORM\Column(name: 'client_alternative_email', type: 'string', length: 64, nullable: true)]
  372. protected $clientAlternativeEmail;
  373. /**
  374. * @var ArrayCollection
  375. */
  376. #[ORM\OneToMany(targetEntity: \BookingViasAddress::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
  377. protected $vias;
  378. #[ORM\OneToMany(targetEntity: \BookingBookingExtra::class, mappedBy: 'booking', cascade: ['persist'])]
  379. protected $extras;
  380. /**
  381. * @var User
  382. */
  383. #[ORM\JoinColumn(name: 'user_id', referencedColumnName: 'id', nullable: true)]
  384. #[ORM\ManyToOne(targetEntity: \User::class, inversedBy: 'clientBookings', cascade: ['all'])]
  385. protected $clientUser;
  386. /**
  387. * @var string
  388. */
  389. #[ORM\Column(name: 'voucher_code', type: 'string', length: 64, nullable: true)]
  390. protected $voucherCode;
  391. /**
  392. * @var string
  393. */
  394. #[ORM\Column(name: 'voucher_value', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  395. protected $voucherValue;
  396. /**
  397. * @var Payment
  398. */
  399. #[ORM\JoinColumn(name: 'payment_id', referencedColumnName: 'id', onDelete: 'SET NULL', nullable: true)]
  400. #[ORM\OneToOne(targetEntity: \AdminBundle\Entity\Payment::class, inversedBy: 'booking')]
  401. private $payment;
  402. /**
  403. * @var boolean
  404. */
  405. #[ORM\Column(name: 'create_account', type: 'boolean')]
  406. private $createAccount = true;
  407. /**
  408. * @var boolean
  409. */
  410. #[ORM\Column(name: 'flight_landing_time_was_changed', type: 'boolean')]
  411. private $flightLandingTimeWasChanged = false;
  412. /**
  413. * @var boolean
  414. */
  415. #[ORM\Column(name: 'automatic_assignment', type: 'boolean')]
  416. private $automaticAssignment = false;
  417. /**
  418. * @var boolean
  419. */
  420. #[ORM\Column(name: 'need_send_to_driver', type: 'boolean')]
  421. private $needSendToDriver = false;
  422. /**
  423. * @var Booking
  424. */
  425. #[ORM\JoinColumn(name: 'return_booking_id', referencedColumnName: 'id')]
  426. #[ORM\OneToOne(targetEntity: \Booking::class, inversedBy: 'parentBooking', cascade: ['persist', 'remove'])]
  427. protected $returnBooking;
  428. /**
  429. * @var Booking
  430. */
  431. #[ORM\OneToOne(targetEntity: \Booking::class, mappedBy: 'returnBooking')]
  432. protected $parentBooking;
  433. /**
  434. * @var float
  435. */
  436. #[ORM\Column(name: 'cancel_refund', type: 'decimal', precision: 7, scale: 2, nullable: true)]
  437. protected $cancelRefund;
  438. /**
  439. * @var string
  440. */
  441. #[ORM\Column(name: 'cancel_reason', type: 'string', nullable: true)]
  442. protected $cancelReason;
  443. /**
  444. * @var ArrayCollection
  445. */
  446. #[ORM\OneToMany(targetEntity: \BroadcastedDriver::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
  447. protected $broadcastedDrivers;
  448. /**
  449. * @var ArrayCollection
  450. */
  451. #[ORM\OneToMany(targetEntity: \UnassignedBookingsDriverRequests::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
  452. protected $unassignedDriverRequests;
  453. /**
  454. * @var ArrayCollection
  455. */
  456. #[ORM\OneToMany(targetEntity: \BookingHistory::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
  457. #[OrderBy(['date' => 'ASC'])]
  458. public $bookingHistory;
  459. /**
  460. * @var ArrayCollection
  461. */
  462. #[ORM\OneToMany(targetEntity: \AdminBundle\Entity\NotificationBookingUpdate::class, mappedBy: 'booking', cascade: ['persist', 'remove'], orphanRemoval: true)]
  463. public $notificationBooking;
  464. /**
  465. * @var string
  466. */
  467. #[ORM\Column(name: 'booking_data_serialized', type: 'json', nullable: true)]
  468. private $bookingDataSerialized;
  469. /**
  470. * @var ClientInvoices
  471. */
  472. #[ORM\OneToOne(targetEntity: \AdminBundle\Entity\ClientInvoices::class, mappedBy: 'booking')]
  473. protected $clientInvoice;
  474. /**
  475. * @var ArrayCollection
  476. */
  477. #[ORM\OneToMany(targetEntity: \AdminBundle\Entity\VoipRecord::class, mappedBy: 'booking')]
  478. protected $voipRecords;
  479. /**
  480. * @var \DateTime
  481. */
  482. #[ORM\Column(name: 'last_opened_date', type: 'datetime', nullable: true)]
  483. protected $lastOpenedDate;
  484. /**
  485. * @var string
  486. */
  487. #[ORM\Column(name: 'last_opened_user', type: 'string', nullable: true)]
  488. protected $lastOpenedUser;
  489. /**
  490. * @var \DateTime
  491. */
  492. #[ORM\Column(name: 'send_notification_undispatched', type: 'datetime', nullable: true)]
  493. protected $sendNotificationUndispatched;
  494. public $linked_booking;
  495. /**
  496. * @var float
  497. */
  498. #[ORM\Column(name: 'booking_form_cc_fee', type: 'float', nullable: false, options: ['default' => 0])]
  499. protected $bookingformCCFee = 0;
  500. /**
  501. * @var string
  502. */
  503. #[ORM\Column(name: 'pickup_address_category', type: 'string', nullable: true, length: 255)]
  504. protected $pickupAddressCategory;
  505. /**
  506. * @var \DateTime
  507. */
  508. #[ORM\Column(name: 'unassigned_hide_at', type: 'datetime', nullable: true)]
  509. protected $unassignedHideAt;
  510. /**
  511. * @var string
  512. */
  513. #[ORM\Column(name: 'dropoff_address_category', type: 'string', nullable: true, length: 255)]
  514. protected $dropoffAddressCategory;
  515. #[ORM\OneToMany(targetEntity: \Ticket::class, mappedBy: 'bookingId', cascade: ['remove'])]
  516. protected $tickets;
  517. /**
  518. * @var int
  519. */
  520. #[ORM\Column(name: 'booking_source_type', type: 'integer', nullable: true)]
  521. protected $bookingSourceType;
  522. /**
  523. * unmapped property
  524. *
  525. * @var bool
  526. */
  527. protected $isLiveUpdateNotificationSent = false;
  528. public function __construct()
  529. {
  530. $this->driversConfirmedNumber = 0;
  531. $this->bookingformCCFee = 0;
  532. $this->bookingDate = new \DateTime();
  533. $this->vias = new ArrayCollection();
  534. $this->extras = new ArrayCollection();
  535. $this->broadcastedDrivers = new ArrayCollection();
  536. $this->bookingHistory = new ArrayCollection();
  537. $this->notificationBooking = new ArrayCollection();
  538. $this->tickets = new ArrayCollection();
  539. $this->generateKey();
  540. }
  541. public function generateKey()
  542. {
  543. $length = 8;
  544. $this->setKey(strtoupper(substr(md5(uniqid()), mt_rand(0, 31 - $length), $length)));
  545. }
  546. /**
  547. * @return int
  548. */
  549. public function getId()
  550. {
  551. return $this->id;
  552. }
  553. /**
  554. * @param int $id
  555. */
  556. public function setId($id)
  557. {
  558. $this->id = $id;
  559. }
  560. /**
  561. * @return string
  562. */
  563. public function getKey()
  564. {
  565. return $this->key;
  566. }
  567. /**
  568. * @param string $key
  569. */
  570. public function setKey($key)
  571. {
  572. $this->key = $key;
  573. }
  574. /**
  575. * @return \DateTime
  576. */
  577. public function getExpireBroadcastDate()
  578. {
  579. return $this->expireBroadcastDate;
  580. }
  581. /**
  582. * @param \DateTime $expireBroadcastDate
  583. */
  584. public function setExpireBroadcastDate($expireBroadcastDate)
  585. {
  586. $this->expireBroadcastDate = $expireBroadcastDate;
  587. }
  588. /**
  589. * @return float
  590. */
  591. public function getQuotePrice()
  592. {
  593. return $this->quotePrice;
  594. }
  595. /**
  596. * @param float $quotePrice
  597. *
  598. * @return Booking
  599. */
  600. public function setQuotePrice($quotePrice): self
  601. {
  602. $this->quotePrice = $quotePrice;
  603. return $this;
  604. }
  605. /**
  606. * @return float
  607. */
  608. public function getOriginalPrice()
  609. {
  610. return $this->originalPrice;
  611. }
  612. /**
  613. * @param float $originalPrice
  614. */
  615. public function setOriginalPrice($originalPrice)
  616. {
  617. $this->originalPrice = $originalPrice;
  618. }
  619. /**
  620. * @return float
  621. */
  622. public function getOverridePrice()
  623. {
  624. return $this->overridePrice;
  625. }
  626. /**
  627. * @param float $overridePrice
  628. *
  629. * @return Booking
  630. */
  631. public function setOverridePrice($overridePrice): self
  632. {
  633. $this->overridePrice = $overridePrice;
  634. return $this;
  635. }
  636. /**
  637. * @return float
  638. */
  639. public function getDriverPrice()
  640. {
  641. return $this->driverPrice;
  642. }
  643. /**
  644. * @return bool
  645. */
  646. public function isFlightLandingTimeWasChanged()
  647. {
  648. return $this->flightLandingTimeWasChanged;
  649. }
  650. public function changeFlightLandingTime()
  651. {
  652. $this->flightLandingTimeWasChanged = true;
  653. }
  654. /**
  655. * @param bool $flightLandingTimeWasChanged
  656. */
  657. public function setFlightLandingTimeWasChanged($flightLandingTimeWasChanged)
  658. {
  659. $this->flightLandingTimeWasChanged = $flightLandingTimeWasChanged;
  660. }
  661. /**
  662. * @param float $driverPrice
  663. *
  664. * @return Booking
  665. */
  666. public function setDriverPrice($driverPrice): self
  667. {
  668. $this->driverPrice = $driverPrice;
  669. return $this;
  670. }
  671. /**
  672. * @return float
  673. */
  674. public function getReturnDriverPrice()
  675. {
  676. return $this->returnDriverPrice;
  677. }
  678. /**
  679. * @param float $returnDriverPrice
  680. */
  681. public function setReturnDriverPrice($returnDriverPrice)
  682. {
  683. $this->returnDriverPrice = $returnDriverPrice;
  684. }
  685. /**
  686. * @return \DateTime
  687. */
  688. public function getBookingDate()
  689. {
  690. return $this->bookingDate;
  691. }
  692. /**
  693. * @param \DateTime $bookingDate
  694. */
  695. public function setBookingDate($bookingDate)
  696. {
  697. $this->bookingDate = $bookingDate;
  698. }
  699. /**
  700. * @return int
  701. */
  702. public function getStatus()
  703. {
  704. return $this->status;
  705. }
  706. /**
  707. * @param int $status
  708. */
  709. public function setStatus($status)
  710. {
  711. $this->status = $status;
  712. }
  713. /**
  714. * @return int
  715. */
  716. public function getDriversConfirmedNumber()
  717. {
  718. return $this->driversConfirmedNumber;
  719. }
  720. /**
  721. * @param int $driversConfirmedNumber
  722. */
  723. public function setDriversConfirmedNumber($driversConfirmedNumber)
  724. {
  725. $this->driversConfirmedNumber = $driversConfirmedNumber;
  726. }
  727. public function incrementDriversConfirmedNumber()
  728. {
  729. $this->driversConfirmedNumber++;
  730. }
  731. /**
  732. * @return mixed
  733. */
  734. public function getRoundTripBookingId()
  735. {
  736. return $this->roundTripBookingId;
  737. }
  738. /**
  739. * @param mixed $roundTripBookingId
  740. */
  741. public function setRoundTripBookingId($roundTripBookingId)
  742. {
  743. $this->roundTripBookingId = $roundTripBookingId;
  744. }
  745. /**
  746. * @return Driver
  747. */
  748. public function getDriver()
  749. {
  750. return $this->driver;
  751. }
  752. /**
  753. * @param mixed $driver
  754. */
  755. public function setDriver($driver)
  756. {
  757. $this->driver = $driver;
  758. }
  759. /**
  760. * @return Car
  761. */
  762. public function getCar()
  763. {
  764. return $this->car;
  765. }
  766. /**
  767. * @param mixed $car
  768. */
  769. public function setCar($car)
  770. {
  771. $this->car = $car;
  772. }
  773. /**
  774. * @return mixed
  775. */
  776. public function getExtras()
  777. {
  778. return $this->extras;
  779. }
  780. /**
  781. * @param ArrayCollection $extras
  782. */
  783. public function setExtras($extras)
  784. {
  785. $this->extras = $extras;
  786. }
  787. public function addExtra($extra)
  788. {
  789. $this->extras->add($extra);
  790. }
  791. public function deleteExtra($extra)
  792. {
  793. $this->extras->removeElement($extra);
  794. $extra->setBooking(null);
  795. }
  796. /**
  797. * @return string
  798. */
  799. public function getPickUpAddress()
  800. {
  801. return $this->pickUpAddress;
  802. }
  803. /**
  804. * @param string $pickUpAddress
  805. */
  806. public function setPickUpAddress($pickUpAddress)
  807. {
  808. $this->pickUpAddress = $pickUpAddress;
  809. }
  810. /**
  811. * @return string
  812. */
  813. public function getPickUpTime($timeFormat = 'H:i')
  814. {
  815. if (!$this->pickUpTime) {
  816. return;
  817. }
  818. return $this->pickUpTime->format($timeFormat);
  819. }
  820. public function getPickUpFullDateTime()
  821. {
  822. $date = clone $this->getPickUpDate();
  823. $pickUpTimeComponents = explode(':', $this->getPickUpTime());
  824. $date->setTime(
  825. intval($pickUpTimeComponents[0]),
  826. intval($pickUpTimeComponents[1])
  827. );
  828. return $date;
  829. }
  830. /**
  831. * @param \DateTime|string $pickUpTime
  832. */
  833. public function setPickUpTime($pickUpTime)
  834. {
  835. if (is_string($pickUpTime)) {
  836. $timeArray = explode(':', $pickUpTime);
  837. $pickUpTime = new \DateTime();
  838. $pickUpTime->setTime(
  839. intval($timeArray[0]),
  840. intval($timeArray[1])
  841. );
  842. }
  843. $this->pickUpTime = $pickUpTime;
  844. $this->updatePickUpDateTime();
  845. }
  846. /**
  847. * @return \DateTime
  848. */
  849. public function getPickUpDateTime()
  850. {
  851. return $this->pickUpDateTime;
  852. }
  853. /**
  854. * @return string
  855. */
  856. public function getDestinationAddress()
  857. {
  858. return $this->destinationAddress;
  859. }
  860. /**
  861. * @param string $destinationAddress
  862. *
  863. * @return Booking
  864. */
  865. public function setDestinationAddress($destinationAddress)
  866. {
  867. $this->destinationAddress = $destinationAddress;
  868. return $this;
  869. }
  870. /**
  871. * @return float
  872. */
  873. public function getPmg()
  874. {
  875. return $this->pmg;
  876. }
  877. /**
  878. * @param float $pmg
  879. */
  880. public function setPmg($pmg)
  881. {
  882. $this->pmg = $pmg;
  883. }
  884. /**
  885. * @return float
  886. */
  887. public function getReturnPmg()
  888. {
  889. return $this->returnPmg;
  890. }
  891. /**
  892. * @param float $returnPmg
  893. */
  894. public function setReturnPmg($returnPmg)
  895. {
  896. $this->returnPmg = $returnPmg;
  897. }
  898. /**
  899. * @return string
  900. */
  901. public function getPickUpMapAddress()
  902. {
  903. return $this->pickUpMapAddress;
  904. }
  905. /**
  906. * @param string $pickUpMapAddress
  907. */
  908. public function setPickUpMapAddress($pickUpMapAddress)
  909. {
  910. $this->pickUpMapAddress = $pickUpMapAddress;
  911. }
  912. /**
  913. * @return string
  914. */
  915. public function getDestinationMapAddress()
  916. {
  917. return $this->destinationMapAddress;
  918. }
  919. /**
  920. * @param string $destinationMapAddress
  921. *
  922. * @return Booking
  923. */
  924. public function setDestinationMapAddress($destinationMapAddress)
  925. {
  926. $this->destinationMapAddress = $destinationMapAddress;
  927. return $this;
  928. }
  929. /**
  930. * @return ArrayCollection
  931. */
  932. public function getBookingHistory()
  933. {
  934. return $this->bookingHistory;
  935. }
  936. /**
  937. * @param ArrayCollection $bookingHistory
  938. */
  939. public function setBookingHistory($bookingHistory)
  940. {
  941. $this->bookingHistory = $bookingHistory;
  942. }
  943. /**
  944. * @param BookingHistory $bookingHistory
  945. *
  946. * @return Booking
  947. */
  948. public function addBookingHistory(BookingHistory $bookingHistory): self
  949. {
  950. $this->bookingHistory[] = $bookingHistory;
  951. return $this;
  952. }
  953. /**
  954. * @param BookingHistory $bookingHistory
  955. *
  956. * @return Booking
  957. */
  958. public function removeBookingHistory(BookingHistory $bookingHistory): self
  959. {
  960. $this->bookingHistory->removeElement($bookingHistory);
  961. return $this;
  962. }
  963. /**
  964. * @return int
  965. */
  966. public function getMatchJob()
  967. {
  968. return $this->matchJob;
  969. }
  970. /**
  971. * @param int $matchJob
  972. */
  973. public function setMatchJob($matchJob)
  974. {
  975. $this->matchJob = $matchJob;
  976. }
  977. /**
  978. * @return int
  979. */
  980. public function getPassengersNumber()
  981. {
  982. return $this->passengersNumber;
  983. }
  984. /**
  985. * @param int $passengersNumber
  986. */
  987. public function setPassengersNumber($passengersNumber)
  988. {
  989. $this->passengersNumber = $passengersNumber;
  990. }
  991. public function getStringStatus($statusType)
  992. {
  993. return self::$statusTypes[$statusType];
  994. }
  995. /**
  996. * @return string
  997. */
  998. public function getHandLuggage()
  999. {
  1000. return $this->handLuggage;
  1001. }
  1002. /**
  1003. * @param string $handLuggage
  1004. */
  1005. public function setHandLuggage($handLuggage)
  1006. {
  1007. $this->handLuggage = $handLuggage;
  1008. }
  1009. /**
  1010. * @return float
  1011. */
  1012. public function getInitialAmountPayment()
  1013. {
  1014. return $this->initialAmountPayment;
  1015. }
  1016. /**
  1017. * @param float $initialAmountPayment
  1018. */
  1019. public function setInitialAmountPayment($initialAmountPayment)
  1020. {
  1021. $this->initialAmountPayment = $initialAmountPayment;
  1022. }
  1023. /**
  1024. * @return string
  1025. */
  1026. public function getCheckinLuggage()
  1027. {
  1028. return $this->checkinLuggage;
  1029. }
  1030. /**
  1031. * @param string $checkinLuggage
  1032. */
  1033. public function setCheckinLuggage($checkinLuggage)
  1034. {
  1035. $this->checkinLuggage = $checkinLuggage;
  1036. }
  1037. /**
  1038. * @return string
  1039. */
  1040. public function getNotes()
  1041. {
  1042. return $this->notes;
  1043. }
  1044. /**
  1045. * @param string $notes
  1046. */
  1047. public function setNotes($notes)
  1048. {
  1049. $this->notes = $notes;
  1050. }
  1051. /**
  1052. * @return string
  1053. */
  1054. public function getOperatorNotes() {
  1055. return $this->operatorNotes;
  1056. }
  1057. /**
  1058. * @param string $var
  1059. */
  1060. public function setOperatorNotes($var) {
  1061. $this->operatorNotes = $var;
  1062. }
  1063. /**
  1064. * @return float
  1065. */
  1066. public function getCcFee()
  1067. {
  1068. return $this->ccFee;
  1069. }
  1070. /**
  1071. * @param float $ccFee
  1072. */
  1073. public function setCcFee($ccFee)
  1074. {
  1075. $this->ccFee = $ccFee;
  1076. }
  1077. /**
  1078. * @return User
  1079. */
  1080. public function getClientUser()
  1081. {
  1082. return $this->clientUser;
  1083. }
  1084. /**
  1085. * @param User $clientUser
  1086. */
  1087. public function setClientUser($clientUser)
  1088. {
  1089. $this->clientUser = $clientUser;
  1090. }
  1091. /**
  1092. * @return bool
  1093. */
  1094. public function isAutomaticAssignment()
  1095. {
  1096. return $this->automaticAssignment;
  1097. }
  1098. /**
  1099. * @param bool $automaticAssignment
  1100. */
  1101. public function setAutomaticAssignment($automaticAssignment)
  1102. {
  1103. $this->automaticAssignment = $automaticAssignment;
  1104. }
  1105. /**
  1106. * @return string
  1107. */
  1108. public function getReturnFlightNumber()
  1109. {
  1110. return $this->returnFlightNumber;
  1111. }
  1112. /**
  1113. * @param string $returnFlightNumber
  1114. */
  1115. public function setReturnFlightNumber($returnFlightNumber)
  1116. {
  1117. $this->returnFlightNumber = $returnFlightNumber;
  1118. }
  1119. /**
  1120. * @return string
  1121. */
  1122. public function getReturnFlightLandingTime()
  1123. {
  1124. if (!$this->returnFlightLandingTime) {
  1125. return;
  1126. }
  1127. return $this->returnFlightLandingTime->format('H:i');
  1128. }
  1129. /**
  1130. * @param \DateTime|string $returnFlightLandingTime
  1131. */
  1132. public function setReturnFlightLandingTime($returnFlightLandingTime)
  1133. {
  1134. if (is_string($returnFlightLandingTime)) {
  1135. $timeArray = explode(':', $returnFlightLandingTime);
  1136. $returnFlightLandingTime = new \DateTime();
  1137. $returnFlightLandingTime->setTime(
  1138. intval($timeArray[0]),
  1139. intval($timeArray[1])
  1140. );
  1141. }
  1142. $this->returnFlightLandingTime = $returnFlightLandingTime;
  1143. }
  1144. /**
  1145. * @return \DateTime
  1146. */
  1147. public function getReturnPickUpDate()
  1148. {
  1149. return $this->returnPickUpDate;
  1150. }
  1151. /**
  1152. * @param \DateTime $returnPickUpDate
  1153. */
  1154. public function setReturnPickUpDate($returnPickUpDate)
  1155. {
  1156. $this->returnPickUpDate = $returnPickUpDate;
  1157. }
  1158. /**
  1159. * @return string
  1160. */
  1161. public function getReturnPickUpTime()
  1162. {
  1163. if (!$this->returnPickUpTime) {
  1164. return;
  1165. }
  1166. return $this->returnPickUpTime->format('H:i');
  1167. }
  1168. public function automaticAssignment($driver)
  1169. {
  1170. $this->automaticAssignment = true;
  1171. $this->setDriver($driver);
  1172. $this->needSendToDriver = true;
  1173. }
  1174. public function setNeedSendToDriver($needSendToDriver)
  1175. {
  1176. $this->needSendToDriver = $needSendToDriver;
  1177. }
  1178. public function getNeedSendToDriver()
  1179. {
  1180. return $this->needSendToDriver;
  1181. }
  1182. /**
  1183. * @param \DateTime $returnPickUpTime
  1184. */
  1185. public function setReturnPickUpTime($returnPickUpTime)
  1186. {
  1187. if (is_string($returnPickUpTime)) {
  1188. $timeArray = explode(':', $returnPickUpTime);
  1189. $returnPickUpTime = new \DateTime();
  1190. $returnPickUpTime->setTime(
  1191. intval($timeArray[0]),
  1192. intval($timeArray[1])
  1193. );
  1194. }
  1195. $this->returnPickUpTime = $returnPickUpTime;
  1196. }
  1197. /**
  1198. * @return string
  1199. */
  1200. public function getReturnBookingNotes()
  1201. {
  1202. return $this->returnBookingNotes;
  1203. }
  1204. /**
  1205. * @param string $returnBookingNotes
  1206. */
  1207. public function setReturnBookingNotes($returnBookingNotes)
  1208. {
  1209. $this->returnBookingNotes = $returnBookingNotes;
  1210. }
  1211. /**
  1212. * @param boolean $toSecond
  1213. * @return \DateTime|int
  1214. */
  1215. public function getWaitingTime($toSecond = false)
  1216. {
  1217. if ($toSecond) {
  1218. return empty($this->waitingTime) ? 0 : (intval($this->waitingTime->format('H')) * 3600) +
  1219. (intval($this->waitingTime->format('i')) * 60) +
  1220. intval($this->waitingTime->format('s'));
  1221. }
  1222. return $this->waitingTime;
  1223. }
  1224. /**
  1225. * @param \DateTime $waitingTime
  1226. */
  1227. public function setWaitingTime($waitingTime)
  1228. {
  1229. $this->waitingTime = $waitingTime;
  1230. }
  1231. /**
  1232. * @param bool $toSecond
  1233. * @return \DateTime
  1234. */
  1235. public function getJobWaitingTime($toSecond = false)
  1236. {
  1237. if ($toSecond) {
  1238. return empty($this->jobWaitingTime) ? 0 : (intval($this->jobWaitingTime->format('H')) * 3600) +
  1239. (intval($this->jobWaitingTime->format('i')) * 60) +
  1240. intval($this->jobWaitingTime->format('s'));
  1241. }
  1242. return $this->jobWaitingTime;
  1243. }
  1244. /**
  1245. * @param \DateTime $jobWaitingTime
  1246. */
  1247. public function setJobWaitingTime($jobWaitingTime)
  1248. {
  1249. $this->jobWaitingTime = $jobWaitingTime;
  1250. }
  1251. /**
  1252. * @return string
  1253. */
  1254. public function getFlightNumber()
  1255. {
  1256. return $this->flightNumber;
  1257. }
  1258. /**
  1259. * @param string $flightNumber
  1260. */
  1261. public function setFlightNumber($flightNumber)
  1262. {
  1263. $this->flightNumber = $flightNumber;
  1264. }
  1265. /**
  1266. * @return string
  1267. */
  1268. public function getFlightLandingTime()
  1269. {
  1270. if (!$this->flightLandingTime) {
  1271. return;
  1272. }
  1273. return $this->flightLandingTime->format('H:i');
  1274. }
  1275. /**
  1276. * @param \DateTime $flightLandingTime
  1277. */
  1278. public function setFlightLandingTime($flightLandingTime)
  1279. {
  1280. if (is_string($flightLandingTime)) {
  1281. $timeArray = explode(':', $flightLandingTime);
  1282. $flightLandingTime = new \DateTime();
  1283. $flightLandingTime->setTime(
  1284. intval($timeArray[0]),
  1285. intval($timeArray[1])
  1286. );
  1287. }
  1288. $this->flightLandingTime = $flightLandingTime;
  1289. }
  1290. /**
  1291. * @return string
  1292. */
  1293. public function getClientFirstName()
  1294. {
  1295. return $this->clientFirstName;
  1296. }
  1297. /**
  1298. * @param string $clientFirstName
  1299. */
  1300. public function setClientFirstName($clientFirstName)
  1301. {
  1302. $this->clientFirstName = $clientFirstName;
  1303. }
  1304. /**
  1305. * @return string
  1306. */
  1307. public function getClientLastName()
  1308. {
  1309. return $this->clientLastName;
  1310. }
  1311. /**
  1312. * @param string $clientLastName
  1313. */
  1314. public function setClientLastName($clientLastName)
  1315. {
  1316. $this->clientLastName = $clientLastName;
  1317. }
  1318. /**
  1319. * @return string
  1320. */
  1321. public function getClientPhone()
  1322. {
  1323. return $this->clientPhone;
  1324. }
  1325. /**
  1326. * @param string $clientPhone
  1327. */
  1328. public function setClientPhone($clientPhone)
  1329. {
  1330. $this->clientPhone = $clientPhone;
  1331. }
  1332. /**
  1333. * @return string
  1334. */
  1335. public function getClientEmail()
  1336. {
  1337. return $this->clientEmail;
  1338. }
  1339. /**
  1340. * @param string $clientEmail
  1341. */
  1342. public function setClientEmail($clientEmail)
  1343. {
  1344. $this->clientEmail = $clientEmail;
  1345. }
  1346. public function getVias()
  1347. {
  1348. return $this->vias;
  1349. }
  1350. public function setVias($vias)
  1351. {
  1352. $this->vias = $vias;
  1353. }
  1354. public function deleteVias($vias)
  1355. {
  1356. $this->vias->removeElement($vias);
  1357. $vias->setBooking(null);
  1358. }
  1359. public function addVias(BookingViasAddress $bookingViasAddress)
  1360. {
  1361. $this->vias->add($bookingViasAddress);
  1362. }
  1363. public function getViasAsArray()
  1364. {
  1365. $vias = [];
  1366. /** @var BookingViasAddress $via */
  1367. foreach ($this->vias as $via) {
  1368. $vias[] = $via->getAddress();
  1369. }
  1370. return $vias;
  1371. }
  1372. public function getCountVias()
  1373. {
  1374. return count($this->vias) > 0 ? count($this->vias) : ' ';
  1375. }
  1376. public function getObjectivesAsArray()
  1377. {
  1378. $objectives = [];
  1379. $bookingData = json_decode($this->getBookingDataSerialized());
  1380. if (is_null($bookingData)) {
  1381. return $objectives;
  1382. }
  1383. $selectedObjectivesIds = $bookingData->selectedObjectives;
  1384. if (!$selectedObjectivesIds) {
  1385. return $objectives;
  1386. }
  1387. $selectedObjectivesHours = $bookingData->selectedObjectivesHours;
  1388. $tours = $bookingData->tours;
  1389. $selectedObjectiveArrayById = [];
  1390. foreach ($tours as $tour) {
  1391. foreach ($tour->objectives as $objective) {
  1392. $selectedObjectiveArrayById[$objective->id . '-' . $tour->tourId] = $objective;
  1393. }
  1394. }
  1395. foreach ($selectedObjectivesIds as $selectedObjectiveId) {
  1396. $objectives[] = [
  1397. 'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
  1398. 'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
  1399. 'hour' => $selectedObjectivesHours->$selectedObjectiveId,
  1400. ];
  1401. }
  1402. return $objectives;
  1403. }
  1404. public function getReturnObjectivesAsArray()
  1405. {
  1406. $returnObjectives = [];
  1407. $bookingData = json_decode($this->getBookingDataSerialized());
  1408. if (is_null($bookingData)) {
  1409. return $returnObjectives;
  1410. }
  1411. $selectedObjectivesIds = $bookingData->returnSelectedObjectives;
  1412. if (!$selectedObjectivesIds) {
  1413. return $returnObjectives;
  1414. }
  1415. $selectedObjectivesHours = $bookingData->returnSelectedObjectivesHours;
  1416. $tours = $bookingData->tours;
  1417. $selectedObjectiveArrayById = [];
  1418. foreach ($tours as $tour) {
  1419. foreach ($tour->objectives as $objective) {
  1420. $selectedObjectiveArrayById[$objective->id . '-' . $tour->tourId] = $objective;
  1421. }
  1422. }
  1423. foreach ($selectedObjectivesIds as $selectedObjectiveId) {
  1424. $returnObjectives[] = [
  1425. 'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
  1426. 'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
  1427. 'hour' => $selectedObjectivesHours->$selectedObjectiveId,
  1428. ];
  1429. }
  1430. return $returnObjectives;
  1431. }
  1432. public function getPaymentString()
  1433. {
  1434. return Payment::TYPE[$this->getPaymentType()];
  1435. }
  1436. /**
  1437. * @return \DateTime
  1438. */
  1439. public function getPickUpDate()
  1440. {
  1441. return $this->pickUpDate;
  1442. }
  1443. public function setPickUpDate($pickUpDate)
  1444. {
  1445. $this->pickUpDate = $pickUpDate;
  1446. $this->updatePickUpDateTime();
  1447. }
  1448. public function updatePickUpDateTime()
  1449. {
  1450. $pickUpDateTime = $this->pickUpDateTime;
  1451. if (!$pickUpDateTime) {
  1452. $pickUpDateTime = new \DateTime();
  1453. if ($this->pickUpDate) {
  1454. $pickUpDateTime = clone ($this->pickUpDate);
  1455. }
  1456. }
  1457. if ($this->pickUpDate) {
  1458. $pickUpDateTime->setDate(
  1459. $this->pickUpDate->format('Y'),
  1460. $this->pickUpDate->format('m'),
  1461. $this->pickUpDate->format('d')
  1462. );
  1463. }
  1464. if ($this->pickUpTime) {
  1465. $pickUpDateTime->setTime(
  1466. intval($this->pickUpTime->format('H')),
  1467. intval($this->pickUpTime->format('i'))
  1468. );
  1469. }
  1470. $this->pickUpDateTime = clone ($pickUpDateTime);
  1471. }
  1472. /**
  1473. * @return Payment
  1474. */
  1475. public function getPayment()
  1476. {
  1477. return $this->payment;
  1478. }
  1479. /**
  1480. * @param Payment $payment
  1481. * @return Booking
  1482. */
  1483. public function setPayment($payment)
  1484. {
  1485. $this->payment = $payment;
  1486. return $this;
  1487. }
  1488. /**
  1489. * @return CarType|null
  1490. */
  1491. public function getCarType()
  1492. {
  1493. return $this->carType;
  1494. }
  1495. /**
  1496. * @param CarType|null $carType
  1497. */
  1498. public function setCarType($carType)
  1499. {
  1500. $this->carType = $carType;
  1501. }
  1502. /**
  1503. * @return float
  1504. */
  1505. public function getDistanceUnit()
  1506. {
  1507. return $this->distanceUnit;
  1508. }
  1509. /**
  1510. * @param float $distanceUnit
  1511. *
  1512. * @return Booking
  1513. */
  1514. public function setDistanceUnit($distanceUnit): self
  1515. {
  1516. $this->distanceUnit = $distanceUnit;
  1517. return $this;
  1518. }
  1519. /**
  1520. * @return string
  1521. */
  1522. public function getEstimatedTime()
  1523. {
  1524. return $this->estimatedTime;
  1525. }
  1526. /**
  1527. * @param string $estimatedTime
  1528. *
  1529. * @return Booking
  1530. */
  1531. public function setEstimatedTime($estimatedTime): self
  1532. {
  1533. $this->estimatedTime = $estimatedTime;
  1534. return $this;
  1535. }
  1536. /**
  1537. * @return int|null
  1538. */
  1539. public function getEstimatedTimeInSeconds(): ?int
  1540. {
  1541. return $this->getEstimatedTime()
  1542. ? DateTimeUtils::convertTimeToSeconds($this->getEstimatedTime())
  1543. : null
  1544. ;
  1545. }
  1546. /**
  1547. * @param bool $seconds
  1548. * @return string
  1549. */
  1550. public function getEstimatedTimePrettyFormat($seconds = false)
  1551. {
  1552. $prettyEstimatedTime = '0 minutes';
  1553. if (!empty($this->estimatedTime)) {
  1554. $eT = explode(":", $this->estimatedTime);
  1555. if (count($eT) === 3) {
  1556. $estimatedTime = "";
  1557. if (intval($eT[0]) > 0) {
  1558. $estimatedTime .= intval($eT[0]) . "h ";
  1559. }
  1560. if (intval($eT[1]) > 0) {
  1561. $estimatedTime .= intval($eT[1]) . "min ";
  1562. }
  1563. if (
  1564. ($seconds || empty($estimatedTime)) &&
  1565. intval($eT[2]) > 0
  1566. ) {
  1567. $estimatedTime .= intval($eT[2]) . "s";
  1568. }
  1569. if (!empty($estimatedTime)) {
  1570. $prettyEstimatedTime = $estimatedTime;
  1571. }
  1572. }
  1573. }
  1574. return $prettyEstimatedTime;
  1575. }
  1576. /**
  1577. * @return bool
  1578. */
  1579. public function isCreateAccount()
  1580. {
  1581. return $this->createAccount;
  1582. }
  1583. /**
  1584. * @param bool $createAccount
  1585. */
  1586. public function setCreateAccount($createAccount)
  1587. {
  1588. $this->createAccount = $createAccount;
  1589. }
  1590. /**
  1591. * @return int
  1592. */
  1593. public function getPaymentType()
  1594. {
  1595. return $this->paymentType;
  1596. }
  1597. /**
  1598. * @param int $paymentType
  1599. */
  1600. public function setPaymentType($paymentType)
  1601. {
  1602. $this->paymentType = $paymentType;
  1603. }
  1604. /**
  1605. * @return Booking|null
  1606. */
  1607. public function getReturnBooking()
  1608. {
  1609. return $this->returnBooking;
  1610. }
  1611. /**
  1612. * @param Booking|null $returnBooking
  1613. */
  1614. public function setReturnBooking($returnBooking)
  1615. {
  1616. $this->returnBooking = $returnBooking;
  1617. }
  1618. public function __toString()
  1619. {
  1620. return $this->getId() ? (string) $this->getId() : 'n\a';
  1621. }
  1622. /**
  1623. * @return float
  1624. */
  1625. public function getCancelRefund()
  1626. {
  1627. return $this->cancelRefund;
  1628. }
  1629. /**
  1630. * @param float $cancelRefund
  1631. */
  1632. public function setCancelRefund($cancelRefund)
  1633. {
  1634. $this->cancelRefund = $cancelRefund;
  1635. }
  1636. /**
  1637. * @return string
  1638. */
  1639. public function getCancelReason()
  1640. {
  1641. return $this->cancelReason;
  1642. }
  1643. /**
  1644. * @param string $cancelReason
  1645. */
  1646. public function setCancelReason($cancelReason)
  1647. {
  1648. $this->cancelReason = $cancelReason;
  1649. }
  1650. /**
  1651. * @return Booking
  1652. */
  1653. public function getParentBooking()
  1654. {
  1655. return $this->parentBooking;
  1656. }
  1657. /**
  1658. * @param Booking $parentBooking
  1659. */
  1660. public function setParentBooking($parentBooking)
  1661. {
  1662. $this->parentBooking = $parentBooking;
  1663. }
  1664. /**
  1665. * @return string
  1666. */
  1667. public function getPaymentReference()
  1668. {
  1669. return $this->paymentReference;
  1670. }
  1671. /**
  1672. * @param string $paymentReference
  1673. */
  1674. public function setPaymentReference($paymentReference)
  1675. {
  1676. $this->paymentReference = $paymentReference;
  1677. }
  1678. /**
  1679. * @return ArrayCollection
  1680. */
  1681. public function getBroadcastedDrivers()
  1682. {
  1683. return $this->broadcastedDrivers;
  1684. }
  1685. /**
  1686. * @param ArrayCollection $broadcastedDrivers
  1687. */
  1688. public function setBroadcastedDrivers($broadcastedDrivers)
  1689. {
  1690. $this->broadcastedDrivers = $broadcastedDrivers;
  1691. }
  1692. /**
  1693. * @return ArrayCollection
  1694. */
  1695. public function getUnassignedDriverRequests()
  1696. {
  1697. return $this->unassignedDriverRequests;
  1698. }
  1699. /**
  1700. * @param ArrayCollection $unassignedDriverRequests;
  1701. */
  1702. public function setUnassignedDriverRequests($unassignedDriverRequests)
  1703. {
  1704. $this->unassignedDriverRequests = $unassignedDriverRequests;
  1705. }
  1706. /**
  1707. * @return string
  1708. */
  1709. public function getPickUpPostCode()
  1710. {
  1711. return $this->pickUpPostCode;
  1712. }
  1713. /**
  1714. * @param string $pickUpPostCode
  1715. */
  1716. public function setPickUpPostCode($pickUpPostCode)
  1717. {
  1718. $this->pickUpPostCode = $pickUpPostCode;
  1719. }
  1720. /**
  1721. * @return string
  1722. */
  1723. public function getDestinationPostCode()
  1724. {
  1725. return $this->destinationPostCode;
  1726. }
  1727. /**
  1728. * @param string $destinationPostCode
  1729. *
  1730. * @return Booking
  1731. */
  1732. public function setDestinationPostCode($destinationPostCode)
  1733. {
  1734. $this->destinationPostCode = $destinationPostCode;
  1735. return $this;
  1736. }
  1737. /**
  1738. * @return string
  1739. */
  1740. public function getClientAlternativePhone()
  1741. {
  1742. return $this->clientAlternativePhone;
  1743. }
  1744. /**
  1745. * @param string $clientAlternativePhone
  1746. */
  1747. public function setClientAlternativePhone($clientAlternativePhone)
  1748. {
  1749. $this->clientAlternativePhone = $clientAlternativePhone;
  1750. }
  1751. /**
  1752. * @return string
  1753. */
  1754. public function getClientAlternativeEmail()
  1755. {
  1756. return $this->clientAlternativeEmail;
  1757. }
  1758. /**
  1759. * @param string $clientAlternativeEmail
  1760. */
  1761. public function setClientAlternativeEmail($clientAlternativeEmail)
  1762. {
  1763. $this->clientAlternativeEmail = $clientAlternativeEmail;
  1764. }
  1765. /**
  1766. * @return string
  1767. */
  1768. public function getVoucherCode()
  1769. {
  1770. return $this->voucherCode;
  1771. }
  1772. /**
  1773. * @param string $voucherCode
  1774. */
  1775. public function setVoucherCode($voucherCode)
  1776. {
  1777. $this->voucherCode = $voucherCode;
  1778. }
  1779. /**
  1780. * @return string
  1781. */
  1782. public function getVoucherValue()
  1783. {
  1784. return $this->voucherValue;
  1785. }
  1786. /**
  1787. * @param string $voucherValue
  1788. */
  1789. public function setVoucherValue($voucherValue)
  1790. {
  1791. $this->voucherValue = $voucherValue;
  1792. }
  1793. /**
  1794. * @return ArrayCollection
  1795. */
  1796. public function getNotificationBooking()
  1797. {
  1798. return $this->notificationBooking;
  1799. }
  1800. /**
  1801. * @param ArrayCollection $notificationBooking
  1802. * @return Booking
  1803. */
  1804. public function setNotificationBooking(ArrayCollection $notificationBooking): Booking
  1805. {
  1806. $this->notificationBooking = $notificationBooking;
  1807. return $this;
  1808. }
  1809. /**
  1810. * @param NotificationBookingUpdate $notificationBooking
  1811. * @return Booking
  1812. */
  1813. public function addNotificationBooking(NotificationBookingUpdate $notificationBooking): Booking
  1814. {
  1815. $this->notificationBooking->add($notificationBooking);
  1816. return $this;
  1817. }
  1818. public function isCancel()
  1819. {
  1820. $cancelBooking = [
  1821. self::STATUS_DELETED,
  1822. self::STATUS_OFFICE_CANCELLATION,
  1823. self::STATUS_CANCELLED_OTHER_REASON,
  1824. self::STATUS_CLIENT_CANCELLATION,
  1825. ];
  1826. if (in_array($this->status, $cancelBooking)) {
  1827. return true;
  1828. }
  1829. return false;
  1830. }
  1831. public function canBroadcast()
  1832. {
  1833. if ($this->getDriver()) {
  1834. return false;
  1835. }
  1836. return !$this->isExpireBroadcast();
  1837. }
  1838. public function isExpireBroadcast()
  1839. {
  1840. if (!$this->expireBroadcastDate) {
  1841. return false;
  1842. }
  1843. $currentDate = new \DateTime();
  1844. if ($currentDate > $this->expireBroadcastDate) {
  1845. return false;
  1846. }
  1847. return true;
  1848. }
  1849. /**
  1850. * check if have update notificaitons
  1851. *
  1852. * @return bool
  1853. */
  1854. public function isUpdated()
  1855. {
  1856. $criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
  1857. ->andWhere(Criteria::expr()->eq('driver', $this->driver));
  1858. return $this->getNotificationBooking()->matching($criteria)->count() >= 1;
  1859. }
  1860. /**
  1861. * mark as read all notifications
  1862. */
  1863. public function returnUnSeenUpdated()
  1864. {
  1865. $criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
  1866. ->andWhere(Criteria::expr()->eq('driver', $this->driver));
  1867. return $this->getNotificationBooking()->matching($criteria);
  1868. }
  1869. /**
  1870. * @return string
  1871. */
  1872. public function getBookingDataSerialized()
  1873. {
  1874. return $this->bookingDataSerialized;
  1875. }
  1876. /**
  1877. * @param string $bookingDataSerialized
  1878. */
  1879. public function setBookingDataSerialized($bookingDataSerialized)
  1880. {
  1881. $this->bookingDataSerialized = $bookingDataSerialized;
  1882. }
  1883. public function __clone()
  1884. {
  1885. $this->id = null;
  1886. $this->pickUpDateTime = null;
  1887. $this->pickUpDate = null;
  1888. $this->pickUpTime = null;
  1889. }
  1890. /**
  1891. * @return ClientInvoices
  1892. */
  1893. public function getClientInvoice()
  1894. {
  1895. return $this->clientInvoice;
  1896. }
  1897. /**
  1898. * @param ClientInvoices $clientInvoice
  1899. */
  1900. public function setClientInvoice($clientInvoice)
  1901. {
  1902. $this->clientInvoice = $clientInvoice;
  1903. }
  1904. public function formatAddressForListing($address)
  1905. {
  1906. $addressArray = explode(',', $address);
  1907. return [
  1908. array_slice($addressArray, 0, (count($addressArray) - 2)),
  1909. array_slice($addressArray, -2),
  1910. ];
  1911. }
  1912. public function getMeetAndGreetTimePrettyFormat()
  1913. {
  1914. if (!empty($this->getFlightLandingTime())) {
  1915. $pickUpTime = explode(":", $this->getPickUpTime());
  1916. $landingTime = explode(":", $this->getFlightLandingTime());
  1917. $date1 = new \DateTime();
  1918. $date2 = new \DateTime();
  1919. if ($landingTime[0] > $pickUpTime[0]) {
  1920. // the landing time & pick up Time is different day
  1921. // example: landing time 23:50, pick up time: 00:10
  1922. $date1->modify("+1 day");
  1923. }
  1924. $date1->setTime(
  1925. intval($pickUpTime[0]),
  1926. intval($pickUpTime[1])
  1927. );
  1928. $date2->setTime(
  1929. intval($landingTime[0]),
  1930. intval($landingTime[1])
  1931. );
  1932. $difference = date_diff($date1, $date2);
  1933. return ($difference->h ? $difference->h . 'H' : '') .
  1934. ($difference->i . 'M');
  1935. }
  1936. return null;
  1937. }
  1938. /**
  1939. * Set pickUpLat
  1940. *
  1941. * @param float $pickUpLat
  1942. *
  1943. * @return Booking
  1944. */
  1945. public function setPickUpLat($pickUpLat)
  1946. {
  1947. $this->pickUpLat = $pickUpLat;
  1948. return $this;
  1949. }
  1950. /**
  1951. * Get pickUpLat
  1952. *
  1953. * @return float
  1954. */
  1955. public function getPickUpLat()
  1956. {
  1957. return $this->pickUpLat;
  1958. }
  1959. /**
  1960. * Set pickUpLng
  1961. *
  1962. * @param float $pickUpLng
  1963. *
  1964. * @return Booking
  1965. */
  1966. public function setPickUpLng($pickUpLng)
  1967. {
  1968. $this->pickUpLng = $pickUpLng;
  1969. return $this;
  1970. }
  1971. /**
  1972. * Get pickUpLng
  1973. *
  1974. * @return float
  1975. */
  1976. public function getPickUpLng()
  1977. {
  1978. return $this->pickUpLng;
  1979. }
  1980. /**
  1981. * Set destinationLat
  1982. *
  1983. * @param float $destinationLat
  1984. *
  1985. * @return Booking
  1986. */
  1987. public function setDestinationLat($destinationLat)
  1988. {
  1989. $this->destinationLat = $destinationLat;
  1990. return $this;
  1991. }
  1992. /**
  1993. * Get destinationLat
  1994. *
  1995. * @return float
  1996. */
  1997. public function getDestinationLat()
  1998. {
  1999. return $this->destinationLat;
  2000. }
  2001. /**
  2002. * Set destinationLng
  2003. *
  2004. * @param float $destinationLng
  2005. *
  2006. * @return Booking
  2007. */
  2008. public function setDestinationLng($destinationLng)
  2009. {
  2010. $this->destinationLng = $destinationLng;
  2011. return $this;
  2012. }
  2013. /**
  2014. * Get destinationLng
  2015. *
  2016. * @return float
  2017. */
  2018. public function getDestinationLng()
  2019. {
  2020. return $this->destinationLng;
  2021. }
  2022. /**
  2023. * Add voipRecord
  2024. *
  2025. * @param \AdminBundle\Entity\VoipRecord $voipRecord
  2026. *
  2027. * @return Booking
  2028. */
  2029. public function addVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
  2030. {
  2031. $this->voipRecords[] = $voipRecord;
  2032. return $this;
  2033. }
  2034. /**
  2035. * Remove voipRecord
  2036. *
  2037. * @param \AdminBundle\Entity\VoipRecord $voipRecord
  2038. */
  2039. public function removeVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
  2040. {
  2041. $this->voipRecords->removeElement($voipRecord);
  2042. }
  2043. /**
  2044. * Get voipRecords
  2045. *
  2046. * @return \Doctrine\Common\Collections\Collection
  2047. */
  2048. public function getVoipRecords()
  2049. {
  2050. return $this->voipRecords;
  2051. }
  2052. public function isOpen($userEmail)
  2053. {
  2054. $this->lastOpenedUser = $userEmail;
  2055. $this->lastOpenedDate = new \DateTime();
  2056. }
  2057. /**
  2058. * @return \DateTime
  2059. */
  2060. public function getLastOpenedDate()
  2061. {
  2062. return $this->lastOpenedDate;
  2063. }
  2064. /**
  2065. * @param \DateTime $lastOpenedDate
  2066. */
  2067. public function setLastOpenedDate($lastOpenedDate)
  2068. {
  2069. $this->lastOpenedDate = $lastOpenedDate;
  2070. }
  2071. /**
  2072. * @return string
  2073. */
  2074. public function getLastOpenedUser()
  2075. {
  2076. return $this->lastOpenedUser;
  2077. }
  2078. /**
  2079. * @param string $lastOpenedUser
  2080. */
  2081. public function setLastOpenedUser($lastOpenedUser)
  2082. {
  2083. $this->lastOpenedUser = $lastOpenedUser;
  2084. }
  2085. public function getBookingDataSerializedDecoded()
  2086. {
  2087. return json_decode($this->bookingDataSerialized);
  2088. }
  2089. /**
  2090. * @return string
  2091. */
  2092. public function getFullname()
  2093. {
  2094. $firstName = $this->getClientFirstName() ?: 'n/a';
  2095. $lastName = $this->getClientLastName() ?: 'n/a';
  2096. return "{$firstName} {$lastName}";
  2097. }
  2098. public function getTotalCost()
  2099. {
  2100. return $this->getOverridePrice() ? $this->overridePrice : $this->getQuotePrice();
  2101. }
  2102. /**
  2103. * @return string
  2104. */
  2105. public function getFirstBookingCreatedBy()
  2106. {
  2107. $firstBookingHistory = $this->getBookingHistory()->first();
  2108. if ($firstBookingHistory && $user = $firstBookingHistory->getUser()) {
  2109. if ($user->getEmail() === 'online@ctlf.co.uk') {
  2110. return self::CREATED_BY_APP;
  2111. }
  2112. if ($user->hasRole('ROLE_CLIENT')) {
  2113. return self::CREATED_BY_CLIENT;
  2114. }
  2115. }
  2116. return self::CREATED_BY_DISPATCH;
  2117. }
  2118. public function getDriverNameAndInternal()
  2119. {
  2120. if (null != $this->getDriver() && null != $this->getDriver()->getUser()) {
  2121. return $this->getDriver()->getUser()->getFirstname() . ' ' . $this->getDriver()->getUser()->getLastname() . ' (' . $this->getDriver()->getInternalName() . ')';
  2122. } else {
  2123. return $this->getDriver();
  2124. }
  2125. }
  2126. public function getBookingDateFormated()
  2127. {
  2128. return $this->getBookingDate()->format('d/m/Y');
  2129. }
  2130. public function getBookingTimeFormated()
  2131. {
  2132. return $this->getBookingDate()->format('H:i');
  2133. }
  2134. public function getPickUpDateFormated()
  2135. {
  2136. return $this->getPickUpDate()->format('d/m/Y');
  2137. }
  2138. public function getTotalCostWithCurrency($currencySymbol = null)
  2139. {
  2140. if ($currencySymbol == null) {
  2141. $currencySymbol = chr(163);
  2142. }
  2143. return $currencySymbol . ' ' . $this->getTotalCost();
  2144. }
  2145. public function getStatusAsText()
  2146. {
  2147. return $this->getStringStatus($this->status);
  2148. }
  2149. public function convertInMinutesPickUpTime()
  2150. {
  2151. $components = explode(':', $this->pickUpTime->format('H:i'));
  2152. return intval($components[1]) + (intval($components[0]) * 60);
  2153. }
  2154. public function estimateEndDateTime()
  2155. {
  2156. $interval = $this->getEstimatedTime();
  2157. $intervalComponents = explode(':', $interval);
  2158. $minutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
  2159. $pickUp = clone $this->pickUpDateTime;
  2160. $pickUp->add(new \DateInterval('PT' . $minutes . 'M'));
  2161. return $pickUp;
  2162. }
  2163. public function estimateEndHourString()
  2164. {
  2165. return $this->estimateEndDateTime()->format('H:i');
  2166. }
  2167. public function convertInMinutesEndTime()
  2168. {
  2169. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2170. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2171. $interval = $this->estimatedTime;
  2172. $intervalComponents = explode(':', $interval);
  2173. $endMinutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
  2174. $total = $pickUpTimeInMinutes + $endMinutes;
  2175. if ($total > 1440) {
  2176. return 1440;
  2177. }
  2178. return $total;
  2179. }
  2180. public function getMgMinutes()
  2181. {
  2182. if (!$this->flightLandingTime) {
  2183. return 0;
  2184. }
  2185. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2186. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2187. $flightLandingTimeComponents = explode(':', $this->flightLandingTime->format('H:i'));
  2188. $flightLandingTimeInMinutes = intval($flightLandingTimeComponents[1]) + (intval($flightLandingTimeComponents[0]) * 60);
  2189. if ($flightLandingTimeInMinutes <= $pickUpTimeInMinutes) {
  2190. return 0;
  2191. }
  2192. return ($flightLandingTimeInMinutes - $pickUpTimeInMinutes);
  2193. }
  2194. public function getMgTime()
  2195. {
  2196. if (!$this->flightLandingTime) {
  2197. return null;
  2198. }
  2199. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2200. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2201. $flightLandingTimeComponents = explode(':', $this->flightLandingTime->format('H:i'));
  2202. $flightLandingTimeInMinutes = intval($flightLandingTimeComponents[1]) + (intval($flightLandingTimeComponents[0]) * 60);
  2203. $difference = $pickUpTimeInMinutes < $flightLandingTimeInMinutes
  2204. ? $pickUpTimeInMinutes + ((24 * 60) - $flightLandingTimeInMinutes)
  2205. : $pickUpTimeInMinutes - $flightLandingTimeInMinutes
  2206. ;
  2207. // mg time return in minutes
  2208. return "{$difference}";
  2209. }
  2210. public function bookingCode($type = null, $main_location = null)
  2211. {
  2212. $resultPostcode = '';
  2213. if ($main_location !== null) {
  2214. if ($main_location == 'US') {
  2215. $pickUpCodeComponents = substr($this->pickUpPostCode, 0, 3);
  2216. $destinationCodeComponents = substr($this->destinationPostCode, 0, 3);
  2217. $resultPostcode = $pickUpCodeComponents . '-' . $destinationCodeComponents;
  2218. }
  2219. if ($main_location == 'UK') {
  2220. $pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
  2221. $destinationCodeComponents = explode(' ', $this->destinationPostCode);
  2222. $resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
  2223. }
  2224. } else {
  2225. $pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
  2226. $destinationCodeComponents = explode(' ', $this->destinationPostCode);
  2227. $resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
  2228. }
  2229. $result = '';
  2230. if ($type == null) {
  2231. $result .= $this->key;
  2232. }
  2233. $result .= ' ' . $resultPostcode;
  2234. return $result;
  2235. }
  2236. /**
  2237. * @return \DateTime
  2238. */
  2239. public function getSendNotificationUndispatched()
  2240. {
  2241. return $this->sendNotificationUndispatched;
  2242. }
  2243. /**
  2244. * @param \DateTime $sendNotificationUndispatched
  2245. */
  2246. public function setSendNotificationUndispatched($sendNotificationUndispatched)
  2247. {
  2248. $this->sendNotificationUndispatched = $sendNotificationUndispatched;
  2249. }
  2250. /**
  2251. * @return float
  2252. */
  2253. public function getBookingformCCFee()
  2254. {
  2255. return $this->bookingformCCFee;
  2256. }
  2257. /**
  2258. * @param float $bookingformCCFee
  2259. */
  2260. public function setBookingformCCFee($bookingformCCFee)
  2261. {
  2262. $this->bookingformCCFee = (float) $bookingformCCFee;
  2263. }
  2264. /**
  2265. * @return string
  2266. */
  2267. public function getPickupAddressCategory()
  2268. {
  2269. return $this->pickupAddressCategory;
  2270. }
  2271. /**
  2272. * @param string $pickupAddressCategory
  2273. */
  2274. public function setPickupAddressCategory($pickupAddressCategory)
  2275. {
  2276. $this->pickupAddressCategory = $pickupAddressCategory;
  2277. }
  2278. /**
  2279. * @return string
  2280. */
  2281. public function getDropoffAddressCategory()
  2282. {
  2283. return $this->dropoffAddressCategory;
  2284. }
  2285. /**
  2286. * @param string $dropoffAddressCategory
  2287. */
  2288. public function setDropoffAddressCategory($dropoffAddressCategory)
  2289. {
  2290. $this->dropoffAddressCategory = $dropoffAddressCategory;
  2291. }
  2292. /**
  2293. * @return \DateTime
  2294. */
  2295. public function getUnassignedHideAt()
  2296. {
  2297. return $this->unassignedHideAt;
  2298. }
  2299. /**
  2300. * @param \DateTime $unassignedHideAt
  2301. */
  2302. public function setUnassignedHideAt($unassignedHideAt)
  2303. {
  2304. $this->unassignedHideAt = $unassignedHideAt;
  2305. return $this;
  2306. }
  2307. /**
  2308. * @param Ticket $ticket
  2309. *
  2310. * @return Booking
  2311. */
  2312. public function addQuestion(Ticket $ticket)
  2313. {
  2314. $ticket->setBooking($this);
  2315. $this->tickets->add($ticket);
  2316. return $this;
  2317. }
  2318. /**
  2319. * @param Ticket $ticket
  2320. *
  2321. * @return Booking
  2322. */
  2323. public function removeTicket(Ticket $ticket)
  2324. {
  2325. if (!$this->tickets->contains($ticket)) {
  2326. return;
  2327. }
  2328. $this->tickets->removeElement($ticket);
  2329. $ticket->setBooking(null);
  2330. return $this;
  2331. }
  2332. /**
  2333. * @return ArrayCollection
  2334. */
  2335. public function getTickets()
  2336. {
  2337. return $this->tickets;
  2338. }
  2339. /**
  2340. * @param int $bookingSourceType
  2341. */
  2342. public function setBookingSourceType($bookingSourceType)
  2343. {
  2344. $this->bookingSourceType = $bookingSourceType;
  2345. }
  2346. /**
  2347. * @return int
  2348. */
  2349. public function getBookingSourceType()
  2350. {
  2351. return $this->bookingSourceType;
  2352. }
  2353. public function getBookingSourceTypeName()
  2354. {
  2355. if (
  2356. $this->bookingSourceType &&
  2357. isset(self::$sourceTypes[$this->bookingSourceType])
  2358. ) {
  2359. return self::$sourceTypes[$this->bookingSourceType];
  2360. }
  2361. }
  2362. public function isBeforeOnTheWay()
  2363. {
  2364. return in_array($this->getStatus(), [
  2365. Booking::STATUS_NEW_BOOKING,
  2366. Booking::STATUS_DISPATCHED,
  2367. Booking::STATUS_DRIVER_REJECT,
  2368. Booking::STATUS_DRIVER_ACCEPT,
  2369. ]);
  2370. }
  2371. public function getClientCancellationCase()
  2372. {
  2373. $status = $this->getStatus();
  2374. if ($this->isBeforeOnTheWay()) {
  2375. return ClientCancellationFee::CANCELLATION_CASE_BEFORE_ON_THE_WAY;
  2376. }
  2377. if ($status === Booking::STATUS_ON_THE_WAY) {
  2378. foreach ($this->getBookingHistory() as $history) {
  2379. if ($history->getActionType() !== BookingHistory::ACTION_TYPE_CHANGED_STATUS) {
  2380. continue;
  2381. }
  2382. $payload = $history->getPayload();
  2383. if (intval($payload['old_status']) !== self::STATUS_DISPATCHED && intval($payload['current_status']) !== self::STATUS_ON_THE_WAY) {
  2384. continue;
  2385. }
  2386. $now = new \DateTime();
  2387. $diff = $history->getDate()->getTimestamp() - $now->getTimestamp();
  2388. // 2 mins difference
  2389. return $diff <= 120 ? ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY_STARTED : ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY;
  2390. }
  2391. }
  2392. if ($status === Booking::STATUS_ARRIVED_AND_WAITING) {
  2393. return ClientCancellationFee::CANCELLATION_CASE_ARRIVED_AND_WAITING;
  2394. }
  2395. return null;
  2396. }
  2397. /**
  2398. * @return bool
  2399. */
  2400. public function hasReturn(): bool
  2401. {
  2402. return null !== $this->getReturnBooking();
  2403. }
  2404. /**
  2405. * @return bool
  2406. */
  2407. public function isPmg(): bool
  2408. {
  2409. return !empty($this->getPmg());
  2410. }
  2411. /**
  2412. * @return bool
  2413. */
  2414. public function isReturnPmg(): bool
  2415. {
  2416. return !empty($this->getReturnPmg());
  2417. }
  2418. public function isPickupAddressCategoryPOI()
  2419. {
  2420. return in_array($this->getPickupAddressCategory(), Area::$categories);
  2421. }
  2422. public function isDropoffAddressCategoryPOI()
  2423. {
  2424. return in_array($this->getDropoffAddressCategory(), Area::$categories);
  2425. }
  2426. /**
  2427. * @return bool
  2428. */
  2429. public function isFixedPrice(): bool
  2430. {
  2431. if (null === $this->getBookingDataSerialized()) {
  2432. return false;
  2433. }
  2434. $data = \json_decode($this->getBookingDataSerialized());
  2435. if (JSON_ERROR_NONE !== \json_last_error()) {
  2436. return false;
  2437. }
  2438. if (!isset($data->result)) {
  2439. return false;
  2440. }
  2441. $result = $data->result;
  2442. if (empty($result->route)) {
  2443. return false;
  2444. }
  2445. $route = $result->route[0];
  2446. return isset($route->fixedPrice) && $route->fixedPrice;
  2447. }
  2448. /**
  2449. * @return bool
  2450. */
  2451. public function isLiveUpdateNotificationSent(): bool
  2452. {
  2453. return $this->isLiveUpdateNotificationSent;
  2454. }
  2455. /**
  2456. * @param bool $isLiveUpdateNotificationSent
  2457. *
  2458. * @return self
  2459. */
  2460. public function setIsLiveUpdatedNotificationSent(bool $isLiveUpdateNotificationSent): self
  2461. {
  2462. $this->isLiveUpdateNotificationSent = $isLiveUpdateNotificationSent;
  2463. return $this;
  2464. }
  2465. }