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 = $this->getDbConnection()->createQueryBuilder();
|
||||||
|
|
||||||
$qb
|
$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')
|
->from('tx_epproducts_domain_model_contingent')
|
||||||
->where('hotel = :hotelUid')
|
->where('hotel = :hotelUid')
|
||||||
->andWhere('date >= :dateFrom')
|
->andWhere('date >= :dateFrom')
|
||||||
@@ -91,9 +91,11 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa
|
|||||||
if ($row['status'] !== Contingent::STATUS_OK) {
|
if ($row['status'] !== Contingent::STATUS_OK) {
|
||||||
$dates[$row['date']]['status'] = $row['status'];
|
$dates[$row['date']]['status'] = $row['status'];
|
||||||
}
|
}
|
||||||
|
if ('BelKal' !== $row['room_code']) {
|
||||||
$dates[$row['date']]['pax'] += $row['pax'];
|
$dates[$row['date']]['pax'] += $row['pax'];
|
||||||
$dates[$row['date']]['available'] += $row['available'];
|
$dates[$row['date']]['available'] += $row['available'];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$events = [];
|
$events = [];
|
||||||
|
|
||||||
|
|||||||
@@ -120,28 +120,47 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param array $events
|
* @param array $contingents
|
||||||
* @param string $apiKey
|
* @param string $apiKey
|
||||||
* @param int $houseNumber
|
* @param int $houseNumber
|
||||||
*/
|
*/
|
||||||
protected function generateChart(array $events, $apiKey, $houseNumber): void
|
protected function generateChart(array $contingents, $apiKey, $houseNumber): void
|
||||||
{
|
{
|
||||||
$item = null;
|
$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) {
|
if (null === $item && Contingent::STATUS_OK !== $contingentStatus) {
|
||||||
$status = $contingentStatus;
|
// Make contingent status the current status
|
||||||
|
$itemStatus = $contingentStatus;
|
||||||
|
// Create fresh chart item
|
||||||
$item = [
|
$item = [
|
||||||
'from' => $event->getBegin(),
|
'from' => $contingent->getBegin(),
|
||||||
|
'status' => $contingentStatus,
|
||||||
];
|
];
|
||||||
} elseif (true === is_array($item) && $status !== $contingentStatus) {
|
} elseif (null !== $item && $itemStatus !== $contingentStatus) {
|
||||||
$item['to'] = $event->getEnd()->modify('-1 day');
|
// Set end date of current chart item to previous contingent's date
|
||||||
$statusCode = Contingent::STATUS_ONREQUEST === $status ? 1 : 2;
|
$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);
|
$this->addItem($item, $statusCode, $apiKey, $houseNumber);
|
||||||
|
// 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;
|
$item = null;
|
||||||
|
} else {
|
||||||
|
$item = [
|
||||||
|
'from' => $contingent->getBegin(),
|
||||||
|
'status' => $contingentStatus,
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -150,12 +169,16 @@ class GroupsSwissService implements SingletonInterface, LoggerAwareInterface
|
|||||||
* @param Contingent $contingent
|
* @param Contingent $contingent
|
||||||
* @return int
|
* @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)) {
|
$contingentStatus = $contingent->getStatus();
|
||||||
return $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();
|
$percentageAvailable = $contingent->getPercentageAvailable();
|
||||||
|
|
||||||
if ($percentageAvailable <= 20) {
|
if ($percentageAvailable <= 20) {
|
||||||
|
|||||||
Reference in New Issue
Block a user