| 1 |
<?php |
| 2 |
/** |
| 3 |
* @package VikBooking |
| 4 |
* @subpackage core |
| 5 |
* @author E4J s.r.l. |
| 6 |
* @copyright Copyright (C) 2025 E4J s.r.l. All Rights Reserved. |
| 7 |
* @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL |
| 8 |
* @link https://vikwp.com |
| 9 |
*/ |
| 10 |
|
| 11 |
// No direct access |
| 12 |
defined('ABSPATH') or die('No script kiddies please!'); |
| 13 |
|
| 14 |
/** |
| 15 |
* RMS Pace Data Metric ADR (Average Daily Rate) implementation. |
| 16 |
* |
| 17 |
* @since 1.18.6 (J) - 1.8.6 (WP) |
| 18 |
*/ |
| 19 |
final class VBORmsPaceDataMetricAdr extends VBORmsPaceDataMetric |
| 20 |
{ |
| 21 |
/** |
| 22 |
* @inheritDoc |
| 23 |
*/ |
| 24 |
public function extract(VBORmsPaceDataperiod $paceDataPeriod, ?array $periodPaceMetrics = null) |
| 25 |
{ |
| 26 |
// list of booking room rates |
| 27 |
$roomRates = []; |
| 28 |
|
| 29 |
// iterate all bookings affecting the current period |
| 30 |
foreach ($paceDataPeriod as $booking) { |
| 31 |
if ($booking['status'] != 'confirmed') { |
| 32 |
// exclude non-confirmed reservations |
| 33 |
continue; |
| 34 |
} |
| 35 |
foreach (($booking['_rooms'] ?? []) as $bookingRoom) { |
| 36 |
if (!empty($bookingRoom['room_cost'])) { |
| 37 |
$netRoomCost = VikBooking::sayCostMinusIva($bookingRoom['room_cost'], $bookingRoom['idprice'] ?? 0); |
| 38 |
$roomRates[] = (float) $netRoomCost; |
| 39 |
} elseif (!empty($bookingRoom['cust_cost'])) { |
| 40 |
$netRoomCost = VikBooking::sayPackageMinusIva($bookingRoom['cust_cost'], $bookingRoom['cust_idiva']); |
| 41 |
$roomRates[] = (float) $netRoomCost; |
| 42 |
} |
| 43 |
} |
| 44 |
} |
| 45 |
|
| 46 |
if (!$roomRates) { |
| 47 |
return 0; |
| 48 |
} |
| 49 |
|
| 50 |
return round(array_sum($roomRates) / count($roomRates), 2); |
| 51 |
} |
| 52 |
} |
| 53 |
|