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

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