Import single contingents per room

This commit is contained in:
Björn Fromme
2018-09-28 12:41:04 +02:00
parent b9ae52e17f
commit 77bd1e6be7
5 changed files with 119 additions and 36 deletions
@@ -62,6 +62,26 @@ class Contingent extends AbstractEntity implements EventInterface
*/
protected $status;
/**
* @param array $data
* @return Contingent
*/
public static function fromArray(array $data)
{
$event = new self;
$event->setPax($data['pax']);
$event->setAvailable($data['available']);
$event->setDate(new \DateTime($data['date']));
$event->setStatus($data['status']);
if ($data['hotel'] instanceof Hotel) {
$event->setHotel($data['hotel']);
}
return $event;
}
/**
* @return \DateTime
*/
@@ -28,7 +28,10 @@ namespace EP\EpProducts\Domain\Repository;
***************************************************************/
use CalendR\Event\Provider\ProviderInterface;
use EP\EpProducts\Domain\Model\Contingent;
use EP\EpProducts\Domain\Model\Hotel;
use EP\EpProducts\Utility\DbUtility;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ContingentRepository extends AbstractRepository implements ProviderInterface
{
@@ -40,16 +43,51 @@ class ContingentRepository extends AbstractRepository implements ProviderInterfa
*/
public function getEvents(\DateTime $dateFrom, \DateTime $dateTo, array $options = [])
{
$query = $this->createQuery();
$query->getQuerySettings()->setRespectStoragePage(false);
$constraints = [
$query->greaterThanOrEqual('date', $dateFrom->format('Y-m-d')),
$query->lessThanOrEqual('date', $dateTo->format('Y-m-d'))
];
if (array_key_exists('hotel', $options) && $options['hotel'] instanceof Hotel) {
$constraints[] = $query->equals('hotel', $options['hotel']->getUid());
$optionsResolver = new OptionsResolver();
$optionsResolver->setDefined(['hotel']);
$optionsResolver->setAllowedTypes('hotel', Hotel::class);
$resolvedOptions = $optionsResolver->resolve($options);
$qb = DbUtility::getDbConnection()->createQueryBuilder();
$qb
->select('status status', 'date date', 'SUM(pax) pax', 'SUM(available) available', 'min_price minPrice')
->from('tx_epproducts_domain_model_contingent')
->groupBy('hotel')
->addGroupBy('date')
->orderBy('date')
;
$hotel = null;
if ($resolvedOptions['hotel']) {
/** @var Hotel $hotel */
$hotel = $resolvedOptions['hotel'];
$qb
->where('hotel = :hotel')
->setParameter('hotel', $hotel->getUid())
;
}
$query->matching($query->logicalAnd($constraints));
return $query->execute()->toArray();
$qb
->andWhere('date >= :dateFrom')
->andWhere('date <= :dateTo')
->setParameter('dateFrom', $dateFrom->format('Y-m-d'))
->setParameter('dateTo', $dateTo->format('Y-m-d'))
;
$result = $qb->execute()->fetchAll();
$events = [];
foreach ($result as $row)
{
if ($hotel) {
$row['hotel'] = $hotel;
}
$events[] = Contingent::fromArray($row);
}
return $events;
}
}
@@ -168,7 +168,7 @@ class ContingentImportService implements SingletonInterface
}
/**
* @param \SimpleXMLElement[] $xmlTypes
* @param \SimpleXMLElement $xmlTypes
* @return array
*/
protected function parseRoomTypes($xmlTypes)
@@ -178,6 +178,7 @@ class ContingentImportService implements SingletonInterface
{
$types[(string) $xmlType['idbuspro']] = [
'pax' => (int) $xmlType['pax_max'],
'code' => (string) $xmlType['code'],
'ctrl' => (string) $xmlType['code'] === self::ROOMCODE_STATUS,
];
}
@@ -196,8 +197,7 @@ class ContingentImportService implements SingletonInterface
$dateCount = 0;
foreach ($xmlDates->kapazitaet as $xmlDate)
{
$totalPax = 0;
$totalAvailable = 0;
$date = \DateTime::createFromFormat('d.m.Y', (string) $xmlDate['termin']);
$status = Contingent::STATUS_OK;
$statusBlocked = false;
$statusOnRequest = false;
@@ -208,6 +208,7 @@ class ContingentImportService implements SingletonInterface
continue;
}
$roomType = $roomTypes[$roomTypeBusProId];
$roomCode = $roomType['code'];
if ($roomType['ctrl'] === true) {
if ((string) $xmlRoom['status'] === 'A') {
$statusOnRequest = true;
@@ -216,29 +217,33 @@ class ContingentImportService implements SingletonInterface
$statusBlocked = true;
}
} else {
$totalPax += $roomType['pax'] * (int) $xmlRoom['kontingent'];
$available = (int) $xmlRoom['frei'] > 0 ? (int) $xmlRoom['frei'] : 0;
$totalAvailable += $roomType['pax'] * $available;
$pax = $roomType['pax'] * (int) $xmlRoom['kontingent'];
$availableRooms = (int) $xmlRoom['frei'] > 0 ? (int) $xmlRoom['frei'] : 0;
$availablePax = $availableRooms * $roomType['pax'];
}
if ($availablePax === 0) {
continue;
}
if ($statusBlocked) {
$status = Contingent::STATUS_BLOCKED;
} elseif ($statusOnRequest) {
$status = Contingent::STATUS_ONREQUEST;
}
//TODO: Parse minPrice when available
$this->db->insert(
'tx_epproducts_domain_model_contingent_temp',
[
'pid' => $this->pid,
'hotel' => $hotelData['uid'],
'room_code' => $roomCode,
'groupsch_id' => $hotelData['groupsch_id'],
'pax' => $pax,
'available' => $availablePax,
'status' => $status,
'date' => $date->format('Y-m-d'),
]
);
}
if ($statusBlocked) {
$status = Contingent::STATUS_BLOCKED;
} elseif ($statusOnRequest) {
$status = Contingent::STATUS_ONREQUEST;
}
$date = \DateTime::createFromFormat('d.m.Y', (string) $xmlDate['termin']);
$this->db->insert(
'tx_epproducts_domain_model_contingent_temp',
[
'pid' => $this->pid,
'hotel' => $hotelData['uid'],
'groupsch_id' => $hotelData['groupsch_id'],
'pax' => $totalPax,
'available' => $totalAvailable,
'status' => $status,
'date' => $date->format('Y-m-d'),
]
);
$dateCount++;
}
return $dateCount;
@@ -24,10 +24,10 @@ return [
'iconfile' => 'EXT:ep_theme/Resources/Public/images/icon_ce.svg',
],
'interface' => [
'showRecordFieldList' => 'date,pax,available,status,hotel,groupsch_id',
'showRecordFieldList' => 'date,pax,available,status,min_price,hotel,room_code,groupsch_id',
],
'types' => [
'1' => ['showitem' => 'date, pax, available, status, hotel,groupsch_id'],
'1' => ['showitem' => 'date, pax, available, status, min_price, hotel, room_code, groupsch_id'],
],
'palettes' => [],
'columns' => [
@@ -176,6 +176,15 @@ return [
]
],
],
'min_price' => [
'exclude' => 0,
'label' => 'ab Preis',
'config' => [
'type' => 'input',
'size' => 30,
'eval' => 'trim',
],
],
'groupsch_id' => [
'exclude' => 0,
'label' => 'LLL:EXT:ep_products/Resources/Private/Language/locallang.xlf:tx_epproducts_domain_model_contingent.groupsch_id',
@@ -185,5 +194,14 @@ return [
'eval' => 'trim,int'
],
],
'room_code' => [
'exclude' => 0,
'label' => 'Zimmercode',
'config' => [
'type' => 'input',
'size' => 8,
'eval' => 'trim'
],
],
],
];
@@ -947,7 +947,9 @@ CREATE TABLE tx_epproducts_domain_model_contingent (
available int(11) unsigned DEFAULT '0' NOT NULL,
date date DEFAULT '0000-00-00',
hotel int(11) unsigned DEFAULT '0',
room_code varchar(64) DEFAULT '' NOT NULL,
status tinyint(4) unsigned DEFAULT '0' NOT NULL,
min_price int(11) DEFAULT '0' NOT NULL,
groupsch_id varchar(8) DEFAULT '' NOT NULL,
tstamp int(11) unsigned DEFAULT '0' NOT NULL,