Search in sources :

Example 11 with BookingBean

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

the class BookingEarningsCalculatorTest method test03.

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

Example 12 with BookingBean

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

the class DefaultNetEarningsCalculatorTest method test.

@Test
public void test() {
    final DefaultNetEarningsCalculator c = new DefaultNetEarningsCalculator();
    final BookingBean b = TestUtils.getTestBooking(LocalDate.now(), LocalDate.now().plusDays(4));
    b.setGrossEarningsExpression("360");
    b.setServiceFee(0);
    b.setServiceFeesPercent(12f);
    b.setCleaningFees(60);
    final CleaningEntry ce = new CleaningEntry(LocalDate.now(), b, new Cleaning("testCleaning"), null);
    ce.setCleaningCosts(40);
    b.setCleaning(ce);
    assertEquals(360 - ((360 - 60) * 0.12), c.apply(b).doubleValue(), 0.001);
}
Also used : CleaningEntry(com.github.drbookings.ui.CleaningEntry) Cleaning(com.github.drbookings.model.data.Cleaning) BookingBean(com.github.drbookings.model.data.BookingBean)

Example 13 with BookingBean

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

Example 14 with BookingBean

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

the class AirbnbEarningsCalculator 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();
    if (logger.isDebugEnabled()) {
        logger.debug("Calculating earnings for\n" + bookings.stream().map(b -> b.toString()).collect(Collectors.joining("\n")));
    }
    for (BookingBean b : bookings) {
        if (b.getNumberOfNights() > LocalDate.now().getMonth().minLength()) {
            if (logger.isDebugEnabled()) {
                logger.debug("Days in month " + LocalDate.now().getMonth() + ": " + LocalDate.now().getMonth().minLength());
            }
            if (logger.isInfoEnabled()) {
                logger.info("Airbnb long term booking, looking at manual registered payments");
            }
            Optional<Payment> op = Payments.getLastPayment(b.getPayments());
            MonetaryAmount payment;
            if (op.isPresent()) {
                payment = op.get().getAmount();
            } else {
                payment = moneyFactory.setNumber(0).create();
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Payment is " + payment);
            }
            result = result.add(payment);
        } else
            result = result.add(moneyFactory.setNumber(b.getEarnings(isNetEarnings())).create());
    }
    return result.getNumber().floatValue();
}
Also used : LinkedHashSet(java.util.LinkedHashSet) BookingBean(com.github.drbookings.model.data.BookingBean) Monetary(javax.money.Monetary) MonetaryAmountFactory(javax.money.MonetaryAmountFactory) Logger(org.slf4j.Logger) Collection(java.util.Collection) Range(com.google.common.collect.Range) LoggerFactory(org.slf4j.LoggerFactory) Collectors(java.util.stream.Collectors) DrBookingsApplication(com.github.drbookings.DrBookingsApplication) LocalDate(java.time.LocalDate) Optional(java.util.Optional) MonetaryAmount(javax.money.MonetaryAmount) LinkedHashSet(java.util.LinkedHashSet) MonetaryAmount(javax.money.MonetaryAmount) BookingBean(com.github.drbookings.model.data.BookingBean)

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