Import prices for additional nights, calculate prices correctly for selected period

This commit is contained in:
Björn Fromme
2018-10-03 13:21:09 +02:00
parent a5ff3e67fc
commit 8a68bba3e5
6 changed files with 182 additions and 25 deletions
@@ -24,7 +24,7 @@
<tbody>
<tr v-for="(row, index) of availableRooms">
<td>{{ row.label }}</td>
<td style="white-space: nowrap">ab {{ row.price * selectedNumberOfDays }} &euro;</td>
<td style="white-space: nowrap">ab {{ calculatePrice(row.code, selectedNumberOfDays) }} &euro;</td>
<td>
<i v-if="row.skipassIncluded" data-placement="top" title="Skipass inklusive" class="fa fa-tag tooltiptoggle"></i>
<a href="#" data-toggle="modal"
@@ -64,7 +64,7 @@
</tbody>
</table>
<div v-show="loading" class="loader"><p>Loading...</p></div>
<div v-show="message">{{message}}</div>
<div v-show="message">{{ message }}</div>
</div>
</div>
</div>
@@ -105,18 +105,6 @@
type: Number,
required: true
},
minDate: {
type: Date,
default () {
return new Date()
}
},
maxDate: {
type: Date,
default () {
return new Date(dayjs().add(1, 'year'))
}
},
contingentEndpointUri: {
type: String,
required: true
@@ -155,13 +143,9 @@
if (this.selectedFrom === null || this.selectedTo === null) {
return 'Bitte einen Zeitraum auswählen.';
}
if (this.selectedTo.diff(this.selectedFrom, 'days') < 2) {
return 'Bitte mindestens zwei Nächte auswählen';
}
if (this.availableRooms.length === 0) {
return 'Im gewählten Zeitraum sind leider keine Zimmer verfügbar.';
}
return '';
}
},
@@ -179,10 +163,12 @@
this.availableDates = json;
const enabledDates = [];
if (json.length) {
for (let entry of this.availableDates) {
for (const entry of this.availableDates) {
enabledDates.push(entry.date);
}
this.picker.set('enable', enabledDates);
this.picker.set('minDate', enabledDates[0]);
this.picker.set('maxDate', enabledDates[enabledDates.length - 1]);
this.picker.jumpToDate(enabledDates[0]);
}
}, 'json');
@@ -199,6 +185,14 @@
this.availableRooms = json;
EventBus.$emit('tableLoaded');
}, 'json');
},
calculatePrice (roomCode, nights) {
for (const room of this.availableRooms) {
if (room.code === roomCode) {
return room.price + (nights - room.minNights) * room.additionalNightPrice;
}
}
return null;
}
},
mounted () {
@@ -207,14 +201,12 @@
dateFormat: 'Y-m-d',
locale: German,
inline: true,
minDate: new Date(this.minDate),
maxDate: new Date(this.maxDate),
onChange: (selectedDates) => {
this.availableRooms = [];
if (selectedDates.length === 2) {
this.selectedFrom = dayjs(selectedDates[0]);
this.selectedTo = dayjs(selectedDates[1]);
if (this.selectedTo.diff(this.selectedFrom, 'days') > 1) {
if (this.selectedNumberOfDays > 1) {
this.fetchAvailableRooms();
}
}
@@ -224,7 +216,7 @@
for (const entry of this.availableDates) {
if (entry.date === day) {
dayElem.classList.add('available');
return false;
return;
}
}