PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.6.6
VikBooking Hotel Booking Engine & PMS v1.6.6
1.8.16 1.8.15 1.8.14 1.8.13 1.8.12 1.8.11 1.8.10 1.8.9 1.8.6 1.8.7 1.8.8 trunk 1.6.0 1.6.1 1.6.2 1.6.3 1.6.4 1.6.5 1.6.6 1.6.7 1.6.8 1.6.9 1.7.0 1.7.1 1.7.2 All 37 releases
vikbooking / site / views / booking / view.html.php

view.html.php in VikBooking Hotel Booking Engine & PMS 1.6.6, at site/views/booking/view.html.php

389 lines 13.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * @package VikBooking
4 * @subpackage com_vikbooking
5 * @author Alessio Gaggii - e4j - Extensionsforjoomla.com
6 * @copyright Copyright (C) 2018 e4j - Extensionsforjoomla.com. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 * @link https://vikwp.com
9 */
10
11 defined('ABSPATH') or die('No script kiddies please!');
12
13 jimport('joomla.application.component.view');
14
15 class VikbookingViewBooking extends JViewVikBooking
16 {
17 public function display($tpl = null)
18 {
19 $dbo = JFactory::getDbo();
20 $app = JFactory::getApplication();
21 $document = JFactory::getDocument();
22 $vbo_tn = VikBooking::getTranslator();
23
24 // validation of data and availability before the rendering
25 $sid = VikRequest::getString('sid', '', 'request');
26 $ts = VikRequest::getString('ts', '', 'request');
27 if (empty($sid) || empty($ts)) {
28 showSelectVb(JText::translate('VBINSUFDATA'));
29 return;
30 }
31
32 $q = "SELECT `o`.*,(SELECT SUM(`or`.`adults`) FROM `#__vikbooking_ordersrooms` AS `or` WHERE `or`.`idorder`=`o`.`id`) AS `tot_adults` FROM `#__vikbooking_orders` AS `o` WHERE (`o`.`sid`=" . $dbo->quote($sid) . " OR `o`.`idorderota`=" . $dbo->quote($sid) . ") AND `o`.`ts`=" . $dbo->quote($ts);
33 $dbo->setQuery($q, 0, 1);
34 $dbo->execute();
35 if (!$dbo->getNumRows()) {
36 showSelectVb(JText::translate('VBORDERNOTFOUND'));
37 return;
38 }
39 $order = $dbo->loadAssoc();
40
41 // availability helper
42 $av_helper = VikBooking::getAvailabilityInstance();
43
44 // room stay dates in case of split stay
45 $room_stay_dates = [];
46 if ($order['split_stay']) {
47 if ($order['status'] == 'confirmed') {
48 $room_stay_dates = $av_helper->loadSplitStayBusyRecords($order['id']);
49 } else {
50 $room_stay_dates = VBOFactory::getConfig()->getArray('split_stay_' . $order['id'], []);
51 }
52 }
53
54 if ($order['status'] == 'confirmed') {
55 // prepare impression data for channels
56 $impressiondata = $order;
57 $q = "SELECT `or`.`idtar`,`d`.`idprice`,`p`.`idiva`,`t`.`aliq`,`t`.`taxcap` FROM `#__vikbooking_ordersrooms` AS `or` " .
58 "LEFT JOIN `#__vikbooking_dispcost` `d` ON `d`.`id`=`or`.`idtar` " .
59 "LEFT JOIN `#__vikbooking_prices` `p` ON `p`.`id`=`d`.`idprice` " .
60 "LEFT JOIN `#__vikbooking_iva` `t` ON `t`.`id`=`p`.`idiva` " .
61 "WHERE `or`.`idorder`='".$order['id']."' ORDER BY `t`.`aliq` ASC";
62 $dbo->setQuery($q, 0, 1);
63 $dbo->execute();
64 if ($dbo->getNumRows() == 1) {
65 $taxdata = $dbo->loadAssoc();
66 $taxes = 0;
67 if (!empty($taxdata['aliq'])) {
68 $realtotal = round(($order['total'] / ((100 + $taxdata['aliq']) / 100)), 2);
69 $taxes = round(($order['total'] - $realtotal), 2);
70 /**
71 * Tax Cap implementation.
72 *
73 * @since 1.12
74 */
75 if ($taxdata['taxcap'] > 0 && $taxes > $taxdata['taxcap']) {
76 $realtotal = $order['total'] - $taxdata['taxcap'];
77 $taxes = $taxdata['taxcap'];
78 }
79 $impressiondata['total'] = $realtotal;
80 }
81 $impressiondata['taxes'] = $taxes;
82 $impressiondata['fees'] = 0;
83 }
84 VikBooking::invokeChannelManager(true, $impressiondata);
85 // end prepare impression data for channels
86 } elseif ($order['status'] == 'standby') {
87 $roomavail = false;
88
89 $q = $dbo->getQuery(true)
90 ->select($dbo->qn('or') . '.*')
91 ->select($dbo->qn('r.units'))
92 ->from($dbo->qn('#__vikbooking_ordersrooms', 'or'))
93 ->leftJoin($dbo->qn('#__vikbooking_rooms', 'r') . ' ON ' . $dbo->qn('or.idroom') . ' = ' . $dbo->qn('r.id'))
94 ->where($dbo->qn('or.idorder') . ' = ' . (int)$order['id'])
95 ->order($dbo->qn('or.id') . ' ASC');
96
97 $dbo->setQuery($q);
98 $orderrooms = $dbo->loadAssocList();
99
100 foreach ($orderrooms as $kor => $or) {
101 // determine proper values for this room
102 $room_stay_checkin = $order['checkin'];
103 $room_stay_checkout = $order['checkout'];
104 if ($order['split_stay'] && $room_stay_dates && isset($room_stay_dates[$kor]) && $room_stay_dates[$kor]['idroom'] == $or['idroom']) {
105 $room_stay_checkin = !empty($room_stay_dates[$kor]['checkin_ts']) ? $room_stay_dates[$kor]['checkin_ts'] : $room_stay_dates[$kor]['checkin'];
106 $room_stay_checkout = !empty($room_stay_dates[$kor]['checkout_ts']) ? $room_stay_dates[$kor]['checkout_ts'] : $room_stay_dates[$kor]['checkout'];
107 }
108
109 // make sure room is still available
110 $roomavail = VikBooking::roomBookable($or['idroom'], $or['units'], $room_stay_checkin, $room_stay_checkout);
111 if (!$roomavail) {
112 break;
113 }
114 }
115
116 $today_midnight = mktime(0, 0, 0, date('n'), date('j'), date('Y'));
117 $autoremove = false;
118 if ($today_midnight > $order['checkin']) {
119 $roomavail = false;
120 }
121 $minautoremove = VikBooking::getMinutesAutoRemove();
122 $mins_elapsed = floor((time() - $order['ts']) / 60);
123 if ($minautoremove > 0 && $mins_elapsed > $minautoremove) {
124 $roomavail = false;
125 $autoremove = true;
126 }
127
128 /**
129 * Make sure not to cancel an OTA pending reservation.
130 *
131 * @since 1.15.4 (J) - 1.5.10 (WP)
132 */
133 $is_ota_pending = (!empty($order['type']) && !empty($order['channel']));
134
135 if ($roomavail || $is_ota_pending) {
136 // invoke channel impression
137 VikBooking::invokeChannelManager(false);
138 //
139 } else {
140 // set the booking to cancelled
141 $q = "UPDATE `#__vikbooking_orders` SET `status`='cancelled' WHERE `id`=".(int)$order['id'].";";
142 $dbo->setQuery($q);
143 $dbo->execute();
144 // update status in the array
145 $order['status'] = 'cancelled';
146 //
147 $q = "DELETE FROM `#__vikbooking_tmplock` WHERE `idorder`=" . (int)$order['id'] . ";";
148 $dbo->setQuery($q);
149 $dbo->execute();
150 $q = "SELECT * FROM `#__vikbooking_ordersbusy` WHERE `idorder`=".(int)$order['id'].";";
151 $dbo->setQuery($q);
152 $dbo->execute();
153 if ($dbo->getNumRows() > 0) {
154 $ordbusy = $dbo->loadAssocList();
155 foreach ($ordbusy as $ob) {
156 $q = "DELETE FROM `#__vikbooking_busy` WHERE `id`=".(int)$ob['idbusy'].";";
157 $dbo->setQuery($q);
158 $dbo->execute();
159 }
160 }
161 $q = "DELETE FROM `#__vikbooking_ordersbusy` WHERE `idorder`=".(int)$order['id'].";";
162 $dbo->setQuery($q);
163 $dbo->execute();
164
165 /**
166 * We now save onto a var the full error message to understand what made the booking become cancelled.
167 * This way, by checking the booking history it will be easy to understand the cause of the issue.
168 *
169 * @since October 15th 2020
170 */
171 $history_err_descr = '';
172 if ($today_midnight > $order['checkin']) {
173 $history_err_descr = JText::translate('VBOBOOKNOLONGERPAYABLE');
174 } elseif ($autoremove === true) {
175 $history_err_descr = JText::translate('VBOERRAUTOREMOVED');
176 } else {
177 $history_err_descr = JText::translate('VBERRREPSEARCH');
178 }
179 if (!empty($history_err_descr)) {
180 VikError::raiseWarning('', $history_err_descr);
181 }
182
183 //Booking History
184 VikBooking::getBookingHistoryInstance()->setBid($order['id'])->store('CA', $history_err_descr);
185 //
186 }
187 }
188
189 // render the booking details
190
191 // set noindex instruction for robots
192 $document->setMetaData('robots', 'noindex,follow');
193
194 // load jQuery
195 if (VikBooking::loadJquery()) {
196 JHtml::fetch('jquery.framework', true, true);
197 }
198
199 $tars = [];
200 $cookie = $app->input->cookie;
201 $pcheckin = $order['checkin'];
202 $pcheckout = $order['checkout'];
203 $secdiff = $pcheckout - $pcheckin;
204 $daysdiff = $secdiff / 86400;
205 if (is_int($daysdiff)) {
206 if ($daysdiff < 1) {
207 $daysdiff = 1;
208 }
209 } else {
210 if ($daysdiff < 1) {
211 $daysdiff = 1;
212 } else {
213 $sum = floor($daysdiff) * 86400;
214 $newdiff = $secdiff - $sum;
215 $maxhmore = VikBooking::getHoursMoreRb() * 3600;
216 if ($maxhmore >= $newdiff) {
217 $daysdiff = floor($daysdiff);
218 } else {
219 $daysdiff = ceil($daysdiff);
220 }
221 }
222 }
223 $is_package = !empty($order['pkg']) ? true : false;
224 $orderrooms = [];
225 $q = "SELECT `or`.`idroom`,`or`.`adults`,`or`.`children`,`or`.`idtar`,`or`.`optionals`,`or`.`roomindex`,`or`.`pkg_id`,`or`.`pkg_name`,`or`.`cust_cost`,`or`.`cust_idiva`,`or`.`extracosts`,`or`.`room_cost`,`or`.`otarplan`,`r`.`id` AS `r_reference_id`,`r`.`name`,`r`.`img`,`r`.`idcarat`,`r`.`fromadult`,`r`.`toadult` FROM `#__vikbooking_ordersrooms` AS `or`,`#__vikbooking_rooms` AS `r` WHERE `or`.`idorder`='".$order['id']."' AND `or`.`idroom`=`r`.`id` ORDER BY `or`.`id` ASC;";
226 $dbo->setQuery($q);
227 $dbo->execute();
228 if ($dbo->getNumRows() > 0) {
229 $orderrooms = $dbo->loadAssocList();
230 $vbo_tn->translateContents($orderrooms, '#__vikbooking_rooms', array('id' => 'r_reference_id'));
231 foreach ($orderrooms as $kor => $or) {
232 $num = $kor + 1;
233 if ($is_package === true || (!empty($or['cust_cost']) && $or['cust_cost'] > 0.00)) {
234 //package or custom cost set from the back-end
235 continue;
236 }
237 $q = "SELECT `t`.*,`p`.`name`,`p`.`free_cancellation`,`p`.`canc_deadline`,`p`.`canc_policy` FROM `#__vikbooking_dispcost` AS `t` LEFT JOIN `#__vikbooking_prices` AS `p` ON `t`.`idprice`=`p`.`id` WHERE `t`.`id`=" . (int)$or['idtar'] . ";";
238 $dbo->setQuery($q);
239 $dbo->execute();
240 if (!$dbo->getNumRows()) {
241 continue;
242 }
243 $tar = $dbo->loadAssocList();
244 $vbo_tn->translateContents($tar, '#__vikbooking_prices', array('id' => 'idprice'));
245
246 // determine proper values for this room
247 $room_stay_checkin = $order['checkin'];
248 $room_stay_checkout = $order['checkout'];
249 $room_stay_nights = $order['days'];
250 if ($order['split_stay'] && count($room_stay_dates) && isset($room_stay_dates[$kor]) && $room_stay_dates[$kor]['idroom'] == $or['idroom']) {
251 $room_stay_checkin = !empty($room_stay_dates[$kor]['checkin_ts']) ? $room_stay_dates[$kor]['checkin_ts'] : $room_stay_dates[$kor]['checkin'];
252 $room_stay_checkout = !empty($room_stay_dates[$kor]['checkout_ts']) ? $room_stay_dates[$kor]['checkout_ts'] : $room_stay_dates[$kor]['checkout'];
253 $room_stay_nights = $av_helper->countNightsOfStay($room_stay_checkin, $room_stay_checkout);
254 }
255
256 // apply seasonal rates
257 $tar = VikBooking::applySeasonsRoom($tar, $room_stay_checkin, $room_stay_checkout);
258
259 // apply OBP rules
260 $tar = VBORoomHelper::getInstance()->applyOBPRules($tar, $or, $or['adults']);
261
262 // push tariffs
263 $tars[$num] = $tar[0];
264 }
265 }
266
267 $days_to_arrival = 0;
268 $now_info = getdate();
269 $checkin_info = getdate($order['checkin']);
270 if ($now_info[0] < $checkin_info[0]) {
271 while ($now_info[0] < $checkin_info[0]) {
272 if (!($now_info['mday'] != $checkin_info['mday'] || $now_info['mon'] != $checkin_info['mon'] || $now_info['year'] != $checkin_info['year'])) {
273 break;
274 }
275 $days_to_arrival++;
276 $now_info = getdate(mktime(0, 0, 0, $now_info['mon'], ($now_info['mday'] + 1), $now_info['year']));
277 }
278 }
279
280 $is_refundable = 0;
281 $daysadv_refund_arr = [];
282 $daysadv_refund = 0;
283 $canc_policy = '';
284 foreach ($tars as $num => $tar) {
285 if ($tar['free_cancellation'] < 1) {
286 // if at least one rate plan is non-refundable, the whole reservation cannot be cancelled
287 $is_refundable = 0;
288 $daysadv_refund_arr = [];
289 break;
290 }
291 $is_refundable = 1;
292 $daysadv_refund_arr[] = $tar['canc_deadline'];
293 }
294
295 // get the rate plan with the lowest cancellation deadline
296 $daysadv_refund = count($daysadv_refund_arr) > 0 ? min($daysadv_refund_arr) : $daysadv_refund;
297 if ($daysadv_refund > 0) {
298 foreach ($tars as $num => $tar) {
299 if ($tar['free_cancellation'] > 0 && $tar['canc_deadline'] == $daysadv_refund) {
300 //get the cancellation policy from the first rate plan with free cancellation and same cancellation deadline
301 $canc_policy = $tar['canc_policy'];
302 break;
303 }
304 }
305 }
306
307 $payment = "";
308 if (!empty($order['idpayment'])) {
309 $exppay = explode('=', $order['idpayment']);
310 $payment = VikBooking::getPayment($exppay[0], $vbo_tn);
311 }
312 $pnodep = VikRequest::getString('nodep', '', 'request');
313 $cnodep = $cookie->get('vboFA', '', 'string');
314 $nodep = intval($pnodep) > 0 || intval($cnodep) > 0 ? 1 : 0;
315
316 /**
317 * Upselling extra services only for non-cancelled bookings
318 * with a check-out date in the future.
319 *
320 * @since 1.13.0 (J) - 1.3.0 (WP)
321 */
322 $upselling = [];
323 if ($order['status'] != 'cancelled' && VikBooking::upsellingEnabled() && $order['checkout'] > time()) {
324 $upsell_data = [];
325 foreach ($orderrooms as $kor => $or) {
326 $room_data = new stdClass;
327 $room_data->id = $or['idroom'];
328 $room_data->name = $or['name'];
329 $room_data->img = $or['img'];
330 $room_data->adults = $or['adults'];
331 $room_data->children = $or['children'];
332 $room_data->nights = $order['days'];
333 $room_data->options = [];
334 if (!empty($or['optionals'])) {
335 $optids = explode(';', $or['optionals']);
336 foreach ($optids as $optid) {
337 if (!empty($optid)) {
338 // the : may express the quantity
339 $optidparts = explode(':', $optid);
340 array_push($room_data->options, (int)$optidparts[0]);
341 }
342 }
343 }
344 array_push($upsell_data, $room_data);
345 }
346 $upselling = VikBooking::loadUpsellingData(
347 $upsell_data,
348 array(
349 'id' => $order['id'],
350 'checkin' => $order['checkin'],
351 'checkout' => $order['checkout'],
352 ),
353 $vbo_tn
354 );
355 }
356
357 /**
358 * Trigger first tracking conversion on booking.
359 *
360 * @since 1.16.3 (J) - 1.6.3 (WP)
361 */
362 VikBooking::getTracker()->triggerBookingConversion($order);
363
364 $this->ord = $order;
365 $this->orderrooms = $orderrooms;
366 $this->tars = $tars;
367 $this->days_to_arrival = $days_to_arrival;
368 $this->is_refundable = $is_refundable;
369 $this->daysadv_refund = $daysadv_refund;
370 $this->canc_policy = $canc_policy;
371 $this->payment = $payment;
372 $this->nodep = $nodep;
373 $this->upselling = $upselling;
374 $this->vbo_tn = $vbo_tn;
375
376 // theme
377 $theme = VikBooking::getTheme();
378 if ($theme != 'default') {
379 $thdir = VBO_SITE_PATH . DIRECTORY_SEPARATOR . 'themes' . DIRECTORY_SEPARATOR . $theme . DIRECTORY_SEPARATOR . 'booking';
380 if (is_dir($thdir)) {
381 $this->_setPath('template', $thdir . DIRECTORY_SEPARATOR);
382 }
383 }
384 //
385
386 parent::display($tpl);
387 }
388 }
389