use of com.github.drbookings.model.ser.BookingBeanSer 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.ser.BookingBeanSer in project drbookings by DrBookings.
the class CleaningFeesAdder method main.
public static void main(final String[] args) throws Exception {
final File file = new File("/home/alex/bookings.xml");
final float cleaningFees = 60;
final DataStore ds = new XMLStorage().load(file);
for (final BookingBeanSer bs : ds.getBookingsSer()) {
if (bs.cleaningFees == 0) {
bs.cleaningFees = cleaningFees;
}
}
new XMLStorage().save(ds, file);
}
use of com.github.drbookings.model.ser.BookingBeanSer in project drbookings by DrBookings.
the class ServicePercentAdder method main.
public static void main(final String[] args) throws Exception {
final File file = new File("/home/alex/bookings.xml");
final DataStore ds = new XMLStorage().load(file);
for (final BookingBeanSer bs : ds.getBookingsSer()) {
if (bs.source.equalsIgnoreCase("booking")) {
bs.serviceFeePercent = 0.12f;
}
}
new XMLStorage().save(ds, file);
}
use of com.github.drbookings.model.ser.BookingBeanSer in project drbookings by DrBookings.
the class ICalBookingFactory method processEvent.
private BookingBeanSer processEvent(final VEvent e) throws IOException {
final LocalDate checkIn = iCalParser.getCheckInDate(e);
final LocalDate checkOut = iCalParser.getCheckOutDate(e);
final String guestName = iCalParser.getGuestName(e);
final String id = iCalParser.getExternalID(e);
final String roomName = iCalParser.getRoomName(e);
if (checkIn == null || checkOut == null || guestName == null || roomName == null) {
throw new NullPointerException();
}
final BookingBeanSer b = new BookingBeanSer();
b.externalId = id;
b.checkInDate = checkIn;
b.checkOutDate = checkOut;
b.guestName = guestName;
b.roomName = roomName;
b.source = "Airbnb";
return b;
}
use of com.github.drbookings.model.ser.BookingBeanSer in project drbookings by DrBookings.
the class XlsxBookingFactory method build.
@Override
public Collection<BookingBeanSer> build() {
final List<BookingBeanSer> bookings = new ArrayList<>();
FileInputStream stream = null;
Workbook workbook = null;
try {
stream = new FileInputStream(file);
workbook = new HSSFWorkbook(stream);
final Sheet sheet = workbook.getSheetAt(0);
if (logger.isInfoEnabled()) {
logger.info("Processing sheet " + sheet.getSheetName());
}
final int indexBookingNumber = FileFormatBookingXLS.getColumnIndexBookingNumber(sheet.getRow(0));
final int indexClientName = FileFormatBookingXLS.getColumnIndexClientName(sheet.getRow(0));
final int indexBookingCheckIn = FileFormatBookingXLS.getColumnIndexCheckIn(sheet.getRow(0));
final int indexBookingCheckOut = FileFormatBookingXLS.getColumnIndexCheckOut(sheet.getRow(0));
final int indexStatus = FileFormatBookingXLS.getColumnIndexStatus(sheet.getRow(0));
final List<Integer> bookingNumbers = new ArrayList<>();
final List<String> guestNames = new ArrayList<>();
final List<String> stati = new ArrayList<>();
final List<LocalDate> bookingCheckIn = new ArrayList<>();
final List<LocalDate> bookingCheckOut = new ArrayList<>();
for (final Row r : sheet) {
// skip first row
if (r.getRowNum() == 0) {
continue;
}
bookingNumbers.add(FileFormatBookingXLS.getBookingNumber(r.getCell(indexBookingNumber)));
guestNames.add(FileFormatBookingXLS.getString(r.getCell(indexClientName)));
bookingCheckIn.add(FileFormatBookingXLS.getDate(r.getCell(indexBookingCheckIn)));
bookingCheckOut.add(FileFormatBookingXLS.getDate(r.getCell(indexBookingCheckOut)));
stati.add(FileFormatBookingXLS.getString(r.getCell(indexStatus)));
}
if (logger.isDebugEnabled()) {
logger.debug("BookingBean numbers: " + bookingNumbers);
logger.debug("Guest names: " + guestNames);
logger.debug("Check-in dates: " + bookingCheckIn);
logger.debug("Check-out dates: " + bookingCheckOut);
}
if (logger.isInfoEnabled()) {
logger.info("Building bookings.. ");
}
for (int i = 0; i < bookingNumbers.size(); i++) {
final int number = bookingNumbers.get(i);
final LocalDate checkIn = bookingCheckIn.get(i);
final LocalDate checkOut = bookingCheckOut.get(i);
final String names = guestNames.get(i);
final String status = stati.get(i);
if (status.equals("ok")) {
final BookingBeanSer bb = new BookingBeanSer();
bb.checkInDate = checkIn;
bb.checkOutDate = checkOut;
bb.guestName = names;
bb.externalId = Integer.toString(number);
bookings.add(bb);
} else {
if (logger.isDebugEnabled()) {
logger.debug("Skipping status " + status);
}
}
}
} catch (final Exception e) {
if (logger.isErrorEnabled()) {
logger.error(e.getLocalizedMessage(), e);
}
} finally {
if (workbook != null) {
IOUtils.closeQuietly(workbook);
}
if (stream != null) {
IOUtils.closeQuietly(stream);
}
}
return bookings;
}
Aggregations