Search in sources :

Example 1 with BookingEntry

use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.

the class MainManager method removeBookings.

public synchronized boolean removeBookings(final List<BookingBean> bookings) {
    this.bookings.removeAll(bookings);
    for (final Iterator<BookingEntry> it = bookingEntries.values().iterator(); it.hasNext(); ) {
        final BookingEntry be = it.next();
        if (bookings.contains(be.getElement())) {
            it.remove();
        }
    }
    if (logger.isDebugEnabled()) {
        logger.debug("BookingBean entries now " + bookingEntries.size());
    }
    final boolean result = this.bookings.removeAll(bookings);
    if (logger.isDebugEnabled()) {
        logger.debug("Bookings now " + this.bookings.size());
    }
    removeUiDataBooking(bookings);
    return result;
}
Also used : BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 2 with BookingEntry

use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.

the class MainManager method getBefore.

public Optional<BookingEntry> getBefore(BookingEntry e) {
    LocalDate plusOneDay = e.getDate().minusDays(1);
    Room room = e.getRoom();
    Collection<BookingEntry> bookingsThatDay = bookingEntries.get(plusOneDay);
    if (bookingsThatDay != null) {
        return bookingsThatDay.stream().filter(b -> b.getRoom().equals(room)).findFirst();
    }
    return Optional.empty();
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) com.github.drbookings.model.data(com.github.drbookings.model.data) java.util(java.util) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) OverbookingException(com.github.drbookings.OverbookingException) DateRange(com.github.drbookings.DateRange) Multimap(com.google.common.collect.Multimap) SimpleListProperty(javafx.beans.property.SimpleListProperty) DateBean(com.github.drbookings.ui.beans.DateBean) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) RoomBean(com.github.drbookings.ui.beans.RoomBean) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) CleaningEntry(com.github.drbookings.ui.CleaningEntry) ObservableList(javafx.collections.ObservableList) BookingEntry(com.github.drbookings.ui.BookingEntry) ListProperty(javafx.beans.property.ListProperty) LocalDate(java.time.LocalDate) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 3 with BookingEntry

use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.

the class MainManager method getAfter.

public Optional<BookingEntry> getAfter(BookingEntry e) {
    LocalDate plusOneDay = e.getDate().plusDays(1);
    Room room = e.getRoom();
    Collection<BookingEntry> bookingsThatDay = bookingEntries.get(plusOneDay);
    if (bookingsThatDay != null) {
        return bookingsThatDay.stream().filter(b -> b.getRoom().equals(room)).findFirst();
    }
    return Optional.empty();
}
Also used : ArrayListMultimap(com.google.common.collect.ArrayListMultimap) com.github.drbookings.model.data(com.github.drbookings.model.data) java.util(java.util) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) FXCollections(javafx.collections.FXCollections) OverbookingException(com.github.drbookings.OverbookingException) DateRange(com.github.drbookings.DateRange) Multimap(com.google.common.collect.Multimap) SimpleListProperty(javafx.beans.property.SimpleListProperty) DateBean(com.github.drbookings.ui.beans.DateBean) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) RoomBean(com.github.drbookings.ui.beans.RoomBean) Stream(java.util.stream.Stream) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) CleaningEntry(com.github.drbookings.ui.CleaningEntry) ObservableList(javafx.collections.ObservableList) BookingEntry(com.github.drbookings.ui.BookingEntry) ListProperty(javafx.beans.property.ListProperty) LocalDate(java.time.LocalDate) BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 4 with BookingEntry

use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.

the class BookingEntries method getEarningsAirbnb.

@Deprecated
public static double getEarningsAirbnb(final Collection<? extends BookingEntry> bookings, final Function<EarningsProvider, Number> earningsProvider) {
    double result = 0;
    final BookingsByOrigin<BookingEntry> bo = new BookingsByOrigin<>(bookings);
    final Map<BookingBean, Collection<BookingEntry>> map = new LinkedHashMap<>();
    for (final BookingEntry be : bo.getAirbnbBookings()) {
        final Collection<BookingEntry> value = map.getOrDefault(be.getElement(), new ArrayList<>());
        value.add(be);
        map.put(be.getElement(), value);
    }
    for (final Entry<BookingBean, Collection<BookingEntry>> en : map.entrySet()) {
        final LocalDate ci = en.getKey().getCheckIn();
        if (en.getKey().isSplitBooking()) {
            final int daysCurrentMonth = YearMonth.from(ci).lengthOfMonth();
            final double earnings = getEarningsGeneral(en.getValue(), earningsProvider);
            if (logger.isInfoEnabled()) {
                logger.info("Split-payment (" + String.format("%5.2f", earnings) + ") for " + en.getKey() + ", days of month " + daysCurrentMonth);
            }
            result += earnings;
        } else {
            result += getEarningsGeneral(en.getValue(), earningsProvider);
        }
    }
    return result;
}
Also used : BookingsByOrigin(com.github.drbookings.ui.BookingsByOrigin) BookingEntry(com.github.drbookings.ui.BookingEntry) LocalDate(java.time.LocalDate)

Example 5 with BookingEntry

use of com.github.drbookings.ui.BookingEntry in project drbookings by DrBookings.

the class CellContentController method buildEntryCheckIn.

private static Node buildEntryCheckIn(final BookingEntry e) {
    final Label l = getNewLabel(e.getElement().getGuest().getName());
    if (e.getElement().isSplitBooking()) {
        Optional<BookingEntry> next = MainManager.getInstance().getBefore(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-in");
    return l;
}
Also used : Label(javafx.scene.control.Label) BookingEntry(com.github.drbookings.ui.BookingEntry)

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