/**
  * Display
  */
 public function display($tpl = null)
 {
     // load app
     $this->app = CHClient::getApp();
     // get the booking info
     $this->booking = $this->get('Booking');
     // no booking found
     if (!$this->booking) {
         $this->setLayout('errors');
         parent::display($tpl);
         return;
     }
     // processing booking
     if ($this->booking->booking_status >= 40) {
         return $this->displayProcessing();
     }
     // new booking analytics tracking
     $this->new_booking = false;
     if ($this->app->getUserState('chclient.new_booking', false)) {
         $this->new_booking = (object) ['booking_id' => $this->booking->booking_id, 'hotel' => $this->booking->hotel->title, 'total' => $this->booking->amounts->total, 'currency' => $this->booking->currency];
         $this->new_booking->rooms = [];
         foreach ($this->booking->rooms as $room) {
             $new_booking_room = (object) ['title' => $room->title, 'reference' => $room->reference, 'total' => $room->amounts->total];
             $this->new_booking->rooms[] = $new_booking_room;
         }
         $this->app->setUserState('chclient.new_booking', null);
     }
     // determine free cancellation
     $this->data = (object) [];
     $this->data->free_cancellation = 1;
     $this->data->deadline = '';
     $deadline = 00;
     foreach ($this->booking->rooms as $room) {
         $rate_deadline = CHLIbdate::sqlToInt($room->rate->deadline);
         if ($rate_deadline > $deadline) {
             $this->data->deadline = $room->rate->deadline;
         }
         if (!in_array($room->rate->conditions, ['pay_at_hotel', 'deposit_refundable', 'prepay_refundable'])) {
             $this->data->free_cancellation = 0;
         }
     }
     if ($this->data->free_cancellation) {
         $this->data->free_cancellation = CHLibDate::isGreater($this->data->deadline, CHLibDate::dateToSql(false));
     }
     // print voucher ?
     if ($this->booking && CHLib::input()->get('print')) {
         return $this->printVoucher();
     }
     // set document title
     $this->document->setTitle(CHClient::string('your_booking') . ' - ' . $this->booking->booking_id);
     // display
     parent::display($tpl);
 }
Example #2
0
 /**
  * Extend the view
  */
 protected function extendView()
 {
     // check we are not on a error view
     if ($this->availability->errors->errors) {
         return;
     }
     // load view info
     $this->loadRooms();
     $this->loadExtras();
     // data
     $this->data->total = $this->rooms->total + $this->extras->total;
     $this->data->currency_total = $this->rooms->currency_total + $this->extras->currency_total;
     $this->data->deposit = 0;
     $this->data->free_cancellation = 1;
     $this->data->deadline = '';
     $deadline = 00;
     foreach ($this->rooms->units as $i => $room) {
         $amount = $room->amount + (isset($this->extras->amount[$i]) ? $this->extras->amount[$i] : 0);
         $this->data->deposit += $this->calculateDeposit($amount, $room);
         $rate_deadline = CHLIbdate::sqlToInt($room->rate_deadline);
         if ($rate_deadline > $deadline) {
             $this->data->deadline = $room->rate_deadline;
         }
         if (!$room->rate_free_cancellation) {
             $this->data->free_cancellation = 0;
         }
     }
     $this->data->currency_deposit = round($this->data->deposit * $this->availability->results->currency_conversion, 2);
     // check deposit is not higher than the reservation
     if ($this->data->deposit > $this->data->total) {
         $this->data->deposit = $this->data->total;
         $this->data->currency_deposit = $this->data->currency_total;
     }
     // booking form state
     $this->data->request = false;
     $app = CHCLient::getApp();
     if ($app->getUserState('chclient.booking_request')) {
         $this->data->request = $app->getUserState('chclient.booking_request');
         $this->data->request_errors = $app->getUserState('chclient.booking_errors');
         $app->setUserState('chclient.booking_request', null);
         $app->setUserState('chclient.booking_errors', null);
     }
 }