Search in sources :

Example 11 with BookingEntry

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()));
    }
}
Also used : Guest(com.github.drbookings.model.data.Guest) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 12 with BookingEntry

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;
}
Also used : Label(javafx.scene.control.Label) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 13 with BookingEntry

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);
}
Also used : BookingSelectionManager(com.github.drbookings.ui.selection.BookingSelectionManager) Initializable(javafx.fxml.Initializable) java.util(java.util) URL(java.net.URL) Series(javafx.scene.chart.XYChart.Series) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) BinType(com.github.drbookings.model.BinType) Callable(java.util.concurrent.Callable) XYChart(javafx.scene.chart.XYChart) Bindings(javafx.beans.binding.Bindings) Slider(javafx.scene.control.Slider) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) CategoryAxis(javafx.scene.chart.CategoryAxis) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) BookingEntry(com.github.drbookings.ui.BookingEntry) ChangeListener(javafx.beans.value.ChangeListener) ExceptionUnknownType(net.sf.kerner.utils.exception.ExceptionUnknownType) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 14 with BookingEntry

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();
}
Also used : BookingSelectionManager(com.github.drbookings.ui.selection.BookingSelectionManager) Initializable(javafx.fxml.Initializable) java.util(java.util) URL(java.net.URL) Series(javafx.scene.chart.XYChart.Series) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) BinType(com.github.drbookings.model.BinType) Callable(java.util.concurrent.Callable) XYChart(javafx.scene.chart.XYChart) Bindings(javafx.beans.binding.Bindings) Slider(javafx.scene.control.Slider) ListChangeListener(javafx.collections.ListChangeListener) ComboBox(javafx.scene.control.ComboBox) Label(javafx.scene.control.Label) Logger(org.slf4j.Logger) CategoryAxis(javafx.scene.chart.CategoryAxis) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ObservableValue(javafx.beans.value.ObservableValue) ObservableList(javafx.collections.ObservableList) NumberAxis(javafx.scene.chart.NumberAxis) BookingEntry(com.github.drbookings.ui.BookingEntry) ChangeListener(javafx.beans.value.ChangeListener) ExceptionUnknownType(net.sf.kerner.utils.exception.ExceptionUnknownType) LocalDate(java.time.LocalDate) BookingEntry(com.github.drbookings.ui.BookingEntry) XYChart(javafx.scene.chart.XYChart)

Example 15 with BookingEntry

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));
}
Also used : Guest(com.github.drbookings.model.data.Guest) BookingOrigin(com.github.drbookings.model.data.BookingOrigin) Room(com.github.drbookings.model.data.Room) BookingEntry(com.github.drbookings.ui.BookingEntry) BookingBean(com.github.drbookings.model.data.BookingBean) Test(org.junit.Test)

Aggregations

BookingEntry (com.github.drbookings.ui.BookingEntry)19 LocalDate (java.time.LocalDate)10 Collectors (java.util.stream.Collectors)8 Logger (org.slf4j.Logger)8 LoggerFactory (org.slf4j.LoggerFactory)8 SettingsManager (com.github.drbookings.model.settings.SettingsManager)7 FXCollections (javafx.collections.FXCollections)6 ListChangeListener (javafx.collections.ListChangeListener)6 ObservableList (javafx.collections.ObservableList)6 URL (java.net.URL)5 java.util (java.util)5 Entry (java.util.Map.Entry)5 FXML (javafx.fxml.FXML)5 Initializable (javafx.fxml.Initializable)5 StringUtils (org.apache.commons.lang3.StringUtils)5 CleaningEntry (com.github.drbookings.ui.CleaningEntry)4 Label (javafx.scene.control.Label)4 Guest (com.github.drbookings.model.data.Guest)3 MainManager (com.github.drbookings.model.data.manager.MainManager)3 BookingsByOrigin (com.github.drbookings.ui.BookingsByOrigin)3