Search in sources :

Example 6 with BookingEntry

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

the class UpcomingController method addEvents.

private void addEvents(final LocalDate date, final Collection<BookingEntry> upcomingBookings, final Collection<CleaningEntry> upcomingCleanings) {
    final VBox box = new VBox(4);
    if (date.equals(LocalDate.now())) {
        box.getStyleClass().add("first-day");
    } else if (date.equals(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("second-day");
    } else if (date.isAfter(LocalDate.now().plusDays(1))) {
        box.getStyleClass().add("later");
    }
    if (upcomingBookings.stream().filter(b -> b.isCheckIn() || b.isCheckOut()).collect(Collectors.toList()).isEmpty() && upcomingCleanings.isEmpty()) {
        final Text t0 = new Text(getDateString(date));
        final Text t1 = new Text(" there are no events.");
        t0.getStyleClass().add("emphasis");
        final TextFlow tf = new TextFlow();
        tf.getChildren().addAll(t0, t1);
        box.getChildren().addAll(tf);
    } else {
        final List<CheckInOutDetails> checkInNotes = Collections.synchronizedList(new ArrayList<>());
        final List<CheckInOutDetails> checkOutNotes = Collections.synchronizedList(new ArrayList<>());
        upcomingBookings.forEach(b -> {
            if (b.isCheckIn()) {
                String note = "";
                if (b.getElement().getCheckInNote() != null) {
                    note = b.getElement().getCheckInNote();
                }
                if (b.getElement().getSpecialRequestNote() != null) {
                    note = note + "\n" + b.getElement().getSpecialRequestNote();
                }
                checkInNotes.add(new CheckInOutDetails(b.getRoom().getName(), b.getElement().getBookingOrigin().getName(), note));
            } else if (b.isCheckOut()) {
                checkOutNotes.add(new CheckInOutDetails(b.getRoom().getName(), b.getElement().getBookingOrigin().getName(), b.getElement().getCheckOutNote()));
            }
        });
        Collections.sort(checkInNotes);
        Collections.sort(checkOutNotes);
        addGeneralSummary(date, box, checkInNotes);
        addCheckOutSummary(date, box, checkOutNotes);
        addCheckOutNotes(date, box, checkOutNotes);
        addCheckInSummary(date, box, checkInNotes);
        addCheckInNotes(date, box, checkInNotes);
        addCleaningSummary(date, box, upcomingCleanings);
        addCleanings(date, box, upcomingCleanings);
    }
    this.box.getChildren().add(box);
}
Also used : Initializable(javafx.fxml.Initializable) Logger(org.slf4j.Logger) URL(java.net.URL) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) MainManager(com.github.drbookings.model.data.manager.MainManager) TextFlow(javafx.scene.text.TextFlow) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DateBean(com.github.drbookings.ui.beans.DateBean) ArrayList(java.util.ArrayList) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) Separator(javafx.scene.control.Separator) Text(javafx.scene.text.Text) List(java.util.List) ResourceBundle(java.util.ResourceBundle) ListChangeListener(javafx.collections.ListChangeListener) LocalDate(java.time.LocalDate) CleaningEntry(com.github.drbookings.ui.CleaningEntry) BookingEntry(com.github.drbookings.ui.BookingEntry) Collections(java.util.Collections) Text(javafx.scene.text.Text) TextFlow(javafx.scene.text.TextFlow) VBox(javafx.scene.layout.VBox)

Example 7 with BookingEntry

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

the class RoomBean method hasCheckOut.

public boolean hasCheckOut() {
    final List<BookingEntry> filteredBookingEntries = getFilteredBookingEntries();
    if (filteredBookingEntries.size() == 1 && filteredBookingEntries.get(0).isCheckOut()) {
        return true;
    }
    boolean check = false;
    boolean split = false;
    for (final BookingEntry be : filteredBookingEntries) {
        if (be.isCheckOut()) {
            check = true;
        }
        if (be.getElement().isSplitBooking()) {
            split = true;
        }
    }
    // any booking is check-out and any booking is split booking
    return check && !split;
}
Also used : BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 8 with BookingEntry

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

the class RoomDetailsController method buildTooltipText.

private String buildTooltipText(final List<BookingEntry> bookings) {
    final StringBuilder sb = new StringBuilder();
    for (final Iterator<BookingEntry> it = bookings.iterator(); it.hasNext(); ) {
        final BookingEntry e = it.next();
        sb.append(e.getElement().getBookingOrigin().getName());
        sb.append("\n");
        sb.append(LocalDates.getDateString(e.getElement().getCheckIn()));
        sb.append("\n");
        sb.append(LocalDates.getDateString(e.getElement().getCheckOut()));
        sb.append("\n");
        sb.append(e.getElement().getNumberOfNights() + " nights");
        if (it.hasNext()) {
            sb.append("\n");
        }
    }
    return sb.toString();
}
Also used : BookingEntry(com.github.drbookings.ui.BookingEntry)

Example 9 with BookingEntry

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

the class StatsViewController method updateUI.

private void updateUI(final BookingsByOrigin<BookingEntry> bookings, final Range<LocalDate> dateRange) {
    if (logger.isDebugEnabled()) {
        logger.debug("Statistics for\n" + BookingEntries.toBookings(bookings.getAllBookings()).stream().map(i -> i.toString()).collect(Collectors.joining("\n")));
    }
    final float allAllNigths = BookingEntries.countNights(bookings, false);
    final NavigableSet<LocalDate> allDates = bookings.getAllBookings(true).stream().map(b -> b.getDate()).collect(Collectors.toCollection(TreeSet::new));
    long monthCount = TemporalQueries.countOccurrences(allDates, SettingsManager.getInstance().getFixCostsPaymentDay());
    if (logger.isDebugEnabled()) {
        logger.debug("Month count: " + monthCount);
    }
    if (monthCount < 1) {
        monthCount = 1;
        if (logger.isDebugEnabled()) {
            logger.debug("Month count (corrected): " + monthCount);
        }
    }
    final float additionalCosts = SettingsManager.getInstance().getAdditionalCosts() * monthCount;
    final float numberOfRooms = SettingsManager.getInstance().getNumberOfRooms();
    final float totalAdditionalCosts = additionalCosts * numberOfRooms;
    if (logger.isDebugEnabled()) {
        logger.debug("Fix costs total: " + totalAdditionalCosts);
    }
    for (final Entry<BookingOrigin, Collection<BookingEntry>> e : bookings.getMap().entrySet()) {
        final Collection<? extends BookingEntry> bookingsFilteredByPaymentDate = e.getValue().stream().filter(new PaymentDateFilter(dateRange)).collect(Collectors.toList());
        final Collection<? extends BookingEntry> bookingsFilteredByCleaningDate = e.getValue().stream().filter(new CleaningDateFilter(dateRange)).collect(Collectors.toList());
        final int numberOfAllBookings = (int) BookingEntries.countBookings(new BookingsByOrigin<>(e.getValue()), false);
        final int numberOfPayedBookings = (int) BookingEntries.countBookings(new BookingsByOrigin<>(e.getValue()), false);
        final int numberOfAllNights = (int) BookingEntries.countNights(new BookingsByOrigin<>(e.getValue()), false);
        final int numberOfPayedNights = (int) BookingEntries.countNights(new BookingsByOrigin<>(bookingsFilteredByPaymentDate), false);
        final float percentage;
        if (StringUtils.isBlank(e.getKey().getName())) {
            percentage = 0;
        } else {
            percentage = numberOfAllNights / allAllNigths * 100f;
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " percentage of all nights: " + percentage);
        }
        final double relativeFixCosts = totalAdditionalCosts * percentage / 100;
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " relative fix costs " + relativeFixCosts);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + " number of bookings (all/payed): " + numberOfAllBookings + "/" + numberOfPayedBookings);
        }
        if (logger.isDebugEnabled()) {
            logger.debug(e.getKey() + ": Number of nights (all/payed): " + numberOfAllNights + "/" + numberOfPayedNights);
        }
        if (logger.isDebugEnabled()) {
            Set<Guest> set = e.getValue().stream().map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(LinkedHashSet::new));
            List<Guest> list = e.getValue().stream().filter(b -> !b.isCheckOut()).map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(ArrayList::new));
            StringBuilder sb = new StringBuilder(e.getKey() + " guest and nights (all):");
            int cnt = 1;
            int cnt2 = 0;
            for (final Guest guest : set) {
                final int cnt3 = Collections.frequency(list, guest);
                sb.append(String.format("%n%4d%20s%4d", cnt++, guest.getName(), cnt3));
                cnt2 += cnt3;
            }
            sb.append(String.format("%n%24s%4d", "Total", cnt2));
            logger.debug(sb.toString());
            set = bookingsFilteredByPaymentDate.stream().map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(LinkedHashSet::new));
            list = bookingsFilteredByPaymentDate.stream().filter(b -> !b.isCheckOut()).map(b -> b.getElement().getGuest()).collect(Collectors.toCollection(ArrayList::new));
            sb = new StringBuilder(e.getKey() + " guest and nights (payed):");
            cnt = 1;
            cnt2 = 0;
            for (final Guest guest : set) {
                final int cnt3 = Collections.frequency(list, guest);
                sb.append(String.format("%n%4d%20s%4d", cnt++, guest.getName(), cnt3));
                cnt2 += cnt3;
            }
            sb.append(String.format("%n%24s%4d", "Total", cnt2));
            logger.debug(sb.toString());
        }
        final StatisticsTableBean b = StatisticsTableBean.build(e.getKey().getName(), bookingsFilteredByPaymentDate);
        StatisticsTableBean.applyCleaningStuff(b, bookingsFilteredByCleaningDate);
        b.setFixCosts((float) relativeFixCosts);
        b.setNightsPercent(percentage);
        b.setNumberOfPayedNights(numberOfPayedNights);
        b.setNumberOfAllNights(numberOfAllNights);
        b.setNumberOfPayedBookings(numberOfPayedBookings);
        b.setNumberOfAllBookings(numberOfAllBookings);
        data.add(b);
    }
    // add a total row
    final float relativeFixCosts = totalAdditionalCosts;
    final StatisticsTableBean b = StatisticsTableBean.buildSum(data);
    b.setFixCosts(relativeFixCosts);
    b.setNightsPercent(100);
    data.add(b);
}
Also used : BookingSelectionManager(com.github.drbookings.ui.selection.BookingSelectionManager) Initializable(javafx.fxml.Initializable) java.util(java.util) URL(java.net.URL) LoggerFactory(org.slf4j.LoggerFactory) IntegerCellValueFactory(com.github.drbookings.ui.IntegerCellValueFactory) FXCollections(javafx.collections.FXCollections) MainManager(com.github.drbookings.model.data.manager.MainManager) StringUtils(org.apache.commons.lang3.StringUtils) BookingsByOrigin(com.github.drbookings.ui.BookingsByOrigin) TableColumn(javafx.scene.control.TableColumn) BookingEntries(com.github.drbookings.model.data.BookingEntries) ListChangeListener(javafx.collections.ListChangeListener) Guest(com.github.drbookings.model.data.Guest) TableView(javafx.scene.control.TableView) Logger(org.slf4j.Logger) Range(com.google.common.collect.Range) CurrencyCellValueFactory(com.github.drbookings.ui.CurrencyCellValueFactory) Collectors(java.util.stream.Collectors) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) com.github.drbookings(com.github.drbookings) BookingOrigin(com.github.drbookings.model.data.BookingOrigin) StatisticsTableBean(com.github.drbookings.ui.beans.StatisticsTableBean) LocalDate(java.time.LocalDate) Entry(java.util.Map.Entry) ObservableList(javafx.collections.ObservableList) BookingEntry(com.github.drbookings.ui.BookingEntry) StatisticsTableBean(com.github.drbookings.ui.beans.StatisticsTableBean) Guest(com.github.drbookings.model.data.Guest) BookingsByOrigin(com.github.drbookings.ui.BookingsByOrigin) LocalDate(java.time.LocalDate) BookingOrigin(com.github.drbookings.model.data.BookingOrigin)

Example 10 with BookingEntry

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

the class UpcomingController method update.

private void update() {
    final int lookAheadDays = SettingsManager.getInstance().getUpcomingLookAhead();
    this.box.getChildren().clear();
    for (int i = 0; i < lookAheadDays; i++) {
        final LocalDate date = LocalDate.now().plusDays(i);
        final List<BookingEntry> upcomingBookings = manager.getBookingEntries().stream().filter(b -> b.getDate().equals(date)).collect(Collectors.toList());
        final List<CleaningEntry> upcomingCleanings = manager.getCleaningEntries().stream().filter(c -> c.getDate().equals(date)).collect(Collectors.toList());
        addEvents(date, upcomingBookings, upcomingCleanings);
        if (i != lookAheadDays - 1) {
            this.box.getChildren().add(new Separator());
        }
    }
}
Also used : Initializable(javafx.fxml.Initializable) Logger(org.slf4j.Logger) URL(java.net.URL) Collection(java.util.Collection) LoggerFactory(org.slf4j.LoggerFactory) MainManager(com.github.drbookings.model.data.manager.MainManager) TextFlow(javafx.scene.text.TextFlow) VBox(javafx.scene.layout.VBox) Collectors(java.util.stream.Collectors) StringUtils(org.apache.commons.lang3.StringUtils) DateBean(com.github.drbookings.ui.beans.DateBean) ArrayList(java.util.ArrayList) SettingsManager(com.github.drbookings.model.settings.SettingsManager) FXML(javafx.fxml.FXML) Separator(javafx.scene.control.Separator) Text(javafx.scene.text.Text) List(java.util.List) ResourceBundle(java.util.ResourceBundle) ListChangeListener(javafx.collections.ListChangeListener) LocalDate(java.time.LocalDate) CleaningEntry(com.github.drbookings.ui.CleaningEntry) BookingEntry(com.github.drbookings.ui.BookingEntry) Collections(java.util.Collections) CleaningEntry(com.github.drbookings.ui.CleaningEntry) LocalDate(java.time.LocalDate) BookingEntry(com.github.drbookings.ui.BookingEntry) Separator(javafx.scene.control.Separator)

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