| @@ -94,8 +94,24 @@ | ||
| 94 | 94 | |
| 95 | 95 | $dbo->setQuery($q); |
| 96 | 96 | $orderrooms = $dbo->loadAssocList(); |
| 97 | 97 | |
| 98 | + /** | |
| 99 | + * Even if redundant, we read the eventually occupied records by this booking ID to ensure | |
| 100 | + * server-side cache will not produce a booking cancellation after receiving a valid payment. | |
| 101 | + * An eventual list of busy record IDs is passed to the method for checking if the room is | |
| 102 | + * available, because the status of the reservation may actually be confirmed already. | |
| 103 | + * | |
| 104 | + * @since 1.16.9 (J) - 1.6.9 (WP) | |
| 105 | + */ | |
| 106 | + $dbo->setQuery( | |
| 107 | + $dbo->getQuery(true) | |
| 108 | + ->select($dbo->qn('idbusy')) | |
| 109 | + ->from($dbo->qn('#__vikbooking_ordersbusy')) | |
| 110 | + ->where($dbo->qn('idorder') . ' = ' . (int)$order['id']) | |
| 111 | + ); | |
| 112 | + $skip_busy_ids = array_column($dbo->loadAssocList(), 'idbusy'); | |
| 113 | + | |
| 98 | 114 | foreach ($orderrooms as $kor => $or) { |
| 99 | 115 | // determine proper values for this room |
| 100 | 116 | $room_stay_checkin = $order['checkin']; |
| 101 | 117 | $room_stay_checkout = $order['checkout']; |
| @@ -104,26 +120,53 @@ | ||
| 104 | 120 | $room_stay_checkout = !empty($room_stay_dates[$kor]['checkout_ts']) ? $room_stay_dates[$kor]['checkout_ts'] : $room_stay_dates[$kor]['checkout']; |
| 105 | 121 | } |
| 106 | 122 | |
| 107 | 123 | // make sure room is still available |
| 108 | - $roomavail = VikBooking::roomBookable($or['idroom'], $or['units'], $room_stay_checkin, $room_stay_checkout); | |
| 124 | + $roomavail = VikBooking::roomBookable($or['idroom'], $or['units'], $room_stay_checkin, $room_stay_checkout, $skip_busy_ids); | |
| 109 | 125 | if (!$roomavail) { |
| 110 | 126 | break; |
| 111 | 127 | } |
| 112 | 128 | } |
| 113 | 129 | |
| 130 | + // tell if the booking has been automatically cancelled | |
| 131 | + $autoremove = false; | |
| 132 | + | |
| 133 | + // make sure we are not beyond the check-in date and time | |
| 114 | 134 | $today_midnight = mktime(0, 0, 0, date('n'), date('j'), date('Y')); |
| 115 | - $autoremove = false; | |
| 116 | 135 | if ($today_midnight > $order['checkin']) { |
| 117 | 136 | $roomavail = false; |
| 118 | 137 | } |
| 119 | - $minautoremove = VikBooking::getMinutesAutoRemove(); | |
| 120 | - $mins_elapsed = floor((time() - $order['ts']) / 60); | |
| 121 | - if ($minautoremove > 0 && $mins_elapsed > $minautoremove) { | |
| 122 | - $roomavail = false; | |
| 123 | - $autoremove = true; | |
| 138 | + | |
| 139 | + /** | |
| 140 | + * Check if we are dealing with a pending booking solution of a quote. | |
| 141 | + * | |
| 142 | + * @since 1.18.8 (J) - 1.8.8 (WP) | |
| 143 | + */ | |
| 144 | + $quoteValidUntilDt = null; | |
| 145 | + if (!empty($order['idquote'])) { | |
| 146 | + // load quote record | |
| 147 | + $quoteRecord = VBOMvcModel::getInstance('quote')->getItem((int) $order['idquote']); | |
| 148 | + if (!empty($quoteRecord->valid_until)) { | |
| 149 | + $quoteValidUntilDt = JFactory::getDate($quoteRecord->valid_until); | |
| 150 | + } | |
| 124 | 151 | } |
| 125 | 152 | |
| 153 | + if ($quoteValidUntilDt) { | |
| 154 | + // make sure the quote is still valid | |
| 155 | + if (JFactory::getDate('now') > $quoteValidUntilDt) { | |
| 156 | + $roomavail = false; | |
| 157 | + $autoremove = true; | |
| 158 | + } | |
| 159 | + } else { | |
| 160 | + // check global settings for booking auto-cancellation | |
| 161 | + $minautoremove = VikBooking::getMinutesAutoRemove(); | |
| 162 | + $mins_elapsed = floor((time() - $order['ts']) / 60); | |
| 163 | + if ($minautoremove > 0 && $mins_elapsed > $minautoremove) { | |
| 164 | + $roomavail = false; | |
| 165 | + $autoremove = true; | |
| 166 | + } | |
| 167 | + } | |
| 168 | + | |
| 126 | 169 | /** |
| 127 | 170 | * Make sure not to cancel an OTA pending reservation. |
| 128 | 171 | * |
| 129 | 172 | * @since 1.15.4 (J) - 1.5.10 (WP) |
| @@ -185,9 +228,9 @@ | ||
| 185 | 228 | |
| 186 | 229 | // render the booking details |
| 187 | 230 | |
| 188 | 231 | // set noindex instruction for robots |
| 189 | - $document->setMetaData('robots', 'noindex,follow'); | |
| 232 | + $document->setMetaData('robots', 'noindex, nofollow'); | |
| 190 | 233 | |
| 191 | 234 | // load jQuery |
| 192 | 235 | if (VikBooking::loadJquery()) { |
| 193 | 236 | JHtml::fetch('jquery.framework', true, true); |
| @@ -217,12 +260,28 @@ | ||
| 217 | 260 | } |
| 218 | 261 | } |
| 219 | 262 | } |
| 220 | 263 | $is_package = !empty($order['pkg']) ? true : false; |
| 221 | - $orderrooms = []; | |
| 222 | - $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;"; | |
| 223 | - $dbo->setQuery($q); | |
| 264 | + | |
| 265 | + // get the rooms booked list | |
| 266 | + $dbo->setQuery( | |
| 267 | + $dbo->getQuery(true) | |
| 268 | + ->select($dbo->qn('or') . '.*') | |
| 269 | + ->select($dbo->qn('r.id', 'r_reference_id')) | |
| 270 | + ->select([ | |
| 271 | + $dbo->qn('r.name'), | |
| 272 | + $dbo->qn('r.img'), | |
| 273 | + $dbo->qn('r.idcarat'), | |
| 274 | + $dbo->qn('r.fromadult'), | |
| 275 | + $dbo->qn('r.toadult'), | |
| 276 | + ]) | |
| 277 | + ->from($dbo->qn('#__vikbooking_ordersrooms', 'or')) | |
| 278 | + ->leftJoin($dbo->qn('#__vikbooking_rooms', 'r') . ' ON ' . $dbo->qn('or.idroom') . ' = ' . $dbo->qn('r.id')) | |
| 279 | + ->where($dbo->qn('or.idorder') . ' = ' . (int)$order['id']) | |
| 280 | + ->order($dbo->qn('or.id') . ' ASC') | |
| 281 | + ); | |
| 224 | 282 | $orderrooms = $dbo->loadAssocList(); |
| 283 | + | |
| 225 | 284 | if ($orderrooms) { |
| 226 | 285 | $vbo_tn->translateContents($orderrooms, '#__vikbooking_rooms', array('id' => 'r_reference_id')); |
| 227 | 286 | foreach ($orderrooms as $kor => $or) { |
| 228 | 287 | $num = $kor + 1; |
| @@ -308,8 +367,30 @@ | ||
| 308 | 367 | $cnodep = $cookie->get('vboFA', '', 'string'); |
| 309 | 368 | $nodep = intval($pnodep) > 0 || intval($cnodep) > 0 ? 1 : 0; |
| 310 | 369 | |
| 311 | 370 | /** |
| 371 | + * Scan the booking and related rooms for damage deposit payment data. | |
| 372 | + * Obtain also the information about possible previous payments. | |
| 373 | + * | |
| 374 | + * @since 1.17.6 (J) - 1.7.6 (WP) | |
| 375 | + */ | |
| 376 | + $damage_deposit_payment = VBORoomHelper::getInstance()->getDamageDepositSplitPayment($order, $orderrooms); | |
| 377 | + $prev_dd_payments = []; | |
| 378 | + if ($damage_deposit_payment['damagedep_gross'] ?? 0) { | |
| 379 | + $prev_dd_payments = VikBooking::getBookingHistoryInstance($order['id']) | |
| 380 | + ->getEventsWithData('PN', function($data) { | |
| 381 | + return (is_object($data) && !empty($data->damage_deposit)); | |
| 382 | + }); | |
| 383 | + if (!$prev_dd_payments) { | |
| 384 | + // check also the first payment event in case of OTA bookings | |
| 385 | + $prev_dd_payments = VikBooking::getBookingHistoryInstance($order['id']) | |
| 386 | + ->getEventsWithData('P0', function($data) { | |
| 387 | + return (is_object($data) && !empty($data->damage_deposit)); | |
| 388 | + }); | |
| 389 | + } | |
| 390 | + } | |
| 391 | + | |
| 392 | + /** | |
| 312 | 393 | * Upselling extra services only for non-cancelled bookings |
| 313 | 394 | * with a check-out date in the future. |
| 314 | 395 | * |
| 315 | 396 | * @since 1.13.0 (J) - 1.3.0 (WP) |
| @@ -337,17 +418,9 @@ | ||
| 337 | 418 | } |
| 338 | 419 | } |
| 339 | 420 | array_push($upsell_data, $room_data); |
| 340 | 421 | } |
| 341 | - $upselling = VikBooking::loadUpsellingData( | |
| 342 | - $upsell_data, | |
| 343 | - array( | |
| 344 | - 'id' => $order['id'], | |
| 345 | - 'checkin' => $order['checkin'], | |
| 346 | - 'checkout' => $order['checkout'], | |
| 347 | - ), | |
| 348 | - $vbo_tn | |
| 349 | - ); | |
| 422 | + $upselling = VikBooking::loadUpsellingData($upsell_data, $order, $vbo_tn); | |
| 350 | 423 | } |
| 351 | 424 | |
| 352 | 425 | /** |
| 353 | 426 | * Trigger first tracking conversion on booking. |
| @@ -365,8 +438,11 @@ | ||
| 365 | 438 | $this->canc_policy = $canc_policy; |
| 366 | 439 | $this->payment = $payment; |
| 367 | 440 | $this->nodep = $nodep; |
| 368 | 441 | $this->upselling = $upselling; |
| 442 | + $this->damage_deposit_payment = $damage_deposit_payment; | |
| 443 | + $this->prev_dd_payments = $prev_dd_payments; | |
| 444 | + $this->quoteValidUntilDt = $quoteValidUntilDt ?? null; | |
| 369 | 445 | $this->vbo_tn = $vbo_tn; |
| 370 | 446 | |
| 371 | 447 | // theme |
| 372 | 448 | $theme = VikBooking::getTheme(); |