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