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);
}
}
}
}
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();
}
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();
}
}
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));
}
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));
}
Aggregations