@@ -158,7 +158,7 @@
********* TERMINE UND PREISE *********
#}
-
+
Saisons
@@ -214,7 +214,7 @@
Buchung
-
Bitte klicken Sie einen Anreisetermin, um zur Buchungsmaske zu gelagen.
+
Bitte klicken Sie einen Anreisetermin (grĂ¼ne Zahl), um zur Buchungsmaske zu gelagen.
{% include 'default/pages/cms/calendarLodgingProgram.html.twig' %}
diff --git a/trunk/app/Resources/views/default/pages/fewoBooking.html.twig b/trunk/app/Resources/views/default/pages/fewoBooking.html.twig
index 6910b64d..8fd95227 100644
--- a/trunk/app/Resources/views/default/pages/fewoBooking.html.twig
+++ b/trunk/app/Resources/views/default/pages/fewoBooking.html.twig
@@ -37,7 +37,7 @@
-{#
+
-#}
+
diff --git a/trunk/src/AppBundle/Controller/CmsController.php b/trunk/src/AppBundle/Controller/CmsController.php
index 0a663507..352010dc 100644
--- a/trunk/src/AppBundle/Controller/CmsController.php
+++ b/trunk/src/AppBundle/Controller/CmsController.php
@@ -144,8 +144,8 @@ class CmsController extends Controller
$paddedCalendar = $calendarService->getCalendarWithPadding($calendarService->getMinCalendarEntriesByLodging($lodging));
if (count($lodging->getPrices()->toArray()) != 0)
{
- $calendar = $calendarService->createCalendarAndFillDayStates($lodging);
- $calendar = $calendarService->mergeWithPaddedCalendar($calendar, $paddedCalendar);
+ $calendar = $calendarService->calendarAndFillDayStates($paddedCalendar, $lodging);
+ // $calendar = $calendarService->mergeWithPaddedCalendar($calendar, $paddedCalendar);
} else {
$calendar = $paddedCalendar;
}
diff --git a/trunk/src/AppBundle/Controller/FewoBookingController.php b/trunk/src/AppBundle/Controller/FewoBookingController.php
index b727fb6b..916225f5 100644
--- a/trunk/src/AppBundle/Controller/FewoBookingController.php
+++ b/trunk/src/AppBundle/Controller/FewoBookingController.php
@@ -67,7 +67,6 @@ class FewoBookingController extends Controller
$fromDate = $calendarService->convertDate($fromDate);
$fromDateTime = new \DateTime($fromDate);
$toDate = '';
-
$maxPersons = $lodging->getMaximumPersons();
@@ -80,6 +79,7 @@ class FewoBookingController extends Controller
$fewoBookingRequest->setLodging($lodging);
$fewoBookingRequest->setPrice($price);
+
$allowedToDateStrs = [];
if (!$lodging->getPrices()->isEmpty())
{
diff --git a/trunk/src/AppBundle/Entity/FewoLodging.php b/trunk/src/AppBundle/Entity/FewoLodging.php
index b05340cb..a5afadfd 100644
--- a/trunk/src/AppBundle/Entity/FewoLodging.php
+++ b/trunk/src/AppBundle/Entity/FewoLodging.php
@@ -522,6 +522,22 @@ class FewoLodging
return $this->prices;
}
+ /**
+ * Get prices
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getPricesFilter($dateFrom, $dateTo)
+ {
+
+ return $this->getPrices()->filter(function(FewoPrice $price) use ($dateFrom, $dateTo) {
+ return ($price->getSeason()->getFromDate() >= $dateFrom && $price->getSeason()->getFromDate() <= $dateTo) ||
+ ($price->getSeason()->getToDate() >= $dateFrom && $price->getSeason()->getToDate() <= $dateTo);
+ });
+ }
+
+
+
/**
* Add image
*
@@ -590,6 +606,19 @@ class FewoLodging
return $this->reservations;
}
+ /**
+ * Get reservationsFilter
+ *
+ * @return \Doctrine\Common\Collections\Collection
+ */
+ public function getReservationsFilter($dateFrom, $dateTo)
+ {
+ return $this->getReservations()->filter(function(FewoReservation $reservation) use ($dateFrom, $dateTo) {
+ return ($reservation->getFromDate() >= $dateFrom && $reservation->getFromDate() <= $dateTo) ||
+ ($reservation->getToDate() >= $dateFrom && $reservation->getToDate() <= $dateTo);
+ });
+ }
+
/**
* Set page
*
diff --git a/trunk/src/AppBundle/Service/LodgingCalendarService.php b/trunk/src/AppBundle/Service/LodgingCalendarService.php
index d48c1323..83efea23 100644
--- a/trunk/src/AppBundle/Service/LodgingCalendarService.php
+++ b/trunk/src/AppBundle/Service/LodgingCalendarService.php
@@ -25,7 +25,7 @@ class LodgingCalendarService
{
return $month == 2 ? ($year % 4 ? 28 : ($year % 100 ? 29 : ($year % 400 ? 28 : 29))) : (($month - 1) % 7 % 2 ? 30 : 31);
}
-
+ //$months = number of Month to the last season
public function getCalendarWithPadding($months)
{
$calendar = null;
@@ -37,6 +37,7 @@ class LodgingCalendarService
$yearTurned = false;
$yearsTurned = 0;
+ $now = new \DateTime();
for($m = $currentMonth; $m < ($currentMonth + $months); $m++)
{
@@ -47,9 +48,7 @@ class LodgingCalendarService
$actualMonth = 12;
$yearTurned = true;
}
-
$actualYear = $currentYear + $yearsTurned;
-
if($yearTurned)
{
$yearsTurned = $yearsTurned + 1;
@@ -68,7 +67,7 @@ class LodgingCalendarService
{
$actualStartingWeekDay = 7;
}
-
+ //first empty days from the last month
for($fwd = 0; $fwd < $actualStartingWeekDay - 1; $fwd++)
{
$day = new CalendarDayState();
@@ -78,25 +77,35 @@ class LodgingCalendarService
$day->setIsReserved(false);
$day->setIsReservationBegin(false);
$day->setIsReservationEnd(false);
+ $day->setIsEmpty(true);
+ $day->setIsPastDate(false);
$data[] = $day;
}
-
+ //days of month
for($d = 1; $d <= $numberDays; $d++)
{
$day = new CalendarDayState();
$day->setDay($d);
+ $datetime = new \DateTime();
+ $datetime->setTimestamp(mktime(0,0,0, $actualMonth, $d, $actualYear));
+ $day->setDate($datetime);
$day->setIsBookable(false);
$day->setIsInSeason(false);
$day->setIsReserved(false);
$day->setIsReservationBegin(false);
$day->setIsReservationEnd(false);
-
+ $day->setIsEmpty(false);
+ if($datetime < $now){
+ $day->setIsPastDate(true);
+ }else{
+ $day->setIsPastDate(false);
+ }
$data[] = $day;
}
$startIndex = count($data);
-
+ //last empty days from the next month
for($lwd = $startIndex; $lwd < 42; $lwd++)
{
$day = new CalendarDayState();
@@ -106,11 +115,12 @@ class LodgingCalendarService
$day->setIsReserved(false);
$day->setIsReservationBegin(false);
$day->setIsReservationEnd(false);
+ $day->setIsEmpty(true);
+ $day->setIsPastDate(false);
$data[] = $day;
}
-
- $calendar[] = [
+ $calendar[$actualYear."-".$actualMonth] = [
'numberDays' => $numberDays,
'monthNumber' => $actualMonth,
'monthName' => utf8_encode(strftime("%B", mktime(0, 0, 0, $actualMonth, 1, $actualYear))),
@@ -161,7 +171,6 @@ class LodgingCalendarService
$numberDays = $this->daysInMonth($actualMonth, $actualYear);
- /** @var CalendarDayState[] $data */
$data = null;
// alle Wochentage
@@ -257,6 +266,7 @@ class LodgingCalendarService
}
+
/**
* @param $calendar
* @param \DateTime $fromDate
@@ -296,7 +306,6 @@ class LodgingCalendarService
// anfang und ende innerhalb eines monats
if($startCalendarIndex == $endCalendarIndex)
{
- /** @var CalendarDayState[] $data */
$data = $calendar[$startCalendarIndex]['data'];
$calendar[$startCalendarIndex]['marked'] = 1;
@@ -348,7 +357,6 @@ class LodgingCalendarService
{
// erster monat
- /** @var CalendarDayState[] $data */
$data = $calendar[$startCalendarIndex]['data'];
$calendar[$startCalendarIndex]['marked'] = 1;
@@ -388,7 +396,6 @@ class LodgingCalendarService
// letzter monat
- /** @var CalendarDayState[] $data */
$data = $calendar[$endCalendarIndex]['data'];
$calendar[$endCalendarIndex]['marked'] = 1;
@@ -431,7 +438,6 @@ class LodgingCalendarService
// alle monate dazwischen
for($i = $startCalendarIndex + 1; $i < $endCalendarIndex; $i++)
{
- /** @var CalendarDayState[] $data */
$data = $calendar[$i]['data'];
$calendar[$i]['marked'] = 1;
@@ -463,15 +469,14 @@ class LodgingCalendarService
return $calendar;
}
+
// in der Regel: calendar = pricesCalendar; extensionCalendar = reservationsCalendar
- private function mergeCalendars($calendar, $extensionCalendar)
+ private function mergeCalendars($calendar, $extensionCalendar)
{
for($i = 0; $i < count($calendar); $i++)
{
- /** @var CalendarDayState[] $calendarData */
$calendarData = $calendar[$i]['data'];
- /** @var CalendarDayState[] $extensionCalendarData */
$extensionCalendarData = $extensionCalendar[$i]['data'];
$endIndex = count($calendarData);
@@ -492,7 +497,6 @@ class LodgingCalendarService
$calendarData[$j]->setIsReservationEnd(false);
}
- /** @var FewoPrice $price */
$calendarData[$j]->setIsInSeason(true);
$calendarData[$j]->setPrice($price);
}
@@ -576,13 +580,11 @@ class LodgingCalendarService
*/
private function filterReservableDays(FewoLodging $lodging, $calendar)
{
- /** @var CalendarDayState[] $potentiallyReservableDays */
$potentiallyReservableDays = [];
for ($currMonthIndex = 0; $currMonthIndex < count($calendar); $currMonthIndex++)
{
$currMonth = $calendar[$currMonthIndex];
- /** @var CalendarDayState[] $data */
$data = $currMonth['data'];
for ($currDayIndex = 0; $currDayIndex < count($data); $currDayIndex++)
@@ -649,6 +651,148 @@ class LodgingCalendarService
return $calendar;
}
+ private function findCalendarDayKey($calendarMonth, $dayNumber){
+
+ foreach ($calendarMonth['data'] as $key => $data) {
+ if($data->getDay() == $dayNumber){
+ return $key;
+ }
+ }
+
+
+ }
+ public function calendarAndFillDayStates($paddedCalendar, FewoLodging $lodging){
+
+ $startMonth = array_values($paddedCalendar)[0]['monthNumber'];
+ $startYear = array_values($paddedCalendar)[0]['year'];
+ $endMonth = array_values($paddedCalendar)[count($paddedCalendar)-1]['monthNumber'];
+ $endYear = array_values($paddedCalendar)[count($paddedCalendar)-1]['year'];
+ $endDay = array_values($paddedCalendar)[count($paddedCalendar)-1]['numberDays'];
+
+ $startDate = new \DateTime(date( "Y-m-d", mktime(0,0,0, $startMonth, 1, $startYear)));
+ $endDate = new \DateTime(date( "Y-m-d", mktime(0,0,0, $endMonth, $endDay, $endYear)));
+
+
+ //reservations in the Calender Time
+ $reservations = $lodging->getReservationsFilter($startDate, $endDate);
+
+
+ foreach($reservations as $reservation)
+ {
+ $setFromIntervall = clone $reservation->getFromDate();
+ $fromDate = $reservation->getFromDate();
+ $toDate = $reservation->getToDate();
+
+ // $diff = $fromDate->diff($toDate);
+ $interval = \DateInterval::createFromDateString('1 day');
+ $period = new \DatePeriod($setFromIntervall->modify('+1 day'), $interval, $toDate);
+
+ //first
+ if(isset($paddedCalendar[$fromDate->format("Y-n")])){
+ $key = $this->findCalendarDayKey($paddedCalendar[$fromDate->format("Y-n")], $fromDate->format("d"));
+ $paddedCalendar[$fromDate->format("Y-n")]['data'][$key]->setIsReservationBegin(true);
+ }
+ //last
+ if(isset($paddedCalendar[$toDate->format("Y-n")])) {
+ $key = $this->findCalendarDayKey($paddedCalendar[$toDate->format("Y-n")], $toDate->format("d"));
+ $paddedCalendar[$toDate->format("Y-n")]['data'][$key]->setIsReservationEnd(true);
+ }
+ //days
+ foreach ($period as $dt) {
+ if(isset($paddedCalendar[$dt->format("Y-n")])) {
+ $key = $this->findCalendarDayKey($paddedCalendar[$dt->format("Y-n")], $dt->format("d"));
+ $paddedCalendar[$dt->format("Y-n")]['data'][$key]->setIsReserved(true);
+ }
+ }
+ }
+
+ $prices = $lodging->getPricesFilter($startDate, $endDate);
+
+ foreach ($prices as $price)
+ {
+
+ /** @var FewoSeason $season */
+ $season = $price->getSeason();
+ $setFromIntervall = clone $season->getFromDate();
+ //$fromDate = $season->getFromDate();
+ $setToIntervall = clone $season->getToDate();
+ //$toDate = $season->getToDate();
+
+ $interval = \DateInterval::createFromDateString('1 day');
+ $period = new \DatePeriod($setFromIntervall, $interval, $setToIntervall->modify('+1 day'));
+
+ //days
+ foreach ($period as $dt) {
+ if(isset($paddedCalendar[$dt->format("Y-n")])) {
+ $key = $this->findCalendarDayKey($paddedCalendar[$dt->format("Y-n")], $dt->format("d"));
+ $currDay = $paddedCalendar[$dt->format("Y-n")]['data'][$key];
+ $currDay->setPrice($price);
+
+
+ if(!$currDay->getIsReserved() && $season->getOnlyWeekday() != null && $season->getOnlyWeekday() == $currDay->getDate()->format('w')){
+ $currDay->setIsBookable(true);
+ }
+
+ if(!$currDay->getIsReserved() && $season->getOnlyWeekday() == null){
+ $currDay->setIsBookable(true);
+ }
+ if($currDay->getIsReservationBegin() == true && $currDay->getIsReservationEnd() == true){
+ $currDay->setIsBookable(false);
+ }
+ //check for the min sty days.
+ if ($currDay->getIsReservationBegin() == true)
+ {
+ //days
+ $minDays = $season->getMinimumStay();
+ $setMinStayFrom = clone $currDay->getDate();
+ $setMinStayTo = clone $currDay->getDate();
+
+ //$minStayInterval = \DateInterval::createFromDateString('-1 day');
+ // $minStayPeriod = new \DatePeriod($setMinStayTo->modify('+1 day'), $minStayInterval, $setMinStayFrom->modify('-'.($minDays-1).' days'));
+ $setMinStayTo->modify('-'.($minDays).' days');
+ $counter = 0;
+ $last = $minDays;
+
+ for($mSdt = $setMinStayFrom; $mSdt >= $setMinStayTo; $mSdt->modify('-1 day')){
+
+ if(isset($paddedCalendar[$mSdt->format("Y-n")])) {
+ $key = $this->findCalendarDayKey($paddedCalendar[$mSdt->format("Y-n")], $mSdt->format("d"));
+ $checkDay = $paddedCalendar[$mSdt->format("Y-n")]['data'][$key];
+
+
+ if($minDays != $checkDay->getPrice()->getSeason()->getMinimumStay()){
+
+ if($minDays > $checkDay->getPrice()->getSeason()->getMinimumStay()){
+ $last = $counter+$checkDay->getPrice()->getSeason()->getMinimumStay();
+
+
+ $setMinStayTo->modify('-'.($last).' days');
+ }
+ if($minDays < $checkDay->getPrice()->getSeason()->getMinimumStay()){
+ $last = $counter+$checkDay->getPrice()->getSeason()->getMinimumStay();
+ $setMinStayTo->modify('-'.($last).' days');
+
+ }
+ $minDays = $checkDay->getPrice()->getSeason()->getMinimumStay();
+ }
+ $counter++;
+
+ if($counter <= $last) {
+ $checkDay->setIsBookable(false);
+ }
+ }
+ }
+
+
+ }
+ }
+ }
+ //$season is end
+ }
+ return $paddedCalendar;
+
+
+ }
/**
* @param FewoLodging $lodging
* @param $calendar
@@ -662,11 +806,11 @@ class LodgingCalendarService
$reservationsCalendar = $this->getCalendar($lodging);
$reservations = $lodging->getReservations();
+
$prices = $lodging->getPrices();
foreach ($prices as $price)
{
- /** @var FewoSeason $season */
$season = $price->getSeason();
$pricesCalendar = $this->markCalendarDays($pricesCalendar, $season->getFromDate(), $season->getToDate(),
false, $price);
@@ -680,7 +824,6 @@ class LodgingCalendarService
$reservationsCalendar = $this->markCalendarDays($reservationsCalendar, $fromDate, $toDate,
true, null, $reservation); //TODO fast fertig
}
-
$mergedPricesAndReservationsCalendar = $this->mergeCalendars($pricesCalendar, $reservationsCalendar);
$actuallyReservableDaysCalendar = $this->filterReservableDays($lodging, $mergedPricesAndReservationsCalendar);
//$resultCalendar = $this->mergeCalendars($actuallyReservableDaysCalendar, $reservationsCalendar, true);
diff --git a/trunk/src/AppBundle/Util/CalendarDayState.php b/trunk/src/AppBundle/Util/CalendarDayState.php
index e6aa1351..a7c987a2 100644
--- a/trunk/src/AppBundle/Util/CalendarDayState.php
+++ b/trunk/src/AppBundle/Util/CalendarDayState.php
@@ -56,6 +56,16 @@ class CalendarDayState
*/
private $date = null;
+ /**
+ * @var bool
+ */
+ private $isEmpty; //empty day in the month
+
+ /**
+ * @var bool
+ */
+ private $isPastDate;
+
/**
* @return int
*/
@@ -200,4 +210,75 @@ class CalendarDayState
$this->date = $date;
}
+ /**
+ * @return bool
+ */
+ public function getIsEmpty(): bool
+ {
+ return $this->isEmpty;
+ }
+
+ /**
+ * @param bool $isEmpty
+ */
+ public function setIsEmpty(bool $isEmpty)
+ {
+ $this->isEmpty = $isEmpty;
+ }
+
+ /**
+ * @return bool
+ */
+ public function getIsPastDate(): bool
+ {
+ return $this->isPastDate;
+ }
+
+ /**
+ * @param bool $isPastDate
+ */
+ public function setIsPastDate(bool $isPastDate)
+ {
+ $this->isPastDate = $isPastDate;
+ }
+
+
+ public function getCssClass(){
+ $ret = "";
+ if($this->getIsPastDate()){
+ $ret .= 'calendar-light ';
+ }
+
+ if($this->getDay() == 0){
+ $ret .= 'calendar-day-non ';
+ }
+
+ if($this->getIsReserved()){
+ $ret .= 'calendar-day-disabled ';
+ return $ret;
+ }
+
+ if($this->getIsReservationBegin() && $this->getIsReservationEnd()){
+ $ret .= 'calendar-day-disabled-half ';
+ return $ret;
+ }
+
+ if($this->getIsReservationBegin()){
+ $ret .= 'calendar-day-reservation-begin ';
+ return $ret;
+ }
+
+ if($this->getIsReservationEnd()){
+ $ret .= 'calendar-day-reservation-end ';
+ return $ret;
+ }
+
+
+
+ return $ret;
+
+
+ }
+
+
}