Search in sources :

Example 1 with BookingBeanSer

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);
            }
        }
    }
}
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 BookingBeanSer

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);
}
Also used : XMLStorage(com.github.drbookings.ser.XMLStorage) DataStore(com.github.drbookings.ser.DataStore) File(java.io.File) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer)

Example 3 with BookingBeanSer

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);
}
Also used : XMLStorage(com.github.drbookings.ser.XMLStorage) DataStore(com.github.drbookings.ser.DataStore) File(java.io.File) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer)

Example 4 with BookingBeanSer

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;
}
Also used : LocalDate(java.time.LocalDate) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer)

Example 5 with BookingBeanSer

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;
}
Also used : ArrayList(java.util.ArrayList) BookingBeanSer(com.github.drbookings.model.ser.BookingBeanSer) LocalDate(java.time.LocalDate) FileInputStream(java.io.FileInputStream) Workbook(org.apache.poi.ss.usermodel.Workbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Row(org.apache.poi.ss.usermodel.Row) Sheet(org.apache.poi.ss.usermodel.Sheet)

Aggregations

BookingBeanSer (com.github.drbookings.model.ser.BookingBeanSer)8 DataStore (com.github.drbookings.ser.DataStore)3 XMLStorage (com.github.drbookings.ser.XMLStorage)3 File (java.io.File)3 ArrayList (java.util.ArrayList)3 CleaningBeanSer (com.github.drbookings.model.ser.CleaningBeanSer)2 LocalDate (java.time.LocalDate)2 ICalendar (biweekly.ICalendar)1 VEvent (biweekly.component.VEvent)1 OverbookingException (com.github.drbookings.OverbookingException)1 BookingBean (com.github.drbookings.model.data.BookingBean)1 RandomString (com.github.ktools1000.RandomString)1 BackupCreator (com.github.ktools1000.io.BackupCreator)1 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 Row (org.apache.poi.ss.usermodel.Row)1 Sheet (org.apache.poi.ss.usermodel.Sheet)1 Workbook (org.apache.poi.ss.usermodel.Workbook)1