Search in sources :

Example 1 with Guest

use of com.github.drbookings.model.data.Guest 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 2 with Guest

use of com.github.drbookings.model.data.Guest 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 3 with Guest

use of com.github.drbookings.model.data.Guest 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

Guest (com.github.drbookings.model.data.Guest)3 BookingEntry (com.github.drbookings.ui.BookingEntry)3 BookingOrigin (com.github.drbookings.model.data.BookingOrigin)2 com.github.drbookings (com.github.drbookings)1 BookingBean (com.github.drbookings.model.data.BookingBean)1 BookingEntries (com.github.drbookings.model.data.BookingEntries)1 Room (com.github.drbookings.model.data.Room)1 MainManager (com.github.drbookings.model.data.manager.MainManager)1 SettingsManager (com.github.drbookings.model.settings.SettingsManager)1 BookingsByOrigin (com.github.drbookings.ui.BookingsByOrigin)1 CurrencyCellValueFactory (com.github.drbookings.ui.CurrencyCellValueFactory)1 IntegerCellValueFactory (com.github.drbookings.ui.IntegerCellValueFactory)1 StatisticsTableBean (com.github.drbookings.ui.beans.StatisticsTableBean)1 BookingSelectionManager (com.github.drbookings.ui.selection.BookingSelectionManager)1 Range (com.google.common.collect.Range)1 URL (java.net.URL)1 LocalDate (java.time.LocalDate)1 java.util (java.util)1 Entry (java.util.Map.Entry)1 Collectors (java.util.stream.Collectors)1