PluginProbe
VikBooking Hotel Booking Engine & PMS / 1.7.1
VikBooking Hotel Booking Engine & PMS v1.7.1
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 / admin / views / editorder / view.html.php

view.html.php in VikBooking Hotel Booking Engine & PMS 1.7.1, at admin/views/editorder/view.html.php

515 lines 21.5 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 // import Joomla view library
14 jimport('joomla.application.component.view');
15
16 class VikBookingViewEditorder extends JViewVikBooking
17 {
18 public function display($tpl = null)
19 {
20 // Set the toolbar
21 $this->addToolBar();
22
23 if (!JFactory::getUser()->authorise('core.vbo.bookings', 'com_vikbooking')) {
24 VBOHttpDocument::getInstance()->close(403, JText::translate('JERROR_ALERTNOAUTHOR'));
25 }
26
27 $cid = VikRequest::getVar('cid', array(0));
28 $ido = $cid[0];
29
30 if (is_file(VCM_ADMIN_PATH.DIRECTORY_SEPARATOR.'assets'.DIRECTORY_SEPARATOR.'css'.DIRECTORY_SEPARATOR.'vcm-channels.css')) {
31 $document = JFactory::getDocument();
32 $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vikchannelmanager.css');
33 $document->addStyleSheet(VCM_ADMIN_URI.'assets/css/vcm-channels.css');
34 if (method_exists('VikChannelManager', 'loadAppearancePreferenceAssets')) {
35 VikChannelManager::loadAppearancePreferenceAssets();
36 }
37 }
38
39 $dbo = JFactory::getDbo();
40 $app = JFactory::getApplication();
41 $user = JFactory::getUser();
42
43 $q = "SELECT * FROM `#__vikbooking_orders` WHERE `id`=" . $dbo->quote($ido);
44 $dbo->setQuery($q, 0, 1);
45 $row = $dbo->loadAssoc();
46 if (!$row) {
47 $app->redirect("index.php?option=com_vikbooking&task=orders");
48 $app->close();
49 return;
50 }
51
52 /**
53 * Check currency conversion request, if needed and supported.
54 *
55 * @since 1.15.0 (J) - 1.5.0 (WP)
56 */
57 $do_ota_curr_conv = VikRequest::getInt('do_ota_curr_conv', 0, 'request');
58 if ($do_ota_curr_conv) {
59 $ota_helper = new VBOCurrencyOta($row);
60 if (!$ota_helper->convertReservationCurrency()) {
61 VikError::raiseWarning('', 'Something went wrong while trying to convert the OTA currency');
62 }
63 $app->redirect('index.php?option=com_vikbooking&task=editorder&cid[]=' . $row['id']);
64 $app->close();
65 }
66
67 $q = "SELECT `id`,`name` FROM `#__vikbooking_gpayments` ORDER BY `#__vikbooking_gpayments`.`name` ASC;";
68 $dbo->setQuery($q);
69 $payments = $dbo->loadAssocList();
70
71 $cpin = VikBooking::getCPinIstance();
72 // VBO 1.11 - change customer assigned to this booking
73 $pnewcustid = VikRequest::getInt('newcustid', 0, 'request');
74 if (!empty($pnewcustid)) {
75 $cpin->updateCustomerBooking($row['id'], $pnewcustid);
76 // update empty values for the booking
77 if (empty($row['custmail']) || empty($row['phone'])) {
78 // get customer information
79 $customer = $cpin->getCustomerByID($pnewcustid);
80 if ($customer && (!empty($customer['email']) || !empty($customer['phone']))) {
81 if (empty($row['custmail']) && !empty($customer['email'])) {
82 $q = "UPDATE `#__vikbooking_orders` SET `custmail`=" . $dbo->quote($customer['email']) . " WHERE `id`=" . $row['id'] . ";";
83 $dbo->setQuery($q);
84 $dbo->execute();
85 $row['custmail'] = $customer['email'];
86 }
87 if (empty($row['phone']) && !empty($customer['phone'])) {
88 $q = "UPDATE `#__vikbooking_orders` SET `phone`=" . $dbo->quote($customer['phone']) . " WHERE `id`=" . $row['id'] . ";";
89 $dbo->setQuery($q);
90 $dbo->execute();
91 $row['phone'] = $customer['phone'];
92 }
93 }
94 }
95 }
96
97 $customer = $cpin->getCustomerFromBooking($row['id']);
98 if ($customer && !empty($customer['country'])) {
99 if (file_exists(VBO_ADMIN_PATH.DIRECTORY_SEPARATOR.'resources'.DIRECTORY_SEPARATOR.'countries'.DIRECTORY_SEPARATOR.$customer['country'].'.png')) {
100 $customer['country_img'] = '<img src="'.VBO_ADMIN_URI.'resources/countries/'.$customer['country'].'.png'.'" title="'.$customer['country'].'" class="vbo-country-flag vbo-country-flag-left"/>';
101 }
102 }
103
104 $padminnotes = VikRequest::getString('adminnotes', '', 'request');
105 $pupdadmnotes = VikRequest::getString('updadmnotes', '', 'request');
106 $pinvnotes = VikRequest::getString('invnotes', '', 'request', VIKREQUEST_ALLOWHTML);
107 $pupdinvnotes = VikRequest::getString('updinvnotes', '', 'request');
108 $pnewpayment = VikRequest::getString('newpayment', '', 'request');
109 $pnewlang = VikRequest::getString('newlang', '', 'request');
110 $padmindisc = VikRequest::getString('admindisc', '', 'request');
111 $ptot_taxes = VikRequest::getString('tot_taxes', '', 'request');
112 $ptot_city_taxes = VikRequest::getString('tot_city_taxes', '', 'request');
113 $ptot_fees = VikRequest::getString('tot_fees', '', 'request');
114 $pcmms = VikRequest::getString('cmms', '', 'request');
115 $pcustmail = VikRequest::getString('custmail', '', 'request');
116 $pcustphone = VikRequest::getString('custphone', '', 'request');
117 $pmakepay = VikRequest::getInt('makepay', 0, 'request');
118 $pnewamountpaid = VikRequest::getFloat('newamountpaid', -1, 'request');
119 $pnewamountpaymeth = VikRequest::getString('newamountpaymeth', '', 'request');
120 // we update the total paid also if the input is 0.0 (float) as the default value is -1 (int)
121 if (($pnewamountpaid > 0 || ($pnewamountpaid == 0 && is_float($pnewamountpaid))) && (float)$row['totpaid'] != $pnewamountpaid) {
122 $prevpaid = (float)$row['totpaid'];
123 $q = "UPDATE `#__vikbooking_orders` SET `totpaid`=".$dbo->quote($pnewamountpaid)." WHERE `id`=".$row['id'].";";
124 $dbo->setQuery($q);
125 $dbo->execute();
126 $row['totpaid'] = $pnewamountpaid;
127 // Booking History log for new amount paid (payment update)
128 $extra_data = null;
129 $newpaympaytype = '';
130 if ($pnewamountpaid > $prevpaid) {
131 $extra_data = new stdClass;
132 $extra_data->amount_paid = ($pnewamountpaid - $prevpaid);
133 if (!empty($pnewamountpaymeth)) {
134 $payparts = explode('_', $pnewamountpaymeth);
135 $newpaympaytype = count($payparts) > 1 ? $payparts[1] : $pnewamountpaymeth;
136 $extra_data->payment_method = $newpaympaytype;
137 }
138 }
139 VikBooking::getBookingHistoryInstance()->setBid($row['id'])->setExtraData($extra_data)->store('PU', JText::sprintf('VBOPREVAMOUNTPAID', VikBooking::numberFormat($prevpaid) . (!empty($newpaympaytype) ? ' ('.$newpaympaytype.')' : '')));
140 //
141 }
142 $pnewamountrefunded = VikRequest::getFloat('newamountrefunded', -1, 'request');
143 // we update the total refunded also if the input is 0.0 (float) as the default value is -1 (int)
144 if (($pnewamountrefunded > 0 || ($pnewamountrefunded == 0 && is_float($pnewamountrefunded))) && (float)$row['refund'] != $pnewamountrefunded) {
145 $prevrefunded = $row['refund'];
146 $refund_diff = $pnewamountrefunded - $row['refund'];
147 if ($refund_diff > 0) {
148 // refund amount increased, lower the booking total
149 $newtotal = $row['total'] - $refund_diff;
150 // lower also the amount paid
151 $newtotpaid = $row['totpaid'] > 0 ? ($row['totpaid'] - $refund_diff) : $row['totpaid'];
152 } else {
153 // refund amount decreased, increase the booking total
154 $newtotal = $row['total'] + abs($refund_diff);
155 // leave the totpaid unchanged in this case
156 $newtotpaid = $row['totpaid'];
157 }
158 $q = "UPDATE `#__vikbooking_orders` SET `total`=" . $dbo->quote($newtotal) . ", `totpaid`=" . ($newtotpaid == null ? 'NULL' : $dbo->quote($newtotpaid)) . ", `refund`=" . $dbo->quote($pnewamountrefunded) . " WHERE `id`=" . $row['id'] . ";";
159 $dbo->setQuery($q);
160 $dbo->execute();
161 $row['total'] = $newtotal;
162 $row['refund'] = $pnewamountrefunded;
163 // booking history log for new amount refunded
164 VikBooking::getBookingHistoryInstance($row['id'])
165 ->setExtraData([
166 'amount_paid' => ($pnewamountrefunded - $prevrefunded),
167 ])
168 ->store('RU', JText::sprintf('VBO_NEWREFUND_AMOUNT', VikBooking::numberFormat($prevrefunded), VikBooking::numberFormat($pnewamountrefunded)));
169 }
170 $pnewamountpayable = VikRequest::getFloat('newamountpayable', -1, 'request');
171 // we update the amount payable also if the input is 0.0 (float) as the default value is -1 (int)
172 if (($pnewamountpayable > 0 || ($pnewamountpayable == 0 && is_float($pnewamountpayable))) && (float)$row['payable'] != $pnewamountpayable) {
173 $q = "UPDATE `#__vikbooking_orders` SET `payable`=" . $dbo->quote($pnewamountpayable) . " WHERE `id`=" . $row['id'] . ";";
174 $dbo->setQuery($q);
175 $dbo->execute();
176 $row['payable'] = $pnewamountpayable;
177 // booking history log for new amount payable
178 VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('PB', JText::sprintf('VBO_NEWPAYABLE_AMOUNT', VikBooking::numberFormat($pnewamountpayable)));
179 // make sure to update the payment counter, or if no payments ever made, the system won't accept a transaction
180 if (!$row['paymcount']) {
181 // turn flag on
182 $pmakepay = 1;
183 }
184 }
185 if ($pmakepay > 0) {
186 // check if the payment counter should be updated
187 $q = "UPDATE `#__vikbooking_orders` SET `paymcount`=" . $pmakepay . " WHERE `id`=" . $row['id'] . ";";
188 $dbo->setQuery($q);
189 $dbo->execute();
190 $row['paymcount'] = 1;
191 }
192 $pnewcancfee = VikRequest::getFloat('newcancfee', -1, 'request');
193 // we update the cancellation fee amount also if the input is 0.0 (float) as the default value is -1 (int)
194 if (($pnewcancfee > 0 || ($pnewcancfee == 0 && is_float($pnewcancfee))) && (float)$row['canc_fee'] != $pnewcancfee) {
195 $q = "UPDATE `#__vikbooking_orders` SET `canc_fee`=" . $dbo->quote($pnewcancfee) . " WHERE `id`=" . $row['id'] . ";";
196 $dbo->setQuery($q);
197 $dbo->execute();
198 $row['canc_fee'] = $pnewcancfee;
199 // booking history log for new cancellation fee amount
200 VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('MB', sprintf(JText::translate('VBO_CANC_FEE') . ': %s', VikBooking::numberFormat($pnewcancfee)));
201 }
202 if (!empty($padminnotes) || !empty($pupdadmnotes)) {
203 $q = "UPDATE `#__vikbooking_orders` SET `adminnotes`=".$dbo->quote($padminnotes)." WHERE `id`=".$row['id'].";";
204 $dbo->setQuery($q);
205 $dbo->execute();
206 $row['adminnotes'] = $padminnotes;
207 }
208 if (!empty($pinvnotes) || !empty($pupdinvnotes)) {
209 $pinvnotes = strpos($pinvnotes, '<br') !== false ? $pinvnotes : nl2br($pinvnotes);
210 $q = "UPDATE `#__vikbooking_orders` SET `inv_notes`=".$dbo->quote($pinvnotes)." WHERE `id`=".$row['id'].";";
211 $dbo->setQuery($q);
212 $dbo->execute();
213 $row['inv_notes'] = $pinvnotes;
214 }
215 if (!empty($pnewpayment) && $payments) {
216 foreach ($payments as $npay) {
217 if ((int)$npay['id'] == (int)$pnewpayment) {
218 $newpayvalid = $npay['id'].'='.$npay['name'];
219 $q = "UPDATE `#__vikbooking_orders` SET `idpayment`=".$dbo->quote($newpayvalid)." WHERE `id`=".$row['id'].";";
220 $dbo->setQuery($q);
221 $dbo->execute();
222 $row['idpayment'] = $newpayvalid;
223 break;
224 }
225 }
226 }
227 if (!empty($pnewlang)) {
228 $q = "UPDATE `#__vikbooking_orders` SET `lang`=".$dbo->quote($pnewlang)." WHERE `id`=".$row['id'].";";
229 $dbo->setQuery($q);
230 $dbo->execute();
231 $row['lang'] = $pnewlang;
232 }
233 if (strlen($padmindisc) > 0) {
234 if (floatval($padmindisc) > 0.00) {
235 $admincoupon = '-1;'.floatval($padmindisc).';'.JText::translate('VBADMINDISCOUNT');
236 } else {
237 $admincoupon = '';
238 }
239 $expcoupon = explode(";", $row['coupon']);
240 // make sure the new discount is different than the previous one, and that the total amount is greater than zero
241 if ($row['total'] > 0 && (empty($row['coupon']) || (float)$expcoupon[1] != (float)$padmindisc)) {
242 // re-calculate new total by adding the previous discount and by subtracting the new one
243 $newtotal = $row['total'] + (!empty($row['coupon']) ? (float)$expcoupon[1] : 0);
244 $newtotal -= (float)$padmindisc;
245 //
246 $q = "UPDATE `#__vikbooking_orders` SET `coupon`=" . $dbo->quote($admincoupon) . ", `total`=" . $dbo->quote($newtotal) . " WHERE `id`={$row['id']};";
247 $dbo->setQuery($q);
248 $dbo->execute();
249 $row['coupon'] = $admincoupon;
250 $row['total'] = $newtotal;
251 }
252 }
253 if (strlen($ptot_taxes) > 0) {
254 $q = "UPDATE `#__vikbooking_orders` SET `tot_taxes`='".floatval($ptot_taxes)."' WHERE `id`=".$row['id'].";";
255 $dbo->setQuery($q);
256 $dbo->execute();
257 $row['tot_taxes'] = $ptot_taxes;
258 }
259 if (strlen($ptot_city_taxes) > 0) {
260 $q = "UPDATE `#__vikbooking_orders` SET `tot_city_taxes`='".floatval($ptot_city_taxes)."' WHERE `id`=".$row['id'].";";
261 $dbo->setQuery($q);
262 $dbo->execute();
263 $row['tot_city_taxes'] = $ptot_city_taxes;
264 }
265 if (strlen($ptot_fees) > 0) {
266 $q = "UPDATE `#__vikbooking_orders` SET `tot_fees`='".floatval($ptot_fees)."' WHERE `id`=".$row['id'].";";
267 $dbo->setQuery($q);
268 $dbo->execute();
269 $row['tot_fees'] = $ptot_fees;
270 }
271 if (strlen($pcmms) > 0) {
272 $q = "UPDATE `#__vikbooking_orders` SET `cmms`='".floatval($pcmms)."' WHERE `id`=".$row['id'].";";
273 $dbo->setQuery($q);
274 $dbo->execute();
275 $row['cmms'] = $pcmms;
276 }
277 if (strlen($pcustmail) > 0) {
278 $q = "UPDATE `#__vikbooking_orders` SET `custmail`=".$dbo->quote($pcustmail)." WHERE `id`=".$row['id'].";";
279 $dbo->setQuery($q);
280 $dbo->execute();
281 $row['custmail'] = $pcustmail;
282 }
283 if (strlen($pcustphone) > 0) {
284 $q = "UPDATE `#__vikbooking_orders` SET `phone`=".$dbo->quote($pcustphone)." WHERE `id`=".$row['id'].";";
285 $dbo->setQuery($q);
286 $dbo->execute();
287 $row['phone'] = $pcustphone;
288 }
289
290 /**
291 * Vik Channel Manager booking assignable channels.
292 *
293 * @since 1.16.3 (J) - 1.6.3 (WP)
294 */
295 $vcm_assign_channel = VikRequest::getString('vcm_assign_channel', '', 'request');
296 if (!empty($vcm_assign_channel) && class_exists('VCMOtaBooking')) {
297 // current unix timestamp will be used in place of OTA Reservation ID
298 $set_ota_bid = time();
299
300 // update fields on db
301 $q = "UPDATE `#__vikbooking_orders` SET `idorderota`=" . $dbo->quote($set_ota_bid) . ", `channel`=" . $dbo->quote($vcm_assign_channel) . " WHERE `id`=" . $row['id'] . ";";
302 $dbo->setQuery($q);
303 $dbo->execute();
304
305 // overwrite booking properties
306 $row['idorderota'] = $set_ota_bid;
307 $row['channel'] = $vcm_assign_channel;
308
309 // update booking history
310 $user = JFactory::getUser();
311 VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('CM', "({$user->name}) " . JText::sprintf('VBO_BOOKING_OTA_ASSIGNED', $vcm_assign_channel));
312 }
313
314 // load data
315 $q = "SELECT `or`.*,`r`.`name`,`r`.`fromadult`,`r`.`toadult`,`r`.`params` FROM `#__vikbooking_ordersrooms` AS `or`,`#__vikbooking_rooms` AS `r` WHERE `or`.`idorder`=".(int)$row['id']." AND `or`.`idroom`=`r`.`id` ORDER BY `or`.`id` ASC;";
316 $dbo->setQuery($q);
317 $rooms = $dbo->loadAssocList();
318 $q = "SELECT * FROM `#__vikbooking_ordersbusy` WHERE `idorder`=".(int)$row['id'].";";
319 $dbo->setQuery($q);
320 $busy = $dbo->loadAssocList();
321
322 // Rooms Specific Unit
323 $proomindex = VikRequest::getVar('roomindex', array());
324 if (!empty($proomindex) && is_array($proomindex) && count($proomindex)) {
325 $orig_rooms = $rooms;
326 foreach ($proomindex as $or_id => $rind) {
327 if (empty($or_id)) {
328 continue;
329 }
330 $q = "UPDATE `#__vikbooking_ordersrooms` SET `roomindex`=".(!empty($rind) ? (int)$rind : "NULL")." WHERE `id`=".(int)$or_id." AND `idorder`=".(int)$row['id'].";";
331 $dbo->setQuery($q);
332 $dbo->execute();
333 // update global array reference
334 $sub_unit_changed = false;
335 foreach ($rooms as $korr => $orr) {
336 if ((int)$or_id == (int)$orr['id']) {
337 $sub_unit_changed = ((string)$orr['roomindex'] != (string)$rind);
338 $rooms[$korr]['roomindex'] = $rind;
339 break;
340 }
341 }
342 if (!$sub_unit_changed) {
343 // no need to store a booking history record
344 continue;
345 }
346 // try to store a booking history record when switching room sub-unit index
347 if (!empty($rind)) {
348 foreach ($orig_rooms as $korr => $orr) {
349 if ((int)$or_id != (int)$orr['id']) {
350 continue;
351 }
352 if (empty($orr['params'])) {
353 continue;
354 }
355 $room_params = json_decode($orr['params'], true);
356 if (is_array($room_params) && !empty($room_params['features'])) {
357 $prev_subindex = empty($orr['roomindex']) ? '---' : $orr['roomindex'];
358 $new_subindex = $rind;
359 foreach ($room_params['features'] as $origrind => $rfeatures) {
360 if ($orr['roomindex'] == $origrind) {
361 foreach ($rfeatures as $fname => $fval) {
362 if (strlen($fval)) {
363 $prev_subindex = '#' . $origrind . ' - ' . JText::translate($fname) . ': ' . $fval;
364 break;
365 }
366 }
367 }
368 if ($rind == $origrind) {
369 foreach ($rfeatures as $fname => $fval) {
370 if (strlen($fval)) {
371 $new_subindex = '#' . $origrind . ' - ' . JText::translate($fname) . ': ' . $fval;
372 break;
373 }
374 }
375 }
376 }
377 //Booking History
378 VikBooking::getBookingHistoryInstance()->setBid($row['id'])->store('MB', "({$user->name}) " . JText::sprintf('VBOROOMSUBUNITCHANGEFT', $orr['name'], $prev_subindex, $new_subindex));
379 //
380 }
381 }
382 }
383 }
384 }
385
386 // PCI DSS Checking
387 if (!empty($row['idorderota']) && !empty($row['channel']) && !empty($row['paymentlog'])) {
388 if (stripos($row['paymentlog'], 'card number') !== false && strpos($row['paymentlog'], '*') !== false) {
389 $checkout_info = getdate($row['checkout']);
390 /**
391 * Limit for accessing the credit card details has been changed to check-out
392 * day at 23:59:59 + 10 extra days. It used to be at 23:59:59 on check-out day.
393 *
394 * @since 1.13
395 */
396 $cardlimit = mktime(23, 59, 59, $checkout_info['mon'], ($checkout_info['mday'] + 10), $checkout_info['year']);
397 if (time() > $cardlimit) {
398 $newlogstr = JText::translate('VBOCCLOGDATAREMOVEDPCIDSS');
399 $q = "UPDATE `#__vikbooking_orders` SET `paymentlog`=".$dbo->quote($newlogstr)." WHERE `id`=".$row['id'].";";
400 $dbo->setQuery($q);
401 $dbo->execute();
402 $row['paymentlog'] = $newlogstr;
403 }
404 }
405 }
406
407 // unset credit card details, if needed, maybe to re-collect them
408 $unset_cc = VikRequest::getInt('unset_cc', 0, 'request');
409 if ($unset_cc && empty($row['idorderota']) && !empty($row['paymentlog'])) {
410 $q = "UPDATE `#__vikbooking_orders` SET `paymentlog` = NULL WHERE `id` = " . $row['id'] . ";";
411 $dbo->setQuery($q);
412 $dbo->execute();
413 $row['paymentlog'] = null;
414 }
415
416 // detect if VCM exists
417 $vcm_exists = class_exists('VikChannelManager');
418
419 // attempt to get the VCM review ID within a try-catch statement to avoid SQL errors
420 $vcm_review = null;
421 if ($vcm_exists) {
422 try {
423 $q = "SELECT * FROM `#__vikchannelmanager_otareviews` WHERE `idorder`=" . (int)$row['id'] . ";";
424 $dbo->setQuery($q);
425 $vcm_review = $dbo->loadAssoc();
426 } catch (Exception $e) {
427 // do nothing as VCM is probably not available/enabled/updated
428 $vcm_review = null;
429 }
430 }
431
432 /**
433 * Check if the reservation requires/supports additional actions.
434 *
435 * @since 1.14 (J) - 1.4.0 (WP)
436 */
437 $vcm_decline_actions = 0;
438 $vcm_pre_approval = 0;
439 $vcm_special_offer = 0;
440 $vcm_host_to_guest_review = 0;
441 $vcm_cancel_active_res = 0;
442 if ($vcm_exists) {
443 try {
444 if (method_exists('VikChannelManager', 'reservationNeedsDeclineReasons')) {
445 $vcm_decline_actions = (int)VikChannelManager::reservationNeedsDeclineReasons($row);
446 }
447 if (method_exists('VikChannelManager', 'reservationSupportsPreApproval')) {
448 $vcm_pre_approval = VikChannelManager::reservationSupportsPreApproval($row);
449 $vcm_pre_approval = $vcm_pre_approval === false ? 0 : $vcm_pre_approval;
450 }
451 if (method_exists('VikChannelManager', 'reservationSupportsSpecialOffer')) {
452 $vcm_special_offer = VikChannelManager::reservationSupportsSpecialOffer($row);
453 $vcm_special_offer = $vcm_special_offer === false ? 0 : $vcm_special_offer;
454 }
455 if (method_exists('VikChannelManager', 'hostToGuestReviewSupported')) {
456 $vcm_host_to_guest_review = VikChannelManager::hostToGuestReviewSupported($row);
457 $vcm_host_to_guest_review = $vcm_host_to_guest_review === false ? 0 : $vcm_host_to_guest_review;
458 }
459 if (method_exists('VikChannelManager', 'cancelActiveOtaReservation')) {
460 $vcm_cancel_active_res = (int)VikChannelManager::cancelActiveOtaReservation($row);
461 }
462 } catch (Exception $e) {
463 // do nothing as VCM is probably not available/enabled/updated
464 }
465 }
466
467 /**
468 * Build currency conversion details, if needed and supported.
469 *
470 * @since 1.15.0 (J) - 1.5.0 (WP)
471 */
472 $ota_helper = new VBOCurrencyOta($row);
473 $allows_conversion = $ota_helper->supportsConversion($row['total']);
474 $conv_from_currency = $allows_conversion !== false ? $ota_helper->getOTACurrency() : null;
475 $conv_to_currency = $allows_conversion !== false ? $ota_helper->getCurrencyName() : null;
476
477 $this->row = $row;
478 $this->rooms = $rooms;
479 $this->busy = $busy;
480 $this->customer = $customer;
481 $this->payments = $payments;
482 $this->vcm_review = $vcm_review;
483 $this->vcm_decline_actions = $vcm_decline_actions;
484 $this->vcm_pre_approval = $vcm_pre_approval;
485 $this->vcm_special_offer = $vcm_special_offer;
486 $this->vcm_host_to_guest_review = $vcm_host_to_guest_review;
487 $this->vcm_cancel_active_res = $vcm_cancel_active_res;
488 $this->allows_conversion = $allows_conversion;
489 $this->conv_from_currency = $conv_from_currency;
490 $this->conv_to_currency = $conv_to_currency;
491
492 // Display the template
493 parent::display($tpl);
494 }
495
496 /**
497 * Sets the toolbar
498 */
499 protected function addToolBar() {
500 $printreceipt = VikRequest::getInt('print', 0, 'request');
501 if ($printreceipt) {
502 // do not print any header or buttons if we are printing the receipt
503 return;
504 }
505
506 JToolBarHelper::title(JText::translate('VBMAINORDERTITLEEDIT'), 'vikbooking');
507 JToolBarHelper::cancel( 'canceledorder', JText::translate('VBBACK'));
508 JToolBarHelper::spacer();
509 JToolBarHelper::custom( 'prev_booking', 'backward', 'backward', JText::translate('VBJQCALPREV'), false);
510 JToolBarHelper::spacer();
511 JToolBarHelper::custom( 'next_booking', 'forward', 'forward', JText::translate('VBJQCALNEXT'), false);
512 JToolBarHelper::spacer();
513 }
514 }
515