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: 'booking', 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->remove($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($pickUpTimeComponents[0], $pickUpTimeComponents[1]);
  825. return $date;
  826. }
  827. /**
  828. * @param \DateTime|string $pickUpTime
  829. */
  830. public function setPickUpTime($pickUpTime)
  831. {
  832. if (is_string($pickUpTime)) {
  833. $timeArray = explode(':', $pickUpTime);
  834. $pickUpTime = new \DateTime();
  835. $pickUpTime->setTime($timeArray[0], $timeArray[1]);
  836. }
  837. $this->pickUpTime = $pickUpTime;
  838. $this->updatePickUpDateTime();
  839. }
  840. /**
  841. * @return \DateTime
  842. */
  843. public function getPickUpDateTime()
  844. {
  845. return $this->pickUpDateTime;
  846. }
  847. /**
  848. * @return string
  849. */
  850. public function getDestinationAddress()
  851. {
  852. return $this->destinationAddress;
  853. }
  854. /**
  855. * @param string $destinationAddress
  856. *
  857. * @return Booking
  858. */
  859. public function setDestinationAddress($destinationAddress)
  860. {
  861. $this->destinationAddress = $destinationAddress;
  862. return $this;
  863. }
  864. /**
  865. * @return float
  866. */
  867. public function getPmg()
  868. {
  869. return $this->pmg;
  870. }
  871. /**
  872. * @param float $pmg
  873. */
  874. public function setPmg($pmg)
  875. {
  876. $this->pmg = $pmg;
  877. }
  878. /**
  879. * @return float
  880. */
  881. public function getReturnPmg()
  882. {
  883. return $this->returnPmg;
  884. }
  885. /**
  886. * @param float $returnPmg
  887. */
  888. public function setReturnPmg($returnPmg)
  889. {
  890. $this->returnPmg = $returnPmg;
  891. }
  892. /**
  893. * @return string
  894. */
  895. public function getPickUpMapAddress()
  896. {
  897. return $this->pickUpMapAddress;
  898. }
  899. /**
  900. * @param string $pickUpMapAddress
  901. */
  902. public function setPickUpMapAddress($pickUpMapAddress)
  903. {
  904. $this->pickUpMapAddress = $pickUpMapAddress;
  905. }
  906. /**
  907. * @return string
  908. */
  909. public function getDestinationMapAddress()
  910. {
  911. return $this->destinationMapAddress;
  912. }
  913. /**
  914. * @param string $destinationMapAddress
  915. *
  916. * @return Booking
  917. */
  918. public function setDestinationMapAddress($destinationMapAddress)
  919. {
  920. $this->destinationMapAddress = $destinationMapAddress;
  921. return $this;
  922. }
  923. /**
  924. * @return ArrayCollection
  925. */
  926. public function getBookingHistory()
  927. {
  928. return $this->bookingHistory;
  929. }
  930. /**
  931. * @param ArrayCollection $bookingHistory
  932. */
  933. public function setBookingHistory($bookingHistory)
  934. {
  935. $this->bookingHistory = $bookingHistory;
  936. }
  937. /**
  938. * @param BookingHistory $bookingHistory
  939. *
  940. * @return Booking
  941. */
  942. public function addBookingHistory(BookingHistory $bookingHistory): self
  943. {
  944. $this->bookingHistory[] = $bookingHistory;
  945. return $this;
  946. }
  947. /**
  948. * @param BookingHistory $bookingHistory
  949. *
  950. * @return Booking
  951. */
  952. public function removeBookingHistory(BookingHistory $bookingHistory): self
  953. {
  954. $this->bookingHistory->removeElement($bookingHistory);
  955. return $this;
  956. }
  957. /**
  958. * @return int
  959. */
  960. public function getMatchJob()
  961. {
  962. return $this->matchJob;
  963. }
  964. /**
  965. * @param int $matchJob
  966. */
  967. public function setMatchJob($matchJob)
  968. {
  969. $this->matchJob = $matchJob;
  970. }
  971. /**
  972. * @return int
  973. */
  974. public function getPassengersNumber()
  975. {
  976. return $this->passengersNumber;
  977. }
  978. /**
  979. * @param int $passengersNumber
  980. */
  981. public function setPassengersNumber($passengersNumber)
  982. {
  983. $this->passengersNumber = $passengersNumber;
  984. }
  985. public function getStringStatus($statusType)
  986. {
  987. return self::$statusTypes[$statusType];
  988. }
  989. /**
  990. * @return string
  991. */
  992. public function getHandLuggage()
  993. {
  994. return $this->handLuggage;
  995. }
  996. /**
  997. * @param string $handLuggage
  998. */
  999. public function setHandLuggage($handLuggage)
  1000. {
  1001. $this->handLuggage = $handLuggage;
  1002. }
  1003. /**
  1004. * @return float
  1005. */
  1006. public function getInitialAmountPayment()
  1007. {
  1008. return $this->initialAmountPayment;
  1009. }
  1010. /**
  1011. * @param float $initialAmountPayment
  1012. */
  1013. public function setInitialAmountPayment($initialAmountPayment)
  1014. {
  1015. $this->initialAmountPayment = $initialAmountPayment;
  1016. }
  1017. /**
  1018. * @return string
  1019. */
  1020. public function getCheckinLuggage()
  1021. {
  1022. return $this->checkinLuggage;
  1023. }
  1024. /**
  1025. * @param string $checkinLuggage
  1026. */
  1027. public function setCheckinLuggage($checkinLuggage)
  1028. {
  1029. $this->checkinLuggage = $checkinLuggage;
  1030. }
  1031. /**
  1032. * @return string
  1033. */
  1034. public function getNotes()
  1035. {
  1036. return $this->notes;
  1037. }
  1038. /**
  1039. * @param string $notes
  1040. */
  1041. public function setNotes($notes)
  1042. {
  1043. $this->notes = $notes;
  1044. }
  1045. /**
  1046. * @return string
  1047. */
  1048. public function getOperatorNotes() {
  1049. return $this->operatorNotes;
  1050. }
  1051. /**
  1052. * @param string $var
  1053. */
  1054. public function setOperatorNotes($var) {
  1055. $this->operatorNotes = $var;
  1056. }
  1057. /**
  1058. * @return float
  1059. */
  1060. public function getCcFee()
  1061. {
  1062. return $this->ccFee;
  1063. }
  1064. /**
  1065. * @param float $ccFee
  1066. */
  1067. public function setCcFee($ccFee)
  1068. {
  1069. $this->ccFee = $ccFee;
  1070. }
  1071. /**
  1072. * @return User
  1073. */
  1074. public function getClientUser()
  1075. {
  1076. return $this->clientUser;
  1077. }
  1078. /**
  1079. * @param User $clientUser
  1080. */
  1081. public function setClientUser($clientUser)
  1082. {
  1083. $this->clientUser = $clientUser;
  1084. }
  1085. /**
  1086. * @return bool
  1087. */
  1088. public function isAutomaticAssignment()
  1089. {
  1090. return $this->automaticAssignment;
  1091. }
  1092. /**
  1093. * @param bool $automaticAssignment
  1094. */
  1095. public function setAutomaticAssignment($automaticAssignment)
  1096. {
  1097. $this->automaticAssignment = $automaticAssignment;
  1098. }
  1099. /**
  1100. * @return string
  1101. */
  1102. public function getReturnFlightNumber()
  1103. {
  1104. return $this->returnFlightNumber;
  1105. }
  1106. /**
  1107. * @param string $returnFlightNumber
  1108. */
  1109. public function setReturnFlightNumber($returnFlightNumber)
  1110. {
  1111. $this->returnFlightNumber = $returnFlightNumber;
  1112. }
  1113. /**
  1114. * @return string
  1115. */
  1116. public function getReturnFlightLandingTime()
  1117. {
  1118. if (!$this->returnFlightLandingTime) {
  1119. return;
  1120. }
  1121. return $this->returnFlightLandingTime->format('H:i');
  1122. }
  1123. /**
  1124. * @param \DateTime|string $returnFlightLandingTime
  1125. */
  1126. public function setReturnFlightLandingTime($returnFlightLandingTime)
  1127. {
  1128. if (is_string($returnFlightLandingTime)) {
  1129. $timeArray = explode(':', $returnFlightLandingTime);
  1130. $returnFlightLandingTime = new \DateTime();
  1131. $returnFlightLandingTime->setTime($timeArray[0], $timeArray[1]);
  1132. }
  1133. $this->returnFlightLandingTime = $returnFlightLandingTime;
  1134. }
  1135. /**
  1136. * @return \DateTime
  1137. */
  1138. public function getReturnPickUpDate()
  1139. {
  1140. return $this->returnPickUpDate;
  1141. }
  1142. /**
  1143. * @param \DateTime $returnPickUpDate
  1144. */
  1145. public function setReturnPickUpDate($returnPickUpDate)
  1146. {
  1147. $this->returnPickUpDate = $returnPickUpDate;
  1148. }
  1149. /**
  1150. * @return string
  1151. */
  1152. public function getReturnPickUpTime()
  1153. {
  1154. if (!$this->returnPickUpTime) {
  1155. return;
  1156. }
  1157. return $this->returnPickUpTime->format('H:i');
  1158. }
  1159. public function automaticAssignment($driver)
  1160. {
  1161. $this->automaticAssignment = true;
  1162. $this->setDriver($driver);
  1163. $this->needSendToDriver = true;
  1164. }
  1165. public function setNeedSendToDriver($needSendToDriver)
  1166. {
  1167. $this->needSendToDriver = $needSendToDriver;
  1168. }
  1169. public function getNeedSendToDriver()
  1170. {
  1171. return $this->needSendToDriver;
  1172. }
  1173. /**
  1174. * @param \DateTime $returnPickUpTime
  1175. */
  1176. public function setReturnPickUpTime($returnPickUpTime)
  1177. {
  1178. if (is_string($returnPickUpTime)) {
  1179. $timeArray = explode(':', $returnPickUpTime);
  1180. $returnPickUpTime = new \DateTime();
  1181. $returnPickUpTime->setTime($timeArray[0], $timeArray[1]);
  1182. }
  1183. $this->returnPickUpTime = $returnPickUpTime;
  1184. }
  1185. /**
  1186. * @return string
  1187. */
  1188. public function getReturnBookingNotes()
  1189. {
  1190. return $this->returnBookingNotes;
  1191. }
  1192. /**
  1193. * @param string $returnBookingNotes
  1194. */
  1195. public function setReturnBookingNotes($returnBookingNotes)
  1196. {
  1197. $this->returnBookingNotes = $returnBookingNotes;
  1198. }
  1199. /**
  1200. * @param boolean $toSecond
  1201. * @return \DateTime|int
  1202. */
  1203. public function getWaitingTime($toSecond = false)
  1204. {
  1205. if ($toSecond) {
  1206. return empty($this->waitingTime) ? 0 : (intval($this->waitingTime->format('H')) * 3600) +
  1207. (intval($this->waitingTime->format('i')) * 60) +
  1208. intval($this->waitingTime->format('s'));
  1209. }
  1210. return $this->waitingTime;
  1211. }
  1212. /**
  1213. * @param \DateTime $waitingTime
  1214. */
  1215. public function setWaitingTime($waitingTime)
  1216. {
  1217. $this->waitingTime = $waitingTime;
  1218. }
  1219. /**
  1220. * @param bool $toSecond
  1221. * @return \DateTime
  1222. */
  1223. public function getJobWaitingTime($toSecond = false)
  1224. {
  1225. if ($toSecond) {
  1226. return empty($this->jobWaitingTime) ? 0 : (intval($this->jobWaitingTime->format('H')) * 3600) +
  1227. (intval($this->jobWaitingTime->format('i')) * 60) +
  1228. intval($this->jobWaitingTime->format('s'));
  1229. }
  1230. return $this->jobWaitingTime;
  1231. }
  1232. /**
  1233. * @param \DateTime $jobWaitingTime
  1234. */
  1235. public function setJobWaitingTime($jobWaitingTime)
  1236. {
  1237. $this->jobWaitingTime = $jobWaitingTime;
  1238. }
  1239. /**
  1240. * @return string
  1241. */
  1242. public function getFlightNumber()
  1243. {
  1244. return $this->flightNumber;
  1245. }
  1246. /**
  1247. * @param string $flightNumber
  1248. */
  1249. public function setFlightNumber($flightNumber)
  1250. {
  1251. $this->flightNumber = $flightNumber;
  1252. }
  1253. /**
  1254. * @return string
  1255. */
  1256. public function getFlightLandingTime()
  1257. {
  1258. if (!$this->flightLandingTime) {
  1259. return;
  1260. }
  1261. return $this->flightLandingTime->format('H:i');
  1262. }
  1263. /**
  1264. * @param \DateTime $flightLandingTime
  1265. */
  1266. public function setFlightLandingTime($flightLandingTime)
  1267. {
  1268. if (is_string($flightLandingTime)) {
  1269. $timeArray = explode(':', $flightLandingTime);
  1270. $flightLandingTime = new \DateTime();
  1271. $flightLandingTime->setTime($timeArray[0], $timeArray[1]);
  1272. }
  1273. $this->flightLandingTime = $flightLandingTime;
  1274. }
  1275. /**
  1276. * @return string
  1277. */
  1278. public function getClientFirstName()
  1279. {
  1280. return $this->clientFirstName;
  1281. }
  1282. /**
  1283. * @param string $clientFirstName
  1284. */
  1285. public function setClientFirstName($clientFirstName)
  1286. {
  1287. $this->clientFirstName = $clientFirstName;
  1288. }
  1289. /**
  1290. * @return string
  1291. */
  1292. public function getClientLastName()
  1293. {
  1294. return $this->clientLastName;
  1295. }
  1296. /**
  1297. * @param string $clientLastName
  1298. */
  1299. public function setClientLastName($clientLastName)
  1300. {
  1301. $this->clientLastName = $clientLastName;
  1302. }
  1303. /**
  1304. * @return string
  1305. */
  1306. public function getClientPhone()
  1307. {
  1308. return $this->clientPhone;
  1309. }
  1310. /**
  1311. * @param string $clientPhone
  1312. */
  1313. public function setClientPhone($clientPhone)
  1314. {
  1315. $this->clientPhone = $clientPhone;
  1316. }
  1317. /**
  1318. * @return string
  1319. */
  1320. public function getClientEmail()
  1321. {
  1322. return $this->clientEmail;
  1323. }
  1324. /**
  1325. * @param string $clientEmail
  1326. */
  1327. public function setClientEmail($clientEmail)
  1328. {
  1329. $this->clientEmail = $clientEmail;
  1330. }
  1331. public function getVias()
  1332. {
  1333. return $this->vias;
  1334. }
  1335. public function setVias($vias)
  1336. {
  1337. $this->vias = $vias;
  1338. }
  1339. public function deleteVias($vias)
  1340. {
  1341. $this->vias->remove($vias);
  1342. $vias->setBooking(null);
  1343. }
  1344. public function addVias(BookingViasAddress $bookingViasAddress)
  1345. {
  1346. $this->vias->add($bookingViasAddress);
  1347. }
  1348. public function getViasAsArray()
  1349. {
  1350. $vias = [];
  1351. /** @var BookingViasAddress $via */
  1352. foreach ($this->vias as $via) {
  1353. $vias[] = $via->getAddress();
  1354. }
  1355. return $vias;
  1356. }
  1357. public function getCountVias()
  1358. {
  1359. return count($this->vias) > 0 ? count($this->vias) : ' ';
  1360. }
  1361. public function getObjectivesAsArray()
  1362. {
  1363. $objectives = [];
  1364. $bookingData = json_decode($this->getBookingDataSerialized());
  1365. if (is_null($bookingData)) {
  1366. return $objectives;
  1367. }
  1368. $selectedObjectivesIds = $bookingData->selectedObjectives;
  1369. if (!$selectedObjectivesIds) {
  1370. return;
  1371. }
  1372. $selectedObjectivesHours = $bookingData->selectedObjectivesHours;
  1373. $tours = $bookingData->tours;
  1374. $selectedObjectiveArrayById = [];
  1375. foreach ($tours as $tour) {
  1376. foreach ($tour->objectives as $objective) {
  1377. $selectedObjectiveArrayById[$objective->id . '-' . $tour->tourId] = $objective;
  1378. }
  1379. }
  1380. foreach ($selectedObjectivesIds as $selectedObjectiveId) {
  1381. $objectives[] = [
  1382. 'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
  1383. 'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
  1384. 'hour' => $selectedObjectivesHours->$selectedObjectiveId,
  1385. ];
  1386. }
  1387. return $objectives;
  1388. }
  1389. public function getReturnObjectivesAsArray()
  1390. {
  1391. $returnObjectives = [];
  1392. $bookingData = json_decode($this->getBookingDataSerialized());
  1393. if (is_null($bookingData)) {
  1394. return $returnObjectives;
  1395. }
  1396. $selectedObjectivesIds = $bookingData->returnSelectedObjectives;
  1397. if (!$selectedObjectivesIds) {
  1398. return;
  1399. }
  1400. $selectedObjectivesHours = $bookingData->returnSelectedObjectivesHours;
  1401. $tours = $bookingData->tours;
  1402. $selectedObjectiveArrayById = [];
  1403. foreach ($tours as $tour) {
  1404. foreach ($tour->objectives as $objective) {
  1405. $selectedObjectiveArrayById[$objective->id . '-' . $tour->tourId] = $objective;
  1406. }
  1407. }
  1408. foreach ($selectedObjectivesIds as $selectedObjectiveId) {
  1409. $returnObjectives[] = [
  1410. 'name' => $selectedObjectiveArrayById[$selectedObjectiveId]->title,
  1411. 'price' => $selectedObjectiveArrayById[$selectedObjectiveId]->price,
  1412. 'hour' => $selectedObjectivesHours->$selectedObjectiveId,
  1413. ];
  1414. }
  1415. return $returnObjectives;
  1416. }
  1417. public function getPaymentString()
  1418. {
  1419. return Payment::TYPE[$this->getPaymentType()];
  1420. }
  1421. /**
  1422. * @return \DateTime
  1423. */
  1424. public function getPickUpDate()
  1425. {
  1426. return $this->pickUpDate;
  1427. }
  1428. public function setPickUpDate($pickUpDate)
  1429. {
  1430. $this->pickUpDate = $pickUpDate;
  1431. $this->updatePickUpDateTime();
  1432. }
  1433. public function updatePickUpDateTime()
  1434. {
  1435. $pickUpDateTime = $this->pickUpDateTime;
  1436. if (!$pickUpDateTime) {
  1437. $pickUpDateTime = new \DateTime();
  1438. if ($this->pickUpDate) {
  1439. $pickUpDateTime = clone ($this->pickUpDate);
  1440. }
  1441. }
  1442. if ($this->pickUpDate) {
  1443. $pickUpDateTime->setDate(
  1444. $this->pickUpDate->format('Y'),
  1445. $this->pickUpDate->format('m'),
  1446. $this->pickUpDate->format('d')
  1447. );
  1448. }
  1449. if ($this->pickUpTime) {
  1450. $pickUpDateTime->setTime(
  1451. $this->pickUpTime->format('H'),
  1452. $this->pickUpTime->format('i')
  1453. );
  1454. }
  1455. $this->pickUpDateTime = clone ($pickUpDateTime);
  1456. }
  1457. /**
  1458. * @return Payment
  1459. */
  1460. public function getPayment()
  1461. {
  1462. return $this->payment;
  1463. }
  1464. /**
  1465. * @param Payment $payment
  1466. * @return Booking
  1467. */
  1468. public function setPayment($payment)
  1469. {
  1470. $this->payment = $payment;
  1471. return $this;
  1472. }
  1473. /**
  1474. * @return CarType|null
  1475. */
  1476. public function getCarType()
  1477. {
  1478. return $this->carType;
  1479. }
  1480. /**
  1481. * @param CarType|null $carType
  1482. */
  1483. public function setCarType($carType)
  1484. {
  1485. $this->carType = $carType;
  1486. }
  1487. /**
  1488. * @return float
  1489. */
  1490. public function getDistanceUnit()
  1491. {
  1492. return $this->distanceUnit;
  1493. }
  1494. /**
  1495. * @param float $distanceUnit
  1496. *
  1497. * @return Booking
  1498. */
  1499. public function setDistanceUnit($distanceUnit): self
  1500. {
  1501. $this->distanceUnit = $distanceUnit;
  1502. return $this;
  1503. }
  1504. /**
  1505. * @return string
  1506. */
  1507. public function getEstimatedTime()
  1508. {
  1509. return $this->estimatedTime;
  1510. }
  1511. /**
  1512. * @param string $estimatedTime
  1513. *
  1514. * @return Booking
  1515. */
  1516. public function setEstimatedTime($estimatedTime): self
  1517. {
  1518. $this->estimatedTime = $estimatedTime;
  1519. return $this;
  1520. }
  1521. /**
  1522. * @return int|null
  1523. */
  1524. public function getEstimatedTimeInSeconds(): ?int
  1525. {
  1526. return $this->getEstimatedTime()
  1527. ? DateTimeUtils::convertTimeToSeconds($this->getEstimatedTime())
  1528. : null
  1529. ;
  1530. }
  1531. /**
  1532. * @param bool $seconds
  1533. * @return string
  1534. */
  1535. public function getEstimatedTimePrettyFormat($seconds = false)
  1536. {
  1537. $prettyEstimatedTime = '0 minutes';
  1538. if (!empty($this->estimatedTime)) {
  1539. $eT = explode(":", $this->estimatedTime);
  1540. if (count($eT) === 3) {
  1541. $estimatedTime = "";
  1542. if (intval($eT[0]) > 0) {
  1543. $estimatedTime .= intval($eT[0]) . "h ";
  1544. }
  1545. if (intval($eT[1]) > 0) {
  1546. $estimatedTime .= intval($eT[1]) . "min ";
  1547. }
  1548. if (
  1549. ($seconds || empty($estimatedTime)) &&
  1550. intval($eT[2]) > 0
  1551. ) {
  1552. $estimatedTime .= intval($eT[2]) . "s";
  1553. }
  1554. if (!empty($estimatedTime)) {
  1555. $prettyEstimatedTime = $estimatedTime;
  1556. }
  1557. }
  1558. }
  1559. return $prettyEstimatedTime;
  1560. }
  1561. /**
  1562. * @return bool
  1563. */
  1564. public function isCreateAccount()
  1565. {
  1566. return $this->createAccount;
  1567. }
  1568. /**
  1569. * @param bool $createAccount
  1570. */
  1571. public function setCreateAccount($createAccount)
  1572. {
  1573. $this->createAccount = $createAccount;
  1574. }
  1575. /**
  1576. * @return int
  1577. */
  1578. public function getPaymentType()
  1579. {
  1580. return $this->paymentType;
  1581. }
  1582. /**
  1583. * @param int $paymentType
  1584. */
  1585. public function setPaymentType($paymentType)
  1586. {
  1587. $this->paymentType = $paymentType;
  1588. }
  1589. /**
  1590. * @return Booking|null
  1591. */
  1592. public function getReturnBooking()
  1593. {
  1594. return $this->returnBooking;
  1595. }
  1596. /**
  1597. * @param Booking|null $returnBooking
  1598. */
  1599. public function setReturnBooking($returnBooking)
  1600. {
  1601. $this->returnBooking = $returnBooking;
  1602. }
  1603. public function __toString()
  1604. {
  1605. return $this->getId() ? (string) $this->getId() : 'n\a';
  1606. }
  1607. /**
  1608. * @return float
  1609. */
  1610. public function getCancelRefund()
  1611. {
  1612. return $this->cancelRefund;
  1613. }
  1614. /**
  1615. * @param float $cancelRefund
  1616. */
  1617. public function setCancelRefund($cancelRefund)
  1618. {
  1619. $this->cancelRefund = $cancelRefund;
  1620. }
  1621. /**
  1622. * @return string
  1623. */
  1624. public function getCancelReason()
  1625. {
  1626. return $this->cancelReason;
  1627. }
  1628. /**
  1629. * @param string $cancelReason
  1630. */
  1631. public function setCancelReason($cancelReason)
  1632. {
  1633. $this->cancelReason = $cancelReason;
  1634. }
  1635. /**
  1636. * @return Booking
  1637. */
  1638. public function getParentBooking()
  1639. {
  1640. return $this->parentBooking;
  1641. }
  1642. /**
  1643. * @param Booking $parentBooking
  1644. */
  1645. public function setParentBooking($parentBooking)
  1646. {
  1647. $this->parentBooking = $parentBooking;
  1648. }
  1649. /**
  1650. * @return string
  1651. */
  1652. public function getPaymentReference()
  1653. {
  1654. return $this->paymentReference;
  1655. }
  1656. /**
  1657. * @param string $paymentReference
  1658. */
  1659. public function setPaymentReference($paymentReference)
  1660. {
  1661. $this->paymentReference = $paymentReference;
  1662. }
  1663. /**
  1664. * @return ArrayCollection
  1665. */
  1666. public function getBroadcastedDrivers()
  1667. {
  1668. return $this->broadcastedDrivers;
  1669. }
  1670. /**
  1671. * @param ArrayCollection $broadcastedDrivers
  1672. */
  1673. public function setBroadcastedDrivers($broadcastedDrivers)
  1674. {
  1675. $this->broadcastedDrivers = $broadcastedDrivers;
  1676. }
  1677. /**
  1678. * @return ArrayCollection
  1679. */
  1680. public function getUnassignedDriverRequests()
  1681. {
  1682. return $this->unassignedDriverRequests;
  1683. }
  1684. /**
  1685. * @param ArrayCollection $unassignedDriverRequests;
  1686. */
  1687. public function setUnassignedDriverRequests($unassignedDriverRequests)
  1688. {
  1689. $this->unassignedDriverRequests = $unassignedDriverRequests;
  1690. }
  1691. /**
  1692. * @return string
  1693. */
  1694. public function getPickUpPostCode()
  1695. {
  1696. return $this->pickUpPostCode;
  1697. }
  1698. /**
  1699. * @param string $pickUpPostCode
  1700. */
  1701. public function setPickUpPostCode($pickUpPostCode)
  1702. {
  1703. $this->pickUpPostCode = $pickUpPostCode;
  1704. }
  1705. /**
  1706. * @return string
  1707. */
  1708. public function getDestinationPostCode()
  1709. {
  1710. return $this->destinationPostCode;
  1711. }
  1712. /**
  1713. * @param string $destinationPostCode
  1714. *
  1715. * @return Booking
  1716. */
  1717. public function setDestinationPostCode($destinationPostCode)
  1718. {
  1719. $this->destinationPostCode = $destinationPostCode;
  1720. return $this;
  1721. }
  1722. /**
  1723. * @return string
  1724. */
  1725. public function getClientAlternativePhone()
  1726. {
  1727. return $this->clientAlternativePhone;
  1728. }
  1729. /**
  1730. * @param string $clientAlternativePhone
  1731. */
  1732. public function setClientAlternativePhone($clientAlternativePhone)
  1733. {
  1734. $this->clientAlternativePhone = $clientAlternativePhone;
  1735. }
  1736. /**
  1737. * @return string
  1738. */
  1739. public function getClientAlternativeEmail()
  1740. {
  1741. return $this->clientAlternativeEmail;
  1742. }
  1743. /**
  1744. * @param string $clientAlternativeEmail
  1745. */
  1746. public function setClientAlternativeEmail($clientAlternativeEmail)
  1747. {
  1748. $this->clientAlternativeEmail = $clientAlternativeEmail;
  1749. }
  1750. /**
  1751. * @return string
  1752. */
  1753. public function getVoucherCode()
  1754. {
  1755. return $this->voucherCode;
  1756. }
  1757. /**
  1758. * @param string $voucherCode
  1759. */
  1760. public function setVoucherCode($voucherCode)
  1761. {
  1762. $this->voucherCode = $voucherCode;
  1763. }
  1764. /**
  1765. * @return string
  1766. */
  1767. public function getVoucherValue()
  1768. {
  1769. return $this->voucherValue;
  1770. }
  1771. /**
  1772. * @param string $voucherValue
  1773. */
  1774. public function setVoucherValue($voucherValue)
  1775. {
  1776. $this->voucherValue = $voucherValue;
  1777. }
  1778. /**
  1779. * @return ArrayCollection
  1780. */
  1781. public function getNotificationBooking()
  1782. {
  1783. return $this->notificationBooking;
  1784. }
  1785. /**
  1786. * @param ArrayCollection $notificationBooking
  1787. * @return Booking
  1788. */
  1789. public function setNotificationBooking(ArrayCollection $notificationBooking): Booking
  1790. {
  1791. $this->notificationBooking = $notificationBooking;
  1792. return $this;
  1793. }
  1794. /**
  1795. * @param NotificationBookingUpdate $notificationBooking
  1796. * @return Booking
  1797. */
  1798. public function addNotificationBooking(NotificationBookingUpdate $notificationBooking): Booking
  1799. {
  1800. $this->notificationBooking->add($notificationBooking);
  1801. return $this;
  1802. }
  1803. public function isCancel()
  1804. {
  1805. $cancelBooking = [
  1806. self::STATUS_DELETED,
  1807. self::STATUS_OFFICE_CANCELLATION,
  1808. self::STATUS_CANCELLED_OTHER_REASON,
  1809. self::STATUS_CLIENT_CANCELLATION,
  1810. ];
  1811. if (in_array($this->status, $cancelBooking)) {
  1812. return true;
  1813. }
  1814. return false;
  1815. }
  1816. public function canBroadcast()
  1817. {
  1818. if ($this->getDriver()) {
  1819. return false;
  1820. }
  1821. return !$this->isExpireBroadcast();
  1822. }
  1823. public function isExpireBroadcast()
  1824. {
  1825. if (!$this->expireBroadcastDate) {
  1826. return false;
  1827. }
  1828. $currentDate = new \DateTime();
  1829. if ($currentDate > $this->expireBroadcastDate) {
  1830. return false;
  1831. }
  1832. return true;
  1833. }
  1834. /**
  1835. * check if have update notificaitons
  1836. *
  1837. * @return bool
  1838. */
  1839. public function isUpdated()
  1840. {
  1841. $criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
  1842. ->andWhere(Criteria::expr()->eq('driver', $this->driver));
  1843. return $this->getNotificationBooking()->matching($criteria)->count() >= 1;
  1844. }
  1845. /**
  1846. * mark as read all notifications
  1847. */
  1848. public function returnUnSeenUpdated()
  1849. {
  1850. $criteria = Criteria::create()->where(Criteria::expr()->neq('seen', true))
  1851. ->andWhere(Criteria::expr()->eq('driver', $this->driver));
  1852. return $this->getNotificationBooking()->matching($criteria);
  1853. }
  1854. /**
  1855. * @return string
  1856. */
  1857. public function getBookingDataSerialized()
  1858. {
  1859. return $this->bookingDataSerialized;
  1860. }
  1861. /**
  1862. * @param string $bookingDataSerialized
  1863. */
  1864. public function setBookingDataSerialized($bookingDataSerialized)
  1865. {
  1866. $this->bookingDataSerialized = $bookingDataSerialized;
  1867. }
  1868. public function __clone()
  1869. {
  1870. $this->id = null;
  1871. $this->pickUpDateTime = null;
  1872. $this->pickUpDate = null;
  1873. $this->pickUpTime = null;
  1874. }
  1875. /**
  1876. * @return ClientInvoices
  1877. */
  1878. public function getClientInvoice()
  1879. {
  1880. return $this->clientInvoice;
  1881. }
  1882. /**
  1883. * @param ClientInvoices $clientInvoice
  1884. */
  1885. public function setClientInvoice($clientInvoice)
  1886. {
  1887. $this->clientInvoice = $clientInvoice;
  1888. }
  1889. public function formatAddressForListing($address)
  1890. {
  1891. $addressArray = explode(',', $address);
  1892. return [
  1893. array_slice($addressArray, 0, (count($addressArray) - 2)),
  1894. array_slice($addressArray, -2),
  1895. ];
  1896. }
  1897. public function getMeetAndGreetTimePrettyFormat()
  1898. {
  1899. if (!empty($this->getFlightLandingTime())) {
  1900. $pickUpTime = explode(":", $this->getPickUpTime());
  1901. $landingTime = explode(":", $this->getFlightLandingTime());
  1902. $date1 = new \DateTime();
  1903. $date2 = new \DateTime();
  1904. if ($landingTime[0] > $pickUpTime[0]) {
  1905. // the landing time & pick up Time is different day
  1906. // example: landing time 23:50, pick up time: 00:10
  1907. $date1->modify("+1 day");
  1908. }
  1909. $date1->setTime($pickUpTime[0], $pickUpTime[1]);
  1910. $date2->setTime($landingTime[0], $landingTime[1]);
  1911. $difference = date_diff($date1, $date2);
  1912. return ($difference->h ? $difference->h . 'H' : '') .
  1913. ($difference->i . 'M');
  1914. }
  1915. return null;
  1916. }
  1917. /**
  1918. * Set pickUpLat
  1919. *
  1920. * @param float $pickUpLat
  1921. *
  1922. * @return Booking
  1923. */
  1924. public function setPickUpLat($pickUpLat)
  1925. {
  1926. $this->pickUpLat = $pickUpLat;
  1927. return $this;
  1928. }
  1929. /**
  1930. * Get pickUpLat
  1931. *
  1932. * @return float
  1933. */
  1934. public function getPickUpLat()
  1935. {
  1936. return $this->pickUpLat;
  1937. }
  1938. /**
  1939. * Set pickUpLng
  1940. *
  1941. * @param float $pickUpLng
  1942. *
  1943. * @return Booking
  1944. */
  1945. public function setPickUpLng($pickUpLng)
  1946. {
  1947. $this->pickUpLng = $pickUpLng;
  1948. return $this;
  1949. }
  1950. /**
  1951. * Get pickUpLng
  1952. *
  1953. * @return float
  1954. */
  1955. public function getPickUpLng()
  1956. {
  1957. return $this->pickUpLng;
  1958. }
  1959. /**
  1960. * Set destinationLat
  1961. *
  1962. * @param float $destinationLat
  1963. *
  1964. * @return Booking
  1965. */
  1966. public function setDestinationLat($destinationLat)
  1967. {
  1968. $this->destinationLat = $destinationLat;
  1969. return $this;
  1970. }
  1971. /**
  1972. * Get destinationLat
  1973. *
  1974. * @return float
  1975. */
  1976. public function getDestinationLat()
  1977. {
  1978. return $this->destinationLat;
  1979. }
  1980. /**
  1981. * Set destinationLng
  1982. *
  1983. * @param float $destinationLng
  1984. *
  1985. * @return Booking
  1986. */
  1987. public function setDestinationLng($destinationLng)
  1988. {
  1989. $this->destinationLng = $destinationLng;
  1990. return $this;
  1991. }
  1992. /**
  1993. * Get destinationLng
  1994. *
  1995. * @return float
  1996. */
  1997. public function getDestinationLng()
  1998. {
  1999. return $this->destinationLng;
  2000. }
  2001. /**
  2002. * Add voipRecord
  2003. *
  2004. * @param \AdminBundle\Entity\VoipRecord $voipRecord
  2005. *
  2006. * @return Booking
  2007. */
  2008. public function addVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
  2009. {
  2010. $this->voipRecords[] = $voipRecord;
  2011. return $this;
  2012. }
  2013. /**
  2014. * Remove voipRecord
  2015. *
  2016. * @param \AdminBundle\Entity\VoipRecord $voipRecord
  2017. */
  2018. public function removeVoipRecord(\AdminBundle\Entity\VoipRecord $voipRecord)
  2019. {
  2020. $this->voipRecords->removeElement($voipRecord);
  2021. }
  2022. /**
  2023. * Get voipRecords
  2024. *
  2025. * @return \Doctrine\Common\Collections\Collection
  2026. */
  2027. public function getVoipRecords()
  2028. {
  2029. return $this->voipRecords;
  2030. }
  2031. public function isOpen($userEmail)
  2032. {
  2033. $this->lastOpenedUser = $userEmail;
  2034. $this->lastOpenedDate = new \DateTime();
  2035. }
  2036. /**
  2037. * @return \DateTime
  2038. */
  2039. public function getLastOpenedDate()
  2040. {
  2041. return $this->lastOpenedDate;
  2042. }
  2043. /**
  2044. * @param \DateTime $lastOpenedDate
  2045. */
  2046. public function setLastOpenedDate($lastOpenedDate)
  2047. {
  2048. $this->lastOpenedDate = $lastOpenedDate;
  2049. }
  2050. /**
  2051. * @return string
  2052. */
  2053. public function getLastOpenedUser()
  2054. {
  2055. return $this->lastOpenedUser;
  2056. }
  2057. /**
  2058. * @param string $lastOpenedUser
  2059. */
  2060. public function setLastOpenedUser($lastOpenedUser)
  2061. {
  2062. $this->lastOpenedUser = $lastOpenedUser;
  2063. }
  2064. public function getBookingDataSerializedDecoded()
  2065. {
  2066. return json_decode($this->bookingDataSerialized);
  2067. }
  2068. /**
  2069. * @return string
  2070. */
  2071. public function getFullname()
  2072. {
  2073. $firstName = $this->getClientFirstName() ?: 'n/a';
  2074. $lastName = $this->getClientLastName() ?: 'n/a';
  2075. return "{$firstName} {$lastName}";
  2076. }
  2077. public function getTotalCost()
  2078. {
  2079. return $this->getOverridePrice() ? $this->overridePrice : $this->getQuotePrice();
  2080. }
  2081. /**
  2082. * @return string
  2083. */
  2084. public function getFirstBookingCreatedBy()
  2085. {
  2086. $firstBookingHistory = $this->getBookingHistory()->first();
  2087. if ($firstBookingHistory && $user = $firstBookingHistory->getUser()) {
  2088. if ($user->getEmail() === 'online@ctlf.co.uk') {
  2089. return self::CREATED_BY_APP;
  2090. }
  2091. if ($user->hasRole('ROLE_CLIENT')) {
  2092. return self::CREATED_BY_CLIENT;
  2093. }
  2094. }
  2095. return self::CREATED_BY_DISPATCH;
  2096. }
  2097. public function getDriverNameAndInternal()
  2098. {
  2099. if (null != $this->getDriver() && null != $this->getDriver()->getUser()) {
  2100. return $this->getDriver()->getUser()->getFirstname() . ' ' . $this->getDriver()->getUser()->getLastname() . ' (' . $this->getDriver()->getInternalName() . ')';
  2101. } else {
  2102. return $this->getDriver();
  2103. }
  2104. }
  2105. public function getBookingDateFormated()
  2106. {
  2107. return $this->getBookingDate()->format('d/m/Y');
  2108. }
  2109. public function getBookingTimeFormated()
  2110. {
  2111. return $this->getBookingDate()->format('H:i');
  2112. }
  2113. public function getPickUpDateFormated()
  2114. {
  2115. return $this->getPickUpDate()->format('d/m/Y');
  2116. }
  2117. public function getTotalCostWithCurrency($currencySymbol = null)
  2118. {
  2119. if ($currencySymbol == null) {
  2120. $currencySymbol = chr(163);
  2121. }
  2122. return $currencySymbol . ' ' . $this->getTotalCost();
  2123. }
  2124. public function getStatusAsText()
  2125. {
  2126. return $this->getStringStatus($this->status);
  2127. }
  2128. public function convertInMinutesPickUpTime()
  2129. {
  2130. $components = explode(':', $this->pickUpTime->format('H:i'));
  2131. return intval($components[1]) + (intval($components[0]) * 60);
  2132. }
  2133. public function estimateEndDateTime()
  2134. {
  2135. $interval = $this->getEstimatedTime();
  2136. $intervalComponents = explode(':', $interval);
  2137. $minutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
  2138. $pickUp = clone $this->pickUpDateTime;
  2139. $pickUp->add(new \DateInterval('PT' . $minutes . 'M'));
  2140. return $pickUp;
  2141. }
  2142. public function estimateEndHourString()
  2143. {
  2144. return $this->estimateEndDateTime()->format('H:i');
  2145. }
  2146. public function convertInMinutesEndTime()
  2147. {
  2148. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2149. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2150. $interval = $this->estimatedTime;
  2151. $intervalComponents = explode(':', $interval);
  2152. $endMinutes = intval($intervalComponents[0]) * 60 + intval($intervalComponents[1]);
  2153. $total = $pickUpTimeInMinutes + $endMinutes;
  2154. if ($total > 1440) {
  2155. return 1440;
  2156. }
  2157. return $total;
  2158. }
  2159. public function getMgMinutes()
  2160. {
  2161. if (!$this->flightLandingTime) {
  2162. return 0;
  2163. }
  2164. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2165. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2166. $flightLandingTimeComponents = explode(':', $this->flightLandingTime->format('H:i'));
  2167. $flightLandingTimeInMinutes = intval($flightLandingTimeComponents[1]) + (intval($flightLandingTimeComponents[0]) * 60);
  2168. if ($flightLandingTimeInMinutes <= $pickUpTimeInMinutes) {
  2169. return 0;
  2170. }
  2171. return ($flightLandingTimeInMinutes - $pickUpTimeInMinutes);
  2172. }
  2173. public function getMgTime()
  2174. {
  2175. if (!$this->flightLandingTime) {
  2176. return null;
  2177. }
  2178. $pickUpTimeComponents = explode(':', $this->pickUpTime->format('H:i'));
  2179. $pickUpTimeInMinutes = intval($pickUpTimeComponents[1]) + (intval($pickUpTimeComponents[0]) * 60);
  2180. $flightLandingTimeComponents = explode(':', $this->flightLandingTime->format('H:i'));
  2181. $flightLandingTimeInMinutes = intval($flightLandingTimeComponents[1]) + (intval($flightLandingTimeComponents[0]) * 60);
  2182. $difference = $pickUpTimeInMinutes < $flightLandingTimeInMinutes
  2183. ? $pickUpTimeInMinutes + ((24 * 60) - $flightLandingTimeInMinutes)
  2184. : $pickUpTimeInMinutes - $flightLandingTimeInMinutes
  2185. ;
  2186. // mg time return in minutes
  2187. return "{$difference}";
  2188. }
  2189. public function bookingCode($type = null, $main_location = null)
  2190. {
  2191. $resultPostcode = '';
  2192. if ($main_location !== null) {
  2193. if ($main_location == 'US') {
  2194. $pickUpCodeComponents = substr($this->pickUpPostCode, 0, 3);
  2195. $destinationCodeComponents = substr($this->destinationPostCode, 0, 3);
  2196. $resultPostcode = $pickUpCodeComponents . '-' . $destinationCodeComponents;
  2197. }
  2198. if ($main_location == 'UK') {
  2199. $pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
  2200. $destinationCodeComponents = explode(' ', $this->destinationPostCode);
  2201. $resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
  2202. }
  2203. } else {
  2204. $pickUpCodeComponents = explode(' ', $this->pickUpPostCode);
  2205. $destinationCodeComponents = explode(' ', $this->destinationPostCode);
  2206. $resultPostcode = $pickUpCodeComponents[0] . '-' . $destinationCodeComponents[0];
  2207. }
  2208. $result = '';
  2209. if ($type == null) {
  2210. $result .= $this->key;
  2211. }
  2212. $result .= ' ' . $resultPostcode;
  2213. return $result;
  2214. }
  2215. /**
  2216. * @return \DateTime
  2217. */
  2218. public function getSendNotificationUndispatched()
  2219. {
  2220. return $this->sendNotificationUndispatched;
  2221. }
  2222. /**
  2223. * @param \DateTime $sendNotificationUndispatched
  2224. */
  2225. public function setSendNotificationUndispatched($sendNotificationUndispatched)
  2226. {
  2227. $this->sendNotificationUndispatched = $sendNotificationUndispatched;
  2228. }
  2229. /**
  2230. * @return float
  2231. */
  2232. public function getBookingformCCFee()
  2233. {
  2234. return $this->bookingformCCFee;
  2235. }
  2236. /**
  2237. * @param float $bookingformCCFee
  2238. */
  2239. public function setBookingformCCFee($bookingformCCFee)
  2240. {
  2241. $this->bookingformCCFee = (float) $bookingformCCFee;
  2242. }
  2243. /**
  2244. * @return string
  2245. */
  2246. public function getPickupAddressCategory()
  2247. {
  2248. return $this->pickupAddressCategory;
  2249. }
  2250. /**
  2251. * @param string $pickupAddressCategory
  2252. */
  2253. public function setPickupAddressCategory($pickupAddressCategory)
  2254. {
  2255. $this->pickupAddressCategory = $pickupAddressCategory;
  2256. }
  2257. /**
  2258. * @return string
  2259. */
  2260. public function getDropoffAddressCategory()
  2261. {
  2262. return $this->dropoffAddressCategory;
  2263. }
  2264. /**
  2265. * @param string $dropoffAddressCategory
  2266. */
  2267. public function setDropoffAddressCategory($dropoffAddressCategory)
  2268. {
  2269. $this->dropoffAddressCategory = $dropoffAddressCategory;
  2270. }
  2271. /**
  2272. * @return \DateTime
  2273. */
  2274. public function getUnassignedHideAt()
  2275. {
  2276. return $this->unassignedHideAt;
  2277. }
  2278. /**
  2279. * @param \DateTime $unassignedHideAt
  2280. */
  2281. public function setUnassignedHideAt($unassignedHideAt)
  2282. {
  2283. $this->unassignedHideAt = $unassignedHideAt;
  2284. return $this;
  2285. }
  2286. /**
  2287. * @param Ticket $ticket
  2288. *
  2289. * @return Booking
  2290. */
  2291. public function addQuestion(Ticket $ticket)
  2292. {
  2293. $ticket->setBooking($this);
  2294. $this->tickets->add($ticket);
  2295. return $this;
  2296. }
  2297. /**
  2298. * @param Ticket $ticket
  2299. *
  2300. * @return Booking
  2301. */
  2302. public function removeTicket(Ticket $ticket)
  2303. {
  2304. if (!$this->tickets->contains($ticket)) {
  2305. return;
  2306. }
  2307. $this->tickets->removeElement($ticket);
  2308. $ticket->setBooking(null);
  2309. return $this;
  2310. }
  2311. /**
  2312. * @return ArrayCollection
  2313. */
  2314. public function getTickets()
  2315. {
  2316. return $this->tickets;
  2317. }
  2318. /**
  2319. * @param int $bookingSourceType
  2320. */
  2321. public function setBookingSourceType($bookingSourceType)
  2322. {
  2323. $this->bookingSourceType = $bookingSourceType;
  2324. }
  2325. /**
  2326. * @return int
  2327. */
  2328. public function getBookingSourceType()
  2329. {
  2330. return $this->bookingSourceType;
  2331. }
  2332. public function getBookingSourceTypeName()
  2333. {
  2334. if (
  2335. $this->bookingSourceType &&
  2336. isset(self::$sourceTypes[$this->bookingSourceType])
  2337. ) {
  2338. return self::$sourceTypes[$this->bookingSourceType];
  2339. }
  2340. }
  2341. public function isBeforeOnTheWay()
  2342. {
  2343. return in_array($this->getStatus(), [
  2344. Booking::STATUS_NEW_BOOKING,
  2345. Booking::STATUS_DISPATCHED,
  2346. Booking::STATUS_DRIVER_REJECT,
  2347. Booking::STATUS_DRIVER_ACCEPT,
  2348. ]);
  2349. }
  2350. public function getClientCancellationCase()
  2351. {
  2352. $status = $this->getStatus();
  2353. if ($this->isBeforeOnTheWay()) {
  2354. return ClientCancellationFee::CANCELLATION_CASE_BEFORE_ON_THE_WAY;
  2355. }
  2356. if ($status === Booking::STATUS_ON_THE_WAY) {
  2357. foreach ($this->getBookingHistory() as $history) {
  2358. if ($history->getActionType() !== BookingHistory::ACTION_TYPE_CHANGED_STATUS) {
  2359. continue;
  2360. }
  2361. $payload = $history->getPayload();
  2362. if (intval($payload['old_status']) !== self::STATUS_DISPATCHED && intval($payload['current_status']) !== self::STATUS_ON_THE_WAY) {
  2363. continue;
  2364. }
  2365. $now = new \DateTime();
  2366. $diff = $history->getDate()->getTimestamp() - $now->getTimestamp();
  2367. // 2 mins difference
  2368. return $diff <= 120 ? ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY_STARTED : ClientCancellationFee::CANCELLATION_CASE_ON_THE_WAY;
  2369. }
  2370. }
  2371. if ($status === Booking::STATUS_ARRIVED_AND_WAITING) {
  2372. return ClientCancellationFee::CANCELLATION_CASE_ARRIVED_AND_WAITING;
  2373. }
  2374. return null;
  2375. }
  2376. /**
  2377. * @return bool
  2378. */
  2379. public function hasReturn(): bool
  2380. {
  2381. return null !== $this->getReturnBooking();
  2382. }
  2383. /**
  2384. * @return bool
  2385. */
  2386. public function isPmg(): bool
  2387. {
  2388. return !empty($this->getPmg());
  2389. }
  2390. /**
  2391. * @return bool
  2392. */
  2393. public function isReturnPmg(): bool
  2394. {
  2395. return !empty($this->getReturnPmg());
  2396. }
  2397. public function isPickupAddressCategoryPOI()
  2398. {
  2399. return in_array($this->getPickupAddressCategory(), Area::$categories);
  2400. }
  2401. public function isDropoffAddressCategoryPOI()
  2402. {
  2403. return in_array($this->getDropoffAddressCategory(), Area::$categories);
  2404. }
  2405. /**
  2406. * @return bool
  2407. */
  2408. public function isFixedPrice(): bool
  2409. {
  2410. if (null === $this->getBookingDataSerialized()) {
  2411. return false;
  2412. }
  2413. $data = \json_decode($this->getBookingDataSerialized());
  2414. if (JSON_ERROR_NONE !== \json_last_error()) {
  2415. return false;
  2416. }
  2417. if (!isset($data->result)) {
  2418. return false;
  2419. }
  2420. $result = $data->result;
  2421. if (empty($result->route)) {
  2422. return false;
  2423. }
  2424. $route = $result->route[0];
  2425. return isset($route->fixedPrice) && $route->fixedPrice;
  2426. }
  2427. /**
  2428. * @return bool
  2429. */
  2430. public function isLiveUpdateNotificationSent(): bool
  2431. {
  2432. return $this->isLiveUpdateNotificationSent;
  2433. }
  2434. /**
  2435. * @param bool $isLiveUpdateNotificationSent
  2436. *
  2437. * @return self
  2438. */
  2439. public function setIsLiveUpdatedNotificationSent(bool $isLiveUpdateNotificationSent): self
  2440. {
  2441. $this->isLiveUpdateNotificationSent = $isLiveUpdateNotificationSent;
  2442. return $this;
  2443. }
  2444. }