From 66bf4988401bab22889b89a9b7d5f3fddbafb21f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bjo=CC=88rn=20Fromme?= Date: Fri, 23 Nov 2018 16:12:05 +0100 Subject: [PATCH] Determine correct occupancy level considering room status --- .../Repository/ContingentRepository.php | 29 +++++++++++++++---- 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php index d26179a5..df6eccab 100644 --- a/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php +++ b/web/typo3conf/ext/ep_products/Classes/Domain/Repository/ContingentRepository.php @@ -53,12 +53,8 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa $qb = $this->getDbConnection()->createQueryBuilder(); $qb - ->select('status as status', 'date as date', 'min_price as minPrice') - ->addSelectLiteral('SUM(pax) as pax') - ->addSelectLiteral('SUM(available) as available') + ->select('status as status', 'date as date', 'min_price as minPrice', 'pax', 'available') ->from('tx_epproducts_domain_model_contingent') - ->groupBy('hotel') - ->addGroupBy('date') ->orderBy('date') ; @@ -82,9 +78,30 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa $result = $qb->execute()->fetchAll(); - $events = []; + $dates = []; foreach ($result as $row) + { + if (!\array_key_exists($row['date'], $dates)) { + $dates[$row['date']] = [ + 'status' => Contingent::STATUS_OK, + 'date' => $row['date'], + 'minPrice' => $row['minPrice'], + 'pax' => $row['pax'], + 'available' => $row['available'], + ]; + } else { + if ($row['status'] !== Contingent::STATUS_OK) { + $dates[$row['date']]['status'] = $row['status']; + } + $dates[$row['date']]['pax'] += $row['pax']; + $dates[$row['date']]['available'] += $row['available']; + } + } + + $events = []; + + foreach ($dates as $row) { if ($hotel) { $row['hotel'] = $hotel;