use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.
the class CellContentController method setData.
public void setData(final RoomBean rb) {
if (rb == null) {
return;
}
Set<Guest> guestsAdded = new LinkedHashSet<>();
BookingEntry last = null;
boolean cleaningToAdd = true;
for (final BookingEntry bb : rb.getFilteredBookingEntries().stream().sorted(Comparator.comparing(BookingEntry::isCheckIn)).collect(Collectors.toList())) {
if (bb.getElement().isSplitBooking() && guestsAdded.contains(bb.getElement().getGuest())) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping duplicate entry " + bb);
}
last = bb;
continue;
}
if (bb.isCheckOut()) {
cellContainer.getChildren().add(buildEntryCheckOut(bb));
cellContainer.setAlignment(Pos.TOP_CENTER);
}
if (cleaningToAdd && rb.needsCleaning()) {
cellContainer.getChildren().add(buildEntryCleaning(rb));
cleaningToAdd = false;
}
if (bb.isCheckIn()) {
cellContainer.getChildren().add(buildEntryCheckIn(bb));
cellContainer.setAlignment(Pos.BOTTOM_CENTER);
}
if (cleaningToAdd && rb.hasCleaning()) {
cellContainer.getChildren().add(buildEntryCleaning(rb));
cleaningToAdd = false;
}
if (!bb.isCheckIn() && !bb.isCheckOut()) {
cellContainer.getChildren().add(buildEntryStay(bb));
cellContainer.setAlignment(Pos.CENTER);
}
last = bb;
guestsAdded.add(bb.getElement().getGuest());
}
if (rb.isWarning()) {
if (rb.hasCheckIn()) {
cellContainer.getStyleClass().add("warning-box-top");
} else if (rb.hasCheckOut()) {
// cellContainer.getStyleClass().add("warning-box-bottom");
} else {
cellContainer.getStyleClass().add("warning-box-middle");
}
}
if (last != null && (!last.isCheckOut() || last.getElement().isSplitBooking())) {
cellContainer.getStyleClass().add(Styles.getBackgroundStyleSource(last.getElement().getBookingOrigin().getName()));
}
}
use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.
the class CellContentController method buildEntryCheckOut.
private static Node buildEntryCheckOut(final BookingEntry e) {
final Label l = getNewLabel(e.getElement().getGuest().getName());
if (e.getElement().isSplitBooking()) {
Optional<BookingEntry> next = MainManager.getInstance().getAfter(e);
if (next.isPresent()) {
BookingEntry be = next.get();
if (be.getElement().getGuest().equals(e.getElement().getGuest())) {
// do not apply label for the same guest
return l;
}
}
}
l.getStyleClass().add("check-out");
return l;
}
use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.
the class EarningsPerDayChartViewController method doChart.
protected void doChart(final List<? extends BookingEntry> allElements) {
categories.clear();
mapSeries.clear();
chart.getData().clear();
for (int i = 0; i < allElements.size(); i++) {
final BookingEntry db = allElements.get(i);
bin.add(db);
if (bin.stream().map(e -> e.getDate()).collect(Collectors.toSet()).size() >= getBinSize()) {
flushBin();
}
}
flushBin();
final ObservableList<String> c = FXCollections.observableArrayList(categories);
Collections.sort(c);
xAxis.setCategories(c);
xAxis.setAutoRanging(true);
}
use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.
the class EarningsPerDayChartViewController method flushBin.
@Override
protected void flushBin() {
if (bin.isEmpty()) {
return;
}
final LocalDate xValue = bin.stream().map(d -> d.getDate()).max((d1, d2) -> d1.compareTo(d2)).get();
final Map<String, Number> yValue = new TreeMap<>();
final int dayCnt = bin.stream().map(d -> d.getDate()).collect(Collectors.toSet()).size();
for (final BookingEntry d : bin) {
final String originName = d.getElement().getBookingOrigin().getName();
Number n = yValue.getOrDefault(originName, 0);
n = n.doubleValue() + d.getEarnings(SettingsManager.getInstance().isShowNetEarnings());
yValue.put(originName, n);
}
for (final Entry<String, Number> e : yValue.entrySet()) {
Series<String, Number> s = mapSeries.get(e.getKey());
if (s == null) {
s = new Series<>();
s.setName(e.getKey());
mapSeries.put(e.getKey(), s);
chart.getData().add(s);
}
Number value = e.getValue();
if (BinType.MEAN.equals(toggle.getSelectionModel().getSelectedItem())) {
if (dayCnt < 1) {
if (logger.isWarnEnabled()) {
logger.warn("Invalid data, day cnt: " + dayCnt + " for " + bin.stream().map(d -> d.getDate()).collect(Collectors.toSet()));
}
}
value = value.doubleValue() / dayCnt;
}
final XYChart.Data<String, Number> data = new XYChart.Data<>(xValue.toString(), value);
categories.add(xValue.toString());
s.getData().add(data);
}
if (logger.isDebugEnabled()) {
logger.debug(xValue + ": " + yValue);
}
bin.clear();
}
use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.
the class NightlyRateViewTest method test01.
@Test
public void test01() {
final BookingBean booking1 = new BookingBean("id1", new Guest("g1"), new Room("1"), new BookingOrigin("airbnb"), LocalDate.of(2000, 4, 4), LocalDate.of(2000, 4, 6));
final BookingBean booking2 = new BookingBean("id2", new Guest("g2"), new Room("2"), new BookingOrigin("airbnb"), LocalDate.of(2000, 4, 4), LocalDate.of(2000, 4, 6));
booking1.setGrossEarningsExpression("100");
booking2.setGrossEarningsExpression("200");
final List<BookingEntry> entries1 = booking1.getEntries();
final List<BookingEntry> entries2 = booking2.getEntries();
// System.out.println(entries.stream().map(b -> b.toString()).collect(Collectors.joining("\n")));
view.addAll(entries1);
view.addAll(entries2);
assertThat(view.data.size(), is(1));
}
Aggregations