| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage com_vikbooking |
| 5 |
* @author Alessio Gaggii - e4j - Extensionsforjoomla.com |
| 6 |
* @copyright Copyright (C) 2023 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 |
/** |
| 14 |
* Takings Report child Class of VikBookingReport. |
| 15 |
* |
| 16 |
* @since 1.16.2 (J) - 1.6.2 (WP) |
| 17 |
*/ |
| 18 |
class VikBookingReportTakings extends VikBookingReport |
| 19 |
{ |
| 20 |
/** |
| 21 |
* Property 'defaultKeySort' is used by the View that renders the report. |
| 22 |
*/ |
| 23 |
public $defaultKeySort = 'dt'; |
| 24 |
|
| 25 |
/** |
| 26 |
* Property 'defaultKeyOrder' is used by the View that renders the report. |
| 27 |
*/ |
| 28 |
public $defaultKeyOrder = 'ASC'; |
| 29 |
|
| 30 |
/** |
| 31 |
* Property 'exportAllowed' is used by the View to display the export button. |
| 32 |
*/ |
| 33 |
public $exportAllowed = 1; |
| 34 |
|
| 35 |
/** |
| 36 |
* Debug mode is activated by passing the value 'e4j_debug' > 0 |
| 37 |
*/ |
| 38 |
private $debug; |
| 39 |
|
| 40 |
/** |
| 41 |
* Class constructor should define the name of the report and |
| 42 |
* other vars. Call the parent constructor to define the DB object. |
| 43 |
*/ |
| 44 |
public function __construct() |
| 45 |
{ |
| 46 |
$this->reportFile = basename(__FILE__, '.php'); |
| 47 |
$this->reportName = JText::translate('VBO_TAKINGS'); |
| 48 |
$this->reportFilters = []; |
| 49 |
|
| 50 |
$this->cols = []; |
| 51 |
$this->rows = []; |
| 52 |
$this->footerRow = []; |
| 53 |
|
| 54 |
$this->debug = (VikRequest::getInt('e4j_debug', 0, 'request') > 0); |
| 55 |
|
| 56 |
$this->registerExportCSVFileName(); |
| 57 |
|
| 58 |
parent::__construct(); |
| 59 |
} |
| 60 |
|
| 61 |
/** |
| 62 |
* Returns the name of this report. |
| 63 |
* |
| 64 |
* @return string |
| 65 |
*/ |
| 66 |
public function getName() |
| 67 |
{ |
| 68 |
return $this->reportName; |
| 69 |
} |
| 70 |
|
| 71 |
/** |
| 72 |
* Returns the name of this file without .php. |
| 73 |
* |
| 74 |
* @return string |
| 75 |
*/ |
| 76 |
public function getFileName() |
| 77 |
{ |
| 78 |
return $this->reportFile; |
| 79 |
} |
| 80 |
|
| 81 |
/** |
| 82 |
* Returns the filters of this report. |
| 83 |
* |
| 84 |
* @return array |
| 85 |
*/ |
| 86 |
public function getFilters() |
| 87 |
{ |
| 88 |
if ($this->reportFilters) { |
| 89 |
// do not run this method twice, as it could load JS and CSS files. |
| 90 |
return $this->reportFilters; |
| 91 |
} |
| 92 |
|
| 93 |
// get VBO Application Object |
| 94 |
$vbo_app = VikBooking::getVboApplication(); |
| 95 |
|
| 96 |
// load the jQuery UI Datepicker |
| 97 |
$this->loadDatePicker(); |
| 98 |
|
| 99 |
// From Date Filter |
| 100 |
$filter_opt = array( |
| 101 |
'label' => '<label for="fromdate">'.JText::translate('VBOREPORTREVENUEDAY').'</label>', |
| 102 |
'html' => '<input type="text" id="fromdate" name="fromdate" value="" class="vbo-report-datepicker vbo-report-datepicker-from" />', |
| 103 |
'type' => 'calendar', |
| 104 |
'name' => 'fromdate' |
| 105 |
); |
| 106 |
array_push($this->reportFilters, $filter_opt); |
| 107 |
|
| 108 |
// To Date Filter |
| 109 |
$filter_opt = array( |
| 110 |
'label' => '<label for="todate">'.JText::translate('VBOREPORTSDATETO').'</label>', |
| 111 |
'html' => '<input type="text" id="todate" name="todate" value="" class="vbo-report-datepicker vbo-report-datepicker-to" />', |
| 112 |
'type' => 'calendar', |
| 113 |
'name' => 'todate' |
| 114 |
); |
| 115 |
array_push($this->reportFilters, $filter_opt); |
| 116 |
|
| 117 |
// status filter |
| 118 |
$types = [ |
| 119 |
'any' => JText::translate('VBANYTHING'), |
| 120 |
'confirmed' => JText::translate('VBCONFIRMED'), |
| 121 |
]; |
| 122 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 123 |
$types_sel_html = $vbo_app->getNiceSelect($types, $ptype, 'type', JText::translate('VBANYTHING'), JText::translate('VBANYTHING'), '', '', 'type'); |
| 124 |
$filter_opt = array( |
| 125 |
'label' => '<label for="type">' . JText::translate('VBSTATUS') . '</label>', |
| 126 |
'html' => $types_sel_html, |
| 127 |
'type' => 'select', |
| 128 |
'name' => 'type' |
| 129 |
); |
| 130 |
array_push($this->reportFilters, $filter_opt); |
| 131 |
|
| 132 |
// get minimum check-in and maximum check-out for dates filters |
| 133 |
$df = $this->getDateFormat(); |
| 134 |
$mindate = 0; |
| 135 |
$maxdate = 0; |
| 136 |
$q = "SELECT MIN(`ts`) AS `mindate`, MAX(`checkout`) AS `maxdate` FROM `#__vikbooking_orders` WHERE `status`='confirmed' AND `closure`=0;"; |
| 137 |
$this->dbo->setQuery($q); |
| 138 |
$data = $this->dbo->loadAssoc(); |
| 139 |
if ($data && !empty($data['mindate']) && !empty($data['maxdate'])) { |
| 140 |
$mindate = $data['mindate']; |
| 141 |
$maxdate = $data['maxdate']; |
| 142 |
} |
| 143 |
|
| 144 |
// jQuery code for the datepicker calendars and select2 |
| 145 |
$pfromdate = VikRequest::getString('fromdate', date($df), 'request'); |
| 146 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 147 |
$js = 'jQuery(function() { |
| 148 |
jQuery(".vbo-report-datepicker:input").datepicker({ |
| 149 |
'.(!empty($mindate) ? 'minDate: "'.date($df, $mindate).'", ' : '').' |
| 150 |
'.(!empty($maxdate) ? 'maxDate: "'.date($df, $maxdate).'", ' : '').' |
| 151 |
dateFormat: "'.$this->getDateFormat('jui').'", |
| 152 |
onSelect: vboReportCheckDates |
| 153 |
}); |
| 154 |
'.(!empty($pfromdate) ? 'jQuery(".vbo-report-datepicker-from").datepicker("setDate", "'.$pfromdate.'");' : '').' |
| 155 |
'.(!empty($ptodate) ? 'jQuery(".vbo-report-datepicker-to").datepicker("setDate", "'.$ptodate.'");' : '').' |
| 156 |
}); |
| 157 |
function vboReportCheckDates(selectedDate, inst) { |
| 158 |
if (selectedDate === null || inst === null) { |
| 159 |
return; |
| 160 |
} |
| 161 |
var cur_from_date = jQuery(this).val(); |
| 162 |
if (jQuery(this).hasClass("vbo-report-datepicker-from") && cur_from_date.length) { |
| 163 |
var nowstart = jQuery(this).datepicker("getDate"); |
| 164 |
var nowstartdate = new Date(nowstart.getTime()); |
| 165 |
jQuery(".vbo-report-datepicker-to").datepicker("option", {minDate: nowstartdate}); |
| 166 |
} |
| 167 |
}'; |
| 168 |
$this->setScript($js); |
| 169 |
|
| 170 |
return $this->reportFilters; |
| 171 |
} |
| 172 |
|
| 173 |
/** |
| 174 |
* Loads the report data from the DB. |
| 175 |
* Returns true in case of success, false otherwise. |
| 176 |
* Sets the columns and rows for the report to be displayed. |
| 177 |
* |
| 178 |
* @return boolean |
| 179 |
*/ |
| 180 |
public function getReportData() |
| 181 |
{ |
| 182 |
if ($this->getError()) { |
| 183 |
// export functions may set errors rather than exiting the process, and the View may continue the execution to attempt to render the report. |
| 184 |
return false; |
| 185 |
} |
| 186 |
|
| 187 |
// input fields and other vars |
| 188 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 189 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 190 |
$ptype = VikRequest::getString('type', '', 'request'); |
| 191 |
$ptype = $ptype ? $ptype : 'any'; |
| 192 |
$pkrsort = VikRequest::getString('krsort', $this->defaultKeySort, 'request'); |
| 193 |
$pkrsort = empty($pkrsort) ? $this->defaultKeySort : $pkrsort; |
| 194 |
$pkrorder = VikRequest::getString('krorder', $this->defaultKeyOrder, 'request'); |
| 195 |
$pkrorder = empty($pkrorder) ? $this->defaultKeyOrder : $pkrorder; |
| 196 |
$pkrorder = $pkrorder == 'DESC' ? 'DESC' : 'ASC'; |
| 197 |
|
| 198 |
$df = $this->getDateFormat(); |
| 199 |
$datesep = VikBooking::getDateSeparator(); |
| 200 |
$currency_symb = VikBooking::getCurrencySymb(); |
| 201 |
if (empty($ptodate)) { |
| 202 |
$ptodate = $pfromdate; |
| 203 |
} |
| 204 |
// get date timestamps |
| 205 |
$from_ts = VikBooking::getDateTimestamp($pfromdate, 0, 0); |
| 206 |
$to_ts = VikBooking::getDateTimestamp($ptodate, 23, 59, 59); |
| 207 |
if (empty($pfromdate) || empty($from_ts)) { |
| 208 |
$this->setError(JText::translate('VBOREPORTSERRNODATES')); |
| 209 |
return false; |
| 210 |
} |
| 211 |
|
| 212 |
// history object |
| 213 |
$history_obj = VikBooking::getBookingHistoryInstance(); |
| 214 |
|
| 215 |
// list of history types to fetch |
| 216 |
$h_payment_group = $history_obj->getTypeGroups($group = 'GPM'); |
| 217 |
if (!$h_payment_group || !$h_payment_group['types']) { |
| 218 |
return false; |
| 219 |
} |
| 220 |
// merge default types with 'PU' for the manually set "new amount paid" and with 'RU' (refunded amount updated) |
| 221 |
$h_payment_types = array_unique(array_merge($h_payment_group['types'], ['PU', 'RU'])); |
| 222 |
|
| 223 |
// query to obtain the records |
| 224 |
$q = $this->dbo->getQuery(true); |
| 225 |
$q->select($this->dbo->qn([ |
| 226 |
'h.idorder', |
| 227 |
'h.dt', |
| 228 |
'h.type', |
| 229 |
'h.descr', |
| 230 |
'h.totpaid', |
| 231 |
'h.total', |
| 232 |
'h.data', |
| 233 |
])); |
| 234 |
$q->from($this->dbo->qn('#__vikbooking_orderhistory', 'h')); |
| 235 |
$q->where($this->dbo->qn('h.dt') . ' >= ' . $this->dbo->q(JDate::getInstance(date('Y-m-d H:i:s', $from_ts))->toSql())); |
| 236 |
$q->where($this->dbo->qn('h.dt') . ' <= ' . $this->dbo->q(JDate::getInstance(date('Y-m-d H:i:s', $to_ts))->toSql())); |
| 237 |
$q->where($this->dbo->qn('h.type') . ' IN (' . implode(', ', array_map([$this->dbo, 'q'], $h_payment_types)) . ')'); |
| 238 |
$q->where($this->dbo->qn('h.total') . ' > 0'); |
| 239 |
$q->order($this->dbo->qn('h.dt') . ' ASC'); |
| 240 |
|
| 241 |
$this->dbo->setQuery($q); |
| 242 |
$records = $this->dbo->loadAssocList(); |
| 243 |
if (!$records) { |
| 244 |
$this->setError(JText::translate('VBOREPORTSERRNORESERV')); |
| 245 |
return false; |
| 246 |
} |
| 247 |
|
| 248 |
// grab all booking IDs involved |
| 249 |
$all_bids = []; |
| 250 |
foreach ($records as $hrecord) { |
| 251 |
if (!in_array($hrecord['idorder'], $all_bids)) { |
| 252 |
$all_bids[] = (int)$hrecord['idorder']; |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
// fetch additional record information |
| 257 |
$q = $this->dbo->getQuery(true); |
| 258 |
$q->select($this->dbo->qn([ |
| 259 |
'o.id', |
| 260 |
'o.custdata', |
| 261 |
'o.ts', |
| 262 |
'o.status', |
| 263 |
'o.days', |
| 264 |
'o.checkin', |
| 265 |
'o.checkout', |
| 266 |
'o.idpayment', |
| 267 |
'o.roomsnum', |
| 268 |
'o.idorderota', |
| 269 |
'o.channel', |
| 270 |
'o.chcurrency', |
| 271 |
'o.country', |
| 272 |
'o.closure', |
| 273 |
'o.refund', |
| 274 |
'o.canc_fee', |
| 275 |
'co.idcustomer', |
| 276 |
'c.first_name', |
| 277 |
'c.last_name', |
| 278 |
])); |
| 279 |
$q->from($this->dbo->qn('#__vikbooking_orders', 'o')); |
| 280 |
$q->leftJoin($this->dbo->qn('#__vikbooking_customers_orders', 'co') . ' ON ' . $this->dbo->qn('co.idorder') . ' = ' . $this->dbo->qn('o.id')); |
| 281 |
$q->leftJoin($this->dbo->qn('#__vikbooking_customers', 'c') . ' ON ' . $this->dbo->qn('c.id') . ' = ' . $this->dbo->qn('co.idcustomer')); |
| 282 |
$q->where($this->dbo->qn('o.id') . ' IN (' . implode(', ', $all_bids) . ')'); |
| 283 |
if ($ptype == 'confirmed') { |
| 284 |
$q->where($this->dbo->qn('o.status') . ' = ' . $this->dbo->q('confirmed')); |
| 285 |
} |
| 286 |
|
| 287 |
$this->dbo->setQuery($q); |
| 288 |
$bookings = $this->dbo->loadAssocList(); |
| 289 |
if (!$bookings) { |
| 290 |
$this->setError(JText::translate('VBOREPORTSERRNORESERV')); |
| 291 |
return false; |
| 292 |
} |
| 293 |
|
| 294 |
// merge history records with booking values |
| 295 |
foreach ($records as $k => &$hrecord) { |
| 296 |
$found = false; |
| 297 |
foreach ($bookings as $booking) { |
| 298 |
if ($booking['id'] == $hrecord['idorder']) { |
| 299 |
$hrecord = array_merge($hrecord, $booking); |
| 300 |
$found = true; |
| 301 |
continue; |
| 302 |
} |
| 303 |
} |
| 304 |
if (!$found) { |
| 305 |
unset($records[$k]); |
| 306 |
} |
| 307 |
} |
| 308 |
|
| 309 |
// unset last reference |
| 310 |
unset($hrecord); |
| 311 |
|
| 312 |
// define the columns of the report |
| 313 |
$this->cols = array( |
| 314 |
// date |
| 315 |
array( |
| 316 |
'key' => 'dt', |
| 317 |
'sortable' => 1, |
| 318 |
'label' => JText::translate('VBPVIEWORDERSONE') |
| 319 |
), |
| 320 |
// customer |
| 321 |
array( |
| 322 |
'key' => 'customer', |
| 323 |
'attr' => array( |
| 324 |
'class="left"' |
| 325 |
), |
| 326 |
'sortable' => 1, |
| 327 |
'label' => JText::translate('VBCUSTOMERNOMINATIVE') |
| 328 |
), |
| 329 |
// channel |
| 330 |
array( |
| 331 |
'key' => 'channel', |
| 332 |
'attr' => array( |
| 333 |
'class="center"' |
| 334 |
), |
| 335 |
'sortable' => 1, |
| 336 |
'label' => JText::translate('VBOCHANNEL') |
| 337 |
), |
| 338 |
// checkin |
| 339 |
array( |
| 340 |
'key' => 'checkin', |
| 341 |
'attr' => array( |
| 342 |
'class="left"' |
| 343 |
), |
| 344 |
'sortable' => 1, |
| 345 |
'label' => JText::translate('VBPICKUPAT') |
| 346 |
), |
| 347 |
// checkout |
| 348 |
array( |
| 349 |
'key' => 'checkout', |
| 350 |
'attr' => array( |
| 351 |
'class="left"' |
| 352 |
), |
| 353 |
'sortable' => 1, |
| 354 |
'label' => JText::translate('VBRELEASEAT') |
| 355 |
), |
| 356 |
// nights |
| 357 |
array( |
| 358 |
'key' => 'nights', |
| 359 |
'attr' => array( |
| 360 |
'class="center"' |
| 361 |
), |
| 362 |
'sortable' => 1, |
| 363 |
'label' => JText::translate('VBDAYS') |
| 364 |
), |
| 365 |
// rooms |
| 366 |
array( |
| 367 |
'key' => 'rooms', |
| 368 |
'attr' => array( |
| 369 |
'class="center"' |
| 370 |
), |
| 371 |
'sortable' => 1, |
| 372 |
'label' => JText::translate('VBPVIEWORDERSTHREE') |
| 373 |
), |
| 374 |
// event |
| 375 |
array( |
| 376 |
'key' => 'event', |
| 377 |
'attr' => array( |
| 378 |
'class="center"' |
| 379 |
), |
| 380 |
'sortable' => 1, |
| 381 |
'label' => JText::translate('VBOBOOKHISTORYLBLTYPE') |
| 382 |
), |
| 383 |
// amount paid |
| 384 |
array( |
| 385 |
'key' => 'amount_paid', |
| 386 |
'attr' => array( |
| 387 |
'class="center"' |
| 388 |
), |
| 389 |
'sortable' => 1, |
| 390 |
'label' => JText::translate('VBAMOUNTPAID') |
| 391 |
), |
| 392 |
// payment method |
| 393 |
array( |
| 394 |
'key' => 'pay_meth', |
| 395 |
'attr' => array( |
| 396 |
'class="center"' |
| 397 |
), |
| 398 |
'sortable' => 1, |
| 399 |
'label' => JText::translate('VBLIBPAYNAME') |
| 400 |
), |
| 401 |
// status |
| 402 |
array( |
| 403 |
'key' => 'status', |
| 404 |
'attr' => array( |
| 405 |
'class="center"' |
| 406 |
), |
| 407 |
'sortable' => 1, |
| 408 |
'label' => JText::translate('VBSTATUS') |
| 409 |
), |
| 410 |
// ID |
| 411 |
array( |
| 412 |
'key' => 'id', |
| 413 |
'attr' => array( |
| 414 |
'class="center"' |
| 415 |
), |
| 416 |
'sortable' => 1, |
| 417 |
'label' => JText::translate('VBDASHBOOKINGID') |
| 418 |
), |
| 419 |
); |
| 420 |
|
| 421 |
// default channel provenience |
| 422 |
$website_provenience = JText::translate('VBORDFROMSITE'); |
| 423 |
|
| 424 |
// channel logos helper |
| 425 |
$vcm_logos = VikBooking::getVcmChannelsLogo('', true); |
| 426 |
|
| 427 |
// default payment method |
| 428 |
$def_pay_meth = JText::translate('VBOREPORTTOPCUNKNC'); |
| 429 |
|
| 430 |
// loop over the history records to build the rows |
| 431 |
foreach ($records as $hrecord) { |
| 432 |
// customer name |
| 433 |
$customer_name = '-----'; |
| 434 |
if (!empty($hrecord['first_name']) && !empty($hrecord['last_name'])) { |
| 435 |
$customer_name = ltrim($hrecord['first_name'] . ' ' . $hrecord['last_name'], ' '); |
| 436 |
} elseif (!empty($hrecord['custdata'])) { |
| 437 |
$parts = explode("\n", $hrecord['custdata']); |
| 438 |
if (count($parts) >= 2 && strpos($parts[0], ':') !== false && strpos($parts[1], ':') !== false) { |
| 439 |
$first_parts = explode(':', $parts[0]); |
| 440 |
$second_parts = explode(':', $parts[1]); |
| 441 |
$customer_name = ltrim(trim($first_parts[1]) . ' ' . trim($second_parts[1]), ' '); |
| 442 |
} |
| 443 |
} |
| 444 |
|
| 445 |
// country and stay dates |
| 446 |
$country = $hrecord['country']; |
| 447 |
$in_info = getdate($hrecord['checkin']); |
| 448 |
$curwday_in = $this->getWdayString($in_info['wday'], 'short'); |
| 449 |
$out_info = getdate($hrecord['checkout']); |
| 450 |
$curwday_out = $this->getWdayString($out_info['wday'], 'short'); |
| 451 |
|
| 452 |
// channel logo and provenience |
| 453 |
$provenience = $website_provenience; |
| 454 |
$channel_html = $website_provenience; |
| 455 |
if (!empty($hrecord['channel'])) { |
| 456 |
// build channel name |
| 457 |
$otachannel = ''; |
| 458 |
$channelparts = explode('_', $hrecord['channel']); |
| 459 |
$otachannel = array_key_exists(1, $channelparts) && strlen($channelparts[1]) ? $channelparts[1] : ucwords($channelparts[0]); |
| 460 |
$provenience = $otachannel; |
| 461 |
|
| 462 |
// attempt to fetch the channel logo |
| 463 |
$ota_logo_img = is_object($vcm_logos) ? $vcm_logos->setProvenience($otachannel, $hrecord['channel'])->getLogoURL() : false; |
| 464 |
if ($ota_logo_img !== false) { |
| 465 |
// display the image in the View and hide it during printing |
| 466 |
$channel_html = '<img src="' . $ota_logo_img . '" title="' . htmlspecialchars($otachannel) . '" class="vbo-hidein-print vbo-channelimg-medium" />'; |
| 467 |
// get rid of the ending "...api" in the channel name |
| 468 |
$channel_html .= '<span class="vbo-showin-print">' . preg_replace("/([a-z0-9 ]+)(api)$/i", '$1', $otachannel) . '</span>'; |
| 469 |
} else { |
| 470 |
// get rid of the ending "...api" in the channel name |
| 471 |
$channel_html = '<span class="vbo-provenience">' . preg_replace("/([a-z0-9 ]+)(api)$/i", '$1', $otachannel) . '</span>'; |
| 472 |
} |
| 473 |
} |
| 474 |
|
| 475 |
// total booking amount, amount paid and payment method |
| 476 |
$tot_booking = $hrecord['total']; |
| 477 |
$amount_paid = $hrecord['totpaid']; |
| 478 |
$pay_meth = ''; |
| 479 |
if (!empty($hrecord['data'])) { |
| 480 |
$ev_data = json_decode($hrecord['data'], true); |
| 481 |
$ev_data = is_array($ev_data) ? $ev_data : []; |
| 482 |
if (isset($ev_data['amount_paid'])) { |
| 483 |
$amount_paid = (float)$ev_data['amount_paid']; |
| 484 |
} |
| 485 |
if (isset($ev_data['payment_method'])) { |
| 486 |
$pay_meth = $ev_data['payment_method']; |
| 487 |
} elseif (isset($ev_data['driver'])) { |
| 488 |
$pay_meth = basename($ev_data['driver'], '.php'); |
| 489 |
} |
| 490 |
} |
| 491 |
|
| 492 |
if (!$pay_meth && !empty($hrecord['idpayment']) && in_array($hrecord['type'], ['P0', 'PN'])) { |
| 493 |
$payment_record = VikBooking::getPayment($hrecord['idpayment']); |
| 494 |
if ($payment_record) { |
| 495 |
$pay_meth = $payment_record['name']; |
| 496 |
} |
| 497 |
} |
| 498 |
|
| 499 |
if (!$pay_meth) { |
| 500 |
// unknown payment method |
| 501 |
$pay_meth = $def_pay_meth; |
| 502 |
} |
| 503 |
|
| 504 |
// refund events |
| 505 |
if ($hrecord['type'] == 'RF' || $hrecord['type'] == 'RU') { |
| 506 |
// set the actual (negative) amount refunded |
| 507 |
$amount_paid = ($hrecord['refund'] - ($hrecord['refund'] * 2)); |
| 508 |
} |
| 509 |
|
| 510 |
// booking status |
| 511 |
if ($hrecord['status'] == 'confirmed') { |
| 512 |
$book_status = JText::translate('VBCONFIRMED'); |
| 513 |
$saystaus = '<span class="label label-success">' . JText::translate('VBCONFIRMED') . '</span>'; |
| 514 |
} elseif ($hrecord['status'] == 'standby') { |
| 515 |
$book_status = JText::translate('VBSTANDBY'); |
| 516 |
$saystaus = '<span class="label label-warning">' . JText::translate('VBSTANDBY') . '</span>'; |
| 517 |
} else { |
| 518 |
$book_status = JText::translate('VBCANCELLED'); |
| 519 |
$saystaus = '<span class="label label-error">' . JText::translate('VBCANCELLED') . '</span>'; |
| 520 |
} |
| 521 |
|
| 522 |
// push fields in the rows array as a new row |
| 523 |
array_push($this->rows, array( |
| 524 |
array( |
| 525 |
'key' => 'dt', |
| 526 |
'callback' => function ($val) use ($df, $datesep) { |
| 527 |
return JHtml::fetch('date', $val, str_replace("/", $datesep, $df) . ' H:i:s'); |
| 528 |
}, |
| 529 |
'export_callback' => function ($val) use ($df, $datesep) { |
| 530 |
return JHtml::fetch('date', $val, str_replace("/", $datesep, $df) . ' H:i:s'); |
| 531 |
}, |
| 532 |
'value' => $hrecord['dt'] |
| 533 |
), |
| 534 |
array( |
| 535 |
'key' => 'customer', |
| 536 |
'attr' => array( |
| 537 |
'class="vbo-report-touristtaxes-countryname"' |
| 538 |
), |
| 539 |
'callback' => function ($val) use ($country) { |
| 540 |
if (is_file(VBO_ADMIN_PATH.DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'countries' . DIRECTORY_SEPARATOR . $country . '.png')) { |
| 541 |
return $val . '<img src="' . VBO_ADMIN_URI . 'resources/countries/' . $country . '.png" title="' . $country . '" class="vbo-country-flag vbo-country-flag-left" />'; |
| 542 |
} |
| 543 |
return $val; |
| 544 |
}, |
| 545 |
'export_callback' => function ($val) use ($country) { |
| 546 |
return $val . (!empty($country) ? ' (' . $country . ')' : ''); |
| 547 |
}, |
| 548 |
'value' => $customer_name |
| 549 |
), |
| 550 |
array( |
| 551 |
'key' => 'channel', |
| 552 |
'attr' => array( |
| 553 |
'class="center"' |
| 554 |
), |
| 555 |
'callback' => function ($val) use ($channel_html) { |
| 556 |
return $channel_html; |
| 557 |
}, |
| 558 |
'export_callback' => function ($val) { |
| 559 |
return $val; |
| 560 |
}, |
| 561 |
'value' => $provenience |
| 562 |
), |
| 563 |
array( |
| 564 |
'key' => 'checkin', |
| 565 |
'callback' => function ($val) use ($df, $datesep, $curwday_in) { |
| 566 |
return $curwday_in . ', ' . date(str_replace("/", $datesep, $df), $val); |
| 567 |
}, |
| 568 |
'export_callback' => function ($val) use ($df, $datesep, $curwday_in) { |
| 569 |
return $curwday_in . ', ' . date(str_replace("/", $datesep, $df), $val); |
| 570 |
}, |
| 571 |
'value' => $hrecord['checkin'] |
| 572 |
), |
| 573 |
array( |
| 574 |
'key' => 'checkout', |
| 575 |
'callback' => function ($val) use ($df, $datesep, $curwday_out) { |
| 576 |
return $curwday_out . ', ' . date(str_replace("/", $datesep, $df), $val); |
| 577 |
}, |
| 578 |
'export_callback' => function ($val) use ($df, $datesep, $curwday_out) { |
| 579 |
return $curwday_out . ', ' . date(str_replace("/", $datesep, $df), $val); |
| 580 |
}, |
| 581 |
'value' => $hrecord['checkout'] |
| 582 |
), |
| 583 |
array( |
| 584 |
'key' => 'nights', |
| 585 |
'attr' => array( |
| 586 |
'class="center"' |
| 587 |
), |
| 588 |
'value' => $hrecord['days'] |
| 589 |
), |
| 590 |
array( |
| 591 |
'key' => 'rooms', |
| 592 |
'attr' => array( |
| 593 |
'class="center"' |
| 594 |
), |
| 595 |
'value' => $hrecord['roomsnum'] |
| 596 |
), |
| 597 |
array( |
| 598 |
'key' => 'event', |
| 599 |
'attr' => array( |
| 600 |
'class="center"' |
| 601 |
), |
| 602 |
'value' => $history_obj->validType($hrecord['type'], true) |
| 603 |
), |
| 604 |
array( |
| 605 |
'key' => 'amount_paid', |
| 606 |
'attr' => array( |
| 607 |
'class="center"' |
| 608 |
), |
| 609 |
'callback' => function ($val) use ($currency_symb) { |
| 610 |
return $currency_symb . ' ' . VikBooking::numberFormat($val); |
| 611 |
}, |
| 612 |
'value' => $amount_paid |
| 613 |
), |
| 614 |
array( |
| 615 |
'key' => 'pay_meth', |
| 616 |
'attr' => array( |
| 617 |
'class="center"' |
| 618 |
), |
| 619 |
'value' => $pay_meth |
| 620 |
), |
| 621 |
array( |
| 622 |
'key' => 'status', |
| 623 |
'attr' => array( |
| 624 |
'class="center"' |
| 625 |
), |
| 626 |
'callback' => function ($val) use ($saystaus) { |
| 627 |
return $saystaus; |
| 628 |
}, |
| 629 |
'export_callback' => function ($val) { |
| 630 |
return $book_status; |
| 631 |
}, |
| 632 |
'value' => $book_status |
| 633 |
), |
| 634 |
array( |
| 635 |
'key' => 'id', |
| 636 |
'attr' => array( |
| 637 |
'class="center"' |
| 638 |
), |
| 639 |
'callback' => function ($val) { |
| 640 |
return '<a href="index.php?option=com_vikbooking&task=editorder&cid[]='.$val.'" target="_blank"><i class="'.VikBookingIcons::i('external-link').'"></i> '.$val.'</a>'; |
| 641 |
}, |
| 642 |
'export_callback' => function ($val) { |
| 643 |
return $val; |
| 644 |
}, |
| 645 |
'value' => $hrecord['idorder'] |
| 646 |
), |
| 647 |
)); |
| 648 |
} |
| 649 |
|
| 650 |
// sort rows |
| 651 |
$this->sortRows($pkrsort, $pkrorder); |
| 652 |
|
| 653 |
// count footer values |
| 654 |
$total_takings = 0; |
| 655 |
foreach ($this->rows as $row_vals) { |
| 656 |
foreach ($row_vals as $row_val) { |
| 657 |
if ($row_val['key'] == 'amount_paid') { |
| 658 |
$total_takings += $row_val['value']; |
| 659 |
} |
| 660 |
} |
| 661 |
} |
| 662 |
|
| 663 |
// push footer rows |
| 664 |
$this->footerRow[] = [ |
| 665 |
[ |
| 666 |
'attr' => [ |
| 667 |
'class="vbo-report-total"' |
| 668 |
], |
| 669 |
'value' => '<h3>' . JText::translate('VBO_TOTAL_TAKINGS') . '</h3>', |
| 670 |
], |
| 671 |
[ |
| 672 |
'value' => '', |
| 673 |
], |
| 674 |
[ |
| 675 |
'value' => '', |
| 676 |
], |
| 677 |
[ |
| 678 |
'value' => '', |
| 679 |
], |
| 680 |
[ |
| 681 |
'value' => '', |
| 682 |
], |
| 683 |
[ |
| 684 |
'value' => '', |
| 685 |
], |
| 686 |
[ |
| 687 |
'value' => '', |
| 688 |
], |
| 689 |
[ |
| 690 |
'value' => '', |
| 691 |
], |
| 692 |
[ |
| 693 |
'attr' => [ |
| 694 |
'class="center"' |
| 695 |
], |
| 696 |
'callback' => function ($val) use ($currency_symb) { |
| 697 |
return $currency_symb . ' ' . VikBooking::numberFormat($val); |
| 698 |
}, |
| 699 |
'value' => $total_takings, |
| 700 |
], |
| 701 |
[ |
| 702 |
'value' => '', |
| 703 |
], |
| 704 |
[ |
| 705 |
'value' => '', |
| 706 |
], |
| 707 |
[ |
| 708 |
'value' => '', |
| 709 |
], |
| 710 |
]; |
| 711 |
|
| 712 |
// Debug |
| 713 |
if ($this->debug) { |
| 714 |
$this->setWarning('path to report file = '.urlencode(dirname(__FILE__)).'<br/>'); |
| 715 |
$this->setWarning('$records:<pre>'.print_r($records, true).'</pre><br/>'); |
| 716 |
} |
| 717 |
|
| 718 |
return true; |
| 719 |
} |
| 720 |
|
| 721 |
/** |
| 722 |
* Registers the name to give to the CSV file being exported. |
| 723 |
* |
| 724 |
* @return void |
| 725 |
*/ |
| 726 |
private function registerExportCSVFileName() |
| 727 |
{ |
| 728 |
$pfromdate = VikRequest::getString('fromdate', '', 'request'); |
| 729 |
$ptodate = VikRequest::getString('todate', '', 'request'); |
| 730 |
|
| 731 |
$this->setExportCSVFileName($this->reportName . '-' . str_replace('/', '_', $pfromdate) . (!empty($ptodate) && $ptodate != $pfromdate ? '-' . str_replace('/', '_', $ptodate) : '') . '.csv'); |
| 732 |
} |
| 733 |
} |
| 734 |
|