PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.8.16
VikBooking Hotel Booking Engine & PMS v1.8.16
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
← All changes | admin/views/ratesoverv/view.html.php +95 -17 1.6.7 → 1.8.16 View file →
@@ -19,8 +19,12 @@
19 19 {
20 20 // Set the toolbar
21 21 $this->addToolBar();
22 22
23 + if (!JFactory::getUser()->authorise('core.vbo.pricing', 'com_vikbooking')) {
24 + VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 + }
26 +
23 27 /**
24 28 * Check the next festivities periodically
25 29 *
26 30 * @since 1.12.0 (J) - 1.2.0 (WP)
@@ -31,11 +35,14 @@
31 35 }
32 36 $festivities = $fests->loadFestDates();
33 37
34 38 $dbo = JFactory::getDbo();
35 - $mainframe = JFactory::getApplication();
39 + $app = JFactory::getApplication();
36 40 $session = JFactory::getSession();
37 41
42 + // define the maximum number of days
43 + $MAX_DAYS = VBOFactory::getConfig()->getInt('roverv_max_days', 60);
44 +
38 45 $cid = VikRequest::getVar('cid', array(0));
39 46 $sesscids = $session->get('vbRatesOviewCids', array());
40 47 if (empty($cid[0]) && is_array($sesscids) && count($sesscids)) {
41 48 // load rooms from session only if no room IDs requested
@@ -55,15 +62,15 @@
55 62 $roomid = $dbo->loadResult();
56 63 }
57 64 }
58 65 if (empty($roomid)) {
59 - $mainframe->redirect("index.php?option=com_vikbooking&task=rooms");
66 + $app->redirect("index.php?option=com_vikbooking&task=rooms");
60 67 exit;
61 68 }
62 69 // make sure to set at least the first index of cid[]
63 70 $cid[0] = $roomid;
64 71 //
65 - $q = "SELECT `id`,`name` FROM `#__vikbooking_rooms` ORDER BY `#__vikbooking_rooms`.`name` ASC;";
72 + $q = "SELECT `id`,`name`,`img` FROM `#__vikbooking_rooms` ORDER BY `#__vikbooking_rooms`.`name` ASC;";
66 73 $dbo->setQuery($q);
67 74 $all_rooms = $dbo->loadAssocList();
68 75
69 76 /**
@@ -91,16 +98,16 @@
91 98 // room
92 99 array_push($reqids, $rid);
93 100 }
94 101 }
95 - if (!count($reqcats) && !count($reqids)) {
96 - $mainframe->redirect("index.php?option=com_vikbooking&task=rooms");
102 + if (!$reqcats && !$reqids) {
103 + $app->redirect("index.php?option=com_vikbooking&task=rooms");
97 104 exit;
98 105 }
99 106
100 - if (!count($reqcats) && empty($sesscids) && count($reqids) === 1 && count($all_rooms) > 1) {
107 + if (!$reqcats && empty($sesscids) && count($reqids) === 1 && count($all_rooms) > 1) {
101 108 // push the first 5 rooms by default
102 - $max_def_rooms = 5;
109 + $max_def_rooms = VBOFactory::getConfig()->getInt('roverv_def_max_rooms', 5);
103 110 $def_rooms_count = 0;
104 111 $reqids = [];
105 112 foreach ($all_rooms as $aroom) {
106 113 $reqids[] = $aroom['id'];
@@ -126,9 +133,9 @@
126 133 $roomrows[$row['id']] = $row;
127 134 }
128 135 }
129 136 if (!$roomrows) {
130 - $mainframe->redirect("index.php?option=com_vikbooking&task=rooms");
137 + $app->redirect("index.php?option=com_vikbooking&task=rooms");
131 138 exit;
132 139 }
133 140 if (!$reqids) {
134 141 // in case of just a category filter we need to restore the requested room IDs for later actions
@@ -275,10 +282,11 @@
275 282 if (!empty($prevts)) {
276 283 $tsstart = $prevts;
277 284 }
278 285 }
286 +
287 + // read the rates for the lowest number of nights for each room requested
279 288 $roomrates = [];
280 - // read the rates for the lowest number of nights for each room requested
281 289 foreach ($req_room_ids as $rid) {
282 290 /**
283 291 * Some types of price may not have a cost for 1 or 2 nights,
284 292 * so joining by MIN(`days`) may exclude certain types of price.
@@ -288,11 +296,16 @@
288 296 * $q = "SELECT `r`.`id`,`r`.`idroom`,`r`.`days`,`r`.`idprice`,`r`.`cost`,`p`.`name` FROM `#__vikbooking_dispcost` AS `r` INNER JOIN (SELECT MIN(`days`) AS `min_days` FROM `#__vikbooking_dispcost` WHERE `idroom`=".(int)$rid." GROUP BY `idroom`) AS `r2` ON `r`.`days`=`r2`.`min_days` LEFT JOIN `#__vikbooking_prices` `p` ON `p`.`id`=`r`.`idprice` WHERE `r`.`idroom`=".(int)$rid." GROUP BY `r`.`id`,`r`.`idroom`,`r`.`days`,`r`.`idprice`,`r`.`cost`,`p`.`name` ORDER BY `r`.`days` ASC, `r`.`cost` ASC;";
289 297 *
290 298 * @since 1.10 (J) - 1.0.14 (WP)
291 299 */
292 - $q = "SELECT `r`.`id`,`r`.`idroom`,`r`.`days`,`r`.`idprice`,`r`.`cost`,`p`.`name`,`p`.`minlos` FROM `#__vikbooking_dispcost` AS `r` LEFT JOIN `#__vikbooking_prices` `p` ON `p`.`id`=`r`.`idprice` WHERE `r`.`idroom`=".(int)$rid." ORDER BY `r`.`days` ASC, `r`.`cost` ASC LIMIT 50;";
293 - $dbo->setQuery($q);
300 + $q = "SELECT `r`.`id`,`r`.`idroom`,`r`.`days`,`r`.`idprice`,`r`.`cost`,`p`.`name`,`p`.`minlos`,`p`.`derived_id`
301 + FROM `#__vikbooking_dispcost` AS `r`
302 + LEFT JOIN `#__vikbooking_prices` `p` ON `p`.`id`=`r`.`idprice`
303 + WHERE `r`.`idroom`=".(int)$rid."
304 + ORDER BY `r`.`days` ASC, `r`.`cost` ASC";
305 + $dbo->setQuery($q, 0, 50);
294 306 $nowroomrates = $dbo->loadAssocList();
307 +
295 308 if ($nowroomrates) {
296 309 $parsed_room_prices = [];
297 310 foreach ($nowroomrates as $rrk => $rrv) {
298 311 if (isset($parsed_room_prices[$rrv['idprice']])) {
@@ -303,9 +316,11 @@
303 316 $nowroomrates[$rrk]['days'] = 1;
304 317 $parsed_room_prices[$rrv['idprice']] = 1;
305 318 }
306 319 }
320 +
307 321 $nowroomrates = array_values($nowroomrates);
322 +
308 323 // push rates for this room
309 324 $roomrates[(int)$rid] = $nowroomrates;
310 325 }
311 326
@@ -315,25 +330,60 @@
315 330 }
316 331
317 332 // read all the bookings between these dates for all rooms
318 333 $booked_dates = [];
319 - $MAX_DAYS = 60;
320 334 $info_start = getdate($tsstart);
321 335 $endts = mktime(23, 59, 59, $info_start['mon'], ($info_start['mday'] + $MAX_DAYS), $info_start['year']);
322 - $q = "SELECT `b`.*,`ob`.`idorder` FROM `#__vikbooking_busy` AS `b`,`#__vikbooking_ordersbusy` AS `ob` WHERE `b`.`idroom` IN (".implode(', ', $reqids).") AND `b`.`id`=`ob`.`idbusy` AND (`b`.`checkin`>=".$tsstart." OR `b`.`checkout`>=".$tsstart.") AND (`b`.`checkin`<=".$endts." OR `b`.`checkout`<=".$tsstart.");";
336 +
337 + $q = "SELECT `b`.*,`ob`.`idorder`,`o`.`custdata`,`o`.`status`,`o`.`days`,`o`.`roomsnum`,`o`.`idorderota`,`o`.`channel`,`o`.`colortag`,`o`.`closure`,`o`.`total`,`o`.`totpaid`,`o`.`paymentlog`
338 + FROM `#__vikbooking_busy` AS `b`
339 + LEFT JOIN `#__vikbooking_ordersbusy` AS `ob` ON `b`.`id`=`ob`.`idbusy`
340 + LEFT JOIN `#__vikbooking_orders` AS `o` ON `ob`.`idorder`=`o`.`id`
341 + WHERE `b`.`idroom` IN (" . implode(', ', $reqids) . ") AND (`b`.`checkin`>=" . $tsstart . " OR `b`.`checkout`>=" . $tsstart . ") AND (`b`.`checkin`<=" . $endts . " OR `b`.`checkout`<=" . $tsstart . ");";
323 342 $dbo->setQuery($q);
324 343 $rbusy = $dbo->loadAssocList();
344 +
325 345 $ridbusy = [];
326 346 foreach ($rbusy as $rb) {
327 347 if (!isset($ridbusy[$rb['idroom']])) {
328 348 $ridbusy[$rb['idroom']] = [];
329 349 }
330 - array_push($ridbusy[$rb['idroom']], $rb);
350 + $ridbusy[$rb['idroom']][] = $rb;
331 351 }
352 +
353 + // collect additional information for each booking
354 + $extra_info_map = [];
355 + foreach ($ridbusy as $rid => $roomres) {
356 + foreach ($roomres as $k => $res) {
357 + if (empty($res['idorder'])) {
358 + continue;
359 + }
360 + if (isset($extra_info_map[$res['idorder']])) {
361 + // merge existing extra information
362 + $ridbusy[$rid][$k] = array_merge($res, $extra_info_map[$res['idorder']]);
363 + continue;
364 + }
365 + // get booking extra information
366 + $q = "SELECT `oc`.`idcustomer`,`c`.`first_name`,`c`.`last_name`,`c`.`pic`
367 + FROM `#__vikbooking_customers_orders` AS `oc`
368 + LEFT JOIN `#__vikbooking_customers` AS `c` ON `oc`.`idcustomer`=`c`.`id`
369 + WHERE `oc`.`idorder`={$res['idorder']}";
370 + $dbo->setQuery($q, 0, 1);
371 + $extra_info = $dbo->loadAssoc();
372 + $extra_info = $extra_info ?: [];
373 + // merge and map booking extra information
374 + $ridbusy[$rid][$k] = array_merge($res, $extra_info);
375 + $extra_info_map[$res['idorder']] = $extra_info;
376 + }
377 + }
378 +
332 379 foreach ($req_room_ids as $rid) {
333 - $booked_dates[(int)$rid] = isset($ridbusy[(int)$rid]) ? $ridbusy[(int)$rid] : [];
380 + $booked_dates[$rid] = $ridbusy[$rid] ?? [];
334 381 }
335 382
383 + // free memory up
384 + unset($ridbusy, $rbusy);
385 +
336 386 /**
337 387 * Load room day notes for the requested dates
338 388 *
339 389 * @since 1.13.5
@@ -338,10 +388,36 @@
338 388 *
339 389 * @since 1.13.5
340 390 */
341 391 $rdaynotes = VikBooking::getCriticalDatesInstance()->loadRoomDayNotes(date('Y-m-d', $tsstart), date('Y-m-d', $endts));
342 - //
343 -
392 +
393 + /**
394 + * Build room-ota relations for pricing alterations, if any.
395 + *
396 + * @since 1.17.2 (J) - 1.7.2 (WP)
397 + */
398 + $room_ota_relations = [];
399 + foreach ($req_room_ids as $rid) {
400 + // always get a new instance of the VikChannelManagerLogos class
401 + $vcm_logos = VikBooking::getVcmChannelsLogo('', true);
402 + // load channels (firsr) and accounts (after) for this listing
403 + $room_ota_channels = is_object($vcm_logos) && method_exists($vcm_logos, 'getVboRoomLogosMapped') ? $vcm_logos->getVboRoomLogosMapped($rid) : [];
404 + $room_ota_accounts = is_object($vcm_logos) && method_exists($vcm_logos, 'getRoomOtaAccounts') ? $vcm_logos->getRoomOtaAccounts() : [];
405 + // filter channels not available as accounts (i.e. iCal)
406 + if (count($room_ota_channels) != count(($room_ota_accounts[$rid] ?? []))) {
407 + $ota_account_names = array_map('strtolower', array_column(($room_ota_accounts[$rid] ?? []), 'channel'));
408 + $room_ota_channels = array_filter($room_ota_channels, function($chid) use ($ota_account_names) {
409 + return in_array(strtolower($chid), $ota_account_names);
410 + }, ARRAY_FILTER_USE_KEY);
411 + }
412 + if ($room_ota_channels && ($room_ota_accounts[$rid] ?? [])) {
413 + $room_ota_relations[$rid] = [
414 + 'channels' => $room_ota_channels,
415 + 'accounts' => $room_ota_accounts[$rid],
416 + ];
417 + }
418 + }
419 +
344 420 $this->all_rooms = $all_rooms;
345 421 $this->categories = $categories;
346 422 $this->reqcats = $reqcats;
347 423 $this->all_restrictions = $all_restrictions;
@@ -354,8 +430,10 @@
354 430 $this->req_room_ids = $req_room_ids;
355 431 $this->firstroom = $roomid;
356 432 $this->festivities = $festivities;
357 433 $this->rdaynotes = $rdaynotes;
434 + $this->room_ota_relations = $room_ota_relations;
435 + $this->max_days = $MAX_DAYS;
358 436
359 437 // Display the template
360 438 parent::display($tpl);
361 439 }