Fix: Properly determine unavailabilities for Groups.swiss
This commit is contained in:
@@ -58,7 +58,7 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa
|
||||
$qb = $this->getDbConnection()->createQueryBuilder();
|
||||
|
||||
$qb
|
||||
->select('status as status', 'date as date', 'min_price as minPrice', 'pax', 'available')
|
||||
->select('status as status', 'date as date', 'min_price as minPrice', 'pax', 'available', 'room_code')
|
||||
->from('tx_epproducts_domain_model_contingent')
|
||||
->where('hotel = :hotelUid')
|
||||
->andWhere('date >= :dateFrom')
|
||||
@@ -91,8 +91,10 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa
|
||||
if ($row['status'] !== Contingent::STATUS_OK) {
|
||||
$dates[$row['date']]['status'] = $row['status'];
|
||||
}
|
||||
$dates[$row['date']]['pax'] += $row['pax'];
|
||||
$dates[$row['date']]['available'] += $row['available'];
|
||||
if ('BelKal' !== $row['room_code']) {
|
||||
$dates[$row['date']]['pax'] += $row['pax'];
|
||||
$dates[$row['date']]['available'] += $row['available'];
|
||||
}
|
||||
}
|
||||
|
||||
$events = [];
|
||||
|
||||
@@ -120,28 +120,47 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $events
|
||||
* @param array $contingents
|
||||
* @param string $apiKey
|
||||
* @param int $houseNumber
|
||||
*/
|
||||
protected function generateChart(array $events, $apiKey, $houseNumber): void
|
||||
protected function generateChart(array $contingents, $apiKey, $houseNumber): void
|
||||
{
|
||||
$item = null;
|
||||
$status = null;
|
||||
$itemStatus = null;
|
||||
|
||||
// Iterate over all contingents
|
||||
foreach ($contingents as $contingent) {
|
||||
/** @var Contingent $contingent */
|
||||
// Get actual or 'virtual' status of current contingent
|
||||
$contingentStatus = $this->getContingentStatus($contingent);
|
||||
|
||||
foreach ($events as $event) {
|
||||
/** @var Contingent $event */
|
||||
$contingentStatus = $this->getContingentStatus($event);
|
||||
if (null === $item && Contingent::STATUS_OK !== $contingentStatus) {
|
||||
$status = $contingentStatus;
|
||||
// Make contingent status the current status
|
||||
$itemStatus = $contingentStatus;
|
||||
// Create fresh chart item
|
||||
$item = [
|
||||
'from' => $event->getBegin(),
|
||||
'from' => $contingent->getBegin(),
|
||||
'status' => $contingentStatus,
|
||||
];
|
||||
} elseif (true === is_array($item) && $status !== $contingentStatus) {
|
||||
$item['to'] = $event->getEnd()->modify('-1 day');
|
||||
$statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2;
|
||||
} elseif (null !== $item && $itemStatus !== $contingentStatus) {
|
||||
// Set end date of current chart item to previous contingent's date
|
||||
$item['to'] = $contingent->getEnd();
|
||||
// Translate status code for Groups.swiss
|
||||
$statusCode = Contingent::STATUS_ONREQUEST === $item['status'] ? 1 : 2;
|
||||
// Post chart item to API
|
||||
$this->addItem($item, $statusCode, $apiKey, $houseNumber);
|
||||
$item = null;
|
||||
// Make contingent status the current status
|
||||
$itemStatus = $contingentStatus;
|
||||
// Reset chart item or create fresh one depending on new status
|
||||
if (Contingent::STATUS_OK === $contingentStatus) {
|
||||
$item = null;
|
||||
} else {
|
||||
$item = [
|
||||
'from' => $contingent->getBegin(),
|
||||
'status' => $contingentStatus,
|
||||
];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -150,12 +169,16 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
||||
* @param Contingent $contingent
|
||||
* @return int
|
||||
*/
|
||||
protected function getContingentStatus(Contingent $contingent)
|
||||
protected function getContingentStatus(Contingent $contingent): int
|
||||
{
|
||||
if (in_array($contingent->getStatus(), [Contingent::STATUS_BLOCKED, Contingent::STATUS_ONREQUEST], true)) {
|
||||
return $contingent->getStatus();
|
||||
$contingentStatus = $contingent->getStatus();
|
||||
|
||||
// All status other than OK are to be applied immediately
|
||||
if (Contingent::STATUS_BLOCKED === $contingentStatus || Contingent::STATUS_ONREQUEST === $contingentStatus) {
|
||||
return $contingentStatus;
|
||||
}
|
||||
|
||||
// Determine 'virtual' status depending on availability
|
||||
$percentageAvailable = $contingent->getPercentageAvailable();
|
||||
|
||||
if ($percentageAvailable <= 20) {
|
||||
|
||||
Reference in New Issue
Block a user