Search in sources :

Example 1 with BookingBean

use of com.github.drbookings.model.data.BookingBean in project drbookings by DrBookings.

the class DataStore method load.

public void load(final MainManager manager) {
    final List<BookingBean> bookingsToAdd = new ArrayList<>();
    for (final BookingBeanSer bb : (Iterable<BookingBeanSer>) () -> getBookingsSer().stream().sorted((b1, b2) -> b1.checkInDate.compareTo(b2.checkInDate)).iterator()) {
        try {
            final BookingBean b = manager.createBooking(bb.bookingId, bb.checkInDate, bb.checkOutDate, bb.guestName, bb.roomName, bb.source);
            // b.setGrossEarnings(bb.grossEarnings);
            b.setGrossEarningsExpression(bb.grossEarningsExpression);
            b.setWelcomeMailSend(bb.welcomeMailSend);
            b.setCheckInNote(bb.checkInNote);
            b.setPaymentDone(bb.paymentDone);
            b.setSpecialRequestNote(bb.specialRequestNote);
            b.setCheckOutNote(bb.checkOutNote);
            b.setExternalId(bb.externalId);
            b.setCalendarIds(bb.calendarIds);
            b.setCleaningFees(bb.cleaningFees);
            b.setServiceFeesPercent(bb.serviceFeePercent);
            b.setDateOfPayment(bb.dateOfPayment);
            b.setSplitBooking(bb.splitBooking);
            b.setPayments(Payment.transform(bb.paymentsSoFar));
            bookingsToAdd.add(b);
        } catch (final Exception e) {
            if (logger.isErrorEnabled()) {
                logger.error(e.getLocalizedMessage(), e);
            }
        }
    }
    bookingsToAdd.forEach(b -> {
        try {
            manager.addBooking(b);
        } catch (final OverbookingException e) {
            if (logger.isWarnEnabled()) {
                logger.warn(e.getLocalizedMessage());
            }
        }
    });
    if (logger.isDebugEnabled()) {
        logger.debug(bookingsToAdd.size() + " added");
    }
    for (final CleaningBeanSer cb : getCleaningsSer()) {
        final Optional<BookingBean> b = manager.getBooking(cb.bookingId);
        if (b.isPresent()) {
            manager.addCleaning(cb.date, cb.name, b.get()).setCalendarIds(cb.calendarIds).setCleaningCosts(cb.cleaningCosts);
        } else {
            if (logger.isWarnEnabled()) {
                logger.warn("Failed to add cleaning " + cb + ", failed to find booking for ID " + cb.bookingId);
            }
        }
    }
}
Also used : CleaningBeanSer(com.github.drbookings.model.ser.CleaningBeanSer) ArrayList(java.util.ArrayList) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer) OverbookingException(com.github.drbookings.OverbookingException) BookingBean(com.github.drbookings.model.data.BookingBean) OverbookingException(com.github.drbookings.OverbookingException)

Example 2 with BookingBean

use of com.github.drbookings.model.data.BookingBean in project drbookings by DrBookings.

the class BookingEarningsCalculator method calculateEarnings.

public float calculateEarnings(Collection<? extends BookingBean> bookings) {
    if (isPaymentDone()) {
        bookings = bookings.stream().filter(b -> b.isPaymentDone()).collect(Collectors.toCollection(LinkedHashSet::new));
    }
    if (getDateRange() != null) {
        bookings = bookings.stream().filter(b -> getDateRange().contains(b.getCheckOut())).collect(Collectors.toCollection(LinkedHashSet::new));
    }
    MonetaryAmountFactory<?> moneyFactory = Monetary.getDefaultAmountFactory().setCurrency(DrBookingsApplication.DEFAULT_CURRENCY.getCurrencyCode());
    MonetaryAmount result = moneyFactory.setNumber(0).create();
    for (BookingBean b : bookings) {
        result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create());
    }
    return result.getNumber().floatValue();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MonetaryAmount(javax.money.MonetaryAmount) BookingBean(com.github.drbookings.model.data.BookingBean)

Example 3 with BookingBean

use of com.github.drbookings.model.data.BookingBean in project drbookings by DrBookings.

the class AddBookingController method handleButtonOK.

@FXML
void handleButtonOK(final ActionEvent event) {
    final boolean valid = validateInput();
    if (valid) {
        try {
            final BookingBean b = getManager().createBooking(datePickerCheckIn.getValue(), datePickerCheckOut.getValue(), textFieldGuestName.getText().trim(), comboBoxRoom.getSelectionModel().getSelectedItem(), textFieldSource.getText().trim());
            b.setGrossEarningsExpression(getGrossEarnings() + "");
            b.setCleaningFees(SettingsManager.getInstance().getCleaningFees());
            try {
                b.setServiceFeesPercent(Float.parseFloat(textFieldServiceFeesPercent.getText()));
            } catch (final NumberFormatException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.toString());
                }
            }
            try {
                b.setServiceFee(Float.parseFloat(textFieldServiceFees.getText()));
            } catch (final NumberFormatException e) {
                if (logger.isDebugEnabled()) {
                    logger.debug(e.toString());
                }
            }
            getManager().addBooking(b);
        } catch (final OverbookingException e) {
            if (logger.isDebugEnabled()) {
                logger.debug(e.getLocalizedMessage());
            }
            UIUtils.showError("Overbooking", e.getLocalizedMessage());
        }
        final Stage stage = (Stage) buttonOK.getScene().getWindow();
        stage.close();
    }
}
Also used : Stage(javafx.stage.Stage) BookingBean(com.github.drbookings.model.data.BookingBean) OverbookingException(com.github.drbookings.OverbookingException) FXML(javafx.fxml.FXML)

Example 4 with BookingBean

use of com.github.drbookings.model.data.BookingBean in project drbookings by DrBookings.

the class AirbnbEarningsCalculatorTest method test02.

@Test
public void test02() {
    BookingBean b = BookingBeanTest.newInstance(LocalDate.of(2012, 02, 02), LocalDate.of(2012, 2, 5));
    b.setPaymentDone(true);
    b.setGrossEarningsExpression("30");
    float result = c.calculateEarnings(b);
    assertThat(result, is(30f));
}
Also used : BookingBean(com.github.drbookings.model.data.BookingBean) BookingBeanTest(com.github.drbookings.model.data.BookingBeanTest)

Example 5 with BookingBean

use of com.github.drbookings.model.data.BookingBean in project drbookings by DrBookings.

the class AirbnbEarningsCalculatorTest method test03.

@Test
public void test03() {
    BookingBean b = BookingBeanTest.newInstance(LocalDate.of(2018, 01, 27), LocalDate.of(2018, 8, 5));
    b.setPaymentDone(true);
    b.setGrossEarningsExpression("8252.86");
    b.getPayments().add(new Payment(LocalDate.of(2018, 01, 29), 1300));
    assertThat(b.getNumberOfNights(), is(190));
    float result = c.calculateEarnings(b);
    assertThat(result, is(1300f));
}
Also used : BookingBean(com.github.drbookings.model.data.BookingBean) BookingBeanTest(com.github.drbookings.model.data.BookingBeanTest)

Aggregations

BookingBean (com.github.drbookings.model.data.BookingBean)14 BookingBeanTest (com.github.drbookings.model.data.BookingBeanTest)6 OverbookingException (com.github.drbookings.OverbookingException)2 CleaningEntry (com.github.drbookings.ui.CleaningEntry)2 RoomBean (com.github.drbookings.ui.beans.RoomBean)2 LocalDate (java.time.LocalDate)2 LinkedHashSet (java.util.LinkedHashSet)2 Collectors (java.util.stream.Collectors)2 FXML (javafx.fxml.FXML)2 Logger (org.slf4j.Logger)2 LoggerFactory (org.slf4j.LoggerFactory)2 DrBookingsApplication (com.github.drbookings.DrBookingsApplication)1 LocalDates (com.github.drbookings.LocalDates)1 Payment (com.github.drbookings.model.Payment)1 BookingOrigin (com.github.drbookings.model.data.BookingOrigin)1 Cleaning (com.github.drbookings.model.data.Cleaning)1 Guest (com.github.drbookings.model.data.Guest)1 Room (com.github.drbookings.model.data.Room)1 MainManager (com.github.drbookings.model.data.manager.MainManager)1 BookingBeanSer (com.github.drbookings.model.ser.BookingBeanSer)1